1 | |
2 | /* |
3 | Open Asset Import Library (assimp) |
4 | ---------------------------------------------------------------------- |
5 | |
6 | Copyright (c) 2006-2017, assimp team |
7 | |
8 | All rights reserved. |
9 | |
10 | Redistribution and use of this software in source and binary forms, |
11 | with or without modification, are permitted provided that the |
12 | following conditions are met: |
13 | |
14 | * Redistributions of source code must retain the above |
15 | copyright notice, this list of conditions and the |
16 | following disclaimer. |
17 | |
18 | * Redistributions in binary form must reproduce the above |
19 | copyright notice, this list of conditions and the |
20 | following disclaimer in the documentation and/or other |
21 | materials provided with the distribution. |
22 | |
23 | * Neither the name of the assimp team, nor the names of its |
24 | contributors may be used to endorse or promote products |
25 | derived from this software without specific prior |
26 | written permission of the assimp team. |
27 | |
28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
39 | |
40 | ---------------------------------------------------------------------- |
41 | */ |
42 | |
43 | /** @file 3DSLoader.h |
44 | * @brief 3DS File format loader |
45 | */ |
46 | #ifndef AI_3DSIMPORTER_H_INC |
47 | #define AI_3DSIMPORTER_H_INC |
48 | |
49 | #include "BaseImporter.h" |
50 | #include <assimp/types.h> |
51 | |
52 | #ifndef ASSIMP_BUILD_NO_3DS_IMPORTER |
53 | |
54 | #include "3DSHelper.h" |
55 | #include "StreamReader.h" |
56 | |
57 | struct aiNode; |
58 | |
59 | namespace Assimp { |
60 | |
61 | |
62 | using namespace D3DS; |
63 | |
64 | // --------------------------------------------------------------------------------- |
65 | /** Importer class for 3D Studio r3 and r4 3DS files |
66 | */ |
67 | class Discreet3DSImporter : public BaseImporter |
68 | { |
69 | public: |
70 | |
71 | Discreet3DSImporter(); |
72 | ~Discreet3DSImporter(); |
73 | |
74 | public: |
75 | |
76 | // ------------------------------------------------------------------- |
77 | /** Returns whether the class can handle the format of the given file. |
78 | * See BaseImporter::CanRead() for details. |
79 | */ |
80 | bool CanRead( const std::string& pFile, IOSystem* pIOHandler, |
81 | bool checkSig) const; |
82 | |
83 | // ------------------------------------------------------------------- |
84 | /** Called prior to ReadFile(). |
85 | * The function is a request to the importer to update its configuration |
86 | * basing on the Importer's configuration property list. |
87 | */ |
88 | void SetupProperties(const Importer* pImp); |
89 | |
90 | protected: |
91 | |
92 | // ------------------------------------------------------------------- |
93 | /** Return importer meta information. |
94 | * See #BaseImporter::GetInfo for the details |
95 | */ |
96 | const aiImporterDesc* GetInfo () const; |
97 | |
98 | // ------------------------------------------------------------------- |
99 | /** Imports the given file into the given scene structure. |
100 | * See BaseImporter::InternReadFile() for details |
101 | */ |
102 | void InternReadFile( const std::string& pFile, aiScene* pScene, |
103 | IOSystem* pIOHandler); |
104 | |
105 | // ------------------------------------------------------------------- |
106 | /** Converts a temporary material to the outer representation |
107 | */ |
108 | void ConvertMaterial(D3DS::Material& p_cMat, |
109 | aiMaterial& p_pcOut); |
110 | |
111 | // ------------------------------------------------------------------- |
112 | /** Read a chunk |
113 | * |
114 | * @param pcOut Receives the current chunk |
115 | */ |
116 | void ReadChunk(Discreet3DS::Chunk* pcOut); |
117 | |
118 | // ------------------------------------------------------------------- |
119 | /** Parse a percentage chunk. mCurrent will point to the next |
120 | * chunk behind afterwards. If no percentage chunk is found |
121 | * QNAN is returned. |
122 | */ |
123 | ai_real ParsePercentageChunk(); |
124 | |
125 | // ------------------------------------------------------------------- |
126 | /** Parse a color chunk. mCurrent will point to the next |
127 | * chunk behind afterwards. If no color chunk is found |
128 | * QNAN is returned in all members. |
129 | */ |
130 | void ParseColorChunk(aiColor3D* p_pcOut, |
131 | bool p_bAcceptPercent = true); |
132 | |
133 | |
134 | // ------------------------------------------------------------------- |
135 | /** Skip a chunk in the file |
136 | */ |
137 | void SkipChunk(); |
138 | |
139 | // ------------------------------------------------------------------- |
140 | /** Generate the nodegraph |
141 | */ |
142 | void GenerateNodeGraph(aiScene* pcOut); |
143 | |
144 | // ------------------------------------------------------------------- |
145 | /** Parse a main top-level chunk in the file |
146 | */ |
147 | void ParseMainChunk(); |
148 | |
149 | // ------------------------------------------------------------------- |
150 | /** Parse a top-level chunk in the file |
151 | */ |
152 | void ParseChunk(const char* name, unsigned int num); |
153 | |
154 | // ------------------------------------------------------------------- |
155 | /** Parse a top-level editor chunk in the file |
156 | */ |
157 | void ParseEditorChunk(); |
158 | |
159 | // ------------------------------------------------------------------- |
160 | /** Parse a top-level object chunk in the file |
161 | */ |
162 | void ParseObjectChunk(); |
163 | |
164 | // ------------------------------------------------------------------- |
165 | /** Parse a material chunk in the file |
166 | */ |
167 | void ParseMaterialChunk(); |
168 | |
169 | // ------------------------------------------------------------------- |
170 | /** Parse a mesh chunk in the file |
171 | */ |
172 | void ParseMeshChunk(); |
173 | |
174 | // ------------------------------------------------------------------- |
175 | /** Parse a light chunk in the file |
176 | */ |
177 | void ParseLightChunk(); |
178 | |
179 | // ------------------------------------------------------------------- |
180 | /** Parse a camera chunk in the file |
181 | */ |
182 | void ParseCameraChunk(); |
183 | |
184 | // ------------------------------------------------------------------- |
185 | /** Parse a face list chunk in the file |
186 | */ |
187 | void ParseFaceChunk(); |
188 | |
189 | // ------------------------------------------------------------------- |
190 | /** Parse a keyframe chunk in the file |
191 | */ |
192 | void ParseKeyframeChunk(); |
193 | |
194 | // ------------------------------------------------------------------- |
195 | /** Parse a hierarchy chunk in the file |
196 | */ |
197 | void ParseHierarchyChunk(uint16_t parent); |
198 | |
199 | // ------------------------------------------------------------------- |
200 | /** Parse a texture chunk in the file |
201 | */ |
202 | void ParseTextureChunk(D3DS::Texture* pcOut); |
203 | |
204 | // ------------------------------------------------------------------- |
205 | /** Convert the meshes in the file |
206 | */ |
207 | void ConvertMeshes(aiScene* pcOut); |
208 | |
209 | // ------------------------------------------------------------------- |
210 | /** Replace the default material in the scene |
211 | */ |
212 | void ReplaceDefaultMaterial(); |
213 | |
214 | // ------------------------------------------------------------------- |
215 | /** Convert the whole scene |
216 | */ |
217 | void ConvertScene(aiScene* pcOut); |
218 | |
219 | // ------------------------------------------------------------------- |
220 | /** generate unique vertices for a mesh |
221 | */ |
222 | void MakeUnique(D3DS::Mesh& sMesh); |
223 | |
224 | // ------------------------------------------------------------------- |
225 | /** Add a node to the node graph |
226 | */ |
227 | void AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,D3DS::Node* pcIn, |
228 | aiMatrix4x4& absTrafo); |
229 | |
230 | // ------------------------------------------------------------------- |
231 | /** Search for a node in the graph. |
232 | * Called recursively |
233 | */ |
234 | void InverseNodeSearch(D3DS::Node* pcNode,D3DS::Node* pcCurrent); |
235 | |
236 | // ------------------------------------------------------------------- |
237 | /** Apply the master scaling factor to the mesh |
238 | */ |
239 | void ApplyMasterScale(aiScene* pScene); |
240 | |
241 | // ------------------------------------------------------------------- |
242 | /** Clamp all indices in the file to a valid range |
243 | */ |
244 | void CheckIndices(D3DS::Mesh& sMesh); |
245 | |
246 | // ------------------------------------------------------------------- |
247 | /** Skip the TCB info in a track key |
248 | */ |
249 | void SkipTCBInfo(); |
250 | |
251 | protected: |
252 | |
253 | /** Stream to read from */ |
254 | StreamReaderLE* stream; |
255 | |
256 | /** Last touched node index */ |
257 | short mLastNodeIndex; |
258 | |
259 | /** Current node, root node */ |
260 | D3DS::Node* mCurrentNode, *mRootNode; |
261 | |
262 | /** Scene under construction */ |
263 | D3DS::Scene* mScene; |
264 | |
265 | /** Ambient base color of the scene */ |
266 | aiColor3D mClrAmbient; |
267 | |
268 | /** Master scaling factor of the scene */ |
269 | ai_real mMasterScale; |
270 | |
271 | /** Path to the background image of the scene */ |
272 | std::string mBackgroundImage; |
273 | bool bHasBG; |
274 | |
275 | /** true if PRJ file */ |
276 | bool bIsPrj; |
277 | }; |
278 | |
279 | } // end of namespace Assimp |
280 | |
281 | #endif // !! ASSIMP_BUILD_NO_3DS_IMPORTER |
282 | |
283 | #endif // AI_3DSIMPORTER_H_INC |
284 | |