Merge pull request #50597 from Calinou/3d-editor-improve-manipulation-gizmo

Improve the 3D editor manipulation gizmo
This commit is contained in:
Rémi Verschelde 2021-07-28 15:33:24 +02:00 committed by GitHub
commit 7f0a83c129
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 11 deletions

View File

@ -942,14 +942,18 @@ bool Node3DEditorViewport::_transform_gizmo_select(const Vector2 &p_screenpos, b
Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized(); Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized();
Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized(); Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized();
Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST); // Allow some tolerance to make the plane easier to click,
// even if the click is actually slightly outside the plane.
const Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST * 0.6667);
Vector3 r; Vector3 r;
Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); Plane plane(gt.origin, gt.basis.get_axis(i).normalized());
if (plane.intersects_ray(ray_pos, ray, &r)) { if (plane.intersects_ray(ray_pos, ray, &r)) {
float dist = r.distance_to(grabber_pos); float dist = r.distance_to(grabber_pos);
if (dist < (gs * GIZMO_PLANE_SIZE)) { // Allow some tolerance to make the plane easier to click,
// even if the click is actually slightly outside the plane.
if (dist < (gs * GIZMO_PLANE_SIZE * 1.5)) {
float d = ray_pos.distance_to(r); float d = ray_pos.distance_to(r);
if (d < col_d) { if (d < col_d) {
col_d = d; col_d = d;
@ -1042,14 +1046,18 @@ bool Node3DEditorViewport::_transform_gizmo_select(const Vector2 &p_screenpos, b
Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized(); Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized();
Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized(); Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized();
Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST); // Allow some tolerance to make the plane easier to click,
// even if the click is actually slightly outside the plane.
Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST * 0.6667);
Vector3 r; Vector3 r;
Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); Plane plane(gt.origin, gt.basis.get_axis(i).normalized());
if (plane.intersects_ray(ray_pos, ray, &r)) { if (plane.intersects_ray(ray_pos, ray, &r)) {
float dist = r.distance_to(grabber_pos); float dist = r.distance_to(grabber_pos);
if (dist < (gs * GIZMO_PLANE_SIZE)) { // Allow some tolerance to make the plane easier to click,
// even if the click is actually slightly outside the plane.
if (dist < (gs * GIZMO_PLANE_SIZE * 1.5)) {
float d = ray_pos.distance_to(r); float d = ray_pos.distance_to(r);
if (d < col_d) { if (d < col_d) {
col_d = d; col_d = d;
@ -2909,9 +2917,7 @@ void Node3DEditorViewport::_draw() {
handle_color = get_theme_color(SNAME("accent_color"), SNAME("Editor")); handle_color = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
break; break;
} }
handle_color.a = 1.0; handle_color = handle_color.from_hsv(handle_color.get_h(), 0.25, 1.0, 1);
const float brightness = 1.3;
handle_color *= Color(brightness, brightness, brightness);
RenderingServer::get_singleton()->canvas_item_add_line( RenderingServer::get_singleton()->canvas_item_add_line(
ci, ci,
@ -5638,8 +5644,7 @@ void fragment() {
gizmo_color[i] = mat; gizmo_color[i] = mat;
Ref<StandardMaterial3D> mat_hl = mat->duplicate(); Ref<StandardMaterial3D> mat_hl = mat->duplicate();
const float brightness = 1.3; const Color albedo = col.from_hsv(col.get_h(), 0.25, 1.0, 1);
const Color albedo = Color(col.r * brightness, col.g * brightness, col.b * brightness);
mat_hl->set_albedo(albedo); mat_hl->set_albedo(albedo);
gizmo_color_hl[i] = mat_hl; gizmo_color_hl[i] = mat_hl;
@ -5746,7 +5751,7 @@ void fragment() {
surftool->begin(Mesh::PRIMITIVE_TRIANGLES); surftool->begin(Mesh::PRIMITIVE_TRIANGLES);
int n = 128; // number of circle segments int n = 128; // number of circle segments
int m = 6; // number of thickness segments int m = 3; // number of thickness segments
real_t step = Math_TAU / n; real_t step = Math_TAU / n;
for (int j = 0; j < n; ++j) { for (int j = 0; j < n; ++j) {
@ -5954,7 +5959,7 @@ void fragment() {
surftool->commit(scale_plane_gizmo[i]); surftool->commit(scale_plane_gizmo[i]);
Ref<StandardMaterial3D> plane_mat_hl = plane_mat->duplicate(); Ref<StandardMaterial3D> plane_mat_hl = plane_mat->duplicate();
plane_mat_hl->set_albedo(Color(col.r * 1.3, col.g * 1.3, col.b * 1.3)); plane_mat_hl->set_albedo(col.from_hsv(col.get_h(), 0.25, 1.0, 1));
plane_gizmo_color_hl[i] = plane_mat_hl; // needed, so we can draw planes from both sides plane_gizmo_color_hl[i] = plane_mat_hl; // needed, so we can draw planes from both sides
} }
} }