Initial fix for geometry being intersected when not visible (#6473)
* initial fix for geometry being intersected when not visible Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * add tests for shape intersection with helpers enabled/disabled Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * update moved cmake file after merge Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * updates following PR feedback Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
ad8b142230
commit
ea55c6d5e5
@@ -7,8 +7,11 @@
|
||||
*/
|
||||
|
||||
#include "EditorBaseShapeComponent.h"
|
||||
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzToolsFramework/Viewport/ViewportMessages.h>
|
||||
#include <AzToolsFramework/Viewport/ViewportSettings.h>
|
||||
#include <LmbrCentral/Shape/ShapeComponentBus.h>
|
||||
|
||||
namespace LmbrCentral
|
||||
@@ -35,22 +38,28 @@ namespace LmbrCentral
|
||||
->Field("Visible", &EditorBaseShapeComponent::m_visibleInEditor)
|
||||
->Field("GameView", &EditorBaseShapeComponent::m_visibleInGameView)
|
||||
->Field("DisplayFilled", &EditorBaseShapeComponent::m_displayFilled)
|
||||
->Field("ShapeColor", &EditorBaseShapeComponent::m_shapeColor)
|
||||
;
|
||||
->Field("ShapeColor", &EditorBaseShapeComponent::m_shapeColor);
|
||||
|
||||
if (auto editContext = context.GetEditContext())
|
||||
{
|
||||
editContext->Class<EditorBaseShapeComponent>("EditorBaseShapeComponent", "Editor base shape component")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::CheckBox, &EditorBaseShapeComponent::m_visibleInEditor, "Visible", "Always display this shape in the editor viewport")
|
||||
->DataElement(AZ::Edit::UIHandlers::CheckBox, &EditorBaseShapeComponent::m_visibleInGameView, "Game View", "Display the shape while in Game View")
|
||||
->DataElement(AZ::Edit::UIHandlers::CheckBox, &EditorBaseShapeComponent::m_displayFilled, "Filled", "Display the shape as either filled or wireframe") // hidden before selection is resolved
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorBaseShapeComponent::OnDisplayFilledChanged)
|
||||
->DataElement(AZ::Edit::UIHandlers::Default, &EditorBaseShapeComponent::m_shapeColor, "Shape Color", "The color to use when rendering the faces of the shape object")
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorBaseShapeComponent::OnShapeColorChanged)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &EditorBaseShapeComponent::GetShapeColorIsEditable)
|
||||
;
|
||||
->DataElement(
|
||||
AZ::Edit::UIHandlers::CheckBox, &EditorBaseShapeComponent::m_visibleInEditor, "Visible",
|
||||
"Always display this shape in the editor viewport")
|
||||
->DataElement(
|
||||
AZ::Edit::UIHandlers::CheckBox, &EditorBaseShapeComponent::m_visibleInGameView, "Game View",
|
||||
"Display the shape while in Game View")
|
||||
->DataElement(
|
||||
AZ::Edit::UIHandlers::CheckBox, &EditorBaseShapeComponent::m_displayFilled, "Filled",
|
||||
"Display the shape as either filled or wireframe") // hidden before selection is resolved
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorBaseShapeComponent::OnDisplayFilledChanged)
|
||||
->DataElement(
|
||||
AZ::Edit::UIHandlers::Default, &EditorBaseShapeComponent::m_shapeColor, "Shape Color",
|
||||
"The color to use when rendering the faces of the shape object")
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorBaseShapeComponent::OnShapeColorChanged)
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, &EditorBaseShapeComponent::GetShapeColorIsEditable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +93,8 @@ namespace LmbrCentral
|
||||
void EditorBaseShapeComponent::SetShapeColor(const AZ::Color& shapeColor)
|
||||
{
|
||||
m_shapeColor = shapeColor;
|
||||
AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_Values);
|
||||
AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(
|
||||
&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_Values);
|
||||
}
|
||||
|
||||
void EditorBaseShapeComponent::SetShapeWireframeColor(const AZ::Color& wireColor)
|
||||
@@ -97,7 +107,7 @@ namespace LmbrCentral
|
||||
if (m_shapeColorIsEditable != editable)
|
||||
{
|
||||
m_shapeColorIsEditable = editable;
|
||||
|
||||
|
||||
if (editable)
|
||||
{
|
||||
// Restore the color to the value from when it was previously editable.
|
||||
@@ -110,7 +120,8 @@ namespace LmbrCentral
|
||||
}
|
||||
|
||||
// This changes the visibility of a property so a request to refresh the entire tree must be sent.
|
||||
AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_EntireTree);
|
||||
AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(
|
||||
&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_EntireTree);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,15 +140,13 @@ namespace LmbrCentral
|
||||
m_shapeConfig = shapeConfig;
|
||||
}
|
||||
|
||||
AZ::Aabb EditorBaseShapeComponent::GetEditorSelectionBoundsViewport(
|
||||
const AzFramework::ViewportInfo& /*viewportInfo*/)
|
||||
AZ::Aabb EditorBaseShapeComponent::GetEditorSelectionBoundsViewport([[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo)
|
||||
{
|
||||
return GetWorldBounds();
|
||||
}
|
||||
|
||||
bool EditorBaseShapeComponent::EditorSelectionIntersectRayViewport(
|
||||
const AzFramework::ViewportInfo& /*viewportInfo*/,
|
||||
const AZ::Vector3& src, const AZ::Vector3& dir, float& distance)
|
||||
[[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo, const AZ::Vector3& src, const AZ::Vector3& dir, float& distance)
|
||||
{
|
||||
// if we are not drawing this or it is wireframe, do not allow selection
|
||||
if (!CanDraw() || !m_displayFilled)
|
||||
@@ -145,19 +154,33 @@ namespace LmbrCentral
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't intersect with shapes when the camera is inside them
|
||||
// don't intersect with shapes when the camera is inside them
|
||||
bool isInside = false;
|
||||
ShapeComponentRequestsBus::EventResult(isInside, GetEntityId(), &ShapeComponentRequests::IsPointInside, src);
|
||||
if (isInside)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool rayHit = false;
|
||||
ShapeComponentRequestsBus::EventResult(rayHit, GetEntityId(), &ShapeComponentRequests::IntersectRay, src, dir, distance);
|
||||
return rayHit;
|
||||
}
|
||||
|
||||
bool EditorBaseShapeComponent::SupportsEditorRayIntersect()
|
||||
{
|
||||
return AzToolsFramework::HelpersVisible();
|
||||
}
|
||||
|
||||
bool EditorBaseShapeComponent::SupportsEditorRayIntersectViewport(const AzFramework::ViewportInfo& viewportInfo)
|
||||
{
|
||||
bool helpersVisible = false;
|
||||
AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::EventResult(
|
||||
helpersVisible, viewportInfo.m_viewportId,
|
||||
&AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::Events::HelpersVisible);
|
||||
return helpersVisible;
|
||||
}
|
||||
|
||||
void EditorBaseShapeComponent::OnAccentTypeChanged(AzToolsFramework::EntityAccentType accent)
|
||||
{
|
||||
if (accent == AzToolsFramework::EntityAccentType::Hover || IsSelected())
|
||||
@@ -200,8 +223,7 @@ namespace LmbrCentral
|
||||
AZ::Transform unused;
|
||||
AZ::Aabb resultBounds = AZ::Aabb::CreateNull();
|
||||
LmbrCentral::ShapeComponentRequestsBus::Event(
|
||||
GetEntityId(), &LmbrCentral::ShapeComponentRequestsBus::Events::GetTransformAndLocalBounds,
|
||||
unused, resultBounds);
|
||||
GetEntityId(), &LmbrCentral::ShapeComponentRequestsBus::Events::GetTransformAndLocalBounds, unused, resultBounds);
|
||||
return resultBounds;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user