vrshoot

view libs/assimp/3DSLoader.h @ 0:b2f14e535253

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