Coverage Report

Created: 2024-08-02 07:04

/src/assimp/code/AssetLib/COB/COBScene.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2024, assimp team
6
7
All rights reserved.
8
9
Redistribution and use of this software in source and binary forms,
10
with or without modification, are permitted provided that the
11
following conditions are met:
12
13
* Redistributions of source code must retain the above
14
copyright notice, this list of conditions and the
15
following disclaimer.
16
17
* Redistributions in binary form must reproduce the above
18
copyright notice, this list of conditions and the
19
following disclaimer in the documentation and/or other
20
materials provided with the distribution.
21
22
* Neither the name of the assimp team, nor the names of its
23
contributors may be used to endorse or promote products
24
derived from this software without specific prior
25
written permission of the assimp team.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
OF 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
#pragma once
46
#ifndef INCLUDED_AI_COB_SCENE_H
47
#define INCLUDED_AI_COB_SCENE_H
48
49
#include <assimp/BaseImporter.h>
50
#include <assimp/material.h>
51
52
#include <deque>
53
#include <map>
54
55
namespace Assimp {
56
namespace COB {
57
58
// ------------------
59
/** Represents a single vertex index in a face */
60
struct VertexIndex
61
{
62
    // intentionally uninitialized
63
    unsigned int pos_idx,uv_idx;
64
};
65
66
// ------------------
67
/** COB Face data structure */
68
struct Face
69
{
70
    // intentionally uninitialized
71
    unsigned int material, flags;
72
    std::vector<VertexIndex> indices;
73
};
74
75
// ------------------
76
/** COB chunk header information */
77
const unsigned int NO_SIZE = UINT_MAX;
78
79
struct ChunkInfo
80
{
81
    ChunkInfo ()
82
        :   id        (0)
83
        ,   parent_id (0)
84
        ,   version   (0)
85
        ,   size      (NO_SIZE)
86
0
    {}
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 */
104
struct Node : public ChunkInfo
105
{
106
    enum Type {
107
        TYPE_MESH,TYPE_GROUP,TYPE_LIGHT,TYPE_CAMERA,TYPE_BONE
108
    };
109
110
0
    virtual ~Node() = default;
111
0
    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 */
131
struct 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
0
    {}
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 */
165
struct Group : public Node
166
{
167
    using ChunkInfo::operator=;
168
0
    Group() : Node(TYPE_GROUP) {}
169
};
170
171
// ------------------
172
/** COB Bone data structure */
173
struct Bone : public Node
174
{
175
    using ChunkInfo::operator=;
176
0
    Bone() : Node(TYPE_BONE) {}
177
};
178
179
// ------------------
180
/** COB Light data structure */
181
struct Light : public Node
182
{
183
    enum LightType {
184
        SPOT,LOCAL,INFINITE
185
    };
186
187
    using ChunkInfo::operator=;
188
0
    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 */
198
struct Camera : public Node
199
{
200
    using ChunkInfo::operator=;
201
0
    Camera() : Node(TYPE_CAMERA) {}
202
};
203
204
// ------------------
205
/** COB Texture data structure */
206
struct Texture
207
{
208
    std::string path;
209
    aiUVTransform transform;
210
};
211
212
// ------------------
213
/** COB Material data structure */
214
struct 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
0
    {}
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 */
247
struct Bitmap : ChunkInfo
248
{
249
0
    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
259
typedef std::deque< std::shared_ptr<Node> > NodeList;
260
typedef std::vector< Material > MaterialList;
261
262
// ------------------
263
/** Represents a master COB scene, even if we loaded just a single COB file */
264
struct 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