3DSLoader.h 8.6 KB

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