1f9b284de2
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> # Conflicts: # Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h # Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h # Code/Editor/Plugins/EditorCommon/stdafx.cpp # Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h # Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h # Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h # Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h # Code/Tools/AssetProcessor/native/precompiled.h # Code/Tools/Standalone/StandaloneTools_precompiled.h # Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h # Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h # Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h # Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h # Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake # Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h # Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h # Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp # Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake # Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h # Gems/Blast/Code/Source/StdAfx.cpp # Gems/Camera/Code/Source/Camera_precompiled.h # Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h # Gems/FastNoise/Code/Source/FastNoise_precompiled.h # Gems/Gestures/Code/Source/Gestures_precompiled.h # Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h # Gems/GraphCanvas/Code/precompiled.h # Gems/ImGui/Code/Source/ImGui_precompiled.h # Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h # Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h # Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp # Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h # Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h # Gems/LyShine/Code/Source/LyShine_precompiled.h # Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h # Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h # Gems/Maestro/Code/Source/Maestro_precompiled.h # Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h # Gems/Metastream/Code/Source/Metastream_precompiled.h # Gems/Microphone/Code/Source/Microphone_precompiled.h # Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h # Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h # Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h # Gems/PhysX/Code/Source/PhysX_precompiled.h # Gems/PhysX/Code/physx_unsupported_files.cmake # Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h # Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h # Gems/ScriptCanvas/Code/Editor/precompiled.h # Gems/ScriptCanvas/Code/Source/precompiled.h # Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h # Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h # Gems/ScriptEvents/Code/Source/precompiled.h # Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp # Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h # Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h # Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h # Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h # Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h # Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h # Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h # Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h # Gems/Twitch/Code/Source/Twitch_precompiled.h # Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
290 lines
11 KiB
C++
290 lines
11 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
|
|
#include "BoxShapeComponent.h"
|
|
#include <AzCore/RTTI/BehaviorContext.h>
|
|
#include <AzCore/Serialization/EditContext.h>
|
|
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
|
|
#include <Shape/ShapeComponentConverters.h>
|
|
#include <Shape/ShapeDisplay.h>
|
|
|
|
namespace LmbrCentral
|
|
{
|
|
void BoxShapeComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
|
|
{
|
|
provided.push_back(AZ_CRC("ShapeService", 0xe86aa5fe));
|
|
provided.push_back(AZ_CRC("BoxShapeService", 0x946a0032));
|
|
}
|
|
|
|
void BoxShapeComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
|
{
|
|
incompatible.push_back(AZ_CRC("ShapeService", 0xe86aa5fe));
|
|
incompatible.push_back(AZ_CRC("BoxShapeService", 0x946a0032));
|
|
}
|
|
|
|
void BoxShapeComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
|
|
{
|
|
required.push_back(AZ_CRC("TransformService", 0x8ee22c50));
|
|
}
|
|
|
|
void BoxShapeComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
|
|
{
|
|
dependent.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
|
}
|
|
|
|
void BoxShapeDebugDisplayComponent::Reflect(AZ::ReflectContext* context)
|
|
{
|
|
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
|
{
|
|
serializeContext->Class<BoxShapeDebugDisplayComponent, EntityDebugDisplayComponent>()
|
|
->Version(1)
|
|
->Field("Configuration", &BoxShapeDebugDisplayComponent::m_boxShapeConfig)
|
|
;
|
|
}
|
|
}
|
|
|
|
void BoxShapeDebugDisplayComponent::Activate()
|
|
{
|
|
EntityDebugDisplayComponent::Activate();
|
|
ShapeComponentNotificationsBus::Handler::BusConnect(GetEntityId());
|
|
m_nonUniformScale = AZ::Vector3::CreateOne();
|
|
AZ::NonUniformScaleRequestBus::EventResult(m_nonUniformScale, GetEntityId(), &AZ::NonUniformScaleRequests::GetScale);
|
|
}
|
|
|
|
void BoxShapeDebugDisplayComponent::Deactivate()
|
|
{
|
|
ShapeComponentNotificationsBus::Handler::BusDisconnect();
|
|
EntityDebugDisplayComponent::Deactivate();
|
|
}
|
|
|
|
void BoxShapeDebugDisplayComponent::Draw(AzFramework::DebugDisplayRequests& debugDisplay)
|
|
{
|
|
ShapeDrawParams drawParams = g_defaultShapeDrawParams;
|
|
drawParams.m_shapeColor = m_boxShapeConfig.GetDrawColor();
|
|
drawParams.m_filled = m_boxShapeConfig.IsFilled();
|
|
|
|
DrawBoxShape(drawParams, m_boxShapeConfig, debugDisplay, m_nonUniformScale);
|
|
}
|
|
|
|
bool BoxShapeDebugDisplayComponent::ReadInConfig(const AZ::ComponentConfig* baseConfig)
|
|
{
|
|
if (const auto config = azrtti_cast<const BoxShapeConfig*>(baseConfig))
|
|
{
|
|
m_boxShapeConfig = *config;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool BoxShapeDebugDisplayComponent::WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const
|
|
{
|
|
if (auto outConfig = azrtti_cast<BoxShapeConfig*>(outBaseConfig))
|
|
{
|
|
*outConfig = m_boxShapeConfig;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void BoxShapeDebugDisplayComponent::OnShapeChanged(ShapeChangeReasons changeReason)
|
|
{
|
|
if (changeReason == ShapeChangeReasons::ShapeChanged)
|
|
{
|
|
BoxShapeComponentRequestsBus::EventResult(m_boxShapeConfig, GetEntityId(), &BoxShapeComponentRequests::GetBoxConfiguration);
|
|
AZ::NonUniformScaleRequestBus::EventResult(m_nonUniformScale, GetEntityId(), &AZ::NonUniformScaleRequests::GetScale);
|
|
}
|
|
}
|
|
|
|
namespace ClassConverters
|
|
{
|
|
static bool DeprecateBoxColliderConfiguration(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement);
|
|
static bool DeprecateBoxColliderComponent(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement);
|
|
}
|
|
|
|
void BoxShapeConfig::Reflect(AZ::ReflectContext* context)
|
|
{
|
|
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
|
{
|
|
// Deprecate: BoxColliderConfiguration -> BoxShapeConfig
|
|
serializeContext->ClassDeprecate(
|
|
"BoxColliderConfiguration",
|
|
"{282E47CB-9F6D-47AE-A210-4CE879527EFD}",
|
|
&ClassConverters::DeprecateBoxColliderConfiguration)
|
|
;
|
|
|
|
serializeContext->Class<BoxShapeConfig, ShapeComponentConfig>()
|
|
->Version(2)
|
|
->Field("Dimensions", &BoxShapeConfig::m_dimensions)
|
|
;
|
|
|
|
if (auto editContext = serializeContext->GetEditContext())
|
|
{
|
|
editContext->Class<BoxShapeConfig>("Configuration", "Box shape configuration parameters")
|
|
->ClassElement(AZ::Edit::ClassElements::EditorData, "Shape Configuration")
|
|
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
|
->DataElement(AZ::Edit::UIHandlers::Default, &BoxShapeConfig::m_dimensions, "Dimensions", "Dimensions of the box along its axes")
|
|
->Attribute(AZ::Edit::Attributes::Suffix, " m")
|
|
->Attribute(AZ::Edit::Attributes::Step, 0.05f)
|
|
;
|
|
}
|
|
}
|
|
|
|
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
|
{
|
|
behaviorContext->Class<BoxShapeConfig>()
|
|
->Constructor()
|
|
->Constructor<AZ::Vector3&>()
|
|
->Property("Dimensions", BehaviorValueProperty(&BoxShapeConfig::m_dimensions))
|
|
;
|
|
}
|
|
}
|
|
|
|
void BoxShapeComponent::Reflect(AZ::ReflectContext* context)
|
|
{
|
|
BoxShape::Reflect(context);
|
|
|
|
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
|
{
|
|
// Deprecate: BoxColliderComponent -> BoxShapeComponent
|
|
serializeContext->ClassDeprecate(
|
|
"BoxColliderComponent",
|
|
"{C215EB2A-1803-4EDC-B032-F7C92C142337}",
|
|
&ClassConverters::DeprecateBoxColliderComponent)
|
|
;
|
|
|
|
serializeContext->Class<BoxShapeComponent, Component>()
|
|
->Version(2, &ClassConverters::UpgradeBoxShapeComponent)
|
|
->Field("BoxShape", &BoxShapeComponent::m_boxShape)
|
|
;
|
|
}
|
|
|
|
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
|
{
|
|
behaviorContext->Constant("BoxShapeComponentTypeId", BehaviorConstant(BoxShapeComponentTypeId));
|
|
|
|
behaviorContext->EBus<BoxShapeComponentRequestsBus>("BoxShapeComponentRequestsBus")
|
|
->Event("GetBoxConfiguration", &BoxShapeComponentRequestsBus::Events::GetBoxConfiguration)
|
|
->Event("GetBoxDimensions", &BoxShapeComponentRequestsBus::Events::GetBoxDimensions)
|
|
->Event("SetBoxDimensions", &BoxShapeComponentRequestsBus::Events::SetBoxDimensions)
|
|
;
|
|
}
|
|
}
|
|
|
|
void BoxShapeComponent::Activate()
|
|
{
|
|
m_boxShape.Activate(GetEntityId());
|
|
}
|
|
|
|
void BoxShapeComponent::Deactivate()
|
|
{
|
|
m_boxShape.Deactivate();
|
|
}
|
|
|
|
bool BoxShapeComponent::ReadInConfig(const AZ::ComponentConfig* baseConfig)
|
|
{
|
|
if (const auto config = azrtti_cast<const BoxShapeConfig*>(baseConfig))
|
|
{
|
|
m_boxShape.SetBoxConfiguration(*config);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool BoxShapeComponent::WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const
|
|
{
|
|
if (auto config = azrtti_cast<BoxShapeConfig*>(outBaseConfig))
|
|
{
|
|
*config = m_boxShape.GetBoxConfiguration();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
namespace ClassConverters
|
|
{
|
|
static bool DeprecateBoxColliderConfiguration(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement)
|
|
{
|
|
/*
|
|
Old:
|
|
<Class name="BoxColliderConfiguration" field="Configuration" version="1" type="{282E47CB-9F6D-47AE-A210-4CE879527EFD}">
|
|
<Class name="Vector3" field="Size" value="1.0000000 1.0000000 1.0000000" type="{8379EB7D-01FA-4538-B64B-A6543B4BE73D}"/>
|
|
</Class>
|
|
|
|
New:
|
|
<Class name="BoxShapeConfig" field="Configuration" version="1" type="{F034FBA2-AC2F-4E66-8152-14DFB90D6283}">
|
|
<Class name="Vector3" field="Dimensions" value="1.0000000 1.0000000 1.0000000" type="{8379EB7D-01FA-4538-B64B-A6543B4BE73D}"/>
|
|
</Class>
|
|
*/
|
|
|
|
// Cache the Dimensions
|
|
AZ::Vector3 oldDimensions;
|
|
const int oldIndex = classElement.FindElement(AZ_CRC("Size", 0xf7c0246a));
|
|
if (oldIndex != -1)
|
|
{
|
|
classElement.GetSubElement(oldIndex).GetData<AZ::Vector3>(oldDimensions);
|
|
}
|
|
|
|
// Convert to BoxShapeConfig
|
|
const bool result = classElement.Convert(context, "{F034FBA2-AC2F-4E66-8152-14DFB90D6283}");
|
|
if (result)
|
|
{
|
|
const int newIndex = classElement.AddElement<AZ::Vector3>(context, "Dimensions");
|
|
if (newIndex != -1)
|
|
{
|
|
classElement.GetSubElement(newIndex).SetData<AZ::Vector3>(context, oldDimensions);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static bool DeprecateBoxColliderComponent(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement)
|
|
{
|
|
/*
|
|
Old:
|
|
<Class name="BoxColliderComponent" version="1" type="{C215EB2A-1803-4EDC-B032-F7C92C142337}">
|
|
<Class name="BoxColliderConfiguration" field="Configuration" version="1" type="{282E47CB-9F6D-47AE-A210-4CE879527EFD}">
|
|
<Class name="Vector3" field="Size" value="1.0000000 1.0000000 1.0000000" type="{8379EB7D-01FA-4538-B64B-A6543B4BE73D}"/>
|
|
</Class>
|
|
</Class>
|
|
|
|
New:
|
|
<Class name="BoxShapeComponent" version="1" type="{5EDF4B9E-0D3D-40B8-8C91-5142BCFC30A6}">
|
|
<Class name="BoxShapeConfig" field="Configuration" version="1" type="{F034FBA2-AC2F-4E66-8152-14DFB90D6283}">
|
|
<Class name="Vector3" field="Dimensions" value="1.0000000 2.0000000 3.0000000" type="{8379EB7D-01FA-4538-B64B-A6543B4BE73D}"/>
|
|
</Class>
|
|
</Class>
|
|
*/
|
|
|
|
// Cache the Configuration
|
|
BoxShapeConfig configuration;
|
|
int configIndex = classElement.FindElement(AZ_CRC("Configuration", 0xa5e2a5d7));
|
|
if (configIndex != -1)
|
|
{
|
|
classElement.GetSubElement(configIndex).GetData<BoxShapeConfig>(configuration);
|
|
}
|
|
|
|
// Convert to BoxShapeComponent
|
|
const bool result = classElement.Convert(context, BoxShapeComponentTypeId);
|
|
if (result)
|
|
{
|
|
configIndex = classElement.AddElement<BoxShapeConfig>(context, "Configuration");
|
|
if (configIndex != -1)
|
|
{
|
|
classElement.GetSubElement(configIndex).SetData<BoxShapeConfig>(context, configuration);
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
} // namespace ClassConverters
|
|
|
|
} // namespace LmbrCentral
|