Coverage Report

Created: 2025-08-26 06:41

/src/assimp/code/AssetLib/FBX/FBXDocumentUtil.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
/** @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
0
void DOMError(const std::string& message, const Token& token) {
61
0
    throw DeadlyImportError("FBX-DOM", Util::GetTokenText(&token), message);
62
0
}
63
64
// ------------------------------------------------------------------------------------------------
65
0
void DOMError(const std::string& message, const Element* element /*= nullptr*/) {
66
0
    if(element) {
67
0
        DOMError(message,element->KeyToken());
68
0
    }
69
0
    throw DeadlyImportError("FBX-DOM ", message);
70
0
}
71
72
73
// ------------------------------------------------------------------------------------------------
74
// print warning, do return
75
0
void DOMWarning(const std::string& message, const Token& token) {
76
0
    if(DefaultLogger::get()) {
77
0
        ASSIMP_LOG_WARN("FBX-DOM", Util::GetTokenText(&token), message);
78
0
    }
79
0
}
80
81
// ------------------------------------------------------------------------------------------------
82
0
void DOMWarning(const std::string& message, const Element* element /*= nullptr*/) {
83
0
    if(element) {
84
0
        DOMWarning(message,element->KeyToken());
85
0
        return;
86
0
    }
87
0
    if(DefaultLogger::get()) {
88
0
        ASSIMP_LOG_WARN("FBX-DOM: ", message);
89
0
    }
90
0
}
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
0
        bool no_warn /*= false*/) {
99
0
    const Element* const Properties70 = sc["Properties70"];
100
0
    std::shared_ptr<const PropertyTable> templateProps = std::shared_ptr<const PropertyTable>(
101
0
            static_cast<const PropertyTable *>(nullptr));
102
103
0
    if (templateName.length()) {
104
0
        PropertyTemplateMap::const_iterator it = doc.Templates().find(templateName);
105
0
        if(it != doc.Templates().end()) {
106
0
            templateProps = (*it).second;
107
0
        }
108
0
    }
109
110
0
    if (!Properties70 || !Properties70->Compound()) {
111
0
        if(!no_warn) {
112
0
            DOMWarning("property table (Properties70) not found",&element);
113
0
        }
114
0
        if(templateProps) {
115
0
            return templateProps;
116
0
        } else {
117
0
            return std::make_shared<const PropertyTable>();
118
0
        }
119
0
    }
120
0
    return std::make_shared<const PropertyTable>(*Properties70,templateProps);
121
0
}
122
123
} // !Util
124
} // !FBX
125
} // !Assimp
126
127
#endif // ASSIMP_BUILD_NO_FBX_IMPORTER