2012-07-02 13:57:51 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2017-05-09 17:57:36 +00:00
|
|
|
Copyright (c) 2006-2017, assimp team
|
|
|
|
|
2012-07-02 13:57:51 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
2012-07-02 13:57:51 +00:00
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2012-07-02 13:57:51 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2012-07-02 13:57:51 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2012-07-02 13:57:51 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2012-07-02 13:57:51 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file FBXProperties.h
|
2015-05-19 03:52:10 +00:00
|
|
|
* @brief FBX dynamic properties
|
2012-07-02 13:57:51 +00:00
|
|
|
*/
|
|
|
|
#ifndef INCLUDED_AI_FBX_PROPERTIES_H
|
|
|
|
#define INCLUDED_AI_FBX_PROPERTIES_H
|
|
|
|
|
2015-04-15 19:22:26 +00:00
|
|
|
#include "FBXCompileConfig.h"
|
2016-04-05 21:23:53 +00:00
|
|
|
#include <memory>
|
2017-03-05 14:05:40 +00:00
|
|
|
#include <string>
|
2012-07-02 13:57:51 +00:00
|
|
|
|
|
|
|
namespace Assimp {
|
|
|
|
namespace FBX {
|
|
|
|
|
2017-03-05 14:05:40 +00:00
|
|
|
// Forward declarations
|
|
|
|
class Element;
|
2012-07-02 13:57:51 +00:00
|
|
|
|
|
|
|
/** Represents a dynamic property. Type info added by deriving classes,
|
|
|
|
* see #TypedProperty.
|
|
|
|
Example:
|
|
|
|
@verbatim
|
|
|
|
P: "ShininessExponent", "double", "Number", "",0.5
|
|
|
|
@endvebatim
|
|
|
|
*/
|
2017-09-30 08:47:23 +00:00
|
|
|
class Property {
|
2012-07-02 13:57:51 +00:00
|
|
|
protected:
|
2015-05-19 03:57:13 +00:00
|
|
|
Property();
|
2012-07-02 13:57:51 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
virtual ~Property();
|
2012-07-02 13:57:51 +00:00
|
|
|
|
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
template <typename T>
|
|
|
|
const T* As() const {
|
|
|
|
return dynamic_cast<const T*>(this);
|
|
|
|
}
|
2012-07-02 13:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
2017-09-30 08:47:23 +00:00
|
|
|
class TypedProperty : public Property {
|
2012-07-02 13:57:51 +00:00
|
|
|
public:
|
2015-10-29 12:04:23 +00:00
|
|
|
explicit TypedProperty(const T& value)
|
2017-09-30 08:47:23 +00:00
|
|
|
: value(value) {
|
|
|
|
// empty
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2012-07-02 13:57:51 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
const T& Value() const {
|
|
|
|
return value;
|
|
|
|
}
|
2012-07-02 13:57:51 +00:00
|
|
|
|
|
|
|
private:
|
2015-05-19 03:57:13 +00:00
|
|
|
T value;
|
2012-07-02 13:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-04-05 21:23:53 +00:00
|
|
|
typedef std::fbx_unordered_map<std::string,std::shared_ptr<Property> > DirectPropertyMap;
|
2017-09-30 08:47:23 +00:00
|
|
|
typedef std::fbx_unordered_map<std::string,const Property*> PropertyMap;
|
|
|
|
typedef std::fbx_unordered_map<std::string,const Element*> LazyPropertyMap;
|
2012-07-02 13:57:51 +00:00
|
|
|
|
2016-03-03 17:38:50 +00:00
|
|
|
/**
|
|
|
|
* Represents a property table as can be found in the newer FBX files (Properties60, Properties70)
|
|
|
|
*/
|
2017-09-30 08:47:23 +00:00
|
|
|
class PropertyTable {
|
2012-07-02 13:57:51 +00:00
|
|
|
public:
|
2015-05-19 03:57:13 +00:00
|
|
|
// in-memory property table with no source element
|
|
|
|
PropertyTable();
|
2016-04-05 21:23:53 +00:00
|
|
|
PropertyTable(const Element& element, std::shared_ptr<const PropertyTable> templateProps);
|
2015-05-19 03:57:13 +00:00
|
|
|
~PropertyTable();
|
2012-07-02 13:57:51 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
const Property* Get(const std::string& name) const;
|
2012-07-02 13:57:51 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// PropertyTable's need not be coupled with FBX elements so this can be NULL
|
|
|
|
const Element* GetElement() const {
|
|
|
|
return element;
|
|
|
|
}
|
2012-07-02 13:57:51 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
const PropertyTable* TemplateProps() const {
|
|
|
|
return templateProps.get();
|
|
|
|
}
|
2012-07-02 13:57:51 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
DirectPropertyMap GetUnparsedProperties() const;
|
2014-03-09 15:18:05 +00:00
|
|
|
|
2012-07-02 13:57:51 +00:00
|
|
|
private:
|
2015-05-19 03:57:13 +00:00
|
|
|
LazyPropertyMap lazyProps;
|
|
|
|
mutable PropertyMap props;
|
2016-04-05 21:23:53 +00:00
|
|
|
const std::shared_ptr<const PropertyTable> templateProps;
|
2015-05-19 03:57:13 +00:00
|
|
|
const Element* const element;
|
2012-07-02 13:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
2017-08-14 20:20:26 +00:00
|
|
|
inline
|
|
|
|
T PropertyGet(const PropertyTable& in, const std::string& name, const T& defaultValue) {
|
2015-05-19 03:57:13 +00:00
|
|
|
const Property* const prop = in.Get(name);
|
2017-08-14 20:20:26 +00:00
|
|
|
if( nullptr == prop) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// strong typing, no need to be lenient
|
|
|
|
const TypedProperty<T>* const tprop = prop->As< TypedProperty<T> >();
|
2017-08-14 20:20:26 +00:00
|
|
|
if( nullptr == tprop) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tprop->Value();
|
2012-07-02 17:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
2017-08-14 20:20:26 +00:00
|
|
|
inline
|
2018-01-11 16:30:17 +00:00
|
|
|
T PropertyGet(const PropertyTable& in, const std::string& name, bool& result, bool useTemplate=false ) {
|
|
|
|
const Property* prop = in.Get(name);
|
2017-08-14 20:20:26 +00:00
|
|
|
if( nullptr == prop) {
|
2018-01-11 16:30:17 +00:00
|
|
|
if ( ! useTemplate ) {
|
|
|
|
result = false;
|
|
|
|
return T();
|
|
|
|
}
|
|
|
|
const PropertyTable* templ = in.TemplateProps();
|
|
|
|
if ( nullptr == templ ) {
|
|
|
|
result = false;
|
|
|
|
return T();
|
|
|
|
}
|
|
|
|
prop = templ->Get(name);
|
|
|
|
if ( nullptr == prop ) {
|
|
|
|
result = false;
|
|
|
|
return T();
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// strong typing, no need to be lenient
|
|
|
|
const TypedProperty<T>* const tprop = prop->As< TypedProperty<T> >();
|
2017-08-14 20:20:26 +00:00
|
|
|
if( nullptr == tprop) {
|
2015-05-19 03:57:13 +00:00
|
|
|
result = false;
|
|
|
|
return T();
|
|
|
|
}
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
return tprop->Value();
|
2012-07-02 13:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} //! FBX
|
|
|
|
} //! Assimp
|
|
|
|
|
2016-03-03 17:38:50 +00:00
|
|
|
#endif // INCLUDED_AI_FBX_PROPERTIES_H
|