Fixed PhysX and Blast creation of default config files (#4497)

- Avoid saving blast global configuration unnecessarily every time the editor is opened.
- Fixed how to obtain the default physics material library. The relative path needs to be from the project folder, not the asset folder inside the project. It was also missing saving the physx configuration after a the default library is assigned to it.
- Fixed asset id for physics material asset 'assets/physics/surfacetypemateriallibrary.physmaterial'

Signed-off-by: moraaar moraaar@amazon.com
This commit is contained in:
moraaar
2021-10-06 09:46:04 +01:00
committed by GitHub
parent 3eb3df6923
commit 606ba45cf2
11 changed files with 63 additions and 20 deletions
@@ -8,7 +8,9 @@
#include "EditorSystemComponent.h"
#include <AzCore/Interface/Interface.h>
#include <AzCore/IO/Path/Path.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzFramework/Physics/SystemBus.h>
#include <AzFramework/Physics/Collision/CollisionEvents.h>
#include <AzFramework/Physics/Common/PhysicsSimulatedBody.h>
@@ -23,7 +25,7 @@
namespace PhysX
{
constexpr const char* DefaultAssetFilePath = "Physics/SurfaceTypeMaterialLibrary";
constexpr const char* DefaultAssetFilePath = "Assets/Physics/SurfaceTypeMaterialLibrary";
constexpr const char* TemplateAssetFilename = "PhysX/TemplateMaterialLibrary";
static AZStd::optional<AZ::Data::Asset<AZ::Data::AssetData>> GetMaterialLibraryTemplate()
@@ -67,7 +69,7 @@ namespace PhysX
assetId, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetIdByPath, relativePath.c_str(), assetType, true /*autoRegisterIfNotFound*/);
AZ::Data::Asset<AZ::Data::AssetData> newAsset =
AZ::Data::AssetManager::Instance().GetAsset(assetId, assetType, AZ::Data::AssetLoadBehavior::Default);
AZ::Data::AssetManager::Instance().FindOrCreateAsset(assetId, assetType, AZ::Data::AssetLoadBehavior::Default);
if (auto* newMaterialLibraryData = azrtti_cast<Physics::MaterialLibraryAsset*>(newAsset.GetData()))
{
@@ -138,6 +140,14 @@ namespace PhysX
if (auto retrievedMaterialLibrary = RetrieveDefaultMaterialLibrary())
{
physxSystem->UpdateMaterialLibrary(retrievedMaterialLibrary.value());
// After setting the default material library, save the physx configuration.
auto saveCallback = []([[maybe_unused]] const PhysXSystemConfiguration& config, [[maybe_unused]] PhysXSettingsRegistryManager::Result result)
{
AZ_Warning("PhysX", result == PhysXSettingsRegistryManager::Result::Success,
"Unable to save the PhysX configuration after setting default material library.");
};
physxSystem->GetSettingsRegistryManager().SaveSystemConfiguration(physxSystem->GetPhysXConfiguration(), saveCallback);
}
}
}
@@ -236,11 +246,15 @@ namespace PhysX
if (!resultAssetId.IsValid())
{
// No file for the default material library, create it
const char* assetRoot = AZ::IO::FileIOBase::GetInstance()->GetAlias("@projectsourceassets@");
AZStd::string fullPath;
AzFramework::StringFunc::Path::ConstructFull(assetRoot, DefaultAssetFilePath, assetExtension.c_str(), fullPath);
AZ::IO::Path fullPath;
if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
{
settingsRegistry->Get(fullPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_ProjectPath);
}
fullPath /= DefaultAssetFilePath;
fullPath.ReplaceExtension(AZ::IO::PathView(assetExtension));
if (auto materialLibraryOpt = CreateMaterialLibrary(fullPath, relativePath))
if (auto materialLibraryOpt = CreateMaterialLibrary(fullPath.Native(), relativePath))
{
return materialLibraryOpt;
}