Files
o3de/Gems/Terrain/Code/Source/TerrainRenderer/TerrainMacroMaterialBus.cpp
T
Ken Pruiksma 2f1346c719 Terrain Feature Processor separated into several classes. Macro materials abstracted from meshes. (#6350)
* Breaking up terrain FP wip - macro materials decoupled from meshes. Mesh creation and rendering pulled out from MeshFeatureProcessor into TerrainMeshManager. Stubs added for macro and detail material managers.

Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>

* Separated macro material management from the terrain feature processor. Also separated bindless image array handling from terrain feature processor.

Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>

* Detail materials separated from terrain feature processor. Also pulled out Aabb2i and Vector2i into their own simple classes

Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>

* Changed some classes so that when the SRG changes the classes don't need to be completely reinitialized and can instead just update their indices and push data to the new srg. Fixed an issue where MacroMaterialData wasn't being exposed to ScriptCanvas. Terrain shader reloads should now work correctly. Also added some debug logging to help catch an issue where sometimes detail materials don't seem to load.

Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>

* Terrain PR reveiw updates

Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>

* Some small PR review fixes. More comments in TerrainDetailMaterialManager.h

Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>

* Fixing unused variable causing clang failure

Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>

* Fixing unused variable in release.

Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>

* Fixing a forward declare that oddly didn't work on linux.

Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>

* Fixing linux missing include... not sure why only linux failed on this.

Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>

* Adding missing include

Signed-off-by: Ken Pruiksma <pruiksma@amazon.com>
2021-12-29 16:38:28 -06:00

113 lines
5.3 KiB
C++

/*
* 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
*
*/
#include "TerrainMacroMaterialBus.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/RTTI/BehaviorContext.h>
namespace Terrain
{
// Create a handler that can be accessed from Python scripts to receive terrain change notifications.
class TerrainMacroMaterialNotificationHandler final
: public Terrain::TerrainMacroMaterialNotificationBus::Handler
, public AZ::BehaviorEBusHandler
{
public:
AZ_EBUS_BEHAVIOR_BINDER(
TerrainMacroMaterialNotificationHandler,
"{B0ED8B29-0E0D-4567-BEAF-C842C4DB2700}",
AZ::SystemAllocator,
OnTerrainMacroMaterialCreated,
OnTerrainMacroMaterialChanged,
OnTerrainMacroMaterialRegionChanged,
OnTerrainMacroMaterialDestroyed);
void OnTerrainMacroMaterialCreated(
[[maybe_unused]] AZ::EntityId macroMaterialEntity,
[[maybe_unused]] const Terrain::MacroMaterialData& macroMaterial) override
{
Call(FN_OnTerrainMacroMaterialCreated);
}
void OnTerrainMacroMaterialChanged(
[[maybe_unused]] AZ::EntityId macroMaterialEntity,
[[maybe_unused]] const Terrain::MacroMaterialData& macroMaterial) override
{
Call(FN_OnTerrainMacroMaterialChanged);
}
void OnTerrainMacroMaterialRegionChanged(
[[maybe_unused]] AZ::EntityId macroMaterialEntity,
[[maybe_unused]] const AZ::Aabb& oldRegion,
[[maybe_unused]] const AZ::Aabb& newRegion) override
{
Call(FN_OnTerrainMacroMaterialRegionChanged);
}
void OnTerrainMacroMaterialDestroyed([[maybe_unused]] AZ::EntityId macroMaterialEntity) override
{
Call(FN_OnTerrainMacroMaterialDestroyed);
}
static void Reflect(AZ::ReflectContext* context)
{
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->EBus<Terrain::TerrainMacroMaterialNotificationBus>("TerrainMacroMaterialAutomationBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
->Attribute(AZ::Script::Attributes::Module, "terrain")
->Handler<TerrainMacroMaterialNotificationHandler>();
}
}
};
void MacroMaterialData::Reflect(AZ::ReflectContext* context)
{
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<MacroMaterialData>()
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Category, "Terrain")
->Attribute(AZ::Script::Attributes::Module, "terrain")
->Property("EntityId", BehaviorValueProperty(&MacroMaterialData::m_entityId))
->Property("Bounds", BehaviorValueProperty(&MacroMaterialData::m_bounds))
->Property("NormalFlipX", BehaviorValueProperty(&MacroMaterialData::m_normalFlipX))
->Property("NormalFlipY", BehaviorValueProperty(&MacroMaterialData::m_normalFlipY))
->Property("NormalFactor", BehaviorValueProperty(&MacroMaterialData::m_normalFactor))
;
}
}
void TerrainMacroMaterialRequests::Reflect(AZ::ReflectContext* context)
{
MacroMaterialData::Reflect(context);
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->EBus<Terrain::TerrainMacroMaterialRequestBus>("TerrainMacroMaterialRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Category, "Terrain")
->Attribute(AZ::Script::Attributes::Module, "terrain")
->Event("GetTerrainMacroMaterialData", &Terrain::TerrainMacroMaterialRequestBus::Events::GetTerrainMacroMaterialData)
;
behaviorContext->EBus<Terrain::TerrainMacroMaterialNotificationBus>("TerrainMacroMaterialNotificationBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Category, "Terrain")
->Attribute(AZ::Script::Attributes::Module, "terrain")
->Event("OnTerrainMacroMaterialCreated", &Terrain::TerrainMacroMaterialNotifications::OnTerrainMacroMaterialCreated)
->Event("OnTerrainMacroMaterialChanged", &Terrain::TerrainMacroMaterialNotifications::OnTerrainMacroMaterialChanged)
->Event("OnTerrainMacroMaterialRegionChanged", &Terrain::TerrainMacroMaterialNotifications::OnTerrainMacroMaterialRegionChanged)
->Event("OnTerrainMacroMaterialDestroyed", &Terrain::TerrainMacroMaterialNotifications::OnTerrainMacroMaterialDestroyed)
;
Terrain::TerrainMacroMaterialNotificationHandler::Reflect(context);
}
}
} // namespace Terrain