Files
o3de/Code/Editor/Objects/DisplayContext.h
T
Artur K 56904d1799 Cry Legacy: the Lessening (#5961)
* 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>
2021-11-29 11:21:06 -07:00

326 lines
13 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
*
*/
// Description : DisplayContext definition.
#ifndef CRYINCLUDE_EDITOR_OBJECTS_DISPLAYCONTEXT_H
#define CRYINCLUDE_EDITOR_OBJECTS_DISPLAYCONTEXT_H
#pragma once
#include "SandboxAPI.h"
#include <Cry_Color.h>
#include <Cry_Geo.h>
#include <AzCore/std/containers/vector.h>
#include <QColor>
#define DC_DEFAULT_DOTLINE_STEPS 10
#define DC_UNIT_DEGREE 1
// forward declarations.
struct IDisplayViewport;
struct IRenderer;
struct IRenderAuxGeom;
struct IIconManager;
class CDisplaySettings;
class QPoint;
enum DisplayFlags
{
DISPLAY_2D = 0x01,
DISPLAY_HIDENAMES = 0x02,
DISPLAY_BBOX = 0x04,
DISPLAY_TRACKS = 0x08,
DISPLAY_TRACKTICKS = 0x010,
DISPLAY_WORLDSPACEAXIS = 0x020, //!< Set if axis must be displayed in world space.
DISPLAY_LINKS = 0x040,
DISPLAY_DEGRADATED = 0x080, //!< Display Objects in degradated quality (When moving/modifying).
DISPLAY_SELECTION_HELPERS = 0x100, //!< Display advanced selection helpers.
};
/*!
* DisplayContex is a structure passed to BaseObject Display method.
* It contains everything the object should know to display itself in a view.
* All fields must be filled before passing that structure to Display call.
*/
struct SANDBOX_API DisplayContext
{
enum ETextureIconFlags
{
TEXICON_ADDITIVE = 0x0001,
TEXICON_ALIGN_BOTTOM = 0x0002,
TEXICON_ALIGN_TOP = 0x0004,
TEXICON_ON_TOP = 0x0008,
};
CDisplaySettings* settings;
IDisplayViewport* view;
IRenderAuxGeom* pRenderAuxGeom;
IIconManager* pIconManager;
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
AABB box; // Bounding box of volume that need to be repainted.
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
int flags;
//! Ctor.
DisplayContext();
// Helper methods.
void SetView(IDisplayViewport* pView);
IDisplayViewport* GetView() const { return view; }
void Flush2D();
//////////////////////////////////////////////////////////////////////////
// Draw functions
//////////////////////////////////////////////////////////////////////////
//! Set current materialc color.
void SetColor(float r, float g, float b, float a = 1)
{
m_color4b = ColorB(
static_cast<uint8>(r * 255.0f), static_cast<uint8>(g * 255.0f), static_cast<uint8>(b * 255.0f), static_cast<uint8>(a * 255.0f));
};
void SetColor(const Vec3& color, float a = 1)
{
m_color4b = ColorB(
static_cast<uint8>(color.x * 255.0f), static_cast<uint8>(color.y * 255.0f), static_cast<uint8>(color.z * 255.0f),
static_cast<uint8>(a * 255.0f));
};
void SetColor(const AZ::Vector3& color, float a = 1)
{
m_color4b = ColorB(
static_cast<uint8>(color.GetX() * 255.0f), static_cast<uint8>(color.GetY() * 255.0f), static_cast<uint8>(color.GetZ() * 255.0f),
static_cast<uint8>(a * 255.0f));
};
void SetColor(const QColor& rgb, float a)
{
m_color4b = ColorB(
static_cast<uint8>(rgb.red()), static_cast<uint8>(rgb.green()), static_cast<uint8>(rgb.blue()), static_cast<uint8>(a * 255.0f));
};
void SetColor(const QColor& color)
{
m_color4b = ColorB(
static_cast<uint8>(color.red()), static_cast<uint8>(color.green()), static_cast<uint8>(color.blue()),
static_cast<uint8>(color.alpha()));
};
void SetColor(const ColorB& color)
{
m_color4b = color;
};
void SetAlpha(float a = 1) { m_color4b.a = static_cast<uint8>(a * 255.0f); };
ColorB GetColor() const { return m_color4b; }
void SetSelectedColor(float fAlpha = 1);
void SetFreezeColor();
//! Get color to draw selectin of object.
QColor GetSelectedColor();
QColor GetFreezeColor();
// Draw 3D quad.
void DrawQuad(const Vec3& p1, const Vec3& p2, const Vec3& p3, const Vec3& p4);
void DrawQuad(float width, float height);
void DrawQuadGradient(const Vec3& p1, const Vec3& p2, const Vec3& p3, const Vec3& p4, ColorB firstColor, ColorB secondColor);
void DrawWireQuad(const Vec3& p1, const Vec3& p2, const Vec3& p3, const Vec3& p4);
void DrawWireQuad(float width, float height);
// Draw 3D Triangle.
void DrawTri(const Vec3& p1, const Vec3& p2, const Vec3& p3);
void DrawTriangles(const AZStd::vector<Vec3>& vertices, const ColorB& color);
void DrawTrianglesIndexed(const AZStd::vector<Vec3>& vertices, const AZStd::vector<vtx_idx>& indices, const ColorB& color);
// Draw wireframe box.
void DrawWireBox(const Vec3& min, const Vec3& max);
void DrawWireBox(const AZ::Vector3& min, const AZ::Vector3& max);
// Draw filled box
void DrawSolidBox(const Vec3& min, const Vec3& max);
void DrawSolidOBB(const Vec3& center, const Vec3& axisX, const Vec3& axisY, const Vec3& axisZ, const Vec3& halfExtents);
void DrawPoint(const Vec3& p, int nSize = 1);
void DrawLine(const Vec3& p1, const Vec3& p2);
void DrawLine(const Vec3& p1, const Vec3& p2, const ColorF& col1, const ColorF& col2);
void DrawLine(const Vec3& p1, const Vec3& p2, const QColor& rgb1, const QColor& rgb2);
void DrawLines(const AZStd::vector<Vec3>& vertices, const ColorF& color);
void DrawPolyLine(const Vec3* pnts, int numPoints, bool cycled = true);
// Vera, Confetti
void DrawDottedLine(const Vec3& p1, const Vec3& p2, const ColorF& col1, const ColorF& col2, const float numOfSteps = DC_DEFAULT_DOTLINE_STEPS);
void DrawWireQuad2d(const QPoint& p1, const QPoint& p2, float z);
void DrawLine2d(const QPoint& p1, const QPoint& p2, float z);
void DrawLine2dGradient(const QPoint& p1, const QPoint& p2, float z, ColorB firstColor, ColorB secondColor);
void DrawWireCircle2d(const QPoint& center, float radius, float z);
// Draw circle from lines on terrain, position is in world space.
void DrawTerrainCircle(const Vec3& worldPos, float radius, float height);
void DrawTerrainCircle(const Vec3& center, float radius, float angle1, float angle2, float height);
/// DrawArc
/// Draws an arc around the specified position from a given angle across the angular length given by sweepAngleDegrees
/// it orients the arc around the index of the given basis axis.
/// \param pos World space position on which to center the arc.
/// \param radius Radius that defines the size of the arc.
/// \param startAngleDegrees Angle in degrees measured clockwise from the basis axis to the starting point of the arc.
/// \param sweepAngleDegreees Angle in degrees measured clockwise from the startAngle parameter to ending point of the arc.
/// \param angularStepDegrees Defines the distance between vertices, a small value will result in a greater number of vertices.
/// \param referenceAxis Axis on which to align the arc (0 for X, 1 for Y, 2 for Z)
void DrawArc(const Vec3& pos, float radius, float startAngleDegrees, float sweepAngleDegrees, float angularStepDegrees, int referenceAxis = 2);
/// DrawArc
/// Draws an arc around the specified position from a given angle across the angular length given by sweepAngleDegrees
/// oriented around the specified axis.
/// \param pos World space position on which to center the arc.
/// \param radius Radius that defines the size of the arc.
/// \param startAngleDegrees Angle in degrees measured clockwise from the basis axis to the starting point of the arc.
/// \param sweepAngleDegreees Angle in degrees measured clockwise from the startAngle parameter to ending point of the arc.
/// \param angularStepDegrees Defines the distance between vertices, a small value will result in a greater number of vertices.
/// \param fixedAxis Normal axis on which to align the arc.
void DrawArc(const Vec3& pos, float radius, float startAngleDegrees, float sweepAngleDegrees, float angularStepDegrees, const Vec3& fixedAxis);
//Vera, Confetti:
//Draw an arc and an arrow at the end of the arc
void DrawArcWithArrow(const Vec3& pos, float radius, float startAngleDegrees, float sweepAngleDegrees, float angularStepDegrees, const Vec3& fixedAxis);
// Draw circle.
void DrawCircle(const Vec3& pos, float radius, int nUnchangedAxis = 2 /*z axis*/);
void DrawHalfDottedCircle(const Vec3& pos, float radius, const Vec3& viewPos, int nUnchangedAxis = 2 /*z axis*/);
// Vera, Confetti :
// Draw a dotted circle.
void DrawDottedCircle(const Vec3& pos, float radius, const Vec3& nUnchangedAxis, int numberOfArrows = 0, float stepDegree = DC_UNIT_DEGREE);
// Draw cylinder.
void DrawCylinder(const Vec3& p1, const Vec3& p2, float radius, float height);
void DrawCone(const Vec3& pos, const Vec3& dir, float radius, float height, bool drawShaded = true);
/// DrawWireCylinder
/// \param center Center of cylinder.
/// \param axis Axis along which cylinder is tall.
/// \param radius Radius of cylinder.
/// \param height Total height of cylinder.
void DrawWireCylinder(const Vec3& center, const Vec3& axis, float radius, float height);
/// DrawSolidCylinder
/// \param center Center of cylinder.
/// \param axis Axis along which cylinder is tall.
/// \param radius Radius of cylinder.
/// \param height Total height of cylinder.
void DrawSolidCylinder(const Vec3& center, const Vec3& axis, float radius, float height, bool drawShaded = true);
/// DrawWireCapsule
/// \param pos Center of capsule.
/// \param axis Axis along which capsule is tall.
/// \param radius Radius of capsule.
/// \param heightStraightSection Height of capsule's straight section (does not include caps).
void DrawWireCapsule(const Vec3& center, const Vec3& axis, float radius, float heightStraightSection);
//! Draw rectangle on top of terrain.
//! Coordinates are in world space.
void DrawTerrainRect(float x1, float y1, float x2, float y2, float height);
void DrawTerrainLine (Vec3 worldPos1, Vec3 worldPos2);
void DrawWireSphere(const Vec3& pos, float radius);
void DrawWireSphere(const Vec3& pos, const Vec3 radius);
void DrawWireDisk(const Vec3& pos, const Vec3& dir, float radius);
void PushMatrix(const Matrix34& tm);
void PopMatrix();
const Matrix34& GetMatrix();
// Draw special 3D objects.
void DrawBall(const Vec3& pos, float radius, bool drawShaded = true);
void DrawDisk(const Vec3& pos, const Vec3& dir, float radius);
//! Draws 3d arrow.
void DrawArrow(const Vec3& src, const Vec3& trg, float fHeadScale = 1, bool b2SidedArrow = false);
// Draw texture label in 2d view coordinates.
// w,h in pixels.
void DrawTextureLabel(const Vec3& pos, int nWidth, int nHeight, int nTexId, int nTexIconFlags = 0, int srcOffsetX = 0, int scrOffsetY = 0, bool bDistanceScaleIcons = false, float fDistanceScale = 1.0f);
void RenderObject(int objectType, const Vec3& pos, float scale);
void RenderObject(int objectType, const Matrix34& tm);
void DrawTextLabel(const Vec3& pos, float size, const char* text, const bool bCenter = false, int srcOffsetX = 0, int scrOffsetY = 0);
void Draw2dTextLabel(float x, float y, float size, const char* text, bool bCenter = false);
void SetLineWidth(float width);
//! Is given bbox visible in this display context.
bool IsVisible(const AABB& bounds);
//! Gets current render state.
uint32 GetState() const;
//! Set a new render state.
//! \param returns previous render state.
uint32 SetState(uint32 state);
//! Set a new render state flags.
//! \param returns previous render state.
uint32 SetStateFlag(uint32 state);
//! Clear specified flags in render state.
//! \param returns previous render state.
uint32 ClearStateFlag(uint32 state);
void DepthTestOff();
void DepthTestOn();
void DepthWriteOff();
void DepthWriteOn();
void CullOff();
void CullOn();
// Enables drawing helper lines in front of usual geometry, adds a small z offset to all drawn lines.
bool SetDrawInFrontMode(bool bOn);
// Description:
// Changes fill mode.
// Arguments:
// nFillMode is one of the values from EAuxGeomPublicRenderflags_FillMode
int SetFillMode(int nFillMode);
//! Convert position to world space.
Vec3 ToWorldSpacePosition(const Vec3& v) { return m_matrixStack[m_currentMatrix].TransformPoint(v); }
//! Convert direction to world space (translation is not considered)
Vec3 ToWorldSpaceVector(const Vec3& v) { return m_matrixStack[m_currentMatrix].TransformVector(v); }
float ToWorldSpaceMaxScale(float value);
float GetLineWidth() const { return m_thickness; }
private:
void InternalDrawLine(const Vec3& v0, const ColorB& colV0, const Vec3& v1, const ColorB& colV1);
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
ColorB m_color4b;
uint32 m_renderState;
float m_thickness;
float m_width;
float m_height;
int m_currentMatrix;
//! Matrix stack.
Matrix34 m_matrixStack[32];
struct STextureLabel
{
float x, y, z; // 2D position (z in world space).
float w, h; // Width height.
int nTexId; // Texture id.
int flags; // ETextureIconFlags
float color[4];
};
std::vector<STextureLabel> m_textureLabels;
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
};
#endif // CRYINCLUDE_EDITOR_OBJECTS_DISPLAYCONTEXT_H