diff --git a/Gems/PhysX/Code/Source/Pipeline/MeshGroup.cpp b/Gems/PhysX/Code/Source/Pipeline/MeshGroup.cpp index 4789377852..ffae8c449b 100644 --- a/Gems/PhysX/Code/Source/Pipeline/MeshGroup.cpp +++ b/Gems/PhysX/Code/Source/Pipeline/MeshGroup.cpp @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include #include @@ -580,7 +582,21 @@ namespace PhysX MeshGroup::MeshGroup() : m_id(AZ::Uuid::CreateRandom()) + , m_materialLibraryChangedHandler( + [this](const AZ::Data::AssetId& materialLibraryAssetId) + { + OnMaterialLibraryChanged(materialLibraryAssetId); + }) { + if (auto* physicsSystem = AZ::Interface::Get()) + { + physicsSystem->RegisterOnMaterialLibraryChangedEventHandler(m_materialLibraryChangedHandler); + } + } + + MeshGroup::~MeshGroup() + { + m_materialLibraryChangedHandler.Disconnect(); } void MeshGroup::Reflect(AZ::ReflectContext* context) @@ -669,6 +685,8 @@ namespace PhysX ->Attribute(AZ::Edit::Attributes::IndexedChildNameLabelOverride, &MeshGroup::GetMaterialSlotLabel) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ->Attribute(AZ::Edit::Attributes::ContainerCanBeModified, false) + ->ElementAttribute(AZ::Edit::UIHandlers::Handler, AZ::Edit::UIHandlers::ComboBox) + ->ElementAttribute(AZ::Edit::Attributes::StringList, &MeshGroup::GetPhysicsMaterialNames) ->DataElement(AZ::Edit::UIHandlers::Default, &MeshGroup::m_rules, "", "Add or remove rules to fine-tune the export process.") @@ -857,6 +875,35 @@ namespace PhysX } } + AZStd::vector MeshGroup::GetPhysicsMaterialNames() const + { + if (auto* physicsSystem = AZ::Interface::Get()) + { + if (const auto* physicsConfiguration = physicsSystem->GetConfiguration()) + { + const auto& materials = physicsConfiguration->m_materialLibraryAsset->GetMaterialsData(); + + AZStd::vector physicsMaterialNames; + physicsMaterialNames.reserve(materials.size() + 1); + + physicsMaterialNames.emplace_back(Physics::DefaultPhysicsMaterialLabel); + for (const auto& material : materials) + { + physicsMaterialNames.emplace_back(material.m_configuration.m_surfaceType); + } + + return physicsMaterialNames; + } + } + return {Physics::DefaultPhysicsMaterialLabel}; + } + + void MeshGroup::OnMaterialLibraryChanged([[maybe_unused]] const AZ::Data::AssetId& materialLibraryAssetId) + { + AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::RequestRefresh, + AzToolsFramework::PropertyModificationRefreshLevel::Refresh_AttributesAndValues); + } + bool MeshGroup::VersionConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement) { // Remove the material rule. diff --git a/Gems/PhysX/Code/Source/Pipeline/MeshGroup.h b/Gems/PhysX/Code/Source/Pipeline/MeshGroup.h index a2c270234a..5b70ded7ea 100644 --- a/Gems/PhysX/Code/Source/Pipeline/MeshGroup.h +++ b/Gems/PhysX/Code/Source/Pipeline/MeshGroup.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -177,7 +178,7 @@ namespace PhysX AZ_CLASS_ALLOCATOR_DECL MeshGroup(); - ~MeshGroup() override = default; + ~MeshGroup() override; static void Reflect(AZ::ReflectContext* context); @@ -224,6 +225,9 @@ namespace PhysX bool GetDecomposeMeshesVisibility() const; AZStd::string GetMaterialSlotLabel(int index) const; + AZStd::vector GetPhysicsMaterialNames() const; + + void OnMaterialLibraryChanged(const AZ::Data::AssetId& materialLibraryAssetId); AZ::Uuid m_id{}; AZStd::string m_name{}; @@ -239,6 +243,8 @@ namespace PhysX AZStd::vector m_physicsMaterials; const AZ::SceneAPI::Containers::SceneGraph* m_graph = nullptr; + + AzPhysics::SystemEvents::OnMaterialLibraryChangedEvent::Handler m_materialLibraryChangedHandler; }; } }