LWOLoader.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 <vector>
  40. namespace Assimp {
  41. using namespace LWO;
  42. // ---------------------------------------------------------------------------
  43. /** Clas to load LWO files
  44. */
  45. class LWOImporter : public BaseImporter
  46. {
  47. friend class Importer;
  48. protected:
  49. /** Constructor to be privately used by Importer */
  50. LWOImporter();
  51. /** Destructor, private as well */
  52. ~LWOImporter();
  53. public:
  54. // -------------------------------------------------------------------
  55. /** Returns whether the class can handle the format of the given file.
  56. * See BaseImporter::CanRead() for details. */
  57. bool CanRead( const std::string& pFile, IOSystem* pIOHandler) const;
  58. protected:
  59. // -------------------------------------------------------------------
  60. /** Called by Importer::GetExtensionList() for each loaded importer.
  61. * See BaseImporter::GetExtensionList() for details
  62. */
  63. void GetExtensionList(std::string& append)
  64. {
  65. append.append("*.lwo");
  66. }
  67. // -------------------------------------------------------------------
  68. /** Imports the given file into the given scene structure.
  69. * See BaseImporter::InternReadFile() for details
  70. */
  71. void InternReadFile( const std::string& pFile, aiScene* pScene,
  72. IOSystem* pIOHandler);
  73. // -------------------------------------------------------------------
  74. /** Loads a LWO file in the older LWOB format (LW < 6)
  75. */
  76. void LoadLWOBFile();
  77. // -------------------------------------------------------------------
  78. /** Loads a LWO file in the newer LWO2 format (LW >= 6)
  79. */
  80. void LoadLWO2File();
  81. // -------------------------------------------------------------------
  82. /** Loads a surface chunk from an LWOB file
  83. */
  84. void LoadLWOBSurface(unsigned int size);
  85. typedef std::vector<aiVector3D> PointList;
  86. typedef std::vector<LWO::Face> FaceList;
  87. typedef std::vector<LWO::Surface> SurfaceList;
  88. private:
  89. // -------------------------------------------------------------------
  90. /** Count vertices and faces in a LWOB file
  91. */
  92. void CountVertsAndFaces(unsigned int& verts,
  93. unsigned int& faces,
  94. LE_NCONST uint8_t*& cursor,
  95. const uint8_t* const end,
  96. unsigned int max = 0xffffffff);
  97. // -------------------------------------------------------------------
  98. /** Read vertices and faces in a LWOB file
  99. */
  100. void CopyFaceIndices(FaceList::iterator& it,
  101. LE_NCONST uint8_t*& cursor,
  102. const uint8_t* const end,
  103. unsigned int max = 0xffffffff);
  104. protected:
  105. /** Temporary point list from the file */
  106. PointList mTempPoints;
  107. /** Temporary face list from the file*/
  108. FaceList mFaces;
  109. /** Temporary surface list from the file */
  110. SurfaceList mSurfaces;
  111. /** file buffer */
  112. LE_NCONST uint8_t* mFileBuffer;
  113. /** Size of the file, in bytes */
  114. unsigned int fileSize;
  115. /** Output scene */
  116. aiScene* pScene;
  117. };
  118. } // end of namespace Assimp
  119. #endif // AI_LWOIMPORTER_H_INCLUDED