diff --git a/Source/Editor/Gizmo/TransformGizmoBase.cs b/Source/Editor/Gizmo/TransformGizmoBase.cs index 290795fa0..81f76d392 100644 --- a/Source/Editor/Gizmo/TransformGizmoBase.cs +++ b/Source/Editor/Gizmo/TransformGizmoBase.cs @@ -85,7 +85,6 @@ namespace FlaxEditor.Gizmo { InitDrawing(); ModeChanged += ResetTranslationScale; - } /// @@ -564,13 +563,13 @@ namespace FlaxEditor.Gizmo 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.OnVertexSnap(ref ray.Ray, closestDistance, out _vertexSnapPoint)) { - //The OnVertexSnap is unimplemented or failed to get point return because there is nothing to do + // 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); } @@ -602,9 +601,9 @@ namespace FlaxEditor.Gizmo var hit = Owner.SceneGraphRoot.RayCast(ref rayCast, out var distance, out var _); if (hit != null) { - if (hit.OnVertexSnap(ref rayCast.Ray, distance, out var pointSnapped) + if (hit.OnVertexSnap(ref rayCast.Ray, distance, out var pointSnapped) //&& Vector3.Distance(point, pointSnapped) <= 25.0f - ) + ) { _vertexSnapObjectTo = hit; _vertexSnapPointTo = hit.Transform.WorldToLocal(pointSnapped); @@ -692,6 +691,7 @@ namespace FlaxEditor.Gizmo protected virtual void OnDuplicate() { } + /// public override void OnSelectionChanged(List newSelection) { diff --git a/Source/Editor/SceneGraph/Actors/StaticModelNode.cs b/Source/Editor/SceneGraph/Actors/StaticModelNode.cs index 0a8fd48bb..1c09691e5 100644 --- a/Source/Editor/SceneGraph/Actors/StaticModelNode.cs +++ b/Source/Editor/SceneGraph/Actors/StaticModelNode.cs @@ -23,13 +23,12 @@ namespace FlaxEditor.SceneGraph.Actors : base(actor) { } - + /// public override bool OnVertexSnap(ref Ray ray, float hitDistance, out Vector3 result) { // Find the closest vertex to bounding box point (collision detection approximation) - result = ray.GetPoint(hitDistance); var model = ((StaticModel)Actor).Model; if (model && !model.WaitForLoaded()) @@ -39,7 +38,8 @@ namespace FlaxEditor.SceneGraph.Actors _vertices = new(); var pointLocal = (Float3)Actor.Transform.WorldToLocal(result); var minDistance = float.MaxValue; - foreach (var lod in model.LODs) //[ToDo] fix it [Nori_SC note] this is wrong it should get current lod level going it throw all lods will create ghost snaping points + var lodIndex = 0; // TODO: use LOD index based on the game view + var lod = model.LODs[lodIndex]; { var hit = false; foreach (var mesh in lod.Meshes) diff --git a/Source/Editor/SceneGraph/SceneGraphNode.cs b/Source/Editor/SceneGraph/SceneGraphNode.cs index e9020592d..dd6a4f9fe 100644 --- a/Source/Editor/SceneGraph/SceneGraphNode.cs +++ b/Source/Editor/SceneGraph/SceneGraphNode.cs @@ -355,11 +355,11 @@ namespace FlaxEditor.SceneGraph /// /// Performs the vertex snapping for a given ray and hitDistance. /// - /// Raycasted ray - /// Hit distance from ray to object bounding box + /// The ray to raycast. + /// Hit distance from ray to object bounding box. /// The result point on the object mesh that is closest to the specified location. /// True if got a valid result value, otherwise false (eg. if missing data or not initialized). - public virtual bool OnVertexSnap(ref Ray ray,float hitDistance, out Vector3 result) // [NoriSC note] ray and hit Distance will be needed for a future use, in mesh types for proper collision detection + public virtual bool OnVertexSnap(ref Ray ray, float hitDistance, out Vector3 result) { result = Vector3.Zero; return false;