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