COBScene.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2008, ASSIMP Development 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 Development 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 <boost/shared_ptr.hpp>
  39. #include "BaseImporter.h"
  40. namespace Assimp {
  41. namespace COB {
  42. // ------------------
  43. /** Represents a single vertex index in a face */
  44. struct VertexIndex
  45. {
  46. // intentionally uninitialized
  47. unsigned int pos_idx,uv_idx;
  48. };
  49. // ------------------
  50. /** COB Face data structure */
  51. struct Face
  52. {
  53. // intentionally uninitialized
  54. unsigned int material, flags;
  55. std::vector<VertexIndex> indices;
  56. };
  57. // ------------------
  58. /** COB chunk header information */
  59. struct ChunkInfo
  60. {
  61. enum {NO_SIZE=0xffffffff};
  62. ChunkInfo ()
  63. : id (0)
  64. , parent_id (0)
  65. , version (0)
  66. , size (NO_SIZE)
  67. {}
  68. // Id of this chunk, unique within file
  69. unsigned int id;
  70. // and the corresponding parent
  71. unsigned int parent_id;
  72. // version. v1.23 becomes 123
  73. unsigned int version;
  74. // chunk size in bytes, only relevant for binary files
  75. // NO_SIZE is also valid.
  76. unsigned int size;
  77. };
  78. // ------------------
  79. /** A node in the scenegraph */
  80. struct Node : public ChunkInfo
  81. {
  82. enum Type {
  83. TYPE_MESH,TYPE_GROUP,TYPE_LIGHT,TYPE_CAMERA,TYPE_BONE
  84. };
  85. virtual ~Node() {}
  86. Node(Type type) : type(type), unit_scale(1.f){}
  87. Type type;
  88. // used during resolving
  89. typedef std::deque<const Node*> ChildList;
  90. mutable ChildList temp_children;
  91. // unique name
  92. std::string name;
  93. // local mesh transformation
  94. aiMatrix4x4 transform;
  95. // scaling for this node to get to the metric system
  96. float unit_scale;
  97. };
  98. // ------------------
  99. /** COB Mesh data structure */
  100. struct Mesh : public Node
  101. {
  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 : public Node
  129. {
  130. using ChunkInfo::operator=;
  131. Group() : Node(TYPE_GROUP) {}
  132. };
  133. // ------------------
  134. /** COB Bone data structure */
  135. struct Bone : public Node
  136. {
  137. using ChunkInfo::operator=;
  138. Bone() : Node(TYPE_BONE) {}
  139. };
  140. // ------------------
  141. /** COB Light data structure */
  142. struct Light : public Node
  143. {
  144. enum LightType {
  145. SPOT,LOCAL,INFINITE
  146. };
  147. using ChunkInfo::operator=;
  148. Light() : Node(TYPE_LIGHT),angle(),inner_angle(),ltype(SPOT) {}
  149. aiColor3D color;
  150. float angle,inner_angle;
  151. LightType ltype;
  152. };
  153. // ------------------
  154. /** COB Camera data structure */
  155. struct Camera : public Node
  156. {
  157. using ChunkInfo::operator=;
  158. Camera() : Node(TYPE_CAMERA) {}
  159. };
  160. // ------------------
  161. /** COB Material data structure */
  162. struct Material : ChunkInfo
  163. {
  164. using ChunkInfo::operator=;
  165. enum Shader {
  166. FLAT,PHONG,METAL
  167. };
  168. Material() : alpha(),exp(),ior(),ka(),ks(1.f),matnum(0xffffffff),shader(FLAT) {}
  169. std::string type;
  170. aiColor3D rgb;
  171. float alpha, exp, ior,ka,ks;
  172. unsigned int matnum;
  173. Shader shader;
  174. };
  175. // ------------------
  176. /** Embedded bitmap, for instance for the thumbnail image */
  177. struct Bitmap : ChunkInfo
  178. {
  179. Bitmap() : orig_size() {}
  180. struct BitmapHeader
  181. {
  182. };
  183. BitmapHeader head;
  184. size_t orig_size;
  185. std::vector<char> buff_zipped;
  186. };
  187. typedef std::deque< boost::shared_ptr<Node> > NodeList;
  188. typedef std::vector< Material > MaterialList;
  189. // ------------------
  190. /** Represents a master COB scene, even if we loaded just a single COB file */
  191. struct Scene
  192. {
  193. NodeList nodes;
  194. MaterialList materials;
  195. // becomes *0 later
  196. Bitmap thumbnail;
  197. };
  198. } // end COB
  199. } // end Assimp
  200. #endif