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