Merge branch 'master' of https://github.com/FlaxEngine/FlaxEngine into double-vectors

This commit is contained in:
Jean-Baptiste Perrier
2021-08-12 20:49:10 +02:00
13 changed files with 106 additions and 16 deletions

View File

@@ -80,6 +80,13 @@ namespace FlaxEditor.Gizmo
{
}
/// <summary>
/// Performs scene objects snapping to the ground.
/// </summary>
public virtual void SnapToGround()
{
}
/// <summary>
/// Draws the gizmo.
/// </summary>

View File

@@ -89,5 +89,10 @@ namespace FlaxEditor.Gizmo
/// Gets a <see cref="FlaxEditor.Undo"/> object used by the gizmo owner.
/// </summary>
Undo Undo { get; }
/// <summary>
/// Gets the root tree node for the scene graph.
/// </summary>
SceneGraph.RootNode SceneGraphRoot { get; }
}
}

View File

@@ -218,6 +218,12 @@ namespace FlaxEditor.Gizmo
}
}
/// <inheritdoc />
protected override bool IsSelected(SceneGraphNode obj)
{
return _selection.Contains(obj);
}
/// <inheritdoc />
protected override void OnApplyTransformation(ref Vector3 translationDelta, ref Quaternion rotationDelta, ref Vector3 scaleDelta)
{

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using FlaxEditor.SceneGraph;
using FlaxEngine;
namespace FlaxEditor.Gizmo
@@ -398,15 +399,7 @@ namespace FlaxEditor.Gizmo
// Snap to ground
if (_activeAxis == Axis.None && SelectionCount != 0 && Owner.SnapToGround)
{
if (Physics.RayCast(Position, Vector3.Down, out var hit, float.MaxValue, uint.MaxValue, false))
{
StartTransforming();
var translationDelta = hit.Point - Position;
var rotationDelta = Quaternion.Identity;
var scaleDelta = Vector3.Zero;
OnApplyTransformation(ref translationDelta, ref rotationDelta, ref scaleDelta);
EndTransforming();
}
SnapToGround();
}
// Only when is active
else if (_isActive)
@@ -517,6 +510,39 @@ namespace FlaxEditor.Gizmo
UpdateMatrices();
}
/// <inheritdoc />
public override void SnapToGround()
{
if (Owner.SceneGraphRoot == null)
return;
var ray = new Ray(Position, Vector3.Down);
while (true)
{
var view = new Ray(Owner.ViewPosition, Owner.ViewDirection);
var rayCastFlags = SceneGraphNode.RayCastData.FlagTypes.SkipEditorPrimitives;
var hit = Owner.SceneGraphRoot.RayCast(ref ray, ref view, out var distance, out _, rayCastFlags);
if (hit != null)
{
// Skip snapping selection to itself
if (IsSelected(hit))
{
GetSelectedObjectsBounds(out var selectionBounds, out _);
ray.Position = ray.GetPoint(selectionBounds.Size.Y * 0.5f);
continue;
}
// Snap
StartTransforming();
var translationDelta = ray.GetPoint(distance) - Position;
var rotationDelta = Quaternion.Identity;
var scaleDelta = Vector3.Zero;
OnApplyTransformation(ref translationDelta, ref rotationDelta, ref scaleDelta);
EndTransforming();
}
break;
}
}
/// <summary>
/// Gets a value indicating whether this tool can transform objects.
/// </summary>
@@ -545,6 +571,13 @@ namespace FlaxEditor.Gizmo
/// <param name="navigationDirty">True if editing the selected objects transformations marks the navigation system area dirty (for auto-rebuild), otherwise skip update.</param>
protected abstract void GetSelectedObjectsBounds(out BoundingBox bounds, out bool navigationDirty);
/// <summary>
/// Checks if the specified object is selected.
/// </summary>
/// <param name="obj">The object to check.</param>
/// <returns>True if it's selected, otherwise false.</returns>
protected abstract bool IsSelected(SceneGraphNode obj);
/// <summary>
/// Called when user starts transforming selected objects.
/// </summary>

View File

@@ -383,6 +383,7 @@ namespace FlaxEditor.Modules
var objects = Selection.Where(x => x.CanDelete).ToList().BuildAllNodes().Where(x => x.CanDelete).ToList();
if (objects.Count == 0)
return;
var isSceneTreeFocus = Editor.Windows.SceneWin.ContainsFocus;
SelectionDeleteBegin?.Invoke();
@@ -404,6 +405,9 @@ namespace FlaxEditor.Modules
SelectionDeleteEnd?.Invoke();
OnDirty(objects);
if (isSceneTreeFocus)
Editor.Windows.SceneWin.Focus();
}
/// <summary>

View File

@@ -2,6 +2,7 @@
using System;
using FlaxEditor.Gizmo;
using FlaxEditor.SceneGraph;
using FlaxEditor.Tools.Foliage.Undo;
using FlaxEngine;
@@ -87,6 +88,12 @@ namespace FlaxEditor.Tools.Foliage
navigationDirty = false;
}
/// <inheritdoc />
protected override bool IsSelected(SceneGraphNode obj)
{
return false;
}
/// <inheritdoc />
protected override void OnStartTransforming()
{
@@ -231,6 +238,21 @@ namespace FlaxEditor.Tools.Foliage
Owner.Undo?.AddAction(action);
}
/// <inheritdoc />
public override void SnapToGround()
{
if (Physics.RayCast(Position, Vector3.Down, out var hit, float.MaxValue, uint.MaxValue, false))
{
// Snap
StartTransforming();
var translationDelta = hit.Point - Position;
var rotationDelta = Quaternion.Identity;
var scaleDelta = Vector3.Zero;
OnApplyTransformation(ref translationDelta, ref rotationDelta, ref scaleDelta);
EndTransforming();
}
}
/// <inheritdoc />
public override void OnActivated()
{

View File

@@ -21,10 +21,12 @@ namespace FlaxEditor.Viewport
/// </summary>
/// <param name="task">The task.</param>
/// <param name="undo">The undo.</param>
public EditorGizmoViewport(SceneRenderTask task, Undo undo)
/// <param name="sceneGraphRoot">The scene graph root.</param>
public EditorGizmoViewport(SceneRenderTask task, Undo undo, SceneGraph.RootNode sceneGraphRoot)
: base(task, new FPSCamera(), true)
{
Undo = undo;
SceneGraphRoot = sceneGraphRoot;
SetUpdate(ref _update, OnUpdate);
}
@@ -73,6 +75,9 @@ namespace FlaxEditor.Viewport
/// <inheritdoc />
public Undo Undo { get; }
/// <inheritdoc />
public SceneGraph.RootNode SceneGraphRoot { get; }
/// <inheritdoc />
protected override bool IsControllingMouse => Gizmos.Active?.IsControllingMouse ?? false;

View File

@@ -184,7 +184,7 @@ namespace FlaxEditor.Viewport
/// </summary>
/// <param name="editor">Editor instance.</param>
public MainEditorGizmoViewport(Editor editor)
: base(Object.New<SceneRenderTask>(), editor.Undo)
: base(Object.New<SceneRenderTask>(), editor.Undo, editor.Scene.Root)
{
_editor = editor;
_dragAssets = new DragAssets<DragDropEventArgs>(ValidateDragItem);

View File

@@ -336,6 +336,9 @@ namespace FlaxEditor.Viewport
/// <inheritdoc />
public Undo Undo { get; }
/// <inheritdoc />
public RootNode SceneGraphRoot => _window.Graph.Root;
/// <inheritdoc />
public EditorViewport Viewport => this;

View File

@@ -29,6 +29,7 @@ namespace FlaxEditor.Windows
: base(editor, true, ScrollBars.Vertical)
{
Title = "Properties";
AutoFocus = true;
Presenter = new CustomEditorPresenter(editor.Undo);
Presenter.Panel.Parent = this;

View File

@@ -25,13 +25,13 @@ public:
/// <summary>
/// The fog density factor.
/// </summary>
API_FIELD(Attributes="EditorOrder(10), DefaultValue(0.02f), Limit(0.000001f, 0.8f, 0.001f), EditorDisplay(\"Exponential Height Fog\")")
API_FIELD(Attributes="EditorOrder(10), DefaultValue(0.02f), Limit(0.0000001f, 100.0f, 0.001f), EditorDisplay(\"Exponential Height Fog\")")
float FogDensity = 0.02f;
/// <summary>
/// The fog height density factor that controls how the density increases as height decreases. The smaller values produce more visible transition larger.
/// </summary>
API_FIELD(Attributes="EditorOrder(20), DefaultValue(0.2f), Limit(0.001f, 2.0f, 0.001f), EditorDisplay(\"Exponential Height Fog\")")
API_FIELD(Attributes="EditorOrder(20), DefaultValue(0.2f), Limit(0.0001f, 10.0f, 0.001f), EditorDisplay(\"Exponential Height Fog\")")
float FogHeightFalloff = 0.2f;
/// <summary>

View File

@@ -324,13 +324,12 @@ void WheeledVehicle::Setup()
wheelData.mMaxHandBrakeTorque = M2ToCm2(wheel.MaxHandBrakeTorque);
PxVec3 centreOffset = centerOfMassOffset.transformInv(offsets[i]);
float suspensionForceOffset = 0.0f;
PxVec3 forceAppPointOffset(centreOffset.x, centreOffset.y, centreOffset.z + suspensionForceOffset);
PxVec3 forceAppPointOffset(centreOffset.z, centreOffset.y + wheel.SuspensionForceOffset, centreOffset.z);
wheelsSimData->setTireData(i, tire);
wheelsSimData->setWheelData(i, wheelData);
wheelsSimData->setSuspensionData(i, suspensionData);
wheelsSimData->setSuspTravelDirection(i, PxVec3(0, -1, 0));
wheelsSimData->setSuspTravelDirection(i, centerOfMassOffset.rotate(PxVec3(0.0f, -1.0f, 0.0f)));
wheelsSimData->setWheelCentreOffset(i, centreOffset);
wheelsSimData->setSuspForceAppPointOffset(i, forceAppPointOffset);
wheelsSimData->setTireForceAppPointOffset(i, forceAppPointOffset);

View File

@@ -228,6 +228,11 @@ public:
/// The maximum offset for the suspension that wheel can go below resting location.
/// </summary>
API_FIELD(Attributes="Limit(0)") float SuspensionMaxDrop = 10.0f;
/// <summary>
/// The vertical offset from where suspension forces are applied.
/// </summary>
API_FIELD() float SuspensionForceOffset = 0.0f;
};
/// <summary>