From fc4243a08f59092e7039a3c7d26932470e9f9a27 Mon Sep 17 00:00:00 2001 From: "nola.donato@samsung.com" Date: Mon, 30 Jan 2017 20:32:37 -0800 Subject: [PATCH 1/2] OBJParser: set material index when changing current material When a new material is parsed from the material library, the name of the current material is set but the old material index remains. This leaves an incorrect material index in the current mesh causing textures to not be associated with the right mesh. This patch updates the material index when changing the material name. submitted by: Nola Donato nola.donato@samsung.com --- code/ObjFileMtlImporter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/code/ObjFileMtlImporter.cpp b/code/ObjFileMtlImporter.cpp index 13b0024a6..487ef5222 100644 --- a/code/ObjFileMtlImporter.cpp +++ b/code/ObjFileMtlImporter.cpp @@ -302,6 +302,7 @@ void ObjFileMtlImporter::createMaterial() // New Material created m_pModel->m_pCurrentMaterial = new ObjFile::Material(); m_pModel->m_pCurrentMaterial->MaterialName.Set( name ); + m_pModel->m_pCurrentMesh->m_uiMaterialIndex = m_pModel->m_MaterialLib.size(); m_pModel->m_MaterialLib.push_back( name ); m_pModel->m_MaterialMap[ name ] = m_pModel->m_pCurrentMaterial; } else { From e28b5422e072fd8037698838ea8f757ade8f251c Mon Sep 17 00:00:00 2001 From: "nola.donato@samsung.com" Date: Tue, 31 Jan 2017 16:40:04 -0800 Subject: [PATCH 2/2] OBJ: check for null mesh before updating material index Sometimes the current mesh is null, should check before updating the material index Submitted by: Nola Donato nola.donato@samsung.com --- code/ObjFileMtlImporter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/ObjFileMtlImporter.cpp b/code/ObjFileMtlImporter.cpp index 487ef5222..c1d899c60 100644 --- a/code/ObjFileMtlImporter.cpp +++ b/code/ObjFileMtlImporter.cpp @@ -185,7 +185,7 @@ void ObjFileMtlImporter::load() getFloatValue( m_pModel->m_pCurrentMaterial->alpha ); m_DataIt = skipLine( m_DataIt, m_DataItEnd, m_uiLine ); } - } + }width * height * 4 break; case 'N': @@ -302,7 +302,8 @@ void ObjFileMtlImporter::createMaterial() // New Material created m_pModel->m_pCurrentMaterial = new ObjFile::Material(); m_pModel->m_pCurrentMaterial->MaterialName.Set( name ); - m_pModel->m_pCurrentMesh->m_uiMaterialIndex = m_pModel->m_MaterialLib.size(); + if (m_pModel->m_pCurrentMesh) + m_pModel->m_pCurrentMesh->m_uiMaterialIndex = m_pModel->m_MaterialLib.size(); m_pModel->m_MaterialLib.push_back( name ); m_pModel->m_MaterialMap[ name ] = m_pModel->m_pCurrentMaterial; } else {