Ue new alloc semantic when using aiMetadata + increase test coverage.
This commit is contained in:
@@ -336,25 +336,21 @@ auto texmap_is_equal = [](const CAMFImporter_NodeElement_TexMap* pTexMap1, const
|
||||
} while(pInputList.size() > 0);
|
||||
}
|
||||
|
||||
void AMFImporter::Postprocess_AddMetadata(const std::list<CAMFImporter_NodeElement_Metadata*>& pMetadataList, aiNode& pSceneNode) const
|
||||
void AMFImporter::Postprocess_AddMetadata(const std::list<CAMFImporter_NodeElement_Metadata*>& metadataList, aiNode& sceneNode) const
|
||||
{
|
||||
if(pMetadataList.size() > 0)
|
||||
if ( !metadataList.empty() )
|
||||
{
|
||||
if(pSceneNode.mMetaData != nullptr) throw DeadlyImportError("Postprocess. MetaData member in node are not nullptr. Something went wrong.");
|
||||
if(sceneNode.mMetaData != nullptr) throw DeadlyImportError("Postprocess. MetaData member in node are not nullptr. Something went wrong.");
|
||||
|
||||
// copy collected metadata to output node.
|
||||
pSceneNode.mMetaData = new aiMetadata();
|
||||
pSceneNode.mMetaData->mNumProperties = pMetadataList.size();
|
||||
pSceneNode.mMetaData->mKeys = new aiString[pSceneNode.mMetaData->mNumProperties];
|
||||
pSceneNode.mMetaData->mValues = new aiMetadataEntry[pSceneNode.mMetaData->mNumProperties];
|
||||
sceneNode.mMetaData = aiMetadata::Alloc( metadataList.size() );
|
||||
size_t meta_idx( 0 );
|
||||
|
||||
size_t meta_idx = 0;
|
||||
|
||||
for(const CAMFImporter_NodeElement_Metadata& metadata: pMetadataList)
|
||||
for(const CAMFImporter_NodeElement_Metadata& metadata: metadataList)
|
||||
{
|
||||
pSceneNode.mMetaData->Set(meta_idx++, metadata.Type, aiString(metadata.Value));
|
||||
sceneNode.mMetaData->Set(meta_idx++, metadata.Type, aiString(metadata.Value));
|
||||
}
|
||||
}// if(pMetadataList.size() > 0)
|
||||
}// if(!metadataList.empty())
|
||||
}
|
||||
|
||||
void AMFImporter::Postprocess_BuildNodeAndObject(const CAMFImporter_NodeElement_Object& pNodeElement, std::list<aiMesh*>& pMeshList, aiNode** pSceneNode)
|
||||
|
||||
@@ -1075,10 +1075,7 @@ void Converter::SetupNodeMetadata( const Model& model, aiNode& nd )
|
||||
|
||||
// create metadata on node
|
||||
std::size_t numStaticMetaData = 2;
|
||||
aiMetadata* data = new aiMetadata();
|
||||
data->mNumProperties = unparsedProperties.size() + numStaticMetaData;
|
||||
data->mKeys = new aiString[ data->mNumProperties ]();
|
||||
data->mValues = new aiMetadataEntry[ data->mNumProperties ]();
|
||||
aiMetadata* data = aiMetadata::Alloc( unparsedProperties.size() + numStaticMetaData );
|
||||
nd.mMetaData = data;
|
||||
int index = 0;
|
||||
|
||||
@@ -1089,22 +1086,22 @@ void Converter::SetupNodeMetadata( const Model& model, aiNode& nd )
|
||||
|
||||
// add unparsed properties to the node's metadata
|
||||
for( const DirectPropertyMap::value_type& prop : unparsedProperties ) {
|
||||
|
||||
// Interpret the property as a concrete type
|
||||
if ( const TypedProperty<bool>* interpreted = prop.second->As<TypedProperty<bool> >() )
|
||||
if ( const TypedProperty<bool>* interpreted = prop.second->As<TypedProperty<bool> >() ) {
|
||||
data->Set( index++, prop.first, interpreted->Value() );
|
||||
else if ( const TypedProperty<int>* interpreted = prop.second->As<TypedProperty<int> >() )
|
||||
} else if ( const TypedProperty<int>* interpreted = prop.second->As<TypedProperty<int> >() ) {
|
||||
data->Set( index++, prop.first, interpreted->Value() );
|
||||
else if ( const TypedProperty<uint64_t>* interpreted = prop.second->As<TypedProperty<uint64_t> >() )
|
||||
} else if ( const TypedProperty<uint64_t>* interpreted = prop.second->As<TypedProperty<uint64_t> >() ) {
|
||||
data->Set( index++, prop.first, interpreted->Value() );
|
||||
else if ( const TypedProperty<float>* interpreted = prop.second->As<TypedProperty<float> >() )
|
||||
} else if ( const TypedProperty<float>* interpreted = prop.second->As<TypedProperty<float> >() ) {
|
||||
data->Set( index++, prop.first, interpreted->Value() );
|
||||
else if ( const TypedProperty<std::string>* interpreted = prop.second->As<TypedProperty<std::string> >() )
|
||||
} else if ( const TypedProperty<std::string>* interpreted = prop.second->As<TypedProperty<std::string> >() ) {
|
||||
data->Set( index++, prop.first, aiString( interpreted->Value() ) );
|
||||
else if ( const TypedProperty<aiVector3D>* interpreted = prop.second->As<TypedProperty<aiVector3D> >() )
|
||||
} else if ( const TypedProperty<aiVector3D>* interpreted = prop.second->As<TypedProperty<aiVector3D> >() ) {
|
||||
data->Set( index++, prop.first, interpreted->Value() );
|
||||
else
|
||||
assert( false );
|
||||
} else {
|
||||
ai_assert( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -707,15 +707,11 @@ 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 aiMetadataEntry[data->mNumProperties]();
|
||||
|
||||
unsigned int index = 0;
|
||||
for(const Metadata::value_type& kv : properties)
|
||||
data->Set(index++, kv.first, aiString(kv.second));
|
||||
|
||||
aiMetadata* data = aiMetadata::Alloc( properties.size() );
|
||||
unsigned int index( 0 );
|
||||
for ( const Metadata::value_type& kv : properties ) {
|
||||
data->Set( index++, kv.first, aiString( kv.second ) );
|
||||
}
|
||||
nd->mMetaData = data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -901,11 +901,8 @@ void SIBImporter::InternReadFile(const std::string& pFile,
|
||||
// Mark instanced objects as being so.
|
||||
if (n >= firstInst)
|
||||
{
|
||||
node->mMetaData = new aiMetadata;
|
||||
node->mMetaData->mNumProperties = 1;
|
||||
node->mMetaData->mKeys = new aiString[1];
|
||||
node->mMetaData->mValues = new aiMetadataEntry[1];
|
||||
node->mMetaData->Set(0, "IsInstance", true);
|
||||
node->mMetaData = aiMetadata::Alloc( 1 );
|
||||
node->mMetaData->Set( 0, "IsInstance", true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,11 +43,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
// possible as new fields are added to assimp structures.
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** @file Implements Assimp::SceneCombiner. This is a smart utility
|
||||
* class that combines multiple scenes, meshes, ... into one. Currently
|
||||
* these utilities are used by the IRR and LWS loaders and the
|
||||
* OptimizeGraph step.
|
||||
*/
|
||||
/**
|
||||
* @file Implements Assimp::SceneCombiner. This is a smart utility
|
||||
* class that combines multiple scenes, meshes, ... into one. Currently
|
||||
* these utilities are used by the IRR and LWS loaders and the
|
||||
* OptimizeGraph step.
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
#include "SceneCombiner.h"
|
||||
#include "StringUtils.h"
|
||||
@@ -59,7 +60,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <stdio.h>
|
||||
#include "ScenePrivate.h"
|
||||
|
||||
namespace Assimp {
|
||||
namespace Assimp {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Add a prefix to a string
|
||||
@@ -198,8 +199,9 @@ void SceneCombiner::MergeScenes(aiScene** _dest,std::vector<aiScene*>& src,
|
||||
void SceneCombiner::AttachToGraph (aiNode* attach, std::vector<NodeAttachmentInfo>& srcList)
|
||||
{
|
||||
unsigned int cnt;
|
||||
for (cnt = 0; cnt < attach->mNumChildren;++cnt)
|
||||
AttachToGraph(attach->mChildren[cnt],srcList);
|
||||
for ( cnt = 0; cnt < attach->mNumChildren; ++cnt ) {
|
||||
AttachToGraph( attach->mChildren[ cnt ], srcList );
|
||||
}
|
||||
|
||||
cnt = 0;
|
||||
for (std::vector<NodeAttachmentInfo>::iterator it = srcList.begin();
|
||||
@@ -1219,13 +1221,12 @@ void SceneCombiner::Copy (aiNode** _dest, const aiNode* src)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SceneCombiner::Copy (aiMetadata** _dest, const aiMetadata* src)
|
||||
void SceneCombiner::Copy(aiMetadata** _dest, const aiMetadata* src)
|
||||
{
|
||||
ai_assert(NULL != _dest && NULL != src);
|
||||
ai_assert( NULL != _dest );
|
||||
ai_assert( NULL != src);
|
||||
|
||||
aiMetadata* dest = *_dest = new aiMetadata();
|
||||
dest->mNumProperties = src->mNumProperties;
|
||||
dest->mKeys = new aiString[src->mNumProperties];
|
||||
aiMetadata* dest = *_dest = aiMetadata::Alloc( src->mNumProperties );
|
||||
std::copy(src->mKeys, src->mKeys + src->mNumProperties, dest->mKeys);
|
||||
|
||||
dest->mValues = new aiMetadataEntry[src->mNumProperties];
|
||||
|
||||
@@ -758,15 +758,14 @@ void X3DImporter::Postprocess_CollectMetadata(const CX3DImporter_NodeElement& pN
|
||||
size_t meta_idx;
|
||||
|
||||
PostprocessHelper_CollectMetadata(pNodeElement, meta_list);// find metadata in current node element.
|
||||
if(meta_list.size() > 0)
|
||||
if ( !meta_list.empty() )
|
||||
{
|
||||
if(pSceneNode.mMetaData != nullptr) throw DeadlyImportError("Postprocess. MetaData member in node are not nullptr. Something went wrong.");
|
||||
if ( pSceneNode.mMetaData != nullptr ) {
|
||||
throw DeadlyImportError( "Postprocess. MetaData member in node are not nullptr. Something went wrong." );
|
||||
}
|
||||
|
||||
// copy collected metadata to output node.
|
||||
pSceneNode.mMetaData = new aiMetadata();
|
||||
pSceneNode.mMetaData->mNumProperties = meta_list.size();
|
||||
pSceneNode.mMetaData->mKeys = new aiString[pSceneNode.mMetaData->mNumProperties];
|
||||
pSceneNode.mMetaData->mValues = new aiMetadataEntry[pSceneNode.mMetaData->mNumProperties];
|
||||
// copy collected metadata to output node.
|
||||
pSceneNode.mMetaData = aiMetadata::Alloc( meta_list.size() );
|
||||
meta_idx = 0;
|
||||
for(std::list<CX3DImporter_NodeElement*>::const_iterator it = meta_list.begin(); it != meta_list.end(); it++, meta_idx++)
|
||||
{
|
||||
@@ -808,7 +807,7 @@ void X3DImporter::Postprocess_CollectMetadata(const CX3DImporter_NodeElement& pN
|
||||
throw DeadlyImportError("Postprocess. Unknown metadata type.");
|
||||
}// if((*it)->Type == CX3DImporter_NodeElement::ENET_Meta*) else
|
||||
}// for(std::list<CX3DImporter_NodeElement*>::const_iterator it = meta_list.begin(); it != meta_list.end(); it++)
|
||||
}// if(meta_list.size() > 0)
|
||||
}// if( !meta_list.empty() )
|
||||
}
|
||||
|
||||
}// namespace Assimp
|
||||
|
||||
Reference in New Issue
Block a user