Coverage Report

Created: 2025-11-11 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/AssetLib/3DS/3DSLoader.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  3DSLoader.h
43
 *  @brief 3DS File format loader
44
 */
45
#ifndef AI_3DSIMPORTER_H_INC
46
#define AI_3DSIMPORTER_H_INC
47
#ifndef ASSIMP_BUILD_NO_3DS_IMPORTER
48
49
#include <assimp/BaseImporter.h>
50
#include <assimp/types.h>
51
52
#include "3DSHelper.h"
53
#include <assimp/StreamReader.h>
54
55
struct aiNode;
56
57
namespace Assimp {
58
59
// ---------------------------------------------------------------------------------
60
/** Importer class for 3D Studio r3 and r4 3DS files
61
 */
62
class Discreet3DSImporter final : public BaseImporter {
63
public:
64
    Discreet3DSImporter();
65
891
    ~Discreet3DSImporter() override = default;
66
67
    // -------------------------------------------------------------------
68
    /** Returns whether the class can handle the format of the given file.
69
     * See BaseImporter::CanRead() for details.
70
     */
71
    bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
72
        bool checkSig) const override;
73
74
    // -------------------------------------------------------------------
75
    /** Called prior to ReadFile().
76
     * The function is a request to the importer to update its configuration
77
     * basing on the Importer's configuration property list.
78
     */
79
    void SetupProperties(const Importer* pImp) override;
80
81
protected:
82
83
    // -------------------------------------------------------------------
84
    /** Return importer meta information.
85
     * See #BaseImporter::GetInfo for the details
86
     */
87
    const aiImporterDesc* GetInfo () const override;
88
89
    // -------------------------------------------------------------------
90
    /** Imports the given file into the given scene structure.
91
     * See BaseImporter::InternReadFile() for details
92
     */
93
    void InternReadFile( const std::string& pFile, aiScene* pScene,
94
        IOSystem* pIOHandler) override;
95
96
    // -------------------------------------------------------------------
97
    /** Converts a temporary material to the outer representation
98
     */
99
    void ConvertMaterial(D3DS::Material& p_cMat, aiMaterial& p_pcOut);
100
101
    // -------------------------------------------------------------------
102
    /** Read a chunk
103
     *
104
     *  @param pcOut Receives the current chunk
105
     */
106
    void ReadChunk(D3DS::Discreet3DS::Chunk* pcOut);
107
108
    // -------------------------------------------------------------------
109
    /** Parse a percentage chunk. mCurrent will point to the next
110
    * chunk behind afterwards. If no percentage chunk is found
111
    * QNAN is returned.
112
    */
113
    ai_real ParsePercentageChunk();
114
115
    // -------------------------------------------------------------------
116
    /** Parse a color chunk. mCurrent will point to the next chunk behind
117
     * afterward. If no color chunk is found QNAN is returned in all members.
118
     */
119
    void ParseColorChunk(aiColor3D* p_pcOut, bool p_bAcceptPercent = true);
120
121
    // -------------------------------------------------------------------
122
    /** Skip a chunk in the file
123
    */
124
    void SkipChunk();
125
126
    // -------------------------------------------------------------------
127
    /** Generate the node-graph
128
    */
129
    void GenerateNodeGraph(aiScene* pcOut);
130
131
    // -------------------------------------------------------------------
132
    /** Parse a main top-level chunk in the file
133
    */
134
    void ParseMainChunk();
135
136
    // -------------------------------------------------------------------
137
    /** Parse a top-level chunk in the file
138
    */
139
    void ParseChunk(const char* name, unsigned int num);
140
141
    // -------------------------------------------------------------------
142
    /** Parse a top-level editor chunk in the file
143
    */
144
    void ParseEditorChunk();
145
146
    // -------------------------------------------------------------------
147
    /** Parse a top-level object chunk in the file
148
    */
149
    void ParseObjectChunk();
150
151
    // -------------------------------------------------------------------
152
    /** Parse a material chunk in the file
153
    */
154
    void ParseMaterialChunk();
155
156
    // -------------------------------------------------------------------
157
    /** Parse a mesh chunk in the file
158
    */
159
    void ParseMeshChunk();
160
161
    // -------------------------------------------------------------------
162
    /** Parse a light chunk in the file
163
    */
164
    void ParseLightChunk();
165
166
    // -------------------------------------------------------------------
167
    /** Parse a camera chunk in the file
168
    */
169
    void ParseCameraChunk();
170
171
    // -------------------------------------------------------------------
172
    /** Parse a face list chunk in the file
173
    */
174
    void ParseFaceChunk();
175
176
    // -------------------------------------------------------------------
177
    /** Parse a keyframe chunk in the file
178
    */
179
    void ParseKeyframeChunk();
180
181
    // -------------------------------------------------------------------
182
    /** Parse a hierarchy chunk in the file
183
    */
184
    void ParseHierarchyChunk(uint16_t parent);
185
186
    // -------------------------------------------------------------------
187
    /** Parse a texture chunk in the file
188
    */
189
    void ParseTextureChunk(D3DS::Texture* pcOut);
190
191
    // -------------------------------------------------------------------
192
    /** Convert the meshes in the file
193
    */
194
    void ConvertMeshes(aiScene* pcOut);
195
196
    // -------------------------------------------------------------------
197
    /** Replace the default material in the scene
198
    */
199
    void ReplaceDefaultMaterial();
200
201
0
    bool ContainsTextures(unsigned int i) const {
202
0
        return !mScene->mMaterials[i].sTexDiffuse.mMapName.empty() ||
203
0
               !mScene->mMaterials[i].sTexBump.mMapName.empty() ||
204
0
               !mScene->mMaterials[i].sTexOpacity.mMapName.empty() ||
205
0
               !mScene->mMaterials[i].sTexEmissive.mMapName.empty() ||
206
0
               !mScene->mMaterials[i].sTexSpecular.mMapName.empty() ||
207
0
               !mScene->mMaterials[i].sTexShininess.mMapName.empty() ;
208
0
    }
209
210
    // -------------------------------------------------------------------
211
    /** Convert the whole scene
212
    */
213
    void ConvertScene(aiScene* pcOut);
214
215
    // -------------------------------------------------------------------
216
    /** generate unique vertices for a mesh
217
    */
218
    void MakeUnique(D3DS::Mesh& sMesh);
219
220
    // -------------------------------------------------------------------
221
    /** Add a node to the node graph
222
    */
223
    void AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut, D3DS::Node* pcIn,
224
        aiMatrix4x4& absTrafo);
225
226
    // -------------------------------------------------------------------
227
    /** Search for a node in the graph.
228
    * Called recursively
229
    */
230
    void InverseNodeSearch(D3DS::Node* pcNode, D3DS::Node* pcCurrent);
231
232
    // -------------------------------------------------------------------
233
    /** Apply the master scaling factor to the mesh
234
    */
235
    void ApplyMasterScale(const aiScene* pScene);
236
237
    // -------------------------------------------------------------------
238
    /** Clamp all indices in the file to a valid range
239
    */
240
    void CheckIndices(D3DS::Mesh& sMesh);
241
242
    // -------------------------------------------------------------------
243
    /** Skip the TCB info in a track key
244
    */
245
    void SkipTCBInfo();
246
247
private:
248
    /// Stream to read from
249
    StreamReaderLE* mStream;
250
    /// Last touched node index
251
    short mLastNodeIndex;
252
    /// Current node
253
    D3DS::Node* mCurrentNode;
254
    /// Root node
255
    D3DS::Node *mRootNode;
256
    /// Scene under construction
257
    D3DS::Scene* mScene;
258
    /// Ambient base color of the scene
259
    aiColor3D mClrAmbient;
260
    /// Master scaling factor of the scene
261
    ai_real mMasterScale;
262
    /// Path to the background image of the scene
263
    std::string mBackgroundImage;
264
    /// true for has a background
265
    bool bHasBG;
266
    /// true if PRJ file
267
    bool bIsPrj;
268
};
269
270
} // end of namespace Assimp
271
272
#endif // !! ASSIMP_BUILD_NO_3DS_IMPORTER
273
274
#endif // AI_3DSIMPORTER_H_INC