56904d1799
* Generic Cleanup Removals: * Unused cvars,member variables and defines * Windows media center edition support routines * CSystem - removed debug_GetCallStackRaw/GetRootWindowMessageHandler/ UnloadDLL/ShutdownModuleLibraries Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Fix CryMessageBox return values in Windows build Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Remove named selection group and a few smaller unused functionalities Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Remove ObjectManager export functionality + 2 deprecated functions Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Remove object legacy freeze/hide support from ObjectManager Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Remove ObjectManager duplicate name dection, as well as object renaming Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Remove ObjectManager serialization and selection callbacks Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * ObjectManager - remove MoveObjects/HitTestObject/EndEditParams and related members/functions Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Remove a bunch of unused clone related functionality + misc Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * ObjectManager - misc removals Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * ObjectManager - more removals Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Remove unused object selection/retrieval in ObjectManager and LoadObjects in ObjectLoader Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * CBaseObject - remove unused material layers mask support Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * More CBaseObject cleanups. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * CBaseObject - remove SubObj functions and IMouseCreateCallback Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Remove unused procedural floor management, helper scale and tags. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * CBaseObject - remove more unused methods. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Removals in multiple places. CBaseObject - unused `OBJTYPE_DUMMY` flag removed, member `IsSameClass` CObjectArchive removed unused methods/members CObjectManager removed unused `Update` method Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * More removals IDisplayViewport - HitTestLine/GetGridStep/setHitcontext/ GetConstructionPlane Unused Cry_Matrix44 template specializations. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * O3DE.exe Project-Centric "Open Editor" fix (#5852) * The O3DE.exe Open Editor button now attempts to open the Editor in the build directory of the project being opened. If their is no Editor within the build directory of the Project, it uses the Editor.exe in the current O3DE.exe executable directory if it exists Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Engine .gitignore now ignores the build directory if placed in the AutomatedTesting project Previously it was just ignoring a `[Bb]uild` directory if it was directly within the engine root. This change matches the behavior of the project templates. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Renamed the ProjectUtils GetEditorDirectory function to GetEditorExecutablePath Added a platform specific implementation for retrieving the path to the Editor executable in the GetEditorExectuablePath function. It first attempts to locate the Editor via checking the project build directory for an Editor executable before falling back to checking the binary directory of the currently running O3DE executable. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Correct the MacOS GetEditorExecutablePath to return the Editor path Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Adding missing C++20 std::erase implementations (#5735) There were already implementations for std::erase_if. This adds the counterpart AZStd::erase versions resolves #5734 Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * More removals and refactors `ShowMessage` and `CryMessageBox` return void now Simplify code in `CSystem::WarningV` Remove unused `CryGetTicksPerSec` Remove unused WinBase functionality Replace `nanosleep` call in WinBase with `std::this_thread::sleep_for` Remove unused Win32Wrapper routines Remove unused IFunctorBase.h and IEntityObjectListener.h Fix VectorAndArray.cpp compilation Use QMessageBox instead of CryMessageBox in the editor. Remove empty ArchiveVars platform specific files Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Fix test code. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Remove an unused function Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * CBaseObject and undo description removals. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * A bunch of removals * Remove IRenderNode * Remove editor's KDTree * Remove StatObjBus, InstanceStatObjEventBus::ReleaseData is redundant ( same functionality in the only available handler is triggered by `OnCryEditorCloseScene`) * Remove CExportManager::AddStatObj/AddMeshes/AddMesh, IExportManager::ExportSingleStatObj * Remove CIconManager/IIconManager::GetObject * Remove CBaseObject::IntersectRayMesh * Remove IIndexedMesh and related structs. * Unused IUndoObject::GetDescription and all derived implementations. * Unused CUndoBaseLibrary/CUndoBaseLibraryManager * Unused Matrix34_tpl typedefs * Legacy Xml classes cleanup Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Remove unused `Vec3ToVector3D` helper Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * fix - remove unused static variable Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
230 lines
9.2 KiB
C++
230 lines
9.2 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 "UiCanvasOnMeshComponent.h"
|
|
#include <AzCore/Component/TransformBus.h>
|
|
#include <AzCore/Serialization/SerializeContext.h>
|
|
#include <AzCore/Serialization/EditContext.h>
|
|
#include <LyShine/Bus/UiCanvasBus.h>
|
|
#include <LyShine/Bus/World/UiCanvasRefBus.h>
|
|
|
|
#include <Cry_Geo.h>
|
|
#include <IIndexedMesh.h>
|
|
|
|
#if !defined(_RELEASE)
|
|
#include <IRenderAuxGeom.h>
|
|
|
|
// set this to 1 to enable debug display
|
|
#define UI_CANVAS_ON_MESH_DEBUG 0
|
|
#endif // !defined(_RELEASE)
|
|
|
|
#include <AzFramework/Render/GeometryIntersectionStructures.h>
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Anonymous namespace
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
namespace
|
|
{
|
|
#if UI_CANVAS_ON_MESH_DEBUG
|
|
// Debug draw methods only used for debugging the collision
|
|
|
|
static const ColorB debugHitColor(255, 0, 0, 255);
|
|
static const ColorB debugCollisionMeshColor(255, 255, 0, 255);
|
|
static const ColorB debugRenderMeshAttempt1Color(0, 255, 0, 255);
|
|
static const ColorB debugRenderMeshAttempt2Color(0, 0, 255, 255);
|
|
|
|
static const float debugDrawSphereSize = 0.01f;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void DrawSphere(const Vec3& point, const ColorB& color, float size)
|
|
{
|
|
IRenderAuxGeom* pRenderAux = gEnv->pRenderer->GetIRenderAuxGeom();
|
|
pRenderAux->DrawSphere(point, size, color);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void DrawTrianglePoints(const Vec3& v0, const Vec3& v1, const Vec3& v2, const ColorB& color, float size)
|
|
{
|
|
IRenderAuxGeom* pRenderAux = gEnv->pRenderer->GetIRenderAuxGeom();
|
|
pRenderAux->DrawSphere(v0, size, color);
|
|
pRenderAux->DrawSphere(v1, size, color);
|
|
pRenderAux->DrawSphere(v2, size, color);
|
|
}
|
|
|
|
void DrawCollisionMeshTrianglePoints(
|
|
int triIndex,
|
|
const IPhysicalEntity* collider,
|
|
int partIndex,
|
|
const Matrix34& slotWorldTM
|
|
)
|
|
{
|
|
if (collider)
|
|
{
|
|
const IPhysicalEntity* pe = collider;
|
|
pe_params_part partParams;
|
|
partParams.ipart = partIndex;
|
|
pe->GetParams(&partParams);
|
|
phys_geometry* pPhysGeom = partParams.pPhysGeom;
|
|
phys_geometry* pPhysGeomProxy = partParams.pPhysGeomProxy;
|
|
|
|
IGeometry* geom = pPhysGeom->pGeom;
|
|
Vec3 featurePoint[3];
|
|
int feat = geom->GetFeature(triIndex, 0, featurePoint);
|
|
primitives::triangle prim;
|
|
int primResult = geom->GetPrimitive(triIndex, &prim);
|
|
|
|
{
|
|
// get verts in world space
|
|
Vec3 wv0 = slotWorldTM.TransformPoint(prim.pt[0]);
|
|
Vec3 wv1 = slotWorldTM.TransformPoint(prim.pt[1]);
|
|
Vec3 wv2 = slotWorldTM.TransformPoint(prim.pt[2]);
|
|
|
|
// offset the points that we draw by the debug sphere radius so they can be seen when
|
|
// they are on top of the render mesh points
|
|
Vec3 worldNormal = slotWorldTM.TransformVector(prim.n);
|
|
|
|
wv0 += worldNormal * debugDrawSphereSize;
|
|
wv1 += worldNormal * debugDrawSphereSize;
|
|
wv2 += worldNormal * debugDrawSphereSize;
|
|
|
|
DrawTrianglePoints(wv0, wv1, wv2, debugCollisionMeshColor, debugDrawSphereSize * 0.5f);
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
} // Anonymous namespace
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// PUBLIC MEMBER FUNCTIONS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
UiCanvasOnMeshComponent::UiCanvasOnMeshComponent()
|
|
{}
|
|
|
|
bool UiCanvasOnMeshComponent::ProcessHitInputEvent(const AzFramework::InputChannel::Snapshot& inputSnapshot, const AzFramework::RenderGeometry::RayResult& rayResult)
|
|
{
|
|
return ProcessCollisionInputEventInternal(inputSnapshot, rayResult);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiCanvasOnMeshComponent::OnCanvasLoadedIntoEntity(AZ::EntityId uiCanvasEntity)
|
|
{
|
|
if (uiCanvasEntity.IsValid() && !m_renderTargetOverride.empty())
|
|
{
|
|
EBUS_EVENT_ID(uiCanvasEntity, UiCanvasBus, SetRenderTargetName, m_renderTargetOverride);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiCanvasOnMeshComponent::OnCanvasReloaded(AZ::EntityId canvasEntityId)
|
|
{
|
|
if (canvasEntityId == GetCanvas())
|
|
{
|
|
// The canvas that we are using has been reloaded, we may need to override the render target
|
|
OnCanvasLoadedIntoEntity(canvasEntityId);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// PUBLIC STATIC MEMBER FUNCTIONS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiCanvasOnMeshComponent::Reflect(AZ::ReflectContext* context)
|
|
{
|
|
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
|
|
|
|
if (serializeContext)
|
|
{
|
|
serializeContext->Class<UiCanvasOnMeshComponent, AZ::Component>()
|
|
->Version(1)
|
|
->Field("RenderTargetOverride", &UiCanvasOnMeshComponent::m_renderTargetOverride);
|
|
|
|
AZ::EditContext* editContext = serializeContext->GetEditContext();
|
|
if (editContext)
|
|
{
|
|
auto editInfo = editContext->Class<UiCanvasOnMeshComponent>(
|
|
"UI Canvas on Mesh", "The UI Canvas on Mesh component allows you to place a UI Canvas on an entity in the 3D world that a player can interact with via ray casts");
|
|
|
|
editInfo->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
|
->Attribute(AZ::Edit::Attributes::Category, "UI")
|
|
->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/UiCanvasOnMesh.svg")
|
|
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/UiCanvasOnMesh.svg")
|
|
->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://o3de.org/docs/user-guide/components/reference/ui-canvas-on-mesh/")
|
|
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c));
|
|
|
|
editInfo->DataElement(0, &UiCanvasOnMeshComponent::m_renderTargetOverride,
|
|
"Render target override",
|
|
"If not empty, this name overrides the render target set on the UI canvas.\n"
|
|
"This is useful if multiple instances the same UI canvas are rendered in the level.");
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// PROTECTED MEMBER FUNCTIONS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiCanvasOnMeshComponent::Activate()
|
|
{
|
|
UiCanvasOnMeshBus::Handler::BusConnect(GetEntityId());
|
|
UiCanvasAssetRefNotificationBus::Handler::BusConnect(GetEntityId());
|
|
UiCanvasManagerNotificationBus::Handler::BusConnect();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void UiCanvasOnMeshComponent::Deactivate()
|
|
{
|
|
UiCanvasAssetRefNotificationBus::Handler::BusDisconnect();
|
|
UiCanvasOnMeshBus::Handler::BusDisconnect();
|
|
UiCanvasManagerNotificationBus::Handler::BusDisconnect();
|
|
}
|
|
|
|
bool UiCanvasOnMeshComponent::ProcessCollisionInputEventInternal(const AzFramework::InputChannel::Snapshot& inputSnapshot, const AzFramework::RenderGeometry::RayResult& rayResult)
|
|
{
|
|
AZ::EntityId canvasEntityId = GetCanvas();
|
|
|
|
if (canvasEntityId.IsValid())
|
|
{
|
|
// Cache bus pointer as it will be used twice
|
|
UiCanvasBus::BusPtr uiCanvasInterfacePtr;
|
|
UiCanvasBus::Bind(uiCanvasInterfacePtr, canvasEntityId);
|
|
if (!uiCanvasInterfacePtr)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
AZ::Vector2 canvasSize;
|
|
UiCanvasBus::EventResult(canvasSize, uiCanvasInterfacePtr, &UiCanvasInterface::GetCanvasSize);
|
|
|
|
AZ::Vector2 canvasPoint = AZ::Vector2(rayResult.m_uv.GetX() * canvasSize.GetX(), rayResult.m_uv.GetY() * canvasSize.GetY());
|
|
|
|
bool handledByCanvas = false;
|
|
UiCanvasBus::EventResult(handledByCanvas, uiCanvasInterfacePtr,
|
|
&UiCanvasInterface::HandleInputPositionalEvent, inputSnapshot, canvasPoint);
|
|
|
|
if (handledByCanvas)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
AZ::EntityId UiCanvasOnMeshComponent::GetCanvas()
|
|
{
|
|
AZ::EntityId result;
|
|
EBUS_EVENT_ID_RESULT(result, GetEntityId(), UiCanvasRefBus, GetCanvas);
|
|
return result;
|
|
}
|