/src/assimp/code/AssetLib/XGL/XGLLoader.h
Line | Count | Source |
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 XGLLoader.h |
43 | | * @brief Declaration of the .xgl/.zgl |
44 | | */ |
45 | | #ifndef AI_XGLLOADER_H_INCLUDED |
46 | | #define AI_XGLLOADER_H_INCLUDED |
47 | | |
48 | | #include <assimp/BaseImporter.h> |
49 | | #include <assimp/XmlParser.h> |
50 | | #include <assimp/LogAux.h> |
51 | | #include <assimp/light.h> |
52 | | #include <assimp/material.h> |
53 | | #include <assimp/mesh.h> |
54 | | #include <assimp/light.h> |
55 | | #include <assimp/Importer.hpp> |
56 | | #include <assimp/XmlParser.h> |
57 | | |
58 | | #include <map> |
59 | | #include <memory> |
60 | | |
61 | | struct aiNode; |
62 | | |
63 | | namespace Assimp { |
64 | | |
65 | | // --------------------------------------------------------------------------- |
66 | | /** XGL/ZGL importer. |
67 | | * |
68 | | * Spec: http://vizstream.aveva.com/release/vsplatform/XGLSpec.htm |
69 | | */ |
70 | | class XGLImporter : public BaseImporter, public LogFunctions<XGLImporter> { |
71 | | public: |
72 | | /// @brief The class constructor. |
73 | | XGLImporter(); |
74 | | |
75 | | /// @brief The class destructor. |
76 | | ~XGLImporter() override; |
77 | | |
78 | | /// @brief Returns whether the class can handle the format of the given file. |
79 | | /// @see BaseImporter::CanRead() for details. */ |
80 | | bool CanRead(const std::string &pFile, IOSystem *pIOHandler, |
81 | | bool checkSig) const override; |
82 | | |
83 | | protected: |
84 | | void clear(); |
85 | | |
86 | | // ------------------------------------------------------------------- |
87 | | /** Return importer meta information. |
88 | | * See #BaseImporter::GetInfo for the details */ |
89 | | const aiImporterDesc *GetInfo() const override; |
90 | | |
91 | | // ------------------------------------------------------------------- |
92 | | /** Imports the given file into the given scene structure. |
93 | | * See BaseImporter::InternReadFile() for details */ |
94 | | void InternReadFile(const std::string &pFile, aiScene *pScene, |
95 | | IOSystem *pIOHandler) override; |
96 | | |
97 | | private: |
98 | | struct TempScope { |
99 | 0 | TempScope() : light() {} |
100 | | |
101 | 0 | ~TempScope() { |
102 | 0 | for (aiMesh *m : meshes_linear) { |
103 | 0 | delete m; |
104 | 0 | } |
105 | |
|
106 | 0 | for (aiMaterial *m : materials_linear) { |
107 | 0 | delete m; |
108 | 0 | } |
109 | |
|
110 | 0 | delete light; |
111 | 0 | } |
112 | | |
113 | 0 | void dismiss() { |
114 | 0 | light = nullptr; |
115 | 0 | meshes_linear.clear(); |
116 | 0 | materials_linear.clear(); |
117 | 0 | meshes.clear(); |
118 | 0 | materials.clear(); |
119 | 0 | } |
120 | | |
121 | | std::multimap<unsigned int, aiMesh *> meshes; |
122 | | std::map<unsigned int, aiMaterial *> materials; |
123 | | |
124 | | std::vector<aiMesh *> meshes_linear; |
125 | | std::vector<aiMaterial *> materials_linear; |
126 | | |
127 | | aiLight *light; |
128 | | }; |
129 | | |
130 | | struct SortMeshByMaterialId { |
131 | | SortMeshByMaterialId(const TempScope &scope) : |
132 | 0 | scope(scope) { |
133 | | // empty |
134 | 0 | } |
135 | 0 | bool operator()(unsigned int a, unsigned int b) const { |
136 | 0 | return scope.meshes_linear[a]->mMaterialIndex < scope.meshes_linear[b]->mMaterialIndex; |
137 | 0 | }; |
138 | | |
139 | | const TempScope &scope; |
140 | | }; |
141 | | |
142 | | struct TempMesh { |
143 | | std::map<unsigned int, aiVector3D> points; |
144 | | std::map<unsigned int, aiVector3D> normals; |
145 | | std::map<unsigned int, aiVector2D> uvs; |
146 | | }; |
147 | | |
148 | | struct TempMaterialMesh { |
149 | 0 | TempMaterialMesh() : pflags(), matid() { |
150 | | // empty |
151 | 0 | } |
152 | | |
153 | | std::vector<aiVector3D> positions, normals; |
154 | | std::vector<aiVector2D> uvs; |
155 | | |
156 | | std::vector<unsigned int> vcounts; |
157 | | unsigned int pflags; |
158 | | unsigned int matid; |
159 | | }; |
160 | | |
161 | | struct TempFace { |
162 | 0 | TempFace() : has_uv(), has_normal() { |
163 | | // empty |
164 | 0 | } |
165 | | |
166 | | aiVector3D pos; |
167 | | aiVector3D normal; |
168 | | aiVector2D uv; |
169 | | bool has_uv; |
170 | | bool has_normal; |
171 | | }; |
172 | | |
173 | | private: |
174 | | void Cleanup(); |
175 | | std::string GetElementName(); |
176 | | bool ReadElement(); |
177 | | bool ReadElementUpToClosing(const char *closetag); |
178 | | bool SkipToText(); |
179 | | unsigned int ReadIDAttr(XmlNode &node); |
180 | | void ReadWorld(XmlNode &node, TempScope &scope); |
181 | | void ReadLighting(XmlNode &node, TempScope &scope); |
182 | | aiLight *ReadDirectionalLight(XmlNode &node); |
183 | | aiNode *ReadObject(XmlNode &node, TempScope &scope); |
184 | | bool ReadMesh(XmlNode &node, TempScope &scope); |
185 | | void AppendOutputMeshes(std::map<unsigned int, TempMaterialMesh> bymat, TempScope &scope, const unsigned int mesh_id); |
186 | | unsigned int ReadVertices(XmlNode &child, TempMesh t, TempFace *tf, bool *has, unsigned int mid, TempScope &scope); |
187 | | unsigned int ReadMaterial(XmlNode &node, TempScope &scope); |
188 | | aiVector2D ReadVec2(XmlNode &node); |
189 | | aiVector3D ReadVec3(XmlNode &node); |
190 | | aiColor3D ReadCol3(XmlNode &node); |
191 | | aiMatrix4x4 ReadTrafo(XmlNode &node); |
192 | | unsigned int ReadIndexFromText(XmlNode &node); |
193 | | float ReadFloat(XmlNode &node); |
194 | | aiMesh *ToOutputMesh(const TempMaterialMesh &m); |
195 | | void ReadFaceVertex(XmlNode &node, const TempMesh &t, TempFace &out); |
196 | | unsigned int ResolveMaterialRef(XmlNode &node, TempScope &scope); |
197 | | |
198 | | private: |
199 | | XmlParser *mXmlParser; |
200 | | aiScene *m_scene; |
201 | | }; |
202 | | |
203 | | } // end of namespace Assimp |
204 | | |
205 | | #endif // AI_IRRMESHIMPORTER_H_INC |