/src/assimp/code/AssetLib/OpenGEX/OpenGEXImporter.h
Line | Count | Source |
1 | | /* |
2 | | Open Asset Import Library (assimp) |
3 | | ---------------------------------------------------------------------- |
4 | | |
5 | | Copyright (c) 2006-2026, 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 | | #pragma once |
42 | | #ifndef AI_OPENGEX_IMPORTER_H |
43 | | #define AI_OPENGEX_IMPORTER_H |
44 | | |
45 | | #ifndef ASSIMP_BUILD_NO_OPENGEX_IMPORTER |
46 | | |
47 | | #include <assimp/BaseImporter.h> |
48 | | #include <assimp/mesh.h> |
49 | | |
50 | | #include <vector> |
51 | | #include <list> |
52 | | #include <map> |
53 | | #include <memory> |
54 | | |
55 | | namespace ODDLParser { |
56 | | class DDLNode; |
57 | | struct Context; |
58 | | } |
59 | | |
60 | | struct aiNode; |
61 | | struct aiMaterial; |
62 | | struct aiCamera; |
63 | | struct aiLight; |
64 | | |
65 | | namespace Assimp { |
66 | | namespace OpenGEX { |
67 | | |
68 | | struct MetricInfo { |
69 | | enum Type { |
70 | | Distance = 0, |
71 | | Angle, |
72 | | Time, |
73 | | Up, |
74 | | Max |
75 | | }; |
76 | | |
77 | | std::string m_stringValue; |
78 | | float m_floatValue; |
79 | | int m_intValue; |
80 | | |
81 | 162k | MetricInfo(): m_stringValue( ), m_floatValue( 0.0f ), m_intValue( -1 ) {} |
82 | | }; |
83 | | |
84 | | /** @brief This class is used to implement the OpenGEX importer |
85 | | * |
86 | | * See http://opengex.org/OpenGEX.pdf for spec. |
87 | | */ |
88 | | class OpenGEXImporter : public BaseImporter { |
89 | | public: |
90 | | /// The class constructor. |
91 | | OpenGEXImporter(); |
92 | | |
93 | | /// The class destructor. |
94 | 40.6k | ~OpenGEXImporter() override = default; |
95 | | |
96 | | /// BaseImporter override. |
97 | | bool CanRead( const std::string &file, IOSystem *pIOHandler, bool checkSig ) const override; |
98 | | |
99 | | protected: |
100 | | /// BaseImporter override. |
101 | | void InternReadFile( const std::string &file, aiScene *pScene, IOSystem *pIOHandler ) override; |
102 | | |
103 | | /// BaseImporter override. |
104 | | const aiImporterDesc *GetInfo() const override; |
105 | | |
106 | | /// BaseImporter override. |
107 | | void SetupProperties( const Importer *pImp ) override; |
108 | | |
109 | | void handleNodes( ODDLParser::DDLNode *node, aiScene *pScene ); |
110 | | void handleMetricNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
111 | | void handleNameNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
112 | | void handleObjectRefNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
113 | | void handleMaterialRefNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
114 | | void handleGeometryNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
115 | | void handleCameraNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
116 | | void handleLightNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
117 | | void handleGeometryObject( ODDLParser::DDLNode *node, aiScene *pScene ); |
118 | | void handleCameraObject( ODDLParser::DDLNode *node, aiScene *pScene ); |
119 | | void handleLightObject( ODDLParser::DDLNode *node, aiScene *pScene ); |
120 | | void handleTransformNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
121 | | void handleMeshNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
122 | | void handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
123 | | void handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
124 | | void handleMaterialNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
125 | | void handleColorNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
126 | | void handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
127 | | void handleParamNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
128 | | void handleAttenNode( ODDLParser::DDLNode *node, aiScene *pScene ); |
129 | | void copyMeshes( aiScene *pScene ); |
130 | | void copyCameras( aiScene *pScene ); |
131 | | void copyLights( aiScene *pScene ); |
132 | | void copyMaterials( aiScene *pScene ); |
133 | | void resolveReferences(); |
134 | | void pushNode( aiNode *node, aiScene *pScene ); |
135 | | aiNode *popNode(); |
136 | | aiNode *top() const; |
137 | | void clearNodeStack(); |
138 | | void createNodeTree( aiScene *pScene ); |
139 | | |
140 | | private: |
141 | | struct VertexContainer { |
142 | | std::vector<aiVector3D> m_vertices; |
143 | | size_t m_numColors; |
144 | | aiColor4D *m_colors; |
145 | | std::vector<aiVector3D> m_normals; |
146 | | size_t m_numUVComps[ AI_MAX_NUMBER_OF_TEXTURECOORDS ]; |
147 | | aiVector3D *m_textureCoords[ AI_MAX_NUMBER_OF_TEXTURECOORDS ]; |
148 | | |
149 | | VertexContainer(); |
150 | | ~VertexContainer(); |
151 | | |
152 | | VertexContainer( const VertexContainer & ) = delete; |
153 | | VertexContainer &operator = ( const VertexContainer & ) = delete; |
154 | | }; |
155 | | |
156 | | struct RefInfo { |
157 | | enum Type { |
158 | | MeshRef, |
159 | | MaterialRef |
160 | | }; |
161 | | |
162 | | aiNode *m_node; |
163 | | Type m_type; |
164 | | std::vector<std::string> m_Names; |
165 | | |
166 | | RefInfo( aiNode *node, Type type, std::vector<std::string> &names ); |
167 | 0 | ~RefInfo() = default; |
168 | | |
169 | | RefInfo( const RefInfo & ) = delete; |
170 | | RefInfo &operator = ( const RefInfo & ) = delete; |
171 | | }; |
172 | | |
173 | | struct ChildInfo { |
174 | | using NodeList = std::list<aiNode*>; |
175 | | std::list<aiNode*> m_children; |
176 | | }; |
177 | | ChildInfo *m_root; |
178 | | using NodeChildMap = std::map<aiNode*, std::unique_ptr<ChildInfo> >; |
179 | | NodeChildMap m_nodeChildMap; |
180 | | |
181 | | std::vector<std::unique_ptr<aiMesh> > m_meshCache; |
182 | | using ReferenceMap = std::map<std::string, size_t>; |
183 | | std::map<std::string, size_t> m_mesh2refMap; |
184 | | std::map<std::string, size_t> m_material2refMap; |
185 | | |
186 | | ODDLParser::Context *m_ctx; |
187 | | MetricInfo m_metrics[ MetricInfo::Max ]; |
188 | | aiNode *m_currentNode; |
189 | | VertexContainer m_currentVertices; |
190 | | aiMesh *m_currentMesh; // not owned, target is owned by m_meshCache |
191 | | aiMaterial *m_currentMaterial; |
192 | | aiLight *m_currentLight; |
193 | | aiCamera *m_currentCamera; |
194 | | int m_tokenType; |
195 | | std::vector<aiMaterial*> m_materialCache; |
196 | | std::vector<aiCamera*> m_cameraCache; |
197 | | std::vector<aiLight*> m_lightCache; |
198 | | std::vector<aiNode*> m_nodeStack; |
199 | | std::vector<std::unique_ptr<RefInfo> > m_unresolvedRefStack; |
200 | | }; |
201 | | |
202 | | } // Namespace OpenGEX |
203 | | } // Namespace Assimp |
204 | | |
205 | | #endif // ASSIMP_BUILD_NO_OPENGEX_IMPORTER |
206 | | |
207 | | #endif // AI_OPENGEX_IMPORTER_H |