diff --git a/ogre/src/OgreMeshFactory.cc b/ogre/src/OgreMeshFactory.cc index d30c55a79..431e3c832 100644 --- a/ogre/src/OgreMeshFactory.cc +++ b/ogre/src/OgreMeshFactory.cc @@ -409,7 +409,10 @@ bool OgreMeshFactory::LoadImpl(const MeshDescriptor &_desc) *indices++ = subMesh.Index(j); common::MaterialPtr material; - material = _desc.mesh->MaterialByIndex(subMesh.MaterialIndex()); + if (const auto subMeshIdx = subMesh.GetMaterialIndex()) + { + material = _desc.mesh->MaterialByIndex(subMeshIdx.value()); + } MaterialPtr mat = this->scene->CreateMaterial(); if (material) diff --git a/ogre2/src/Ogre2MeshFactory.cc b/ogre2/src/Ogre2MeshFactory.cc index 82d392abb..807f24d98 100644 --- a/ogre2/src/Ogre2MeshFactory.cc +++ b/ogre2/src/Ogre2MeshFactory.cc @@ -469,7 +469,10 @@ bool Ogre2MeshFactory::LoadImpl(const MeshDescriptor &_desc) iBuf->unlock(); common::MaterialPtr material; - material = _desc.mesh->MaterialByIndex(subMesh.MaterialIndex()); + if (const auto subMeshIdx = subMesh.GetMaterialIndex()) + { + material = _desc.mesh->MaterialByIndex(subMeshIdx.value()); + } MaterialPtr mat = this->scene->CreateMaterial(); if (material) diff --git a/optix/src/OptixMeshFactory.cc b/optix/src/OptixMeshFactory.cc index 8788a3f2c..24ad23035 100644 --- a/optix/src/OptixMeshFactory.cc +++ b/optix/src/OptixMeshFactory.cc @@ -125,7 +125,10 @@ OptixSubMeshStorePtr OptixSubMeshStoreFactory::Create( sm->optixGeomInstance->setGeometry(optixGeometry); common::MaterialPtr material; - material = _desc.mesh->MaterialByIndex(subMesh->MaterialIndex()); + if (const auto subMeshIdx = SubMesh.GetMaterialIndex()) + { + material = _desc.mesh->MaterialByIndex(subMeshIdx.value()); + } MaterialPtr mat = this->scene->CreateMaterial(); if (material) {