Show the 3D transform gizmo in the center when otherwise offscreen
This commit is contained in:
parent
76ce5c16f3
commit
4234a72b25
2 changed files with 137 additions and 45 deletions
|
|
@ -87,6 +87,19 @@ public:
|
|||
void set_viewport(Node3DEditorViewport *p_viewport);
|
||||
};
|
||||
|
||||
class GizmoOffScreenLine : public Control {
|
||||
GDCLASS(GizmoOffScreenLine, Control);
|
||||
|
||||
public:
|
||||
Vector2 point1;
|
||||
Vector2 point2;
|
||||
void _notification(int p_what) {
|
||||
if (p_what == NOTIFICATION_DRAW && is_visible()) {
|
||||
draw_line(point1, point2, Color(0.0f, 0.75f, 0.75f), 2);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Node3DEditorViewport : public Control {
|
||||
GDCLASS(Node3DEditorViewport, Control);
|
||||
friend class Node3DEditor;
|
||||
|
|
@ -201,6 +214,7 @@ private:
|
|||
|
||||
CheckBox *preview_camera;
|
||||
SubViewportContainer *subviewport_container;
|
||||
GizmoOffScreenLine *gizmo_offscreen_line;
|
||||
|
||||
MenuButton *view_menu;
|
||||
PopupMenu *display_submenu;
|
||||
|
|
@ -237,7 +251,7 @@ private:
|
|||
};
|
||||
|
||||
void _update_name();
|
||||
void _compute_edit(const Point2 &p_point);
|
||||
void _compute_edit(const Point2 &p_point, const bool p_auto_center = true);
|
||||
void _clear_selected();
|
||||
void _select_clicked(bool p_allow_locked);
|
||||
ObjectID _select_ray(const Point2 &p_pos);
|
||||
|
|
@ -507,6 +521,35 @@ class Node3DEditor : public VBoxContainer {
|
|||
public:
|
||||
static const unsigned int VIEWPORTS_COUNT = 4;
|
||||
|
||||
enum MenuOption {
|
||||
MENU_GROUP_SELECTED,
|
||||
MENU_KEEP_GIZMO_ONSCREEN,
|
||||
MENU_LOCK_SELECTED,
|
||||
MENU_SNAP_TO_FLOOR,
|
||||
MENU_TOOL_LIST_SELECT,
|
||||
MENU_TOOL_LOCAL_COORDS,
|
||||
MENU_TOOL_MOVE,
|
||||
MENU_TOOL_OVERRIDE_CAMERA,
|
||||
MENU_TOOL_ROTATE,
|
||||
MENU_TOOL_SCALE,
|
||||
MENU_TOOL_SELECT,
|
||||
MENU_TOOL_USE_SNAP,
|
||||
MENU_TRANSFORM_CONFIGURE_SNAP,
|
||||
MENU_TRANSFORM_DIALOG,
|
||||
MENU_UNGROUP_SELECTED,
|
||||
MENU_UNLOCK_SELECTED,
|
||||
MENU_VIEW_CAMERA_SETTINGS,
|
||||
MENU_VIEW_GIZMOS_3D_ICONS,
|
||||
MENU_VIEW_GRID,
|
||||
MENU_VIEW_ORIGIN,
|
||||
MENU_VIEW_USE_1_VIEWPORT,
|
||||
MENU_VIEW_USE_2_VIEWPORTS,
|
||||
MENU_VIEW_USE_2_VIEWPORTS_ALT,
|
||||
MENU_VIEW_USE_3_VIEWPORTS,
|
||||
MENU_VIEW_USE_3_VIEWPORTS_ALT,
|
||||
MENU_VIEW_USE_4_VIEWPORTS,
|
||||
};
|
||||
|
||||
enum ToolMode {
|
||||
TOOL_MODE_SELECT,
|
||||
TOOL_MODE_MOVE,
|
||||
|
|
@ -525,7 +568,6 @@ public:
|
|||
TOOL_OPT_USE_SNAP,
|
||||
TOOL_OPT_OVERRIDE_CAMERA,
|
||||
TOOL_OPT_MAX
|
||||
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
@ -554,6 +596,7 @@ private:
|
|||
Camera3D::Projection grid_camera_last_update_perspective = Camera3D::PROJECTION_PERSPECTIVE;
|
||||
Vector3 grid_camera_last_update_position = Vector3();
|
||||
|
||||
bool keep_gizmo_onscreen = true;
|
||||
Ref<ArrayMesh> move_gizmo[3], move_plane_gizmo[3], rotate_gizmo[4], scale_gizmo[3], scale_plane_gizmo[3], axis_gizmo[3];
|
||||
Ref<StandardMaterial3D> gizmo_color[3];
|
||||
Ref<StandardMaterial3D> plane_gizmo_color[3];
|
||||
|
|
@ -587,37 +630,10 @@ private:
|
|||
struct Gizmo {
|
||||
bool visible = false;
|
||||
real_t scale = 0;
|
||||
Vector3 target_center;
|
||||
Transform3D transform;
|
||||
} gizmo;
|
||||
|
||||
enum MenuOption {
|
||||
MENU_TOOL_SELECT,
|
||||
MENU_TOOL_MOVE,
|
||||
MENU_TOOL_ROTATE,
|
||||
MENU_TOOL_SCALE,
|
||||
MENU_TOOL_LIST_SELECT,
|
||||
MENU_TOOL_LOCAL_COORDS,
|
||||
MENU_TOOL_USE_SNAP,
|
||||
MENU_TOOL_OVERRIDE_CAMERA,
|
||||
MENU_TRANSFORM_CONFIGURE_SNAP,
|
||||
MENU_TRANSFORM_DIALOG,
|
||||
MENU_VIEW_USE_1_VIEWPORT,
|
||||
MENU_VIEW_USE_2_VIEWPORTS,
|
||||
MENU_VIEW_USE_2_VIEWPORTS_ALT,
|
||||
MENU_VIEW_USE_3_VIEWPORTS,
|
||||
MENU_VIEW_USE_3_VIEWPORTS_ALT,
|
||||
MENU_VIEW_USE_4_VIEWPORTS,
|
||||
MENU_VIEW_ORIGIN,
|
||||
MENU_VIEW_GRID,
|
||||
MENU_VIEW_GIZMOS_3D_ICONS,
|
||||
MENU_VIEW_CAMERA_SETTINGS,
|
||||
MENU_LOCK_SELECTED,
|
||||
MENU_UNLOCK_SELECTED,
|
||||
MENU_GROUP_SELECTED,
|
||||
MENU_UNGROUP_SELECTED,
|
||||
MENU_SNAP_TO_FLOOR
|
||||
};
|
||||
|
||||
Button *tool_button[TOOL_MAX];
|
||||
Button *tool_option_button[TOOL_OPT_MAX];
|
||||
|
||||
|
|
@ -776,7 +792,10 @@ public:
|
|||
float get_zfar() const { return settings_zfar->get_value(); }
|
||||
float get_fov() const { return settings_fov->get_value(); }
|
||||
|
||||
Vector3 get_gizmo_target_center() const { return gizmo.target_center; }
|
||||
Transform3D get_gizmo_transform() const { return gizmo.transform; }
|
||||
void set_gizmo_transform(const Transform3D &p_transform) { gizmo.transform = p_transform; }
|
||||
bool is_keep_gizmo_onscreen_enabled() const { return keep_gizmo_onscreen; }
|
||||
bool is_gizmo_visible() const;
|
||||
|
||||
ToolMode get_tool_mode() const { return tool_mode; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue