3ds loader now sets aiMesh::mName according to the original mesh groups found in the file.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@727 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2010-05-20 12:07:04 +00:00
parent 6e133a6cd9
commit f9b06f8d89
2 changed files with 56 additions and 53 deletions

View File

@ -348,14 +348,14 @@ void Discreet3DSImporter::ConvertMeshes(aiScene* pcOut)
std::vector<aiMesh*> avOutMeshes; std::vector<aiMesh*> avOutMeshes;
avOutMeshes.reserve(mScene->mMeshes.size() * 2); avOutMeshes.reserve(mScene->mMeshes.size() * 2);
unsigned int iFaceCnt = 0; unsigned int iFaceCnt = 0,num = 0;
aiString name;
// we need to split all meshes by their materials // we need to split all meshes by their materials
for (std::vector<D3DS::Mesh>::iterator i = mScene->mMeshes.begin(); for (std::vector<D3DS::Mesh>::iterator i = mScene->mMeshes.begin(); i != mScene->mMeshes.end();++i) {
i != mScene->mMeshes.end();++i) boost::scoped_array< std::vector<unsigned int> > aiSplit(new std::vector<unsigned int>[mScene->mMaterials.size()]);
{
std::vector<unsigned int>* aiSplit = new std::vector<unsigned int>[ name.length = ASSIMP_itoa10(name.data,num++);
mScene->mMaterials.size()];
unsigned int iNum = 0; unsigned int iNum = 0;
for (std::vector<unsigned int>::const_iterator a = (*i).mFaceMaterials.begin(); for (std::vector<unsigned int>::const_iterator a = (*i).mFaceMaterials.begin();
@ -366,9 +366,11 @@ void Discreet3DSImporter::ConvertMeshes(aiScene* pcOut)
// now generate submeshes // now generate submeshes
for (unsigned int p = 0; p < mScene->mMaterials.size();++p) for (unsigned int p = 0; p < mScene->mMaterials.size();++p)
{ {
if (aiSplit[p].size()) if (aiSplit[p].empty()) {
{ continue;
}
aiMesh* meshOut = new aiMesh(); aiMesh* meshOut = new aiMesh();
meshOut->mName = name;
meshOut->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; meshOut->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
// be sure to setup the correct material index // be sure to setup the correct material index
@ -414,19 +416,19 @@ void Discreet3DSImporter::ConvertMeshes(aiScene* pcOut)
} }
} }
} }
delete[] aiSplit;
}
// Copy them to the output array // Copy them to the output array
pcOut->mNumMeshes = (unsigned int)avOutMeshes.size(); pcOut->mNumMeshes = (unsigned int)avOutMeshes.size();
pcOut->mMeshes = new aiMesh*[pcOut->mNumMeshes](); pcOut->mMeshes = new aiMesh*[pcOut->mNumMeshes]();
for (unsigned int a = 0; a < pcOut->mNumMeshes;++a) for (unsigned int a = 0; a < pcOut->mNumMeshes;++a) {
pcOut->mMeshes[a] = avOutMeshes[a]; pcOut->mMeshes[a] = avOutMeshes[a];
}
// We should have at least one face here // We should have at least one face here
if (!iFaceCnt) if (!iFaceCnt) {
throw DeadlyImportError("No faces loaded. The mesh is empty"); throw DeadlyImportError("No faces loaded. The mesh is empty");
} }
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Add a node to the scenegraph and setup its final transformation // Add a node to the scenegraph and setup its final transformation

View File

@ -58,9 +58,10 @@ namespace Assimp {
* to have a small replacement function here. No need to use a full sprintf() * to have a small replacement function here. No need to use a full sprintf()
* if we just want to print a number ... * if we just want to print a number ...
* @param out Output buffer * @param out Output buffer
* @param max Maximum number of characters to be written, including '\0' * @param max Maximum number of characters to be written, including '\0'.
* This parameter may not be 0.
* @param number Number to be written * @param number Number to be written
* @return Number of bytes written. * @return Length of the output string, excluding the '\0'
*/ */
inline unsigned int ASSIMP_itoa10( char* out, unsigned int max, int32_t number) inline unsigned int ASSIMP_itoa10( char* out, unsigned int max, int32_t number)
{ {
@ -97,15 +98,15 @@ inline unsigned int ASSIMP_itoa10( char* out, unsigned int max, int32_t number)
// append a terminal zero // append a terminal zero
*out++ = '\0'; *out++ = '\0';
return written; return written-1;
} }
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
/** @brief itoa with a fixed base 10 (Secure template overload) /** @brief itoa with a fixed base 10 (Secure template overload)
* The compiler should choose this function if he is able to determine the * The compiler should choose this function if he or she is able to determine the
* size of the array automatically. * size of the array automatically.
*/ */
template <unsigned int length> template <size_t length>
inline unsigned int ASSIMP_itoa10( char(& out)[length], int32_t number) inline unsigned int ASSIMP_itoa10( char(& out)[length], int32_t number)
{ {
return ASSIMP_itoa10(out,length,number); return ASSIMP_itoa10(out,length,number);