UnrealLoader.h 5.6 KB

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