Fixed an issue with Actors where the material slot IDs were incorrect, and caused the displayed slot labels to be all "<unknown>" (and likely other issues).

Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
monroegm-disable-blank-issue-2
Chris Santora 4 years ago committed by santorac
parent 28671c8546
commit 3daf3f7d7a

@ -45,7 +45,7 @@ namespace AZ
uint32_t m_vertexOffset = 0; uint32_t m_vertexOffset = 0;
uint32_t m_vertexCount = 0; uint32_t m_vertexCount = 0;
Aabb m_aabb = Aabb::CreateNull(); Aabb m_aabb = Aabb::CreateNull();
Data::Asset<RPI::MaterialAsset> m_material; AZ::RPI::ModelMaterialSlot m_materialSlot;
}; };
//! Buffer views for a specific sub-mesh that are not modified during skinning and thus are shared by all instances of the same skinned mesh //! Buffer views for a specific sub-mesh that are not modified during skinning and thus are shared by all instances of the same skinned mesh

@ -640,12 +640,7 @@ namespace AZ
Aabb localAabb = lod.m_subMeshProperties[i].m_aabb; Aabb localAabb = lod.m_subMeshProperties[i].m_aabb;
modelLodCreator.SetMeshAabb(AZStd::move(localAabb)); modelLodCreator.SetMeshAabb(AZStd::move(localAabb));
// Create a separate material slot for each sub-mesh modelLodCreator.SetMeshMaterialSlot(lod.m_subMeshProperties[i].m_materialSlot);
AZ::RPI::ModelMaterialSlot materialSlot;
materialSlot.m_stableId = i;
materialSlot.m_defaultMaterialAsset = lod.m_subMeshProperties[i].m_material;
modelLodCreator.SetMeshMaterialSlot(materialSlot);
modelLodCreator.EndMesh(); modelLodCreator.EndMesh();
} }

@ -96,9 +96,10 @@ namespace AZ
skinnedSubMesh.m_vertexCount = aznumeric_cast<uint32_t>(subMeshVertexCount); skinnedSubMesh.m_vertexCount = aznumeric_cast<uint32_t>(subMeshVertexCount);
lodVertexCount += aznumeric_cast<uint32_t>(subMeshVertexCount); lodVertexCount += aznumeric_cast<uint32_t>(subMeshVertexCount);
skinnedSubMesh.m_material = lodAsset->GetMaterialSlot(modelMesh.GetMaterialSlotIndex()).m_defaultMaterialAsset; skinnedSubMesh.m_materialSlot = lodAsset->GetMaterialSlot(modelMesh.GetMaterialSlotIndex());
// Queue the material asset - the ModelLod seems to handle delayed material loads // Queue the material asset - the ModelLod seems to handle delayed material loads
skinnedSubMesh.m_material.QueueLoad(); skinnedSubMesh.m_materialSlot.m_defaultMaterialAsset.QueueLoad();
subMeshes.push_back(skinnedSubMesh); subMeshes.push_back(skinnedSubMesh);
} }

@ -503,16 +503,18 @@ namespace AZ
const AZStd::vector< SkinnedSubMeshProperties>& subMeshProperties = inputLod.GetSubMeshProperties(); const AZStd::vector< SkinnedSubMeshProperties>& subMeshProperties = inputLod.GetSubMeshProperties();
for (const SkinnedSubMeshProperties& submesh : subMeshProperties) for (const SkinnedSubMeshProperties& submesh : subMeshProperties)
{ {
AZ_Error("AtomActorInstance", submesh.m_material, "Actor does not have a valid default material in lod %d", lodIndex); Data::Asset<RPI::MaterialAsset> materialAsset = submesh.m_materialSlot.m_defaultMaterialAsset;
if (submesh.m_material) AZ_Error("AtomActorInstance", materialAsset, "Actor does not have a valid default material in lod %d", lodIndex);
if (materialAsset)
{ {
if (!submesh.m_material->IsReady()) if (!materialAsset->IsReady())
{ {
// Start listening for the material's OnAssetReady event. // Start listening for the material's OnAssetReady event.
// AtomActorInstance::Create is called on the main thread, so there should be no need to synchronize with the OnAssetReady event handler // AtomActorInstance::Create is called on the main thread, so there should be no need to synchronize with the OnAssetReady event handler
// since those events will also come from the main thread // since those events will also come from the main thread
m_waitForMaterialLoadIds.insert(submesh.m_material->GetId()); m_waitForMaterialLoadIds.insert(materialAsset->GetId());
Data::AssetBus::MultiHandler::BusConnect(submesh.m_material->GetId()); Data::AssetBus::MultiHandler::BusConnect(materialAsset->GetId());
} }
} }
} }

Loading…
Cancel
Save