You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

201 rivejä
5.1 KiB

  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 UnrealLoader.h
  34. * @brief Declaration of the .3d (UNREAL) importer class.
  35. */
  36. #ifndef INCLUDED_AI_3D_LOADER_H
  37. #define INCLUDED_AI_3D_LOADER_H
  38. #include "BaseImporter.h"
  39. namespace Assimp {
  40. namespace Unreal {
  41. /*
  42. 0 = Normal one-sided
  43. 1 = Normal two-sided
  44. 2 = Translucent two-sided
  45. 3 = Masked two-sided
  46. 4 = Modulation blended two-sided
  47. 8 = Placeholder triangle for weapon positioning (invisible)
  48. */
  49. enum MeshFlags {
  50. MF_NORMAL_OS = 0,
  51. MF_NORMAL_TS = 1,
  52. MF_NORMAL_TRANS_TS = 2,
  53. MF_NORMAL_MASKED_TS = 3,
  54. MF_NORMAL_MOD_TS = 4,
  55. MF_WEAPON_PLACEHOLDER = 8
  56. };
  57. // a single triangle
  58. struct Triangle {
  59. uint16_t mVertex[3]; // Vertex indices
  60. char mType; // James' Mesh Type
  61. char mColor; // Color for flat and Gourand Shaded
  62. unsigned char mTex[3][2]; // Texture UV coordinates
  63. unsigned char mTextureNum; // Source texture offset
  64. char mFlags; // Unreal Mesh Flags (unused)
  65. unsigned int matIndex;
  66. };
  67. // temporary representation for a material
  68. struct TempMat {
  69. TempMat()
  70. : numFaces (0)
  71. {}
  72. TempMat(const Triangle& in)
  73. : type ((Unreal::MeshFlags)in.mType)
  74. , tex (in.mTextureNum)
  75. , numFaces (0)
  76. {}
  77. // type of mesh
  78. Unreal::MeshFlags type;
  79. // index of texture
  80. unsigned int tex;
  81. // number of faces using us
  82. unsigned int numFaces;
  83. // for std::find
  84. bool operator == (const TempMat& o ) {
  85. return (tex == o.tex && type == o.type);
  86. }
  87. };
  88. struct Vertex
  89. {
  90. int32_t X : 11;
  91. int32_t Y : 11;
  92. int32_t Z : 10;
  93. };
  94. // UNREAL vertex compression
  95. inline void CompressVertex(const aiVector3D& v, uint32_t& out)
  96. {
  97. union {
  98. Vertex n;
  99. int32_t t;
  100. };
  101. n.X = (int32_t)v.x;
  102. n.Y = (int32_t)v.y;
  103. n.Z = (int32_t)v.z;
  104. out = t;
  105. }
  106. // UNREAL vertex decompression
  107. inline void DecompressVertex(aiVector3D& v, int32_t in)
  108. {
  109. union {
  110. Vertex n;
  111. int32_t i;
  112. };
  113. i = in;
  114. v.x = (float)n.X;
  115. v.y = (float)n.Y;
  116. v.z = (float)n.Z;
  117. }
  118. } // end namespace Unreal
  119. // ---------------------------------------------------------------------------
  120. /** @brief Importer class to load UNREAL files (*.3d)
  121. */
  122. class UnrealImporter : public BaseImporter
  123. {
  124. public:
  125. UnrealImporter();
  126. ~UnrealImporter();
  127. public:
  128. // -------------------------------------------------------------------
  129. /** @brief Returns whether we can handle the format of the given file
  130. *
  131. * See BaseImporter::CanRead() for details.
  132. **/
  133. bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
  134. bool checkSig) const;
  135. protected:
  136. // -------------------------------------------------------------------
  137. /** @brief Called by Importer::GetExtensionList()
  138. *
  139. * See #BaseImporter::GetInfo for the details
  140. */
  141. const aiImporterDesc* GetInfo () const;
  142. // -------------------------------------------------------------------
  143. /** @brief Setup properties for the importer
  144. *
  145. * See BaseImporter::SetupProperties() for details
  146. */
  147. void SetupProperties(const Importer* pImp);
  148. // -------------------------------------------------------------------
  149. /** @brief Imports the given file into the given scene structure.
  150. *
  151. * See BaseImporter::InternReadFile() for details
  152. */
  153. void InternReadFile( const std::string& pFile, aiScene* pScene,
  154. IOSystem* pIOHandler);
  155. private:
  156. //! frame to be loaded
  157. uint32_t configFrameID;
  158. //! process surface flags
  159. bool configHandleFlags;
  160. }; // !class UnrealImporter
  161. } // end of namespace Assimp
  162. #endif // AI_UNREALIMPORTER_H_INC