Coverage Report

Created: 2025-12-05 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/AssetLib/LWS/LWSLoader.h
Line
Count
Source
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2025, 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  LWSLoader.h
43
 *  @brief Declaration of the LightWave scene importer class.
44
 */
45
#pragma once
46
#ifndef AI_LWSLOADER_H_INCLUDED
47
#define AI_LWSLOADER_H_INCLUDED
48
49
#include "AssetLib/LWO/LWOFileData.h"
50
51
#include <assimp/BaseImporter.h>
52
#include <assimp/SceneCombiner.h>
53
54
struct aiImporterDesc;
55
56
namespace Assimp {
57
58
class BatchLoader;
59
class Importer;
60
class IOSystem;
61
62
namespace LWS {
63
64
// ---------------------------------------------------------------------------
65
/** Represents an element in a LWS file.
66
 *
67
 *  This can either be a single data line - <name> <value> or a data
68
 *  group - { name <data_line0> ... n }
69
 */
70
class Element {
71
public:
72
129k
    Element() = default;
73
74
    // first: name, second: rest
75
    std::string tokens[2];
76
    std::list<Element> children;
77
78
    //! Recursive parsing function
79
    void Parse(const char *&buffer, const char *end, int depth = 0);
80
};
81
82
255
#define AI_LWS_MASK (0xffffffff >> 4u)
83
84
// ---------------------------------------------------------------------------
85
/** Represents a LWS scenegraph element
86
 */
87
struct NodeDesc {
88
    NodeDesc() :
89
            type(),
90
            id(),
91
21.4k
            number(0),
92
21.4k
            parent(0),
93
            name(),
94
21.4k
            isPivotSet(false),
95
21.4k
            lightColor(1.f, 1.f, 1.f),
96
21.4k
            lightIntensity(1.f),
97
21.4k
            lightType(0),
98
21.4k
            lightFalloffType(0),
99
21.4k
            lightConeAngle(45.f),
100
            lightEdgeAngle(),
101
21.4k
            parent_resolved(nullptr) {}
102
103
    enum {
104
105
        OBJECT = 1,
106
        LIGHT = 2,
107
        CAMERA = 3,
108
        BONE = 4
109
    } type; // type of node
110
111
    // if object: path
112
    std::string path;
113
    unsigned int id;
114
115
    // number of object
116
    unsigned int number;
117
118
    // index of parent index
119
    unsigned int parent;
120
121
    // lights & cameras & dummies: name
122
    const char *name;
123
124
    // animation channels
125
    std::list<LWO::Envelope> channels;
126
127
    // position of pivot point
128
    aiVector3D pivotPos;
129
    bool isPivotSet;
130
131
    // color of light source
132
    aiColor3D lightColor;
133
134
    // intensity of light source
135
    float lightIntensity;
136
137
    // type of light source
138
    unsigned int lightType;
139
140
    // falloff type of light source
141
    unsigned int lightFalloffType;
142
143
    // cone angle of (spot) light source
144
    float lightConeAngle;
145
146
    // soft cone angle of (spot) light source
147
    float lightEdgeAngle;
148
149
    // list of resolved children
150
    std::list<NodeDesc *> children;
151
152
    // resolved parent node
153
    NodeDesc *parent_resolved;
154
155
    // for std::find()
156
5.37M
    bool operator==(unsigned int num) const {
157
5.37M
        if (!num)
158
5.37M
            return false;
159
923
        unsigned int _type = num >> 28u;
160
161
923
        return _type == static_cast<unsigned int>(type) && (num & AI_LWS_MASK) == number;
162
5.37M
    }
163
};
164
165
} // end namespace LWS
166
167
// ---------------------------------------------------------------------------
168
/** LWS (LightWave Scene Format) importer class.
169
 *
170
 *  This class does heavily depend on the LWO importer class. LWS files
171
 *  contain mainly descriptions how LWO objects are composed together
172
 *  in a scene.
173
*/
174
class LWSImporter : public BaseImporter {
175
public:
176
    LWSImporter();
177
    ~LWSImporter() override = default;
178
179
    // -------------------------------------------------------------------
180
    // Check whether we can read a specific file
181
    bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
182
            bool checkSig) const override;
183
184
protected:
185
    // -------------------------------------------------------------------
186
    // Get list of supported extensions
187
    const aiImporterDesc *GetInfo() const override;
188
189
    // -------------------------------------------------------------------
190
    // Import file into given scene data structure
191
    void InternReadFile(const std::string &pFile, aiScene *pScene,
192
            IOSystem *pIOHandler) override;
193
194
    // -------------------------------------------------------------------
195
    // Setup import properties
196
    void SetupProperties(const Importer *pImp) override;
197
198
private:
199
    // -------------------------------------------------------------------
200
    // Read an envelope description
201
    void ReadEnvelope(const LWS::Element &dad, LWO::Envelope &out);
202
203
    // -------------------------------------------------------------------
204
    // Read an envelope description for the older LW file format
205
    void ReadEnvelope_Old(std::list<LWS::Element>::const_iterator &it,
206
            const std::list<LWS::Element>::const_iterator &end,
207
            LWS::NodeDesc &nodes,
208
            unsigned int version);
209
210
    // -------------------------------------------------------------------
211
    // Setup a nice name for a node
212
    void SetupNodeName(aiNode *nd, LWS::NodeDesc &src);
213
214
    // -------------------------------------------------------------------
215
    // Recursively build the scenegraph
216
    void BuildGraph(aiNode *nd,
217
            LWS::NodeDesc &src,
218
            std::vector<AttachmentInfo> &attach,
219
            BatchLoader &batch,
220
            aiCamera **&camOut,
221
            aiLight **&lightOut,
222
            std::vector<aiNodeAnim *> &animOut);
223
224
    // -------------------------------------------------------------------
225
    // Try several dirs until we find the right location of a LWS file.
226
    std::string FindLWOFile(const std::string &in);
227
228
private:
229
    bool configSpeedFlag;
230
    IOSystem *io;
231
    double first, last, fps;
232
    bool noSkeletonMesh;
233
};
234
235
} // end of namespace Assimp
236
237
#endif // AI_LWSIMPORTER_H_INC