Commit f093ed8d authored by hybrid's avatar hybrid

Fix meshbuffer creation for new groups.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1968 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 9f2d1075
......@@ -83,7 +83,8 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
// Process obj information
const c8* bufPtr = buf;
core::stringc grpName;
core::stringc grpName, mtlName;
bool mtlChanged=false;
bool useGroups = !SceneManager->getParameters()->getAttributeAsBool(OBJ_LOADER_IGNORE_GROUPS);
while(bufPtr != bufEnd)
{
......@@ -143,6 +144,7 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
else
grpName = "default";
}
mtlChanged=true;
}
break;
......@@ -168,11 +170,8 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
#ifdef _IRR_DEBUG_OBJ_LOADER_
os::Printer::log("Loaded material start",matName);
#endif
// retrieve the material
SObjMtl *useMtl = findMtl(matName, grpName);
// only change material if we found it
if (useMtl)
currMtl = useMtl;
mtlName=matName;
mtlChanged=true;
}
break;
......@@ -181,6 +180,15 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
c8 vertexWord[WORD_BUFFER_LENGTH]; // for retrieving vertex data
video::S3DVertex v;
// Assign vertex color from currently active material's diffuse colour
if (mtlChanged)
{
// retrieve the material
SObjMtl *useMtl = findMtl(mtlName, grpName);
// only change material if we found it
if (useMtl)
currMtl = useMtl;
mtlChanged=false;
}
if (currMtl)
v.Color = currMtl->Meshbuffer->Material.DiffuseColor;
......@@ -672,6 +680,8 @@ const c8* COBJMeshFileLoader::readBool(const c8* bufPtr, bool& tf, const c8* con
COBJMeshFileLoader::SObjMtl* COBJMeshFileLoader::findMtl(const core::stringc& mtlName, const core::stringc& grpName)
{
COBJMeshFileLoader::SObjMtl* defMaterial = 0;
// search existing Materials for best match
// exact match does return immediately, only name match means a new group
for (u32 i = 0; i < Materials.size(); ++i)
{
if ( Materials[i]->Name == mtlName )
......@@ -679,16 +689,23 @@ COBJMeshFileLoader::SObjMtl* COBJMeshFileLoader::findMtl(const core::stringc& mt
if ( Materials[i]->Group == grpName )
return Materials[i];
else
if ( Materials[i]->Group == "" )
defMaterial = Materials[i];
}
}
// we found a partial match
if (defMaterial)
{
Materials.push_back(new SObjMtl(*defMaterial));
Materials.getLast()->Group = grpName;
return Materials.getLast();
}
// we found a new group for a non-existant material
else if (grpName.size())
{
Materials.push_back(new SObjMtl(*Materials[0]));
Materials.getLast()->Group = grpName;
return Materials.getLast();
}
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment