15#include "node_owner.hpp"
16#include "workspace_history.hpp"
20#include <glm/gtc/quaternion.hpp>
22#include <toast/events/listener.hpp>
42 glm::vec3 world_position {0.0f};
46 static constexpr size_t k_max_size_handles = 6;
72 auto name() -> std::string
override;
77 void registerDependency(
Node& from,
Node& to)
override;
78 void unregisterDependency(
Node& from,
Node& to)
override;
80 void nodeEnabledChanged(
Node& node)
noexcept override;
83 auto participatesIn(NodeOwnerParticipation use)
const noexcept ->
bool override;
86 auto receivesEvents() const noexcept ->
bool override;
89 auto findFrom(const
Node& origin, std::string_view query) ->
Box<
Node> override;
92 auto findFrom(const
Node& origin, const
UID& uid) ->
Box<
Node> override;
95 auto searchFrom(const
Node& origin, std::string_view query) -> std::vector<
Box<
Node>> override;
104 auto usesGameCamera() const noexcept ->
bool {
105 return m_game_camera;
108 void inheritEditorCamera(
const Workspace& source);
109 void preparePrefabReload(UID uid);
110 void finishPrefabReload();
114 auto owningPrefabUid() const -> UID
override {
126 std::unique_ptr<assets::Prefab> m_owned_source_prefab;
137 GizmoTool m_gizmo_tool = GizmoTool::select;
140 SnapSetting m_rotate_snap {
true, 30.0f};
141 SnapSetting m_scale_snap {
true, 0.10f};
143 std::unique_ptr<Camera> m_editor_camera;
145 std::unique_ptr<WorkspaceHistory> m_history;
146 std::mutex m_enabled_changes_mutex;
147 std::vector<Box<Node>> m_enabled_changes;
149 void sendEnabledChanges();
152 auto isActiveWorkspace() const noexcept ->
bool;
159 glm::vec3 m_gizmo_drag_start_world_pos {0.0f};
160 glm::quat m_gizmo_drag_start_rotation {1.0f, 0.0f, 0.0f, 0.0f};
161 glm::vec3 m_gizmo_drag_start_scale {1.0f};
168 glm::vec3 m_gizmo_drag_start_size {0.0f};
169 glm::vec3 m_gizmo_drag_start_local_pos {0.0f};
170 glm::quat m_gizmo_drag_start_local_rot {1.0f, 0.0f, 0.0f, 0.0f};
175 auto gizmoOrigin() const -> glm::vec3;
177 auto gizmoOrientation() const -> glm::quat;
179 auto gizmoScale() const ->
float;
181 auto gizmoInteractionAllowed() const ->
bool;
184 auto collectSizeHandles() const -> std::pair<std::array<
SizeHandlePoint, k_max_size_handles>, uint32_t>;
186 void gizmoApplySizeDrag(
float delta);
187 void gizmoUpdateHover();
189 void gizmoUpdateDrag();
192 void eventSubscriptions();
193 void initializeHistory(
bool available,
bool initially_saved);
194 auto restoreHistorySnapshot(const assets::Prefab& snapshot) ->
bool;
195 void destroyOwnedTree(
Box<
Node>& root);
214 uint8_t paint_id = 1;
217 Phase phase = Phase::idle;
225 glm::ivec3 anchor {0};
226 glm::ivec3 current {0};
227 glm::ivec3
face_min {std::numeric_limits<int32_t>::min()};
228 glm::ivec3 face_max {std::numeric_limits<int32_t>::max()};
231 glm::vec2 cut_start {0.0f};
232 glm::vec4 cut_plane {0.0f};
236 auto box() const -> std::pair<glm::ivec3, glm::ivec3>;
239 VoxelToolState m_voxel_tool;
242 void voxelUpdatePreview(uint8_t kind);
244 void voxelReparent(
Box<
Node> node,
Box<
Node> parent,
size_t index);
245 auto voxelWrapInGroup(
Box<
Node> node, std::string_view name) ->
Box<
Node>;
249 void voxelToolMouseMove();
250 auto voxelToolMouseButton(uint32_t button,
bool pressed,
int mods) ->
bool;
251 void voxelToolCancel();
253 auto pickNodeUnderMouse() ->
Box<
Node>;
254 std::optional<glm::vec2> m_pick_press;
256 auto retypeNode(
Box<
Node>& target, std::string_view type,
bool keep_fields) ->
Box<
Node>;
257 void promoteNode(
Box<
Node>& target, std::string_view path);
261 const bool owned = m_history && m_history->beginAtomic(std::move(context));
262 std::forward<F>(mutation)();
264 m_history->finishAtomic(owned);
269 void initFromPrefab(
const assets::Handle<assets::Prefab>& file);
270 void applyActiveCamera()
override;
273 struct PendingPrefabReload {
275 assets::Prefab reference;
278 std::vector<PendingPrefabReload> m_prefab_reloads;
279 double m_inspector_accum = 0.0;
287 void tickAnimationPreviews(
const Node& node);
295 void tick()
override;
298 auto rootNode() const -> const Node& {
303 auto isValid() const ->
bool {
304 return m_root_node.
exists();
308 auto findPrefabInstance(UID prefab, UID instance) -> Box<Node>;
311 bool visible =
false;
313 glm::vec3 origin {0.0f};
314 glm::quat orientation {1.0f, 0.0f, 0.0f, 0.0f};
319 std::array<SizeHandlePoint, k_max_size_handles> size_handles {};
320 uint32_t size_handle_count = 0;
321 float size_handle_scale = 1.0f;
328 auto gizmoRenderState() const -> GizmoRenderState;
manages the lifetime, subscription, and unsubscription of callbacks
Definition listener.hpp:39
Intrusive reference-counted handle to a Node.
Definition box.hpp:35
auto exists() const noexcept -> bool
Whether this box holds a live node.
Definition box.inl:135
Definition editor_camera.hpp:15
Definition procedural_voxel.hpp:41
Definition workspace_history.hpp:13
EditorCameraController m_editor_camera_controller
drives m_editor_camera; ticked from tick() below
Definition workspace.hpp:144
glm::vec2 m_gizmo_mouse_pos
The gizmo's current state.
Definition workspace.hpp:156
virtual auto isPlaying() const -> bool
True for PlayWorkspace, gates gizmo interaction off so it can never run against a live game.
Definition workspace.hpp:99
float m_gizmo_drag_start_angle
radians, for rotate drags
Definition workspace.hpp:165
auto asWorkspace() -> Workspace *override
Downcast helper for owners that need Workspace-specific state.
Definition workspace.hpp:74
glm::vec3 m_gizmo_drag_plane_normal
world-space plane normal, for plane/center/ring drags
Definition workspace.hpp:164
void subscribeVoxelEditing()
Definition workspace_voxel.cpp:694
float m_gizmo_drag_current_factor
live scale factor, for the scale feedback stretch
Definition workspace.hpp:166
bool m_world_space
false = local coordinates
Definition workspace.hpp:138
bool m_game_camera
false = editor camera
Definition workspace.hpp:142
glm::vec3 m_gizmo_drag_anchor
closest-point-on-axis or ray-plane hit at drag start
Definition workspace.hpp:162
std::optional< std::string > m_gizmo_history_start
dragged field's value at drag start, set while the drag owns the open history transaction
Definition workspace.hpp:172
Workspace(std::string_view type, UID handle)
Creates a new workspace rooted at a single fresh node of the given type.
Definition workspace.cpp:352
glm::vec3 m_gizmo_drag_axis
world-space axis direction, for axis/ring drags
Definition workspace.hpp:163
Geometry + hit-test constants shared between DebugPass (renders the gizmos) and Workspace (hit-tests/...
GizmoTool
Mirrors editor.WorkspaceViewModel.GizmoTool / proto SetGizmoTool - 0 Select, 1 Translate,...
Definition gizmo_layout.hpp:21
GizmoHandle
Which part of the active gizmo a ray/click is interacting with, axis_x/y/z and center are reused acro...
Definition gizmo_layout.hpp:32
disambiguates the protected ctor from Workspace(UID)
Definition workspace.hpp:119
Definition workspace.hpp:310
float drag_scale_factor
scale tool only: live multiplicative factor for the active handle
Definition workspace.hpp:317
Definition workspace.hpp:41
Definition workspace.hpp:132