1 
2 /*
3 Open Asset Import Library (assimp)
4 ----------------------------------------------------------------------
5 
6 Copyright (c) 2006-2015, assimp team
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  3DSLoader.h
43  *  @brief 3DS File format loader
44  */
45 #ifndef AI_3DSIMPORTER_H_INC
46 #define AI_3DSIMPORTER_H_INC
47 
48 #include "BaseImporter.h"
49 #include "../include/assimp/types.h"
50 
51 #ifndef ASSIMP_BUILD_NO_3DS_IMPORTER
52 
53 #include "3DSHelper.h"
54 #include "StreamReader.h"
55 
56 struct aiNode;
57 
58 namespace Assimp    {
59 
60 
61 using namespace D3DS;
62 
63 // ---------------------------------------------------------------------------------
64 /** Importer class for 3D Studio r3 and r4 3DS files
65  */
66 class Discreet3DSImporter : public BaseImporter
67 {
68 public:
69 
70     Discreet3DSImporter();
71     ~Discreet3DSImporter();
72 
73 public:
74 
75     // -------------------------------------------------------------------
76     /** Returns whether the class can handle the format of the given file.
77      * See BaseImporter::CanRead() for details.
78      */
79     bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
80         bool checkSig) const;
81 
82     // -------------------------------------------------------------------
83     /** Called prior to ReadFile().
84      * The function is a request to the importer to update its configuration
85      * basing on the Importer's configuration property list.
86      */
87     void SetupProperties(const Importer* pImp);
88 
89 protected:
90 
91     // -------------------------------------------------------------------
92     /** Return importer meta information.
93      * See #BaseImporter::GetInfo for the details
94      */
95     const aiImporterDesc* GetInfo () const;
96 
97     // -------------------------------------------------------------------
98     /** Imports the given file into the given scene structure.
99      * See BaseImporter::InternReadFile() for details
100      */
101     void InternReadFile( const std::string& pFile, aiScene* pScene,
102         IOSystem* pIOHandler);
103 
104     // -------------------------------------------------------------------
105     /** Converts a temporary material to the outer representation
106      */
107     void ConvertMaterial(D3DS::Material& p_cMat,
108         aiMaterial& p_pcOut);
109 
110     // -------------------------------------------------------------------
111     /** Read a chunk
112      *
113      *  @param pcOut Receives the current chunk
114      */
115     void ReadChunk(Discreet3DS::Chunk* pcOut);
116 
117     // -------------------------------------------------------------------
118     /** Parse a percentage chunk. mCurrent will point to the next
119     * chunk behind afterwards. If no percentage chunk is found
120     * QNAN is returned.
121     */
122     float ParsePercentageChunk();
123 
124     // -------------------------------------------------------------------
125     /** Parse a color chunk. mCurrent will point to the next
126     * chunk behind afterwards. If no color chunk is found
127     * QNAN is returned in all members.
128     */
129     void ParseColorChunk(aiColor3D* p_pcOut,
130         bool p_bAcceptPercent = true);
131 
132 
133     // -------------------------------------------------------------------
134     /** Skip a chunk in the file
135     */
136     void SkipChunk();
137 
138     // -------------------------------------------------------------------
139     /** Generate the nodegraph
140     */
141     void GenerateNodeGraph(aiScene* pcOut);
142 
143     // -------------------------------------------------------------------
144     /** Parse a main top-level chunk in the file
145     */
146     void ParseMainChunk();
147 
148     // -------------------------------------------------------------------
149     /** Parse a top-level chunk in the file
150     */
151     void ParseChunk(const char* name, unsigned int num);
152 
153     // -------------------------------------------------------------------
154     /** Parse a top-level editor chunk in the file
155     */
156     void ParseEditorChunk();
157 
158     // -------------------------------------------------------------------
159     /** Parse a top-level object chunk in the file
160     */
161     void ParseObjectChunk();
162 
163     // -------------------------------------------------------------------
164     /** Parse a material chunk in the file
165     */
166     void ParseMaterialChunk();
167 
168     // -------------------------------------------------------------------
169     /** Parse a mesh chunk in the file
170     */
171     void ParseMeshChunk();
172 
173     // -------------------------------------------------------------------
174     /** Parse a light chunk in the file
175     */
176     void ParseLightChunk();
177 
178     // -------------------------------------------------------------------
179     /** Parse a camera chunk in the file
180     */
181     void ParseCameraChunk();
182 
183     // -------------------------------------------------------------------
184     /** Parse a face list chunk in the file
185     */
186     void ParseFaceChunk();
187 
188     // -------------------------------------------------------------------
189     /** Parse a keyframe chunk in the file
190     */
191     void ParseKeyframeChunk();
192 
193     // -------------------------------------------------------------------
194     /** Parse a hierarchy chunk in the file
195     */
196     void ParseHierarchyChunk(uint16_t parent);
197 
198     // -------------------------------------------------------------------
199     /** Parse a texture chunk in the file
200     */
201     void ParseTextureChunk(D3DS::Texture* pcOut);
202 
203     // -------------------------------------------------------------------
204     /** Convert the meshes in the file
205     */
206     void ConvertMeshes(aiScene* pcOut);
207 
208     // -------------------------------------------------------------------
209     /** Replace the default material in the scene
210     */
211     void ReplaceDefaultMaterial();
212 
213     // -------------------------------------------------------------------
214     /** Convert the whole scene
215     */
216     void ConvertScene(aiScene* pcOut);
217 
218     // -------------------------------------------------------------------
219     /** generate unique vertices for a mesh
220     */
221     void MakeUnique(D3DS::Mesh& sMesh);
222 
223     // -------------------------------------------------------------------
224     /** Add a node to the node graph
225     */
226     void AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,D3DS::Node* pcIn,
227         aiMatrix4x4& absTrafo);
228 
229     // -------------------------------------------------------------------
230     /** Search for a node in the graph.
231     * Called recursively
232     */
233     void InverseNodeSearch(D3DS::Node* pcNode,D3DS::Node* pcCurrent);
234 
235     // -------------------------------------------------------------------
236     /** Apply the master scaling factor to the mesh
237     */
238     void ApplyMasterScale(aiScene* pScene);
239 
240     // -------------------------------------------------------------------
241     /** Clamp all indices in the file to a valid range
242     */
243     void CheckIndices(D3DS::Mesh& sMesh);
244 
245     // -------------------------------------------------------------------
246     /** Skip the TCB info in a track key
247     */
248     void SkipTCBInfo();
249 
250 protected:
251 
252     /** Stream to read from */
253     StreamReaderLE* stream;
254 
255     /** Last touched node index */
256     short mLastNodeIndex;
257 
258     /** Current node, root node */
259     D3DS::Node* mCurrentNode, *mRootNode;
260 
261     /** Scene under construction */
262     D3DS::Scene* mScene;
263 
264     /** Ambient base color of the scene */
265     aiColor3D mClrAmbient;
266 
267     /** Master scaling factor of the scene */
268     float mMasterScale;
269 
270     /** Path to the background image of the scene */
271     std::string mBackgroundImage;
272     bool bHasBG;
273 
274     /** true if PRJ file */
275     bool bIsPrj;
276 };
277 
278 } // end of namespace Assimp
279 
280 #endif // !! ASSIMP_BUILD_NO_3DS_IMPORTER
281 
282 #endif // AI_3DSIMPORTER_H_INC
283