LWOLoader.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 LWO importer class. */
  34. #ifndef AI_LWOLOADER_H_INCLUDED
  35. #define AI_LWOLOADER_H_INCLUDED
  36. #include "../include/aiTypes.h"
  37. #include "BaseImporter.h"
  38. #include "LWOFileData.h"
  39. #include "MaterialSystem.h"
  40. struct aiTexture;
  41. struct aiNode;
  42. namespace Assimp {
  43. using namespace LWO;
  44. // ---------------------------------------------------------------------------
  45. /** Class to load LWO files.
  46. *
  47. * @note Methods named "xxxLWO2[xxx]" are used with the newer LWO2 format.
  48. * Methods named "xxxLWOB[xxx]" are used with the older LWOB format.
  49. * Methods named "xxxLWO[xxx]" are used with both formats.
  50. * Methods named "xxx" are used to preprocess the loaded data -
  51. * they aren't specific to one format version, either
  52. */
  53. class LWOImporter : public BaseImporter
  54. {
  55. friend class Importer;
  56. protected:
  57. /** Constructor to be privately used by Importer */
  58. LWOImporter();
  59. /** Destructor, private as well */
  60. ~LWOImporter();
  61. public:
  62. // -------------------------------------------------------------------
  63. /** Returns whether the class can handle the format of the given file.
  64. * See BaseImporter::CanRead() for details. */
  65. bool CanRead( const std::string& pFile, IOSystem* pIOHandler) const;
  66. // -------------------------------------------------------------------
  67. /** Called prior to ReadFile().
  68. * The function is a request to the importer to update its configuration
  69. * basing on the Importer's configuration property list.
  70. */
  71. void SetupProperties(const Importer* pImp);
  72. protected:
  73. // -------------------------------------------------------------------
  74. /** Called by Importer::GetExtensionList() for each loaded importer.
  75. * See BaseImporter::GetExtensionList() for details
  76. */
  77. void GetExtensionList(std::string& append)
  78. {
  79. append.append("*.lwo");
  80. }
  81. // -------------------------------------------------------------------
  82. /** Imports the given file into the given scene structure.
  83. * See BaseImporter::InternReadFile() for details
  84. */
  85. void InternReadFile( const std::string& pFile, aiScene* pScene,
  86. IOSystem* pIOHandler);
  87. private:
  88. // -------------------------------------------------------------------
  89. /** Loads a LWO file in the older LWOB format (LW < 6)
  90. */
  91. void LoadLWOBFile();
  92. // -------------------------------------------------------------------
  93. /** Loads a LWO file in the newer LWO2 format (LW >= 6)
  94. */
  95. void LoadLWO2File();
  96. // -------------------------------------------------------------------
  97. /** Loads a surface chunk from an LWOB file
  98. * @param size Maximum size to be read, in bytes.
  99. */
  100. void LoadLWOBSurface(unsigned int size);
  101. // -------------------------------------------------------------------
  102. /** Loads a surface chunk from an LWO2 file
  103. * @param size Maximum size to be read, in bytes.
  104. */
  105. void LoadLWO2Surface(unsigned int size);
  106. // -------------------------------------------------------------------
  107. /** Loads a texture block from a LWO2 file.
  108. * @param size Maximum size to be read, in bytes.
  109. * @param type Type of the texture block - PROC, GRAD or IMAP
  110. */
  111. void LoadLWO2TextureBlock(uint32_t type, unsigned int size );
  112. // -------------------------------------------------------------------
  113. /** Loads an image map from a LWO2 file
  114. * @param size Maximum size to be read, in bytes.
  115. * @param tex Texture object to be filled
  116. */
  117. void LoadLWO2ImageMap(unsigned int size, LWO::Texture& tex );
  118. void LoadLWO2Gradient(unsigned int size, LWO::Texture& tex );
  119. void LoadLWO2Procedural(unsigned int size, LWO::Texture& tex );
  120. // loads the header - used by thethree functions above
  121. void LoadLWO2TextureHeader(unsigned int size, LWO::Texture& tex );
  122. // -------------------------------------------------------------------
  123. /** Loads the LWO tag list from the file
  124. * @param size Maximum size to be read, in bytes.
  125. */
  126. void LoadLWOTags(unsigned int size);
  127. // -------------------------------------------------------------------
  128. /** Load polygons from a POLS chunk
  129. * @param length Size of the chunk
  130. */
  131. void LoadLWO2Polygons(unsigned int length);
  132. void LoadLWOBPolygons(unsigned int length);
  133. // -------------------------------------------------------------------
  134. /** Load polygon tags from a PTAG chunk
  135. * @param length Size of the chunk
  136. */
  137. void LoadLWO2PolygonTags(unsigned int length);
  138. // -------------------------------------------------------------------
  139. /** Load a vertex map from a VMAP/VMAD chunk
  140. * @param length Size of the chunk
  141. * @param perPoly Operate on per-polygon base?
  142. */
  143. void LoadLWO2VertexMap(unsigned int length, bool perPoly);
  144. // -------------------------------------------------------------------
  145. /** Load polygons from a PNTS chunk
  146. * @param length Size of the chunk
  147. */
  148. void LoadLWOPoints(unsigned int length);
  149. // -------------------------------------------------------------------
  150. /** Count vertices and faces in a LWOB/LWO2 file
  151. */
  152. void CountVertsAndFacesLWO2(unsigned int& verts,
  153. unsigned int& faces,
  154. LE_NCONST uint16_t*& cursor,
  155. const uint16_t* const end,
  156. unsigned int max = 0xffffffff);
  157. void CountVertsAndFacesLWOB(unsigned int& verts,
  158. unsigned int& faces,
  159. LE_NCONST uint16_t*& cursor,
  160. const uint16_t* const end,
  161. unsigned int max = 0xffffffff);
  162. // -------------------------------------------------------------------
  163. /** Read vertices and faces in a LWOB/LWO2 file
  164. */
  165. void CopyFaceIndicesLWO2(LWO::FaceList::iterator& it,
  166. LE_NCONST uint16_t*& cursor,
  167. const uint16_t* const end);
  168. void CopyFaceIndicesLWOB(LWO::FaceList::iterator& it,
  169. LE_NCONST uint16_t*& cursor,
  170. const uint16_t* const end,
  171. unsigned int max = 0xffffffff);
  172. // -------------------------------------------------------------------
  173. /** Resolve the tag and surface lists that have been loaded.
  174. * Generates the mMapping table.
  175. */
  176. void ResolveTags();
  177. // -------------------------------------------------------------------
  178. /** Parse a string from the current file position
  179. */
  180. void ParseString(std::string& out,unsigned int max);
  181. // -------------------------------------------------------------------
  182. /** Adjust a texture path
  183. */
  184. void AdjustTexturePath(std::string& out);
  185. // -------------------------------------------------------------------
  186. /** Convert a LWO surface description to an ASSIMP material
  187. */
  188. void ConvertMaterial(const LWO::Surface& surf,MaterialHelper* pcMat);
  189. // -------------------------------------------------------------------
  190. /** Get a list of all UV/VC channels required by a specific surface.
  191. *
  192. * @param surf Working surface
  193. * @param layer Working layer
  194. * @param out Output list. The members are indices into the
  195. * UV/VC channel lists of the layer
  196. */
  197. void FindUVChannels(const LWO::Surface& surf,
  198. const LWO::Layer& layer,
  199. unsigned int out[AI_MAX_NUMBER_OF_TEXTURECOORDS]);
  200. void FindVCChannels(const LWO::Surface& surf,
  201. const LWO::Layer& layer,
  202. unsigned int out[AI_MAX_NUMBER_OF_COLOR_SETS]);
  203. // -------------------------------------------------------------------
  204. /** Generate the final node graph
  205. * Unused nodes are deleted.
  206. * @param apcNodes Flat list of nodes
  207. */
  208. void GenerateNodeGraph(std::vector<aiNode*>& apcNodes);
  209. // -------------------------------------------------------------------
  210. /** Add children to a node
  211. * @param node Node to become a father
  212. * @param parent Index of the node
  213. * @param apcNodes Flat list of nodes - used nodes are set to NULL.
  214. */
  215. void AddChildren(aiNode* node, uintptr_t parent,
  216. std::vector<aiNode*>& apcNodes);
  217. // -------------------------------------------------------------------
  218. /** Read a variable sized integer
  219. * @param inout Input and output buffer
  220. */
  221. int ReadVSizedIntLWO2(uint8_t*& inout);
  222. protected:
  223. /** true if the file is a LWO2 file*/
  224. bool mIsLWO2;
  225. /** Temporary list of layers from the file */
  226. LayerList* mLayers;
  227. /** Pointer to the current layer */
  228. LWO::Layer* mCurLayer;
  229. /** Temporary tag list from the file */
  230. TagList* mTags;
  231. /** Mapping table to convert from tag to surface indices.
  232. 0xffffffff indicates that a no corresponding surface is available */
  233. TagMappingTable* mMapping;
  234. /** Temporary surface list from the file */
  235. SurfaceList* mSurfaces;
  236. /** Temporary clip list from the file */
  237. ClipList mClips;
  238. /** file buffer */
  239. LE_NCONST uint8_t* mFileBuffer;
  240. /** Size of the file, in bytes */
  241. unsigned int fileSize;
  242. /** Output scene */
  243. aiScene* pScene;
  244. };
  245. } // end of namespace Assimp
  246. #endif // AI_LWOIMPORTER_H_INCLUDED