@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ namespace FlaxEditor.SceneGraph
|
||||
/// <summary>
|
||||
/// The list of objects to exclude from tracing against. Null if unused.
|
||||
/// </summary>
|
||||
public List<object> ExcludeObjects;
|
||||
public List<SceneGraphNode> ExcludeObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RayCastData"/> struct.
|
||||
@@ -326,19 +326,12 @@ namespace FlaxEditor.SceneGraph
|
||||
|
||||
private bool RayMask(ref RayCastData ray)
|
||||
{
|
||||
if (ray.ExcludeObjects != null)
|
||||
if (ray.ExcludeObjects != null && ray.ExcludeObjects.Remove(this))
|
||||
{
|
||||
for (int j = 0; j < ray.ExcludeObjects.Count; j++)
|
||||
{
|
||||
if (ray.ExcludeObjects[j] == EditableObject)
|
||||
{
|
||||
// Remove form exclude because it is passed by ref and function is recursive it will slowly shrink the list until nothing is left as a micro optimization
|
||||
ray.ExcludeObjects.RemoveAt(j);
|
||||
if (ray.ExcludeObjects.Count == 0)
|
||||
ray.ExcludeObjects = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Remove form exclude because it is passed by ref and function is recursive it will slowly shrink the list until nothing is left as a micro optimization
|
||||
if (ray.ExcludeObjects.Count == 0)
|
||||
ray.ExcludeObjects = null;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user