1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2017, assimp team
6
7All rights reserved.
8
9Redistribution and use of this software in source and binary forms,
10with or without modification, are permitted provided that the
11following 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
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39----------------------------------------------------------------------
40*/
41
42
43/** @file IRRLoader.h
44 * @brief Declaration of the .irrMesh (Irrlight Engine Mesh Format)
45 * importer class.
46 */
47#ifndef AI_IRRLOADER_H_INCLUDED
48#define AI_IRRLOADER_H_INCLUDED
49
50#include "IRRShared.h"
51#include <assimp/SceneCombiner.h>
52#include "Importer.h"
53#include "StringUtils.h"
54#include <assimp/anim.h>
55
56namespace Assimp {
57
58
59// ---------------------------------------------------------------------------
60/** Irr importer class.
61 *
62 * Irr is the native scene file format of the Irrlight engine and its editor
63 * irrEdit. As IrrEdit itself is capable of importing quite many file formats,
64 * it might be a good file format for data exchange.
65 */
66class IRRImporter : public BaseImporter, public IrrlichtBase
67{
68public:
69 IRRImporter();
70 ~IRRImporter();
71
72
73public:
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
82protected:
83
84 // -------------------------------------------------------------------
85 /**
86 */
87 const aiImporterDesc* GetInfo () const;
88
89 // -------------------------------------------------------------------
90 /**
91 */
92 void InternReadFile( const std::string& pFile, aiScene* pScene,
93 IOSystem* pIOHandler);
94
95 // -------------------------------------------------------------------
96 /**
97 */
98 void SetupProperties(const Importer* pImp);
99
100private:
101
102 /** Data structure for a scenegraph node animator
103 */
104 struct Animator
105 {
106 // Type of the animator
107 enum AT
108 {
109 UNKNOWN = 0x0,
110 ROTATION = 0x1,
111 FLY_CIRCLE = 0x2,
112 FLY_STRAIGHT = 0x3,
113 FOLLOW_SPLINE = 0x4,
114 OTHER = 0x5
115
116 } type;
117
118 explicit Animator(AT t = UNKNOWN)
119 : type (t)
120 , speed ( ai_real( 0.001 ) )
121 , direction ( ai_real( 0.0 ), ai_real( 1.0 ), ai_real( 0.0 ) )
122 , circleRadius ( ai_real( 1.0) )
123 , tightness ( ai_real( 0.5 ) )
124 , loop (true)
125 , timeForWay (100)
126 {
127 }
128
129
130 // common parameters
131 ai_real speed;
132 aiVector3D direction;
133
134 // FLY_CIRCLE
135 aiVector3D circleCenter;
136 ai_real circleRadius;
137
138 // FOLLOW_SPLINE
139 ai_real tightness;
140 std::vector<aiVectorKey> splineKeys;
141
142 // ROTATION (angles given in direction)
143
144 // FLY STRAIGHT
145 // circleCenter = start, direction = end
146 bool loop;
147 int timeForWay;
148 };
149
150 /** Data structure for a scenegraph node in an IRR file
151 */
152 struct Node
153 {
154 // Type of the node
155 enum ET
156 {
157 LIGHT,
158 CUBE,
159 MESH,
160 SKYBOX,
161 DUMMY,
162 CAMERA,
163 TERRAIN,
164 SPHERE,
165 ANIMMESH
166 } type;
167
168 explicit Node(ET t)
169 : type (t)
170 , scaling (1.0,1.0,1.0) // assume uniform scaling by default
171 , parent()
172 , framesPerSecond (0.0)
173 , id()
174 , sphereRadius (1.0)
175 , spherePolyCountX (100)
176 , spherePolyCountY (100)
177 {
178
179 // Generate a default name for the node
180 char buffer[128];
181 static int cnt;
182 ai_snprintf(buffer, 128, "IrrNode_%i",cnt++);
183 name = std::string(buffer);
184
185 // reserve space for up to 5 materials
186 materials.reserve(5);
187
188 // reserve space for up to 5 children
189 children.reserve(5);
190 }
191
192 // Transformation of the node
193 aiVector3D position, rotation, scaling;
194
195 // Name of the node
196 std::string name;
197
198 // List of all child nodes
199 std::vector<Node*> children;
200
201 // Parent node
202 Node* parent;
203
204 // Animated meshes: frames per second
205 // 0.f if not specified
206 ai_real framesPerSecond;
207
208 // Meshes: path to the mesh to be loaded
209 std::string meshPath;
210 unsigned int id;
211
212 // Meshes: List of materials to be assigned
213 // along with their corresponding material flags
214 std::vector< std::pair<aiMaterial*, unsigned int> > materials;
215
216 // Spheres: radius of the sphere to be generates
217 ai_real sphereRadius;
218
219 // Spheres: Number of polygons in the x,y direction
220 unsigned int spherePolyCountX,spherePolyCountY;
221
222 // List of all animators assigned to the node
223 std::list<Animator> animators;
224 };
225
226 /** Data structure for a vertex in an IRR skybox
227 */
228 struct SkyboxVertex
229 {
230 SkyboxVertex()
231 {}
232
233 //! Construction from single vertex components
234 SkyboxVertex(ai_real px, ai_real py, ai_real pz,
235 ai_real nx, ai_real ny, ai_real nz,
236 ai_real uvx, ai_real uvy)
237
238 : position (px,py,pz)
239 , normal (nx,ny,nz)
240 , uv (uvx,uvy,0.0)
241 {}
242
243 aiVector3D position, normal, uv;
244 };
245
246
247 // -------------------------------------------------------------------
248 /** Fill the scenegraph recursively
249 */
250 void GenerateGraph(Node* root,aiNode* rootOut ,aiScene* scene,
251 BatchLoader& batch,
252 std::vector<aiMesh*>& meshes,
253 std::vector<aiNodeAnim*>& anims,
254 std::vector<AttachmentInfo>& attach,
255 std::vector<aiMaterial*>& materials,
256 unsigned int& defaultMatIdx);
257
258
259 // -------------------------------------------------------------------
260 /** Generate a mesh that consists of just a single quad
261 */
262 aiMesh* BuildSingleQuadMesh(const SkyboxVertex& v1,
263 const SkyboxVertex& v2,
264 const SkyboxVertex& v3,
265 const SkyboxVertex& v4);
266
267
268 // -------------------------------------------------------------------
269 /** Build a skybox
270 *
271 * @param meshes Receives 6 output meshes
272 * @param materials The last 6 materials are assigned to the newly
273 * created meshes. The names of the materials are adjusted.
274 */
275 void BuildSkybox(std::vector<aiMesh*>& meshes,
276 std::vector<aiMaterial*> materials);
277
278
279 // -------------------------------------------------------------------
280 /** Copy a material for a mesh to the output material list
281 *
282 * @param materials Receives an output material
283 * @param inmaterials List of input materials
284 * @param defMatIdx Default material index - UINT_MAX if not present
285 * @param mesh Mesh to work on
286 */
287 void CopyMaterial(std::vector<aiMaterial*>& materials,
288 std::vector< std::pair<aiMaterial*, unsigned int> >& inmaterials,
289 unsigned int& defMatIdx,
290 aiMesh* mesh);
291
292
293 // -------------------------------------------------------------------
294 /** Compute animations for a specific node
295 *
296 * @param root Node to be processed
297 * @param anims The list of output animations
298 */
299 void ComputeAnimations(Node* root, aiNode* real,
300 std::vector<aiNodeAnim*>& anims);
301
302
303private:
304
305 /** Configuration option: desired output FPS */
306 double fps;
307
308 /** Configuration option: speed flag was set? */
309 bool configSpeedFlag;
310};
311
312} // end of namespace Assimp
313
314#endif // AI_IRRIMPORTER_H_INC
315