Implement snapping for most 3D gizmos
This commit is contained in:
parent
f5f7244a2b
commit
0ce59bf6dd
|
@ -95,6 +95,7 @@ void PathSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_p
|
||||||
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
||||||
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
||||||
|
|
||||||
|
// Setting curve point positions
|
||||||
if (p_idx < c->get_point_count()) {
|
if (p_idx < c->get_point_count()) {
|
||||||
|
|
||||||
Plane p(gt.xform(original), p_camera->get_transform().basis.get_axis(2));
|
Plane p(gt.xform(original), p_camera->get_transform().basis.get_axis(2));
|
||||||
|
@ -126,6 +127,7 @@ void PathSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_p
|
||||||
|
|
||||||
Vector3 inters;
|
Vector3 inters;
|
||||||
|
|
||||||
|
// Setting curve in/out positions
|
||||||
if (p.intersects_ray(ray_from, ray_dir, &inters)) {
|
if (p.intersects_ray(ray_from, ray_dir, &inters)) {
|
||||||
|
|
||||||
if (!PathEditorPlugin::singleton->is_handle_clicked()) {
|
if (!PathEditorPlugin::singleton->is_handle_clicked()) {
|
||||||
|
@ -135,9 +137,13 @@ void PathSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_p
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 local = gi.xform(inters) - base;
|
Vector3 local = gi.xform(inters) - base;
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
float snap = SpatialEditor::get_singleton()->get_translate_snap();
|
||||||
|
local.snap(Vector3(snap, snap, snap));
|
||||||
|
}
|
||||||
|
|
||||||
if (t == 0) {
|
if (t == 0) {
|
||||||
c->set_point_in(idx, local);
|
c->set_point_in(idx, local);
|
||||||
|
|
||||||
if (PathEditorPlugin::singleton->mirror_angle_enabled())
|
if (PathEditorPlugin::singleton->mirror_angle_enabled())
|
||||||
c->set_point_out(idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_out_length));
|
c->set_point_out(idx, PathEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_out_length));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -873,6 +873,10 @@ void LightSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_idx,
|
||||||
Geometry::get_closest_points_between_segments(Vector3(), Vector3(0, 0, -4096), s[0], s[1], ra, rb);
|
Geometry::get_closest_points_between_segments(Vector3(), Vector3(0, 0, -4096), s[0], s[1], ra, rb);
|
||||||
|
|
||||||
float d = -ra.z;
|
float d = -ra.z;
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
if (d < 0)
|
if (d < 0)
|
||||||
d = 0;
|
d = 0;
|
||||||
|
|
||||||
|
@ -885,6 +889,10 @@ void LightSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_idx,
|
||||||
if (cp.intersects_ray(ray_from, ray_dir, &inters)) {
|
if (cp.intersects_ray(ray_from, ray_dir, &inters)) {
|
||||||
|
|
||||||
float r = inters.distance_to(gt.origin);
|
float r = inters.distance_to(gt.origin);
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
r = Math::stepify(r, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
light->set_param(Light::PARAM_RANGE, r);
|
light->set_param(Light::PARAM_RANGE, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1257,6 +1265,10 @@ void CameraSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_idx
|
||||||
Vector3 ra, rb;
|
Vector3 ra, rb;
|
||||||
Geometry::get_closest_points_between_segments(Vector3(0, 0, -1), Vector3(4096, 0, -1), s[0], s[1], ra, rb);
|
Geometry::get_closest_points_between_segments(Vector3(0, 0, -1), Vector3(4096, 0, -1), s[0], s[1], ra, rb);
|
||||||
float d = ra.x * 2.0;
|
float d = ra.x * 2.0;
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
if (d < 0)
|
if (d < 0)
|
||||||
d = 0;
|
d = 0;
|
||||||
|
|
||||||
|
@ -2310,6 +2322,9 @@ void VisibilityNotifierGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int
|
||||||
Geometry::get_closest_points_between_segments(ofs - axis * 4096, ofs + axis * 4096, sg[0], sg[1], ra, rb);
|
Geometry::get_closest_points_between_segments(ofs - axis * 4096, ofs + axis * 4096, sg[0], sg[1], ra, rb);
|
||||||
|
|
||||||
float d = ra[p_idx];
|
float d = ra[p_idx];
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
aabb.position[p_idx] = d - 1.0 - aabb.size[p_idx] * 0.5;
|
aabb.position[p_idx] = d - 1.0 - aabb.size[p_idx] * 0.5;
|
||||||
notifier->set_aabb(aabb);
|
notifier->set_aabb(aabb);
|
||||||
|
@ -2319,6 +2334,10 @@ void VisibilityNotifierGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int
|
||||||
Geometry::get_closest_points_between_segments(ofs, ofs + axis * 4096, sg[0], sg[1], ra, rb);
|
Geometry::get_closest_points_between_segments(ofs, ofs + axis * 4096, sg[0], sg[1], ra, rb);
|
||||||
|
|
||||||
float d = ra[p_idx] - ofs[p_idx];
|
float d = ra[p_idx] - ofs[p_idx];
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
if (d < 0.001)
|
if (d < 0.001)
|
||||||
d = 0.001;
|
d = 0.001;
|
||||||
//resize
|
//resize
|
||||||
|
@ -2444,7 +2463,6 @@ void ParticlesGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Ca
|
||||||
Particles *particles = Object::cast_to<Particles>(p_gizmo->get_spatial_node());
|
Particles *particles = Object::cast_to<Particles>(p_gizmo->get_spatial_node());
|
||||||
|
|
||||||
Transform gt = particles->get_global_transform();
|
Transform gt = particles->get_global_transform();
|
||||||
//gt.orthonormalize();
|
|
||||||
Transform gi = gt.affine_inverse();
|
Transform gi = gt.affine_inverse();
|
||||||
|
|
||||||
bool move = p_idx >= 3;
|
bool move = p_idx >= 3;
|
||||||
|
@ -2467,6 +2485,9 @@ void ParticlesGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Ca
|
||||||
Geometry::get_closest_points_between_segments(ofs - axis * 4096, ofs + axis * 4096, sg[0], sg[1], ra, rb);
|
Geometry::get_closest_points_between_segments(ofs - axis * 4096, ofs + axis * 4096, sg[0], sg[1], ra, rb);
|
||||||
|
|
||||||
float d = ra[p_idx];
|
float d = ra[p_idx];
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
aabb.position[p_idx] = d - 1.0 - aabb.size[p_idx] * 0.5;
|
aabb.position[p_idx] = d - 1.0 - aabb.size[p_idx] * 0.5;
|
||||||
particles->set_visibility_aabb(aabb);
|
particles->set_visibility_aabb(aabb);
|
||||||
|
@ -2476,6 +2497,10 @@ void ParticlesGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Ca
|
||||||
Geometry::get_closest_points_between_segments(ofs, ofs + axis * 4096, sg[0], sg[1], ra, rb);
|
Geometry::get_closest_points_between_segments(ofs, ofs + axis * 4096, sg[0], sg[1], ra, rb);
|
||||||
|
|
||||||
float d = ra[p_idx] - ofs[p_idx];
|
float d = ra[p_idx] - ofs[p_idx];
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
if (d < 0.001)
|
if (d < 0.001)
|
||||||
d = 0.001;
|
d = 0.001;
|
||||||
//resize
|
//resize
|
||||||
|
@ -2619,6 +2644,10 @@ void ReflectionProbeGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_i
|
||||||
Vector3 ra, rb;
|
Vector3 ra, rb;
|
||||||
Geometry::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb);
|
Geometry::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb);
|
||||||
float d = ra[p_idx];
|
float d = ra[p_idx];
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
if (d < 0.001)
|
if (d < 0.001)
|
||||||
d = 0.001;
|
d = 0.001;
|
||||||
|
|
||||||
|
@ -2641,8 +2670,11 @@ void ReflectionProbeGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_i
|
||||||
|
|
||||||
Vector3 ra, rb;
|
Vector3 ra, rb;
|
||||||
Geometry::get_closest_points_between_segments(origin - axis * 16384, origin + axis * 16384, sg[0], sg[1], ra, rb);
|
Geometry::get_closest_points_between_segments(origin - axis * 16384, origin + axis * 16384, sg[0], sg[1], ra, rb);
|
||||||
float d = ra[p_idx];
|
// Adjust the actual position to account for the gizmo handle position
|
||||||
d += 0.25;
|
float d = ra[p_idx] + 0.25;
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
origin[p_idx] = d;
|
origin[p_idx] = d;
|
||||||
probe->set_origin_offset(origin);
|
probe->set_origin_offset(origin);
|
||||||
|
@ -2780,7 +2812,6 @@ void GIProbeGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Came
|
||||||
GIProbe *probe = Object::cast_to<GIProbe>(p_gizmo->get_spatial_node());
|
GIProbe *probe = Object::cast_to<GIProbe>(p_gizmo->get_spatial_node());
|
||||||
|
|
||||||
Transform gt = probe->get_global_transform();
|
Transform gt = probe->get_global_transform();
|
||||||
//gt.orthonormalize();
|
|
||||||
Transform gi = gt.affine_inverse();
|
Transform gi = gt.affine_inverse();
|
||||||
|
|
||||||
Vector3 extents = probe->get_extents();
|
Vector3 extents = probe->get_extents();
|
||||||
|
@ -2796,6 +2827,10 @@ void GIProbeGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Came
|
||||||
Vector3 ra, rb;
|
Vector3 ra, rb;
|
||||||
Geometry::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb);
|
Geometry::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb);
|
||||||
float d = ra[p_idx];
|
float d = ra[p_idx];
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
if (d < 0.001)
|
if (d < 0.001)
|
||||||
d = 0.001;
|
d = 0.001;
|
||||||
|
|
||||||
|
@ -2945,7 +2980,6 @@ void BakedIndirectLightGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int
|
||||||
BakedLightmap *baker = Object::cast_to<BakedLightmap>(p_gizmo->get_spatial_node());
|
BakedLightmap *baker = Object::cast_to<BakedLightmap>(p_gizmo->get_spatial_node());
|
||||||
|
|
||||||
Transform gt = baker->get_global_transform();
|
Transform gt = baker->get_global_transform();
|
||||||
//gt.orthonormalize();
|
|
||||||
Transform gi = gt.affine_inverse();
|
Transform gi = gt.affine_inverse();
|
||||||
|
|
||||||
Vector3 extents = baker->get_extents();
|
Vector3 extents = baker->get_extents();
|
||||||
|
@ -2961,6 +2995,10 @@ void BakedIndirectLightGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int
|
||||||
Vector3 ra, rb;
|
Vector3 ra, rb;
|
||||||
Geometry::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb);
|
Geometry::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb);
|
||||||
float d = ra[p_idx];
|
float d = ra[p_idx];
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
if (d < 0.001)
|
if (d < 0.001)
|
||||||
d = 0.001;
|
d = 0.001;
|
||||||
|
|
||||||
|
@ -3158,6 +3196,10 @@ void CollisionShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, i
|
||||||
Vector3 ra, rb;
|
Vector3 ra, rb;
|
||||||
Geometry::get_closest_points_between_segments(Vector3(), Vector3(4096, 0, 0), sg[0], sg[1], ra, rb);
|
Geometry::get_closest_points_between_segments(Vector3(), Vector3(4096, 0, 0), sg[0], sg[1], ra, rb);
|
||||||
float d = ra.x;
|
float d = ra.x;
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
if (d < 0.001)
|
if (d < 0.001)
|
||||||
d = 0.001;
|
d = 0.001;
|
||||||
|
|
||||||
|
@ -3170,6 +3212,10 @@ void CollisionShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, i
|
||||||
Vector3 ra, rb;
|
Vector3 ra, rb;
|
||||||
Geometry::get_closest_points_between_segments(Vector3(), Vector3(0, 0, 4096), sg[0], sg[1], ra, rb);
|
Geometry::get_closest_points_between_segments(Vector3(), Vector3(0, 0, 4096), sg[0], sg[1], ra, rb);
|
||||||
float d = ra.z;
|
float d = ra.z;
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
if (d < 0.001)
|
if (d < 0.001)
|
||||||
d = 0.001;
|
d = 0.001;
|
||||||
|
|
||||||
|
@ -3184,6 +3230,10 @@ void CollisionShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, i
|
||||||
Vector3 ra, rb;
|
Vector3 ra, rb;
|
||||||
Geometry::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
|
Geometry::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
|
||||||
float d = ra[p_idx];
|
float d = ra[p_idx];
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
if (d < 0.001)
|
if (d < 0.001)
|
||||||
d = 0.001;
|
d = 0.001;
|
||||||
|
|
||||||
|
@ -3202,6 +3252,11 @@ void CollisionShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, i
|
||||||
float d = axis.dot(ra);
|
float d = axis.dot(ra);
|
||||||
if (p_idx == 1)
|
if (p_idx == 1)
|
||||||
d -= cs2->get_radius();
|
d -= cs2->get_radius();
|
||||||
|
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
if (d < 0.001)
|
if (d < 0.001)
|
||||||
d = 0.001;
|
d = 0.001;
|
||||||
|
|
||||||
|
@ -3219,6 +3274,9 @@ void CollisionShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, i
|
||||||
Vector3 ra, rb;
|
Vector3 ra, rb;
|
||||||
Geometry::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
|
Geometry::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
|
||||||
float d = axis.dot(ra);
|
float d = axis.dot(ra);
|
||||||
|
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||||
|
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||||
|
}
|
||||||
|
|
||||||
if (d < 0.001)
|
if (d < 0.001)
|
||||||
d = 0.001;
|
d = 0.001;
|
||||||
|
|
Loading…
Reference in New Issue