1 #ifndef __DALI_SLP_PLATFORM_ASSIMP_MODEL_BUILDER_H__
2 #define __DALI_SLP_PLATFORM_ASSIMP_MODEL_BUILDER_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://floralicense.org/license/
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
20 #include "model-builder.h"
23 #include <assimp/assimp.hpp>
24 #include <assimp/aiScene.h>
26 #include <dali/public-api/modeling/model-data.h>
33 class ModelAnimationMap;
34 class EntityAnimatorMap;
43 class AssimpModelBuilder : public ModelBuilder
47 * Construct a Builder object with the filename of the Model to import
48 * @param[in] name - the filename of the model
50 AssimpModelBuilder(AssimpProxy* importer, const std::string& name);
55 virtual ~AssimpModelBuilder();
57 public: // ModelBuilder Interface
60 * Build a model structure from the Assimp scene
61 * @param[inout] Model - the model to build
63 virtual bool Build(ModelData model);
65 virtual const std::string& GetModelName();
69 * Build this mesh from the assimp model.
70 * @param[out] meshData - object to which the data will be written into
71 * @param[in] ai_scene - the Assimp scene with the data
72 * @param[in] meshIndex - the index within the ai_scene of the mesh data
73 * @param[in] model - the current model
75 void BuildMeshData(MeshData& meshData, const aiScene* ai_scene, unsigned int meshIndex, ModelData& model);
78 * Build this entity from the assimp model
79 * @pre The internal model should already contain the assimp mesh data
80 * @param[in] ai_scene - the assimp scene with the data
81 * @param[in] ai_node - the assimp node to which this entity corresponds
82 * @param[in] model - the current model
83 * @param[in] transform - the current transform matrix to apply
84 * @return An Entity object.
86 Entity BuildEntity(const aiScene* ai_scene, aiNode* ai_node, ModelData* model, const Matrix& transform);
89 * Create a key frame animator from the given node.
90 * @param[in] node - assimp animation node
91 * @param[in] duration - length of animation in seconds
92 * @return the animator data for the node
94 EntityAnimatorMap CreateAnimator(aiNodeAnim* aiNode, float duration, const std::string& name, Entity animatedEntity);
97 * Build this animation from the assimp model
98 * @pre The internal model should already contain all the entities of the scene, and they
99 * should have an entity id set (so that the animation can be referenced back to them)
100 * @param[in] ai_anim - the assimp animation
101 * @param[in] model - the current internal model
102 * @return The animation
104 ModelAnimationMap BuildAnimation(const aiAnimation *ai_anim, ModelData *model);
107 * Build this light from the assimp model
108 * @param[in] ai_scene - The assimp scene with the data
109 * @param[in] lightIndex - The index of the light within the assimp scene
110 * @return A valid Dali::Light handle or false on failure
112 Light BuildLight(const aiScene* ai_scene, const unsigned int lightIndex);
115 * Build this material from the assimp model, and load all appropriate textures
116 * @param[in] ai_material A pointer to an <a href="http://assimp.sourceforge.net/lib_html/structai_material.html">Assimp Material</a>.
117 * @param[in] sBasePath The base path for any texture filenames referenced by the material
118 * @return A pointer to a Material or false.
120 Material BuildMaterial(const aiMaterial* ai_material, const std::string& sBasePath);
123 * Match up the bone names to entities. Goes through each mesh, and assigns the correct
124 * entity onto each bone.
125 * @model - the model to update
127 void MatchBonesToEntities(ModelData* model);
130 private: // Attributes
131 const std::string mFilename;
132 std::string mModelName;
134 AssimpProxy* mModelImporter;
140 #endif // __DALI_SLP_PLATFORM_ASSIMP_MODEL_BUILDER_H__