Implemented KRLocator::getUserAttributes(), which returns a list of additional properties enumerated from fbx files so client code can convert locators into application-specific objects

--HG--
branch : nfb
This commit is contained in:
2013-12-05 19:44:58 -08:00
parent f1d23de23f
commit 5b708fa1cd
3 changed files with 46 additions and 1 deletions

View File

@@ -33,3 +33,8 @@ void KRLocator::loadXML(tinyxml2::XMLElement *e)
{
KRNode::loadXML(e);
}
unordered_map<std::string, boost::variant<int, double, bool, std::string> > &KRLocator::getUserAttributes()
{
return m_userAttributes;
}

View File

@@ -13,6 +13,8 @@
#include "KRNode.h"
#include "KRTexture.h"
#include "boost/variant.hpp"
class KRLocator : public KRNode {
public:
KRLocator(KRScene &scene, std::string name);
@@ -20,7 +22,10 @@ public:
virtual std::string getElementName();
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
virtual void loadXML(tinyxml2::XMLElement *e);
unordered_map<std::string, boost::variant<int, double, bool, std::string> > &getUserAttributes();
private:
unordered_map<std::string, boost::variant<int, double, bool, std::string> > m_userAttributes;
};

View File

@@ -9,6 +9,7 @@
#include "KREngine-common.h"
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/variant.hpp>
#include <fbxsdk.h>
@@ -1610,6 +1611,40 @@ KRNode *LoadLocator(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) {
KRLocator *new_locator = new KRLocator(parent_node->getScene(), name.c_str());
// Enumerate fbx properties so client code can convert locators into application-specific objects
FbxProperty fbx_property = pNode->GetFirstProperty();
while(fbx_property.IsValid()) {
std::string property_name = fbx_property.GetNameAsCStr();
boost::variant<int, double, bool, std::string> property_value = "";
switch(fbx_property.GetPropertyDataType().GetType()) {
case eFbxInt:
property_value = fbx_property.Get<FbxInt>();
break;
case eFbxDouble:
property_value = fbx_property.Get<FbxDouble>();
break;
case eFbxBool:
property_value = fbx_property.Get<FbxBool>();
break;
case eFbxFloat:
property_value = fbx_property.Get<FbxDouble>();
break;
case eFbxString:
property_value = std::string(fbx_property.Get<FbxString>().Buffer());
break;
default:
{
fprintf(stderr, "FBX property not imported due to unsupported data type: %s.%s\n", name.c_str(), property_name.c_str());
}
break;
}
std::transform(property_name.begin(), property_name.end(), property_name.begin(), ::tolower);
new_locator->getUserAttributes()[property_name] = property_value;
}
//static bool GetBindPoseContaining(FbxScene* pScene, FbxNode* pNode, PoseList& pPoseList, FbxArray<int>& pIndex);
// PoseList pose_list;
// FbxArray<int> pose_indices;