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