Merge pull request #223 from VirusFree/master
[FBX ] Use AiNode's metadata to keep objects UserDefinedPropertiespull/224/head
commit
de914d375f
|
@ -223,6 +223,9 @@ private:
|
|||
name_carrier = nodes_chain.back();
|
||||
}
|
||||
|
||||
//setup metadata on newest node
|
||||
SetupNodeMetadata(*model, *nodes_chain.back());
|
||||
|
||||
// link all nodes in a row
|
||||
aiNode* last_parent = &parent;
|
||||
BOOST_FOREACH(aiNode* prenode, nodes_chain) {
|
||||
|
@ -755,6 +758,27 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void SetupNodeMetadata(const Model& model, aiNode& nd)
|
||||
{
|
||||
const PropertyTable& props = model.Props();
|
||||
|
||||
// find user defined properties
|
||||
const std::string& userProps = PropertyGet<std::string>(props, "UDP3DSMAX", "");
|
||||
|
||||
//setup metadata //TODO: make metadata more friendly (eg. have Add()/Remove() functions to be easier to use)
|
||||
aiMetadata* data = new aiMetadata();
|
||||
data->mNumProperties = 1;
|
||||
data->mKeys = new aiString[data->mNumProperties]();
|
||||
data->mValues = new aiString[data->mNumProperties]();
|
||||
|
||||
//add user properties
|
||||
data->mKeys[0].Set("UserProperties");
|
||||
data->mValues[0].Set(userProps);
|
||||
|
||||
nd.mMetaData = data;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ConvertModel(const Model& model, aiNode& nd, const aiMatrix4x4& node_global_transform)
|
||||
|
|
|
@ -725,14 +725,14 @@ aiNode* ProcessSpatialStructure(aiNode* parent, const IfcProduct& el, Conversion
|
|||
if (!properties.empty()) {
|
||||
aiMetadata* data = new aiMetadata();
|
||||
data->mNumProperties = properties.size();
|
||||
data->mKeys = new aiString*[data->mNumProperties]();
|
||||
data->mValues = new aiString*[data->mNumProperties]();
|
||||
data->mKeys = new aiString[data->mNumProperties]();
|
||||
data->mValues = new aiString[data->mNumProperties]();
|
||||
|
||||
unsigned int i = 0;
|
||||
BOOST_FOREACH(const Metadata::value_type& kv, properties) {
|
||||
data->mKeys[i] = new aiString(kv.first);
|
||||
data->mKeys[i].Set(kv.first);
|
||||
if (kv.second.length() > 0) {
|
||||
data->mValues[i] = new aiString(kv.second);
|
||||
data->mValues[i].Set(kv.second);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
|
|
@ -62,11 +62,11 @@ struct aiMetadata
|
|||
unsigned int mNumProperties;
|
||||
|
||||
/** Arrays of keys, may not be NULL. Entries in this array may not be NULL as well. */
|
||||
C_STRUCT aiString** mKeys;
|
||||
C_STRUCT aiString* mKeys;
|
||||
|
||||
/** Arrays of values, may not be NULL. Entries in this array may be NULL if the
|
||||
* corresponding property key has no assigned value. */
|
||||
C_STRUCT aiString** mValues;
|
||||
C_STRUCT aiString* mValues;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
|
@ -83,26 +83,18 @@ struct aiMetadata
|
|||
/** Destructor */
|
||||
~aiMetadata()
|
||||
{
|
||||
if (mKeys && mValues) {
|
||||
for (unsigned i=0; i<mNumProperties; ++i) {
|
||||
if (mKeys[i]) {
|
||||
delete mKeys[i];
|
||||
}
|
||||
if (mValues[i]) {
|
||||
delete mValues[i];
|
||||
}
|
||||
}
|
||||
if (mKeys)
|
||||
delete [] mKeys;
|
||||
if (mValues)
|
||||
delete [] mValues;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline bool Get(const aiString& key, aiString& value)
|
||||
{
|
||||
for (unsigned i=0; i<mNumProperties; ++i) {
|
||||
if (mKeys[i] && *mKeys[i]==key) {
|
||||
value=*mValues[i];
|
||||
if (mKeys[i]==key) {
|
||||
value=mValues[i];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue