diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index c2ad4daf3..9a8edff45 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -46,6 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER #include +#include #include #include "FBXParser.h" @@ -94,14 +95,6 @@ public: TransformationComp_MAXIMUM }; - enum MetadataKeys - { - MetadataKeys_UserProperties = 0, - MetadataKeys_IsNull, - - MetadataKeys_MAXIMUM - }; - public: Converter(aiScene* out, const Document& doc) @@ -760,21 +753,56 @@ private: void SetupNodeMetadata(const Model& model, aiNode& nd) { const PropertyTable& props = model.Props(); + DirectPropertyMap unparsedProperties = props.GetUnparsedProperties(); - //create metadata on node + // create metadata on node + std::size_t numStaticMetaData = 2; aiMetadata* data = new aiMetadata(); - data->mNumProperties = MetadataKeys_MAXIMUM; + data->mNumProperties = unparsedProperties.size() + numStaticMetaData; data->mKeys = new aiString[data->mNumProperties](); data->mValues = new aiString[data->mNumProperties](); nd.mMetaData = data; + int index = 0; - // find user defined properties - data->mKeys[MetadataKeys_UserProperties].Set("UserProperties"); - data->mValues[MetadataKeys_UserProperties].Set(PropertyGet(props, "UDP3DSMAX", "")); + // find user defined properties (3ds Max) + data->mKeys[index].Set("UserProperties"); + data->mValues[index].Set(PropertyGet(props, "UDP3DSMAX", "")); + ++index; // preserve the info that a node was marked as Null node in the original file. - data->mKeys[MetadataKeys_IsNull].Set("IsNull"); - data->mValues[MetadataKeys_IsNull].Set(model.IsNull() ? "true" : "false"); + data->mKeys[index].Set("IsNull"); + data->mValues[index].Set(model.IsNull() ? "true" : "false"); + ++index; + + // add unparsed properties to the node's metadata + BOOST_FOREACH(const DirectPropertyMap::value_type& prop, unparsedProperties) { + + // all values are converted to strings using the following stringstream + std::stringstream ss; + bool parse_succeeded = false; + + // Interpret the property as a concrete type + if (const TypedProperty* interpreted = prop.second->As>()) + ss << interpreted->Value(); + else if (const TypedProperty* interpreted = prop.second->As>()) + ss << interpreted->Value(); + else if (const TypedProperty* interpreted = prop.second->As>()) + ss << interpreted->Value(); + else if (const TypedProperty* interpreted = prop.second->As>()) + ss << interpreted->Value(); + else if (const TypedProperty* interpreted = prop.second->As>()) + ss << interpreted->Value(); + else if (const TypedProperty* interpreted = prop.second->As>()) + { + aiVector3D v = interpreted->Value(); + ss << v.x << ";" << v.y << ";" << v.z; + } + + // add property to meta data + data->mKeys[index].Set(prop.first); + data->mValues[index].Set(ss.str()); + ++index; + } } // ------------------------------------------------------------------------------------------------ diff --git a/code/FBXProperties.cpp b/code/FBXProperties.cpp index 6c5433d74..48bdb4f40 100644 --- a/code/FBXProperties.cpp +++ b/code/FBXProperties.cpp @@ -201,6 +201,33 @@ const Property* PropertyTable::Get(const std::string& name) const return (*it).second; } +DirectPropertyMap PropertyTable::GetUnparsedProperties() const +{ + DirectPropertyMap result; + + // Loop through all the lazy properties (which is all the properties) + BOOST_FOREACH(const LazyPropertyMap::value_type& element, lazyProps) { + + // Skip parsed properties + if (props.end() != props.find(element.first)) continue; + + // Read the element's value. + // Wrap the naked pointer (since the call site is required to acquire ownership) + // std::unique_ptr from C++11 would be preferred both as a wrapper and a return value. + boost::shared_ptr prop = boost::shared_ptr(ReadTypedProperty(*element.second)); + + // Element could not be read. Skip it. + if (!prop) continue; + + // Add to result + result[element.first] = prop; + } + + return result; +} + + + } //! FBX } //! Assimp diff --git a/code/FBXProperties.h b/code/FBXProperties.h index 5e386444d..68c67e01d 100644 --- a/code/FBXProperties.h +++ b/code/FBXProperties.h @@ -101,6 +101,7 @@ private: }; +typedef std::fbx_unordered_map> DirectPropertyMap; typedef std::fbx_unordered_map PropertyMap; typedef std::fbx_unordered_map LazyPropertyMap; @@ -128,6 +129,8 @@ public: return templateProps.get(); } + DirectPropertyMap GetUnparsedProperties() const; + private: LazyPropertyMap lazyProps;