IRRLoader.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2008, ASSIMP Development 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 Development 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 Declaration of the .irrMesh (Irrlight Engine Mesh Format)
  34. importer class.
  35. */
  36. #ifndef AI_IRRLOADER_H_INCLUDED
  37. #define AI_IRRLOADER_H_INCLUDED
  38. #include "IRRMeshLoader.h"
  39. #include "SceneCombiner.h"
  40. namespace Assimp {
  41. // ---------------------------------------------------------------------------
  42. /** Irr importer class.
  43. *
  44. * Irr is the native scene file format of the Irrlight engine and its editor
  45. * irrEdit. As IrrEdit itself is capable of importing quite many file formats,
  46. * it might be a good file format for data exchange.
  47. */
  48. class IRRImporter : public BaseImporter, public IrrlichtBase
  49. {
  50. friend class Importer;
  51. protected:
  52. /** Constructor to be privately used by Importer */
  53. IRRImporter();
  54. /** Destructor, private as well */
  55. ~IRRImporter();
  56. public:
  57. // -------------------------------------------------------------------
  58. /** Returns whether the class can handle the format of the given file.
  59. * See BaseImporter::CanRead() for details.
  60. */
  61. bool CanRead( const std::string& pFile, IOSystem* pIOHandler) const;
  62. protected:
  63. // -------------------------------------------------------------------
  64. /**
  65. */
  66. void GetExtensionList(std::string& append);
  67. // -------------------------------------------------------------------
  68. /**
  69. */
  70. void InternReadFile( const std::string& pFile, aiScene* pScene,
  71. IOSystem* pIOHandler);
  72. // -------------------------------------------------------------------
  73. /**
  74. */
  75. void SetupProperties(const Importer* pImp);
  76. private:
  77. /** Data structure for a scenegraph node animator
  78. */
  79. struct Animator
  80. {
  81. // Type of the animator
  82. enum AT
  83. {
  84. UNKNOWN = 0x0,
  85. ROTATION = 0x1,
  86. FLY_CIRCLE = 0x2,
  87. FLY_STRAIGHT = 0x3,
  88. FOLLOW_SPLINE = 0x4,
  89. OTHER = 0x5
  90. } type;
  91. Animator(AT t = UNKNOWN)
  92. : type (t)
  93. , speed (0.001f)
  94. , direction (0.f,1.f,0.f)
  95. , circleRadius (1.f)
  96. , tightness (0.5f)
  97. , loop (true)
  98. , timeForWay (100)
  99. {
  100. }
  101. // common parameters
  102. float speed;
  103. aiVector3D direction;
  104. // FLY_CIRCLE
  105. aiVector3D circleCenter;
  106. float circleRadius;
  107. // FOLLOW_SPLINE
  108. float tightness;
  109. std::vector<aiVectorKey> splineKeys;
  110. // ROTATION (angles given in direction)
  111. // FLY STRAIGHT
  112. // circleCenter = start, direction = end
  113. bool loop;
  114. int timeForWay;
  115. };
  116. /** Data structure for a scenegraph node in an IRR file
  117. */
  118. struct Node
  119. {
  120. // Type of the node
  121. enum ET
  122. {
  123. LIGHT,
  124. CUBE,
  125. MESH,
  126. SKYBOX,
  127. DUMMY,
  128. CAMERA,
  129. TERRAIN,
  130. SPHERE,
  131. ANIMMESH
  132. } type;
  133. Node(ET t)
  134. : type (t)
  135. , scaling (1.f,1.f,1.f) // assume uniform scaling by default
  136. , framesPerSecond (0.f)
  137. , sphereRadius (1.f)
  138. , spherePolyCountX (100)
  139. , spherePolyCountY (100)
  140. {
  141. // Generate a default name for the node
  142. char buffer[128];
  143. static int cnt;
  144. ::sprintf(buffer,"IrrNode_%i",cnt++);
  145. name = std::string(buffer);
  146. // reserve space for up to 5 materials
  147. materials.reserve(5);
  148. // reserve space for up to 5 children
  149. children.reserve(5);
  150. }
  151. // Transformation of the node
  152. aiVector3D position, rotation, scaling;
  153. // Name of the node
  154. std::string name;
  155. // List of all child nodes
  156. std::vector<Node*> children;
  157. // Parent node
  158. Node* parent;
  159. // Animated meshes: frames per second
  160. // 0.f if not specified
  161. float framesPerSecond;
  162. // Meshes: path to the mesh to be loaded
  163. std::string meshPath;
  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 - 0xffffffff if not there
  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. double fps;
  238. };
  239. } // end of namespace Assimp
  240. #endif // AI_IRRIMPORTER_H_INC