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