2
0

COBScene.h 6.4 KB

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