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/** @file ACLoader.h
43 * @brief Declaration of the .ac importer class.
44 */
45#ifndef AI_AC3DLOADER_H_INCLUDED
46#define AI_AC3DLOADER_H_INCLUDED
47
48#include <vector>
49
50#include "BaseImporter.h"
51#include <assimp/types.h>
52
53struct aiNode;
54struct aiMesh;
55struct aiMaterial;
56struct aiLight;
57
58
59namespace Assimp {
60
61// ---------------------------------------------------------------------------
62/** AC3D (*.ac) importer class
63*/
64class AC3DImporter : public BaseImporter
65{
66public:
67 AC3DImporter();
68 ~AC3DImporter();
69
70
71
72 // Represents an AC3D material
73 struct Material
74 {
75 Material()
76 : rgb (0.6f,0.6f,0.6f)
77 , spec (1.f,1.f,1.f)
78 , shin (0.f)
79 , trans (0.f)
80 {}
81
82 // base color of the material
83 aiColor3D rgb;
84
85 // ambient color of the material
86 aiColor3D amb;
87
88 // emissive color of the material
89 aiColor3D emis;
90
91 // specular color of the material
92 aiColor3D spec;
93
94 // shininess exponent
95 float shin;
96
97 // transparency. 0 == opaque
98 float trans;
99
100 // name of the material. optional.
101 std::string name;
102 };
103
104 // Represents an AC3D surface
105 struct Surface
106 {
107 Surface()
108 : mat (0)
109 , flags (0)
110 {}
111
112 unsigned int mat,flags;
113
114 typedef std::pair<unsigned int, aiVector2D > SurfaceEntry;
115 std::vector< SurfaceEntry > entries;
116 };
117
118 // Represents an AC3D object
119 struct Object
120 {
121 Object()
122 : type (World)
123 , name( "" )
124 , children()
125 , texture( "" )
126 , texRepeat( 1.f, 1.f )
127 , texOffset( 0.0f, 0.0f )
128 , rotation()
129 , translation()
130 , vertices()
131 , surfaces()
132 , numRefs (0)
133 , subDiv (0)
134 , crease()
135 {}
136
137 // Type description
138 enum Type
139 {
140 World = 0x0,
141 Poly = 0x1,
142 Group = 0x2,
143 Light = 0x4
144 } type;
145
146 // name of the object
147 std::string name;
148
149 // object children
150 std::vector<Object> children;
151
152 // texture to be assigned to all surfaces of the object
153 std::string texture;
154
155 // texture repat factors (scaling for all coordinates)
156 aiVector2D texRepeat, texOffset;
157
158 // rotation matrix
159 aiMatrix3x3 rotation;
160
161 // translation vector
162 aiVector3D translation;
163
164 // vertices
165 std::vector<aiVector3D> vertices;
166
167 // surfaces
168 std::vector<Surface> surfaces;
169
170 // number of indices (= num verts in verbose format)
171 unsigned int numRefs;
172
173 // number of subdivisions to be performed on the
174 // imported data
175 unsigned int subDiv;
176
177 // max angle limit for smoothing
178 float crease;
179 };
180
181
182public:
183
184 // -------------------------------------------------------------------
185 /** Returns whether the class can handle the format of the given file.
186 * See BaseImporter::CanRead() for details.
187 */
188 bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
189 bool checkSig) const;
190
191protected:
192
193 // -------------------------------------------------------------------
194 /** Return importer meta information.
195 * See #BaseImporter::GetInfo for the details */
196 const aiImporterDesc* GetInfo () const;
197
198 // -------------------------------------------------------------------
199 /** Imports the given file into the given scene structure.
200 * See BaseImporter::InternReadFile() for details*/
201 void InternReadFile( const std::string& pFile, aiScene* pScene,
202 IOSystem* pIOHandler);
203
204 // -------------------------------------------------------------------
205 /** Called prior to ReadFile().
206 * The function is a request to the importer to update its configuration
207 * basing on the Importer's configuration property list.*/
208 void SetupProperties(const Importer* pImp);
209
210private:
211
212 // -------------------------------------------------------------------
213 /** Get the next line from the file.
214 * @return false if the end of the file was reached*/
215 bool GetNextLine();
216
217 // -------------------------------------------------------------------
218 /** Load the object section. This method is called recursively to
219 * load subobjects, the method returns after a 'kids 0' was
220 * encountered.
221 * @objects List of output objects*/
222 void LoadObjectSection(std::vector<Object>& objects);
223
224 // -------------------------------------------------------------------
225 /** Convert all objects into meshes and nodes.
226 * @param object Current object to work on
227 * @param meshes Pointer to the list of output meshes
228 * @param outMaterials List of output materials
229 * @param materials Material list
230 * @param Scenegraph node for the object */
231 aiNode* ConvertObjectSection(Object& object,
232 std::vector<aiMesh*>& meshes,
233 std::vector<aiMaterial*>& outMaterials,
234 const std::vector<Material>& materials,
235 aiNode* parent = NULL);
236
237 // -------------------------------------------------------------------
238 /** Convert a material
239 * @param object Current object
240 * @param matSrc Source material description
241 * @param matDest Destination material to be filled */
242 void ConvertMaterial(const Object& object,
243 const Material& matSrc,
244 aiMaterial& matDest);
245
246private:
247
248
249 // points to the next data line
250 const char* buffer;
251
252 // Configuration option: if enabled, up to two meshes
253 // are generated per material: those faces who have
254 // their bf cull flags set are separated.
255 bool configSplitBFCull;
256
257 // Configuration switch: subdivision surfaces are only
258 // evaluated if the value is true.
259 bool configEvalSubdivision;
260
261 // counts how many objects we have in the tree.
262 // basing on this information we can find a
263 // good estimate how many meshes we'll have in the final scene.
264 unsigned int mNumMeshes;
265
266 // current list of light sources
267 std::vector<aiLight*>* mLights;
268
269 // name counters
270 unsigned int lights, groups, polys, worlds;
271};
272
273} // end of namespace Assimp
274
275#endif // AI_AC3DIMPORTER_H_INC
276