Coverage Report

Created: 2026-03-12 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/AssetLib/FBX/FBXDocumentUtil.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
/** @file  FBXDocumentUtil.cpp
42
 *  @brief Implementation of the FBX DOM utility functions declared in FBXDocumentUtil.h
43
 */
44
45
#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
46
47
#include "FBXParser.h"
48
#include "FBXDocument.h"
49
#include "FBXUtil.h"
50
#include "FBXDocumentUtil.h"
51
#include "FBXProperties.h"
52
53
54
namespace Assimp {
55
namespace FBX {
56
namespace Util {
57
58
// ------------------------------------------------------------------------------------------------
59
// signal DOM construction error, this is always unrecoverable. Throws DeadlyImportError.
60
281
void DOMError(const std::string& message, const Token& token) {
61
281
    throw DeadlyImportError("FBX-DOM", Util::GetTokenText(&token), message);
62
281
}
63
64
// ------------------------------------------------------------------------------------------------
65
301
void DOMError(const std::string& message, const Element* element /*= nullptr*/) {
66
301
    if(element) {
67
281
        DOMError(message,element->KeyToken());
68
281
    }
69
20
    throw DeadlyImportError("FBX-DOM ", message);
70
301
}
71
72
73
// ------------------------------------------------------------------------------------------------
74
// print warning, do return
75
17.6k
void DOMWarning(const std::string& message, const Token& token) {
76
17.6k
    if(DefaultLogger::get()) {
77
17.6k
        ASSIMP_LOG_WARN("FBX-DOM", Util::GetTokenText(&token), message);
78
17.6k
    }
79
17.6k
}
80
81
// ------------------------------------------------------------------------------------------------
82
17.8k
void DOMWarning(const std::string& message, const Element* element /*= nullptr*/) {
83
17.8k
    if(element) {
84
17.6k
        DOMWarning(message,element->KeyToken());
85
17.6k
        return;
86
17.6k
    }
87
158
    if(DefaultLogger::get()) {
88
158
        ASSIMP_LOG_WARN("FBX-DOM: ", message);
89
158
    }
90
158
}
91
92
// ------------------------------------------------------------------------------------------------
93
// fetch a property table and the corresponding property template
94
std::shared_ptr<const PropertyTable> GetPropertyTable(const Document& doc,
95
        const std::string& templateName,
96
        const Element &element,
97
        const Scope& sc,
98
23.9k
        bool no_warn /*= false*/) {
99
23.9k
    const Element* const Properties70 = sc["Properties70"];
100
23.9k
    std::shared_ptr<const PropertyTable> templateProps = std::shared_ptr<const PropertyTable>(
101
23.9k
            static_cast<const PropertyTable *>(nullptr));
102
103
23.9k
    if (templateName.length()) {
104
23.6k
        PropertyTemplateMap::const_iterator it = doc.Templates().find(templateName);
105
23.6k
        if(it != doc.Templates().end()) {
106
15.7k
            templateProps = (*it).second;
107
15.7k
        }
108
23.6k
    }
109
110
23.9k
    if (!Properties70 || !Properties70->Compound()) {
111
3.65k
        if(!no_warn) {
112
306
            DOMWarning("property table (Properties70) not found",&element);
113
306
        }
114
3.65k
        if(templateProps) {
115
479
            return templateProps;
116
3.17k
        } else {
117
3.17k
            return std::make_shared<const PropertyTable>();
118
3.17k
        }
119
3.65k
    }
120
20.3k
    return std::make_shared<const PropertyTable>(*Properties70,templateProps);
121
23.9k
}
122
123
} // !Util
124
} // !FBX
125
} // !Assimp
126
127
#endif // ASSIMP_BUILD_NO_FBX_IMPORTER