選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

309 行
7.7 KiB

  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file IRRLoader.h
  34. * @brief Declaration of the .irrMesh (Irrlight Engine Mesh Format)
  35. * importer class.
  36. */
  37. #ifndef AI_IRRLOADER_H_INCLUDED
  38. #define AI_IRRLOADER_H_INCLUDED
  39. #include "IRRShared.h"
  40. #include "SceneCombiner.h"
  41. namespace Assimp {
  42. // ---------------------------------------------------------------------------
  43. /** Irr importer class.
  44. *
  45. * Irr is the native scene file format of the Irrlight engine and its editor
  46. * irrEdit. As IrrEdit itself is capable of importing quite many file formats,
  47. * it might be a good file format for data exchange.
  48. */
  49. class IRRImporter : public BaseImporter, public IrrlichtBase
  50. {
  51. public:
  52. IRRImporter();
  53. ~IRRImporter();
  54. public:
  55. // -------------------------------------------------------------------
  56. /** Returns whether the class can handle the format of the given file.
  57. * See BaseImporter::CanRead() for details.
  58. */
  59. bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
  60. bool checkSig) const;
  61. protected:
  62. // -------------------------------------------------------------------
  63. /**
  64. */
  65. const aiImporterDesc* GetInfo () const;
  66. // -------------------------------------------------------------------
  67. /**
  68. */
  69. void InternReadFile( const std::string& pFile, aiScene* pScene,
  70. IOSystem* pIOHandler);
  71. // -------------------------------------------------------------------
  72. /**
  73. */
  74. void SetupProperties(const Importer* pImp);
  75. private:
  76. /** Data structure for a scenegraph node animator
  77. */
  78. struct Animator
  79. {
  80. // Type of the animator
  81. enum AT
  82. {
  83. UNKNOWN = 0x0,
  84. ROTATION = 0x1,
  85. FLY_CIRCLE = 0x2,
  86. FLY_STRAIGHT = 0x3,
  87. FOLLOW_SPLINE = 0x4,
  88. OTHER = 0x5
  89. } type;
  90. Animator(AT t = UNKNOWN)
  91. : type (t)
  92. , speed (0.001f)
  93. , direction (0.f,1.f,0.f)
  94. , circleRadius (1.f)
  95. , tightness (0.5f)
  96. , loop (true)
  97. , timeForWay (100)
  98. {
  99. }
  100. // common parameters
  101. float speed;
  102. aiVector3D direction;
  103. // FLY_CIRCLE
  104. aiVector3D circleCenter;
  105. float circleRadius;
  106. // FOLLOW_SPLINE
  107. float tightness;
  108. std::vector<aiVectorKey> splineKeys;
  109. // ROTATION (angles given in direction)
  110. // FLY STRAIGHT
  111. // circleCenter = start, direction = end
  112. bool loop;
  113. int timeForWay;
  114. };
  115. /** Data structure for a scenegraph node in an IRR file
  116. */
  117. struct Node
  118. {
  119. // Type of the node
  120. enum ET
  121. {
  122. LIGHT,
  123. CUBE,
  124. MESH,
  125. SKYBOX,
  126. DUMMY,
  127. CAMERA,
  128. TERRAIN,
  129. SPHERE,
  130. ANIMMESH
  131. } type;
  132. Node(ET t)
  133. : type (t)
  134. , scaling (1.f,1.f,1.f) // assume uniform scaling by default
  135. , framesPerSecond (0.f)
  136. , sphereRadius (1.f)
  137. , spherePolyCountX (100)
  138. , spherePolyCountY (100)
  139. {
  140. // Generate a default name for the node
  141. char buffer[128];
  142. static int cnt;
  143. ::sprintf(buffer,"IrrNode_%i",cnt++);
  144. name = std::string(buffer);
  145. // reserve space for up to 5 materials
  146. materials.reserve(5);
  147. // reserve space for up to 5 children
  148. children.reserve(5);
  149. }
  150. // Transformation of the node
  151. aiVector3D position, rotation, scaling;
  152. // Name of the node
  153. std::string name;
  154. // List of all child nodes
  155. std::vector<Node*> children;
  156. // Parent node
  157. Node* parent;
  158. // Animated meshes: frames per second
  159. // 0.f if not specified
  160. float framesPerSecond;
  161. // Meshes: path to the mesh to be loaded
  162. std::string meshPath;
  163. unsigned int id;
  164. // Meshes: List of materials to be assigned
  165. // along with their corresponding material flags
  166. std::vector< std::pair<aiMaterial*, unsigned int> > materials;
  167. // Spheres: radius of the sphere to be generates
  168. float sphereRadius;
  169. // Spheres: Number of polygons in the x,y direction
  170. unsigned int spherePolyCountX,spherePolyCountY;
  171. // List of all animators assigned to the node
  172. std::list<Animator> animators;
  173. };
  174. /** Data structure for a vertex in an IRR skybox
  175. */
  176. struct SkyboxVertex
  177. {
  178. SkyboxVertex()
  179. {}
  180. //! Construction from single vertex components
  181. SkyboxVertex(float px, float py, float pz,
  182. float nx, float ny, float nz,
  183. float uvx, float uvy)
  184. : position (px,py,pz)
  185. , normal (nx,ny,nz)
  186. , uv (uvx,uvy,0.f)
  187. {}
  188. aiVector3D position, normal, uv;
  189. };
  190. // -------------------------------------------------------------------
  191. /** Fill the scenegraph recursively
  192. */
  193. void GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
  194. BatchLoader& batch,
  195. std::vector<aiMesh*>& meshes,
  196. std::vector<aiNodeAnim*>& anims,
  197. std::vector<AttachmentInfo>& attach,
  198. std::vector<aiMaterial*>& materials,
  199. unsigned int& defaultMatIdx);
  200. // -------------------------------------------------------------------
  201. /** Generate a mesh that consists of just a single quad
  202. */
  203. aiMesh* BuildSingleQuadMesh(const SkyboxVertex& v1,
  204. const SkyboxVertex& v2,
  205. const SkyboxVertex& v3,
  206. const SkyboxVertex& v4);
  207. // -------------------------------------------------------------------
  208. /** Build a skybox
  209. *
  210. * @param meshes Receives 6 output meshes
  211. * @param materials The last 6 materials are assigned to the newly
  212. * created meshes. The names of the materials are adjusted.
  213. */
  214. void BuildSkybox(std::vector<aiMesh*>& meshes,
  215. std::vector<aiMaterial*> materials);
  216. // -------------------------------------------------------------------
  217. /** Copy a material for a mesh to the output material list
  218. *
  219. * @param materials Receives an output material
  220. * @param inmaterials List of input materials
  221. * @param defMatIdx Default material index - UINT_MAX if not present
  222. * @param mesh Mesh to work on
  223. */
  224. void CopyMaterial(std::vector<aiMaterial*>& materials,
  225. std::vector< std::pair<aiMaterial*, unsigned int> >& inmaterials,
  226. unsigned int& defMatIdx,
  227. aiMesh* mesh);
  228. // -------------------------------------------------------------------
  229. /** Compute animations for a specific node
  230. *
  231. * @param root Node to be processed
  232. * @param anims The list of output animations
  233. */
  234. void ComputeAnimations(Node* root, aiNode* real,
  235. std::vector<aiNodeAnim*>& anims);
  236. private:
  237. /** Configuration option: desired output FPS */
  238. double fps;
  239. /** Configuration option: speed flag was set? */
  240. bool configSpeedFlag;
  241. };
  242. } // end of namespace Assimp
  243. #endif // AI_IRRIMPORTER_H_INC