Merge pull request #1692 from awefers/issue_1691

glTF 2.0: Assign default material to meshes with no material reference.
pull/1696/head
Kim Kulling 2018-01-11 00:53:54 +01:00 committed by GitHub
commit 7d7d7cd9ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 66 additions and 53 deletions

View File

@ -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;
}
}
}