Merge branch 'development' into Atom/santorac/OptionalSceneApiMaterialConversion
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
----------------------------------------------------------------------------------------------------
|
||||
--
|
||||
-- Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
-- For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
--
|
||||
-- SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
--
|
||||
--
|
||||
--
|
||||
----------------------------------------------------------------------------------------------------
|
||||
|
||||
local FindMaterialAssignmentTest =
|
||||
{
|
||||
Properties =
|
||||
{
|
||||
Textures =
|
||||
{
|
||||
"materials/presets/macbeth/05_blue_flower_srgb.tif.streamingimage",
|
||||
"materials/presets/macbeth/06_bluish_green_srgb.tif.streamingimage",
|
||||
"materials/presets/macbeth/09_moderate_red_srgb.tif.streamingimage",
|
||||
"materials/presets/macbeth/11_yellow_green_srgb.tif.streamingimage",
|
||||
"materials/presets/macbeth/12_orange_yellow_srgb.tif.streamingimage",
|
||||
"materials/presets/macbeth/17_magenta_srgb.tif.streamingimage"
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
function randomColor()
|
||||
return Color(math.random(), math.random(), math.random(), 1.0)
|
||||
end
|
||||
|
||||
function randomDir()
|
||||
dir = {}
|
||||
for i = 1, 3 do
|
||||
lerpDir = math.random()
|
||||
if lerpDir < 0.5 then
|
||||
table.insert(dir, -1.0)
|
||||
else
|
||||
table.insert(dir, 1.0)
|
||||
end
|
||||
end
|
||||
return dir
|
||||
end
|
||||
|
||||
function FindMaterialAssignmentTest:OnActivate()
|
||||
self.timer = 0.0
|
||||
self.totalTime = 0.0
|
||||
self.totalTimeMax = 200.0
|
||||
self.timeUpdate = 2.0
|
||||
self.colors = {}
|
||||
self.lerpDirs = {}
|
||||
|
||||
self.assignmentIds =
|
||||
{
|
||||
MaterialComponentRequestBus.Event.FindMaterialAssignmentId(self.entityId, -1, "lambert"),
|
||||
}
|
||||
|
||||
for index = 1, #self.assignmentIds do
|
||||
local id = self.assignmentIds[index]
|
||||
if (id ~= nil) then
|
||||
self.colors[index] = randomColor()
|
||||
self.lerpDirs[index] = randomDir()
|
||||
end
|
||||
end
|
||||
self.tickBusHandler = TickBus.Connect(self);
|
||||
end
|
||||
|
||||
function FindMaterialAssignmentTest:UpdateFactor(assignmentId)
|
||||
local propertyName = Name("baseColor.factor")
|
||||
local propertyValue = math.random()
|
||||
MaterialComponentRequestBus.Event.SetPropertyOverride(self.entityId, assignmentId, propertyName, propertyValue);
|
||||
end
|
||||
|
||||
function FindMaterialAssignmentTest:UpdateColor(assignmentId, color)
|
||||
local propertyName = Name("baseColor.color")
|
||||
local propertyValue = color
|
||||
MaterialComponentRequestBus.Event.SetPropertyOverride(self.entityId, assignmentId, propertyName, propertyValue);
|
||||
end
|
||||
|
||||
function FindMaterialAssignmentTest:UpdateTexture(assignmentId)
|
||||
if (#self.Properties.Textures > 0) then
|
||||
local propertyName = Name("baseColor.textureMap")
|
||||
local textureName = self.Properties.Textures[ math.random( #self.Properties.Textures ) ]
|
||||
Debug.Log(textureName)
|
||||
local textureAssetId = AssetCatalogRequestBus.Broadcast.GetAssetIdByPath(textureName, Uuid(), false)
|
||||
MaterialComponentRequestBus.Event.SetPropertyOverride(self.entityId, assignmentId, propertyName, textureAssetId);
|
||||
end
|
||||
end
|
||||
|
||||
function FindMaterialAssignmentTest:UpdateProperties()
|
||||
Debug.Log("Overriding properties...")
|
||||
for index = 1, #self.assignmentIds do
|
||||
local id = self.assignmentIds[index]
|
||||
if (id ~= nil) then
|
||||
self:UpdateFactor(id)
|
||||
self:UpdateTexture(id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function FindMaterialAssignmentTest:ClearProperties()
|
||||
Debug.Log("Clearing properties...")
|
||||
MaterialComponentRequestBus.Event.ClearAllPropertyOverrides(self.entityId);
|
||||
end
|
||||
|
||||
function lerpColor(color, lerpDir, deltaTime)
|
||||
local lerpSpeed = 0.5
|
||||
color.r = color.r + deltaTime * lerpDir[1] * lerpSpeed
|
||||
if color.r > 1.0 then
|
||||
color.r = 1.0
|
||||
lerpDir[1] = -1.0
|
||||
elseif color.r < 0 then
|
||||
color.r = 0
|
||||
lerpDir[1] = 1.0
|
||||
end
|
||||
|
||||
color.g = color.g + deltaTime * lerpDir[2] * lerpSpeed
|
||||
if color.g > 1.0 then
|
||||
color.g = 1.0
|
||||
lerpDir[2] = -1.0
|
||||
elseif color.g < 0 then
|
||||
color.g = 0
|
||||
lerpDir[2] = 1.0
|
||||
end
|
||||
|
||||
color.b = color.b + deltaTime * lerpDir[3] * lerpSpeed
|
||||
if color.b > 1.0 then
|
||||
color.b = 1.0
|
||||
lerpDir[3] = -1.0
|
||||
elseif color.b < 0 then
|
||||
color.b = 0
|
||||
lerpDir[3] = 1.0
|
||||
end
|
||||
end
|
||||
|
||||
function FindMaterialAssignmentTest:lerpColors(deltaTime)
|
||||
for index = 1, #self.assignmentIds do
|
||||
local id = self.assignmentIds[index]
|
||||
if (id ~= nil) then
|
||||
lerpColor(self.colors[index], self.lerpDirs[index], deltaTime)
|
||||
self:UpdateColor(id, self.colors[index])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function FindMaterialAssignmentTest:OnTick(deltaTime, timePoint)
|
||||
self.timer = self.timer + deltaTime
|
||||
self.totalTime = self.totalTime + deltaTime
|
||||
self:lerpColors(deltaTime)
|
||||
|
||||
if (self.timer > self.timeUpdate and self.totalTime < self.totalTimeMax) then
|
||||
self.timer = self.timer - self.timeUpdate
|
||||
self:UpdateProperties()
|
||||
elseif self.totalTime > self.totalTimeMax then
|
||||
self:ClearProperties()
|
||||
self.tickBusHandler:Disconnect(self);
|
||||
end
|
||||
end
|
||||
|
||||
return FindMaterialAssignmentTest
|
||||
@@ -5,6 +5,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Atom/Feature/Material/MaterialAssignmentId.h>
|
||||
@@ -63,5 +64,8 @@ namespace AZ
|
||||
//! Utility function for generating a set of available material assignments in a model
|
||||
MaterialAssignmentMap GetMaterialAssignmentsFromModel(Data::Instance<AZ::RPI::Model> model);
|
||||
|
||||
//! Find an assignment id corresponding to the lod and label substring filters
|
||||
MaterialAssignmentId FindMaterialAssignmentIdInModel(
|
||||
const Data::Instance<AZ::RPI::Model> model, const MaterialAssignmentLodIndex lodFilter, const AZStd::string& labelFilter);
|
||||
} // namespace Render
|
||||
} // namespace AZ
|
||||
|
||||
@@ -166,5 +166,48 @@ namespace AZ
|
||||
|
||||
return materials;
|
||||
}
|
||||
|
||||
MaterialAssignmentId FindMaterialAssignmentIdInLod(
|
||||
const Data::Instance<AZ::RPI::ModelLod>& lod, const MaterialAssignmentLodIndex lodIndex, const AZStd::string& labelFilter)
|
||||
{
|
||||
for (const AZ::RPI::ModelLod::Mesh& mesh : lod->GetMeshes())
|
||||
{
|
||||
if (mesh.m_material && mesh.m_material->GetAssetId().IsValid())
|
||||
{
|
||||
AZ::Data::AssetInfo assetInfo;
|
||||
AZ::Data::AssetCatalogRequestBus::BroadcastResult(
|
||||
assetInfo, &AZ::Data::AssetCatalogRequests::GetAssetInfoById, mesh.m_material->GetAssetId());
|
||||
if (assetInfo.m_assetId.IsValid() && AZ::StringFunc::Contains(assetInfo.m_relativePath, labelFilter, true))
|
||||
{
|
||||
return MaterialAssignmentId::CreateFromLodAndAsset(lodIndex, mesh.m_material->GetAssetId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return MaterialAssignmentId();
|
||||
}
|
||||
|
||||
MaterialAssignmentId FindMaterialAssignmentIdInModel(
|
||||
const Data::Instance<AZ::RPI::Model> model, const MaterialAssignmentLodIndex lodFilter, const AZStd::string& labelFilter)
|
||||
{
|
||||
if (model && !labelFilter.empty())
|
||||
{
|
||||
if (lodFilter < model->GetLodCount())
|
||||
{
|
||||
return FindMaterialAssignmentIdInLod(model->GetLods()[lodFilter], lodFilter, labelFilter);
|
||||
}
|
||||
|
||||
for (size_t lodIndex = 0; lodIndex < model->GetLodCount(); ++lodIndex)
|
||||
{
|
||||
const MaterialAssignmentId result =
|
||||
FindMaterialAssignmentIdInLod(model->GetLods()[lodIndex], MaterialAssignmentId::NonLodIndex, labelFilter);
|
||||
if (!result.IsDefault())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return MaterialAssignmentId();
|
||||
}
|
||||
} // namespace Render
|
||||
} // namespace AZ
|
||||
|
||||
+6
@@ -21,6 +21,8 @@ namespace AZ
|
||||
public:
|
||||
//! Get all material assignments that can be overridden
|
||||
virtual MaterialAssignmentMap GetOriginalMaterialAssignments() const = 0;
|
||||
//! Get material assignment id matching lod and label substring
|
||||
virtual MaterialAssignmentId FindMaterialAssignmentId(const MaterialAssignmentLodIndex lod, const AZStd::string& label) const = 0;
|
||||
//! Set material overrides
|
||||
virtual void SetMaterialOverrides(const MaterialAssignmentMap& materials) = 0;
|
||||
//! Get material overrides
|
||||
@@ -69,6 +71,10 @@ namespace AZ
|
||||
: public ComponentBus
|
||||
{
|
||||
public:
|
||||
//! Get material assignment id matching lod and label substring
|
||||
virtual MaterialAssignmentId FindMaterialAssignmentId(
|
||||
const MaterialAssignmentLodIndex lod, const AZStd::string& label) const = 0;
|
||||
|
||||
//! Returns the list of all ModelMaterialSlot's for the model, across all LODs.
|
||||
virtual RPI::ModelMaterialSlotMap GetModelMaterialSlots() const = 0;
|
||||
|
||||
|
||||
+12
-1
@@ -33,6 +33,7 @@ namespace AZ
|
||||
->Attribute(AZ::Script::Attributes::Category, "render")
|
||||
->Attribute(AZ::Script::Attributes::Module, "render")
|
||||
->Event("GetOriginalMaterialAssignments", &MaterialComponentRequestBus::Events::GetOriginalMaterialAssignments)
|
||||
->Event("FindMaterialAssignmentId", &MaterialComponentRequestBus::Events::FindMaterialAssignmentId)
|
||||
->Event("SetMaterialOverrides", &MaterialComponentRequestBus::Events::SetMaterialOverrides)
|
||||
->Event("GetMaterialOverrides", &MaterialComponentRequestBus::Events::GetMaterialOverrides)
|
||||
->Event("ClearAllMaterialOverrides", &MaterialComponentRequestBus::Events::ClearAllMaterialOverrides)
|
||||
@@ -249,10 +250,20 @@ namespace AZ
|
||||
MaterialAssignmentMap MaterialComponentController::GetOriginalMaterialAssignments() const
|
||||
{
|
||||
MaterialAssignmentMap materialAssignmentMap;
|
||||
MaterialReceiverRequestBus::EventResult(materialAssignmentMap, m_entityId, &MaterialReceiverRequestBus::Events::GetMaterialAssignments);
|
||||
MaterialReceiverRequestBus::EventResult(
|
||||
materialAssignmentMap, m_entityId, &MaterialReceiverRequestBus::Events::GetMaterialAssignments);
|
||||
return materialAssignmentMap;
|
||||
}
|
||||
|
||||
MaterialAssignmentId MaterialComponentController::FindMaterialAssignmentId(
|
||||
const MaterialAssignmentLodIndex lod, const AZStd::string& label) const
|
||||
{
|
||||
MaterialAssignmentId materialAssignmentId;
|
||||
MaterialReceiverRequestBus::EventResult(
|
||||
materialAssignmentId, m_entityId, &MaterialReceiverRequestBus::Events::FindMaterialAssignmentId, lod, label);
|
||||
return materialAssignmentId;
|
||||
}
|
||||
|
||||
void MaterialComponentController::SetMaterialOverrides(const MaterialAssignmentMap& materials)
|
||||
{
|
||||
// this function is called twice once material asset is changed, a temp variable is
|
||||
|
||||
+1
@@ -46,6 +46,7 @@ namespace AZ
|
||||
|
||||
//! MaterialComponentRequestBus overrides...
|
||||
MaterialAssignmentMap GetOriginalMaterialAssignments() const override;
|
||||
MaterialAssignmentId FindMaterialAssignmentId(const MaterialAssignmentLodIndex lod, const AZStd::string& label) const override;
|
||||
void SetMaterialOverrides(const MaterialAssignmentMap& materials) override;
|
||||
const MaterialAssignmentMap& GetMaterialOverrides() const override;
|
||||
void ClearAllMaterialOverrides() override;
|
||||
|
||||
@@ -265,6 +265,12 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
MaterialAssignmentId MeshComponentController::FindMaterialAssignmentId(
|
||||
const MaterialAssignmentLodIndex lod, const AZStd::string& label) const
|
||||
{
|
||||
return FindMaterialAssignmentIdInModel(GetModel(), lod, label);
|
||||
}
|
||||
|
||||
MaterialAssignmentMap MeshComponentController::GetMaterialAssignments() const
|
||||
{
|
||||
return GetMaterialAssignmentsFromModel(GetModel());
|
||||
|
||||
@@ -111,6 +111,8 @@ namespace AZ
|
||||
void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override;
|
||||
|
||||
// MaterialReceiverRequestBus::Handler overrides ...
|
||||
virtual MaterialAssignmentId FindMaterialAssignmentId(
|
||||
const MaterialAssignmentLodIndex lod, const AZStd::string& label) const override;
|
||||
RPI::ModelMaterialSlotMap GetModelMaterialSlots() const override;
|
||||
MaterialAssignmentMap GetMaterialAssignments() const override;
|
||||
AZStd::unordered_set<AZ::Name> GetModelUvNames() const override;
|
||||
|
||||
@@ -321,6 +321,17 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
MaterialAssignmentId AtomActorInstance::FindMaterialAssignmentId(
|
||||
const MaterialAssignmentLodIndex lod, const AZStd::string& label) const
|
||||
{
|
||||
if (m_skinnedMeshInstance && m_skinnedMeshInstance->m_model)
|
||||
{
|
||||
return FindMaterialAssignmentIdInModel(m_skinnedMeshInstance->m_model, lod, label);
|
||||
}
|
||||
|
||||
return MaterialAssignmentId();
|
||||
}
|
||||
|
||||
MaterialAssignmentMap AtomActorInstance::GetMaterialAssignments() const
|
||||
{
|
||||
if (m_skinnedMeshInstance && m_skinnedMeshInstance->m_model)
|
||||
|
||||
@@ -120,6 +120,8 @@ namespace AZ
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// MaterialReceiverRequestBus::Handler overrides...
|
||||
virtual MaterialAssignmentId FindMaterialAssignmentId(
|
||||
const MaterialAssignmentLodIndex lod, const AZStd::string& label) const override;
|
||||
RPI::ModelMaterialSlotMap GetModelMaterialSlots() const override;
|
||||
MaterialAssignmentMap GetMaterialAssignments() const override;
|
||||
AZStd::unordered_set<AZ::Name> GetModelUvNames() const override;
|
||||
|
||||
@@ -120,7 +120,6 @@ namespace ScriptCanvasEditor
|
||||
m_variableName = m_variable->GetVariableName();
|
||||
|
||||
const AZStd::string variableTypeName = TranslationHelper::GetSafeTypeName(m_variable->GetDatum()->GetType());
|
||||
m_variable->SetDisplayName(variableTypeName);
|
||||
|
||||
m_componentTitle = AZStd::string::format("%s Variable", variableTypeName.data());
|
||||
|
||||
|
||||
@@ -2083,7 +2083,6 @@ namespace ScriptCanvas
|
||||
editContext->Class<Datum>("Datum", "Datum")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "Datum")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &Datum::GetVisibility)
|
||||
->Attribute(AZ::Edit::Attributes::ChildNameLabelOverride, &Datum::GetLabel)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &Datum::m_storage, "Datum", "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &Datum::GetDatumVisibility)
|
||||
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
||||
|
||||
@@ -348,7 +348,6 @@ namespace ScriptCanvas
|
||||
void GraphVariable::SetVariableName(AZStd::string_view variableName)
|
||||
{
|
||||
m_variableName = variableName;
|
||||
SetDisplayName(variableName);
|
||||
}
|
||||
|
||||
AZStd::string_view GraphVariable::GetVariableName() const
|
||||
@@ -356,16 +355,6 @@ namespace ScriptCanvas
|
||||
return m_variableName;
|
||||
}
|
||||
|
||||
void GraphVariable::SetDisplayName(const AZStd::string& displayName)
|
||||
{
|
||||
m_datum.SetLabel(displayName);
|
||||
}
|
||||
|
||||
AZStd::string_view GraphVariable::GetDisplayName() const
|
||||
{
|
||||
return m_datum.GetLabel();
|
||||
}
|
||||
|
||||
void GraphVariable::SetScriptInputControlVisibility(const AZ::Crc32& inputControlVisibility)
|
||||
{
|
||||
m_inputControlVisibility = inputControlVisibility;
|
||||
|
||||
@@ -134,9 +134,6 @@ namespace ScriptCanvas
|
||||
void SetVariableName(AZStd::string_view displayName);
|
||||
AZStd::string_view GetVariableName() const;
|
||||
|
||||
void SetDisplayName(const AZStd::string& displayName);
|
||||
AZStd::string_view GetDisplayName() const;
|
||||
|
||||
void SetScriptInputControlVisibility(const AZ::Crc32& inputControlVisibility);
|
||||
|
||||
AZ::Crc32 GetInputControlVisibility() const;
|
||||
|
||||
Reference in New Issue
Block a user