Use dropdown comboboxes in Physics Materials fields' of PhysX Groups in FBX Settings (#1242)

This commit is contained in:
Aaron Ruiz Mora
2021-06-10 18:39:42 +01:00
committed by GitHub
parent c684714e4b
commit 42cc4214ba
2 changed files with 54 additions and 1 deletions
@@ -16,6 +16,8 @@
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzFramework/Physics/PhysicsSystem.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
#include <SceneAPI/SceneCore/DataTypes/Rules/IRule.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IBoneData.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IMeshData.h>
@@ -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<AzPhysics::SystemInterface>::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<AZStd::string> MeshGroup::GetPhysicsMaterialNames() const
{
if (auto* physicsSystem = AZ::Interface<AzPhysics::SystemInterface>::Get())
{
if (const auto* physicsConfiguration = physicsSystem->GetConfiguration())
{
const auto& materials = physicsConfiguration->m_materialLibraryAsset->GetMaterialsData();
AZStd::vector<AZStd::string> 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.
+7 -1
View File
@@ -15,6 +15,7 @@
#include <AzCore/Memory/Memory.h>
#include <AzCore/RTTI/RTTI.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzFramework/Physics/Common/PhysicsEvents.h>
#include <SceneAPI/SceneCore/Containers/RuleContainer.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISceneNodeGroup.h>
#include <SceneAPI/SceneData/ManifestBase/SceneNodeSelectionList.h>
@@ -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<AZStd::string> 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<AZStd::string> m_physicsMaterials;
const AZ::SceneAPI::Containers::SceneGraph* m_graph = nullptr;
AzPhysics::SystemEvents::OnMaterialLibraryChangedEvent::Handler m_materialLibraryChangedHandler;
};
}
}