Coverage Report

Created: 2025-06-22 07:30

/src/assimp/code/AssetLib/FBX/FBXDeformer.cpp
Line
Count
Source (jump to first uncovered line)
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  FBXNoteAttribute.cpp
43
 *  @brief Assimp::FBX::NodeAttribute (and subclasses) implementation
44
 */
45
46
#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
47
48
#include "FBXParser.h"
49
#include "FBXDocument.h"
50
#include "FBXMeshGeometry.h"
51
#include "FBXImporter.h"
52
#include "FBXDocumentUtil.h"
53
54
namespace Assimp {
55
namespace FBX {
56
57
using namespace Util;
58
59
// ------------------------------------------------------------------------------------------------
60
Deformer::Deformer(uint64_t id, const Element& element, const Document& doc, const std::string& name) :
61
0
        Object(id,element,name) {
62
0
    const Scope& sc = GetRequiredScope(element);
63
64
0
    const std::string& classname = ParseTokenAsString(GetRequiredToken(element,2));
65
0
    props = GetPropertyTable(doc,"Deformer.Fbx" + classname,element,sc,true);
66
0
}
67
68
// ------------------------------------------------------------------------------------------------
69
Cluster::Cluster(uint64_t id, const Element& element, const Document& doc, const std::string& name)
70
0
: Deformer(id,element,doc,name)
71
, node()
72
0
{
73
0
    const Scope& sc = GetRequiredScope(element);
74
75
0
    const Element* const Indexes = sc["Indexes"];
76
0
    const Element* const Weights = sc["Weights"];
77
78
0
    const Element& Transform = GetRequiredElement(sc,"Transform",&element);
79
0
    const Element& TransformLink = GetRequiredElement(sc,"TransformLink",&element);
80
81
0
    transform = ReadMatrix(Transform);
82
0
    transformLink = ReadMatrix(TransformLink);
83
84
    // it is actually possible that there are Deformer's with no weights
85
0
    if (!!Indexes != !!Weights) {
86
0
        DOMError("either Indexes or Weights are missing from Cluster",&element);
87
0
    }
88
89
0
    if(Indexes) {
90
0
        ParseVectorDataArray(indices,*Indexes);
91
0
        ParseVectorDataArray(weights,*Weights);
92
0
    }
93
94
0
    if(indices.size() != weights.size()) {
95
0
        DOMError("sizes of index and weight array don't match up",&element);
96
0
    }
97
98
    // read assigned node
99
0
    const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(),"Model");
100
0
    for(const Connection* con : conns) {
101
0
        const Model* const mod = ProcessSimpleConnection<Model>(*con, false, "Model -> Cluster", element);
102
0
        if(mod) {
103
0
            node = mod;
104
0
            break;
105
0
        }
106
0
    }
107
108
0
    if (!node) {
109
0
        DOMError("failed to read target Node for Cluster",&element);
110
0
    }
111
0
}
112
113
// ------------------------------------------------------------------------------------------------
114
Skin::Skin(uint64_t id, const Element& element, const Document& doc, const std::string& name)
115
0
: Deformer(id,element,doc,name)
116
0
, accuracy( 0.0f ) {
117
0
    const Scope& sc = GetRequiredScope(element);
118
119
0
    const Element* const Link_DeformAcuracy = sc["Link_DeformAcuracy"];
120
0
    if(Link_DeformAcuracy) {
121
0
        accuracy = ParseTokenAsFloat(GetRequiredToken(*Link_DeformAcuracy,0));
122
0
    }
123
124
    // resolve assigned clusters
125
0
    const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(),"Deformer");
126
127
0
    clusters.reserve(conns.size());
128
0
    for(const Connection* con : conns) {
129
130
0
        const Cluster* const cluster = ProcessSimpleConnection<Cluster>(*con, false, "Cluster -> Skin", element);
131
0
        if(cluster) {
132
0
            clusters.push_back(cluster);
133
0
            continue;
134
0
        }
135
0
    }
136
0
}
137
138
// ------------------------------------------------------------------------------------------------
139
BlendShape::BlendShape(uint64_t id, const Element& element, const Document& doc, const std::string& name)
140
0
    : Deformer(id, element, doc, name)
141
0
{
142
0
    const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(), "Deformer");
143
0
    blendShapeChannels.reserve(conns.size());
144
0
    for (const Connection* con : conns) {
145
0
        const BlendShapeChannel* const bspc = ProcessSimpleConnection<BlendShapeChannel>(*con, false, "BlendShapeChannel -> BlendShape", element);
146
0
        if (bspc) {
147
0
            auto pr = blendShapeChannels.insert(bspc);
148
0
            if (!pr.second) {
149
0
                FBXImporter::LogWarn("there is the same blendShapeChannel id ", bspc->ID());
150
0
            }
151
0
        }
152
0
    }
153
0
}
154
155
// ------------------------------------------------------------------------------------------------
156
BlendShapeChannel::BlendShapeChannel(uint64_t id, const Element& element, const Document& doc, const std::string& name)
157
0
    : Deformer(id, element, doc, name)
158
0
{
159
0
    const Scope& sc = GetRequiredScope(element);
160
0
    const Element* const DeformPercent = sc["DeformPercent"];
161
0
    if (DeformPercent) {
162
0
        percent = ParseTokenAsFloat(GetRequiredToken(*DeformPercent, 0));
163
0
    }
164
0
    const Element* const FullWeights = sc["FullWeights"];
165
0
    if (FullWeights) {
166
0
        ParseVectorDataArray(fullWeights, *FullWeights);
167
0
    }
168
0
    const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(), "Geometry");
169
0
    shapeGeometries.reserve(conns.size());
170
0
    for (const Connection* con : conns) {
171
0
        const ShapeGeometry* const sg = ProcessSimpleConnection<ShapeGeometry>(*con, false, "Shape -> BlendShapeChannel", element);
172
0
        if (sg) {
173
0
            auto pr = shapeGeometries.insert(sg);
174
0
            if (!pr.second) {
175
0
                FBXImporter::LogWarn("there is the same shapeGeometrie id ", sg->ID());
176
0
            }
177
0
        }
178
0
    }
179
0
}
180
181
} // namespace FBX
182
} // Namespace Assimp
183
184
#endif // ASSIMP_BUILD_NO_FBX_IMPORTER