diff --git a/engine/includes/components/actor.h b/engine/includes/components/actor.h index 9066ac017..8f318687c 100644 --- a/engine/includes/components/actor.h +++ b/engine/includes/components/actor.h @@ -30,9 +30,11 @@ class ENGINE_EXPORT Actor : public Object { ) public: - enum HideFlags { - ENABLE = (1<<0), - SELECTABLE = (1<<1) + enum Flags { + Enable = (1<<0), + Selectable = (1<<1), + NonSerializable = (1<<2), + Static = (1<<3) }; public: @@ -62,8 +64,8 @@ class ENGINE_EXPORT Actor : public Object { bool isEnabled() const; void setEnabled(const bool enabled); - int hideFlags() const; - void setHideFlags(int flags); + int flags() const; + void setFlags(int flags); bool isEnabledInHierarchy() const; @@ -120,8 +122,6 @@ class ENGINE_EXPORT Actor : public Object { bool m_hierarchyEnable; - bool m_static; - bool m_muteUpdates; }; diff --git a/engine/includes/components/camera.h b/engine/includes/components/camera.h index 8a572ac7b..6c868a502 100644 --- a/engine/includes/components/camera.h +++ b/engine/includes/components/camera.h @@ -62,6 +62,9 @@ class ENGINE_EXPORT Camera : public Component { bool orthographic() const; void setOrthographic(const bool mode); + bool isScreenSpace() const; + void setScreenSpace(bool mode); + static Camera *current(); static void setCurrent(Camera *current); @@ -100,6 +103,8 @@ class ENGINE_EXPORT Camera : public Component { bool m_ortho; + bool m_screen; + }; #endif // CAMERA_H diff --git a/engine/includes/editor/viewport/tasks/gridrender.h b/engine/includes/editor/viewport/tasks/gridrender.h index b8c7def0e..4b9637759 100644 --- a/engine/includes/editor/viewport/tasks/gridrender.h +++ b/engine/includes/editor/viewport/tasks/gridrender.h @@ -131,6 +131,11 @@ class GridRender : public PipelineTask { } break; default: break; } + + if(camera->isScreenSpace()) { + pos += planeScale * 0.5f; + } + } else { Ray ray = camera->castRay(0.0f, 0.0f); diff --git a/engine/src/components/actor.cpp b/engine/src/components/actor.cpp index e7362c051..129efb1e1 100644 --- a/engine/src/components/actor.cpp +++ b/engine/src/components/actor.cpp @@ -68,9 +68,8 @@ Actor::Actor() : m_prefab(nullptr), m_scene(nullptr), m_layers(CommandBuffer::DEFAULT | CommandBuffer::RAYCAST | CommandBuffer::SHADOWCAST | CommandBuffer::TRANSLUCENT), - m_flags(Actor::ENABLE | Actor::SELECTABLE), - m_hierarchyEnable(m_flags & Actor::ENABLE), - m_static(false), + m_flags(Actor::Enable | Actor::Selectable), + m_hierarchyEnable(m_flags & Actor::Enable), m_muteUpdates(false) { } @@ -91,7 +90,7 @@ Actor::~Actor() { */ bool Actor::isEnabled() const { PROFILE_FUNCTION(); - return m_flags & ENABLE; + return m_flags & Enable; } /*! Marks this Actor as \a enabled or disabled. @@ -100,9 +99,9 @@ bool Actor::isEnabled() const { void Actor::setEnabled(const bool enabled) { PROFILE_FUNCTION(); if(enabled) { - m_flags |= ENABLE; + m_flags |= Enable; } else { - m_flags &= ~ENABLE; + m_flags &= ~Enable; } setHierarchyEnabled(enabled); @@ -112,17 +111,17 @@ void Actor::setEnabled(const bool enabled) { } } /*! - Returns a set of Actor::HideFlags applied to this Actor. + Returns a set of Actor::Flags applied to this Actor. */ -int Actor::hideFlags() const { +int Actor::flags() const { PROFILE_FUNCTION(); return m_flags; } /*! - Applies a new set of Actor::HideFlags \a flags to this Actor. + Applies a new set of Actor::Flags \a flags to this Actor. */ -void Actor::setHideFlags(int flags) { +void Actor::setFlags(int flags) { PROFILE_FUNCTION(); bool old = isEnabled(); @@ -173,14 +172,18 @@ void Actor::setScene(Scene *scene) { Returns true if this actor will not be moved during the game; otherwise returns false. */ bool Actor::isStatic() const { - return m_static; + return m_flags & Static; } /*! Marks current Actor as static or dynamic (by default). This \a flag can help to optimize rendering. */ void Actor::setStatic(const bool flag) { - m_static = flag; + if(flag) { + m_flags |= Static; + } else { + m_flags &= ~Static; + } } /*! Returns the layers list for the this Actor as a bit mask. @@ -283,7 +286,7 @@ Component *Actor::addComponent(const std::string type) { */ bool Actor::isSerializable() const { PROFILE_FUNCTION(); - return (clonedFrom() == 0 || isInstance()); + return !(m_flags & NonSerializable) && (clonedFrom() == 0 || isInstance()); } /*! \internal diff --git a/engine/src/components/camera.cpp b/engine/src/components/camera.cpp index 0d32efb94..a225e8223 100644 --- a/engine/src/components/camera.cpp +++ b/engine/src/components/camera.cpp @@ -23,7 +23,8 @@ Camera::Camera() : m_ratio(1.0f), m_focal(1.0f), m_orthoSize(1.0f), - m_ortho(false) { + m_ortho(false), + m_screen(false) { recalcProjection(); } @@ -69,11 +70,10 @@ Vector3 Camera::project(const Vector3 &worldSpace) { Vector3 Camera::unproject(const Vector3 &screenSpace) { Matrix4 final((m_projection * viewMatrix()).inverse()); - Vector4 in; - in.x = (screenSpace.x) * 2.0f - 1.0f; - in.y = (screenSpace.y) * 2.0f - 1.0f; - in.z = 2.0f * screenSpace.z - 1.0f; - in.w = 1.0f; + Vector4 in(2.0f * screenSpace.x - 1.0f, + 2.0f * screenSpace.y - 1.0f, + 2.0f * screenSpace.z - 1.0f, + 1.0f); Vector4 out(final * in); @@ -210,6 +210,21 @@ void Camera::setOrthographic(const bool mode) { m_ortho = mode; recalcProjection(); } +/*! + Returns true is this camera in the screen space mode. + Typically used for Editor. +*/ +bool Camera::isScreenSpace() const { + return m_screen; +} +/*! + Sets the screen space \a mode for the camera. + Typically used for Editor. +*/ +void Camera::setScreenSpace(bool mode) { + m_screen = mode; + recalcProjection(); +} /*! Returns current active camera. */ @@ -328,7 +343,11 @@ void Camera::drawGizmosSelected() { void Camera::recalcProjection() { if(m_ortho) { float width = m_orthoSize * m_ratio; - m_projection = Matrix4::ortho(-width / 2, width / 2, -m_orthoSize / 2, m_orthoSize / 2, m_near, m_far); + if(m_screen) { + m_projection = Matrix4::ortho(0, width, 0, m_orthoSize, m_near, m_far); + } else { + m_projection = Matrix4::ortho(-width / 2, width / 2, -m_orthoSize / 2, m_orthoSize / 2, m_near, m_far); + } } else { m_projection = Matrix4::perspective(m_fov, m_ratio, m_near, m_far); } diff --git a/engine/src/components/transform.cpp b/engine/src/components/transform.cpp index db408794b..960482bc7 100644 --- a/engine/src/components/transform.cpp +++ b/engine/src/components/transform.cpp @@ -67,9 +67,11 @@ Vector3 Transform::position() const { Changes \a position of the Transform in local space. */ void Transform::setPosition(const Vector3 position) { - std::unique_lock locker(m_mutex); - m_position = position; - setDirty(); + if(m_position != position) { + std::unique_lock locker(m_mutex); + m_position = position; + setDirty(); + } } /*! Returns current rotation of the Transform in local space as Euler angles in degrees. diff --git a/engine/src/editor/viewport/viewport.cpp b/engine/src/editor/viewport/viewport.cpp index fa5908f74..11062a4e3 100644 --- a/engine/src/editor/viewport/viewport.cpp +++ b/engine/src/editor/viewport/viewport.cpp @@ -91,6 +91,8 @@ void Viewport::init() { m_color = pipelineContext->resultTexture(); m_color->setFlags(m_color->flags() | Texture::Feedback); + m_debugRender = new DebugRender; + if(!m_gameView) { m_gridRender = new GridRender; m_gridRender->setController(m_controller); @@ -112,14 +114,12 @@ void Viewport::init() { pipelineContext->insertRenderTask(m_gridRender, m_guiLayer); pipelineContext->insertRenderTask(m_outlinePass, m_guiLayer); - pipelineContext->insertRenderTask(m_gizmoRender, m_guiLayer); + pipelineContext->insertRenderTask(m_gizmoRender); Handles::init(); } - m_debugRender = new DebugRender; pipelineContext->insertRenderTask(m_debugRender, m_guiLayer); - pipelineContext->subscribePost(Viewport::readPixels, this); } } diff --git a/engine/src/pipelinecontext.cpp b/engine/src/pipelinecontext.cpp index ae47fbb76..3af606729 100644 --- a/engine/src/pipelinecontext.cpp +++ b/engine/src/pipelinecontext.cpp @@ -397,7 +397,7 @@ void PipelineContext::drawRenderers(const RenderList &list, uint32_t layer, uint if(it) { Actor *actor = it->actor(); - if((flags == 0 || actor->hideFlags() & flags) && actor->layers() & layer) { + if((flags == 0 || actor->flags() & flags) && actor->layers() & layer) { for(int32_t i = 0; i < it->m_materials.size(); i++) { MaterialInstance *instance = it->m_materials[i]; if(instance->transform() == nullptr) { diff --git a/modules/uikit/includes/components/frame.h b/modules/uikit/includes/components/frame.h index c056fc68f..a37adfe54 100644 --- a/modules/uikit/includes/components/frame.h +++ b/modules/uikit/includes/components/frame.h @@ -58,8 +58,6 @@ class UIKIT_EXPORT Frame : public Widget { Vector4 m_bottomColor; Vector4 m_leftColor; - Vector2 m_meshSize; - Mesh *m_mesh; MaterialInstance *m_material; diff --git a/modules/uikit/includes/components/uiloader.h b/modules/uikit/includes/components/uiloader.h index 481234ef6..61943bfcc 100644 --- a/modules/uikit/includes/components/uiloader.h +++ b/modules/uikit/includes/components/uiloader.h @@ -35,8 +35,6 @@ class UIKIT_EXPORT UiLoader : public Widget { void cleanHierarchy(Widget *widget); - void drawGizmos() override; - private: std::string m_documentStyle; diff --git a/modules/uikit/includes/components/widget.h b/modules/uikit/includes/components/widget.h index efd8cddf3..d68980c50 100644 --- a/modules/uikit/includes/components/widget.h +++ b/modules/uikit/includes/components/widget.h @@ -54,8 +54,6 @@ class UIKIT_EXPORT Widget : public NativeBehaviour { void setParent(Object *parent, int32_t position = -1, bool force = false) override; - void drawGizmosSelected() override; - float styleLength(const std::string &key, float value, bool &pixels); Vector2 styleBlock2Length(const std::string &property, const Vector2 &value, bool &pixels); Vector4 styleBlock4Length(const std::string &property, const Vector4 &value, bool &pixels); diff --git a/modules/uikit/includes/editor/tools/widgettool.h b/modules/uikit/includes/editor/tools/widgettool.h index 615c90a12..c4ce8b2c7 100644 --- a/modules/uikit/includes/editor/tools/widgettool.h +++ b/modules/uikit/includes/editor/tools/widgettool.h @@ -4,32 +4,13 @@ #include class WidgetController; -class Renderable; +class RectTransform; class WidgetTool : public EditorTool { -public: - struct Select { - bool operator==(const Select &left) { - return (uuid == left.uuid); - } - - uint32_t uuid = 0; - Actor *object = nullptr; - Renderable *renderable = nullptr; - - Vector3 position; - Vector3 scale; - Vector3 euler; - Quaternion quat; - }; - - typedef QList