Coverage Report

Created: 2026-01-25 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/AssetLib/FBX/FBXModel.cpp
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  FBXModel.cpp
43
 *  @brief Assimp::FBX::Model implementation
44
 */
45
46
#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
47
48
#include "FBXDocument.h"
49
#include "FBXDocumentUtil.h"
50
#include "FBXImporter.h"
51
#include "FBXMeshGeometry.h"
52
#include "FBXParser.h"
53
54
namespace Assimp {
55
namespace FBX {
56
57
using namespace Util;
58
59
// ------------------------------------------------------------------------------------------------
60
Model::Model(uint64_t id, const Element &element, const Document &doc, const std::string &name) :
61
17.9k
        Object(id, element, name), shading("Y") {
62
17.9k
    const Scope &sc = GetRequiredScope(element);
63
17.9k
    const Element *const Shading = sc["Shading"];
64
17.9k
    const Element *const Culling = sc["Culling"];
65
66
17.9k
    if (Shading) {
67
17.7k
        shading = GetRequiredToken(*Shading, 0).StringContents();
68
17.7k
    }
69
70
17.9k
    if (Culling) {
71
17.7k
        culling = ParseTokenAsString(GetRequiredToken(*Culling, 0));
72
17.7k
    }
73
74
17.9k
    props = GetPropertyTable(doc, "Model.FbxNode", element, sc);
75
17.9k
    ResolveLinks(element, doc);
76
17.9k
}
77
78
// ------------------------------------------------------------------------------------------------
79
17.9k
void Model::ResolveLinks(const Element&, const Document &doc) {
80
17.9k
    const char *const arr[] = { "Geometry", "Material", "NodeAttribute" };
81
82
    // resolve material
83
17.9k
    const std::vector<const Connection *> &conns = doc.GetConnectionsByDestinationSequenced(ID(), arr, 3);
84
85
17.9k
    materials.reserve(conns.size());
86
17.9k
    geometry.reserve(conns.size());
87
17.9k
    attributes.reserve(conns.size());
88
27.7k
    for (const Connection *con : conns) {
89
90
        // material and geometry links should be Object-Object connections
91
27.7k
        if (con->PropertyName().length()) {
92
0
            continue;
93
0
        }
94
95
27.7k
        const Object *const ob = con->SourceObject();
96
27.7k
        if (!ob) {
97
4.77k
            DOMWarning("failed to read source object for incoming Model link, ignoring", &element);
98
4.77k
            continue;
99
4.77k
        }
100
101
22.9k
        const Material *const mat = dynamic_cast<const Material *>(ob);
102
22.9k
        if (mat) {
103
10.0k
            materials.push_back(mat);
104
10.0k
            continue;
105
10.0k
        }
106
107
12.8k
        const Geometry *const geo = dynamic_cast<const Geometry *>(ob);
108
12.8k
        if (geo) {
109
5.90k
            geometry.push_back(geo);
110
5.90k
            continue;
111
5.90k
        }
112
113
6.96k
        const NodeAttribute *const att = dynamic_cast<const NodeAttribute *>(ob);
114
6.96k
        if (att) {
115
6.96k
            attributes.push_back(att);
116
6.96k
            continue;
117
6.96k
        }
118
119
1
        DOMWarning("source object for model link is neither Material, NodeAttribute nor Geometry, ignoring", &element);
120
1
        continue;
121
6.96k
    }
122
17.9k
}
123
124
// ------------------------------------------------------------------------------------------------
125
16.2k
bool Model::IsNull() const {
126
16.2k
    const std::vector<const NodeAttribute *> &attrs = GetAttributes();
127
16.2k
    for (const NodeAttribute *att : attrs) {
128
129
5.43k
        const Null *null_tag = dynamic_cast<const Null *>(att);
130
5.43k
        if (null_tag) {
131
360
            return true;
132
360
        }
133
5.43k
    }
134
135
15.9k
    return false;
136
16.2k
}
137
138
} // namespace FBX
139
} // namespace Assimp
140
141
#endif