Optimized OBJ loader
No longer loading same material twice Former-commit-id: 21e1842600722f4ba3c02816fbfc016a6e5175c5
This commit is contained in:
parent
dbbc931df1
commit
672cbaed1d
|
|
@ -193,12 +193,18 @@ namespace
|
|||
NzMTLParser materialParser(file);
|
||||
if (materialParser.Parse())
|
||||
{
|
||||
std::unordered_map<NzString, NzMaterial*> materialCache;
|
||||
NzString baseDir = file.GetDirectory();
|
||||
for (unsigned int i = 0; i < meshCount; ++i)
|
||||
{
|
||||
const NzString& matName = materials[meshes[i].material];
|
||||
const NzMTLParser::Material* mtlMat = materialParser.GetMaterial(matName);
|
||||
if (mtlMat)
|
||||
{
|
||||
auto it = materialCache.find(matName);
|
||||
if (it != materialCache.end())
|
||||
model->SetMaterial(meshes[i].material, it->second);
|
||||
else
|
||||
{
|
||||
std::unique_ptr<NzMaterial> material(new NzMaterial);
|
||||
material->SetPersistent(false);
|
||||
|
|
@ -275,9 +281,12 @@ namespace
|
|||
material->SetSrcBlend(nzBlendFunc_SrcAlpha);
|
||||
}
|
||||
|
||||
materialCache[matName] = material.get();
|
||||
|
||||
model->SetMaterial(meshes[i].material, material.get());
|
||||
material.release();
|
||||
}
|
||||
}
|
||||
else
|
||||
NazaraWarning("MTL has no material \"" + matName + '"');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue