vrshoot

view libs/assimp/FBXProperties.cpp @ 2:334d17aed7de

visual studio project files
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Feb 2014 18:36:38 +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 FBXProperties.cpp
42 * @brief Implementation of the FBX dynamic properties system
43 */
44 #include "AssimpPCH.h"
46 #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
48 #include "FBXTokenizer.h"
49 #include "FBXParser.h"
50 #include "FBXDocument.h"
51 #include "FBXDocumentUtil.h"
52 #include "FBXProperties.h"
54 namespace Assimp {
55 namespace FBX {
57 using namespace Util;
59 // ------------------------------------------------------------------------------------------------
60 Property::Property()
61 {
62 }
64 // ------------------------------------------------------------------------------------------------
65 Property::~Property()
66 {
67 }
69 namespace {
71 // ------------------------------------------------------------------------------------------------
72 // read a typed property out of a FBX element. The return value is NULL if the property cannot be read.
73 Property* ReadTypedProperty(const Element& element)
74 {
75 ai_assert(element.KeyToken().StringContents() == "P");
77 const TokenList& tok = element.Tokens();
78 ai_assert(tok.size() >= 5);
80 const std::string& s = ParseTokenAsString(*tok[1]);
81 const char* const cs = s.c_str();
82 if (!strcmp(cs,"KString")) {
83 return new TypedProperty<std::string>(ParseTokenAsString(*tok[4]));
84 }
85 else if (!strcmp(cs,"bool") || !strcmp(cs,"Bool")) {
86 return new TypedProperty<bool>(ParseTokenAsInt(*tok[4]) != 0);
87 }
88 else if (!strcmp(cs,"int") || !strcmp(cs,"enum")) {
89 return new TypedProperty<int>(ParseTokenAsInt(*tok[4]));
90 }
91 else if (!strcmp(cs,"ULongLong")) {
92 return new TypedProperty<uint64_t>(ParseTokenAsID(*tok[4]));
93 }
94 else if (!strcmp(cs,"Vector3D") ||
95 !strcmp(cs,"ColorRGB") ||
96 !strcmp(cs,"Vector") ||
97 !strcmp(cs,"Color") ||
98 !strcmp(cs,"Lcl Translation") ||
99 !strcmp(cs,"Lcl Rotation") ||
100 !strcmp(cs,"Lcl Scaling")
101 ) {
102 return new TypedProperty<aiVector3D>(aiVector3D(
103 ParseTokenAsFloat(*tok[4]),
104 ParseTokenAsFloat(*tok[5]),
105 ParseTokenAsFloat(*tok[6]))
106 );
107 }
108 else if (!strcmp(cs,"double") || !strcmp(cs,"Number") || !strcmp(cs,"KTime") || !strcmp(cs,"Float")) {
109 return new TypedProperty<float>(ParseTokenAsFloat(*tok[4]));
110 }
111 return NULL;
112 }
115 // ------------------------------------------------------------------------------------------------
116 // peek into an element and check if it contains a FBX property, if so return its name.
117 std::string PeekPropertyName(const Element& element)
118 {
119 ai_assert(element.KeyToken().StringContents() == "P");
120 const TokenList& tok = element.Tokens();
121 if(tok.size() < 4) {
122 return "";
123 }
125 return ParseTokenAsString(*tok[0]);
126 }
128 } //! anon
131 // ------------------------------------------------------------------------------------------------
132 PropertyTable::PropertyTable()
133 : templateProps()
134 , element()
135 {
136 }
139 // ------------------------------------------------------------------------------------------------
140 PropertyTable::PropertyTable(const Element& element, boost::shared_ptr<const PropertyTable> templateProps)
141 : templateProps(templateProps)
142 , element(&element)
143 {
144 const Scope& scope = GetRequiredScope(element);
145 BOOST_FOREACH(const ElementMap::value_type& v, scope.Elements()) {
146 if(v.first != "P") {
147 DOMWarning("expected only P elements in property table",v.second);
148 continue;
149 }
151 const std::string& name = PeekPropertyName(*v.second);
152 if(!name.length()) {
153 DOMWarning("could not read property name",v.second);
154 continue;
155 }
157 LazyPropertyMap::const_iterator it = lazyProps.find(name);
158 if (it != lazyProps.end()) {
159 DOMWarning("duplicate property name, will hide previous value: " + name,v.second);
160 continue;
161 }
163 lazyProps[name] = v.second;
164 }
165 }
168 // ------------------------------------------------------------------------------------------------
169 PropertyTable::~PropertyTable()
170 {
171 BOOST_FOREACH(PropertyMap::value_type& v, props) {
172 delete v.second;
173 }
174 }
177 // ------------------------------------------------------------------------------------------------
178 const Property* PropertyTable::Get(const std::string& name) const
179 {
180 PropertyMap::const_iterator it = props.find(name);
181 if (it == props.end()) {
182 // hasn't been parsed yet?
183 LazyPropertyMap::const_iterator lit = lazyProps.find(name);
184 if(lit != lazyProps.end()) {
185 props[name] = ReadTypedProperty(*(*lit).second);
186 it = props.find(name);
188 ai_assert(it != props.end());
189 }
191 if (it == props.end()) {
192 // check property template
193 if(templateProps) {
194 return templateProps->Get(name);
195 }
197 return NULL;
198 }
199 }
201 return (*it).second;
202 }
204 } //! FBX
205 } //! Assimp
207 #endif