Physics material system for spectra launch
- Invalidate 'Physics Materials From Mesh' boolean from collider component - Removed material library from material selector. Default material library will always be used instead. - Marking failing automated test as xfail - Added default material to physics configuration. - Moved material library asset from physx configuration to physics configuration, as it doesn't need to be physx specific. - Refactor physics material system having into account that there is only one material library in the project. - Renaming code from DefaultMaterialLibrary to MaterialLibrary. - All queries about physics materials unified under PhysicsMaterialRequests bus. - PhysXSystem only manages the material library asset. - Saving and reloading the same physics material asset with different content didn't trigger a events that the material library has changed. - Changing Physics Material Request interface to use shared_ptr instead of weak_ptr to be simpler to handle the returned materials and having a more consistent code. - Refactored Material Manager to improve its implementation. Still following the same approach of "creating materials on the fly as they are requested", but now it's doing it consistently across the interface, with private helpers functions FindOrCreateMaterial that simplify vastly the implementation. - Material Manager now listens to change event of material library asset and default material configuration so it updates its materials accordingly. - Complete Material move constructor and operator.
This commit is contained in:
@@ -40,8 +40,8 @@ namespace PhysX
|
||||
}
|
||||
#endif
|
||||
|
||||
PhysXSystem::MaterialLibraryAssetHelper::MaterialLibraryAssetHelper(PhysXSystem* physXSystem)
|
||||
: m_physXSystem(physXSystem)
|
||||
PhysXSystem::MaterialLibraryAssetHelper::MaterialLibraryAssetHelper(OnMaterialLibraryReloadedCallback callback)
|
||||
: m_onMaterialLibraryReloadedCallback(callback)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -62,16 +62,16 @@ namespace PhysX
|
||||
|
||||
void PhysXSystem::MaterialLibraryAssetHelper::OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset)
|
||||
{
|
||||
if (m_physXSystem == nullptr || m_physXSystem->GetDefaultMaterialLibrary() != asset)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_physXSystem->UpdateDefaultMaterialLibrary(asset);
|
||||
m_onMaterialLibraryReloadedCallback(asset);
|
||||
}
|
||||
|
||||
PhysXSystem::PhysXSystem(PhysXSettingsRegistryManager* registryManager, const physx::PxCookingParams& cookingParams)
|
||||
: m_registryManager(*registryManager)
|
||||
, m_materialLibraryAssetHelper(this)
|
||||
, m_materialLibraryAssetHelper(
|
||||
[this](const AZ::Data::Asset<Physics::MaterialLibraryAsset>& materialLibrary)
|
||||
{
|
||||
UpdateMaterialLibrary(materialLibrary);
|
||||
})
|
||||
, m_sceneInterface(this)
|
||||
{
|
||||
// Start PhysX allocator
|
||||
@@ -127,7 +127,7 @@ namespace PhysX
|
||||
m_materialLibraryAssetHelper.Disconnect();
|
||||
// Clear the asset reference in deactivate. The asset system is shut down before destructors are called
|
||||
// for system components, causing any hanging asset references to become crashes on shutdown in release builds.
|
||||
m_systemConfig.m_defaultMaterialLibrary.Reset();
|
||||
m_systemConfig.m_materialLibraryAsset.Reset();
|
||||
|
||||
m_accumulatedTime = 0.0f;
|
||||
m_state = State::Shutdown;
|
||||
@@ -369,8 +369,18 @@ namespace PhysX
|
||||
|
||||
void PhysXSystem::OnCatalogLoaded([[maybe_unused]]const char* catalogFile)
|
||||
{
|
||||
//now that assets can be resolved, lets load the default material library.
|
||||
LoadDefaultMaterialLibrary();
|
||||
// now that assets can be resolved, lets load the default material library.
|
||||
|
||||
if (!m_systemConfig.m_materialLibraryAsset.GetId().IsValid())
|
||||
{
|
||||
m_onMaterialLibraryLoadErrorEvent.Signal(AzPhysics::SystemEvents::MaterialLibraryLoadErrorType::InvalidId);
|
||||
}
|
||||
|
||||
bool success = LoadMaterialLibrary();
|
||||
if (!success)
|
||||
{
|
||||
m_onMaterialLibraryLoadErrorEvent.Signal(AzPhysics::SystemEvents::MaterialLibraryLoadErrorType::ErrorLoading);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysXSystem::UpdateConfiguration(const AzPhysics::SystemConfiguration* newConfig, [[maybe_unused]] bool forceReinitialization /*= false*/)
|
||||
@@ -378,7 +388,7 @@ namespace PhysX
|
||||
if (const auto* physXConfig = azdynamic_cast<const PhysXSystemConfiguration*>(newConfig);
|
||||
m_systemConfig != (*physXConfig))
|
||||
{
|
||||
const bool newMaterialLibrary = m_systemConfig.m_defaultMaterialLibrary != physXConfig->m_defaultMaterialLibrary;
|
||||
const bool newMaterialLibrary = m_systemConfig.m_materialLibraryAsset != physXConfig->m_materialLibraryAsset;
|
||||
m_systemConfig = (*physXConfig);
|
||||
m_configChangeEvent.Signal(physXConfig);
|
||||
|
||||
@@ -386,9 +396,11 @@ namespace PhysX
|
||||
|
||||
if (newMaterialLibrary)
|
||||
{
|
||||
LoadDefaultMaterialLibrary();
|
||||
m_onDefaultMaterialLibraryChangedEvent.Signal(m_systemConfig.m_defaultMaterialLibrary.GetId());
|
||||
LoadMaterialLibrary();
|
||||
m_onMaterialLibraryChangedEvent.Signal(m_systemConfig.m_materialLibraryAsset.GetId());
|
||||
}
|
||||
// This function is not called from reloading the material library asset,
|
||||
// which means we don't need to check if the materials inside the library have been modified.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,23 +457,6 @@ namespace PhysX
|
||||
return m_systemConfig;
|
||||
}
|
||||
|
||||
void PhysXSystem::UpdateDefaultMaterialLibrary(const AZ::Data::Asset<Physics::MaterialLibraryAsset>& materialLibrary)
|
||||
{
|
||||
if (m_systemConfig.m_defaultMaterialLibrary == materialLibrary)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_systemConfig.m_defaultMaterialLibrary = materialLibrary;
|
||||
|
||||
LoadDefaultMaterialLibrary();
|
||||
m_onDefaultMaterialLibraryChangedEvent.Signal(materialLibrary.GetId());
|
||||
}
|
||||
|
||||
const AZ::Data::Asset<Physics::MaterialLibraryAsset>& PhysXSystem::GetDefaultMaterialLibrary() const
|
||||
{
|
||||
return m_systemConfig.m_defaultMaterialLibrary;
|
||||
}
|
||||
|
||||
void PhysXSystem::UpdateDefaultSceneConfiguration(const AzPhysics::SceneConfiguration& sceneConfiguration)
|
||||
{
|
||||
if (m_defaultSceneConfiguration != sceneConfiguration)
|
||||
@@ -482,9 +477,30 @@ namespace PhysX
|
||||
return m_registryManager;
|
||||
}
|
||||
|
||||
bool PhysXSystem::LoadDefaultMaterialLibrary()
|
||||
void PhysXSystem::UpdateMaterialLibrary(const AZ::Data::Asset<Physics::MaterialLibraryAsset>& materialLibrary)
|
||||
{
|
||||
AZ::Data::Asset<Physics::MaterialLibraryAsset>& materialLibrary = m_systemConfig.m_defaultMaterialLibrary;
|
||||
if (m_systemConfig.m_materialLibraryAsset == materialLibrary)
|
||||
{
|
||||
// Same library asset, check if its data has changed.
|
||||
if (m_systemConfig.m_materialLibraryAsset->GetMaterialsData() != materialLibrary->GetMaterialsData())
|
||||
{
|
||||
m_systemConfig.m_materialLibraryAsset = materialLibrary;
|
||||
m_onMaterialLibraryChangedEvent.Signal(materialLibrary.GetId());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// New material library asset
|
||||
m_systemConfig.m_materialLibraryAsset = materialLibrary;
|
||||
|
||||
LoadMaterialLibrary();
|
||||
m_onMaterialLibraryChangedEvent.Signal(materialLibrary.GetId());
|
||||
}
|
||||
}
|
||||
|
||||
bool PhysXSystem::LoadMaterialLibrary()
|
||||
{
|
||||
AZ::Data::Asset<Physics::MaterialLibraryAsset>& materialLibrary = m_systemConfig.m_materialLibraryAsset;
|
||||
const AZ::Data::AssetId& materialLibraryId = materialLibrary.GetId();
|
||||
if (!materialLibraryId.IsValid())
|
||||
{
|
||||
@@ -503,7 +519,7 @@ namespace PhysX
|
||||
AZ_Warning("PhysX", (materialLibrary.GetData() != nullptr),
|
||||
"LoadDefaultMaterialLibrary: Default Material Library asset data is invalid.");
|
||||
|
||||
return materialLibrary.GetData() != nullptr;
|
||||
return materialLibrary.GetData() != nullptr && !materialLibrary.IsError();
|
||||
}
|
||||
|
||||
//TEMP -- until these are fully moved over here
|
||||
|
||||
Reference in New Issue
Block a user