1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
7
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
11
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
15
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
20
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
38 ----------------------------------------------------------------------
39 */
40
41 /** @file UnrealLoader.h
42 * @brief Declaration of the .3d (UNREAL) importer class.
43 */
44 #ifndef INCLUDED_AI_3D_LOADER_H
45 #define INCLUDED_AI_3D_LOADER_H
46
47 #include "BaseImporter.h"
48 namespace Assimp {
49 namespace Unreal {
50
51 /*
52 0 = Normal one-sided
53 1 = Normal two-sided
54 2 = Translucent two-sided
55 3 = Masked two-sided
56 4 = Modulation blended two-sided
57 8 = Placeholder triangle for weapon positioning (invisible)
58 */
59 enum MeshFlags {
60 MF_NORMAL_OS = 0,
61 MF_NORMAL_TS = 1,
62 MF_NORMAL_TRANS_TS = 2,
63 MF_NORMAL_MASKED_TS = 3,
64 MF_NORMAL_MOD_TS = 4,
65 MF_WEAPON_PLACEHOLDER = 8
66 };
67
68 // a single triangle
69 struct Triangle {
70 uint16_t mVertex[3]; // Vertex indices
71 char mType; // James' Mesh Type
72 char mColor; // Color for flat and Gourand Shaded
73 unsigned char mTex[3][2]; // Texture UV coordinates
74 unsigned char mTextureNum; // Source texture offset
75 char mFlags; // Unreal Mesh Flags (unused)
76
77 unsigned int matIndex;
78 };
79
80 // temporary representation for a material
81 struct TempMat {
TempMatTempMat82 TempMat()
83 : numFaces (0)
84 {}
85
TempMatTempMat86 TempMat(const Triangle& in)
87 : type ((Unreal::MeshFlags)in.mType)
88 , tex (in.mTextureNum)
89 , numFaces (0)
90 {}
91
92 // type of mesh
93 Unreal::MeshFlags type;
94
95 // index of texture
96 unsigned int tex;
97
98 // number of faces using us
99 unsigned int numFaces;
100
101 // for std::find
102 bool operator == (const TempMat& o ) {
103 return (tex == o.tex && type == o.type);
104 }
105 };
106
107 struct Vertex
108 {
109 int32_t X : 11;
110 int32_t Y : 11;
111 int32_t Z : 10;
112 };
113
114 // UNREAL vertex compression
CompressVertex(const aiVector3D & v,uint32_t & out)115 inline void CompressVertex(const aiVector3D& v, uint32_t& out)
116 {
117 union {
118 Vertex n;
119 int32_t t;
120 };
121 n.X = (int32_t)v.x;
122 n.Y = (int32_t)v.y;
123 n.Z = (int32_t)v.z;
124 out = t;
125 }
126
127 // UNREAL vertex decompression
DecompressVertex(aiVector3D & v,int32_t in)128 inline void DecompressVertex(aiVector3D& v, int32_t in)
129 {
130 union {
131 Vertex n;
132 int32_t i;
133 };
134 i = in;
135
136 v.x = (float)n.X;
137 v.y = (float)n.Y;
138 v.z = (float)n.Z;
139 }
140
141 } // end namespace Unreal
142
143 // ---------------------------------------------------------------------------
144 /** @brief Importer class to load UNREAL files (*.3d)
145 */
146 class UnrealImporter : public BaseImporter
147 {
148 public:
149 UnrealImporter();
150 ~UnrealImporter();
151
152
153 public:
154
155 // -------------------------------------------------------------------
156 /** @brief Returns whether we can handle the format of the given file
157 *
158 * See BaseImporter::CanRead() for details.
159 **/
160 bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
161 bool checkSig) const;
162
163 protected:
164
165 // -------------------------------------------------------------------
166 /** @brief Called by Importer::GetExtensionList()
167 *
168 * See BaseImporter::GetExtensionList() for details
169 */
170 void GetExtensionList(std::set<std::string>& extensions);
171
172
173 // -------------------------------------------------------------------
174 /** @brief Setup properties for the importer
175 *
176 * See BaseImporter::SetupProperties() for details
177 */
178 void SetupProperties(const Importer* pImp);
179
180
181 // -------------------------------------------------------------------
182 /** @brief Imports the given file into the given scene structure.
183 *
184 * See BaseImporter::InternReadFile() for details
185 */
186 void InternReadFile( const std::string& pFile, aiScene* pScene,
187 IOSystem* pIOHandler);
188
189 private:
190
191 //! frame to be loaded
192 uint32_t configFrameID;
193
194 //! process surface flags
195 bool configHandleFlags;
196
197 }; // !class UnrealImporter
198
199 } // end of namespace Assimp
200 #endif // AI_UNREALIMPORTER_H_INC
201