3DSLoader.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /** @file Definition of the .3ds importer class. */
  2. #ifndef AI_3DSIMPORTER_H_INC
  3. #define AI_3DSIMPORTER_H_INC
  4. #include <map>
  5. #include "BaseImporter.h"
  6. #include "../include/aiTypes.h"
  7. struct aiNode;
  8. #include "3DSHelper.h"
  9. namespace Assimp
  10. {
  11. class MaterialHelper;
  12. using namespace Dot3DS;
  13. // ---------------------------------------------------------------------------
  14. /** The Dot3DSImporter is a worker class capable of importing a scene from a
  15. * 3ds Max 4/5 File (.3ds)
  16. */
  17. class Dot3DSImporter : public BaseImporter
  18. {
  19. friend class Importer;
  20. protected:
  21. /** Constructor to be privately used by Importer */
  22. Dot3DSImporter();
  23. /** Destructor, private as well */
  24. ~Dot3DSImporter();
  25. public:
  26. // -------------------------------------------------------------------
  27. /** Returns whether the class can handle the format of the given file.
  28. * See BaseImporter::CanRead() for details. */
  29. bool CanRead( const std::string& pFile, IOSystem* pIOHandler) const;
  30. protected:
  31. // -------------------------------------------------------------------
  32. /** Imports the given file into the given scene structure.
  33. * See BaseImporter::InternReadFile() for details
  34. */
  35. void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
  36. // -------------------------------------------------------------------
  37. /** Converts a temporary material to the outer representation
  38. */
  39. void ConvertMaterial(Dot3DS::Material& p_cMat,
  40. MaterialHelper& p_pcOut);
  41. // -------------------------------------------------------------------
  42. /** Read a chunk, get a pointer to it
  43. * The mCurrent pointer will be increased by sizeof(Dot3DSFile::Chunk),
  44. * thus pointing directly to the data of the chunk
  45. */
  46. void ReadChunk(const Dot3DSFile::Chunk** p_ppcOut);
  47. // -------------------------------------------------------------------
  48. /** Parse a percentage chunk. mCurrent will point to the next
  49. * chunk behind afterwards. If no percentage chunk is found
  50. * QNAN is returned.
  51. */
  52. float ParsePercentageChunk();
  53. // -------------------------------------------------------------------
  54. /** Parse a color chunk. mCurrent will point to the next
  55. * chunk behind afterwards. If no color chunk is found
  56. * QNAN is returned in all members.
  57. */
  58. void ParseColorChunk(aiColor3D* p_pcOut,
  59. bool p_bAcceptPercent = true);
  60. // -------------------------------------------------------------------
  61. /** Skip a chunk in the file
  62. */
  63. void SkipChunk();
  64. // -------------------------------------------------------------------
  65. /** Generate the nodegraph
  66. */
  67. void GenerateNodeGraph(aiScene* pcOut);
  68. // -------------------------------------------------------------------
  69. /** Parse a main top-level chunk in the file
  70. */
  71. void ParseMainChunk(int* piRemaining);
  72. // -------------------------------------------------------------------
  73. /** Parse a top-level chunk in the file
  74. */
  75. void ParseChunk(int* piRemaining);
  76. // -------------------------------------------------------------------
  77. /** Parse a top-level editor chunk in the file
  78. */
  79. void ParseEditorChunk(int* piRemaining);
  80. // -------------------------------------------------------------------
  81. /** Parse a top-level object chunk in the file
  82. */
  83. void ParseObjectChunk(int* piRemaining);
  84. // -------------------------------------------------------------------
  85. /** Parse a material chunk in the file
  86. */
  87. void ParseMaterialChunk(int* piRemaining);
  88. // -------------------------------------------------------------------
  89. /** Apply texture coordinate offsets
  90. */
  91. void ApplyScaleNOffset();
  92. void BakeScaleNOffset(aiMesh* pcMesh, Dot3DS::Material* pcSrc);
  93. // -------------------------------------------------------------------
  94. /** Parse a mesh chunk in the file
  95. */
  96. void ParseMeshChunk(int* piRemaining);
  97. // -------------------------------------------------------------------
  98. /** Parse a face list chunk in the file
  99. */
  100. void ParseFaceChunk(int* piRemaining);
  101. // -------------------------------------------------------------------
  102. /** Parse a keyframe chunk in the file
  103. */
  104. void ParseKeyframeChunk(int* piRemaining);
  105. // -------------------------------------------------------------------
  106. /** Parse a hierarchy chunk in the file
  107. */
  108. void ParseHierarchyChunk(int* piRemaining);
  109. // -------------------------------------------------------------------
  110. /** Parse a texture chunk in the file
  111. */
  112. void ParseTextureChunk(int* piRemaining,Dot3DS::Texture* pcOut);
  113. // -------------------------------------------------------------------
  114. /** Convert the meshes in the file
  115. */
  116. void ConvertMeshes(aiScene* pcOut);
  117. // -------------------------------------------------------------------
  118. /** Replace the default material in the scene
  119. */
  120. void ReplaceDefaultMaterial();
  121. // -------------------------------------------------------------------
  122. /** Convert the whole scene
  123. */
  124. void ConvertScene(aiScene* pcOut);
  125. // -------------------------------------------------------------------
  126. /** U/V Scaling/Offset handling
  127. */
  128. void GenTexCoord (Dot3DS::Texture* pcTexture,
  129. const std::vector<aiVector2D>& p_vIn,
  130. std::vector<aiVector2D>& p_vOut);
  131. // -------------------------------------------------------------------
  132. /** generate normal vectors for a given mesh
  133. */
  134. void GenNormals(Dot3DS::Mesh* sMesh);
  135. // -------------------------------------------------------------------
  136. /** generate unique vertices for a mesh
  137. */
  138. void MakeUnique(Dot3DS::Mesh* sMesh);
  139. // -------------------------------------------------------------------
  140. /** Add a node to the node graph
  141. */
  142. void AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,Dot3DS::Node* pcIn);
  143. // -------------------------------------------------------------------
  144. /** Search for a node in the graph.
  145. * Called recursively
  146. */
  147. void InverseNodeSearch(Dot3DS::Node* pcNode,Dot3DS::Node* pcCurrent);
  148. // -------------------------------------------------------------------
  149. /** Apply the master scaling factor to the mesh
  150. */
  151. void ApplyMasterScale(aiScene* pScene);
  152. // -------------------------------------------------------------------
  153. /** Clamp all indices in the file to a valid range
  154. */
  155. void Dot3DSImporter::CheckIndices(Dot3DS::Mesh* sMesh);
  156. protected:
  157. /** Buffer to hold the loaded file */
  158. unsigned char* mBuffer;
  159. /** Pointer to the current read position */
  160. const unsigned char* mCurrent;
  161. /** Used to store old chunk addresses to jump back in the file*/
  162. const unsigned char* mLast;
  163. /** Last touched node index */
  164. short mLastNodeIndex;
  165. /** Current node, root node */
  166. Dot3DS::Node* mCurrentNode, *mRootNode;
  167. /** Scene under construction */
  168. Dot3DS::Scene* mScene;
  169. /** Ambient base color of the scene */
  170. aiColor3D mClrAmbient;
  171. /** Master scaling factor of the scene */
  172. float mMasterScale;
  173. /** Path to the background image of the scene */
  174. std::string mBackgroundImage;
  175. bool bHasBG;
  176. };
  177. } // end of namespace Assimp
  178. #endif // AI_3DSIMPORTER_H_INC