3DSLoader.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2010, 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 3DSLoader.h
  34. * @brief 3DS File format loader
  35. */
  36. #ifndef AI_3DSIMPORTER_H_INC
  37. #define AI_3DSIMPORTER_H_INC
  38. #include "BaseImporter.h"
  39. #include "../include/aiTypes.h"
  40. struct aiNode;
  41. #include "3DSHelper.h"
  42. namespace Assimp {
  43. class MaterialHelper;
  44. using namespace D3DS;
  45. // ---------------------------------------------------------------------------------
  46. /** Importer class for 3D Studio r3 and r4 3DS files
  47. */
  48. class Discreet3DSImporter : public BaseImporter
  49. {
  50. friend class Importer;
  51. protected:
  52. /** Constructor to be privately used by Importer */
  53. Discreet3DSImporter();
  54. /** Destructor, private as well */
  55. ~Discreet3DSImporter();
  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. // -------------------------------------------------------------------
  64. /** Called prior to ReadFile().
  65. * The function is a request to the importer to update its configuration
  66. * basing on the Importer's configuration property list.
  67. */
  68. void SetupProperties(const Importer* pImp);
  69. protected:
  70. // -------------------------------------------------------------------
  71. /** Called by Importer::GetExtensionList() for each loaded importer.
  72. * See BaseImporter::GetExtensionList() for details
  73. */
  74. void GetExtensionList(std::set<std::string>& extensions);
  75. // -------------------------------------------------------------------
  76. /** Imports the given file into the given scene structure.
  77. * See BaseImporter::InternReadFile() for details
  78. */
  79. void InternReadFile( const std::string& pFile, aiScene* pScene,
  80. IOSystem* pIOHandler);
  81. // -------------------------------------------------------------------
  82. /** Converts a temporary material to the outer representation
  83. */
  84. void ConvertMaterial(D3DS::Material& p_cMat,
  85. MaterialHelper& p_pcOut);
  86. // -------------------------------------------------------------------
  87. /** Read a chunk
  88. *
  89. * @param pcOut Receives the current chunk
  90. */
  91. void ReadChunk(Discreet3DS::Chunk* pcOut);
  92. // -------------------------------------------------------------------
  93. /** Parse a percentage chunk. mCurrent will point to the next
  94. * chunk behind afterwards. If no percentage chunk is found
  95. * QNAN is returned.
  96. */
  97. float ParsePercentageChunk();
  98. // -------------------------------------------------------------------
  99. /** Parse a color chunk. mCurrent will point to the next
  100. * chunk behind afterwards. If no color chunk is found
  101. * QNAN is returned in all members.
  102. */
  103. void ParseColorChunk(aiColor3D* p_pcOut,
  104. bool p_bAcceptPercent = true);
  105. // -------------------------------------------------------------------
  106. /** Skip a chunk in the file
  107. */
  108. void SkipChunk();
  109. // -------------------------------------------------------------------
  110. /** Generate the nodegraph
  111. */
  112. void GenerateNodeGraph(aiScene* pcOut);
  113. // -------------------------------------------------------------------
  114. /** Parse a main top-level chunk in the file
  115. */
  116. void ParseMainChunk();
  117. // -------------------------------------------------------------------
  118. /** Parse a top-level chunk in the file
  119. */
  120. void ParseChunk(const char* name, unsigned int num);
  121. // -------------------------------------------------------------------
  122. /** Parse a top-level editor chunk in the file
  123. */
  124. void ParseEditorChunk();
  125. // -------------------------------------------------------------------
  126. /** Parse a top-level object chunk in the file
  127. */
  128. void ParseObjectChunk();
  129. // -------------------------------------------------------------------
  130. /** Parse a material chunk in the file
  131. */
  132. void ParseMaterialChunk();
  133. // -------------------------------------------------------------------
  134. /** Parse a mesh chunk in the file
  135. */
  136. void ParseMeshChunk();
  137. // -------------------------------------------------------------------
  138. /** Parse a light chunk in the file
  139. */
  140. void ParseLightChunk();
  141. // -------------------------------------------------------------------
  142. /** Parse a camera chunk in the file
  143. */
  144. void ParseCameraChunk();
  145. // -------------------------------------------------------------------
  146. /** Parse a face list chunk in the file
  147. */
  148. void ParseFaceChunk();
  149. // -------------------------------------------------------------------
  150. /** Parse a keyframe chunk in the file
  151. */
  152. void ParseKeyframeChunk();
  153. // -------------------------------------------------------------------
  154. /** Parse a hierarchy chunk in the file
  155. */
  156. void ParseHierarchyChunk(uint16_t parent);
  157. // -------------------------------------------------------------------
  158. /** Parse a texture chunk in the file
  159. */
  160. void ParseTextureChunk(D3DS::Texture* pcOut);
  161. // -------------------------------------------------------------------
  162. /** Convert the meshes in the file
  163. */
  164. void ConvertMeshes(aiScene* pcOut);
  165. // -------------------------------------------------------------------
  166. /** Replace the default material in the scene
  167. */
  168. void ReplaceDefaultMaterial();
  169. // -------------------------------------------------------------------
  170. /** Convert the whole scene
  171. */
  172. void ConvertScene(aiScene* pcOut);
  173. // -------------------------------------------------------------------
  174. /** generate unique vertices for a mesh
  175. */
  176. void MakeUnique(D3DS::Mesh& sMesh);
  177. // -------------------------------------------------------------------
  178. /** Add a node to the node graph
  179. */
  180. void AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,D3DS::Node* pcIn,
  181. aiMatrix4x4& absTrafo);
  182. // -------------------------------------------------------------------
  183. /** Search for a node in the graph.
  184. * Called recursively
  185. */
  186. void InverseNodeSearch(D3DS::Node* pcNode,D3DS::Node* pcCurrent);
  187. // -------------------------------------------------------------------
  188. /** Apply the master scaling factor to the mesh
  189. */
  190. void ApplyMasterScale(aiScene* pScene);
  191. // -------------------------------------------------------------------
  192. /** Clamp all indices in the file to a valid range
  193. */
  194. void CheckIndices(D3DS::Mesh& sMesh);
  195. // -------------------------------------------------------------------
  196. /** Skip the TCB info in a track key
  197. */
  198. void SkipTCBInfo();
  199. protected:
  200. /** Stream to read from */
  201. StreamReaderLE* stream;
  202. /** Last touched node index */
  203. short mLastNodeIndex;
  204. /** Current node, root node */
  205. D3DS::Node* mCurrentNode, *mRootNode;
  206. /** Scene under construction */
  207. D3DS::Scene* mScene;
  208. /** Ambient base color of the scene */
  209. aiColor3D mClrAmbient;
  210. /** Master scaling factor of the scene */
  211. float mMasterScale;
  212. /** Path to the background image of the scene */
  213. std::string mBackgroundImage;
  214. bool bHasBG;
  215. /** true if PRJ file */
  216. bool bIsPrj;
  217. };
  218. } // end of namespace Assimp
  219. #endif // AI_3DSIMPORTER_H_INC