vertex snapping refactor corrections
This commit is contained in:
@@ -85,6 +85,7 @@ namespace FlaxEditor.Gizmo
|
||||
{
|
||||
InitDrawing();
|
||||
ModeChanged += ResetTranslationScale;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -437,8 +438,6 @@ namespace FlaxEditor.Gizmo
|
||||
{
|
||||
case Mode.Translate:
|
||||
UpdateTranslateScale();
|
||||
if (Owner.SnapToVertex)
|
||||
UpdateVertexSnapping();
|
||||
break;
|
||||
case Mode.Scale:
|
||||
UpdateTranslateScale();
|
||||
@@ -447,6 +446,8 @@ namespace FlaxEditor.Gizmo
|
||||
UpdateRotate(dt);
|
||||
break;
|
||||
}
|
||||
if (Owner.SnapToVertex)
|
||||
UpdateVertexSnapping();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -553,43 +554,23 @@ namespace FlaxEditor.Gizmo
|
||||
for (int i = 0; i < SelectionCount; i++)
|
||||
{
|
||||
var obj = GetSelectedObject(i);
|
||||
if (obj.CanVertexSnap && obj.RayCastSelf(ref ray, out var distance, out _) && distance < closestDistance)
|
||||
if (obj.RayCastSelf(ref ray, out var distance, out _) && distance < closestDistance)
|
||||
{
|
||||
closestDistance = distance;
|
||||
closestObject = obj;
|
||||
}
|
||||
}
|
||||
if (closestObject == null)
|
||||
{
|
||||
// Find the closest object in selection (in case ray didn't hit anything)
|
||||
for (int i = 0; i < SelectionCount; i++)
|
||||
{
|
||||
var obj = GetSelectedObject(i);
|
||||
if (obj.CanVertexSnap)
|
||||
{
|
||||
GetSelectedObjectsBounds(out var bounds, out _);
|
||||
CollisionsHelper.ClosestPointBoxPoint(ref bounds, ref ray.Ray.Position, out var point);
|
||||
var distance = Vector3.Distance(ref point, ref ray.Ray.Position);
|
||||
if (distance < closestDistance)
|
||||
{
|
||||
closestDistance = distance;
|
||||
closestObject = obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return; // ignore it if there is nothing under the mouse closestObject is only null if ray caster missed everything or Selection Count == 0
|
||||
|
||||
_vertexSnapObject = closestObject;
|
||||
if (closestObject == null)
|
||||
return;
|
||||
|
||||
// Find the closest vertex to bounding box point (collision detection approximation)
|
||||
var closestPoint = ray.Ray.GetPoint(closestDistance);
|
||||
if (!closestObject.OnVertexSnap(ref closestPoint, out _vertexSnapPoint))
|
||||
if (!closestObject.OnVertexSnap(ref ray.Ray, closestDistance, out _vertexSnapPoint))
|
||||
{
|
||||
// Failed to get the closest point
|
||||
_vertexSnapPoint = closestPoint;
|
||||
//The OnVertexSnap is unimplemented or failed to get point return because there is nothing to do
|
||||
_vertexSnapPoint = Vector3.Zero;
|
||||
return;
|
||||
}
|
||||
|
||||
// Transform back to the local space of the object to work when moving it
|
||||
_vertexSnapPoint = closestObject.Transform.WorldToLocal(_vertexSnapPoint);
|
||||
}
|
||||
@@ -619,10 +600,9 @@ namespace FlaxEditor.Gizmo
|
||||
for (int i = 0; i < SelectionCount; i++)
|
||||
rayCast.ExcludeObjects.Add(GetSelectedObject(i));
|
||||
var hit = Owner.SceneGraphRoot.RayCast(ref rayCast, out var distance, out var _);
|
||||
if (hit != null && hit.CanVertexSnap)
|
||||
if (hit != null)
|
||||
{
|
||||
var point = rayCast.Ray.GetPoint(distance);
|
||||
if (hit.OnVertexSnap(ref point, out var pointSnapped)
|
||||
if (hit.OnVertexSnap(ref rayCast.Ray, distance, out var pointSnapped)
|
||||
//&& Vector3.Distance(point, pointSnapped) <= 25.0f
|
||||
)
|
||||
{
|
||||
@@ -712,5 +692,11 @@ namespace FlaxEditor.Gizmo
|
||||
protected virtual void OnDuplicate()
|
||||
{
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public override void OnSelectionChanged(List<SceneGraphNode> newSelection)
|
||||
{
|
||||
EndVertexSnapping();
|
||||
UpdateGizmoPosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user