From de14e06805c6b30798ed0a293818bb47d794a192 Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Sat, 16 May 2009 15:33:01 +0000 Subject: [PATCH] FIX: Nasty debug-only bug in FindInstancesProcess. FIX: Crash at ReplaceCurrentTexture(). FIX: Crash at 'compute smooth normals' in AssimpView. FIX: Obj shininess is now scaled by 4.0. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@421 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/FindInstancesProcess.cpp | 3 ++- code/ObjFileImporter.cpp | 3 +++ tools/assimp_view/Display.cpp | 5 +++-- tools/assimp_view/Material.cpp | 1 + tools/assimp_view/Normals.cpp | 4 ++++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/code/FindInstancesProcess.cpp b/code/FindInstancesProcess.cpp index c1a145a47..47038faab 100644 --- a/code/FindInstancesProcess.cpp +++ b/code/FindInstancesProcess.cpp @@ -134,7 +134,7 @@ void FindInstancesProcess::Execute( aiScene* pScene) aiMesh* inst = pScene->mMeshes[i]; hashes[i] = GetMeshHash(inst); - for (int a = i-1; a > 0; --a) { + for (int a = i-1; a >= 0; --a) { if (hashes[i] == hashes[a]) { aiMesh* orig = pScene->mMeshes[a]; @@ -253,6 +253,7 @@ void FindInstancesProcess::Execute( aiScene* pScene) // Delete the instanced mesh, we don't need it anymore delete inst; pScene->mMeshes[i] = NULL; + break; } } diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 3c0aa77c6..6b702d5dc 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -443,6 +443,9 @@ void ObjFileImporter::createMaterial(const ObjFile::Model* pModel, const ObjFile } mat->AddProperty( &sm, 1, AI_MATKEY_SHADING_MODEL); + // multiplying the specular exponent with 2 seems to yield better results + pCurrentMaterial->shineness *= 4.f; + // Adding material colors mat->AddProperty( &pCurrentMaterial->ambient, 1, AI_MATKEY_COLOR_AMBIENT ); mat->AddProperty( &pCurrentMaterial->diffuse, 1, AI_MATKEY_COLOR_DIFFUSE ); diff --git a/tools/assimp_view/Display.cpp b/tools/assimp_view/Display.cpp index 7ed7df98d..6f90d57d9 100644 --- a/tools/assimp_view/Display.cpp +++ b/tools/assimp_view/Display.cpp @@ -280,6 +280,7 @@ int CDisplay::ReplaceCurrentTexture(const char* szPath) // special handling here if (pcMesh->piNormalTexture && pcMesh->piNormalTexture != piTexture) { + piTexture->AddRef(); pcMesh->piNormalTexture->Release(); pcMesh->piNormalTexture = piTexture; CMaterialManager::Instance().HMtoNMIfNecessary(pcMesh->piNormalTexture,&pcMesh->piNormalTexture,true); @@ -302,9 +303,9 @@ int CDisplay::ReplaceCurrentTexture(const char* szPath) *tex = piTexture; m_pcCurrentTexture->piTexture = tex; - if (!pcMesh->bSharedFX){ + //if (!pcMesh->bSharedFX){ pcMesh->piEffect->SetTexture(tex_string,piTexture); - } + //} } } // now update the material itself diff --git a/tools/assimp_view/Material.cpp b/tools/assimp_view/Material.cpp index af6c6143f..cde8d38b6 100644 --- a/tools/assimp_view/Material.cpp +++ b/tools/assimp_view/Material.cpp @@ -456,6 +456,7 @@ void CMaterialManager::DeleteMaterial(AssetHelper::MeshHelper* pcIn) pcIn->piLightmapTexture->Release(); pcIn->piLightmapTexture = NULL; } + pcIn->piEffect = NULL; } //------------------------------------------------------------------------------- void CMaterialManager::HMtoNMIfNecessary( diff --git a/tools/assimp_view/Normals.cpp b/tools/assimp_view/Normals.cpp index 387007074..44e441163 100644 --- a/tools/assimp_view/Normals.cpp +++ b/tools/assimp_view/Normals.cpp @@ -103,6 +103,10 @@ void AssetHelper::FlipNormalsInt() for (unsigned int i = 0; i < this->pcScene->mNumMeshes;++i) { aiMesh* pcMesh = this->pcScene->mMeshes[i]; + + if (!pcMesh->mNormals) + continue; + for (unsigned int a = 0; a < pcMesh->mNumVertices;++a){ pcMesh->mNormals[a] *= -1.0f; }