/src/assimp/code/AssetLib/FBX/FBXProperties.h
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 | | |
42 | | /** @file FBXProperties.h |
43 | | * @brief FBX dynamic properties |
44 | | */ |
45 | | #ifndef INCLUDED_AI_FBX_PROPERTIES_H |
46 | | #define INCLUDED_AI_FBX_PROPERTIES_H |
47 | | |
48 | | #include "FBXCompileConfig.h" |
49 | | #include <memory> |
50 | | #include <string> |
51 | | |
52 | | namespace Assimp { |
53 | | namespace FBX { |
54 | | |
55 | | // Forward declarations |
56 | | class Element; |
57 | | |
58 | | /** |
59 | | * Represents a dynamic property. Type info added by deriving classes, |
60 | | * see #TypedProperty. |
61 | | * Example: |
62 | | * |
63 | | * @verbatim |
64 | | * P: "ShininessExponent", "double", "Number", "",0.5 |
65 | | * @endvebatim |
66 | | */ |
67 | | class Property { |
68 | | |
69 | | public: |
70 | 0 | virtual ~Property() = default; |
71 | | |
72 | | template <typename T> |
73 | 0 | const T* As() const { |
74 | 0 | return dynamic_cast<const T*>(this); |
75 | 0 | } Unexecuted instantiation: Assimp::FBX::TypedProperty<aiVector3t<float> > const* Assimp::FBX::Property::As<Assimp::FBX::TypedProperty<aiVector3t<float> > >() const Unexecuted instantiation: Assimp::FBX::TypedProperty<float> const* Assimp::FBX::Property::As<Assimp::FBX::TypedProperty<float> >() const Unexecuted instantiation: Assimp::FBX::TypedProperty<int> const* Assimp::FBX::Property::As<Assimp::FBX::TypedProperty<int> >() const Unexecuted instantiation: Assimp::FBX::TypedProperty<bool> const* Assimp::FBX::Property::As<Assimp::FBX::TypedProperty<bool> >() const Unexecuted instantiation: Assimp::FBX::TypedProperty<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const* Assimp::FBX::Property::As<Assimp::FBX::TypedProperty<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >() const Unexecuted instantiation: Assimp::FBX::TypedProperty<long> const* Assimp::FBX::Property::As<Assimp::FBX::TypedProperty<long> >() const Unexecuted instantiation: Assimp::FBX::TypedProperty<unsigned long> const* Assimp::FBX::Property::As<Assimp::FBX::TypedProperty<unsigned long> >() const Unexecuted instantiation: Assimp::FBX::TypedProperty<unsigned int> const* Assimp::FBX::Property::As<Assimp::FBX::TypedProperty<unsigned int> >() const Unexecuted instantiation: Assimp::FBX::TypedProperty<aiColor3D> const* Assimp::FBX::Property::As<Assimp::FBX::TypedProperty<aiColor3D> >() const Unexecuted instantiation: Assimp::FBX::TypedProperty<aiColor4t<float> > const* Assimp::FBX::Property::As<Assimp::FBX::TypedProperty<aiColor4t<float> > >() const |
76 | | |
77 | | protected: |
78 | 0 | Property() = default; |
79 | | }; |
80 | | |
81 | | template<typename T> |
82 | | class TypedProperty : public Property { |
83 | | public: |
84 | 0 | explicit TypedProperty(const T& value) : value(value) {} Unexecuted instantiation: Assimp::FBX::TypedProperty<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::TypedProperty(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: Assimp::FBX::TypedProperty<aiVector3t<float> >::TypedProperty(aiVector3t<float> const&) Unexecuted instantiation: Assimp::FBX::TypedProperty<aiColor4t<float> >::TypedProperty(aiColor4t<float> const&) Unexecuted instantiation: Assimp::FBX::TypedProperty<bool>::TypedProperty(bool const&) Unexecuted instantiation: Assimp::FBX::TypedProperty<int>::TypedProperty(int const&) Unexecuted instantiation: Assimp::FBX::TypedProperty<unsigned long>::TypedProperty(unsigned long const&) Unexecuted instantiation: Assimp::FBX::TypedProperty<long>::TypedProperty(long const&) Unexecuted instantiation: Assimp::FBX::TypedProperty<float>::TypedProperty(float const&) |
85 | | |
86 | 0 | const T& Value() const { |
87 | 0 | return value; |
88 | 0 | } Unexecuted instantiation: Assimp::FBX::TypedProperty<aiVector3t<float> >::Value() const Unexecuted instantiation: Assimp::FBX::TypedProperty<float>::Value() const Unexecuted instantiation: Assimp::FBX::TypedProperty<int>::Value() const Unexecuted instantiation: Assimp::FBX::TypedProperty<bool>::Value() const Unexecuted instantiation: Assimp::FBX::TypedProperty<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::Value() const Unexecuted instantiation: Assimp::FBX::TypedProperty<long>::Value() const Unexecuted instantiation: Assimp::FBX::TypedProperty<unsigned long>::Value() const Unexecuted instantiation: Assimp::FBX::TypedProperty<unsigned int>::Value() const Unexecuted instantiation: Assimp::FBX::TypedProperty<aiColor3D>::Value() const Unexecuted instantiation: Assimp::FBX::TypedProperty<aiColor4t<float> >::Value() const |
89 | | |
90 | | private: |
91 | | T value; |
92 | | }; |
93 | | |
94 | | using DirectPropertyMap = std::fbx_unordered_map<std::string,std::shared_ptr<Property> >; |
95 | | using PropertyMap = std::fbx_unordered_map<std::string,const Property*>; |
96 | | using LazyPropertyMap = std::fbx_unordered_map<std::string,const Element*>; |
97 | | |
98 | | /** |
99 | | * Represents a property table as can be found in the newer FBX files (Properties60, Properties70) |
100 | | */ |
101 | | class PropertyTable { |
102 | | public: |
103 | | // in-memory property table with no source element |
104 | 0 | PropertyTable() : element() {} |
105 | | PropertyTable(const Element& element, std::shared_ptr<const PropertyTable> templateProps); |
106 | | ~PropertyTable(); |
107 | | |
108 | | const Property* Get(const std::string& name) const; |
109 | | |
110 | | // PropertyTable's need not be coupled with FBX elements so this can be nullptr |
111 | 0 | const Element* GetElement() const { |
112 | 0 | return element; |
113 | 0 | } |
114 | | |
115 | 0 | const PropertyTable* TemplateProps() const { |
116 | 0 | return templateProps.get(); |
117 | 0 | } |
118 | | |
119 | | DirectPropertyMap GetUnparsedProperties() const; |
120 | | |
121 | | private: |
122 | | LazyPropertyMap lazyProps; |
123 | | mutable PropertyMap props; |
124 | | const std::shared_ptr<const PropertyTable> templateProps; |
125 | | const Element* const element; |
126 | | }; |
127 | | |
128 | | // ------------------------------------------------------------------------------------------------ |
129 | | template <typename T> |
130 | 0 | inline T PropertyGet(const PropertyTable& in, const std::string& name, const T& defaultValue) { |
131 | 0 | const Property* const prop = in.Get(name); |
132 | 0 | if( nullptr == prop) { |
133 | 0 | return defaultValue; |
134 | 0 | } |
135 | | |
136 | | // strong typing, no need to be lenient |
137 | 0 | const TypedProperty<T>* const tprop = prop->As< TypedProperty<T> >(); |
138 | 0 | if( nullptr == tprop) { |
139 | 0 | return defaultValue; |
140 | 0 | } |
141 | | |
142 | 0 | return tprop->Value(); |
143 | 0 | } Unexecuted instantiation: aiVector3t<float> Assimp::FBX::PropertyGet<aiVector3t<float> >(Assimp::FBX::PropertyTable const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, aiVector3t<float> const&) Unexecuted instantiation: float Assimp::FBX::PropertyGet<float>(Assimp::FBX::PropertyTable const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, float const&) Unexecuted instantiation: int Assimp::FBX::PropertyGet<int>(Assimp::FBX::PropertyTable const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int const&) Unexecuted instantiation: bool Assimp::FBX::PropertyGet<bool>(Assimp::FBX::PropertyTable const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool const&) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Assimp::FBX::PropertyGet<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(Assimp::FBX::PropertyTable const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: long Assimp::FBX::PropertyGet<long>(Assimp::FBX::PropertyTable const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, long const&) Unexecuted instantiation: unsigned long Assimp::FBX::PropertyGet<unsigned long>(Assimp::FBX::PropertyTable const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long const&) |
144 | | |
145 | | // ------------------------------------------------------------------------------------------------ |
146 | | template <typename T> |
147 | 0 | inline T PropertyGet(const PropertyTable& in, const std::string& name, bool& result, bool useTemplate=false ) { |
148 | 0 | const Property* prop = in.Get(name); |
149 | 0 | if( nullptr == prop) { |
150 | 0 | if ( ! useTemplate ) { |
151 | 0 | result = false; |
152 | 0 | return T(); |
153 | 0 | } |
154 | 0 | const PropertyTable* templ = in.TemplateProps(); |
155 | 0 | if ( nullptr == templ ) { |
156 | 0 | result = false; |
157 | 0 | return T(); |
158 | 0 | } |
159 | 0 | prop = templ->Get(name); |
160 | 0 | if ( nullptr == prop ) { |
161 | 0 | result = false; |
162 | 0 | return T(); |
163 | 0 | } |
164 | 0 | } |
165 | | |
166 | | // strong typing, no need to be lenient |
167 | 0 | const TypedProperty<T>* const tprop = prop->As< TypedProperty<T> >(); |
168 | 0 | if( nullptr == tprop) { |
169 | 0 | result = false; |
170 | 0 | return T(); |
171 | 0 | } |
172 | | |
173 | 0 | result = true; |
174 | 0 | return tprop->Value(); |
175 | 0 | } Unexecuted instantiation: aiVector3t<float> Assimp::FBX::PropertyGet<aiVector3t<float> >(Assimp::FBX::PropertyTable const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool&, bool) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Assimp::FBX::PropertyGet<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(Assimp::FBX::PropertyTable const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool&, bool) Unexecuted instantiation: float Assimp::FBX::PropertyGet<float>(Assimp::FBX::PropertyTable const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool&, bool) |
176 | | |
177 | | } //! FBX |
178 | | } //! Assimp |
179 | | |
180 | | #endif // INCLUDED_AI_FBX_PROPERTIES_H |