Coverage Report

Created: 2026-04-01 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/AssetLib/COB/COBScene.h
Line
Count
Source
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2026, 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::COB {
56
57
// ------------------
58
/** Represents a single vertex index in a face */
59
struct VertexIndex {
60
    // intentionally uninitialized
61
    unsigned int pos_idx,uv_idx;
62
};
63
64
// ------------------
65
/** COB Face data structure */
66
struct Face {
67
    // intentionally uninitialized
68
    unsigned int material;
69
    unsigned int flags;
70
    std::vector<VertexIndex> indices;
71
};
72
73
// ------------------
74
/** COB chunk header information */
75
constexpr unsigned int NO_SIZE = UINT_MAX;
76
77
struct ChunkInfo {
78
0
    ChunkInfo() = default;
79
0
    virtual ~ChunkInfo() = default;
80
81
    // Id of this chunk, unique within file
82
    unsigned int id{ 0 };
83
84
    // and the corresponding parent
85
    unsigned int parent_id{ 0 };
86
87
    // version. v1.23 becomes 123
88
    unsigned int version{ 0 };
89
90
    // chunk size in bytes, only relevant for binary files
91
    // NO_SIZE is also valid.
92
    unsigned int size{NO_SIZE};
93
};
94
95
// ------------------
96
/** A node in the scenegraph */
97
struct Node : ChunkInfo {
98
    enum Type {
99
        TYPE_INVALID = -1,
100
        TYPE_MESH = 0,
101
        TYPE_GROUP,
102
        TYPE_LIGHT,
103
        TYPE_CAMERA,
104
        TYPE_BONE,
105
        TYPE_COUNT
106
    };
107
108
0
    ~Node() override = default;
109
0
    explicit Node(Type type) : type(type), unit_scale(1.f){}
110
111
    Type type;
112
113
    // used during resolving
114
    using ChildList = std::deque<const Node*> ;
115
    mutable ChildList temp_children;
116
117
    // unique name
118
    std::string name;
119
120
    // local mesh transformation
121
    aiMatrix4x4 transform;
122
123
    // scaling for this node to get to the metric system
124
    float unit_scale;
125
};
126
127
// ------------------
128
/** COB Mesh data structure */
129
struct Mesh final : Node {
130
    using ChunkInfo::operator=;
131
    enum DrawFlags {
132
        SOLID = 0x1,
133
        TRANS = 0x2,
134
        WIRED = 0x4,
135
        BBOX  = 0x8,
136
        HIDE  = 0x10
137
    };
138
139
    Mesh()
140
0
        : Node(TYPE_MESH)
141
0
        , draw_flags(SOLID)
142
0
    {}
143
144
    // vertex elements
145
    std::vector<aiVector2D> texture_coords;
146
    std::vector<aiVector3D> vertex_positions;
147
148
    // face data
149
    std::vector<Face> faces;
150
151
    // misc. drawing flags
152
    unsigned int draw_flags;
153
154
    // used during resolving
155
    typedef std::deque<Face*> FaceRefList;
156
    typedef std::map< unsigned int,FaceRefList > TempMap;
157
    TempMap temp_map;
158
};
159
160
// ------------------
161
/** COB Group data structure */
162
struct Group final : Node {
163
    using ChunkInfo::operator=;
164
    
165
0
    Group() : Node(TYPE_GROUP) {
166
        // empty
167
0
    }
168
};
169
170
// ------------------
171
/** COB Bone data structure */
172
struct Bone final : Node {
173
    using ChunkInfo::operator=;
174
    
175
0
    Bone() : Node(TYPE_BONE) {
176
        // empty
177
0
    }
178
};
179
180
// ------------------
181
/** COB Light data structure */
182
struct Light final : Node {
183
    enum LightType {
184
        SPOT,
185
        LOCAL,
186
        INFINITE
187
    };
188
189
    using ChunkInfo::operator=;
190
191
0
    Light() : Node(TYPE_LIGHT), ltype() {
192
        // empty
193
0
    }
194
195
    aiColor3D color;
196
    float angle{ 0.0f };
197
    float inner_angle{ 0.0f };
198
199
    LightType ltype{SPOT};
200
};
201
202
// ------------------
203
/** COB Camera data structure */
204
struct Camera final : Node {
205
    using ChunkInfo::operator=;
206
207
0
    Camera() : Node(TYPE_CAMERA) {
208
        // empty
209
0
    }
210
};
211
212
// ------------------
213
/** COB Texture data structure */
214
struct Texture {
215
    std::string path;
216
    aiUVTransform transform;
217
};
218
219
// ------------------
220
/** COB Material data structure */
221
struct Material : ChunkInfo {
222
    using ChunkInfo::operator=;
223
224
    enum Shader {
225
        FLAT,
226
        PHONG,
227
        METAL
228
    };
229
230
    enum AutoFacet {
231
        FACETED,
232
        AUTOFACETED,
233
        SMOOTH
234
    };
235
236
0
    Material() : shader(FLAT) {
237
        // empty
238
0
    }
239
240
    std::string type;
241
    aiColor3D rgb;
242
    float alpha{ 0.0f };
243
    float exp{ 0.0f };
244
    float ior{ 0.0f };
245
    float ka{ 0.0f };
246
    float ks{ 1.0f };
247
    unsigned int matnum{ UINT_MAX };
248
    Shader shader;
249
    AutoFacet autofacet{FACETED};
250
    float autofacet_angle{ 0.0f };
251
    std::shared_ptr<Texture> tex_env,tex_bump,tex_color;
252
};
253
254
// ------------------
255
/** Embedded bitmap, for instance for the thumbnail image */
256
struct Bitmap : ChunkInfo {
257
0
    Bitmap() = default;
258
259
    struct BitmapHeader {
260
        // empty
261
    };
262
263
    BitmapHeader head;
264
    size_t orig_size{ 0u };
265
    std::vector<char> buff_zipped;
266
};
267
268
using NodeList      = std::deque< std::shared_ptr<Node>>;
269
using MaterialList = std::vector< Material >;
270
271
// ------------------
272
/** Represents a master COB scene, even if we loaded just a single COB file */
273
struct Scene {
274
    NodeList nodes;
275
    MaterialList materials;
276
277
    // becomes *0 later
278
    Bitmap thumbnail;
279
};
280
281
} // end Assimp::COB
282
283
#endif // INCLUDED_AI_COB_SCENE_H