Merge branch 'master' into master

pull/1683/head
Christian Meurin 2018-01-10 20:10:54 -08:00 committed by GitHub
commit 538bc95499
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 69 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()); aiMaterial* aimat = new aiMaterial();
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];
if (!mat.name.empty()) { if (!mat.name.empty()) {
aiString str(mat.name); aiString str(mat.name);
@ -268,6 +262,21 @@ void glTF2Importer::ImportMaterials(glTF2::Asset& r)
SetMaterialTextureProperty(embeddedTexIdxs, r, pbrSG.specularGlossinessTexture, aimat, aiTextureType_SPECULAR); 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) { if (prim.material) {
aim->mMaterialIndex = prim.material.GetIndex(); aim->mMaterialIndex = prim.material.GetIndex();
} }
else {
aim->mMaterialIndex = mScene->mNumMaterials - 1;
}
} }
} }
@ -499,6 +512,9 @@ void glTF2Importer::ImportCameras(glTF2::Asset& r)
aiCamera* aicam = mScene->mCameras[i] = new aiCamera(); aiCamera* aicam = mScene->mCameras[i] = new aiCamera();
// cameras point in -Z by default, rest is specified in node transform
aicam->mLookAt = aiVector3D(0.f,0.f,-1.f);
if (cam.type == Camera::Perspective) { if (cam.type == Camera::Perspective) {
aicam->mAspect = cam.cameraProperties.perspective.aspectRatio; aicam->mAspect = cam.cameraProperties.perspective.aspectRatio;