Coverage Report

Created: 2026-09-14 07:44

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
30.6k
        Object(id, element, name), shading("Y") {
62
30.6k
    const Scope &sc = GetRequiredScope(element);
63
30.6k
    const Element *const Shading = sc["Shading"];
64
30.6k
    const Element *const Culling = sc["Culling"];
65
66
30.6k
    if (Shading) {
67
23.8k
        shading = GetRequiredToken(*Shading, 0).StringContents();
68
23.8k
    }
69
70
30.6k
    if (Culling) {
71
23.7k
        culling = ParseTokenAsString(GetRequiredToken(*Culling, 0));
72
23.7k
    }
73
74
30.6k
    props = GetPropertyTable(doc, "Model.FbxNode", element, sc);
75
30.6k
    ResolveLinks(element, doc);
76
30.6k
}
77
78
// ------------------------------------------------------------------------------------------------
79
30.5k
void Model::ResolveLinks(const Element&, const Document &doc) {
80
30.5k
    const char *const arr[] = { "Geometry", "Material", "NodeAttribute" };
81
82
    // resolve material
83
30.5k
    const std::vector<const Connection *> &conns = doc.GetConnectionsByDestinationSequenced(ID(), arr, 3);
84
85
30.5k
    materials.reserve(conns.size());
86
30.5k
    geometry.reserve(conns.size());
87
30.5k
    attributes.reserve(conns.size());
88
41.7k
    for (const Connection *con : conns) {
89
90
        // material and geometry links should be Object-Object connections
91
41.7k
        if (con->PropertyName().length()) {
92
4
            continue;
93
4
        }
94
95
41.7k
        const Object *const ob = con->SourceObject();
96
41.7k
        if (!ob) {
97
9.29k
            DOMWarning("failed to read source object for incoming Model link, ignoring", &element);
98
9.29k
            continue;
99
9.29k
        }
100
101
32.4k
        const Material *const mat = dynamic_cast<const Material *>(ob);
102
32.4k
        if (mat) {
103
11.3k
            materials.push_back(mat);
104
11.3k
            continue;
105
11.3k
        }
106
107
21.0k
        const Geometry *const geo = dynamic_cast<const Geometry *>(ob);
108
21.0k
        if (geo) {
109
8.33k
            geometry.push_back(geo);
110
8.33k
            continue;
111
8.33k
        }
112
113
12.7k
        const NodeAttribute *const att = dynamic_cast<const NodeAttribute *>(ob);
114
12.7k
        if (att) {
115
12.6k
            attributes.push_back(att);
116
12.6k
            continue;
117
12.6k
        }
118
119
59
        DOMWarning("source object for model link is neither Material, NodeAttribute nor Geometry, ignoring", &element);
120
59
        continue;
121
12.7k
    }
122
30.5k
}
123
124
// ------------------------------------------------------------------------------------------------
125
69.5k
bool Model::IsNull() const {
126
69.5k
    const std::vector<const NodeAttribute *> &attrs = GetAttributes();
127
69.5k
    for (const NodeAttribute *att : attrs) {
128
129
7.69k
        const Null *null_tag = dynamic_cast<const Null *>(att);
130
7.69k
        if (null_tag) {
131
774
            return true;
132
774
        }
133
7.69k
    }
134
135
68.7k
    return false;
136
69.5k
}
137
138
} // namespace FBX
139
} // namespace Assimp
140
141
#endif