UnrealLoader.h 5.6 KB

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