OpenGEXImporter.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2025, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. #pragma once
  34. #ifndef AI_OPENGEX_IMPORTER_H
  35. #define AI_OPENGEX_IMPORTER_H
  36. #ifndef ASSIMP_BUILD_NO_OPENGEX_IMPORTER
  37. #include <assimp/BaseImporter.h>
  38. #include <assimp/mesh.h>
  39. #include <vector>
  40. #include <list>
  41. #include <map>
  42. #include <memory>
  43. namespace ODDLParser {
  44. class DDLNode;
  45. struct Context;
  46. }
  47. struct aiNode;
  48. struct aiMaterial;
  49. struct aiCamera;
  50. struct aiLight;
  51. namespace Assimp {
  52. namespace OpenGEX {
  53. struct MetricInfo {
  54. enum Type {
  55. Distance = 0,
  56. Angle,
  57. Time,
  58. Up,
  59. Max
  60. };
  61. std::string m_stringValue;
  62. float m_floatValue;
  63. int m_intValue;
  64. MetricInfo(): m_stringValue( ), m_floatValue( 0.0f ), m_intValue( -1 ) {}
  65. };
  66. /** @brief This class is used to implement the OpenGEX importer
  67. *
  68. * See http://opengex.org/OpenGEX.pdf for spec.
  69. */
  70. class OpenGEXImporter : public BaseImporter {
  71. public:
  72. /// The class constructor.
  73. OpenGEXImporter();
  74. /// The class destructor.
  75. ~OpenGEXImporter() override = default;
  76. /// BaseImporter override.
  77. bool CanRead( const std::string &file, IOSystem *pIOHandler, bool checkSig ) const override;
  78. protected:
  79. /// BaseImporter override.
  80. void InternReadFile( const std::string &file, aiScene *pScene, IOSystem *pIOHandler ) override;
  81. /// BaseImporter override.
  82. const aiImporterDesc *GetInfo() const override;
  83. /// BaseImporter override.
  84. void SetupProperties( const Importer *pImp ) override;
  85. void handleNodes( ODDLParser::DDLNode *node, aiScene *pScene );
  86. void handleMetricNode( ODDLParser::DDLNode *node, aiScene *pScene );
  87. void handleNameNode( ODDLParser::DDLNode *node, aiScene *pScene );
  88. void handleObjectRefNode( ODDLParser::DDLNode *node, aiScene *pScene );
  89. void handleMaterialRefNode( ODDLParser::DDLNode *node, aiScene *pScene );
  90. void handleGeometryNode( ODDLParser::DDLNode *node, aiScene *pScene );
  91. void handleCameraNode( ODDLParser::DDLNode *node, aiScene *pScene );
  92. void handleLightNode( ODDLParser::DDLNode *node, aiScene *pScene );
  93. void handleGeometryObject( ODDLParser::DDLNode *node, aiScene *pScene );
  94. void handleCameraObject( ODDLParser::DDLNode *node, aiScene *pScene );
  95. void handleLightObject( ODDLParser::DDLNode *node, aiScene *pScene );
  96. void handleTransformNode( ODDLParser::DDLNode *node, aiScene *pScene );
  97. void handleMeshNode( ODDLParser::DDLNode *node, aiScene *pScene );
  98. void handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene );
  99. void handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene );
  100. void handleMaterialNode( ODDLParser::DDLNode *node, aiScene *pScene );
  101. void handleColorNode( ODDLParser::DDLNode *node, aiScene *pScene );
  102. void handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene );
  103. void handleParamNode( ODDLParser::DDLNode *node, aiScene *pScene );
  104. void handleAttenNode( ODDLParser::DDLNode *node, aiScene *pScene );
  105. void copyMeshes( aiScene *pScene );
  106. void copyCameras( aiScene *pScene );
  107. void copyLights( aiScene *pScene );
  108. void copyMaterials( aiScene *pScene );
  109. void resolveReferences();
  110. void pushNode( aiNode *node, aiScene *pScene );
  111. aiNode *popNode();
  112. aiNode *top() const;
  113. void clearNodeStack();
  114. void createNodeTree( aiScene *pScene );
  115. private:
  116. struct VertexContainer {
  117. std::vector<aiVector3D> m_vertices;
  118. size_t m_numColors;
  119. aiColor4D *m_colors;
  120. std::vector<aiVector3D> m_normals;
  121. size_t m_numUVComps[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
  122. aiVector3D *m_textureCoords[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
  123. VertexContainer();
  124. ~VertexContainer();
  125. VertexContainer( const VertexContainer & ) = delete;
  126. VertexContainer &operator = ( const VertexContainer & ) = delete;
  127. };
  128. struct RefInfo {
  129. enum Type {
  130. MeshRef,
  131. MaterialRef
  132. };
  133. aiNode *m_node;
  134. Type m_type;
  135. std::vector<std::string> m_Names;
  136. RefInfo( aiNode *node, Type type, std::vector<std::string> &names );
  137. ~RefInfo() = default;
  138. RefInfo( const RefInfo & ) = delete;
  139. RefInfo &operator = ( const RefInfo & ) = delete;
  140. };
  141. struct ChildInfo {
  142. using NodeList = std::list<aiNode*>;
  143. std::list<aiNode*> m_children;
  144. };
  145. ChildInfo *m_root;
  146. using NodeChildMap = std::map<aiNode*, std::unique_ptr<ChildInfo> >;
  147. NodeChildMap m_nodeChildMap;
  148. std::vector<std::unique_ptr<aiMesh> > m_meshCache;
  149. using ReferenceMap = std::map<std::string, size_t>;
  150. std::map<std::string, size_t> m_mesh2refMap;
  151. std::map<std::string, size_t> m_material2refMap;
  152. ODDLParser::Context *m_ctx;
  153. MetricInfo m_metrics[ MetricInfo::Max ];
  154. aiNode *m_currentNode;
  155. VertexContainer m_currentVertices;
  156. aiMesh *m_currentMesh; // not owned, target is owned by m_meshCache
  157. aiMaterial *m_currentMaterial;
  158. aiLight *m_currentLight;
  159. aiCamera *m_currentCamera;
  160. int m_tokenType;
  161. std::vector<aiMaterial*> m_materialCache;
  162. std::vector<aiCamera*> m_cameraCache;
  163. std::vector<aiLight*> m_lightCache;
  164. std::vector<aiNode*> m_nodeStack;
  165. std::vector<std::unique_ptr<RefInfo> > m_unresolvedRefStack;
  166. };
  167. } // Namespace OpenGEX
  168. } // Namespace Assimp
  169. #endif // ASSIMP_BUILD_NO_OPENGEX_IMPORTER
  170. #endif // AI_OPENGEX_IMPORTER_H