vrshoot
diff libs/assimp/FBXProperties.h @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/FBXProperties.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,188 @@ 1.4 +/* 1.5 +Open Asset Import Library (assimp) 1.6 +---------------------------------------------------------------------- 1.7 + 1.8 +Copyright (c) 2006-2012, assimp team 1.9 +All rights reserved. 1.10 + 1.11 +Redistribution and use of this software in source and binary forms, 1.12 +with or without modification, are permitted provided that the 1.13 +following conditions are met: 1.14 + 1.15 +* Redistributions of source code must retain the above 1.16 + copyright notice, this list of conditions and the 1.17 + following disclaimer. 1.18 + 1.19 +* Redistributions in binary form must reproduce the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer in the documentation and/or other 1.22 + materials provided with the distribution. 1.23 + 1.24 +* Neither the name of the assimp team, nor the names of its 1.25 + contributors may be used to endorse or promote products 1.26 + derived from this software without specific prior 1.27 + written permission of the assimp team. 1.28 + 1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.40 + 1.41 +---------------------------------------------------------------------- 1.42 +*/ 1.43 + 1.44 +/** @file FBXProperties.h 1.45 + * @brief FBX dynamic properties 1.46 + */ 1.47 +#ifndef INCLUDED_AI_FBX_PROPERTIES_H 1.48 +#define INCLUDED_AI_FBX_PROPERTIES_H 1.49 + 1.50 +#include <map> 1.51 +#include <string> 1.52 + 1.53 +namespace Assimp { 1.54 +namespace FBX { 1.55 + 1.56 + class Element; 1.57 + 1.58 + 1.59 +/** Represents a dynamic property. Type info added by deriving classes, 1.60 + * see #TypedProperty. 1.61 + Example: 1.62 + @verbatim 1.63 + P: "ShininessExponent", "double", "Number", "",0.5 1.64 + @endvebatim 1.65 + 1.66 +*/ 1.67 +class Property 1.68 +{ 1.69 +protected: 1.70 + 1.71 + Property(); 1.72 + 1.73 +public: 1.74 + 1.75 + virtual ~Property(); 1.76 + 1.77 +public: 1.78 + 1.79 + template <typename T> 1.80 + const T* As() const { 1.81 + return dynamic_cast<const T*>(this); 1.82 + } 1.83 +}; 1.84 + 1.85 + 1.86 +template<typename T> 1.87 +class TypedProperty : public Property 1.88 +{ 1.89 +public: 1.90 + 1.91 + TypedProperty(const T& value) 1.92 + : value(value) 1.93 + { 1.94 + } 1.95 + 1.96 +public: 1.97 + 1.98 + const T& Value() const { 1.99 + return value; 1.100 + } 1.101 + 1.102 +private: 1.103 + T value; 1.104 +}; 1.105 + 1.106 + 1.107 +typedef std::fbx_unordered_map<std::string,const Property*> PropertyMap; 1.108 +typedef std::fbx_unordered_map<std::string,const Element*> LazyPropertyMap; 1.109 + 1.110 +/** Represents a property table as can be found in the newer FBX files (Properties60, Properties70)*/ 1.111 +class PropertyTable 1.112 +{ 1.113 +public: 1.114 + 1.115 + // in-memory property table with no source element 1.116 + PropertyTable(); 1.117 + 1.118 + PropertyTable(const Element& element, boost::shared_ptr<const PropertyTable> templateProps); 1.119 + ~PropertyTable(); 1.120 + 1.121 +public: 1.122 + 1.123 + const Property* Get(const std::string& name) const; 1.124 + 1.125 + // PropertyTable's need not be coupled with FBX elements so this can be NULL 1.126 + const Element* GetElement() const { 1.127 + return element; 1.128 + } 1.129 + 1.130 + const PropertyTable* TemplateProps() const { 1.131 + return templateProps.get(); 1.132 + } 1.133 + 1.134 +private: 1.135 + 1.136 + LazyPropertyMap lazyProps; 1.137 + mutable PropertyMap props; 1.138 + const boost::shared_ptr<const PropertyTable> templateProps; 1.139 + const Element* const element; 1.140 +}; 1.141 + 1.142 + 1.143 +// ------------------------------------------------------------------------------------------------ 1.144 +template <typename T> 1.145 +inline T PropertyGet(const PropertyTable& in, const std::string& name, 1.146 + const T& defaultValue, 1.147 + bool ignoreTemplate = false) 1.148 +{ 1.149 + const Property* const prop = in.Get(name); 1.150 + if(!prop) { 1.151 + return defaultValue; 1.152 + } 1.153 + 1.154 + // strong typing, no need to be lenient 1.155 + const TypedProperty<T>* const tprop = prop->As< TypedProperty<T> >(); 1.156 + if(!tprop) { 1.157 + return defaultValue; 1.158 + } 1.159 + 1.160 + return tprop->Value(); 1.161 +} 1.162 + 1.163 + 1.164 +// ------------------------------------------------------------------------------------------------ 1.165 +template <typename T> 1.166 +inline T PropertyGet(const PropertyTable& in, const std::string& name, 1.167 + bool& result, 1.168 + bool ignoreTemplate = false) 1.169 +{ 1.170 + const Property* const prop = in.Get(name); 1.171 + if(!prop) { 1.172 + result = false; 1.173 + return T(); 1.174 + } 1.175 + 1.176 + // strong typing, no need to be lenient 1.177 + const TypedProperty<T>* const tprop = prop->As< TypedProperty<T> >(); 1.178 + if(!tprop) { 1.179 + result = false; 1.180 + return T(); 1.181 + } 1.182 + 1.183 + result = true; 1.184 + return tprop->Value(); 1.185 +} 1.186 + 1.187 + 1.188 +} //! FBX 1.189 +} //! Assimp 1.190 + 1.191 +#endif //