diff --git a/Source/Editor/Gizmo/TransformGizmoBase.Draw.cs b/Source/Editor/Gizmo/TransformGizmoBase.Draw.cs
index a182fd149..dc1d7035e 100644
--- a/Source/Editor/Gizmo/TransformGizmoBase.Draw.cs
+++ b/Source/Editor/Gizmo/TransformGizmoBase.Draw.cs
@@ -57,6 +57,8 @@ namespace FlaxEditor.Gizmo
{
if (!_isActive || !IsActive)
return;
+ if (!_modelCube || !_modelCube.IsLoaded)
+ return;
// As all axisMesh have the same pivot, add a little offset to the x axisMesh, this way SortDrawCalls is able to sort the draw order
// https://github.com/FlaxEngine/FlaxEngine/issues/680
@@ -71,7 +73,8 @@ namespace FlaxEditor.Gizmo
renderContext.View.GetWorldMatrix(ref _gizmoWorld, out Matrix world);
const float gizmoModelsScale2RealGizmoSize = 0.075f;
- Mesh sphereMesh, cubeMesh;
+ Mesh cubeMesh = _modelCube.LODs[0].Meshes[0];
+ Mesh sphereMesh = _modelSphere.LODs[0].Meshes[0];
Matrix.Scaling(gizmoModelsScale2RealGizmoSize, out m3);
Matrix.Multiply(ref m3, ref world, out m1);
@@ -82,11 +85,9 @@ namespace FlaxEditor.Gizmo
{
case Mode.Translate:
{
- if (!_modelTranslationAxis || !_modelTranslationAxis.IsLoaded || !_modelCube || !_modelCube.IsLoaded || !_modelSphere || !_modelSphere.IsLoaded)
+ if (!_modelTranslationAxis || !_modelTranslationAxis.IsLoaded)
break;
var transAxisMesh = _modelTranslationAxis.LODs[0].Meshes[0];
- cubeMesh = _modelCube.LODs[0].Meshes[0];
- sphereMesh = _modelSphere.LODs[0].Meshes[0];
// X axis
Matrix.RotationY(-Mathf.PiOverTwo, out m2);
@@ -128,10 +129,9 @@ namespace FlaxEditor.Gizmo
case Mode.Rotate:
{
- if (!_modelRotationAxis || !_modelRotationAxis.IsLoaded || !_modelSphere || !_modelSphere.IsLoaded)
+ if (!_modelRotationAxis || !_modelRotationAxis.IsLoaded)
break;
var rotationAxisMesh = _modelRotationAxis.LODs[0].Meshes[0];
- sphereMesh = _modelSphere.LODs[0].Meshes[0];
// X axis
Matrix.RotationZ(Mathf.PiOverTwo, out m2);
@@ -156,11 +156,9 @@ namespace FlaxEditor.Gizmo
case Mode.Scale:
{
- if (!_modelScaleAxis || !_modelScaleAxis.IsLoaded || !_modelCube || !_modelCube.IsLoaded || !_modelSphere || !_modelSphere.IsLoaded)
+ if (!_modelScaleAxis || !_modelScaleAxis.IsLoaded)
break;
var scaleAxisMesh = _modelScaleAxis.LODs[0].Meshes[0];
- cubeMesh = _modelCube.LODs[0].Meshes[0];
- sphereMesh = _modelSphere.LODs[0].Meshes[0];
// X axis
Matrix.RotationY(-Mathf.PiOverTwo, out m2);
@@ -202,24 +200,12 @@ namespace FlaxEditor.Gizmo
}
// Vertex snapping
- if (_vertexSnapObject != null)
+ if (_vertexSnapObject != null || _vertexSnapObjectTo != null)
{
- if (!_modelCube || !_modelCube.IsLoaded)
- return;
- cubeMesh = _modelCube.LODs[0].Meshes[0];
-
- Transform t = _vertexSnapObject.Transform;
- Vector3 p = t.LocalToWorld(_vertexSnapPoint);
+ Transform t = _vertexSnapObject?.Transform ?? _vertexSnapObjectTo.Transform;
+ Vector3 p = t.LocalToWorld(_vertexSnapObject != null ? _vertexSnapPoint : _vertexSnapPointTo);
Matrix matrix = new Transform(p, t.Orientation, new Float3(gizmoModelsScale2RealGizmoSize)).GetWorld();
cubeMesh.Draw(ref renderContext, _materialSphere, ref matrix);
-
- if (_vertexSnapObjectTo != null)
- {
- t = _vertexSnapObjectTo.Transform;
- p = t.LocalToWorld(_vertexSnapPointTo);
- matrix = new Transform(p, t.Orientation, new Float3(gizmoModelsScale2RealGizmoSize)).GetWorld();
- cubeMesh.Draw(ref renderContext, _materialSphere, ref matrix);
- }
}
}
}
diff --git a/Source/Editor/Gizmo/TransformGizmoBase.cs b/Source/Editor/Gizmo/TransformGizmoBase.cs
index bb6522047..5919bda75 100644
--- a/Source/Editor/Gizmo/TransformGizmoBase.cs
+++ b/Source/Editor/Gizmo/TransformGizmoBase.cs
@@ -605,7 +605,7 @@ namespace FlaxEditor.Gizmo
private void UpdateVertexSnapping()
{
_vertexSnapObjectTo = null;
- if (Owner.SceneGraphRoot == null || _vertexSnapObject == null)
+ if (Owner.SceneGraphRoot == null)
return;
Profiler.BeginEvent("VertexSnap");
@@ -629,10 +629,8 @@ namespace FlaxEditor.Gizmo
_vertexSnapObjectTo = hit;
_vertexSnapPointTo = hit.Transform.WorldToLocal(pointSnapped);
- // Snap current vertex to the other vertex
- Vector3 selected = _vertexSnapObject.Transform.LocalToWorld(_vertexSnapPoint);
- Vector3 other = _vertexSnapObjectTo.Transform.LocalToWorld(_vertexSnapPointTo);
- _translationDelta = other - selected;
+ // Snap current vertex to the target vertex
+ _translationDelta = pointSnapped - Position;
}
}
diff --git a/Source/Editor/SceneGraph/SceneGraphNode.cs b/Source/Editor/SceneGraph/SceneGraphNode.cs
index cab2e9b6a..d805f92bf 100644
--- a/Source/Editor/SceneGraph/SceneGraphNode.cs
+++ b/Source/Editor/SceneGraph/SceneGraphNode.cs
@@ -231,7 +231,7 @@ namespace FlaxEditor.SceneGraph
///
/// The list of objects to exclude from tracing against. Null if unused.
///
- public List