Merge pull request #1692 from awefers/issue_1691
glTF 2.0: Assign default material to meshes with no material reference.pull/1696/head
commit
7d7d7cd9ec
|
@ -211,15 +211,9 @@ inline void SetMaterialTextureProperty(std::vector<int>& embeddedTexIdxs, Asset&
|
|||
}
|
||||
}
|
||||
|
||||
void glTF2Importer::ImportMaterials(glTF2::Asset& r)
|
||||
static aiMaterial* ImportMaterial(std::vector<int>& embeddedTexIdxs, Asset& r, Material& mat)
|
||||
{
|
||||
mScene->mNumMaterials = unsigned(r.materials.Size());
|
||||
mScene->mMaterials = new aiMaterial*[mScene->mNumMaterials];
|
||||
|
||||
for (unsigned int i = 0; i < mScene->mNumMaterials; ++i) {
|
||||
aiMaterial* aimat = mScene->mMaterials[i] = new aiMaterial();
|
||||
|
||||
Material& mat = r.materials[i];
|
||||
aiMaterial* aimat = new aiMaterial();
|
||||
|
||||
if (!mat.name.empty()) {
|
||||
aiString str(mat.name);
|
||||
|
@ -268,6 +262,21 @@ void glTF2Importer::ImportMaterials(glTF2::Asset& r)
|
|||
|
||||
SetMaterialTextureProperty(embeddedTexIdxs, r, pbrSG.specularGlossinessTexture, aimat, aiTextureType_SPECULAR);
|
||||
}
|
||||
|
||||
return aimat;
|
||||
}
|
||||
|
||||
void glTF2Importer::ImportMaterials(glTF2::Asset& r)
|
||||
{
|
||||
const unsigned int numImportedMaterials = unsigned(r.materials.Size());
|
||||
Material defaultMaterial;
|
||||
|
||||
mScene->mNumMaterials = numImportedMaterials + 1;
|
||||
mScene->mMaterials = new aiMaterial*[mScene->mNumMaterials];
|
||||
mScene->mMaterials[numImportedMaterials] = ImportMaterial(embeddedTexIdxs, r, defaultMaterial);
|
||||
|
||||
for (unsigned int i = 0; i < numImportedMaterials; ++i) {
|
||||
mScene->mMaterials[i] = ImportMaterial(embeddedTexIdxs, r, r.materials[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -479,6 +488,10 @@ void glTF2Importer::ImportMeshes(glTF2::Asset& r)
|
|||
if (prim.material) {
|
||||
aim->mMaterialIndex = prim.material.GetIndex();
|
||||
}
|
||||
else {
|
||||
aim->mMaterialIndex = mScene->mNumMaterials - 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue