IRRLoader.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2015, 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. #include "Importer.h"
  42. #include "../include/assimp/anim.h"
  43. namespace Assimp {
  44. // ---------------------------------------------------------------------------
  45. /** Irr importer class.
  46. *
  47. * Irr is the native scene file format of the Irrlight engine and its editor
  48. * irrEdit. As IrrEdit itself is capable of importing quite many file formats,
  49. * it might be a good file format for data exchange.
  50. */
  51. class IRRImporter : public BaseImporter, public IrrlichtBase
  52. {
  53. public:
  54. IRRImporter();
  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,
  62. bool checkSig) const;
  63. protected:
  64. // -------------------------------------------------------------------
  65. /**
  66. */
  67. const aiImporterDesc* GetInfo () const;
  68. // -------------------------------------------------------------------
  69. /**
  70. */
  71. void InternReadFile( const std::string& pFile, aiScene* pScene,
  72. IOSystem* pIOHandler);
  73. // -------------------------------------------------------------------
  74. /**
  75. */
  76. void SetupProperties(const Importer* pImp);
  77. private:
  78. /** Data structure for a scenegraph node animator
  79. */
  80. struct Animator
  81. {
  82. // Type of the animator
  83. enum AT
  84. {
  85. UNKNOWN = 0x0,
  86. ROTATION = 0x1,
  87. FLY_CIRCLE = 0x2,
  88. FLY_STRAIGHT = 0x3,
  89. FOLLOW_SPLINE = 0x4,
  90. OTHER = 0x5
  91. } type;
  92. Animator(AT t = UNKNOWN)
  93. : type (t)
  94. , speed (0.001f)
  95. , direction (0.f,1.f,0.f)
  96. , circleRadius (1.f)
  97. , tightness (0.5f)
  98. , loop (true)
  99. , timeForWay (100)
  100. {
  101. }
  102. // common parameters
  103. float speed;
  104. aiVector3D direction;
  105. // FLY_CIRCLE
  106. aiVector3D circleCenter;
  107. float circleRadius;
  108. // FOLLOW_SPLINE
  109. float tightness;
  110. std::vector<aiVectorKey> splineKeys;
  111. // ROTATION (angles given in direction)
  112. // FLY STRAIGHT
  113. // circleCenter = start, direction = end
  114. bool loop;
  115. int timeForWay;
  116. };
  117. /** Data structure for a scenegraph node in an IRR file
  118. */
  119. struct Node
  120. {
  121. // Type of the node
  122. enum ET
  123. {
  124. LIGHT,
  125. CUBE,
  126. MESH,
  127. SKYBOX,
  128. DUMMY,
  129. CAMERA,
  130. TERRAIN,
  131. SPHERE,
  132. ANIMMESH
  133. } type;
  134. Node(ET t)
  135. : type (t)
  136. , scaling (1.f,1.f,1.f) // assume uniform scaling by default
  137. , parent()
  138. , framesPerSecond (0.f)
  139. , id()
  140. , sphereRadius (1.f)
  141. , spherePolyCountX (100)
  142. , spherePolyCountY (100)
  143. {
  144. // Generate a default name for the node
  145. char buffer[128];
  146. static int cnt;
  147. ::sprintf(buffer,"IrrNode_%i",cnt++);
  148. name = std::string(buffer);
  149. // reserve space for up to 5 materials
  150. materials.reserve(5);
  151. // reserve space for up to 5 children
  152. children.reserve(5);
  153. }
  154. // Transformation of the node
  155. aiVector3D position, rotation, scaling;
  156. // Name of the node
  157. std::string name;
  158. // List of all child nodes
  159. std::vector<Node*> children;
  160. // Parent node
  161. Node* parent;
  162. // Animated meshes: frames per second
  163. // 0.f if not specified
  164. float framesPerSecond;
  165. // Meshes: path to the mesh to be loaded
  166. std::string meshPath;
  167. unsigned int id;
  168. // Meshes: List of materials to be assigned
  169. // along with their corresponding material flags
  170. std::vector< std::pair<aiMaterial*, unsigned int> > materials;
  171. // Spheres: radius of the sphere to be generates
  172. float sphereRadius;
  173. // Spheres: Number of polygons in the x,y direction
  174. unsigned int spherePolyCountX,spherePolyCountY;
  175. // List of all animators assigned to the node
  176. std::list<Animator> animators;
  177. };
  178. /** Data structure for a vertex in an IRR skybox
  179. */
  180. struct SkyboxVertex
  181. {
  182. SkyboxVertex()
  183. {}
  184. //! Construction from single vertex components
  185. SkyboxVertex(float px, float py, float pz,
  186. float nx, float ny, float nz,
  187. float uvx, float uvy)
  188. : position (px,py,pz)
  189. , normal (nx,ny,nz)
  190. , uv (uvx,uvy,0.f)
  191. {}
  192. aiVector3D position, normal, uv;
  193. };
  194. // -------------------------------------------------------------------
  195. /** Fill the scenegraph recursively
  196. */
  197. void GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
  198. BatchLoader& batch,
  199. std::vector<aiMesh*>& meshes,
  200. std::vector<aiNodeAnim*>& anims,
  201. std::vector<AttachmentInfo>& attach,
  202. std::vector<aiMaterial*>& materials,
  203. unsigned int& defaultMatIdx);
  204. // -------------------------------------------------------------------
  205. /** Generate a mesh that consists of just a single quad
  206. */
  207. aiMesh* BuildSingleQuadMesh(const SkyboxVertex& v1,
  208. const SkyboxVertex& v2,
  209. const SkyboxVertex& v3,
  210. const SkyboxVertex& v4);
  211. // -------------------------------------------------------------------
  212. /** Build a skybox
  213. *
  214. * @param meshes Receives 6 output meshes
  215. * @param materials The last 6 materials are assigned to the newly
  216. * created meshes. The names of the materials are adjusted.
  217. */
  218. void BuildSkybox(std::vector<aiMesh*>& meshes,
  219. std::vector<aiMaterial*> materials);
  220. // -------------------------------------------------------------------
  221. /** Copy a material for a mesh to the output material list
  222. *
  223. * @param materials Receives an output material
  224. * @param inmaterials List of input materials
  225. * @param defMatIdx Default material index - UINT_MAX if not present
  226. * @param mesh Mesh to work on
  227. */
  228. void CopyMaterial(std::vector<aiMaterial*>& materials,
  229. std::vector< std::pair<aiMaterial*, unsigned int> >& inmaterials,
  230. unsigned int& defMatIdx,
  231. aiMesh* mesh);
  232. // -------------------------------------------------------------------
  233. /** Compute animations for a specific node
  234. *
  235. * @param root Node to be processed
  236. * @param anims The list of output animations
  237. */
  238. void ComputeAnimations(Node* root, aiNode* real,
  239. std::vector<aiNodeAnim*>& anims);
  240. private:
  241. /** Configuration option: desired output FPS */
  242. double fps;
  243. /** Configuration option: speed flag was set? */
  244. bool configSpeedFlag;
  245. };
  246. } // end of namespace Assimp
  247. #endif // AI_IRRIMPORTER_H_INC