From 6b23e07af4781de2393367e4c269c53f37ed4889 Mon Sep 17 00:00:00 2001 From: santorac <55155825+santorac@users.noreply.github.com> Date: Fri, 20 Aug 2021 17:22:11 -0700 Subject: [PATCH] Changed MaterialConverterBus GetMaterialTypePath() to return a string instead of char* Minor code cleanup. Signed-off-by: santorac <55155825+santorac@users.noreply.github.com> --- .../MaterialConverterSystemComponent.cpp | 19 ++++++------------- .../MaterialConverterSystemComponent.h | 2 +- .../RPI.Edit/Material/MaterialConverterBus.h | 4 ++-- .../Model/MaterialAssetBuilderComponent.cpp | 4 ++-- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Gems/Atom/Feature/Common/Code/Source/Material/MaterialConverterSystemComponent.cpp b/Gems/Atom/Feature/Common/Code/Source/Material/MaterialConverterSystemComponent.cpp index d5fdcd9e41..e26a0fb274 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Material/MaterialConverterSystemComponent.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/Material/MaterialConverterSystemComponent.cpp @@ -23,12 +23,12 @@ namespace AZ { void MaterialConverterSettings::Reflect(AZ::ReflectContext* context) { - if (auto serializeContext = azrtti_cast(context); serializeContext) + if (auto serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(1) - ->Field("Enable", &MaterialConverterSettings::m_enable) - ->Field("DefaultMaterial", &MaterialConverterSettings::m_defaultMaterial); + ->Version(1) + ->Field("Enable", &MaterialConverterSettings::m_enable) + ->Field("DefaultMaterial", &MaterialConverterSettings::m_defaultMaterial); } } @@ -176,16 +176,9 @@ namespace AZ return true; } - const char* MaterialConverterSystemComponent::GetMaterialTypePath() const + AZStd::string MaterialConverterSystemComponent::GetMaterialTypePath() const { - if (m_settings.m_enable) - { - return "Materials/Types/StandardPBR.materialtype"; - } - else - { - return nullptr; - } + return "Materials/Types/StandardPBR.materialtype"; } AZStd::string MaterialConverterSystemComponent::GetDefaultMaterialPath() const diff --git a/Gems/Atom/Feature/Common/Code/Source/Material/MaterialConverterSystemComponent.h b/Gems/Atom/Feature/Common/Code/Source/Material/MaterialConverterSystemComponent.h index e7e5c63732..7d95024759 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Material/MaterialConverterSystemComponent.h +++ b/Gems/Atom/Feature/Common/Code/Source/Material/MaterialConverterSystemComponent.h @@ -46,7 +46,7 @@ namespace AZ // MaterialConverterBus overrides ... bool IsEnabled() const override; bool ConvertMaterial(const AZ::SceneAPI::DataTypes::IMaterialData& materialData, RPI::MaterialSourceData& out) override; - const char* GetMaterialTypePath() const override; + AZStd::string GetMaterialTypePath() const override; AZStd::string GetDefaultMaterialPath() const override; private: diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Edit/Material/MaterialConverterBus.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Edit/Material/MaterialConverterBus.h index e5aa32c175..8052fc4feb 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Edit/Material/MaterialConverterBus.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Edit/Material/MaterialConverterBus.h @@ -37,8 +37,8 @@ namespace AZ //! @return true if the MaterialSourceData output was populated with converted material data. virtual bool ConvertMaterial(const AZ::SceneAPI::DataTypes::IMaterialData& materialData, MaterialSourceData& out) = 0; - //! Returns the path to the .materialtype file that the converted materials are based on, such as StandardPBR.materialtype, etc. Or nullptr when conversion is disabled. - virtual const char* GetMaterialTypePath() const = 0; + //! Returns the path to the .materialtype file that the converted materials are based on, such as StandardPBR.materialtype, etc. + virtual AZStd::string GetMaterialTypePath() const = 0; //! Returns the path to a .material file to use as the default material when conversion is disabled. virtual AZStd::string GetDefaultMaterialPath() const = 0; diff --git a/Gems/Atom/RPI/Code/Source/RPI.Builders/Model/MaterialAssetBuilderComponent.cpp b/Gems/Atom/RPI/Code/Source/RPI.Builders/Model/MaterialAssetBuilderComponent.cpp index 3eb60956ad..4a4c2156ce 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Builders/Model/MaterialAssetBuilderComponent.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Builders/Model/MaterialAssetBuilderComponent.cpp @@ -75,10 +75,10 @@ namespace AZ RPI::MaterialConverterBus::BroadcastResult(conversionEnabled, &RPI::MaterialConverterBus::Events::IsEnabled); // Right now, scene file importing only supports a single material type, once that changes, this will have to be re-designed, see ATOM-3554 - const char* materialTypePath = nullptr; + AZStd::string materialTypePath; RPI::MaterialConverterBus::BroadcastResult(materialTypePath, &RPI::MaterialConverterBus::Events::GetMaterialTypePath); - if (conversionEnabled && materialTypePath) + if (conversionEnabled && !materialTypePath.empty()) { AssetBuilderSDK::SourceFileDependency materialTypeSource; materialTypeSource.m_sourceFileDependencyPath = materialTypePath;