@ -40,6 +40,12 @@
# include <AtomLyIntegration/CommonFeatures/PostProcess/ExposureControl/ExposureControlBus.h>
# include <AtomLyIntegration/CommonFeatures/PostProcess/ExposureControl/ExposureControlBus.h>
# include <AtomLyIntegration/CommonFeatures/PostProcess/ExposureControl/ExposureControlComponentConstants.h>
# include <AtomLyIntegration/CommonFeatures/PostProcess/ExposureControl/ExposureControlComponentConstants.h>
# include <AtomLyIntegration/CommonFeatures/PostProcess/PostFxLayerComponentConstants.h>
# include <AtomLyIntegration/CommonFeatures/PostProcess/PostFxLayerComponentConstants.h>
# include <AtomToolsFramework/Viewport/ViewportInputBehaviorController/DollyCameraBehavior.h>
# include <AtomToolsFramework/Viewport/ViewportInputBehaviorController/MoveCameraBehavior.h>
# include <AtomToolsFramework/Viewport/ViewportInputBehaviorController/OrbitCameraBehavior.h>
# include <AtomToolsFramework/Viewport/ViewportInputBehaviorController/PanCameraBehavior.h>
# include <AtomToolsFramework/Viewport/ViewportInputBehaviorController/RotateEnvironmentBehavior.h>
# include <AtomToolsFramework/Viewport/ViewportInputBehaviorController/RotateModelBehavior.h>
# include <AzCore/Component/Component.h>
# include <AzCore/Component/Component.h>
# include <AzCore/Component/Entity.h>
# include <AzCore/Component/Entity.h>
# include <AzFramework/Components/NonUniformScaleComponent.h>
# include <AzFramework/Components/NonUniformScaleComponent.h>
@ -64,7 +70,6 @@ namespace MaterialEditor
: AtomToolsFramework : : RenderViewportWidget ( parent )
: AtomToolsFramework : : RenderViewportWidget ( parent )
, m_ui ( new Ui : : MaterialViewportWidget )
, m_ui ( new Ui : : MaterialViewportWidget )
, m_toolId ( toolId )
, m_toolId ( toolId )
, m_viewportController ( AZStd : : make_shared < MaterialEditorViewportInputController > ( ) )
{
{
m_ui - > setupUi ( this ) ;
m_ui - > setupUi ( this ) ;
@ -117,31 +122,24 @@ namespace MaterialEditor
entityContextId , & AzFramework : : GameEntityContextRequestBus : : Events : : GetGameEntityContextId ) ;
entityContextId , & AzFramework : : GameEntityContextRequestBus : : Events : : GetGameEntityContextId ) ;
// Configure camera
// Configure camera
AzFramework : : EntityContextRequestBus : : EventResult (
m_cameraEntity =
m_cameraEntity , entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : CreateEntity , " Cameraentity " ) ;
CreateEntity ( " Cameraentity " , { azrtti_typeid < AzFramework : : TransformComponent > ( ) , azrtti_typeid < AZ : : Debug : : CameraComponent > ( ) } ) ;
AZ_Assert ( m_cameraEntity ! = nullptr , " Failed to create camera entity. " ) ;
// Add debug camera and controller components
AZ : : Debug : : CameraComponentConfig cameraConfig ( GetViewportContext ( ) - > GetWindowContext ( ) ) ;
AZ : : Debug : : CameraComponentConfig cameraConfig ( GetViewportContext ( ) - > GetWindowContext ( ) ) ;
cameraConfig . m_fovY = AZ : : Constants : : HalfPi ;
cameraConfig . m_fovY = AZ : : Constants : : HalfPi ;
cameraConfig . m_depthNear = DepthNear ;
cameraConfig . m_depthNear = DepthNear ;
m_cameraComponent = m_cameraEntity - > CreateComponent ( azrtti_typeid < AZ : : Debug : : CameraComponent > ( ) ) ;
m_cameraEntity - > Deactivate ( ) ;
m_cameraComponent - > SetConfiguration ( cameraConfig ) ;
m_cameraEntity - > FindComponent ( azrtti_typeid < AZ : : Debug : : CameraComponent > ( ) ) - > SetConfiguration ( cameraConfig ) ;
m_cameraEntity - > CreateComponent ( azrtti_typeid < AzFramework : : TransformComponent > ( ) ) ;
m_cameraEntity - > Activate ( ) ;
m_cameraEntity - > Activate ( ) ;
// Connect camera to pipeline's default view after camera entity activated
// Connect camera to pipeline's default view after camera entity activated
m_renderPipeline - > SetDefaultViewFromEntity ( m_cameraEntity - > GetId ( ) ) ;
m_renderPipeline - > SetDefaultViewFromEntity ( m_cameraEntity - > GetId ( ) ) ;
// Configure tone mapper
// Configure tone mapper
AzFramework : : EntityContextRequestBus : : EventResult (
m_postProcessEntity = CreateEntity (
m_postProcessEntity , entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : CreateEntity , " postProcessEntity " ) ;
" PostProcessEntity " ,
AZ_Assert ( m_postProcessEntity ! = nullptr , " Failed to create post process entity. " ) ;
{ AZ : : Render : : PostFxLayerComponentTypeId , AZ : : Render : : ExposureControlComponentTypeId ,
azrtti_typeid < AzFramework : : TransformComponent > ( ) } ) ;
m_postProcessEntity - > CreateComponent ( AZ : : Render : : PostFxLayerComponentTypeId ) ;
m_postProcessEntity - > CreateComponent ( AZ : : Render : : ExposureControlComponentTypeId ) ;
m_postProcessEntity - > CreateComponent ( azrtti_typeid < AzFramework : : TransformComponent > ( ) ) ;
m_postProcessEntity - > Activate ( ) ;
// Init directional light processor
// Init directional light processor
m_directionalLightFeatureProcessor = m_scene - > GetFeatureProcessor < AZ : : Render : : DirectionalLightFeatureProcessorInterface > ( ) ;
m_directionalLightFeatureProcessor = m_scene - > GetFeatureProcessor < AZ : : Render : : DirectionalLightFeatureProcessorInterface > ( ) ;
@ -155,33 +153,19 @@ namespace MaterialEditor
m_skyboxFeatureProcessor - > SetSkyboxMode ( AZ : : Render : : SkyBoxMode : : Cubemap ) ;
m_skyboxFeatureProcessor - > SetSkyboxMode ( AZ : : Render : : SkyBoxMode : : Cubemap ) ;
// Create IBL
// Create IBL
AzFramework : : EntityContextRequestBus : : EventResult (
m_iblEntity =
m_iblEntity , entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : CreateEntity , " IblEntity " ) ;
CreateEntity ( " IblEntity " , { AZ : : Render : : ImageBasedLightComponentTypeId , azrtti_typeid < AzFramework : : TransformComponent > ( ) } ) ;
AZ_Assert ( m_iblEntity ! = nullptr , " Failed to create ibl entity. " ) ;
m_iblEntity - > CreateComponent ( AZ : : Render : : ImageBasedLightComponentTypeId ) ;
m_iblEntity - > CreateComponent ( azrtti_typeid < AzFramework : : TransformComponent > ( ) ) ;
m_iblEntity - > Activate ( ) ;
// Create model
// Create model
AzFramework : : EntityContextRequestBus : : EventResult (
m_modelEntity = CreateEntity (
m_modelEntity , entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : CreateEntity , " ViewportModel " ) ;
" ViewportModel " ,
AZ_Assert ( m_modelEntity ! = nullptr , " Failed to create model entity. " ) ;
{ AZ : : Render : : MeshComponentTypeId , AZ : : Render : : MaterialComponentTypeId , azrtti_typeid < AzFramework : : TransformComponent > ( ) } ) ;
m_modelEntity - > CreateComponent ( AZ : : Render : : MeshComponentTypeId ) ;
m_modelEntity - > CreateComponent ( AZ : : Render : : MaterialComponentTypeId ) ;
m_modelEntity - > CreateComponent ( azrtti_typeid < AzFramework : : TransformComponent > ( ) ) ;
m_modelEntity - > Activate ( ) ;
// Create shadow catcher
// Create shadow catcher
AzFramework : : EntityContextRequestBus : : EventResult (
m_shadowCatcherEntity = CreateEntity (
m_shadowCatcherEntity , entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : CreateEntity , " ViewportShadowCatcher " ) ;
" ViewportShadowCatcher " ,
AZ_Assert ( m_shadowCatcherEntity ! = nullptr , " Failed to create shadow catcher entity. " ) ;
{ AZ : : Render : : MeshComponentTypeId , AZ : : Render : : MaterialComponentTypeId , azrtti_typeid < AzFramework : : TransformComponent > ( ) ,
m_shadowCatcherEntity - > CreateComponent ( AZ : : Render : : MeshComponentTypeId ) ;
azrtti_typeid < AzFramework : : NonUniformScaleComponent > ( ) } ) ;
m_shadowCatcherEntity - > CreateComponent ( AZ : : Render : : MaterialComponentTypeId ) ;
m_shadowCatcherEntity - > CreateComponent ( azrtti_typeid < AzFramework : : TransformComponent > ( ) ) ;
m_shadowCatcherEntity - > CreateComponent ( azrtti_typeid < AzFramework : : NonUniformScaleComponent > ( ) ) ;
m_shadowCatcherEntity - > Activate ( ) ;
AZ : : NonUniformScaleRequestBus : : Event (
AZ : : NonUniformScaleRequestBus : : Event (
m_shadowCatcherEntity - > GetId ( ) , & AZ : : NonUniformScaleRequests : : SetScale , AZ : : Vector3 { 100 , 100 , 1.0 } ) ;
m_shadowCatcherEntity - > GetId ( ) , & AZ : : NonUniformScaleRequests : : SetScale , AZ : : Vector3 { 100 , 100 , 1.0 } ) ;
@ -214,21 +198,19 @@ namespace MaterialEditor
}
}
// Create grid
// Create grid
AzFramework : : EntityContextRequestBus : : EventResult (
m_gridEntity = CreateEntity ( " ViewportGrid " , { AZ : : Render : : GridComponentTypeId , azrtti_typeid < AzFramework : : TransformComponent > ( ) } ) ;
m_gridEntity , entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : CreateEntity , " ViewportGrid " ) ;
AZ_Assert ( m_gridEntity ! = nullptr , " Failed to create grid entity. " ) ;
AZ : : Render : : GridComponentConfig gridConfig ;
AZ : : Render : : GridComponentConfig gridConfig ;
gridConfig . m_gridSize = 4.0f ;
gridConfig . m_gridSize = 4.0f ;
gridConfig . m_axisColor = AZ : : Color ( 0.1f , 0.1f , 0.1f , 1.0f ) ;
gridConfig . m_axisColor = AZ : : Color ( 0.1f , 0.1f , 0.1f , 1.0f ) ;
gridConfig . m_primaryColor = AZ : : Color ( 0.1f , 0.1f , 0.1f , 1.0f ) ;
gridConfig . m_primaryColor = AZ : : Color ( 0.1f , 0.1f , 0.1f , 1.0f ) ;
gridConfig . m_secondaryColor = AZ : : Color ( 0.1f , 0.1f , 0.1f , 1.0f ) ;
gridConfig . m_secondaryColor = AZ : : Color ( 0.1f , 0.1f , 0.1f , 1.0f ) ;
auto gridComponent = m_gridEntity - > CreateComponent ( AZ : : Render : : GridComponentTypeId ) ;
m_gridEntity - > Deactivate ( ) ;
gridComponent - > SetConfiguration ( gridConfig ) ;
m_gridEntity - > FindComponent ( AZ : : Render : : GridComponentTypeId ) - > SetConfiguration ( gridConfig ) ;
m_gridEntity - > CreateComponent ( azrtti_typeid < AzFramework : : TransformComponent > ( ) ) ;
m_gridEntity - > Activate ( ) ;
m_gridEntity - > Activate ( ) ;
SetupInputController ( ) ;
OnDocumentOpened ( AZ : : Uuid : : CreateNull ( ) ) ;
OnDocumentOpened ( AZ : : Uuid : : CreateNull ( ) ) ;
// Attempt to apply the default lighting preset
// Attempt to apply the default lighting preset
@ -241,8 +223,6 @@ namespace MaterialEditor
MaterialViewportRequestBus : : BroadcastResult ( modelPreset , & MaterialViewportRequestBus : : Events : : GetModelPresetSelection ) ;
MaterialViewportRequestBus : : BroadcastResult ( modelPreset , & MaterialViewportRequestBus : : Events : : GetModelPresetSelection ) ;
OnModelPresetSelected ( modelPreset ) ;
OnModelPresetSelected ( modelPreset ) ;
m_viewportController - > Init ( m_cameraEntity - > GetId ( ) , m_modelEntity - > GetId ( ) , m_iblEntity - > GetId ( ) ) ;
// Apply user settinngs restored since last run
// Apply user settinngs restored since last run
AZStd : : intrusive_ptr < MaterialViewportSettings > viewportSettings =
AZStd : : intrusive_ptr < MaterialViewportSettings > viewportSettings =
AZ : : UserSettings : : CreateFind < MaterialViewportSettings > ( AZ : : Crc32 ( " MaterialViewportSettings " ) , AZ : : UserSettings : : CT_GLOBAL ) ;
AZ : : UserSettings : : CreateFind < MaterialViewportSettings > ( AZ : : Crc32 ( " MaterialViewportSettings " ) , AZ : : UserSettings : : CT_GLOBAL ) ;
@ -257,8 +237,6 @@ namespace MaterialEditor
MaterialViewportNotificationBus : : Handler : : BusConnect ( ) ;
MaterialViewportNotificationBus : : Handler : : BusConnect ( ) ;
AZ : : TickBus : : Handler : : BusConnect ( ) ;
AZ : : TickBus : : Handler : : BusConnect ( ) ;
AZ : : TransformNotificationBus : : MultiHandler : : BusConnect ( m_cameraEntity - > GetId ( ) ) ;
AZ : : TransformNotificationBus : : MultiHandler : : BusConnect ( m_cameraEntity - > GetId ( ) ) ;
GetControllerList ( ) - > Add ( m_viewportController ) ;
}
}
MaterialViewportWidget : : ~ MaterialViewportWidget ( )
MaterialViewportWidget : : ~ MaterialViewportWidget ( )
@ -269,33 +247,12 @@ namespace MaterialEditor
MaterialViewportNotificationBus : : Handler : : BusDisconnect ( ) ;
MaterialViewportNotificationBus : : Handler : : BusDisconnect ( ) ;
AZ : : Data : : AssetBus : : Handler : : BusDisconnect ( ) ;
AZ : : Data : : AssetBus : : Handler : : BusDisconnect ( ) ;
AzFramework : : EntityContextId entityContextId ;
DestroyEntity ( m_iblEntity ) ;
AzFramework : : GameEntityContextRequestBus : : BroadcastResult (
DestroyEntity ( m_modelEntity ) ;
entityContextId , & AzFramework : : GameEntityContextRequestBus : : Events : : GetGameEntityContextId ) ;
DestroyEntity ( m_shadowCatcherEntity ) ;
DestroyEntity ( m_gridEntity ) ;
AzFramework : : EntityContextRequestBus : : Event (
DestroyEntity ( m_cameraEntity ) ;
entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : DestroyEntity , m_iblEntity ) ;
DestroyEntity ( m_postProcessEntity ) ;
m_iblEntity = nullptr ;
AzFramework : : EntityContextRequestBus : : Event (
entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : DestroyEntity , m_modelEntity ) ;
m_modelEntity = nullptr ;
AzFramework : : EntityContextRequestBus : : Event (
entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : DestroyEntity , m_shadowCatcherEntity ) ;
m_shadowCatcherEntity = nullptr ;
AzFramework : : EntityContextRequestBus : : Event (
entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : DestroyEntity , m_gridEntity ) ;
m_gridEntity = nullptr ;
AzFramework : : EntityContextRequestBus : : Event (
entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : DestroyEntity , m_cameraEntity ) ;
m_cameraEntity = nullptr ;
AzFramework : : EntityContextRequestBus : : Event (
entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : DestroyEntity , m_postProcessEntity ) ;
m_postProcessEntity = nullptr ;
for ( DirectionalLightHandle & handle : m_lightHandles )
for ( DirectionalLightHandle & handle : m_lightHandles )
{
{
@ -315,6 +272,74 @@ namespace MaterialEditor
m_scene = nullptr ;
m_scene = nullptr ;
}
}
AZ : : Entity * MaterialViewportWidget : : CreateEntity ( const AZStd : : string & name , const AZStd : : vector < AZ : : Uuid > & componentTypeIds )
{
AzFramework : : EntityContextId entityContextId ;
AzFramework : : GameEntityContextRequestBus : : BroadcastResult (
entityContextId , & AzFramework : : GameEntityContextRequestBus : : Events : : GetGameEntityContextId ) ;
AZ : : Entity * entity = { } ;
AzFramework : : EntityContextRequestBus : : EventResult (
entity , entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : CreateEntity , name . c_str ( ) ) ;
AZ_Assert ( entity ! = nullptr , " Failed to create post process entity: %s. " , name . c_str ( ) ) ;
if ( entity )
{
for ( const auto & componentTypeId : componentTypeIds )
{
entity - > CreateComponent ( componentTypeId ) ;
}
entity - > Activate ( ) ;
}
return entity ;
}
void MaterialViewportWidget : : DestroyEntity ( AZ : : Entity * & entity )
{
AzFramework : : EntityContextId entityContextId ;
AzFramework : : GameEntityContextRequestBus : : BroadcastResult (
entityContextId , & AzFramework : : GameEntityContextRequestBus : : Events : : GetGameEntityContextId ) ;
AzFramework : : EntityContextRequestBus : : Event ( entityContextId , & AzFramework : : EntityContextRequestBus : : Events : : DestroyEntity , entity ) ;
entity = nullptr ;
}
void MaterialViewportWidget : : SetupInputController ( )
{
using namespace AtomToolsFramework ;
// Create viewport input controller and regioster its behaviors
m_viewportController . reset (
aznew ViewportInputBehaviorController ( m_cameraEntity - > GetId ( ) , m_modelEntity - > GetId ( ) , m_iblEntity - > GetId ( ) ) ) ;
m_viewportController - > AddBehavior (
ViewportInputBehaviorController : : Lmb , AZStd : : make_shared < PanCameraBehavior > ( m_viewportController . get ( ) ) ) ;
m_viewportController - > AddBehavior (
ViewportInputBehaviorController : : Mmb , AZStd : : make_shared < MoveCameraBehavior > ( m_viewportController . get ( ) ) ) ;
m_viewportController - > AddBehavior (
ViewportInputBehaviorController : : Rmb , AZStd : : make_shared < OrbitCameraBehavior > ( m_viewportController . get ( ) ) ) ;
m_viewportController - > AddBehavior (
ViewportInputBehaviorController : : Alt ^ ViewportInputBehaviorController : : Lmb ,
AZStd : : make_shared < OrbitCameraBehavior > ( m_viewportController . get ( ) ) ) ;
m_viewportController - > AddBehavior (
ViewportInputBehaviorController : : Alt ^ ViewportInputBehaviorController : : Mmb ,
AZStd : : make_shared < MoveCameraBehavior > ( m_viewportController . get ( ) ) ) ;
m_viewportController - > AddBehavior (
ViewportInputBehaviorController : : Alt ^ ViewportInputBehaviorController : : Rmb ,
AZStd : : make_shared < DollyCameraBehavior > ( m_viewportController . get ( ) ) ) ;
m_viewportController - > AddBehavior (
ViewportInputBehaviorController : : Lmb ^ ViewportInputBehaviorController : : Rmb ,
AZStd : : make_shared < DollyCameraBehavior > ( m_viewportController . get ( ) ) ) ;
m_viewportController - > AddBehavior (
ViewportInputBehaviorController : : Ctrl ^ ViewportInputBehaviorController : : Lmb ,
AZStd : : make_shared < RotateModelBehavior > ( m_viewportController . get ( ) ) ) ;
m_viewportController - > AddBehavior (
ViewportInputBehaviorController : : Shift ^ ViewportInputBehaviorController : : Lmb ,
AZStd : : make_shared < RotateEnvironmentBehavior > ( m_viewportController . get ( ) ) ) ;
GetControllerList ( ) - > Add ( m_viewportController ) ;
}
void MaterialViewportWidget : : OnDocumentOpened ( const AZ : : Uuid & documentId )
void MaterialViewportWidget : : OnDocumentOpened ( const AZ : : Uuid & documentId )
{
{
AZ : : Data : : Instance < AZ : : RPI : : Material > materialInstance ;
AZ : : Data : : Instance < AZ : : RPI : : Material > materialInstance ;
@ -436,8 +461,7 @@ namespace MaterialEditor
void MaterialViewportWidget : : OnFieldOfViewChanged ( float fieldOfView )
void MaterialViewportWidget : : OnFieldOfViewChanged ( float fieldOfView )
{
{
MaterialEditorViewportInputControllerRequestBus : : Broadcast (
m_viewportController - > SetFieldOfView ( fieldOfView ) ;
& MaterialEditorViewportInputControllerRequestBus : : Handler : : SetFieldOfView , fieldOfView ) ;
}
}
void MaterialViewportWidget : : OnDisplayMapperOperationTypeChanged ( AZ : : Render : : DisplayMapperOperationType operationType )
void MaterialViewportWidget : : OnDisplayMapperOperationTypeChanged ( AZ : : Render : : DisplayMapperOperationType operationType )
@ -451,7 +475,9 @@ namespace MaterialEditor
{
{
if ( m_modelAssetId = = asset . GetId ( ) )
if ( m_modelAssetId = = asset . GetId ( ) )
{
{
MaterialEditorViewportInputControllerRequestBus : : Broadcast ( & MaterialEditorViewportInputControllerRequestBus : : Handler : : Reset ) ;
AZ : : Data : : Asset < AZ : : RPI : : ModelAsset > modelAsset = asset ;
m_viewportController - > SetTargetBounds ( modelAsset - > GetAabb ( ) ) ;
m_viewportController - > Reset ( ) ;
AZ : : Data : : AssetBus : : Handler : : BusDisconnect ( asset . GetId ( ) ) ;
AZ : : Data : : AssetBus : : Handler : : BusDisconnect ( asset . GetId ( ) ) ;
}
}
}
}