vrshoot

view libs/assimp/XGLLoader.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 /** @file XGLLoader.h
42 * @brief Declaration of the .xgl/.zgl
43 */
44 #ifndef AI_XGLLOADER_H_INCLUDED
45 #define AI_XGLLOADER_H_INCLUDED
47 #include "BaseImporter.h"
48 #include "irrXMLWrapper.h"
49 #include "LogAux.h"
51 namespace Assimp {
53 // ---------------------------------------------------------------------------
54 /** XGL/ZGL importer.
55 *
56 * Spec: http://vizstream.aveva.com/release/vsplatform/XGLSpec.htm
57 */
58 class XGLImporter : public BaseImporter, public LogFunctions<XGLImporter>
59 {
60 public:
62 XGLImporter();
63 ~XGLImporter();
66 public:
68 // -------------------------------------------------------------------
69 /** Returns whether the class can handle the format of the given file.
70 * See BaseImporter::CanRead() for details. */
71 bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
72 bool checkSig) const;
74 protected:
76 // -------------------------------------------------------------------
77 /** Return importer meta information.
78 * See #BaseImporter::GetInfo for the details */
79 const aiImporterDesc* GetInfo () const;
81 // -------------------------------------------------------------------
82 /** Imports the given file into the given scene structure.
83 * See BaseImporter::InternReadFile() for details */
84 void InternReadFile( const std::string& pFile, aiScene* pScene,
85 IOSystem* pIOHandler);
87 private:
89 struct TempScope
90 {
91 TempScope()
92 : light()
93 {}
95 ~TempScope()
96 {
97 BOOST_FOREACH(aiMesh* m, meshes_linear) {
98 delete m;
99 }
101 BOOST_FOREACH(aiMaterial* m, materials_linear) {
102 delete m;
103 }
105 delete light;
106 }
108 void dismiss() {
109 light = NULL;
110 meshes_linear.clear();
111 materials_linear.clear();
112 meshes.clear();
113 materials.clear();
114 }
116 std::multimap<unsigned int, aiMesh*> meshes;
117 std::map<unsigned int, aiMaterial*> materials;
119 std::vector<aiMesh*> meshes_linear;
120 std::vector<aiMaterial*> materials_linear;
122 aiLight* light;
123 };
125 struct TempMesh
126 {
127 std::map<unsigned int, aiVector3D> points;
128 std::map<unsigned int, aiVector3D> normals;
129 std::map<unsigned int, aiVector2D> uvs;
130 };
132 struct TempMaterialMesh
133 {
134 TempMaterialMesh()
135 : pflags()
136 , matid()
137 {}
139 std::vector<aiVector3D> positions, normals;
140 std::vector<aiVector2D> uvs;
142 std::vector<unsigned int> vcounts;
143 unsigned int pflags;
144 unsigned int matid;
145 };
147 struct TempFace
148 {
149 TempFace()
150 : has_uv()
151 , has_normal()
152 {}
154 aiVector3D pos;
155 aiVector3D normal;
156 aiVector2D uv;
157 bool has_uv;
158 bool has_normal;
159 };
161 private:
163 void Cleanup();
165 std::string GetElementName();
166 bool ReadElement();
167 bool ReadElementUpToClosing(const char* closetag);
168 bool SkipToText();
169 unsigned int ReadIDAttr();
171 void ReadWorld(TempScope& scope);
172 void ReadLighting(TempScope& scope);
173 aiLight* ReadDirectionalLight();
174 aiNode* ReadObject(TempScope& scope,bool skipFirst = false,const char* closetag = "object");
175 bool ReadMesh(TempScope& scope);
176 void ReadMaterial(TempScope& scope);
177 aiVector2D ReadVec2();
178 aiVector3D ReadVec3();
179 aiColor3D ReadCol3();
180 aiMatrix4x4 ReadTrafo();
181 unsigned int ReadIndexFromText();
182 float ReadFloat();
184 aiMesh* ToOutputMesh(const TempMaterialMesh& m);
185 void ReadFaceVertex(const TempMesh& t, TempFace& out);
186 unsigned int ResolveMaterialRef(TempScope& scope);
188 private:
191 private:
193 irr::io::IrrXMLReader* reader;
194 aiScene* scene;
195 };
197 } // end of namespace Assimp
199 #endif // AI_IRRMESHIMPORTER_H_INC