1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4
5 Copyright (c) 2006-2019, assimp team
6
7
8 All rights reserved.
9
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the
12 following conditions are met:
13
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
17
18 * Redistributions in binary form must reproduce the above
19 copyright notice, this list of conditions and the
20 following disclaimer in the documentation and/or other
21 materials provided with the distribution.
22
23 * Neither the name of the assimp team, nor the names of its
24 contributors may be used to endorse or promote products
25 derived from this software without specific prior
26 written permission of the assimp team.
27
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
40 ----------------------------------------------------------------------
41 */
42
43 /** @file FBXDocumentUtil.cpp
44 * @brief Implementation of the FBX DOM utility functions declared in FBXDocumentUtil.h
45 */
46
47 #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
48
49 #include "FBXParser.h"
50 #include "FBXDocument.h"
51 #include "FBXUtil.h"
52 #include "FBXDocumentUtil.h"
53 #include "FBXProperties.h"
54
55
56 namespace Assimp {
57 namespace FBX {
58 namespace Util {
59
60 // ------------------------------------------------------------------------------------------------
61 // signal DOM construction error, this is always unrecoverable. Throws DeadlyImportError.
DOMError(const std::string & message,const Token & token)62 void DOMError(const std::string& message, const Token& token)
63 {
64 throw DeadlyImportError(Util::AddTokenText("FBX-DOM",message,&token));
65 }
66
67 // ------------------------------------------------------------------------------------------------
DOMError(const std::string & message,const Element * element)68 void DOMError(const std::string& message, const Element* element /*= NULL*/)
69 {
70 if(element) {
71 DOMError(message,element->KeyToken());
72 }
73 throw DeadlyImportError("FBX-DOM " + message);
74 }
75
76
77 // ------------------------------------------------------------------------------------------------
78 // print warning, do return
DOMWarning(const std::string & message,const Token & token)79 void DOMWarning(const std::string& message, const Token& token)
80 {
81 if(DefaultLogger::get()) {
82 ASSIMP_LOG_WARN(Util::AddTokenText("FBX-DOM",message,&token));
83 }
84 }
85
86 // ------------------------------------------------------------------------------------------------
DOMWarning(const std::string & message,const Element * element)87 void DOMWarning(const std::string& message, const Element* element /*= NULL*/)
88 {
89 if(element) {
90 DOMWarning(message,element->KeyToken());
91 return;
92 }
93 if(DefaultLogger::get()) {
94 ASSIMP_LOG_WARN("FBX-DOM: " + message);
95 }
96 }
97
98
99 // ------------------------------------------------------------------------------------------------
100 // fetch a property table and the corresponding property template
GetPropertyTable(const Document & doc,const std::string & templateName,const Element & element,const Scope & sc,bool no_warn)101 std::shared_ptr<const PropertyTable> GetPropertyTable(const Document& doc,
102 const std::string& templateName,
103 const Element &element,
104 const Scope& sc,
105 bool no_warn /*= false*/)
106 {
107 const Element* const Properties70 = sc["Properties70"];
108 std::shared_ptr<const PropertyTable> templateProps = std::shared_ptr<const PropertyTable>(
109 static_cast<const PropertyTable*>(NULL));
110
111 if(templateName.length()) {
112 PropertyTemplateMap::const_iterator it = doc.Templates().find(templateName);
113 if(it != doc.Templates().end()) {
114 templateProps = (*it).second;
115 }
116 }
117
118 if(!Properties70 || !Properties70->Compound()) {
119 if(!no_warn) {
120 DOMWarning("property table (Properties70) not found",&element);
121 }
122 if(templateProps) {
123 return templateProps;
124 }
125 else {
126 return std::make_shared<const PropertyTable>();
127 }
128 }
129 return std::make_shared<const PropertyTable>(*Properties70,templateProps);
130 }
131 } // !Util
132 } // !FBX
133 } // !Assimp
134
135 #endif
136