From 6fb9ebe3c891f05acccb08e7c89d70077409b2bd Mon Sep 17 00:00:00 2001 From: Trylz Date: Sat, 28 Apr 2018 23:34:07 -0400 Subject: [PATCH] Apply fix --- code/FBXConverter.cpp | 27 ++++++++++++++++----------- code/FBXConverter.h | 10 +++++----- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 2c9818a16..d6529d119 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -874,7 +874,7 @@ void Converter::ConvertModel( const Model& model, aiNode& nd, const aiMatrix4x4& const MeshGeometry* const mesh = dynamic_cast< const MeshGeometry* >( geo ); if ( mesh ) { - const std::vector& indices = ConvertMesh( *mesh, model, node_global_transform ); + const std::vector& indices = ConvertMesh( *mesh, model, node_global_transform, nd); std::copy( indices.begin(), indices.end(), std::back_inserter( meshes ) ); } else { @@ -891,7 +891,7 @@ void Converter::ConvertModel( const Model& model, aiNode& nd, const aiMatrix4x4& } std::vector Converter::ConvertMesh( const MeshGeometry& mesh, const Model& model, - const aiMatrix4x4& node_global_transform ) + const aiMatrix4x4& node_global_transform, aiNode& nd) { std::vector temp; @@ -915,17 +915,17 @@ std::vector Converter::ConvertMesh( const MeshGeometry& mesh, cons const MatIndexArray::value_type base = mindices[ 0 ]; for( MatIndexArray::value_type index : mindices ) { if ( index != base ) { - return ConvertMeshMultiMaterial( mesh, model, node_global_transform ); + return ConvertMeshMultiMaterial( mesh, model, node_global_transform, nd); } } } // faster code-path, just copy the data - temp.push_back( ConvertMeshSingleMaterial( mesh, model, node_global_transform ) ); + temp.push_back( ConvertMeshSingleMaterial( mesh, model, node_global_transform, nd) ); return temp; } -aiMesh* Converter::SetupEmptyMesh( const MeshGeometry& mesh ) +aiMesh* Converter::SetupEmptyMesh( const MeshGeometry& mesh, aiNode& nd) { aiMesh* const out_mesh = new aiMesh(); meshes.push_back( out_mesh ); @@ -940,15 +940,19 @@ aiMesh* Converter::SetupEmptyMesh( const MeshGeometry& mesh ) if ( name.length() ) { out_mesh->mName.Set( name ); } + else + { + out_mesh->mName = nd.mName; + } return out_mesh; } unsigned int Converter::ConvertMeshSingleMaterial( const MeshGeometry& mesh, const Model& model, - const aiMatrix4x4& node_global_transform ) + const aiMatrix4x4& node_global_transform, aiNode& nd) { const MatIndexArray& mindices = mesh.GetMaterialIndices(); - aiMesh* const out_mesh = SetupEmptyMesh( mesh ); + aiMesh* const out_mesh = SetupEmptyMesh(mesh, nd); const std::vector& vertices = mesh.GetVertices(); const std::vector& faces = mesh.GetFaceIndexCounts(); @@ -1072,7 +1076,7 @@ unsigned int Converter::ConvertMeshSingleMaterial( const MeshGeometry& mesh, con } std::vector Converter::ConvertMeshMultiMaterial( const MeshGeometry& mesh, const Model& model, - const aiMatrix4x4& node_global_transform ) + const aiMatrix4x4& node_global_transform, aiNode& nd) { const MatIndexArray& mindices = mesh.GetMaterialIndices(); ai_assert( mindices.size() ); @@ -1083,7 +1087,7 @@ std::vector Converter::ConvertMeshMultiMaterial( const MeshGeometr for( MatIndexArray::value_type index : mindices ) { if ( had.find( index ) == had.end() ) { - indices.push_back( ConvertMeshMultiMaterial( mesh, model, index, node_global_transform ) ); + indices.push_back( ConvertMeshMultiMaterial( mesh, model, index, node_global_transform, nd) ); had.insert( index ); } } @@ -1093,9 +1097,10 @@ std::vector Converter::ConvertMeshMultiMaterial( const MeshGeometr unsigned int Converter::ConvertMeshMultiMaterial( const MeshGeometry& mesh, const Model& model, MatIndexArray::value_type index, - const aiMatrix4x4& node_global_transform ) + const aiMatrix4x4& node_global_transform, + aiNode& nd) { - aiMesh* const out_mesh = SetupEmptyMesh( mesh ); + aiMesh* const out_mesh = SetupEmptyMesh(mesh, nd); const MatIndexArray& mindices = mesh.GetMaterialIndices(); const std::vector& vertices = mesh.GetVertices(); diff --git a/code/FBXConverter.h b/code/FBXConverter.h index 60fd04e2c..71d93d339 100644 --- a/code/FBXConverter.h +++ b/code/FBXConverter.h @@ -172,23 +172,23 @@ private: // ------------------------------------------------------------------------------------------------ // MeshGeometry -> aiMesh, return mesh index + 1 or 0 if the conversion failed std::vector ConvertMesh(const MeshGeometry& mesh, const Model& model, - const aiMatrix4x4& node_global_transform); + const aiMatrix4x4& node_global_transform, aiNode& nd); // ------------------------------------------------------------------------------------------------ - aiMesh* SetupEmptyMesh(const MeshGeometry& mesh); + aiMesh* SetupEmptyMesh(const MeshGeometry& mesh, aiNode& nd); // ------------------------------------------------------------------------------------------------ unsigned int ConvertMeshSingleMaterial(const MeshGeometry& mesh, const Model& model, - const aiMatrix4x4& node_global_transform); + const aiMatrix4x4& node_global_transform, aiNode& nd); // ------------------------------------------------------------------------------------------------ std::vector ConvertMeshMultiMaterial(const MeshGeometry& mesh, const Model& model, - const aiMatrix4x4& node_global_transform); + const aiMatrix4x4& node_global_transform, aiNode& nd); // ------------------------------------------------------------------------------------------------ unsigned int ConvertMeshMultiMaterial(const MeshGeometry& mesh, const Model& model, MatIndexArray::value_type index, - const aiMatrix4x4& node_global_transform); + const aiMatrix4x4& node_global_transform, aiNode& nd); // ------------------------------------------------------------------------------------------------ static const unsigned int NO_MATERIAL_SEPARATION = /* std::numeric_limits::max() */