Moved the material slot list from ModelLodAsset to ModelAsset, so all the slots live in one main list. This removes data duplication between LODs and cleans up the code a bit.

I had to update the ModelLod class to take in both the ModelLodAsset and ModelAsset for initialization so it can fetch the slots for each mesh.

Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
Chris Santora
2021-07-20 16:23:56 -07:00
committed by santorac
parent a71ee7eb3a
commit fec79a7d53
22 changed files with 135 additions and 158 deletions
@@ -112,20 +112,8 @@ namespace WhiteBox
AddLodBuffers(modelLodCreator);
modelLodCreator.BeginMesh();
modelLodCreator.SetMeshAabb(meshData.GetAabb());
// set the default material
if (auto materialAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath<AZ::RPI::MaterialAsset>(TexturedMaterialPath.data()))
{
AZ::RPI::ModelMaterialSlot materialSlot;
materialSlot.m_stableId = 0;
materialSlot.m_defaultMaterialAsset = materialAsset;
modelLodCreator.SetMeshMaterialSlot(materialSlot);
}
else
{
AZ_Error("CreateLodAsset", false, "Could not load material.");
return false;
}
modelLodCreator.SetMeshMaterialSlot(OneMaterialSlotId);
AddMeshBuffers(modelLodCreator);
modelLodCreator.EndMesh();
@@ -157,6 +145,20 @@ namespace WhiteBox
modelCreator.Begin(AZ::Data::AssetId(AZ::Uuid::CreateRandom()));
modelCreator.SetName(ModelName);
modelCreator.AddLodAsset(AZStd::move(m_lodAsset));
if (auto materialAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath<AZ::RPI::MaterialAsset>(TexturedMaterialPath.data()))
{
AZ::RPI::ModelMaterialSlot materialSlot;
materialSlot.m_stableId = OneMaterialSlotId;
materialSlot.m_defaultMaterialAsset = materialAsset;
modelCreator.AddMaterialSlot(materialSlot);
}
else
{
AZ_Error("CreateLodAsset", false, "Could not load material.");
return;
}
modelCreator.End(m_modelAsset);
}
@@ -91,6 +91,7 @@ namespace WhiteBox
// TODO: LYN-784
static constexpr AZStd::string_view TexturedMaterialPath = "materials/defaultpbr.azmaterial";
static constexpr AZStd::string_view SolidMaterialPath = "materials/defaultpbr.azmaterial";
static constexpr AZ::RPI::ModelMaterialSlot::StableId OneMaterialSlotId = 0;
//! White box model name.
static constexpr AZStd::string_view ModelName = "WhiteBoxMesh";