vrshoot

view libs/assimp/FBXDocumentUtil.cpp @ 0:b2f14e535253

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