From 6cc3d697ee127d6de3d39ef8772bacdf08a8d3fa Mon Sep 17 00:00:00 2001 From: Judy Ng Date: Wed, 27 Jul 2022 13:27:17 -0700 Subject: [PATCH 01/12] Component shows up in Editor! Signed-off-by: Judy Ng --- atom_gems/AtomTutorials/Code/CMakeLists.txt | 68 +++-- .../Include/AtomTutorials/AtomTutorialsBus.h | 2 +- .../Billboard/BillboardComponentBus.h | 72 +++++ .../Billboard/BillboardComponentConfig.h | 38 +++ .../Billboard/BillboardComponentConstants.h | 18 ++ .../Source/AtomTutorialsModuleInterface.h | 36 --- .../Source/Billboard/BillboardComponent.cpp | 42 +++ .../Source/Billboard/BillboardComponent.h | 33 +++ .../Billboard/BillboardComponentConfig.cpp | 32 +++ .../BillboardComponentController.cpp | 268 ++++++++++++++++++ .../Billboard/BillboardComponentController.h | 83 ++++++ .../Billboard/EditorBillboardComponent.cpp | 85 ++++++ .../Billboard/EditorBillboardComponent.h | 34 +++ .../Source/Clients/AtomTutorialsModule.cpp | 45 ++- .../Tools/AtomTutorialsEditorModule.cpp | 46 --- .../AtomTutorialsEditorSystemComponent.cpp | 2 - .../Code/atomtutorials_api_files.cmake | 3 + .../atomtutorials_editor_private_files.cmake | 2 + .../atomtutorials_editor_shared_files.cmake | 1 - .../Code/atomtutorials_private_files.cmake | 6 +- atom_gems/AtomTutorials/gem.json | 10 +- 21 files changed, 811 insertions(+), 115 deletions(-) create mode 100644 atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h create mode 100644 atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentConfig.h create mode 100644 atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentConstants.h delete mode 100644 atom_gems/AtomTutorials/Code/Source/AtomTutorialsModuleInterface.h create mode 100644 atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponent.cpp create mode 100644 atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponent.h create mode 100644 atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentConfig.cpp create mode 100644 atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp create mode 100644 atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h create mode 100644 atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp create mode 100644 atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.h delete mode 100644 atom_gems/AtomTutorials/Code/Source/Tools/AtomTutorialsEditorModule.cpp diff --git a/atom_gems/AtomTutorials/Code/CMakeLists.txt b/atom_gems/AtomTutorials/Code/CMakeLists.txt index 4ce4783..6ad1418 100644 --- a/atom_gems/AtomTutorials/Code/CMakeLists.txt +++ b/atom_gems/AtomTutorials/Code/CMakeLists.txt @@ -25,6 +25,7 @@ ly_add_target( BUILD_DEPENDENCIES INTERFACE AZ::AzCore + Gem::Atom_Feature_Common.Public ) # The AtomTutorials.Private.Object target is an internal target @@ -45,6 +46,13 @@ ly_add_target( PUBLIC AZ::AzCore AZ::AzFramework + AZ::AzToolsFramework + Gem::AtomTutorials.API + Gem::LmbrCentral.Static + Gem::GradientSignal.Static + Gem::SurfaceData.Static + Gem::Atom_Feature_Common.Static + Gem::Atom_Bootstrap.Headers ) # Here add AtomTutorials target, it depends on the Private Object library and Public API interface @@ -64,6 +72,9 @@ ly_add_target( Gem::AtomTutorials.API PRIVATE Gem::AtomTutorials.Private.Object + RUNTIME_DEPENDENCIES + Gem::Atom_RPI.Private + Gem::Atom_Feature_Common ) # By default, we will specify that the above target AtomTutorials would be used by @@ -78,20 +89,6 @@ ly_create_alias(NAME AtomTutorials.Servers.API NAMESPACE Gem TARGETS Gem::AtomTu # If we are on a host platform, we want to add the host tools targets like the AtomTutorials.Editor MODULE target if(PAL_TRAIT_BUILD_HOST_TOOLS) - # The AtomTutorials.Editor.API target can be used by other gems that want to interact with the AtomTutorials.Editor module - ly_add_target( - NAME AtomTutorials.Editor.API INTERFACE - NAMESPACE Gem - FILES_CMAKE - atomtutorials_editor_api_files.cmake - ${pal_dir}/atomtutorials_editor_api_files.cmake - INCLUDE_DIRECTORIES - INTERFACE - Include - BUILD_DEPENDENCIES - INTERFACE - AZ::AzToolsFramework - ) # The AtomTutorials.Editor.Private.Object target is an internal target # which is only to be used by this gems CMakeLists.txt and any subdirectories @@ -109,10 +106,21 @@ if(PAL_TRAIT_BUILD_HOST_TOOLS) PRIVATE Include Source + COMPILE_DEFINITIONS + PRIVATE + ATOMTUTORIALS_EDITOR BUILD_DEPENDENCIES PUBLIC AZ::AzToolsFramework - $ + Gem::AtomTutorials.Private.Object + Gem::Atom_RPI.Edit + Gem::AtomToolsFramework.Static + Gem::AtomToolsFramework.Editor + AZ::SceneCore + AZ::SceneData + Legacy::Editor.Headers + Legacy::EditorCommon + Legacy::CryCommon ) ly_add_target( @@ -120,28 +128,40 @@ if(PAL_TRAIT_BUILD_HOST_TOOLS) NAMESPACE Gem AUTOMOC FILES_CMAKE - atomtutorials_editor_shared_files.cmake + atomtutorials_shared_files.cmake INCLUDE_DIRECTORIES PRIVATE Source PUBLIC Include + COMPILE_DEFINITIONS + PRIVATE + ATOMTUTORIALS_EDITOR BUILD_DEPENDENCIES - PUBLIC - Gem::AtomTutorials.Editor.API PRIVATE Gem::AtomTutorials.Editor.Private.Object + RUNTIME_DEPENDENCIES + Gem::Atom_RPI.Editor + Gem::Atom_Feature_Common.Editor + Gem::AtomToolsFramework.Editor + Legacy::EditorCommon ) # By default, we will specify that the above target AtomTutorials would be used by # Tool and Builder type targets when this gem is enabled. If you don't want it # active in Tools or Builders by default, delete one of both of the following lines: - ly_create_alias(NAME AtomTutorials.Tools NAMESPACE Gem TARGETS Gem::AtomTutorials.Editor) - ly_create_alias(NAME AtomTutorials.Builders NAMESPACE Gem TARGETS Gem::AtomTutorials.Editor) - - # For the Tools and Builders variants of AtomTutorials Gem, an alias to the AtomTutorials.Editor API target will be made - ly_create_alias(NAME AtomTutorials.Tools.API NAMESPACE Gem TARGETS Gem::AtomTutorials.Editor.API) - ly_create_alias(NAME AtomTutorials.Builders.API NAMESPACE Gem TARGETS Gem::AtomTutorials.Editor.API) + ly_create_alias(NAME AtomTutorials.Tools NAMESPACE Gem + TARGETS + Gem::AtomTutorials.Editor + Gem::Atom_Feature_Common.Builders + Gem::Atom_RPI.Builders + Gem::GradientSignal.Builders + ) + ly_create_alias(NAME AtomTutorials.Builders NAMESPACE Gem + TARGETS + Gem::AtomTutorials.Editor + Gem::GradientSignal.Tools + ) endif() diff --git a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/AtomTutorialsBus.h b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/AtomTutorialsBus.h index 5da4c4e..08a97a9 100644 --- a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/AtomTutorialsBus.h +++ b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/AtomTutorialsBus.h @@ -9,7 +9,7 @@ namespace AtomTutorials class AtomTutorialsRequests { public: - AZ_RTTI(AtomTutorialsRequests, "{802636CF-89EA-42DD-9E24-E3884C1EF9CA}"); + AZ_RTTI(AtomTutorialsRequests, "{1AC8C7D5-4D5D-40CC-9877-C04099C9BFB1}"); virtual ~AtomTutorialsRequests() = default; // Put your public methods here }; diff --git a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h new file mode 100644 index 0000000..db03bdd --- /dev/null +++ b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h @@ -0,0 +1,72 @@ +/* + * 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 + * + */ + +#pragma once + +#include +#include + +namespace AZ +{ + namespace Render + { + //! GridComponentRequestBus declares an interface for configuring and interacting with the grid component + class BillboardComponentRequests : public ComponentBus + { + public: + //! Sets the dimensions of the grid in meters + virtual void SetSize(float size) = 0; + + //! Returns the dimensions of the grid in meters + virtual float GetSize() const = 0; + + //! Sets the distance between grid lines drawn in the primary grid color + virtual void SetPrimarySpacing(float spacing) = 0; + + //! Returns the distance between grid lines drawn and the primary grid color + virtual float GetPrimarySpacing() const = 0; + + //! Sets the distance between grid lines drawn in the secondary grid color + virtual void SetSecondarySpacing(float spacing) = 0; + + //! Returns the distance between grid lines drawn in the secondary grid color + virtual float GetSecondarySpacing() const = 0; + + //! Sets the color of the axis lines spanning the grid dimensions + virtual void SetAxisColor(const AZ::Color& color) = 0; + + //! Returns the color of the axis lines spanning the grid dimensions + virtual AZ::Color GetAxisColor() const = 0; + + //! Sets the color of primary grid lines + virtual void SetPrimaryColor(const AZ::Color& color) = 0; + + //! Returns the color of primary grid lines + virtual AZ::Color GetPrimaryColor() const = 0; + + //! Sets the color of secondary grid lines + virtual void SetSecondaryColor(const AZ::Color& color) = 0; + + //! Returns the color of secondary grid lines + virtual AZ::Color GetSecondaryColor() const = 0; + }; + + using BillboardComponentRequestBus = EBus; + + //! BillboardComponentNotificationBus notifications are triggered whenever the grid changes + class BillboardComponentNotifications : public ComponentBus + { + public: + //! Notify any handlers that the grid has been modified + virtual void OnGridChanged(){}; + }; + + using BillboardComponentNotificationBus = EBus; + + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentConfig.h b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentConfig.h new file mode 100644 index 0000000..f356cb9 --- /dev/null +++ b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentConfig.h @@ -0,0 +1,38 @@ +/* + * 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 + * + */ + +#pragma once + +#include +#include + +namespace AZ +{ + namespace Render + { + //! Common settings for GridComponents and EditorGridComponent. + class BillboardComponentConfig final + : public ComponentConfig + { + public: + AZ_RTTI(BillboardComponentConfig, "{864A9EB9-0ABB-47B0-AA2A-4E96840C8FD9}", ComponentConfig); + AZ_CLASS_ALLOCATOR(BillboardComponentConfig, SystemAllocator, 0); + + static void Reflect(ReflectContext* context); + + float m_gridSize = 32.0f; + AZ::Color m_axisColor = AZ::Color(0.0f, 0.0f, 1.0f, 1.0f); + + float m_primarySpacing = 1.0f; + AZ::Color m_primaryColor = AZ::Color(0.25f, 0.25f, 0.25f, 1.0f); + + float m_secondarySpacing = 0.25f; + AZ::Color m_secondaryColor = AZ::Color(0.5f, 0.5f, 0.5f, 1.0f); + }; + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentConstants.h b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentConstants.h new file mode 100644 index 0000000..fc3f246 --- /dev/null +++ b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentConstants.h @@ -0,0 +1,18 @@ +/* + * 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 + * + */ + +#pragma once + +namespace AZ +{ + namespace Render + { + static constexpr const char* const BillboardComponentTypeId = "{15305641-513D-40FF-9F73-1707869CC96E}"; + static constexpr const char* const EditorBillboardComponentTypeId = "{D4205908-B206-4488-9381-A148D81F52E7}"; + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/AtomTutorialsModuleInterface.h b/atom_gems/AtomTutorials/Code/Source/AtomTutorialsModuleInterface.h deleted file mode 100644 index 51488db..0000000 --- a/atom_gems/AtomTutorials/Code/Source/AtomTutorialsModuleInterface.h +++ /dev/null @@ -1,36 +0,0 @@ - -#include -#include -#include - -namespace AtomTutorials -{ - class AtomTutorialsModuleInterface - : public AZ::Module - { - public: - AZ_RTTI(AtomTutorialsModuleInterface, "{553B66F8-E05B-450B-81D2-3D5139B60B8A}", AZ::Module); - AZ_CLASS_ALLOCATOR(AtomTutorialsModuleInterface, AZ::SystemAllocator, 0); - - AtomTutorialsModuleInterface() - { - // Push results of [MyComponent]::CreateDescriptor() into m_descriptors here. - // Add ALL components descriptors associated with this gem to m_descriptors. - // This will associate the AzTypeInfo information for the components with the the SerializeContext, BehaviorContext and EditContext. - // This happens through the [MyComponent]::Reflect() function. - m_descriptors.insert(m_descriptors.end(), { - AtomTutorialsSystemComponent::CreateDescriptor(), - }); - } - - /** - * Add required SystemComponents to the SystemEntity. - */ - AZ::ComponentTypeList GetRequiredSystemComponents() const override - { - return AZ::ComponentTypeList{ - azrtti_typeid(), - }; - } - }; -}// namespace AtomTutorials diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponent.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponent.cpp new file mode 100644 index 0000000..beab1ae --- /dev/null +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponent.cpp @@ -0,0 +1,42 @@ +/* + * 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 +#include + +namespace AZ +{ + namespace Render + { + BillboardComponent::BillboardComponent(const BillboardComponentConfig& config) + : BaseClass(config) + { + } + + void BillboardComponent::Reflect(AZ::ReflectContext* context) + { + BaseClass::Reflect(context); + + if (auto serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(0) + ; + } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->Class()->RequestBus("BillboardComponentRequestBus"); + + behaviorContext->ConstantProperty("BillboardComponentTypeId", BehaviorConstant(Uuid(BillboardComponentTypeId))) + ->Attribute(AZ::Script::Attributes::Module, "render") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common); + } + } + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponent.h b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponent.h new file mode 100644 index 0000000..8229419 --- /dev/null +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponent.h @@ -0,0 +1,33 @@ +/* + * 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 + * + */ + +#pragma once + +#include +#include +#include + +namespace AZ +{ + namespace Render + { + class BillboardComponent final + : public AzFramework::Components::ComponentAdapter + { + public: + + using BaseClass = AzFramework::Components::ComponentAdapter; + AZ_COMPONENT(AZ::Render::BillboardComponent, BillboardComponentTypeId, BaseClass); + + BillboardComponent() = default; + BillboardComponent(const BillboardComponentConfig& config); + + static void Reflect(AZ::ReflectContext* context); + }; + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentConfig.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentConfig.cpp new file mode 100644 index 0000000..68996f8 --- /dev/null +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentConfig.cpp @@ -0,0 +1,32 @@ +/* + * 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 +#include + +namespace AZ +{ + namespace Render + { + void BillboardComponentConfig::Reflect(ReflectContext* context) + { + if (AZ::SerializeContext* serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(0) + ->Field("gridSize", &BillboardComponentConfig::m_gridSize) + ->Field("axisColor", &BillboardComponentConfig::m_axisColor) + ->Field("primarySpacing", &BillboardComponentConfig::m_primarySpacing) + ->Field("primaryColor", &BillboardComponentConfig::m_primaryColor) + ->Field("secondarySpacing", &BillboardComponentConfig::m_secondarySpacing) + ->Field("secondaryColor", &BillboardComponentConfig::m_secondaryColor) + ; + } + } + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp new file mode 100644 index 0000000..e15dcb5 --- /dev/null +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp @@ -0,0 +1,268 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +namespace AZ +{ + namespace Render + { + void BillboardComponentController::Reflect(ReflectContext* context) + { + BillboardComponentConfig::Reflect(context); + + if (SerializeContext* serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(0) + ->Field("Configuration", &BillboardComponentController::m_configuration) + ; + } + + if (AZ::BehaviorContext* behaviorContext = azrtti_cast(context)) + { + behaviorContext->EBus("BillboardComponentRequestBus") + ->Event("GetSize", &BillboardComponentRequestBus::Events::GetSize) + ->Event("SetSize", &BillboardComponentRequestBus::Events::SetSize) + ->Event("GetAxisColor", &BillboardComponentRequestBus::Events::GetAxisColor) + ->Event("SetAxisColor", &BillboardComponentRequestBus::Events::SetAxisColor) + ->Event("GetPrimaryColor", &BillboardComponentRequestBus::Events::GetPrimaryColor) + ->Event("SetPrimaryColor", &BillboardComponentRequestBus::Events::SetPrimaryColor) + ->Event("GetPrimarySpacing", &BillboardComponentRequestBus::Events::GetPrimarySpacing) + ->Event("SetPrimarySpacing", &BillboardComponentRequestBus::Events::SetPrimarySpacing) + ->Event("GetSecondaryColor", &BillboardComponentRequestBus::Events::GetSecondaryColor) + ->Event("SetSecondaryColor", &BillboardComponentRequestBus::Events::SetSecondaryColor) + ->Event("GetSecondarySpacing", &BillboardComponentRequestBus::Events::GetSecondarySpacing) + ->Event("SetSecondarySpacing", &BillboardComponentRequestBus::Events::SetSecondarySpacing) + ->VirtualProperty("Size", "GetSize", "SetSize") + ->VirtualProperty("AxisColor", "GetAxisColor", "SetAxisColor") + ->VirtualProperty("PrimaryColor", "GetPrimaryColor", "SetPrimaryColor") + ->VirtualProperty("PrimarySpacing", "GetPrimarySpacing", "SetPrimarySpacing") + ->VirtualProperty("SecondaryColor", "GetSecondaryColor", "SetSecondaryColor") + ->VirtualProperty("SecondarySpacing", "GetSecondarySpacing", "SetSecondarySpacing") + ; + } + } + + void BillboardComponentController::GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided) + { + provided.push_back(AZ_CRC_CE("BillboardService")); + } + + void BillboardComponentController::GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible) + { + incompatible.push_back(AZ_CRC_CE("BillboardService")); + } + + BillboardComponentController::BillboardComponentController(const BillboardComponentConfig& config) + : m_configuration(config) + { + } + + void BillboardComponentController::Activate(EntityId entityId) + { + m_entityId = entityId; + m_dirty = true; + + RPI::Scene* scene = RPI::Scene::GetSceneForEntityId(m_entityId); + if (scene) + { + AZ::RPI::SceneNotificationBus::Handler::BusConnect(scene->GetId()); + } + + BillboardComponentRequestBus::Handler::BusConnect(m_entityId); + AZ::TransformNotificationBus::Handler::BusConnect(m_entityId); + } + + void BillboardComponentController::Deactivate() + { + AZ::TransformNotificationBus::Handler::BusDisconnect(); + BillboardComponentRequestBus::Handler::BusDisconnect(); + AZ::RPI::SceneNotificationBus::Handler::BusDisconnect(); + + m_entityId = EntityId(EntityId::InvalidEntityId); + } + + void BillboardComponentController::SetConfiguration(const BillboardComponentConfig& config) + { + m_configuration = config; + m_dirty = true; + } + + const BillboardComponentConfig& BillboardComponentController::GetConfiguration() const + { + return m_configuration; + } + + void BillboardComponentController::SetSize(float size) + { + m_configuration.m_gridSize = AZStd::clamp(size, MinGridSize, MaxGridSize); + m_dirty = true; + } + + float BillboardComponentController::GetSize() const + { + return m_configuration.m_gridSize; + } + + void BillboardComponentController::SetPrimarySpacing(float spacing) + { + m_configuration.m_primarySpacing = AZStd::max(spacing, MinSpacing); + m_dirty = true; + } + + float BillboardComponentController::GetPrimarySpacing() const + { + return m_configuration.m_primarySpacing; + } + + void BillboardComponentController::SetSecondarySpacing(float spacing) + { + m_configuration.m_secondarySpacing = AZStd::max(spacing, MinSpacing); + m_dirty = true; + } + + float BillboardComponentController::GetSecondarySpacing() const + { + return m_configuration.m_secondarySpacing; + } + + void BillboardComponentController::SetAxisColor(const AZ::Color& color) + { + m_configuration.m_axisColor = color; + } + + AZ::Color BillboardComponentController::GetAxisColor() const + { + return m_configuration.m_axisColor; + } + + void BillboardComponentController::SetPrimaryColor(const AZ::Color& color) + { + m_configuration.m_primaryColor = color; + } + + AZ::Color BillboardComponentController::GetPrimaryColor() const + { + return m_configuration.m_primaryColor; + } + + void BillboardComponentController::SetSecondaryColor(const AZ::Color& color) + { + m_configuration.m_secondaryColor = color; + } + + AZ::Color BillboardComponentController::GetSecondaryColor() const + { + return m_configuration.m_secondaryColor; + } + + void BillboardComponentController::OnBeginPrepareRender() + { + if (m_configuration.m_gridSize <= 0.0f) + { + return; + } + + auto* auxGeomFP = AZ::RPI::Scene::GetFeatureProcessorForEntity(m_entityId); + if (!auxGeomFP) + { + return; + } + + if (auto auxGeom = auxGeomFP->GetDrawQueue()) + { + BuildGrid(); + + AZ::RPI::AuxGeomDraw::AuxGeomDynamicDrawArguments drawArgs; + drawArgs.m_verts = m_secondaryGridPoints.data(); + drawArgs.m_vertCount = aznumeric_cast(m_secondaryGridPoints.size()); + drawArgs.m_colors = &m_configuration.m_secondaryColor; + drawArgs.m_colorCount = 1; + auxGeom->DrawLines(drawArgs); + + drawArgs.m_verts = m_primaryGridPoints.data(); + drawArgs.m_vertCount = aznumeric_cast(m_primaryGridPoints.size()); + drawArgs.m_colors = &m_configuration.m_primaryColor; + auxGeom->DrawLines(drawArgs); + + drawArgs.m_verts = m_axisGridPoints.data(); + drawArgs.m_vertCount = aznumeric_cast(m_axisGridPoints.size()); + drawArgs.m_colors = &m_configuration.m_axisColor; + auxGeom->DrawLines(drawArgs); + } + } + + void BillboardComponentController::OnTransformChanged(const Transform& local, const Transform& world) + { + AZ_UNUSED(local); + AZ_UNUSED(world); + m_dirty = true; + } + + void BillboardComponentController::BuildGrid() + { + if (m_dirty) + { + m_dirty = false; + + AZ::Transform transform; + AZ::TransformBus::EventResult(transform, m_entityId, &AZ::TransformBus::Events::GetWorldTM); + + const float halfLength = m_configuration.m_gridSize / 2.0f; + + m_axisGridPoints.clear(); + m_axisGridPoints.reserve(4); + m_axisGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, 0, 0.0f))); + m_axisGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, 0, 0.0f))); + m_axisGridPoints.push_back(transform.TransformPoint(AZ::Vector3(0, -halfLength, 0.0f))); + m_axisGridPoints.push_back(transform.TransformPoint(AZ::Vector3(0, halfLength, 0.0f))); + + m_primaryGridPoints.clear(); + m_primaryGridPoints.reserve(aznumeric_cast(4.0f * m_configuration.m_gridSize / m_configuration.m_primarySpacing)); + for (float position = m_configuration.m_primarySpacing; position <= halfLength; + position += m_configuration.m_primarySpacing) + { + m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, -position, 0.0f))); + m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, -position, 0.0f))); + m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, position, 0.0f))); + m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, position, 0.0f))); + m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, -halfLength, 0.0f))); + m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, halfLength, 0.0f))); + m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, -halfLength, 0.0f))); + m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, halfLength, 0.0f))); + } + + m_secondaryGridPoints.clear(); + m_secondaryGridPoints.reserve(aznumeric_cast(4.0f * m_configuration.m_gridSize / m_configuration.m_secondarySpacing)); + for (float position = m_configuration.m_secondarySpacing; position <= halfLength; + position += m_configuration.m_secondarySpacing) + { + m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, -position, 0.0f))); + m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, -position, 0.0f))); + m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, position, 0.0f))); + m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, position, 0.0f))); + m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, -halfLength, 0.0f))); + m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, halfLength, 0.0f))); + m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, -halfLength, 0.0f))); + m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, halfLength, 0.0f))); + } + + BillboardComponentNotificationBus::Event(m_entityId, &BillboardComponentNotificationBus::Events::OnGridChanged); + } + } + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h new file mode 100644 index 0000000..844670a --- /dev/null +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h @@ -0,0 +1,83 @@ +/* + * 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 + * + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace AZ +{ + namespace Render + { + //! Controls behavior and rendering of a wireframe Billboard + class BillboardComponentController final + : public BillboardComponentRequestBus::Handler + , public AZ::TransformNotificationBus::Handler + , public AZ::RPI::SceneNotificationBus::Handler + { + public: + friend class EditorBillboardComponent; + + AZ_CLASS_ALLOCATOR(BillboardComponentController, SystemAllocator, 0) + AZ_RTTI(AZ::Render::BillboardComponentController, "{A0288BD7-B660-47B6-88D7-57E7C4F92FEK}"); + + static void Reflect(ReflectContext* context); + static void GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided); + static void GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible); + + BillboardComponentController() = default; + BillboardComponentController(const BillboardComponentConfig& config); + + void Activate(EntityId entityId); + void Deactivate(); + void SetConfiguration(const BillboardComponentConfig& config); + const BillboardComponentConfig& GetConfiguration() const; + + static constexpr float MinGridSize = 0.0f; + static constexpr float MaxGridSize = 1000000.0f; + static constexpr float MinSpacing = 0.01f; + + private: + AZ_DISABLE_COPY(BillboardComponentController); + + //! BillboardComponentRequestBus overrides... + void SetSize(float size) override; + float GetSize() const override; + void SetPrimarySpacing(float spacing) override; + float GetPrimarySpacing() const override; + void SetSecondarySpacing(float spacing) override; + float GetSecondarySpacing() const override; + + void SetAxisColor(const AZ::Color& color) override; + AZ::Color GetAxisColor() const override; + void SetPrimaryColor(const AZ::Color& color) override; + AZ::Color GetPrimaryColor() const override; + void SetSecondaryColor(const AZ::Color& color) override; + AZ::Color GetSecondaryColor() const override; + + //! AZ::TransformNotificationBus::Handler overrides ... + void OnTransformChanged(const Transform& local, const Transform& world) override; + + // AZ::RPI::SceneNotificationBus::Handler overrides ... + void OnBeginPrepareRender() override; + + void BuildGrid(); + + EntityId m_entityId; + BillboardComponentConfig m_configuration; + AZStd::vector m_axisGridPoints; + AZStd::vector m_primaryGridPoints; + AZStd::vector m_secondaryGridPoints; + bool m_dirty = true; // must be set to true for any configuration change that rebuilds the grid + }; + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp new file mode 100644 index 0000000..8a709b3 --- /dev/null +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp @@ -0,0 +1,85 @@ +/* + * 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 +#include +#include +#include + +namespace AZ +{ + namespace Render + { + void EditorBillboardComponent::Reflect(AZ::ReflectContext* context) + { + BaseClass::Reflect(context); + + if (AZ::SerializeContext* serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(1, ConvertToEditorRenderComponentAdapter<1>); + + if (AZ::EditContext* editContext = serializeContext->GetEditContext()) + { + editContext->Class( + "Billboard", "Adds grid to the scene") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::Category, "AtomTutorials") + ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Component_Placeholder.svg") + ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Component_Placeholder.svg") + ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c)) + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://o3de.org/docs/user-guide/components/reference/atom/grid/") + ; + + editContext->Class( + "BillboardComponentController", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &BillboardComponentController::m_configuration, "Configuration", "") + ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly) + ; + + editContext->Class( + "BillboardComponentConfig", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &BillboardComponentConfig::m_gridSize, "Grid Size", "Grid width and depth") + ->Attribute(AZ::Edit::Attributes::Min, BillboardComponentController::MinGridSize) + ->Attribute(AZ::Edit::Attributes::Max, BillboardComponentController::MaxGridSize) + ->Attribute(AZ::Edit::Attributes::Suffix, " m") + ->DataElement(AZ::Edit::UIHandlers::Default, &BillboardComponentConfig::m_primarySpacing, "Primary Grid Spacing", "Amount of space between grid lines") + ->Attribute(AZ::Edit::Attributes::Min, BillboardComponentController::MinSpacing) + ->Attribute(AZ::Edit::Attributes::Suffix, " m") + ->DataElement(AZ::Edit::UIHandlers::Default, &BillboardComponentConfig::m_secondarySpacing, "Secondary Grid Spacing", "Amount of space between sub-grid lines") + ->Attribute(AZ::Edit::Attributes::Min, BillboardComponentController::MinSpacing) + ->Attribute(AZ::Edit::Attributes::Suffix, " m") + ->DataElement(AZ::Edit::UIHandlers::Color, &BillboardComponentConfig::m_axisColor, "Axis Color", "Color of the grid axis") + ->DataElement(AZ::Edit::UIHandlers::Color, &BillboardComponentConfig::m_primaryColor, "Primary Color", "Color of the primary grid lines") + ->DataElement(AZ::Edit::UIHandlers::Color, &BillboardComponentConfig::m_secondaryColor, "Secondary Color", "Color of the secondary grid lines") + ; + } + } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->Class()->RequestBus("BillboardComponentRequestBus"); + + behaviorContext->ConstantProperty("EditorBillboardComponentTypeId", BehaviorConstant(Uuid(EditorBillboardComponentTypeId))) + ->Attribute(AZ::Script::Attributes::Module, "render") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation); + } + } + + EditorBillboardComponent::EditorBillboardComponent(const BillboardComponentConfig& config) + : BaseClass(config) + { + } + + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.h b/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.h new file mode 100644 index 0000000..b4cd028 --- /dev/null +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.h @@ -0,0 +1,34 @@ +/* + * 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 + * + */ + +#pragma once + +#include +#include +#include +#include + +namespace AZ +{ + namespace Render + { + //! In-editor grid component + class EditorBillboardComponent final + : public EditorRenderComponentAdapter + { + public: + using BaseClass = EditorRenderComponentAdapter; + AZ_EDITOR_COMPONENT(AZ::Render::EditorBillboardComponent, EditorBillboardComponentTypeId, BaseClass); + + static void Reflect(AZ::ReflectContext* context); + + EditorBillboardComponent() = default; + EditorBillboardComponent(const BillboardComponentConfig& config); + }; + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Clients/AtomTutorialsModule.cpp b/atom_gems/AtomTutorials/Code/Source/Clients/AtomTutorialsModule.cpp index 1e2da51..cf8c040 100644 --- a/atom_gems/AtomTutorials/Code/Source/Clients/AtomTutorialsModule.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Clients/AtomTutorialsModule.cpp @@ -1,15 +1,54 @@ -#include +#include +#include +#include + #include "AtomTutorialsSystemComponent.h" +#include + +#ifdef ATOMTUTORIALS_EDITOR +#include +#include +#endif + namespace AtomTutorials { class AtomTutorialsModule - : public AtomTutorialsModuleInterface + : public AZ::Module { public: - AZ_RTTI(AtomTutorialsModule, "{C96BD29A-15A9-4C5F-8076-4C4DB113A5FE}", AtomTutorialsModuleInterface); + AZ_RTTI(AtomTutorialsModule, "{123CAB07-FB14-4CF2-A7FD-C550136194EC}", AZ::Module); AZ_CLASS_ALLOCATOR(AtomTutorialsModule, AZ::SystemAllocator, 0); + + AtomTutorialsModule() + : AZ::Module() + { + // Push results of [MyComponent]::CreateDescriptor() into m_descriptors here. + // Add ALL components descriptors associated with this gem to m_descriptors. + // This will associate the AzTypeInfo information for the components with the the SerializeContext, BehaviorContext and EditContext. + // This happens through the [MyComponent]::Reflect() function. + m_descriptors.insert(m_descriptors.end(), { + AtomTutorialsSystemComponent::CreateDescriptor(), + AZ::Render::BillboardComponent::CreateDescriptor(), + +#ifdef ATOMTUTORIALS_EDITOR + AtomTutorialsEditorSystemComponent::CreateDescriptor(), + AZ::Render::EditorBillboardComponent::CreateDescriptor(), +#endif + }); + } + + AZ::ComponentTypeList GetRequiredSystemComponents() const override + { + return AZ::ComponentTypeList { + azrtti_typeid(), +#ifdef ATOMTUTORIALS_EDITOR + azrtti_typeid(), +#endif + }; + } + }; }// namespace AtomTutorials diff --git a/atom_gems/AtomTutorials/Code/Source/Tools/AtomTutorialsEditorModule.cpp b/atom_gems/AtomTutorials/Code/Source/Tools/AtomTutorialsEditorModule.cpp deleted file mode 100644 index 2fffb14..0000000 --- a/atom_gems/AtomTutorials/Code/Source/Tools/AtomTutorialsEditorModule.cpp +++ /dev/null @@ -1,46 +0,0 @@ - -#include -#include "AtomTutorialsEditorSystemComponent.h" - -void InitAtomTutorialsResources() -{ - // We must register our Qt resources (.qrc file) since this is being loaded from a separate module (gem) - Q_INIT_RESOURCE(AtomTutorials); -} - -namespace AtomTutorials -{ - class AtomTutorialsEditorModule - : public AtomTutorialsModuleInterface - { - public: - AZ_RTTI(AtomTutorialsEditorModule, "{C96BD29A-15A9-4C5F-8076-4C4DB113A5FE}", AtomTutorialsModuleInterface); - AZ_CLASS_ALLOCATOR(AtomTutorialsEditorModule, AZ::SystemAllocator, 0); - - AtomTutorialsEditorModule() - { - InitAtomTutorialsResources(); - - // Push results of [MyComponent]::CreateDescriptor() into m_descriptors here. - // Add ALL components descriptors associated with this gem to m_descriptors. - // This will associate the AzTypeInfo information for the components with the the SerializeContext, BehaviorContext and EditContext. - // This happens through the [MyComponent]::Reflect() function. - m_descriptors.insert(m_descriptors.end(), { - AtomTutorialsEditorSystemComponent::CreateDescriptor(), - }); - } - - /** - * Add required SystemComponents to the SystemEntity. - * Non-SystemComponents should not be added here - */ - AZ::ComponentTypeList GetRequiredSystemComponents() const override - { - return AZ::ComponentTypeList { - azrtti_typeid(), - }; - } - }; -}// namespace AtomTutorials - -AZ_DECLARE_MODULE_CLASS(Gem_AtomTutorials, AtomTutorials::AtomTutorialsEditorModule) diff --git a/atom_gems/AtomTutorials/Code/Source/Tools/AtomTutorialsEditorSystemComponent.cpp b/atom_gems/AtomTutorials/Code/Source/Tools/AtomTutorialsEditorSystemComponent.cpp index de71a23..52f9c2f 100644 --- a/atom_gems/AtomTutorials/Code/Source/Tools/AtomTutorialsEditorSystemComponent.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Tools/AtomTutorialsEditorSystemComponent.cpp @@ -23,13 +23,11 @@ namespace AtomTutorials void AtomTutorialsEditorSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { - BaseSystemComponent::GetProvidedServices(provided); provided.push_back(AZ_CRC_CE("AtomTutorialsEditorService")); } void AtomTutorialsEditorSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { - BaseSystemComponent::GetIncompatibleServices(incompatible); incompatible.push_back(AZ_CRC_CE("AtomTutorialsEditorService")); } diff --git a/atom_gems/AtomTutorials/Code/atomtutorials_api_files.cmake b/atom_gems/AtomTutorials/Code/atomtutorials_api_files.cmake index 513f7bc..2034c8d 100644 --- a/atom_gems/AtomTutorials/Code/atomtutorials_api_files.cmake +++ b/atom_gems/AtomTutorials/Code/atomtutorials_api_files.cmake @@ -1,4 +1,7 @@ set(FILES Include/AtomTutorials/AtomTutorialsBus.h + Include/AtomTutorials/Billboard/BillboardComponentBus.h + Include/AtomTutorials/Billboard/BillboardComponentConfig.h + Include/AtomTutorials/Billboard/BillboardComponentConstants.h ) diff --git a/atom_gems/AtomTutorials/Code/atomtutorials_editor_private_files.cmake b/atom_gems/AtomTutorials/Code/atomtutorials_editor_private_files.cmake index 6b5df74..e2ffb08 100644 --- a/atom_gems/AtomTutorials/Code/atomtutorials_editor_private_files.cmake +++ b/atom_gems/AtomTutorials/Code/atomtutorials_editor_private_files.cmake @@ -1,5 +1,7 @@ set(FILES + Source/Billboard/EditorBillboardComponent.cpp + Source/Billboard/EditorBillboardComponent.h Source/Tools/AtomTutorialsEditorSystemComponent.cpp Source/Tools/AtomTutorialsEditorSystemComponent.h Source/Tools/AtomTutorialsWidget.cpp diff --git a/atom_gems/AtomTutorials/Code/atomtutorials_editor_shared_files.cmake b/atom_gems/AtomTutorials/Code/atomtutorials_editor_shared_files.cmake index c140053..f5526ee 100644 --- a/atom_gems/AtomTutorials/Code/atomtutorials_editor_shared_files.cmake +++ b/atom_gems/AtomTutorials/Code/atomtutorials_editor_shared_files.cmake @@ -1,4 +1,3 @@ set(FILES - Source/Tools/AtomTutorialsEditorModule.cpp ) diff --git a/atom_gems/AtomTutorials/Code/atomtutorials_private_files.cmake b/atom_gems/AtomTutorials/Code/atomtutorials_private_files.cmake index d52d38f..4fd48af 100644 --- a/atom_gems/AtomTutorials/Code/atomtutorials_private_files.cmake +++ b/atom_gems/AtomTutorials/Code/atomtutorials_private_files.cmake @@ -1,6 +1,10 @@ set(FILES - Source/AtomTutorialsModuleInterface.h Source/Clients/AtomTutorialsSystemComponent.cpp Source/Clients/AtomTutorialsSystemComponent.h + Source/Billboard/BillboardComponent.cpp + Source/Billboard/BillboardComponent.h + Source/Billboard/BillboardComponentConfig.cpp + Source/Billboard/BillboardComponentController.cpp + Source/Billboard/BillboardComponentController.h ) diff --git a/atom_gems/AtomTutorials/gem.json b/atom_gems/AtomTutorials/gem.json index 5cd2492..97922f4 100644 --- a/atom_gems/AtomTutorials/gem.json +++ b/atom_gems/AtomTutorials/gem.json @@ -16,6 +16,14 @@ "icon_path": "preview.png", "requirements": "This requires the Atom gem.", "documentation_url": "https://o3de.org/docs/user-guide/gems/reference/rendering/atom/atom/", - "dependencies": [], + "dependencies": [ + "Atom_Feature_Common", + "LmbrCentral", + "GradientSignal", + "SurfaceData", + "Atom_Bootstrap", + "Atom_RPI", + "AtomToolsFramework" + ], "restricted": "AtomTutorials" } From 400ff539373962fc2a64edbf35cf98616edb46f7 Mon Sep 17 00:00:00 2001 From: Judy Ng Date: Fri, 29 Jul 2022 01:43:19 -0700 Subject: [PATCH 02/12] quad always faces camera! Signed-off-by: Judy Ng --- .../BillboardComponentController.cpp | 128 ++++++++++-------- .../Billboard/BillboardComponentController.h | 3 +- .../Code/atomtutorials_api_files.cmake | 1 - 3 files changed, 70 insertions(+), 62 deletions(-) diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp index e15dcb5..b9a29ee 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp @@ -188,17 +188,6 @@ namespace AZ BuildGrid(); AZ::RPI::AuxGeomDraw::AuxGeomDynamicDrawArguments drawArgs; - drawArgs.m_verts = m_secondaryGridPoints.data(); - drawArgs.m_vertCount = aznumeric_cast(m_secondaryGridPoints.size()); - drawArgs.m_colors = &m_configuration.m_secondaryColor; - drawArgs.m_colorCount = 1; - auxGeom->DrawLines(drawArgs); - - drawArgs.m_verts = m_primaryGridPoints.data(); - drawArgs.m_vertCount = aznumeric_cast(m_primaryGridPoints.size()); - drawArgs.m_colors = &m_configuration.m_primaryColor; - auxGeom->DrawLines(drawArgs); - drawArgs.m_verts = m_axisGridPoints.data(); drawArgs.m_vertCount = aznumeric_cast(m_axisGridPoints.size()); drawArgs.m_colors = &m_configuration.m_axisColor; @@ -215,54 +204,75 @@ namespace AZ void BillboardComponentController::BuildGrid() { - if (m_dirty) - { - m_dirty = false; - - AZ::Transform transform; - AZ::TransformBus::EventResult(transform, m_entityId, &AZ::TransformBus::Events::GetWorldTM); - - const float halfLength = m_configuration.m_gridSize / 2.0f; - - m_axisGridPoints.clear(); - m_axisGridPoints.reserve(4); - m_axisGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, 0, 0.0f))); - m_axisGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, 0, 0.0f))); - m_axisGridPoints.push_back(transform.TransformPoint(AZ::Vector3(0, -halfLength, 0.0f))); - m_axisGridPoints.push_back(transform.TransformPoint(AZ::Vector3(0, halfLength, 0.0f))); - - m_primaryGridPoints.clear(); - m_primaryGridPoints.reserve(aznumeric_cast(4.0f * m_configuration.m_gridSize / m_configuration.m_primarySpacing)); - for (float position = m_configuration.m_primarySpacing; position <= halfLength; - position += m_configuration.m_primarySpacing) - { - m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, -position, 0.0f))); - m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, -position, 0.0f))); - m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, position, 0.0f))); - m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, position, 0.0f))); - m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, -halfLength, 0.0f))); - m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, halfLength, 0.0f))); - m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, -halfLength, 0.0f))); - m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, halfLength, 0.0f))); - } - - m_secondaryGridPoints.clear(); - m_secondaryGridPoints.reserve(aznumeric_cast(4.0f * m_configuration.m_gridSize / m_configuration.m_secondarySpacing)); - for (float position = m_configuration.m_secondarySpacing; position <= halfLength; - position += m_configuration.m_secondarySpacing) - { - m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, -position, 0.0f))); - m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, -position, 0.0f))); - m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, position, 0.0f))); - m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, position, 0.0f))); - m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, -halfLength, 0.0f))); - m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, halfLength, 0.0f))); - m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, -halfLength, 0.0f))); - m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, halfLength, 0.0f))); - } - - BillboardComponentNotificationBus::Event(m_entityId, &BillboardComponentNotificationBus::Events::OnGridChanged); - } + EntityId cam; + Camera::CameraSystemRequestBus::BroadcastResult(cam, &Camera::CameraSystemRequests::GetActiveCamera); + + AZ::Vector3 cameraWorldPosition; + AZ::TransformBus::EventResult(cameraWorldPosition, cam, &AZ::TransformBus::Events::GetWorldTranslation); + + AZ::Vector3 myPosition; + AZ::TransformBus::EventResult(myPosition, m_entityId, &AZ::TransformBus::Events::GetWorldTranslation); + + const float halfLength = m_configuration.m_gridSize / 2.0f; + + // From camera POV, the forward axis is Z positive, even though O3DE's default is Y positive for forward axis. + AZ::Matrix3x4 viewMatrix = AZ::Matrix3x4::CreateFromTransform(AZ::Transform::CreateLookAt(cameraWorldPosition, myPosition, AZ::Transform::Axis::ZPositive)); + AZ::Vector3 cameraRight = AZ::Vector3(viewMatrix(0, 0), viewMatrix(1, 0), viewMatrix(2, 0)); + AZ::Vector3 cameraUp = AZ::Vector3(viewMatrix(0, 1), viewMatrix(1, 1), viewMatrix(2, 1)); + + AZ::Vector3 p0_world = myPosition + cameraRight * halfLength + cameraUp * halfLength; // top right + AZ::Vector3 p1_world = myPosition + cameraRight * halfLength - cameraUp * halfLength; // bottom right + AZ::Vector3 p2_world = myPosition - cameraRight * halfLength - cameraUp * halfLength; // bottom left + AZ::Vector3 p3_world = myPosition - cameraRight * halfLength + cameraUp * halfLength; // top left + + + // Make lines + m_axisGridPoints.clear(); + m_axisGridPoints.reserve(8); + // Right + m_axisGridPoints.push_back(p0_world); + m_axisGridPoints.push_back(p1_world); + // Bottom + m_axisGridPoints.push_back(p1_world); + m_axisGridPoints.push_back(p2_world); + // Left + m_axisGridPoints.push_back(p2_world); + m_axisGridPoints.push_back(p3_world); + // Top + m_axisGridPoints.push_back(p3_world); + m_axisGridPoints.push_back(p0_world); + + // m_primaryGridPoints.clear(); + // m_primaryGridPoints.reserve(aznumeric_cast(4.0f * m_configuration.m_gridSize / m_configuration.m_primarySpacing)); + // for (float position = m_configuration.m_primarySpacing; position <= halfLength; + // position += m_configuration.m_primarySpacing) + // { + // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, -position, 0.0f))); + // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, -position, 0.0f))); + // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, position, 0.0f))); + // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, position, 0.0f))); + // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, -halfLength, 0.0f))); + // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, halfLength, 0.0f))); + // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, -halfLength, 0.0f))); + // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, halfLength, 0.0f))); + // } + + // m_secondaryGridPoints.clear(); + // m_secondaryGridPoints.reserve(aznumeric_cast(4.0f * m_configuration.m_gridSize / m_configuration.m_secondarySpacing)); + // for (float position = m_configuration.m_secondarySpacing; position <= halfLength; + // position += m_configuration.m_secondarySpacing) + // { + // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, -position, 0.0f))); + // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, -position, 0.0f))); + // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, position, 0.0f))); + // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, position, 0.0f))); + // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, -halfLength, 0.0f))); + // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, halfLength, 0.0f))); + // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, -halfLength, 0.0f))); + // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, halfLength, 0.0f))); + // } + + BillboardComponentNotificationBus::Event(m_entityId, &BillboardComponentNotificationBus::Events::OnGridChanged); } } // namespace Render } // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h index 844670a..54bb068 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace AZ { @@ -75,8 +76,6 @@ namespace AZ EntityId m_entityId; BillboardComponentConfig m_configuration; AZStd::vector m_axisGridPoints; - AZStd::vector m_primaryGridPoints; - AZStd::vector m_secondaryGridPoints; bool m_dirty = true; // must be set to true for any configuration change that rebuilds the grid }; } // namespace Render diff --git a/atom_gems/AtomTutorials/Code/atomtutorials_api_files.cmake b/atom_gems/AtomTutorials/Code/atomtutorials_api_files.cmake index 2034c8d..ae39ab9 100644 --- a/atom_gems/AtomTutorials/Code/atomtutorials_api_files.cmake +++ b/atom_gems/AtomTutorials/Code/atomtutorials_api_files.cmake @@ -1,6 +1,5 @@ set(FILES - Include/AtomTutorials/AtomTutorialsBus.h Include/AtomTutorials/Billboard/BillboardComponentBus.h Include/AtomTutorials/Billboard/BillboardComponentConfig.h Include/AtomTutorials/Billboard/BillboardComponentConstants.h From 6efc5058e9238bdbac705765b51b6cf112e2a800 Mon Sep 17 00:00:00 2001 From: Judy Ng Date: Mon, 1 Aug 2022 11:55:23 -0700 Subject: [PATCH 03/12] start dynamic draw Signed-off-by: Judy Ng --- .../BillboardComponentController.cpp | 89 ++++++++++++------- .../Billboard/BillboardComponentController.h | 17 ++++ .../DynamicDraw/DynamicDrawExample.azsl | 55 ++++++++++++ .../DynamicDraw/DynamicDrawExample.shader | 39 ++++++++ 4 files changed, 168 insertions(+), 32 deletions(-) create mode 100644 atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.azsl create mode 100644 atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.shader diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp index b9a29ee..3c9109b 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -85,6 +86,22 @@ namespace AZ BillboardComponentRequestBus::Handler::BusConnect(m_entityId); AZ::TransformNotificationBus::Handler::BusConnect(m_entityId); + + // Dynamic Draw + AZStd::vector vertexChannels = + { + { "POSITION", RHI::Format::R32G32B32_FLOAT }, + { "COLOR", RHI::Format::R32G32B32A32_FLOAT } + }; + + m_dynamicDraw = RPI::DynamicDrawInterface::Get()->CreateDynamicDrawContext(); + m_dynamicDraw->InitVertexFormat(vertexChannels); + m_dynamicDraw->AddDrawStateOptions(RPI::DynamicDrawContext::DrawStateOptions::BlendMode | RPI::DynamicDrawContext::DrawStateOptions::PrimitiveType + | RPI::DynamicDrawContext::DrawStateOptions::DepthState | RPI::DynamicDrawContext::DrawStateOptions::FaceCullMode); + m_dynamicDraw->SetOutputScope(scene); + m_dynamicDraw->EndInit(); + + AZ_Assert(m_dynamicDraw->IsVertexSizeValid(sizeof(ExampleVertex)), "Invalid vertex format"); } void BillboardComponentController::Deactivate() @@ -187,11 +204,12 @@ namespace AZ { BuildGrid(); + /* AZ::RPI::AuxGeomDraw::AuxGeomDynamicDrawArguments drawArgs; drawArgs.m_verts = m_axisGridPoints.data(); drawArgs.m_vertCount = aznumeric_cast(m_axisGridPoints.size()); drawArgs.m_colors = &m_configuration.m_axisColor; - auxGeom->DrawLines(drawArgs); + auxGeom->DrawLines(drawArgs);*/ } } @@ -225,7 +243,7 @@ namespace AZ AZ::Vector3 p2_world = myPosition - cameraRight * halfLength - cameraUp * halfLength; // bottom left AZ::Vector3 p3_world = myPosition - cameraRight * halfLength + cameraUp * halfLength; // top left - + /* // Make lines m_axisGridPoints.clear(); m_axisGridPoints.reserve(8); @@ -240,37 +258,44 @@ namespace AZ m_axisGridPoints.push_back(p3_world); // Top m_axisGridPoints.push_back(p3_world); - m_axisGridPoints.push_back(p0_world); + m_axisGridPoints.push_back(p0_world);*/ - // m_primaryGridPoints.clear(); - // m_primaryGridPoints.reserve(aznumeric_cast(4.0f * m_configuration.m_gridSize / m_configuration.m_primarySpacing)); - // for (float position = m_configuration.m_primarySpacing; position <= halfLength; - // position += m_configuration.m_primarySpacing) - // { - // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, -position, 0.0f))); - // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, -position, 0.0f))); - // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, position, 0.0f))); - // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, position, 0.0f))); - // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, -halfLength, 0.0f))); - // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, halfLength, 0.0f))); - // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, -halfLength, 0.0f))); - // m_primaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, halfLength, 0.0f))); - // } - - // m_secondaryGridPoints.clear(); - // m_secondaryGridPoints.reserve(aznumeric_cast(4.0f * m_configuration.m_gridSize / m_configuration.m_secondarySpacing)); - // for (float position = m_configuration.m_secondarySpacing; position <= halfLength; - // position += m_configuration.m_secondarySpacing) - // { - // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, -position, 0.0f))); - // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, -position, 0.0f))); - // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-halfLength, position, 0.0f))); - // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(halfLength, position, 0.0f))); - // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, -halfLength, 0.0f))); - // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(-position, halfLength, 0.0f))); - // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, -halfLength, 0.0f))); - // m_secondaryGridPoints.push_back(transform.TransformPoint(AZ::Vector3(position, halfLength, 0.0f))); - // } + float positions[4][3] = + { + {p0_world.GetX(), p0_world.GetY(), p0_world.GetZ()}, + {p1_world.GetX(), p1_world.GetY(), p1_world.GetZ()}, + {p2_world.GetX(), p2_world.GetY(), p2_world.GetZ()}, + {p3_world.GetX(), p3_world.GetY(), p3_world.GetZ()}, + }; + + float colors[4][4] = { { 1, 0, 0, 0.5f }, { 0, 1, 0, 0.5f }, { 0, 0, 1, 0.5f }, {1, 1, 0, 0.5f} }; + + ExampleVertex vertices[8] = { + ExampleVertex{positions[0], colors[0]}, + ExampleVertex{positions[1], colors[0]}, + ExampleVertex{positions[1], colors[0]}, + ExampleVertex{positions[2], colors[0]}, + ExampleVertex{positions[2], colors[0]}, + ExampleVertex{positions[3], colors[0]}, + ExampleVertex{positions[3], colors[0]}, + ExampleVertex{positions[0], colors[0]} + }; + + RHI::DepthState depthState; + depthState.m_enable = true; + depthState.m_writeMask = RHI::DepthWriteMask::All; + depthState.m_func = RHI::ComparisonFunc::GreaterEqual; + m_dynamicDraw->SetDepthState(depthState); + // Disable blend + RHI::TargetBlendState blendState; + blendState.m_enable = false; + m_dynamicDraw->SetTarget0BlendState(blendState); + + Data::Instance drawSrg = m_dynamicDraw->NewDrawSrg(); + drawSrg->Compile(); + + m_dynamicDraw->SetCullMode(RHI::CullMode::None); + m_dynamicDraw->DrawLinear(vertices, 8, drawSrg); BillboardComponentNotificationBus::Event(m_entityId, &BillboardComponentNotificationBus::Events::OnGridChanged); } diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h index 54bb068..9d9a3b7 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h @@ -9,11 +9,13 @@ #pragma once #include +#include #include #include #include #include #include +#include namespace AZ { @@ -50,6 +52,17 @@ namespace AZ private: AZ_DISABLE_COPY(BillboardComponentController); + struct ExampleVertex + { + ExampleVertex(float position[3], float color[4]) + { + memcpy(m_position, position, sizeof(float) * 3); + memcpy(m_color, color, sizeof(float) * 4); + } + float m_position[3]; + float m_color[4]; + }; + //! BillboardComponentRequestBus overrides... void SetSize(float size) override; float GetSize() const override; @@ -77,6 +90,10 @@ namespace AZ BillboardComponentConfig m_configuration; AZStd::vector m_axisGridPoints; bool m_dirty = true; // must be set to true for any configuration change that rebuilds the grid + AZ::RHI::Ptr m_dynamicDraw; + + //! Async asset load + AZ::AssetCollectionAsyncLoader m_assetLoadManager; }; } // namespace Render } // namespace AZ diff --git a/atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.azsl b/atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.azsl new file mode 100644 index 0000000..c8fa31c --- /dev/null +++ b/atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.azsl @@ -0,0 +1,55 @@ +/* + * 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 +#include + +ShaderResourceGroup PerContextSrg : SRG_PerSubPass +{ + float m_scale; +} + +ShaderResourceGroup PerDrawSrg : SRG_PerDraw +{ + float3 m_positionOffset; +} + +struct VSInput +{ + float3 m_position : POSITION; + float4 m_color : COLOR0; +}; + +struct VSOutput +{ + float4 m_position : SV_Position; + float4 m_color : COLOR0; +}; + +VSOutput MainVS(VSInput IN) +{ + VSOutput OUT; + + OUT.m_position = float4(IN.m_position + PerDrawSrg::m_positionOffset, 1.0f);// * PerContextSrg::m_scale; + OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, OUT.m_position); + OUT.m_color = IN.m_color; + return OUT; +}; + +struct PSOutput +{ + float4 m_diffuse : SV_Target0; +}; + +PSOutput MainPS(VSOutput IN) +{ + PSOutput OUT; + OUT.m_diffuse = IN.m_color; + return OUT; +}; + diff --git a/atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.shader b/atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.shader new file mode 100644 index 0000000..08e2bbd --- /dev/null +++ b/atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.shader @@ -0,0 +1,39 @@ +{ + "Source" : "DynamicDrawExample.azsl", + + "DepthStencilState" : { + "Depth" : { + "Enable" : true, + "CompareFunc" : "Always" + } + }, + + "RasterState" : { + "DepthClipEnable" : false, + "CullMode" : "None" + }, + + "BlendState" : { + "Enable" : true, + "BlendSource" : "One", + "BlendDest" : "AlphaSourceInverse", + "BlendOp" : "Add" + }, + + "DrawList" : "auxgeom", + + "ProgramSettings": + { + "EntryPoints": + [ + { + "name": "MainVS", + "type": "Vertex" + }, + { + "name": "MainPS", + "type": "Fragment" + } + ] + } +} From 423c272189a91ecf821b958da3131c6da6b7ce10 Mon Sep 17 00:00:00 2001 From: Judy Ng Date: Wed, 3 Aug 2022 00:26:01 -0700 Subject: [PATCH 04/12] billboard mostly working Signed-off-by: Judy Ng --- .../BillboardComponentController.cpp | 172 +++++++++++++----- .../Billboard/BillboardComponentController.h | 32 +++- 2 files changed, 152 insertions(+), 52 deletions(-) diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp index 3c9109b..7e4161d 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -73,44 +72,109 @@ namespace AZ { } - void BillboardComponentController::Activate(EntityId entityId) + void BillboardComponentController::Activate(const AZ::EntityComponentIdPair& entityComponentIdPair) { - m_entityId = entityId; + const AZ::EntityId entityId = entityComponentIdPair.GetEntityId(); + m_entityComponentIdPair = entityComponentIdPair; m_dirty = true; - RPI::Scene* scene = RPI::Scene::GetSceneForEntityId(m_entityId); + RPI::Scene* scene = RPI::Scene::GetSceneForEntityId(entityId); if (scene) { AZ::RPI::SceneNotificationBus::Handler::BusConnect(scene->GetId()); } - BillboardComponentRequestBus::Handler::BusConnect(m_entityId); - AZ::TransformNotificationBus::Handler::BusConnect(m_entityId); - - // Dynamic Draw - AZStd::vector vertexChannels = - { - { "POSITION", RHI::Format::R32G32B32_FLOAT }, - { "COLOR", RHI::Format::R32G32B32A32_FLOAT } - }; - - m_dynamicDraw = RPI::DynamicDrawInterface::Get()->CreateDynamicDrawContext(); - m_dynamicDraw->InitVertexFormat(vertexChannels); - m_dynamicDraw->AddDrawStateOptions(RPI::DynamicDrawContext::DrawStateOptions::BlendMode | RPI::DynamicDrawContext::DrawStateOptions::PrimitiveType - | RPI::DynamicDrawContext::DrawStateOptions::DepthState | RPI::DynamicDrawContext::DrawStateOptions::FaceCullMode); - m_dynamicDraw->SetOutputScope(scene); - m_dynamicDraw->EndInit(); - - AZ_Assert(m_dynamicDraw->IsVertexSizeValid(sizeof(ExampleVertex)), "Invalid vertex format"); + BillboardComponentRequestBus::Handler::BusConnect(entityId); + AZ::TransformNotificationBus::Handler::BusConnect(entityId); + + AzFramework::EntityContextId contextId = AzFramework::EntityContextId::CreateNull(); + AzFramework::EntityIdContextQueryBus::EventResult( + contextId, entityId, &AzFramework::EntityIdContextQueries::GetOwningContextId); + AzFramework::BoundsRequestBus::Handler::BusConnect(entityId); + AzFramework::RenderGeometry::IntersectionRequestBus::Handler::BusConnect({ entityId, contextId }); + AzFramework::RenderGeometry::IntersectionNotificationBus::Bind(m_intersectionNotificationBus, contextId); + + m_transformInterface = TransformBus::FindFirstHandler(entityId); + AZ_Warning( + "BillboardComponentController", m_transformInterface, + "Unable to attach to a TransformBus handler. This mesh will always be rendered at the origin."); + + m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(entityId); + AZ_Assert(m_meshFeatureProcessor, "MeshFeatureProcessor not available."); + + AZ::Data::Asset materialAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath("materials/presets/pbr/metal_gold.azmaterial", AZ::RPI::AssetUtils::TraceLevel::Error); + m_material = AZ::RPI::Material::FindOrCreate(materialAsset); + m_modelAsset = AZ::RPI::AssetUtils::GetAssetByProductPath("materialeditor/viewportmodels/plane_1x1.azmodel", AZ::RPI::AssetUtils::TraceLevel::Assert); + auto meshDescriptor = AZ::Render::MeshHandleDescriptor{ m_modelAsset }; + meshDescriptor.m_isRayTracingEnabled = false; + + m_meshHandle = m_meshFeatureProcessor->AcquireMesh(meshDescriptor, m_material); + + const AZ::Transform& transform = + m_transformInterface ? m_transformInterface->GetWorldTM() : AZ::Transform::CreateIdentity(); + + m_meshFeatureProcessor->SetRayTracingEnabled(m_meshHandle, false); + m_meshFeatureProcessor->SetTransform(m_meshHandle, transform); } void BillboardComponentController::Deactivate() { + AzFramework::RenderGeometry::IntersectionRequestBus::Handler::BusDisconnect(); + AzFramework::BoundsRequestBus::Handler::BusDisconnect(); AZ::TransformNotificationBus::Handler::BusDisconnect(); BillboardComponentRequestBus::Handler::BusDisconnect(); AZ::RPI::SceneNotificationBus::Handler::BusDisconnect(); - m_entityId = EntityId(EntityId::InvalidEntityId); + m_entityComponentIdPair = AZ::EntityComponentIdPair(AZ::EntityId(), AZ::InvalidComponentId); + } + + Aabb BillboardComponentController::GetWorldBounds() + { + if (const AZ::Aabb localBounds = GetLocalBounds(); localBounds.IsValid()) + { + return localBounds.GetTransformedAabb(m_transformInterface->GetWorldTM()); + } + + return AZ::Aabb::CreateNull(); + } + + Aabb BillboardComponentController::GetLocalBounds() + { + if (m_meshHandle.IsValid() && m_meshFeatureProcessor) + { + if (Aabb aabb = m_meshFeatureProcessor->GetLocalAabb(m_meshHandle); aabb.IsValid()) + { + return aabb; + } + } + + return Aabb::CreateNull(); + } + + + AzFramework::RenderGeometry::RayResult BillboardComponentController::RenderGeometryIntersect( + const AzFramework::RenderGeometry::RayRequest& ray) + { + AzFramework::RenderGeometry::RayResult result; + const Data::Instance model = m_meshFeatureProcessor->GetModel(m_meshHandle); + float t; + AZ::Transform curT = m_meshFeatureProcessor->GetTransform(m_meshHandle); + + AZ::Vector3 normal; + if (model->RayIntersection( + curT, AZ::Vector3::CreateOne(), ray.m_startWorldPosition, + ray.m_endWorldPosition - ray.m_startWorldPosition, t, normal)) + { + // fill in ray result structure after successful intersection + const auto intersectionLine = (ray.m_endWorldPosition - ray.m_startWorldPosition); + result.m_uv = AZ::Vector2::CreateZero(); + result.m_worldPosition = ray.m_startWorldPosition + intersectionLine * t; + result.m_worldNormal = normal; + result.m_distance = intersectionLine.GetLength() * t; + result.m_entityAndComponent = m_entityComponentIdPair; + } + + return result; } void BillboardComponentController::SetConfiguration(const BillboardComponentConfig& config) @@ -194,7 +258,12 @@ namespace AZ return; } - auto* auxGeomFP = AZ::RPI::Scene::GetFeatureProcessorForEntity(m_entityId); + m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(m_entityComponentIdPair.GetEntityId()); + if (!m_meshFeatureProcessor) { + return; + } + + auto* auxGeomFP = AZ::RPI::Scene::GetFeatureProcessorForEntity(m_entityComponentIdPair.GetEntityId()); if (!auxGeomFP) { return; @@ -218,6 +287,16 @@ namespace AZ AZ_UNUSED(local); AZ_UNUSED(world); m_dirty = true; + + if (m_meshFeatureProcessor) + { + /*AZ::Transform transf = world; + transf.SetTranslation(AZ::Vector3(world.GetTranslation().GetX() + 1, world.GetTranslation().GetY() + 1, world.GetTranslation().GetZ() + 1)); + m_meshFeatureProcessor->SetTransform(m_meshHandle, transf); + AzFramework::RenderGeometry::IntersectionNotificationBus::Event( + m_intersectionNotificationBus, &AzFramework::RenderGeometry::IntersectionNotificationBus::Events::OnGeometryChanged, + m_entityComponentIdPair.GetEntityId());*/ + } } void BillboardComponentController::BuildGrid() @@ -228,20 +307,37 @@ namespace AZ AZ::Vector3 cameraWorldPosition; AZ::TransformBus::EventResult(cameraWorldPosition, cam, &AZ::TransformBus::Events::GetWorldTranslation); + + AZ::Vector3 myPosition; - AZ::TransformBus::EventResult(myPosition, m_entityId, &AZ::TransformBus::Events::GetWorldTranslation); + AZ::TransformBus::EventResult(myPosition, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation); + AZ::Transform myTransform; + AZ::TransformBus::EventResult(myTransform, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTM); + /* const float halfLength = m_configuration.m_gridSize / 2.0f; // From camera POV, the forward axis is Z positive, even though O3DE's default is Y positive for forward axis. - AZ::Matrix3x4 viewMatrix = AZ::Matrix3x4::CreateFromTransform(AZ::Transform::CreateLookAt(cameraWorldPosition, myPosition, AZ::Transform::Axis::ZPositive)); + AZ::Transform tf = AZ::Transform::CreateLookAt(cameraWorldPosition, myPosition, AZ::Transform::Axis::ZPositive); + AZ::Matrix3x4 viewMatrix = AZ::Matrix3x4::CreateFromTransform(tf);*/ + + //AZ::Transform curT = m_meshFeatureProcessor->GetTransform(m_meshHandle); + //AZ::Transform transf = AZ::Transform::CreateLookAt(cameraWorldPosition, myPosition, AZ::Transform::Axis::ZPositive); + AZ::Transform tf = AZ::Transform::CreateLookAt(myPosition, cameraWorldPosition, AZ::Transform::Axis::ZPositive); + m_meshFeatureProcessor->SetTransform(m_meshHandle, tf); + + AzFramework::RenderGeometry::IntersectionNotificationBus::Event( + m_intersectionNotificationBus, &AzFramework::RenderGeometry::IntersectionNotificationBus::Events::OnGeometryChanged, + m_entityComponentIdPair.GetEntityId()); + + /* AZ::Vector3 cameraRight = AZ::Vector3(viewMatrix(0, 0), viewMatrix(1, 0), viewMatrix(2, 0)); AZ::Vector3 cameraUp = AZ::Vector3(viewMatrix(0, 1), viewMatrix(1, 1), viewMatrix(2, 1)); AZ::Vector3 p0_world = myPosition + cameraRight * halfLength + cameraUp * halfLength; // top right AZ::Vector3 p1_world = myPosition + cameraRight * halfLength - cameraUp * halfLength; // bottom right AZ::Vector3 p2_world = myPosition - cameraRight * halfLength - cameraUp * halfLength; // bottom left - AZ::Vector3 p3_world = myPosition - cameraRight * halfLength + cameraUp * halfLength; // top left + AZ::Vector3 p3_world = myPosition - cameraRight * halfLength + cameraUp * halfLength; // top left*/ /* // Make lines @@ -258,7 +354,7 @@ namespace AZ m_axisGridPoints.push_back(p3_world); // Top m_axisGridPoints.push_back(p3_world); - m_axisGridPoints.push_back(p0_world);*/ + m_axisGridPoints.push_back(p0_world); float positions[4][3] = { @@ -280,24 +376,10 @@ namespace AZ ExampleVertex{positions[3], colors[0]}, ExampleVertex{positions[0], colors[0]} }; + */ + - RHI::DepthState depthState; - depthState.m_enable = true; - depthState.m_writeMask = RHI::DepthWriteMask::All; - depthState.m_func = RHI::ComparisonFunc::GreaterEqual; - m_dynamicDraw->SetDepthState(depthState); - // Disable blend - RHI::TargetBlendState blendState; - blendState.m_enable = false; - m_dynamicDraw->SetTarget0BlendState(blendState); - - Data::Instance drawSrg = m_dynamicDraw->NewDrawSrg(); - drawSrg->Compile(); - - m_dynamicDraw->SetCullMode(RHI::CullMode::None); - m_dynamicDraw->DrawLinear(vertices, 8, drawSrg); - - BillboardComponentNotificationBus::Event(m_entityId, &BillboardComponentNotificationBus::Events::OnGridChanged); + BillboardComponentNotificationBus::Event(m_entityComponentIdPair.GetEntityId(), &BillboardComponentNotificationBus::Events::OnGridChanged); } } // namespace Render } // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h index 9d9a3b7..b064293 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h @@ -9,13 +9,15 @@ #pragma once #include -#include #include #include #include #include #include -#include +#include +#include +#include +#include namespace AZ { @@ -26,6 +28,8 @@ namespace AZ : public BillboardComponentRequestBus::Handler , public AZ::TransformNotificationBus::Handler , public AZ::RPI::SceneNotificationBus::Handler + , public AzFramework::BoundsRequestBus::Handler + , public AzFramework::RenderGeometry::IntersectionRequestBus::Handler { public: friend class EditorBillboardComponent; @@ -40,7 +44,7 @@ namespace AZ BillboardComponentController() = default; BillboardComponentController(const BillboardComponentConfig& config); - void Activate(EntityId entityId); + void Activate(const AZ::EntityComponentIdPair& entityComponentIdPair); void Deactivate(); void SetConfiguration(const BillboardComponentConfig& config); const BillboardComponentConfig& GetConfiguration() const; @@ -84,16 +88,30 @@ namespace AZ // AZ::RPI::SceneNotificationBus::Handler overrides ... void OnBeginPrepareRender() override; + // BoundsRequestBus and MeshComponentRequestBus overrides ... + AZ::Aabb GetWorldBounds() override; + AZ::Aabb GetLocalBounds() override; + + // IntersectionRequestBus overrides ... + AzFramework::RenderGeometry::RayResult RenderGeometryIntersect(const AzFramework::RenderGeometry::RayRequest& ray) override; + void BuildGrid(); - EntityId m_entityId; BillboardComponentConfig m_configuration; AZStd::vector m_axisGridPoints; bool m_dirty = true; // must be set to true for any configuration change that rebuilds the grid - AZ::RHI::Ptr m_dynamicDraw; - //! Async asset load - AZ::AssetCollectionAsyncLoader m_assetLoadManager; + //! Cached bus to use to notify RenderGeometry::Intersector the entity/component has changed. + AzFramework::RenderGeometry::IntersectionNotificationBus::BusPtr m_intersectionNotificationBus; + + AZ::Render::MeshFeatureProcessorInterface* m_meshFeatureProcessor; + TransformInterface* m_transformInterface = nullptr; + + AZ::Data::Asset m_modelAsset; + AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle; + AZ::Data::Instance m_material; + + AZ::EntityComponentIdPair m_entityComponentIdPair; }; } // namespace Render } // namespace AZ From 25553e32f8050cc8fcdba31cd44ad4a152948ed7 Mon Sep 17 00:00:00 2001 From: Judy Ng Date: Wed, 3 Aug 2022 10:53:39 -0700 Subject: [PATCH 05/12] Billboard w/ material works! Signed-off-by: Judy Ng --- .../BillboardComponentController.cpp | 101 ++---------------- .../Billboard/BillboardComponentController.h | 15 --- 2 files changed, 9 insertions(+), 107 deletions(-) diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp index 7e4161d..80fcebb 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp @@ -90,14 +90,6 @@ namespace AZ AzFramework::EntityContextId contextId = AzFramework::EntityContextId::CreateNull(); AzFramework::EntityIdContextQueryBus::EventResult( contextId, entityId, &AzFramework::EntityIdContextQueries::GetOwningContextId); - AzFramework::BoundsRequestBus::Handler::BusConnect(entityId); - AzFramework::RenderGeometry::IntersectionRequestBus::Handler::BusConnect({ entityId, contextId }); - AzFramework::RenderGeometry::IntersectionNotificationBus::Bind(m_intersectionNotificationBus, contextId); - - m_transformInterface = TransformBus::FindFirstHandler(entityId); - AZ_Warning( - "BillboardComponentController", m_transformInterface, - "Unable to attach to a TransformBus handler. This mesh will always be rendered at the origin."); m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(entityId); AZ_Assert(m_meshFeatureProcessor, "MeshFeatureProcessor not available."); @@ -106,75 +98,26 @@ namespace AZ m_material = AZ::RPI::Material::FindOrCreate(materialAsset); m_modelAsset = AZ::RPI::AssetUtils::GetAssetByProductPath("materialeditor/viewportmodels/plane_1x1.azmodel", AZ::RPI::AssetUtils::TraceLevel::Assert); auto meshDescriptor = AZ::Render::MeshHandleDescriptor{ m_modelAsset }; - meshDescriptor.m_isRayTracingEnabled = false; m_meshHandle = m_meshFeatureProcessor->AcquireMesh(meshDescriptor, m_material); - const AZ::Transform& transform = - m_transformInterface ? m_transformInterface->GetWorldTM() : AZ::Transform::CreateIdentity(); - - m_meshFeatureProcessor->SetRayTracingEnabled(m_meshHandle, false); - m_meshFeatureProcessor->SetTransform(m_meshHandle, transform); + m_meshFeatureProcessor->SetTransform(m_meshHandle, AZ::Transform::CreateIdentity()); } void BillboardComponentController::Deactivate() { - AzFramework::RenderGeometry::IntersectionRequestBus::Handler::BusDisconnect(); - AzFramework::BoundsRequestBus::Handler::BusDisconnect(); + if (m_meshFeatureProcessor && m_meshHandle.IsValid()) + { + m_meshFeatureProcessor->ReleaseMesh(m_meshHandle); + } + AZ::TransformNotificationBus::Handler::BusDisconnect(); BillboardComponentRequestBus::Handler::BusDisconnect(); AZ::RPI::SceneNotificationBus::Handler::BusDisconnect(); + m_meshFeatureProcessor = nullptr; m_entityComponentIdPair = AZ::EntityComponentIdPair(AZ::EntityId(), AZ::InvalidComponentId); - } - - Aabb BillboardComponentController::GetWorldBounds() - { - if (const AZ::Aabb localBounds = GetLocalBounds(); localBounds.IsValid()) - { - return localBounds.GetTransformedAabb(m_transformInterface->GetWorldTM()); - } - - return AZ::Aabb::CreateNull(); - } - - Aabb BillboardComponentController::GetLocalBounds() - { - if (m_meshHandle.IsValid() && m_meshFeatureProcessor) - { - if (Aabb aabb = m_meshFeatureProcessor->GetLocalAabb(m_meshHandle); aabb.IsValid()) - { - return aabb; - } - } - - return Aabb::CreateNull(); - } - - - AzFramework::RenderGeometry::RayResult BillboardComponentController::RenderGeometryIntersect( - const AzFramework::RenderGeometry::RayRequest& ray) - { - AzFramework::RenderGeometry::RayResult result; - const Data::Instance model = m_meshFeatureProcessor->GetModel(m_meshHandle); - float t; - AZ::Transform curT = m_meshFeatureProcessor->GetTransform(m_meshHandle); - - AZ::Vector3 normal; - if (model->RayIntersection( - curT, AZ::Vector3::CreateOne(), ray.m_startWorldPosition, - ray.m_endWorldPosition - ray.m_startWorldPosition, t, normal)) - { - // fill in ray result structure after successful intersection - const auto intersectionLine = (ray.m_endWorldPosition - ray.m_startWorldPosition); - result.m_uv = AZ::Vector2::CreateZero(); - result.m_worldPosition = ray.m_startWorldPosition + intersectionLine * t; - result.m_worldNormal = normal; - result.m_distance = intersectionLine.GetLength() * t; - result.m_entityAndComponent = m_entityComponentIdPair; - } - - return result; + m_modelAsset.Release(); } void BillboardComponentController::SetConfiguration(const BillboardComponentConfig& config) @@ -326,10 +269,6 @@ namespace AZ AZ::Transform tf = AZ::Transform::CreateLookAt(myPosition, cameraWorldPosition, AZ::Transform::Axis::ZPositive); m_meshFeatureProcessor->SetTransform(m_meshHandle, tf); - AzFramework::RenderGeometry::IntersectionNotificationBus::Event( - m_intersectionNotificationBus, &AzFramework::RenderGeometry::IntersectionNotificationBus::Events::OnGeometryChanged, - m_entityComponentIdPair.GetEntityId()); - /* AZ::Vector3 cameraRight = AZ::Vector3(viewMatrix(0, 0), viewMatrix(1, 0), viewMatrix(2, 0)); AZ::Vector3 cameraUp = AZ::Vector3(viewMatrix(0, 1), viewMatrix(1, 1), viewMatrix(2, 1)); @@ -354,29 +293,7 @@ namespace AZ m_axisGridPoints.push_back(p3_world); // Top m_axisGridPoints.push_back(p3_world); - m_axisGridPoints.push_back(p0_world); - - float positions[4][3] = - { - {p0_world.GetX(), p0_world.GetY(), p0_world.GetZ()}, - {p1_world.GetX(), p1_world.GetY(), p1_world.GetZ()}, - {p2_world.GetX(), p2_world.GetY(), p2_world.GetZ()}, - {p3_world.GetX(), p3_world.GetY(), p3_world.GetZ()}, - }; - - float colors[4][4] = { { 1, 0, 0, 0.5f }, { 0, 1, 0, 0.5f }, { 0, 0, 1, 0.5f }, {1, 1, 0, 0.5f} }; - - ExampleVertex vertices[8] = { - ExampleVertex{positions[0], colors[0]}, - ExampleVertex{positions[1], colors[0]}, - ExampleVertex{positions[1], colors[0]}, - ExampleVertex{positions[2], colors[0]}, - ExampleVertex{positions[2], colors[0]}, - ExampleVertex{positions[3], colors[0]}, - ExampleVertex{positions[3], colors[0]}, - ExampleVertex{positions[0], colors[0]} - }; - */ + m_axisGridPoints.push_back(p0_world);*/ BillboardComponentNotificationBus::Event(m_entityComponentIdPair.GetEntityId(), &BillboardComponentNotificationBus::Events::OnGridChanged); diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h index b064293..98e3185 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h @@ -16,8 +16,6 @@ #include #include #include -#include -#include namespace AZ { @@ -28,8 +26,6 @@ namespace AZ : public BillboardComponentRequestBus::Handler , public AZ::TransformNotificationBus::Handler , public AZ::RPI::SceneNotificationBus::Handler - , public AzFramework::BoundsRequestBus::Handler - , public AzFramework::RenderGeometry::IntersectionRequestBus::Handler { public: friend class EditorBillboardComponent; @@ -88,24 +84,13 @@ namespace AZ // AZ::RPI::SceneNotificationBus::Handler overrides ... void OnBeginPrepareRender() override; - // BoundsRequestBus and MeshComponentRequestBus overrides ... - AZ::Aabb GetWorldBounds() override; - AZ::Aabb GetLocalBounds() override; - - // IntersectionRequestBus overrides ... - AzFramework::RenderGeometry::RayResult RenderGeometryIntersect(const AzFramework::RenderGeometry::RayRequest& ray) override; - void BuildGrid(); BillboardComponentConfig m_configuration; AZStd::vector m_axisGridPoints; bool m_dirty = true; // must be set to true for any configuration change that rebuilds the grid - //! Cached bus to use to notify RenderGeometry::Intersector the entity/component has changed. - AzFramework::RenderGeometry::IntersectionNotificationBus::BusPtr m_intersectionNotificationBus; - AZ::Render::MeshFeatureProcessorInterface* m_meshFeatureProcessor; - TransformInterface* m_transformInterface = nullptr; AZ::Data::Asset m_modelAsset; AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle; From 324c9654300b1790c6544aca32a34f588d721a1f Mon Sep 17 00:00:00 2001 From: Judy Ng Date: Wed, 3 Aug 2022 12:34:49 -0700 Subject: [PATCH 06/12] clean up Signed-off-by: Judy Ng --- .../Billboard/BillboardComponentBus.h | 30 -------- .../Billboard/BillboardComponentConfig.cpp | 5 -- .../BillboardComponentController.cpp | 69 +------------------ .../Billboard/BillboardComponentController.h | 22 ------ .../Billboard/EditorBillboardComponent.cpp | 9 --- .../DynamicDraw/DynamicDrawExample.azsl | 55 --------------- .../DynamicDraw/DynamicDrawExample.shader | 39 ----------- 7 files changed, 1 insertion(+), 228 deletions(-) delete mode 100644 atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.azsl delete mode 100644 atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.shader diff --git a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h index db03bdd..81e391e 100644 --- a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h +++ b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h @@ -24,36 +24,6 @@ namespace AZ //! Returns the dimensions of the grid in meters virtual float GetSize() const = 0; - - //! Sets the distance between grid lines drawn in the primary grid color - virtual void SetPrimarySpacing(float spacing) = 0; - - //! Returns the distance between grid lines drawn and the primary grid color - virtual float GetPrimarySpacing() const = 0; - - //! Sets the distance between grid lines drawn in the secondary grid color - virtual void SetSecondarySpacing(float spacing) = 0; - - //! Returns the distance between grid lines drawn in the secondary grid color - virtual float GetSecondarySpacing() const = 0; - - //! Sets the color of the axis lines spanning the grid dimensions - virtual void SetAxisColor(const AZ::Color& color) = 0; - - //! Returns the color of the axis lines spanning the grid dimensions - virtual AZ::Color GetAxisColor() const = 0; - - //! Sets the color of primary grid lines - virtual void SetPrimaryColor(const AZ::Color& color) = 0; - - //! Returns the color of primary grid lines - virtual AZ::Color GetPrimaryColor() const = 0; - - //! Sets the color of secondary grid lines - virtual void SetSecondaryColor(const AZ::Color& color) = 0; - - //! Returns the color of secondary grid lines - virtual AZ::Color GetSecondaryColor() const = 0; }; using BillboardComponentRequestBus = EBus; diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentConfig.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentConfig.cpp index 68996f8..10eb567 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentConfig.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentConfig.cpp @@ -20,11 +20,6 @@ namespace AZ serializeContext->Class() ->Version(0) ->Field("gridSize", &BillboardComponentConfig::m_gridSize) - ->Field("axisColor", &BillboardComponentConfig::m_axisColor) - ->Field("primarySpacing", &BillboardComponentConfig::m_primarySpacing) - ->Field("primaryColor", &BillboardComponentConfig::m_primaryColor) - ->Field("secondarySpacing", &BillboardComponentConfig::m_secondarySpacing) - ->Field("secondaryColor", &BillboardComponentConfig::m_secondaryColor) ; } } diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp index 80fcebb..f917912 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp @@ -36,23 +36,7 @@ namespace AZ { behaviorContext->EBus("BillboardComponentRequestBus") ->Event("GetSize", &BillboardComponentRequestBus::Events::GetSize) - ->Event("SetSize", &BillboardComponentRequestBus::Events::SetSize) - ->Event("GetAxisColor", &BillboardComponentRequestBus::Events::GetAxisColor) - ->Event("SetAxisColor", &BillboardComponentRequestBus::Events::SetAxisColor) - ->Event("GetPrimaryColor", &BillboardComponentRequestBus::Events::GetPrimaryColor) - ->Event("SetPrimaryColor", &BillboardComponentRequestBus::Events::SetPrimaryColor) - ->Event("GetPrimarySpacing", &BillboardComponentRequestBus::Events::GetPrimarySpacing) - ->Event("SetPrimarySpacing", &BillboardComponentRequestBus::Events::SetPrimarySpacing) - ->Event("GetSecondaryColor", &BillboardComponentRequestBus::Events::GetSecondaryColor) - ->Event("SetSecondaryColor", &BillboardComponentRequestBus::Events::SetSecondaryColor) - ->Event("GetSecondarySpacing", &BillboardComponentRequestBus::Events::GetSecondarySpacing) - ->Event("SetSecondarySpacing", &BillboardComponentRequestBus::Events::SetSecondarySpacing) ->VirtualProperty("Size", "GetSize", "SetSize") - ->VirtualProperty("AxisColor", "GetAxisColor", "SetAxisColor") - ->VirtualProperty("PrimaryColor", "GetPrimaryColor", "SetPrimaryColor") - ->VirtualProperty("PrimarySpacing", "GetPrimarySpacing", "SetPrimarySpacing") - ->VirtualProperty("SecondaryColor", "GetSecondaryColor", "SetSecondaryColor") - ->VirtualProperty("SecondarySpacing", "GetSecondarySpacing", "SetSecondarySpacing") ; } } @@ -94,7 +78,7 @@ namespace AZ m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(entityId); AZ_Assert(m_meshFeatureProcessor, "MeshFeatureProcessor not available."); - AZ::Data::Asset materialAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath("materials/presets/pbr/metal_gold.azmaterial", AZ::RPI::AssetUtils::TraceLevel::Error); + AZ::Data::Asset materialAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath("assets/explosion.azmaterial", AZ::RPI::AssetUtils::TraceLevel::Error); m_material = AZ::RPI::Material::FindOrCreate(materialAsset); m_modelAsset = AZ::RPI::AssetUtils::GetAssetByProductPath("materialeditor/viewportmodels/plane_1x1.azmodel", AZ::RPI::AssetUtils::TraceLevel::Assert); auto meshDescriptor = AZ::Render::MeshHandleDescriptor{ m_modelAsset }; @@ -142,57 +126,6 @@ namespace AZ return m_configuration.m_gridSize; } - void BillboardComponentController::SetPrimarySpacing(float spacing) - { - m_configuration.m_primarySpacing = AZStd::max(spacing, MinSpacing); - m_dirty = true; - } - - float BillboardComponentController::GetPrimarySpacing() const - { - return m_configuration.m_primarySpacing; - } - - void BillboardComponentController::SetSecondarySpacing(float spacing) - { - m_configuration.m_secondarySpacing = AZStd::max(spacing, MinSpacing); - m_dirty = true; - } - - float BillboardComponentController::GetSecondarySpacing() const - { - return m_configuration.m_secondarySpacing; - } - - void BillboardComponentController::SetAxisColor(const AZ::Color& color) - { - m_configuration.m_axisColor = color; - } - - AZ::Color BillboardComponentController::GetAxisColor() const - { - return m_configuration.m_axisColor; - } - - void BillboardComponentController::SetPrimaryColor(const AZ::Color& color) - { - m_configuration.m_primaryColor = color; - } - - AZ::Color BillboardComponentController::GetPrimaryColor() const - { - return m_configuration.m_primaryColor; - } - - void BillboardComponentController::SetSecondaryColor(const AZ::Color& color) - { - m_configuration.m_secondaryColor = color; - } - - AZ::Color BillboardComponentController::GetSecondaryColor() const - { - return m_configuration.m_secondaryColor; - } void BillboardComponentController::OnBeginPrepareRender() { diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h index 98e3185..84afe59 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h @@ -52,31 +52,9 @@ namespace AZ private: AZ_DISABLE_COPY(BillboardComponentController); - struct ExampleVertex - { - ExampleVertex(float position[3], float color[4]) - { - memcpy(m_position, position, sizeof(float) * 3); - memcpy(m_color, color, sizeof(float) * 4); - } - float m_position[3]; - float m_color[4]; - }; - //! BillboardComponentRequestBus overrides... void SetSize(float size) override; float GetSize() const override; - void SetPrimarySpacing(float spacing) override; - float GetPrimarySpacing() const override; - void SetSecondarySpacing(float spacing) override; - float GetSecondarySpacing() const override; - - void SetAxisColor(const AZ::Color& color) override; - AZ::Color GetAxisColor() const override; - void SetPrimaryColor(const AZ::Color& color) override; - AZ::Color GetPrimaryColor() const override; - void SetSecondaryColor(const AZ::Color& color) override; - AZ::Color GetSecondaryColor() const override; //! AZ::TransformNotificationBus::Handler overrides ... void OnTransformChanged(const Transform& local, const Transform& world) override; diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp index 8a709b3..7417b77 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp @@ -53,15 +53,6 @@ namespace AZ ->Attribute(AZ::Edit::Attributes::Min, BillboardComponentController::MinGridSize) ->Attribute(AZ::Edit::Attributes::Max, BillboardComponentController::MaxGridSize) ->Attribute(AZ::Edit::Attributes::Suffix, " m") - ->DataElement(AZ::Edit::UIHandlers::Default, &BillboardComponentConfig::m_primarySpacing, "Primary Grid Spacing", "Amount of space between grid lines") - ->Attribute(AZ::Edit::Attributes::Min, BillboardComponentController::MinSpacing) - ->Attribute(AZ::Edit::Attributes::Suffix, " m") - ->DataElement(AZ::Edit::UIHandlers::Default, &BillboardComponentConfig::m_secondarySpacing, "Secondary Grid Spacing", "Amount of space between sub-grid lines") - ->Attribute(AZ::Edit::Attributes::Min, BillboardComponentController::MinSpacing) - ->Attribute(AZ::Edit::Attributes::Suffix, " m") - ->DataElement(AZ::Edit::UIHandlers::Color, &BillboardComponentConfig::m_axisColor, "Axis Color", "Color of the grid axis") - ->DataElement(AZ::Edit::UIHandlers::Color, &BillboardComponentConfig::m_primaryColor, "Primary Color", "Color of the primary grid lines") - ->DataElement(AZ::Edit::UIHandlers::Color, &BillboardComponentConfig::m_secondaryColor, "Secondary Color", "Color of the secondary grid lines") ; } } diff --git a/atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.azsl b/atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.azsl deleted file mode 100644 index c8fa31c..0000000 --- a/atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.azsl +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 -#include - -ShaderResourceGroup PerContextSrg : SRG_PerSubPass -{ - float m_scale; -} - -ShaderResourceGroup PerDrawSrg : SRG_PerDraw -{ - float3 m_positionOffset; -} - -struct VSInput -{ - float3 m_position : POSITION; - float4 m_color : COLOR0; -}; - -struct VSOutput -{ - float4 m_position : SV_Position; - float4 m_color : COLOR0; -}; - -VSOutput MainVS(VSInput IN) -{ - VSOutput OUT; - - OUT.m_position = float4(IN.m_position + PerDrawSrg::m_positionOffset, 1.0f);// * PerContextSrg::m_scale; - OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, OUT.m_position); - OUT.m_color = IN.m_color; - return OUT; -}; - -struct PSOutput -{ - float4 m_diffuse : SV_Target0; -}; - -PSOutput MainPS(VSOutput IN) -{ - PSOutput OUT; - OUT.m_diffuse = IN.m_color; - return OUT; -}; - diff --git a/atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.shader b/atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.shader deleted file mode 100644 index 08e2bbd..0000000 --- a/atom_gems/AtomTutorials/Shaders/DynamicDraw/DynamicDrawExample.shader +++ /dev/null @@ -1,39 +0,0 @@ -{ - "Source" : "DynamicDrawExample.azsl", - - "DepthStencilState" : { - "Depth" : { - "Enable" : true, - "CompareFunc" : "Always" - } - }, - - "RasterState" : { - "DepthClipEnable" : false, - "CullMode" : "None" - }, - - "BlendState" : { - "Enable" : true, - "BlendSource" : "One", - "BlendDest" : "AlphaSourceInverse", - "BlendOp" : "Add" - }, - - "DrawList" : "auxgeom", - - "ProgramSettings": - { - "EntryPoints": - [ - { - "name": "MainVS", - "type": "Vertex" - }, - { - "name": "MainPS", - "type": "Fragment" - } - ] - } -} From 719db5d2ff7049abcc6f77ec960b3d9c04a39aac Mon Sep 17 00:00:00 2001 From: Judy Ng Date: Thu, 4 Aug 2022 14:55:16 -0700 Subject: [PATCH 07/12] remove last grid part Signed-off-by: Judy Ng --- .../Billboard/BillboardComponentBus.h | 5 ----- .../Source/Billboard/BillboardComponentConfig.cpp | 1 - .../Billboard/BillboardComponentController.cpp | 15 +-------------- .../Billboard/BillboardComponentController.h | 4 ---- .../Source/Billboard/EditorBillboardComponent.cpp | 4 ---- 5 files changed, 1 insertion(+), 28 deletions(-) diff --git a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h index 81e391e..ac58725 100644 --- a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h +++ b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h @@ -19,11 +19,6 @@ namespace AZ class BillboardComponentRequests : public ComponentBus { public: - //! Sets the dimensions of the grid in meters - virtual void SetSize(float size) = 0; - - //! Returns the dimensions of the grid in meters - virtual float GetSize() const = 0; }; using BillboardComponentRequestBus = EBus; diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentConfig.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentConfig.cpp index 10eb567..56fd317 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentConfig.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentConfig.cpp @@ -19,7 +19,6 @@ namespace AZ { serializeContext->Class() ->Version(0) - ->Field("gridSize", &BillboardComponentConfig::m_gridSize) ; } } diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp index f917912..3a9d449 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp @@ -35,8 +35,6 @@ namespace AZ if (AZ::BehaviorContext* behaviorContext = azrtti_cast(context)) { behaviorContext->EBus("BillboardComponentRequestBus") - ->Event("GetSize", &BillboardComponentRequestBus::Events::GetSize) - ->VirtualProperty("Size", "GetSize", "SetSize") ; } } @@ -84,7 +82,7 @@ namespace AZ auto meshDescriptor = AZ::Render::MeshHandleDescriptor{ m_modelAsset }; m_meshHandle = m_meshFeatureProcessor->AcquireMesh(meshDescriptor, m_material); - + m_meshFeatureProcessor->SetTransform(m_meshHandle, AZ::Transform::CreateIdentity()); } @@ -115,17 +113,6 @@ namespace AZ return m_configuration; } - void BillboardComponentController::SetSize(float size) - { - m_configuration.m_gridSize = AZStd::clamp(size, MinGridSize, MaxGridSize); - m_dirty = true; - } - - float BillboardComponentController::GetSize() const - { - return m_configuration.m_gridSize; - } - void BillboardComponentController::OnBeginPrepareRender() { diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h index 84afe59..e75c4a8 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h @@ -52,10 +52,6 @@ namespace AZ private: AZ_DISABLE_COPY(BillboardComponentController); - //! BillboardComponentRequestBus overrides... - void SetSize(float size) override; - float GetSize() const override; - //! AZ::TransformNotificationBus::Handler overrides ... void OnTransformChanged(const Transform& local, const Transform& world) override; diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp index 7417b77..3b3fc92 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp @@ -49,10 +49,6 @@ namespace AZ "BillboardComponentConfig", "") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::AutoExpand, true) - ->DataElement(AZ::Edit::UIHandlers::Default, &BillboardComponentConfig::m_gridSize, "Grid Size", "Grid width and depth") - ->Attribute(AZ::Edit::Attributes::Min, BillboardComponentController::MinGridSize) - ->Attribute(AZ::Edit::Attributes::Max, BillboardComponentController::MaxGridSize) - ->Attribute(AZ::Edit::Attributes::Suffix, " m") ; } } From 7e003c49e68c4d2307bf9668d970ea0366f6b730 Mon Sep 17 00:00:00 2001 From: Judy Ng Date: Wed, 10 Aug 2022 10:14:05 -0700 Subject: [PATCH 08/12] Get rid of more grid component stuff Signed-off-by: Judy Ng --- .../Billboard/BillboardComponentBus.h | 2 - .../Billboard/BillboardComponentConfig.h | 9 -- .../BillboardComponentController.cpp | 90 ++----------------- .../Billboard/BillboardComponentController.h | 6 -- 4 files changed, 5 insertions(+), 102 deletions(-) diff --git a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h index ac58725..1acbb69 100644 --- a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h +++ b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h @@ -27,8 +27,6 @@ namespace AZ class BillboardComponentNotifications : public ComponentBus { public: - //! Notify any handlers that the grid has been modified - virtual void OnGridChanged(){}; }; using BillboardComponentNotificationBus = EBus; diff --git a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentConfig.h b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentConfig.h index f356cb9..3a9a1ae 100644 --- a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentConfig.h +++ b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentConfig.h @@ -24,15 +24,6 @@ namespace AZ AZ_CLASS_ALLOCATOR(BillboardComponentConfig, SystemAllocator, 0); static void Reflect(ReflectContext* context); - - float m_gridSize = 32.0f; - AZ::Color m_axisColor = AZ::Color(0.0f, 0.0f, 1.0f, 1.0f); - - float m_primarySpacing = 1.0f; - AZ::Color m_primaryColor = AZ::Color(0.25f, 0.25f, 0.25f, 1.0f); - - float m_secondarySpacing = 0.25f; - AZ::Color m_secondaryColor = AZ::Color(0.5f, 0.5f, 0.5f, 1.0f); }; } // namespace Render } // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp index 3a9d449..321ac19 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp @@ -58,7 +58,6 @@ namespace AZ { const AZ::EntityId entityId = entityComponentIdPair.GetEntityId(); m_entityComponentIdPair = entityComponentIdPair; - m_dirty = true; RPI::Scene* scene = RPI::Scene::GetSceneForEntityId(entityId); if (scene) @@ -69,20 +68,14 @@ namespace AZ BillboardComponentRequestBus::Handler::BusConnect(entityId); AZ::TransformNotificationBus::Handler::BusConnect(entityId); - AzFramework::EntityContextId contextId = AzFramework::EntityContextId::CreateNull(); - AzFramework::EntityIdContextQueryBus::EventResult( - contextId, entityId, &AzFramework::EntityIdContextQueries::GetOwningContextId); - m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(entityId); AZ_Assert(m_meshFeatureProcessor, "MeshFeatureProcessor not available."); AZ::Data::Asset materialAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath("assets/explosion.azmaterial", AZ::RPI::AssetUtils::TraceLevel::Error); m_material = AZ::RPI::Material::FindOrCreate(materialAsset); m_modelAsset = AZ::RPI::AssetUtils::GetAssetByProductPath("materialeditor/viewportmodels/plane_1x1.azmodel", AZ::RPI::AssetUtils::TraceLevel::Assert); - auto meshDescriptor = AZ::Render::MeshHandleDescriptor{ m_modelAsset }; + m_meshHandle = m_meshFeatureProcessor->AcquireMesh(AZ::Render::MeshHandleDescriptor{ m_modelAsset }, m_material); - m_meshHandle = m_meshFeatureProcessor->AcquireMesh(meshDescriptor, m_material); - m_meshFeatureProcessor->SetTransform(m_meshHandle, AZ::Transform::CreateIdentity()); } @@ -105,7 +98,6 @@ namespace AZ void BillboardComponentController::SetConfiguration(const BillboardComponentConfig& config) { m_configuration = config; - m_dirty = true; } const BillboardComponentConfig& BillboardComponentController::GetConfiguration() const @@ -116,107 +108,35 @@ namespace AZ void BillboardComponentController::OnBeginPrepareRender() { - if (m_configuration.m_gridSize <= 0.0f) - { - return; - } - m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(m_entityComponentIdPair.GetEntityId()); if (!m_meshFeatureProcessor) { return; } - auto* auxGeomFP = AZ::RPI::Scene::GetFeatureProcessorForEntity(m_entityComponentIdPair.GetEntityId()); - if (!auxGeomFP) - { - return; - } - - if (auto auxGeom = auxGeomFP->GetDrawQueue()) - { - BuildGrid(); - - /* - AZ::RPI::AuxGeomDraw::AuxGeomDynamicDrawArguments drawArgs; - drawArgs.m_verts = m_axisGridPoints.data(); - drawArgs.m_vertCount = aznumeric_cast(m_axisGridPoints.size()); - drawArgs.m_colors = &m_configuration.m_axisColor; - auxGeom->DrawLines(drawArgs);*/ - } + BuildGrid(); } void BillboardComponentController::OnTransformChanged(const Transform& local, const Transform& world) { AZ_UNUSED(local); AZ_UNUSED(world); - m_dirty = true; - - if (m_meshFeatureProcessor) - { - /*AZ::Transform transf = world; - transf.SetTranslation(AZ::Vector3(world.GetTranslation().GetX() + 1, world.GetTranslation().GetY() + 1, world.GetTranslation().GetZ() + 1)); - m_meshFeatureProcessor->SetTransform(m_meshHandle, transf); - AzFramework::RenderGeometry::IntersectionNotificationBus::Event( - m_intersectionNotificationBus, &AzFramework::RenderGeometry::IntersectionNotificationBus::Events::OnGeometryChanged, - m_entityComponentIdPair.GetEntityId());*/ - } + + BuildGrid(); } void BillboardComponentController::BuildGrid() { EntityId cam; Camera::CameraSystemRequestBus::BroadcastResult(cam, &Camera::CameraSystemRequests::GetActiveCamera); - AZ::Vector3 cameraWorldPosition; AZ::TransformBus::EventResult(cameraWorldPosition, cam, &AZ::TransformBus::Events::GetWorldTranslation); - - AZ::Vector3 myPosition; AZ::TransformBus::EventResult(myPosition, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation); - AZ::Transform myTransform; - AZ::TransformBus::EventResult(myTransform, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTM); - /* - const float halfLength = m_configuration.m_gridSize / 2.0f; - - // From camera POV, the forward axis is Z positive, even though O3DE's default is Y positive for forward axis. - AZ::Transform tf = AZ::Transform::CreateLookAt(cameraWorldPosition, myPosition, AZ::Transform::Axis::ZPositive); - AZ::Matrix3x4 viewMatrix = AZ::Matrix3x4::CreateFromTransform(tf);*/ - - //AZ::Transform curT = m_meshFeatureProcessor->GetTransform(m_meshHandle); - //AZ::Transform transf = AZ::Transform::CreateLookAt(cameraWorldPosition, myPosition, AZ::Transform::Axis::ZPositive); + // From mesh POV, the forward axis is Z positive, even though O3DE's default is Y positive for forward axis. AZ::Transform tf = AZ::Transform::CreateLookAt(myPosition, cameraWorldPosition, AZ::Transform::Axis::ZPositive); m_meshFeatureProcessor->SetTransform(m_meshHandle, tf); - - /* - AZ::Vector3 cameraRight = AZ::Vector3(viewMatrix(0, 0), viewMatrix(1, 0), viewMatrix(2, 0)); - AZ::Vector3 cameraUp = AZ::Vector3(viewMatrix(0, 1), viewMatrix(1, 1), viewMatrix(2, 1)); - - AZ::Vector3 p0_world = myPosition + cameraRight * halfLength + cameraUp * halfLength; // top right - AZ::Vector3 p1_world = myPosition + cameraRight * halfLength - cameraUp * halfLength; // bottom right - AZ::Vector3 p2_world = myPosition - cameraRight * halfLength - cameraUp * halfLength; // bottom left - AZ::Vector3 p3_world = myPosition - cameraRight * halfLength + cameraUp * halfLength; // top left*/ - - /* - // Make lines - m_axisGridPoints.clear(); - m_axisGridPoints.reserve(8); - // Right - m_axisGridPoints.push_back(p0_world); - m_axisGridPoints.push_back(p1_world); - // Bottom - m_axisGridPoints.push_back(p1_world); - m_axisGridPoints.push_back(p2_world); - // Left - m_axisGridPoints.push_back(p2_world); - m_axisGridPoints.push_back(p3_world); - // Top - m_axisGridPoints.push_back(p3_world); - m_axisGridPoints.push_back(p0_world);*/ - - - BillboardComponentNotificationBus::Event(m_entityComponentIdPair.GetEntityId(), &BillboardComponentNotificationBus::Events::OnGridChanged); } } // namespace Render } // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h index e75c4a8..8de452c 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h @@ -45,10 +45,6 @@ namespace AZ void SetConfiguration(const BillboardComponentConfig& config); const BillboardComponentConfig& GetConfiguration() const; - static constexpr float MinGridSize = 0.0f; - static constexpr float MaxGridSize = 1000000.0f; - static constexpr float MinSpacing = 0.01f; - private: AZ_DISABLE_COPY(BillboardComponentController); @@ -61,8 +57,6 @@ namespace AZ void BuildGrid(); BillboardComponentConfig m_configuration; - AZStd::vector m_axisGridPoints; - bool m_dirty = true; // must be set to true for any configuration change that rebuilds the grid AZ::Render::MeshFeatureProcessorInterface* m_meshFeatureProcessor; From 0b285a2942800763b3773cb4e78865596f2aee98 Mon Sep 17 00:00:00 2001 From: Judy Ng Date: Thu, 11 Aug 2022 00:04:22 -0700 Subject: [PATCH 09/12] add template code, polish final Signed-off-by: Judy Ng --- .../Billboard/BillboardComponentBus.h | 3 +- .../BillboardComponentController.cpp | 22 ++-- .../Billboard/BillboardComponentController.h | 2 +- .../Billboard/Include/BillboardComponentBus.h | 34 ++++++ .../Include/BillboardComponentConfig.h | 29 +++++ .../Include/BillboardComponentConstants.h | 18 +++ .../Billboard/Source/BillboardComponent.cpp | 42 +++++++ .../Billboard/Source/BillboardComponent.h | 33 ++++++ .../Source/BillboardComponentConfig.cpp | 26 +++++ .../Source/BillboardComponentController.cpp | 108 ++++++++++++++++++ .../Source/BillboardComponentController.h | 70 ++++++++++++ .../Source/EditorBillboardComponent.cpp | 72 ++++++++++++ .../Source/EditorBillboardComponent.h | 34 ++++++ 13 files changed, 478 insertions(+), 15 deletions(-) create mode 100644 atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentBus.h create mode 100644 atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentConfig.h create mode 100644 atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentConstants.h create mode 100644 atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponent.cpp create mode 100644 atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponent.h create mode 100644 atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentConfig.cpp create mode 100644 atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.cpp create mode 100644 atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.h create mode 100644 atom_gems/AtomTutorials/Templates/Billboard/Source/EditorBillboardComponent.cpp create mode 100644 atom_gems/AtomTutorials/Templates/Billboard/Source/EditorBillboardComponent.h diff --git a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h index 1acbb69..d7496e9 100644 --- a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h +++ b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h @@ -15,7 +15,7 @@ namespace AZ { namespace Render { - //! GridComponentRequestBus declares an interface for configuring and interacting with the grid component + //! BillboardComponentRequestBus declares an interface for configuring and interacting with the billboard component class BillboardComponentRequests : public ComponentBus { public: @@ -23,7 +23,6 @@ namespace AZ using BillboardComponentRequestBus = EBus; - //! BillboardComponentNotificationBus notifications are triggered whenever the grid changes class BillboardComponentNotifications : public ComponentBus { public: diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp index 321ac19..80ce9df 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp @@ -6,8 +6,6 @@ * */ -#include -#include #include #include #include @@ -71,7 +69,7 @@ namespace AZ m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(entityId); AZ_Assert(m_meshFeatureProcessor, "MeshFeatureProcessor not available."); - AZ::Data::Asset materialAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath("assets/explosion.azmaterial", AZ::RPI::AssetUtils::TraceLevel::Error); + AZ::Data::Asset materialAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath("materials/presets/pbr/metal_gold.azmaterial", AZ::RPI::AssetUtils::TraceLevel::Error); m_material = AZ::RPI::Material::FindOrCreate(materialAsset); m_modelAsset = AZ::RPI::AssetUtils::GetAssetByProductPath("materialeditor/viewportmodels/plane_1x1.azmodel", AZ::RPI::AssetUtils::TraceLevel::Assert); m_meshHandle = m_meshFeatureProcessor->AcquireMesh(AZ::Render::MeshHandleDescriptor{ m_modelAsset }, m_material); @@ -113,7 +111,7 @@ namespace AZ return; } - BuildGrid(); + SetBillboardTransform(); } void BillboardComponentController::OnTransformChanged(const Transform& local, const Transform& world) @@ -121,21 +119,21 @@ namespace AZ AZ_UNUSED(local); AZ_UNUSED(world); - BuildGrid(); + SetBillboardTransform(); } - void BillboardComponentController::BuildGrid() + void BillboardComponentController::SetBillboardTransform() { - EntityId cam; - Camera::CameraSystemRequestBus::BroadcastResult(cam, &Camera::CameraSystemRequests::GetActiveCamera); + EntityId cameraId; + Camera::CameraSystemRequestBus::BroadcastResult(cameraId, &Camera::CameraSystemRequests::GetActiveCamera); AZ::Vector3 cameraWorldPosition; - AZ::TransformBus::EventResult(cameraWorldPosition, cam, &AZ::TransformBus::Events::GetWorldTranslation); + AZ::TransformBus::EventResult(cameraWorldPosition, cameraId, &AZ::TransformBus::Events::GetWorldTranslation); - AZ::Vector3 myPosition; - AZ::TransformBus::EventResult(myPosition, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation); + AZ::Vector3 entityWorldPosition; + AZ::TransformBus::EventResult(entityWorldPosition, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation); // From mesh POV, the forward axis is Z positive, even though O3DE's default is Y positive for forward axis. - AZ::Transform tf = AZ::Transform::CreateLookAt(myPosition, cameraWorldPosition, AZ::Transform::Axis::ZPositive); + AZ::Transform tf = AZ::Transform::CreateLookAt(entityWorldPosition, cameraWorldPosition, AZ::Transform::Axis::ZPositive); m_meshFeatureProcessor->SetTransform(m_meshHandle, tf); } } // namespace Render diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h index 8de452c..c33bb72 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h @@ -54,7 +54,7 @@ namespace AZ // AZ::RPI::SceneNotificationBus::Handler overrides ... void OnBeginPrepareRender() override; - void BuildGrid(); + void SetBillboardTransform(); BillboardComponentConfig m_configuration; diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentBus.h b/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentBus.h new file mode 100644 index 0000000..d7496e9 --- /dev/null +++ b/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentBus.h @@ -0,0 +1,34 @@ +/* + * 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 + * + */ + +#pragma once + +#include +#include + +namespace AZ +{ + namespace Render + { + //! BillboardComponentRequestBus declares an interface for configuring and interacting with the billboard component + class BillboardComponentRequests : public ComponentBus + { + public: + }; + + using BillboardComponentRequestBus = EBus; + + class BillboardComponentNotifications : public ComponentBus + { + public: + }; + + using BillboardComponentNotificationBus = EBus; + + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentConfig.h b/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentConfig.h new file mode 100644 index 0000000..3a9a1ae --- /dev/null +++ b/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentConfig.h @@ -0,0 +1,29 @@ +/* + * 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 + * + */ + +#pragma once + +#include +#include + +namespace AZ +{ + namespace Render + { + //! Common settings for GridComponents and EditorGridComponent. + class BillboardComponentConfig final + : public ComponentConfig + { + public: + AZ_RTTI(BillboardComponentConfig, "{864A9EB9-0ABB-47B0-AA2A-4E96840C8FD9}", ComponentConfig); + AZ_CLASS_ALLOCATOR(BillboardComponentConfig, SystemAllocator, 0); + + static void Reflect(ReflectContext* context); + }; + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentConstants.h b/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentConstants.h new file mode 100644 index 0000000..fc3f246 --- /dev/null +++ b/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentConstants.h @@ -0,0 +1,18 @@ +/* + * 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 + * + */ + +#pragma once + +namespace AZ +{ + namespace Render + { + static constexpr const char* const BillboardComponentTypeId = "{15305641-513D-40FF-9F73-1707869CC96E}"; + static constexpr const char* const EditorBillboardComponentTypeId = "{D4205908-B206-4488-9381-A148D81F52E7}"; + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponent.cpp b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponent.cpp new file mode 100644 index 0000000..beab1ae --- /dev/null +++ b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponent.cpp @@ -0,0 +1,42 @@ +/* + * 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 +#include + +namespace AZ +{ + namespace Render + { + BillboardComponent::BillboardComponent(const BillboardComponentConfig& config) + : BaseClass(config) + { + } + + void BillboardComponent::Reflect(AZ::ReflectContext* context) + { + BaseClass::Reflect(context); + + if (auto serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(0) + ; + } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->Class()->RequestBus("BillboardComponentRequestBus"); + + behaviorContext->ConstantProperty("BillboardComponentTypeId", BehaviorConstant(Uuid(BillboardComponentTypeId))) + ->Attribute(AZ::Script::Attributes::Module, "render") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common); + } + } + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponent.h b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponent.h new file mode 100644 index 0000000..8229419 --- /dev/null +++ b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponent.h @@ -0,0 +1,33 @@ +/* + * 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 + * + */ + +#pragma once + +#include +#include +#include + +namespace AZ +{ + namespace Render + { + class BillboardComponent final + : public AzFramework::Components::ComponentAdapter + { + public: + + using BaseClass = AzFramework::Components::ComponentAdapter; + AZ_COMPONENT(AZ::Render::BillboardComponent, BillboardComponentTypeId, BaseClass); + + BillboardComponent() = default; + BillboardComponent(const BillboardComponentConfig& config); + + static void Reflect(AZ::ReflectContext* context); + }; + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentConfig.cpp b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentConfig.cpp new file mode 100644 index 0000000..56fd317 --- /dev/null +++ b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentConfig.cpp @@ -0,0 +1,26 @@ +/* + * 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 +#include + +namespace AZ +{ + namespace Render + { + void BillboardComponentConfig::Reflect(ReflectContext* context) + { + if (AZ::SerializeContext* serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(0) + ; + } + } + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.cpp new file mode 100644 index 0000000..26273e1 --- /dev/null +++ b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.cpp @@ -0,0 +1,108 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +namespace AZ +{ + namespace Render + { + void BillboardComponentController::Reflect(ReflectContext* context) + { + BillboardComponentConfig::Reflect(context); + + if (SerializeContext* serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(0) + ->Field("Configuration", &BillboardComponentController::m_configuration) + ; + } + + if (AZ::BehaviorContext* behaviorContext = azrtti_cast(context)) + { + behaviorContext->EBus("BillboardComponentRequestBus") + ; + } + } + + void BillboardComponentController::GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided) + { + provided.push_back(AZ_CRC_CE("BillboardService")); + } + + void BillboardComponentController::GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible) + { + incompatible.push_back(AZ_CRC_CE("BillboardService")); + } + + BillboardComponentController::BillboardComponentController(const BillboardComponentConfig& config) + : m_configuration(config) + { + } + + void BillboardComponentController::Activate(const AZ::EntityComponentIdPair& entityComponentIdPair) + { + const AZ::EntityId entityId = entityComponentIdPair.GetEntityId(); + m_entityComponentIdPair = entityComponentIdPair; + + RPI::Scene* scene = RPI::Scene::GetSceneForEntityId(entityId); + if (scene) + { + AZ::RPI::SceneNotificationBus::Handler::BusConnect(scene->GetId()); + } + } + + void BillboardComponentController::Deactivate() + { + AZ::RPI::SceneNotificationBus::Handler::BusDisconnect(); + + m_entityComponentIdPair = AZ::EntityComponentIdPair(AZ::EntityId(), AZ::InvalidComponentId); + } + + void BillboardComponentController::SetConfiguration(const BillboardComponentConfig& config) + { + m_configuration = config; + } + + const BillboardComponentConfig& BillboardComponentController::GetConfiguration() const + { + return m_configuration; + } + + + void BillboardComponentController::OnBeginPrepareRender() + { + m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(m_entityComponentIdPair.GetEntityId()); + if (!m_meshFeatureProcessor) { + return; + } + + SetBillboardTransform(); + } + + void BillboardComponentController::OnTransformChanged(const Transform& local, const Transform& world) + { + AZ_UNUSED(local); + AZ_UNUSED(world); + + SetBillboardTransform(); + } + + void BillboardComponentController::SetBillboardTransform() + { + + } + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.h b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.h new file mode 100644 index 0000000..c33bb72 --- /dev/null +++ b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.h @@ -0,0 +1,70 @@ +/* + * 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 + * + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace AZ +{ + namespace Render + { + //! Controls behavior and rendering of a wireframe Billboard + class BillboardComponentController final + : public BillboardComponentRequestBus::Handler + , public AZ::TransformNotificationBus::Handler + , public AZ::RPI::SceneNotificationBus::Handler + { + public: + friend class EditorBillboardComponent; + + AZ_CLASS_ALLOCATOR(BillboardComponentController, SystemAllocator, 0) + AZ_RTTI(AZ::Render::BillboardComponentController, "{A0288BD7-B660-47B6-88D7-57E7C4F92FEK}"); + + static void Reflect(ReflectContext* context); + static void GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided); + static void GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible); + + BillboardComponentController() = default; + BillboardComponentController(const BillboardComponentConfig& config); + + void Activate(const AZ::EntityComponentIdPair& entityComponentIdPair); + void Deactivate(); + void SetConfiguration(const BillboardComponentConfig& config); + const BillboardComponentConfig& GetConfiguration() const; + + private: + AZ_DISABLE_COPY(BillboardComponentController); + + //! AZ::TransformNotificationBus::Handler overrides ... + void OnTransformChanged(const Transform& local, const Transform& world) override; + + // AZ::RPI::SceneNotificationBus::Handler overrides ... + void OnBeginPrepareRender() override; + + void SetBillboardTransform(); + + BillboardComponentConfig m_configuration; + + AZ::Render::MeshFeatureProcessorInterface* m_meshFeatureProcessor; + + AZ::Data::Asset m_modelAsset; + AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle; + AZ::Data::Instance m_material; + + AZ::EntityComponentIdPair m_entityComponentIdPair; + }; + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Source/EditorBillboardComponent.cpp b/atom_gems/AtomTutorials/Templates/Billboard/Source/EditorBillboardComponent.cpp new file mode 100644 index 0000000..3b3fc92 --- /dev/null +++ b/atom_gems/AtomTutorials/Templates/Billboard/Source/EditorBillboardComponent.cpp @@ -0,0 +1,72 @@ +/* + * 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 +#include +#include +#include + +namespace AZ +{ + namespace Render + { + void EditorBillboardComponent::Reflect(AZ::ReflectContext* context) + { + BaseClass::Reflect(context); + + if (AZ::SerializeContext* serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(1, ConvertToEditorRenderComponentAdapter<1>); + + if (AZ::EditContext* editContext = serializeContext->GetEditContext()) + { + editContext->Class( + "Billboard", "Adds grid to the scene") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::Category, "AtomTutorials") + ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Component_Placeholder.svg") + ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Component_Placeholder.svg") + ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c)) + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://o3de.org/docs/user-guide/components/reference/atom/grid/") + ; + + editContext->Class( + "BillboardComponentController", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &BillboardComponentController::m_configuration, "Configuration", "") + ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly) + ; + + editContext->Class( + "BillboardComponentConfig", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ; + } + } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->Class()->RequestBus("BillboardComponentRequestBus"); + + behaviorContext->ConstantProperty("EditorBillboardComponentTypeId", BehaviorConstant(Uuid(EditorBillboardComponentTypeId))) + ->Attribute(AZ::Script::Attributes::Module, "render") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation); + } + } + + EditorBillboardComponent::EditorBillboardComponent(const BillboardComponentConfig& config) + : BaseClass(config) + { + } + + } // namespace Render +} // namespace AZ diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Source/EditorBillboardComponent.h b/atom_gems/AtomTutorials/Templates/Billboard/Source/EditorBillboardComponent.h new file mode 100644 index 0000000..b4cd028 --- /dev/null +++ b/atom_gems/AtomTutorials/Templates/Billboard/Source/EditorBillboardComponent.h @@ -0,0 +1,34 @@ +/* + * 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 + * + */ + +#pragma once + +#include +#include +#include +#include + +namespace AZ +{ + namespace Render + { + //! In-editor grid component + class EditorBillboardComponent final + : public EditorRenderComponentAdapter + { + public: + using BaseClass = EditorRenderComponentAdapter; + AZ_EDITOR_COMPONENT(AZ::Render::EditorBillboardComponent, EditorBillboardComponentTypeId, BaseClass); + + static void Reflect(AZ::ReflectContext* context); + + EditorBillboardComponent() = default; + EditorBillboardComponent(const BillboardComponentConfig& config); + }; + } // namespace Render +} // namespace AZ From ebb1dfe778d4e7a59be2e4d0379f4b292c51ede2 Mon Sep 17 00:00:00 2001 From: Judy Ng Date: Fri, 12 Aug 2022 02:19:03 -0700 Subject: [PATCH 10/12] Changes for tutorial Signed-off-by: Judy Ng --- .../BillboardComponentController.cpp | 39 +++++++++++-------- .../Billboard/EditorBillboardComponent.cpp | 4 +- .../Source/BillboardComponentController.cpp | 16 +------- .../Source/EditorBillboardComponent.cpp | 4 +- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp index 80ce9df..0b86571 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp @@ -57,13 +57,14 @@ namespace AZ const AZ::EntityId entityId = entityComponentIdPair.GetEntityId(); m_entityComponentIdPair = entityComponentIdPair; + BillboardComponentRequestBus::Handler::BusConnect(entityId); + RPI::Scene* scene = RPI::Scene::GetSceneForEntityId(entityId); if (scene) { AZ::RPI::SceneNotificationBus::Handler::BusConnect(scene->GetId()); } - BillboardComponentRequestBus::Handler::BusConnect(entityId); AZ::TransformNotificationBus::Handler::BusConnect(entityId); m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(entityId); @@ -74,23 +75,27 @@ namespace AZ m_modelAsset = AZ::RPI::AssetUtils::GetAssetByProductPath("materialeditor/viewportmodels/plane_1x1.azmodel", AZ::RPI::AssetUtils::TraceLevel::Assert); m_meshHandle = m_meshFeatureProcessor->AcquireMesh(AZ::Render::MeshHandleDescriptor{ m_modelAsset }, m_material); - m_meshFeatureProcessor->SetTransform(m_meshHandle, AZ::Transform::CreateIdentity()); + AZ::Transform entityTransform; + AZ::TransformBus::EventResult(entityTransform, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTM); + + m_meshFeatureProcessor->SetTransform(m_meshHandle, entityTransform); } void BillboardComponentController::Deactivate() { + AZ::TransformNotificationBus::Handler::BusDisconnect(); + AZ::RPI::SceneNotificationBus::Handler::BusDisconnect(); + BillboardComponentRequestBus::Handler::BusDisconnect(); + if (m_meshFeatureProcessor && m_meshHandle.IsValid()) { m_meshFeatureProcessor->ReleaseMesh(m_meshHandle); } - AZ::TransformNotificationBus::Handler::BusDisconnect(); - BillboardComponentRequestBus::Handler::BusDisconnect(); - AZ::RPI::SceneNotificationBus::Handler::BusDisconnect(); - m_meshFeatureProcessor = nullptr; - m_entityComponentIdPair = AZ::EntityComponentIdPair(AZ::EntityId(), AZ::InvalidComponentId); m_modelAsset.Release(); + + m_entityComponentIdPair = AZ::EntityComponentIdPair(AZ::EntityId(), AZ::InvalidComponentId); } void BillboardComponentController::SetConfiguration(const BillboardComponentConfig& config) @@ -106,11 +111,6 @@ namespace AZ void BillboardComponentController::OnBeginPrepareRender() { - m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(m_entityComponentIdPair.GetEntityId()); - if (!m_meshFeatureProcessor) { - return; - } - SetBillboardTransform(); } @@ -124,17 +124,22 @@ namespace AZ void BillboardComponentController::SetBillboardTransform() { + m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(m_entityComponentIdPair.GetEntityId()); + if (!m_meshFeatureProcessor) { + return; + } + + AZ::Vector3 entityWorldPosition; + AZ::TransformBus::EventResult(entityWorldPosition, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation); + EntityId cameraId; Camera::CameraSystemRequestBus::BroadcastResult(cameraId, &Camera::CameraSystemRequests::GetActiveCamera); AZ::Vector3 cameraWorldPosition; AZ::TransformBus::EventResult(cameraWorldPosition, cameraId, &AZ::TransformBus::Events::GetWorldTranslation); - AZ::Vector3 entityWorldPosition; - AZ::TransformBus::EventResult(entityWorldPosition, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation); - // From mesh POV, the forward axis is Z positive, even though O3DE's default is Y positive for forward axis. - AZ::Transform tf = AZ::Transform::CreateLookAt(entityWorldPosition, cameraWorldPosition, AZ::Transform::Axis::ZPositive); - m_meshFeatureProcessor->SetTransform(m_meshHandle, tf); + AZ::Transform transform = AZ::Transform::CreateLookAt(entityWorldPosition, cameraWorldPosition, AZ::Transform::Axis::ZPositive); + m_meshFeatureProcessor->SetTransform(m_meshHandle, transform); } } // namespace Render } // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp index 3b3fc92..1299fa1 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/EditorBillboardComponent.cpp @@ -27,14 +27,14 @@ namespace AZ if (AZ::EditContext* editContext = serializeContext->GetEditContext()) { editContext->Class( - "Billboard", "Adds grid to the scene") + "Billboard", "Adds billboard to the scene") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::Category, "AtomTutorials") ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Component_Placeholder.svg") ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Component_Placeholder.svg") ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c)) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) - ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://o3de.org/docs/user-guide/components/reference/atom/grid/") + ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://o3de.org/docs/") ; editContext->Class( diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.cpp index 26273e1..e0cc3ca 100644 --- a/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.cpp @@ -57,16 +57,12 @@ namespace AZ const AZ::EntityId entityId = entityComponentIdPair.GetEntityId(); m_entityComponentIdPair = entityComponentIdPair; - RPI::Scene* scene = RPI::Scene::GetSceneForEntityId(entityId); - if (scene) - { - AZ::RPI::SceneNotificationBus::Handler::BusConnect(scene->GetId()); - } + BillboardComponentRequestBus::Handler::BusConnect(entityId); } void BillboardComponentController::Deactivate() { - AZ::RPI::SceneNotificationBus::Handler::BusDisconnect(); + BillboardComponentRequestBus::Handler::BusDisconnect(); m_entityComponentIdPair = AZ::EntityComponentIdPair(AZ::EntityId(), AZ::InvalidComponentId); } @@ -84,20 +80,12 @@ namespace AZ void BillboardComponentController::OnBeginPrepareRender() { - m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(m_entityComponentIdPair.GetEntityId()); - if (!m_meshFeatureProcessor) { - return; - } - - SetBillboardTransform(); } void BillboardComponentController::OnTransformChanged(const Transform& local, const Transform& world) { AZ_UNUSED(local); AZ_UNUSED(world); - - SetBillboardTransform(); } void BillboardComponentController::SetBillboardTransform() diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Source/EditorBillboardComponent.cpp b/atom_gems/AtomTutorials/Templates/Billboard/Source/EditorBillboardComponent.cpp index 3b3fc92..1299fa1 100644 --- a/atom_gems/AtomTutorials/Templates/Billboard/Source/EditorBillboardComponent.cpp +++ b/atom_gems/AtomTutorials/Templates/Billboard/Source/EditorBillboardComponent.cpp @@ -27,14 +27,14 @@ namespace AZ if (AZ::EditContext* editContext = serializeContext->GetEditContext()) { editContext->Class( - "Billboard", "Adds grid to the scene") + "Billboard", "Adds billboard to the scene") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::Category, "AtomTutorials") ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Component_Placeholder.svg") ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Component_Placeholder.svg") ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c)) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) - ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://o3de.org/docs/user-guide/components/reference/atom/grid/") + ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://o3de.org/docs/") ; editContext->Class( From e8aa3bbb63aae61bcf2dc8f5c6ea77e6708534da Mon Sep 17 00:00:00 2001 From: Judy Ng Date: Fri, 12 Aug 2022 10:30:31 -0700 Subject: [PATCH 11/12] Fix previous weirdness Signed-off-by: Judy Ng --- .../Billboard/BillboardComponentBus.h | 5 ++- .../BillboardComponentController.cpp | 34 ++++++------------- .../Billboard/BillboardComponentController.h | 4 --- .../Billboard/Include/BillboardComponentBus.h | 5 ++- .../Source/BillboardComponentController.cpp | 5 --- .../Source/BillboardComponentController.h | 4 --- 6 files changed, 19 insertions(+), 38 deletions(-) diff --git a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h index d7496e9..6e175f4 100644 --- a/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h +++ b/atom_gems/AtomTutorials/Code/Include/AtomTutorials/Billboard/BillboardComponentBus.h @@ -15,7 +15,7 @@ namespace AZ { namespace Render { - //! BillboardComponentRequestBus declares an interface for configuring and interacting with the billboard component + //! Billboard ComponentRequestBus declares an interface for configuring and interacting with the billboard component class BillboardComponentRequests : public ComponentBus { public: @@ -23,9 +23,12 @@ namespace AZ using BillboardComponentRequestBus = EBus; + //! BillboardComponentNotificationBus notifications are triggered whenever the billboard changes class BillboardComponentNotifications : public ComponentBus { public: + //! Notify any handlers that the billboard has been modified + virtual void OnBillboardTransformed(){}; }; using BillboardComponentNotificationBus = EBus; diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp index 0b86571..154f019 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp @@ -57,15 +57,13 @@ namespace AZ const AZ::EntityId entityId = entityComponentIdPair.GetEntityId(); m_entityComponentIdPair = entityComponentIdPair; - BillboardComponentRequestBus::Handler::BusConnect(entityId); - RPI::Scene* scene = RPI::Scene::GetSceneForEntityId(entityId); if (scene) { AZ::RPI::SceneNotificationBus::Handler::BusConnect(scene->GetId()); } - AZ::TransformNotificationBus::Handler::BusConnect(entityId); + BillboardComponentRequestBus::Handler::BusConnect(entityId); m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(entityId); AZ_Assert(m_meshFeatureProcessor, "MeshFeatureProcessor not available."); @@ -73,25 +71,22 @@ namespace AZ AZ::Data::Asset materialAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath("materials/presets/pbr/metal_gold.azmaterial", AZ::RPI::AssetUtils::TraceLevel::Error); m_material = AZ::RPI::Material::FindOrCreate(materialAsset); m_modelAsset = AZ::RPI::AssetUtils::GetAssetByProductPath("materialeditor/viewportmodels/plane_1x1.azmodel", AZ::RPI::AssetUtils::TraceLevel::Assert); - m_meshHandle = m_meshFeatureProcessor->AcquireMesh(AZ::Render::MeshHandleDescriptor{ m_modelAsset }, m_material); - - AZ::Transform entityTransform; - AZ::TransformBus::EventResult(entityTransform, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTM); + + auto meshDescriptor = AZ::Render::MeshHandleDescriptor{ m_modelAsset }; + m_meshHandle = m_meshFeatureProcessor->AcquireMesh(meshDescriptor, m_material); - m_meshFeatureProcessor->SetTransform(m_meshHandle, entityTransform); + m_meshFeatureProcessor->SetTransform(m_meshHandle, AZ::Transform::CreateIdentity()); } void BillboardComponentController::Deactivate() { - AZ::TransformNotificationBus::Handler::BusDisconnect(); - AZ::RPI::SceneNotificationBus::Handler::BusDisconnect(); BillboardComponentRequestBus::Handler::BusDisconnect(); + AZ::RPI::SceneNotificationBus::Handler::BusDisconnect(); if (m_meshFeatureProcessor && m_meshHandle.IsValid()) { m_meshFeatureProcessor->ReleaseMesh(m_meshHandle); } - m_meshFeatureProcessor = nullptr; m_modelAsset.Release(); @@ -114,14 +109,6 @@ namespace AZ SetBillboardTransform(); } - void BillboardComponentController::OnTransformChanged(const Transform& local, const Transform& world) - { - AZ_UNUSED(local); - AZ_UNUSED(world); - - SetBillboardTransform(); - } - void BillboardComponentController::SetBillboardTransform() { m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity(m_entityComponentIdPair.GetEntityId()); @@ -129,17 +116,18 @@ namespace AZ return; } - AZ::Vector3 entityWorldPosition; - AZ::TransformBus::EventResult(entityWorldPosition, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation); - EntityId cameraId; Camera::CameraSystemRequestBus::BroadcastResult(cameraId, &Camera::CameraSystemRequests::GetActiveCamera); AZ::Vector3 cameraWorldPosition; AZ::TransformBus::EventResult(cameraWorldPosition, cameraId, &AZ::TransformBus::Events::GetWorldTranslation); - // From mesh POV, the forward axis is Z positive, even though O3DE's default is Y positive for forward axis. + AZ::Vector3 entityWorldPosition; + AZ::TransformBus::EventResult(entityWorldPosition, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation); + AZ::Transform transform = AZ::Transform::CreateLookAt(entityWorldPosition, cameraWorldPosition, AZ::Transform::Axis::ZPositive); m_meshFeatureProcessor->SetTransform(m_meshHandle, transform); + + BillboardComponentNotificationBus::Event(m_entityComponentIdPair.GetEntityId(), &BillboardComponentNotificationBus::Events::OnBillboardTransformed); } } // namespace Render } // namespace AZ diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h index c33bb72..d18a32c 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.h @@ -24,7 +24,6 @@ namespace AZ //! Controls behavior and rendering of a wireframe Billboard class BillboardComponentController final : public BillboardComponentRequestBus::Handler - , public AZ::TransformNotificationBus::Handler , public AZ::RPI::SceneNotificationBus::Handler { public: @@ -48,9 +47,6 @@ namespace AZ private: AZ_DISABLE_COPY(BillboardComponentController); - //! AZ::TransformNotificationBus::Handler overrides ... - void OnTransformChanged(const Transform& local, const Transform& world) override; - // AZ::RPI::SceneNotificationBus::Handler overrides ... void OnBeginPrepareRender() override; diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentBus.h b/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentBus.h index d7496e9..89af84c 100644 --- a/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentBus.h +++ b/atom_gems/AtomTutorials/Templates/Billboard/Include/BillboardComponentBus.h @@ -15,7 +15,7 @@ namespace AZ { namespace Render { - //! BillboardComponentRequestBus declares an interface for configuring and interacting with the billboard component + //! Billboard ComponentRequestBus declares an interface for configuring and interacting with the billboard component class BillboardComponentRequests : public ComponentBus { public: @@ -23,9 +23,12 @@ namespace AZ using BillboardComponentRequestBus = EBus; + //! BillboardComponentNotificationBus notifications are triggered whenever the grid changes class BillboardComponentNotifications : public ComponentBus { public: + //! Notify any handlers that the billboard has been modified + virtual void OnBillboardTransformed(){}; }; using BillboardComponentNotificationBus = EBus; diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.cpp index e0cc3ca..1d2efb2 100644 --- a/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.cpp @@ -80,12 +80,7 @@ namespace AZ void BillboardComponentController::OnBeginPrepareRender() { - } - void BillboardComponentController::OnTransformChanged(const Transform& local, const Transform& world) - { - AZ_UNUSED(local); - AZ_UNUSED(world); } void BillboardComponentController::SetBillboardTransform() diff --git a/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.h b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.h index c33bb72..d18a32c 100644 --- a/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.h +++ b/atom_gems/AtomTutorials/Templates/Billboard/Source/BillboardComponentController.h @@ -24,7 +24,6 @@ namespace AZ //! Controls behavior and rendering of a wireframe Billboard class BillboardComponentController final : public BillboardComponentRequestBus::Handler - , public AZ::TransformNotificationBus::Handler , public AZ::RPI::SceneNotificationBus::Handler { public: @@ -48,9 +47,6 @@ namespace AZ private: AZ_DISABLE_COPY(BillboardComponentController); - //! AZ::TransformNotificationBus::Handler overrides ... - void OnTransformChanged(const Transform& local, const Transform& world) override; - // AZ::RPI::SceneNotificationBus::Handler overrides ... void OnBeginPrepareRender() override; From b78ee8666ab0be3e568519b846e9b815350f87c5 Mon Sep 17 00:00:00 2001 From: Judy Ng Date: Fri, 12 Aug 2022 10:45:52 -0700 Subject: [PATCH 12/12] Add comment Signed-off-by: Judy Ng --- .../Code/Source/Billboard/BillboardComponentController.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp index 154f019..c30d686 100644 --- a/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp +++ b/atom_gems/AtomTutorials/Code/Source/Billboard/BillboardComponentController.cpp @@ -124,6 +124,7 @@ namespace AZ AZ::Vector3 entityWorldPosition; AZ::TransformBus::EventResult(entityWorldPosition, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation); + // From mesh POV, the forward axis is Z positive, even though O3DE's default is Y positive for forward axis AZ::Transform transform = AZ::Transform::CreateLookAt(entityWorldPosition, cameraWorldPosition, AZ::Transform::Axis::ZPositive); m_meshFeatureProcessor->SetTransform(m_meshHandle, transform);