COBScene.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. /** @file COBScene.h
  34. * @brief Utilities for the COB importer.
  35. */
  36. #pragma once
  37. #ifndef INCLUDED_AI_COB_SCENE_H
  38. #define INCLUDED_AI_COB_SCENE_H
  39. #include <assimp/BaseImporter.h>
  40. #include <assimp/material.h>
  41. #include <deque>
  42. #include <map>
  43. namespace Assimp {
  44. namespace COB {
  45. // ------------------
  46. /** Represents a single vertex index in a face */
  47. struct VertexIndex
  48. {
  49. // intentionally uninitialized
  50. unsigned int pos_idx,uv_idx;
  51. };
  52. // ------------------
  53. /** COB Face data structure */
  54. struct Face
  55. {
  56. // intentionally uninitialized
  57. unsigned int material, flags;
  58. std::vector<VertexIndex> indices;
  59. };
  60. // ------------------
  61. /** COB chunk header information */
  62. const unsigned int NO_SIZE = UINT_MAX;
  63. struct ChunkInfo
  64. {
  65. ChunkInfo ()
  66. : id (0)
  67. , parent_id (0)
  68. , version (0)
  69. , size (NO_SIZE)
  70. {}
  71. // Id of this chunk, unique within file
  72. unsigned int id;
  73. // and the corresponding parent
  74. unsigned int parent_id;
  75. // version. v1.23 becomes 123
  76. unsigned int version;
  77. // chunk size in bytes, only relevant for binary files
  78. // NO_SIZE is also valid.
  79. unsigned int size;
  80. };
  81. // ------------------
  82. /** A node in the scenegraph */
  83. struct Node : public ChunkInfo
  84. {
  85. enum Type {
  86. TYPE_MESH,TYPE_GROUP,TYPE_LIGHT,TYPE_CAMERA,TYPE_BONE
  87. };
  88. virtual ~Node() = default;
  89. Node(Type type) : type(type), unit_scale(1.f){}
  90. Type type;
  91. // used during resolving
  92. typedef std::deque<const Node*> ChildList;
  93. mutable ChildList temp_children;
  94. // unique name
  95. std::string name;
  96. // local mesh transformation
  97. aiMatrix4x4 transform;
  98. // scaling for this node to get to the metric system
  99. float unit_scale;
  100. };
  101. // ------------------
  102. /** COB Mesh data structure */
  103. struct Mesh : public Node
  104. {
  105. using ChunkInfo::operator=;
  106. enum DrawFlags {
  107. SOLID = 0x1,
  108. TRANS = 0x2,
  109. WIRED = 0x4,
  110. BBOX = 0x8,
  111. HIDE = 0x10
  112. };
  113. Mesh()
  114. : Node(TYPE_MESH)
  115. , draw_flags(SOLID)
  116. {}
  117. // vertex elements
  118. std::vector<aiVector2D> texture_coords;
  119. std::vector<aiVector3D> vertex_positions;
  120. // face data
  121. std::vector<Face> faces;
  122. // misc. drawing flags
  123. unsigned int draw_flags;
  124. // used during resolving
  125. typedef std::deque<Face*> FaceRefList;
  126. typedef std::map< unsigned int,FaceRefList > TempMap;
  127. TempMap temp_map;
  128. };
  129. // ------------------
  130. /** COB Group data structure */
  131. struct Group : public Node
  132. {
  133. using ChunkInfo::operator=;
  134. Group() : Node(TYPE_GROUP) {}
  135. };
  136. // ------------------
  137. /** COB Bone data structure */
  138. struct Bone : public Node
  139. {
  140. using ChunkInfo::operator=;
  141. Bone() : Node(TYPE_BONE) {}
  142. };
  143. // ------------------
  144. /** COB Light data structure */
  145. struct Light : public Node
  146. {
  147. enum LightType {
  148. SPOT,LOCAL,INFINITE
  149. };
  150. using ChunkInfo::operator=;
  151. Light() : Node(TYPE_LIGHT),angle(),inner_angle(),ltype(SPOT) {}
  152. aiColor3D color;
  153. float angle,inner_angle;
  154. LightType ltype;
  155. };
  156. // ------------------
  157. /** COB Camera data structure */
  158. struct Camera : public Node
  159. {
  160. using ChunkInfo::operator=;
  161. Camera() : Node(TYPE_CAMERA) {}
  162. };
  163. // ------------------
  164. /** COB Texture data structure */
  165. struct Texture
  166. {
  167. std::string path;
  168. aiUVTransform transform;
  169. };
  170. // ------------------
  171. /** COB Material data structure */
  172. struct Material : ChunkInfo
  173. {
  174. using ChunkInfo::operator=;
  175. enum Shader {
  176. FLAT,PHONG,METAL
  177. };
  178. enum AutoFacet {
  179. FACETED,AUTOFACETED,SMOOTH
  180. };
  181. Material() : alpha(),exp(),ior(),ka(),ks(1.f),
  182. matnum(UINT_MAX),
  183. shader(FLAT),autofacet(FACETED),
  184. autofacet_angle()
  185. {}
  186. std::string type;
  187. aiColor3D rgb;
  188. float alpha, exp, ior,ka,ks;
  189. unsigned int matnum;
  190. Shader shader;
  191. AutoFacet autofacet;
  192. float autofacet_angle;
  193. std::shared_ptr<Texture> tex_env,tex_bump,tex_color;
  194. };
  195. // ------------------
  196. /** Embedded bitmap, for instance for the thumbnail image */
  197. struct Bitmap : ChunkInfo
  198. {
  199. Bitmap() : orig_size() {}
  200. struct BitmapHeader
  201. {
  202. };
  203. BitmapHeader head;
  204. size_t orig_size;
  205. std::vector<char> buff_zipped;
  206. };
  207. typedef std::deque< std::shared_ptr<Node> > NodeList;
  208. typedef std::vector< Material > MaterialList;
  209. // ------------------
  210. /** Represents a master COB scene, even if we loaded just a single COB file */
  211. struct Scene
  212. {
  213. NodeList nodes;
  214. MaterialList materials;
  215. // becomes *0 later
  216. Bitmap thumbnail;
  217. };
  218. } // end COB
  219. } // end Assimp
  220. #endif