vrshoot

view libs/assimp/COBScene.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 /** @file COBScene.h
42 * @brief Utilities for the COB importer.
43 */
44 #ifndef INCLUDED_AI_COB_SCENE_H
45 #define INCLUDED_AI_COB_SCENE_H
47 #include <boost/shared_ptr.hpp>
48 #include "BaseImporter.h"
50 namespace Assimp {
51 namespace COB {
53 // ------------------
54 /** Represents a single vertex index in a face */
55 struct VertexIndex
56 {
57 // intentionally uninitialized
58 unsigned int pos_idx,uv_idx;
59 };
61 // ------------------
62 /** COB Face data structure */
63 struct Face
64 {
65 // intentionally uninitialized
66 unsigned int material, flags;
67 std::vector<VertexIndex> indices;
68 };
70 // ------------------
71 /** COB chunk header information */
72 struct ChunkInfo
73 {
74 enum {NO_SIZE=UINT_MAX};
76 ChunkInfo ()
77 : id (0)
78 , parent_id (0)
79 , version (0)
80 , size (NO_SIZE)
81 {}
83 // Id of this chunk, unique within file
84 unsigned int id;
86 // and the corresponding parent
87 unsigned int parent_id;
89 // version. v1.23 becomes 123
90 unsigned int version;
92 // chunk size in bytes, only relevant for binary files
93 // NO_SIZE is also valid.
94 unsigned int size;
95 };
97 // ------------------
98 /** A node in the scenegraph */
99 struct Node : public ChunkInfo
100 {
101 enum Type {
102 TYPE_MESH,TYPE_GROUP,TYPE_LIGHT,TYPE_CAMERA,TYPE_BONE
103 };
105 virtual ~Node() {}
106 Node(Type type) : type(type), unit_scale(1.f){}
108 Type type;
110 // used during resolving
111 typedef std::deque<const Node*> ChildList;
112 mutable ChildList temp_children;
114 // unique name
115 std::string name;
117 // local mesh transformation
118 aiMatrix4x4 transform;
120 // scaling for this node to get to the metric system
121 float unit_scale;
122 };
124 // ------------------
125 /** COB Mesh data structure */
126 struct Mesh : public Node
127 {
128 using ChunkInfo::operator=;
129 enum DrawFlags {
130 SOLID = 0x1,
131 TRANS = 0x2,
132 WIRED = 0x4,
133 BBOX = 0x8,
134 HIDE = 0x10
135 };
137 Mesh()
138 : Node(TYPE_MESH)
139 , draw_flags(SOLID)
140 {}
142 // vertex elements
143 std::vector<aiVector2D> texture_coords;
144 std::vector<aiVector3D> vertex_positions;
146 // face data
147 std::vector<Face> faces;
149 // misc. drawing flags
150 unsigned int draw_flags;
152 // used during resolving
153 typedef std::deque<Face*> FaceRefList;
154 typedef std::map< unsigned int,FaceRefList > TempMap;
155 TempMap temp_map;
156 };
158 // ------------------
159 /** COB Group data structure */
160 struct Group : public Node
161 {
162 using ChunkInfo::operator=;
163 Group() : Node(TYPE_GROUP) {}
164 };
166 // ------------------
167 /** COB Bone data structure */
168 struct Bone : public Node
169 {
170 using ChunkInfo::operator=;
171 Bone() : Node(TYPE_BONE) {}
172 };
174 // ------------------
175 /** COB Light data structure */
176 struct Light : public Node
177 {
178 enum LightType {
179 SPOT,LOCAL,INFINITE
180 };
182 using ChunkInfo::operator=;
183 Light() : Node(TYPE_LIGHT),angle(),inner_angle(),ltype(SPOT) {}
185 aiColor3D color;
186 float angle,inner_angle;
188 LightType ltype;
189 };
191 // ------------------
192 /** COB Camera data structure */
193 struct Camera : public Node
194 {
195 using ChunkInfo::operator=;
196 Camera() : Node(TYPE_CAMERA) {}
197 };
199 // ------------------
200 /** COB Texture data structure */
201 struct Texture
202 {
203 std::string path;
204 aiUVTransform transform;
205 };
207 // ------------------
208 /** COB Material data structure */
209 struct Material : ChunkInfo
210 {
211 using ChunkInfo::operator=;
212 enum Shader {
213 FLAT,PHONG,METAL
214 };
216 enum AutoFacet {
217 FACETED,AUTOFACETED,SMOOTH
218 };
220 Material() : alpha(),exp(),ior(),ka(),ks(1.f),
221 matnum(UINT_MAX),
222 shader(FLAT),autofacet(FACETED),
223 autofacet_angle()
224 {}
226 std::string type;
228 aiColor3D rgb;
229 float alpha, exp, ior,ka,ks;
231 unsigned int matnum;
232 Shader shader;
234 AutoFacet autofacet;
235 float autofacet_angle;
237 boost::shared_ptr<Texture> tex_env,tex_bump,tex_color;
238 };
240 // ------------------
241 /** Embedded bitmap, for instance for the thumbnail image */
242 struct Bitmap : ChunkInfo
243 {
244 Bitmap() : orig_size() {}
245 struct BitmapHeader
246 {
247 };
249 BitmapHeader head;
250 size_t orig_size;
251 std::vector<char> buff_zipped;
252 };
254 typedef std::deque< boost::shared_ptr<Node> > NodeList;
255 typedef std::vector< Material > MaterialList;
257 // ------------------
258 /** Represents a master COB scene, even if we loaded just a single COB file */
259 struct Scene
260 {
261 NodeList nodes;
262 MaterialList materials;
264 // becomes *0 later
265 Bitmap thumbnail;
266 };
268 } // end COB
269 } // end Assimp
271 #endif