closes https://github.com/assimp/assimp/issues/1404: set name with merged meshes for output mesh.
parent
ee56ffa1f1
commit
c143d2e02c
|
@ -56,18 +56,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
|
static const unsigned int NotSet = 0xcdcdcdcd;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Setup final material indices, generae a default material if necessary
|
// Setup final material indices, generae a default material if necessary
|
||||||
void Discreet3DSImporter::ReplaceDefaultMaterial()
|
void Discreet3DSImporter::ReplaceDefaultMaterial()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Try to find an existing material that matches the
|
// Try to find an existing material that matches the
|
||||||
// typical default material setting:
|
// typical default material setting:
|
||||||
// - no textures
|
// - no textures
|
||||||
// - diffuse color (in grey!)
|
// - diffuse color (in grey!)
|
||||||
// NOTE: This is here to workaround the fact that some
|
// NOTE: This is here to workaround the fact that some
|
||||||
// exporters are writing a default material, too.
|
// exporters are writing a default material, too.
|
||||||
unsigned int idx = 0xcdcdcdcd;
|
unsigned int idx( NotSet );
|
||||||
for (unsigned int i = 0; i < mScene->mMaterials.size();++i)
|
for (unsigned int i = 0; i < mScene->mMaterials.size();++i)
|
||||||
{
|
{
|
||||||
std::string s = mScene->mMaterials[i].mName;
|
std::string s = mScene->mMaterials[i].mName;
|
||||||
|
@ -93,7 +94,9 @@ void Discreet3DSImporter::ReplaceDefaultMaterial()
|
||||||
}
|
}
|
||||||
idx = i;
|
idx = i;
|
||||||
}
|
}
|
||||||
if (0xcdcdcdcd == idx)idx = (unsigned int)mScene->mMaterials.size();
|
if ( NotSet == idx ) {
|
||||||
|
idx = ( unsigned int )mScene->mMaterials.size();
|
||||||
|
}
|
||||||
|
|
||||||
// now iterate through all meshes and through all faces and
|
// now iterate through all meshes and through all faces and
|
||||||
// find all faces that are using the default material
|
// find all faces that are using the default material
|
||||||
|
|
|
@ -58,6 +58,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
|
#include <assimp/mesh.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "ScenePrivate.h"
|
#include "ScenePrivate.h"
|
||||||
|
|
||||||
|
@ -757,7 +758,7 @@ void SceneCombiner::MergeBones(aiMesh* out,std::vector<aiMesh*>::const_iterator
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Merge a list of meshes
|
// Merge a list of meshes
|
||||||
void SceneCombiner::MergeMeshes(aiMesh** _out,unsigned int /*flags*/,
|
void SceneCombiner::MergeMeshes(aiMesh** _out, unsigned int /*flags*/,
|
||||||
std::vector<aiMesh*>::const_iterator begin,
|
std::vector<aiMesh*>::const_iterator begin,
|
||||||
std::vector<aiMesh*>::const_iterator end)
|
std::vector<aiMesh*>::const_iterator end)
|
||||||
{
|
{
|
||||||
|
@ -772,8 +773,14 @@ void SceneCombiner::MergeMeshes(aiMesh** _out,unsigned int /*flags*/,
|
||||||
aiMesh* out = *_out = new aiMesh();
|
aiMesh* out = *_out = new aiMesh();
|
||||||
out->mMaterialIndex = (*begin)->mMaterialIndex;
|
out->mMaterialIndex = (*begin)->mMaterialIndex;
|
||||||
|
|
||||||
|
std::string name;
|
||||||
// Find out how much output storage we'll need
|
// Find out how much output storage we'll need
|
||||||
for (std::vector<aiMesh*>::const_iterator it = begin; it != end;++it) {
|
for (std::vector<aiMesh*>::const_iterator it = begin; it != end; ++it) {
|
||||||
|
const char *meshName( (*it)->mName.C_Str() );
|
||||||
|
name += std::string( meshName );
|
||||||
|
if ( it != end - 1 ) {
|
||||||
|
name += ".";
|
||||||
|
}
|
||||||
out->mNumVertices += (*it)->mNumVertices;
|
out->mNumVertices += (*it)->mNumVertices;
|
||||||
out->mNumFaces += (*it)->mNumFaces;
|
out->mNumFaces += (*it)->mNumFaces;
|
||||||
out->mNumBones += (*it)->mNumBones;
|
out->mNumBones += (*it)->mNumBones;
|
||||||
|
@ -781,6 +788,7 @@ void SceneCombiner::MergeMeshes(aiMesh** _out,unsigned int /*flags*/,
|
||||||
// combine primitive type flags
|
// combine primitive type flags
|
||||||
out->mPrimitiveTypes |= (*it)->mPrimitiveTypes;
|
out->mPrimitiveTypes |= (*it)->mPrimitiveTypes;
|
||||||
}
|
}
|
||||||
|
out->mName.Set( name.c_str() );
|
||||||
|
|
||||||
if (out->mNumVertices) {
|
if (out->mNumVertices) {
|
||||||
aiVector3D* pv2;
|
aiVector3D* pv2;
|
||||||
|
@ -789,7 +797,7 @@ void SceneCombiner::MergeMeshes(aiMesh** _out,unsigned int /*flags*/,
|
||||||
if ((**begin).HasPositions()) {
|
if ((**begin).HasPositions()) {
|
||||||
|
|
||||||
pv2 = out->mVertices = new aiVector3D[out->mNumVertices];
|
pv2 = out->mVertices = new aiVector3D[out->mNumVertices];
|
||||||
for (std::vector<aiMesh*>::const_iterator it = begin; it != end;++it) {
|
for (std::vector<aiMesh*>::const_iterator it = begin; it != end; ++it) {
|
||||||
if ((*it)->mVertices) {
|
if ((*it)->mVertices) {
|
||||||
::memcpy(pv2,(*it)->mVertices,(*it)->mNumVertices*sizeof(aiVector3D));
|
::memcpy(pv2,(*it)->mVertices,(*it)->mNumVertices*sizeof(aiVector3D));
|
||||||
}
|
}
|
||||||
|
@ -809,7 +817,7 @@ void SceneCombiner::MergeMeshes(aiMesh** _out,unsigned int /*flags*/,
|
||||||
pv2 += (*it)->mNumVertices;
|
pv2 += (*it)->mNumVertices;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// copy tangents and bitangents
|
// copy tangents and bi-tangents
|
||||||
if ((**begin).HasTangentsAndBitangents()) {
|
if ((**begin).HasTangentsAndBitangents()) {
|
||||||
|
|
||||||
pv2 = out->mTangents = new aiVector3D[out->mNumVertices];
|
pv2 = out->mTangents = new aiVector3D[out->mNumVertices];
|
||||||
|
|
|
@ -217,10 +217,9 @@ public:
|
||||||
static void MergeScenes(aiScene** dest,std::vector<aiScene*>& src,
|
static void MergeScenes(aiScene** dest,std::vector<aiScene*>& src,
|
||||||
unsigned int flags = 0);
|
unsigned int flags = 0);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Merges two or more scenes and attaches all sceenes to a specific
|
/** Merges two or more scenes and attaches all scenes to a specific
|
||||||
* position in the node graph of the masteer scene.
|
* position in the node graph of the master scene.
|
||||||
*
|
*
|
||||||
* @param dest Receives a pointer to the destination scene. If the
|
* @param dest Receives a pointer to the destination scene. If the
|
||||||
* pointer doesn't point to NULL when the function is called, the
|
* pointer doesn't point to NULL when the function is called, the
|
||||||
|
@ -236,7 +235,6 @@ public:
|
||||||
std::vector<AttachmentInfo>& src,
|
std::vector<AttachmentInfo>& src,
|
||||||
unsigned int flags = 0);
|
unsigned int flags = 0);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Merges two or more meshes
|
/** Merges two or more meshes
|
||||||
*
|
*
|
||||||
|
@ -255,7 +253,6 @@ public:
|
||||||
std::vector<aiMesh*>::const_iterator begin,
|
std::vector<aiMesh*>::const_iterator begin,
|
||||||
std::vector<aiMesh*>::const_iterator end);
|
std::vector<aiMesh*>::const_iterator end);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Merges two or more bones
|
/** Merges two or more bones
|
||||||
*
|
*
|
||||||
|
|
|
@ -116,6 +116,7 @@ SET( TEST_SRCS
|
||||||
unit/utRemoveRedundantMaterials.cpp
|
unit/utRemoveRedundantMaterials.cpp
|
||||||
unit/utRemoveVCProcess.cpp
|
unit/utRemoveVCProcess.cpp
|
||||||
unit/utScenePreprocessor.cpp
|
unit/utScenePreprocessor.cpp
|
||||||
|
unit/utSceneCombiner.cpp
|
||||||
unit/utSharedPPData.cpp
|
unit/utSharedPPData.cpp
|
||||||
unit/utStringUtils.cpp
|
unit/utStringUtils.cpp
|
||||||
unit/utSMDImportExport.cpp
|
unit/utSMDImportExport.cpp
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
Open Asset Import Library (assimp)
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006-2017, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
with or without modification, are permitted provided that the following
|
||||||
|
conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above
|
||||||
|
copyright notice, this list of conditions and the
|
||||||
|
following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the
|
||||||
|
following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of the assimp team, nor the names of its
|
||||||
|
contributors may be used to endorse or promote products
|
||||||
|
derived from this software without specific prior
|
||||||
|
written permission of the assimp team.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
#include "UnitTestPCH.h"
|
||||||
|
#include <assimp/SceneCombiner.h>
|
||||||
|
#include <assimp/mesh.h>
|
||||||
|
|
||||||
|
using namespace ::Assimp;
|
||||||
|
|
||||||
|
class utSceneCombiner : public ::testing::Test {
|
||||||
|
// empty
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F( utSceneCombiner, MergeMeshes_ValidNames_Test ) {
|
||||||
|
std::vector<aiMesh*> merge_list;
|
||||||
|
aiMesh *mesh1 = new aiMesh;
|
||||||
|
mesh1->mName.Set( "mesh_1" );
|
||||||
|
merge_list.push_back( mesh1 );
|
||||||
|
|
||||||
|
aiMesh *mesh2 = new aiMesh;
|
||||||
|
mesh2->mName.Set( "mesh_2" );
|
||||||
|
merge_list.push_back( mesh2 );
|
||||||
|
|
||||||
|
aiMesh *mesh3 = new aiMesh;
|
||||||
|
mesh3->mName.Set( "mesh_3" );
|
||||||
|
merge_list.push_back( mesh3 );
|
||||||
|
|
||||||
|
aiMesh *out( nullptr );
|
||||||
|
SceneCombiner::MergeMeshes( &out, 0, merge_list.begin(), merge_list.end() );
|
||||||
|
std::string outName = out->mName.C_Str();
|
||||||
|
EXPECT_EQ( "mesh_1.mesh_2.mesh_3", outName );
|
||||||
|
}
|
Loading…
Reference in New Issue