AMFImporter_Node.hpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2025, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /// \file AMFImporter_Node.hpp
  35. /// \brief Elements of scene graph.
  36. /// \date 2016
  37. /// \author [email protected]
  38. #pragma once
  39. #ifndef INCLUDED_AI_AMF_IMPORTER_NODE_H
  40. #define INCLUDED_AI_AMF_IMPORTER_NODE_H
  41. // Header files, Assimp.
  42. #include <assimp/scene.h>
  43. #include <assimp/types.h>
  44. #include <list>
  45. #include <string>
  46. #include <vector>
  47. /// Base class for elements of nodes.
  48. class AMFNodeElementBase {
  49. public:
  50. /// Define what data type contain node element.
  51. enum EType {
  52. ENET_Color, ///< Color element: <color>.
  53. ENET_Constellation, ///< Grouping element: <constellation>.
  54. ENET_Coordinates, ///< Coordinates element: <coordinates>.
  55. ENET_Edge, ///< Edge element: <edge>.
  56. ENET_Instance, ///< Grouping element: <constellation>.
  57. ENET_Material, ///< Material element: <material>.
  58. ENET_Metadata, ///< Metadata element: <metadata>.
  59. ENET_Mesh, ///< Metadata element: <mesh>.
  60. ENET_Object, ///< Element which hold object: <object>.
  61. ENET_Root, ///< Root element: <amf>.
  62. ENET_Triangle, ///< Triangle element: <triangle>.
  63. ENET_TexMap, ///< Texture coordinates element: <texmap> or <map>.
  64. ENET_Texture, ///< Texture element: <texture>.
  65. ENET_Vertex, ///< Vertex element: <vertex>.
  66. ENET_Vertices, ///< Vertex element: <vertices>.
  67. ENET_Volume, ///< Volume element: <volume>.
  68. ENET_Invalid ///< Element has invalid type and possible contain invalid data.
  69. };
  70. const EType Type; ///< Type of element.
  71. std::string ID; ///< ID of element.
  72. AMFNodeElementBase *Parent; ///< Parent element. If nullptr then this node is root.
  73. std::list<AMFNodeElementBase *> Child; ///< Child elements.
  74. public:
  75. /// Destructor, virtual..
  76. virtual ~AMFNodeElementBase() = default;
  77. /// Disabled copy constructor and co.
  78. AMFNodeElementBase(const AMFNodeElementBase &pNodeElement) = delete;
  79. AMFNodeElementBase(AMFNodeElementBase &&) = delete;
  80. AMFNodeElementBase &operator=(const AMFNodeElementBase &pNodeElement) = delete;
  81. AMFNodeElementBase() = delete;
  82. protected:
  83. /// In constructor inheritor must set element type.
  84. /// \param [in] type - element type.
  85. /// \param [in] pParent - parent element.
  86. AMFNodeElementBase(EType type, AMFNodeElementBase *pParent) :
  87. Type(type), Parent(pParent) {
  88. // empty
  89. }
  90. }; // class IAMFImporter_NodeElement
  91. /// A collection of objects or constellations with specific relative locations.
  92. struct AMFConstellation : public AMFNodeElementBase {
  93. /// Constructor.
  94. /// \param [in] pParent - pointer to parent node.
  95. AMFConstellation(AMFNodeElementBase *pParent) :
  96. AMFNodeElementBase(ENET_Constellation, pParent) {}
  97. }; // struct CAMFImporter_NodeElement_Constellation
  98. /// Part of constellation.
  99. struct AMFInstance : public AMFNodeElementBase {
  100. std::string ObjectID; ///< ID of object for instantiation.
  101. /// \var Delta - The distance of translation in the x, y, or z direction, respectively, in the referenced object's coordinate system, to
  102. /// create an instance of the object in the current constellation.
  103. aiVector3D Delta;
  104. /// \var Rotation - The rotation, in degrees, to rotate the referenced object about its x, y, and z axes, respectively, to create an
  105. /// instance of the object in the current constellation. Rotations shall be executed in order of x first, then y, then z.
  106. aiVector3D Rotation;
  107. /// Constructor.
  108. /// \param [in] pParent - pointer to parent node.
  109. AMFInstance(AMFNodeElementBase *pParent) :
  110. AMFNodeElementBase(ENET_Instance, pParent) {}
  111. };
  112. /// Structure that define metadata node.
  113. struct AMFMetadata : public AMFNodeElementBase {
  114. std::string MetaType; ///< Type of "Value".
  115. std::string Value; ///< Value.
  116. /// Constructor.
  117. /// \param [in] pParent - pointer to parent node.
  118. AMFMetadata(AMFNodeElementBase *pParent) :
  119. AMFNodeElementBase(ENET_Metadata, pParent) {}
  120. };
  121. /// Structure that define root node.
  122. struct AMFRoot : public AMFNodeElementBase {
  123. std::string Unit; ///< The units to be used. May be "inch", "millimeter", "meter", "feet", or "micron".
  124. std::string Version; ///< Version of format.
  125. /// Constructor.
  126. /// \param [in] pParent - pointer to parent node.
  127. AMFRoot(AMFNodeElementBase *pParent) :
  128. AMFNodeElementBase(ENET_Root, pParent) {}
  129. };
  130. /// Structure that define object node.
  131. struct AMFColor : public AMFNodeElementBase {
  132. bool Composed; ///< Type of color stored: if true then look for formula in \ref Color_Composed[4], else - in \ref Color.
  133. std::string Color_Composed[4]; ///< By components formulas of composed color. [0..3] - RGBA.
  134. aiColor4D Color; ///< Constant color.
  135. std::string Profile; ///< The ICC color space used to interpret the three color channels r, g and b..
  136. /// @brief Constructor.
  137. /// @param [in] pParent - pointer to parent node.
  138. AMFColor(AMFNodeElementBase *pParent) :
  139. AMFNodeElementBase(ENET_Color, pParent), Composed(false), Color() {
  140. // empty
  141. }
  142. };
  143. /// Structure that define material node.
  144. struct AMFMaterial : public AMFNodeElementBase {
  145. /// Constructor.
  146. /// \param [in] pParent - pointer to parent node.
  147. AMFMaterial(AMFNodeElementBase *pParent) :
  148. AMFNodeElementBase(ENET_Material, pParent) {}
  149. };
  150. /// Structure that define object node.
  151. struct AMFObject : public AMFNodeElementBase {
  152. /// Constructor.
  153. /// \param [in] pParent - pointer to parent node.
  154. AMFObject(AMFNodeElementBase *pParent) :
  155. AMFNodeElementBase(ENET_Object, pParent) {}
  156. };
  157. /// \struct CAMFImporter_NodeElement_Mesh
  158. /// Structure that define mesh node.
  159. struct AMFMesh : public AMFNodeElementBase {
  160. /// Constructor.
  161. /// \param [in] pParent - pointer to parent node.
  162. AMFMesh(AMFNodeElementBase *pParent) :
  163. AMFNodeElementBase(ENET_Mesh, pParent) {}
  164. };
  165. /// Structure that define vertex node.
  166. struct AMFVertex : public AMFNodeElementBase {
  167. /// Constructor.
  168. /// \param [in] pParent - pointer to parent node.
  169. AMFVertex(AMFNodeElementBase *pParent) :
  170. AMFNodeElementBase(ENET_Vertex, pParent) {}
  171. };
  172. /// Structure that define edge node.
  173. struct AMFEdge : public AMFNodeElementBase {
  174. /// Constructor.
  175. /// \param [in] pParent - pointer to parent node.
  176. AMFEdge(AMFNodeElementBase *pParent) :
  177. AMFNodeElementBase(ENET_Edge, pParent) {}
  178. };
  179. /// Structure that define vertices node.
  180. struct AMFVertices : public AMFNodeElementBase {
  181. /// Constructor.
  182. /// \param [in] pParent - pointer to parent node.
  183. AMFVertices(AMFNodeElementBase *pParent) :
  184. AMFNodeElementBase(ENET_Vertices, pParent) {}
  185. };
  186. /// Structure that define volume node.
  187. struct AMFVolume : public AMFNodeElementBase {
  188. std::string MaterialID; ///< Which material to use.
  189. std::string VolumeType; ///< What this volume describes can be "region" or "support". If none specified, "object" is assumed.
  190. /// Constructor.
  191. /// \param [in] pParent - pointer to parent node.
  192. AMFVolume(AMFNodeElementBase *pParent) :
  193. AMFNodeElementBase(ENET_Volume, pParent) {}
  194. };
  195. /// Structure that define coordinates node.
  196. struct AMFCoordinates : public AMFNodeElementBase {
  197. aiVector3D Coordinate; ///< Coordinate.
  198. /// Constructor.
  199. /// \param [in] pParent - pointer to parent node.
  200. AMFCoordinates(AMFNodeElementBase *pParent) :
  201. AMFNodeElementBase(ENET_Coordinates, pParent) {}
  202. };
  203. /// Structure that define texture coordinates node.
  204. struct AMFTexMap : public AMFNodeElementBase {
  205. aiVector3D TextureCoordinate[3]; ///< Texture coordinates.
  206. std::string TextureID_R; ///< Texture ID for red color component.
  207. std::string TextureID_G; ///< Texture ID for green color component.
  208. std::string TextureID_B; ///< Texture ID for blue color component.
  209. std::string TextureID_A; ///< Texture ID for alpha color component.
  210. /// Constructor.
  211. /// \param [in] pParent - pointer to parent node.
  212. AMFTexMap(AMFNodeElementBase *pParent) :
  213. AMFNodeElementBase(ENET_TexMap, pParent), TextureCoordinate{} {
  214. // empty
  215. }
  216. };
  217. /// Structure that define triangle node.
  218. struct AMFTriangle : public AMFNodeElementBase {
  219. size_t V[3]; ///< Triangle vertices.
  220. /// Constructor.
  221. /// \param [in] pParent - pointer to parent node.
  222. AMFTriangle(AMFNodeElementBase *pParent) :
  223. AMFNodeElementBase(ENET_Triangle, pParent) {
  224. // empty
  225. }
  226. };
  227. /// Structure that define texture node.
  228. struct AMFTexture : public AMFNodeElementBase {
  229. size_t Width, Height, Depth; ///< Size of the texture.
  230. std::vector<uint8_t> Data; ///< Data of the texture.
  231. bool Tiled;
  232. /// Constructor.
  233. /// \param [in] pParent - pointer to parent node.
  234. AMFTexture(AMFNodeElementBase *pParent) :
  235. AMFNodeElementBase(ENET_Texture, pParent), Width(0), Height(0), Depth(0), Data(), Tiled(false) {
  236. // empty
  237. }
  238. };
  239. #endif // INCLUDED_AI_AMF_IMPORTER_NODE_H