COBScene.h 6.1 KB

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