Merge remote-tracking branch 'origin/master' into 1.9
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using FlaxEditor.CustomEditors.Elements;
|
||||
using FlaxEditor.Surface;
|
||||
using FlaxEngine;
|
||||
|
||||
@@ -12,6 +14,8 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
||||
[CustomEditor(typeof(AnimatedModel)), DefaultEditor]
|
||||
public class AnimatedModelEditor : ActorEditor
|
||||
{
|
||||
private bool _parametersAdded = false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize(LayoutElementsContainer layout)
|
||||
{
|
||||
@@ -31,6 +35,24 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
||||
(instance, parameter, tag) => ((AnimatedModel)instance).GetParameterValue(parameter.Identifier),
|
||||
(instance, value, parameter, tag) => ((AnimatedModel)instance).SetParameterValue(parameter.Identifier, value),
|
||||
Values);
|
||||
_parametersAdded = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Refresh()
|
||||
{
|
||||
base.Refresh();
|
||||
|
||||
// Check if parameters group is still showing if not in play mode and hide it.
|
||||
if (!Editor.Instance.StateMachine.IsPlayMode && _parametersAdded)
|
||||
{
|
||||
var group = Layout.Children.Find(x => x is GroupElement g && g.Panel.HeaderText.Equals("Parameters", StringComparison.Ordinal));
|
||||
if (group != null)
|
||||
{
|
||||
RebuildLayout();
|
||||
_parametersAdded = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,6 +178,8 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
return 1;
|
||||
if (Info.MetadataToken < other.Info.MetadataToken)
|
||||
return -1;
|
||||
// Keep declaration order if same metadata token.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// By name
|
||||
|
||||
@@ -138,18 +138,17 @@ namespace FlaxEditor.Gizmo
|
||||
|
||||
private void UpdateGizmoPosition()
|
||||
{
|
||||
var position = Vector3.Zero;
|
||||
|
||||
// Get gizmo pivot
|
||||
switch (_activePivotType)
|
||||
{
|
||||
case PivotType.ObjectCenter:
|
||||
if (SelectionCount > 0)
|
||||
Position = GetSelectedTransform(0).Translation;
|
||||
position = GetSelectedTransform(0).Translation;
|
||||
break;
|
||||
case PivotType.SelectionCenter:
|
||||
Position = GetSelectionCenter();
|
||||
break;
|
||||
case PivotType.WorldOrigin:
|
||||
Position = Vector3.Zero;
|
||||
position = GetSelectionCenter();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -157,11 +156,13 @@ namespace FlaxEditor.Gizmo
|
||||
if (_vertexSnapObject != null)
|
||||
{
|
||||
Vector3 vertexSnapPoint = _vertexSnapObject.Transform.LocalToWorld(_vertexSnapPoint);
|
||||
Position += vertexSnapPoint - Position;
|
||||
position += vertexSnapPoint - position;
|
||||
}
|
||||
|
||||
// Apply current movement
|
||||
Position += _translationDelta;
|
||||
position += _translationDelta;
|
||||
|
||||
Position = position;
|
||||
}
|
||||
|
||||
private void UpdateMatrices()
|
||||
@@ -213,10 +214,11 @@ namespace FlaxEditor.Gizmo
|
||||
ray.Position = Vector3.Transform(ray.Position, invRotationMatrix);
|
||||
Vector3.TransformNormal(ref ray.Direction, ref invRotationMatrix, out ray.Direction);
|
||||
|
||||
var planeXY = new Plane(Vector3.Backward, Vector3.Transform(Position, invRotationMatrix).Z);
|
||||
var planeYZ = new Plane(Vector3.Left, Vector3.Transform(Position, invRotationMatrix).X);
|
||||
var planeZX = new Plane(Vector3.Down, Vector3.Transform(Position, invRotationMatrix).Y);
|
||||
var dir = Vector3.Normalize(ray.Position - Position);
|
||||
var position = Position;
|
||||
var planeXY = new Plane(Vector3.Backward, Vector3.Transform(position, invRotationMatrix).Z);
|
||||
var planeYZ = new Plane(Vector3.Left, Vector3.Transform(position, invRotationMatrix).X);
|
||||
var planeZX = new Plane(Vector3.Down, Vector3.Transform(position, invRotationMatrix).Y);
|
||||
var dir = Vector3.Normalize(ray.Position - position);
|
||||
var planeDotXY = Mathf.Abs(Vector3.Dot(planeXY.Normal, dir));
|
||||
var planeDotYZ = Mathf.Abs(Vector3.Dot(planeYZ.Normal, dir));
|
||||
var planeDotZX = Mathf.Abs(Vector3.Dot(planeZX.Normal, dir));
|
||||
@@ -229,8 +231,8 @@ namespace FlaxEditor.Gizmo
|
||||
var plane = planeDotXY > planeDotZX ? planeXY : planeZX;
|
||||
if (ray.Intersects(ref plane, out intersection))
|
||||
{
|
||||
_intersectPosition = ray.Position + ray.Direction * intersection;
|
||||
if (_lastIntersectionPosition != Vector3.Zero)
|
||||
_intersectPosition = ray.GetPoint(intersection);
|
||||
if (!_lastIntersectionPosition.IsZero)
|
||||
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
||||
delta = new Vector3(_tDelta.X, 0, 0);
|
||||
}
|
||||
@@ -241,8 +243,8 @@ namespace FlaxEditor.Gizmo
|
||||
var plane = planeDotXY > planeDotYZ ? planeXY : planeYZ;
|
||||
if (ray.Intersects(ref plane, out intersection))
|
||||
{
|
||||
_intersectPosition = ray.Position + ray.Direction * intersection;
|
||||
if (_lastIntersectionPosition != Vector3.Zero)
|
||||
_intersectPosition = ray.GetPoint(intersection);
|
||||
if (!_lastIntersectionPosition.IsZero)
|
||||
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
||||
delta = new Vector3(0, _tDelta.Y, 0);
|
||||
}
|
||||
@@ -253,8 +255,8 @@ namespace FlaxEditor.Gizmo
|
||||
var plane = planeDotZX > planeDotYZ ? planeZX : planeYZ;
|
||||
if (ray.Intersects(ref plane, out intersection))
|
||||
{
|
||||
_intersectPosition = ray.Position + ray.Direction * intersection;
|
||||
if (_lastIntersectionPosition != Vector3.Zero)
|
||||
_intersectPosition = ray.GetPoint(intersection);
|
||||
if (!_lastIntersectionPosition.IsZero)
|
||||
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
||||
delta = new Vector3(0, 0, _tDelta.Z);
|
||||
}
|
||||
@@ -264,8 +266,8 @@ namespace FlaxEditor.Gizmo
|
||||
{
|
||||
if (ray.Intersects(ref planeYZ, out intersection))
|
||||
{
|
||||
_intersectPosition = ray.Position + ray.Direction * intersection;
|
||||
if (_lastIntersectionPosition != Vector3.Zero)
|
||||
_intersectPosition = ray.GetPoint(intersection);
|
||||
if (!_lastIntersectionPosition.IsZero)
|
||||
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
||||
delta = new Vector3(0, _tDelta.Y, _tDelta.Z);
|
||||
}
|
||||
@@ -275,8 +277,8 @@ namespace FlaxEditor.Gizmo
|
||||
{
|
||||
if (ray.Intersects(ref planeXY, out intersection))
|
||||
{
|
||||
_intersectPosition = ray.Position + ray.Direction * intersection;
|
||||
if (_lastIntersectionPosition != Vector3.Zero)
|
||||
_intersectPosition = ray.GetPoint(intersection);
|
||||
if (!_lastIntersectionPosition.IsZero)
|
||||
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
||||
delta = new Vector3(_tDelta.X, _tDelta.Y, 0);
|
||||
}
|
||||
@@ -286,8 +288,8 @@ namespace FlaxEditor.Gizmo
|
||||
{
|
||||
if (ray.Intersects(ref planeZX, out intersection))
|
||||
{
|
||||
_intersectPosition = ray.Position + ray.Direction * intersection;
|
||||
if (_lastIntersectionPosition != Vector3.Zero)
|
||||
_intersectPosition = ray.GetPoint(intersection);
|
||||
if (!_lastIntersectionPosition.IsZero)
|
||||
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
||||
delta = new Vector3(_tDelta.X, 0, _tDelta.Z);
|
||||
}
|
||||
@@ -299,8 +301,8 @@ namespace FlaxEditor.Gizmo
|
||||
var plane = new Plane(-Vector3.Normalize(gizmoToView), gizmoToView.Length);
|
||||
if (ray.Intersects(ref plane, out intersection))
|
||||
{
|
||||
_intersectPosition = ray.Position + ray.Direction * intersection;
|
||||
if (_lastIntersectionPosition != Vector3.Zero)
|
||||
_intersectPosition = ray.GetPoint(intersection);
|
||||
if (!_lastIntersectionPosition.IsZero)
|
||||
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
||||
}
|
||||
delta = _tDelta;
|
||||
@@ -412,10 +414,8 @@ namespace FlaxEditor.Gizmo
|
||||
public override void Update(float dt)
|
||||
{
|
||||
LastDelta = Transform.Identity;
|
||||
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
bool isLeftBtnDown = Owner.IsLeftMouseButtonDown;
|
||||
|
||||
// Snap to ground
|
||||
@@ -516,6 +516,7 @@ namespace FlaxEditor.Gizmo
|
||||
{
|
||||
// Clear cache
|
||||
_accMoveDelta = Vector3.Zero;
|
||||
_lastIntersectionPosition = _intersectPosition = Vector3.Zero;
|
||||
EndTransforming();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -717,6 +717,9 @@ namespace FlaxEditor.Modules
|
||||
/// <param name="rebuild">Should rebuild entire database after addition.</param>
|
||||
public void AddProxy(ContentProxy proxy, bool rebuild = false)
|
||||
{
|
||||
var oldProxy = Proxy.Find(x => x.GetType().ToString().Equals(proxy.GetType().ToString(), StringComparison.Ordinal));
|
||||
if (oldProxy != null)
|
||||
RemoveProxy(oldProxy);
|
||||
Proxy.Insert(0, proxy);
|
||||
if (rebuild)
|
||||
Rebuild(true);
|
||||
|
||||
@@ -24,6 +24,13 @@ namespace FlaxEditor.Options
|
||||
[DefaultValue(1.0f), Limit(0.01f, 100.0f)]
|
||||
[EditorDisplay("General"), EditorOrder(101), Tooltip("The mouse wheel sensitivity applied to zoom in orthographic mode.")]
|
||||
public float MouseWheelSensitivity { get; set; } = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether to invert the Y rotation of the mouse in the editor viewport.
|
||||
/// </summary>
|
||||
[DefaultValue(false)]
|
||||
[EditorDisplay("General"), EditorOrder(102), Tooltip("Whether to invert the Y rotation of the mouse in the editor viewport.")]
|
||||
public bool InvertMouseYAxisRotation { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total amount of steps the camera needs to go from minimum to maximum speed.
|
||||
|
||||
@@ -111,6 +111,9 @@ namespace FlaxEditor.Viewport
|
||||
IsMouseRightDown = useMouse && window.GetMouseButton(MouseButton.Right);
|
||||
IsMouseMiddleDown = useMouse && window.GetMouseButton(MouseButton.Middle);
|
||||
IsMouseLeftDown = useMouse && window.GetMouseButton(MouseButton.Left);
|
||||
|
||||
if (WasAltDownBefore && !IsMouseLeftDown && !IsAltDown)
|
||||
WasAltDownBefore = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1385,15 +1388,32 @@ namespace FlaxEditor.Viewport
|
||||
/// <summary>
|
||||
/// Converts the mouse position to the ray (in world space of the viewport).
|
||||
/// </summary>
|
||||
/// <param name="mousePosition">The mouse position.</param>
|
||||
/// <param name="mousePosition">The mouse position (in UI space of the viewport [0; Size]).</param>
|
||||
/// <returns>The result ray.</returns>
|
||||
public Ray ConvertMouseToRay(ref Float2 mousePosition)
|
||||
{
|
||||
// Prepare
|
||||
var viewport = new FlaxEngine.Viewport(0, 0, Width, Height);
|
||||
CreateProjectionMatrix(out var p);
|
||||
if (viewport.Width < Mathf.Epsilon || viewport.Height < Mathf.Epsilon)
|
||||
return ViewRay;
|
||||
|
||||
Vector3 viewOrigin = Task.View.Origin;
|
||||
Float3 position = ViewPosition - viewOrigin;
|
||||
|
||||
// Use different logic in orthographic projection
|
||||
if (_isOrtho)
|
||||
{
|
||||
var screenPosition = new Float2(mousePosition.X / viewport.Width - 0.5f, -mousePosition.Y / viewport.Height + 0.5f);
|
||||
var orientation = ViewOrientation;
|
||||
var direction = Float3.Forward * orientation;
|
||||
var rayOrigin = new Vector3(screenPosition.X * viewport.Width * _orthoSize, screenPosition.Y * viewport.Height * _orthoSize, 0);
|
||||
rayOrigin = position + Vector3.Transform(rayOrigin, orientation);
|
||||
rayOrigin += direction * _nearPlane;
|
||||
rayOrigin += viewOrigin;
|
||||
return new Ray(rayOrigin, direction);
|
||||
}
|
||||
|
||||
// Create view frustum
|
||||
CreateProjectionMatrix(out var p);
|
||||
CreateViewMatrix(position, out var v);
|
||||
Matrix.Multiply(ref v, ref p, out var ivp);
|
||||
ivp.Invert();
|
||||
@@ -1404,11 +1424,7 @@ namespace FlaxEditor.Viewport
|
||||
viewport.Unproject(ref nearPoint, ref ivp, out nearPoint);
|
||||
viewport.Unproject(ref farPoint, ref ivp, out farPoint);
|
||||
|
||||
// Create direction vector
|
||||
Vector3 direction = farPoint - nearPoint;
|
||||
direction.Normalize();
|
||||
|
||||
return new Ray(nearPoint + viewOrigin, direction);
|
||||
return new Ray(nearPoint + viewOrigin, Vector3.Normalize(farPoint - nearPoint));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1704,6 +1720,8 @@ namespace FlaxEditor.Viewport
|
||||
// Update
|
||||
moveDelta *= dt * (60.0f * 4.0f);
|
||||
mouseDelta *= 0.1833f * MouseSpeed * _mouseSensitivity;
|
||||
if (options.Viewport.InvertMouseYAxisRotation)
|
||||
mouseDelta *= new Float2(1, -1);
|
||||
UpdateView(dt, ref moveDelta, ref mouseDelta, out var centerMouse);
|
||||
|
||||
// Move mouse back to the root position
|
||||
|
||||
@@ -627,8 +627,8 @@ namespace FlaxEditor.Viewport
|
||||
}
|
||||
|
||||
// Debug draw all actors in prefab and collect actors
|
||||
var viewFlags = Task.ViewFlags;
|
||||
var collectActors = (viewFlags & ViewFlags.PhysicsDebug) != 0 || (viewFlags & ViewFlags.LightsDebug) != 0;
|
||||
var view = Task.View;
|
||||
var collectActors = (view.Flags & ViewFlags.PhysicsDebug) != 0 || view.Mode == ViewMode.PhysicsColliders || (view.Flags & ViewFlags.LightsDebug) != 0;
|
||||
_debugDrawActors.Clear();
|
||||
foreach (var child in SceneGraphRoot.ChildNodes)
|
||||
{
|
||||
@@ -641,19 +641,17 @@ namespace FlaxEditor.Viewport
|
||||
}
|
||||
|
||||
// Draw physics debug
|
||||
if ((viewFlags & ViewFlags.PhysicsDebug) != 0)
|
||||
if ((view.Flags & ViewFlags.PhysicsDebug) != 0 || view.Mode == ViewMode.PhysicsColliders)
|
||||
{
|
||||
foreach (var actor in _debugDrawActors)
|
||||
{
|
||||
if (actor is Collider c && c.IsActiveInHierarchy)
|
||||
{
|
||||
DebugDraw.DrawColliderDebugPhysics(c, renderContext.View);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw lights debug
|
||||
if ((viewFlags & ViewFlags.LightsDebug) != 0)
|
||||
if ((view.Flags & ViewFlags.LightsDebug) != 0)
|
||||
{
|
||||
foreach (var actor in _debugDrawActors)
|
||||
{
|
||||
|
||||
@@ -80,6 +80,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
private AnimationWindow Window;
|
||||
private Animation Asset;
|
||||
private ModelImportSettings ImportSettings = new ModelImportSettings();
|
||||
private bool EnablePreviewModelCache = true;
|
||||
|
||||
[EditorDisplay("Preview"), NoSerialize, AssetReference(true), Tooltip("The skinned model to preview the animation playback.")]
|
||||
public SkinnedModel PreviewModel
|
||||
@@ -134,6 +135,15 @@ namespace FlaxEditor.Windows.Assets
|
||||
value.WaitForLoaded(500);
|
||||
Window._preview.ViewportCamera.SetArcBallView(Window._preview.PreviewActor.Sphere);
|
||||
}
|
||||
|
||||
if (EnablePreviewModelCache)
|
||||
{
|
||||
var customDataName = Window.GetPreviewModelCacheName();
|
||||
if (value)
|
||||
Window.Editor.ProjectCache.SetCustomData(customDataName, value.ID.ToString());
|
||||
else
|
||||
Window.Editor.ProjectCache.RemoveCustomData(customDataName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +152,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
// Link
|
||||
Window = window;
|
||||
Asset = window.Asset;
|
||||
EnablePreviewModelCache = true;
|
||||
|
||||
// Try to restore target asset import options (useful for fast reimport)
|
||||
Editor.TryRestoreImportOptions(ref ImportSettings.Settings, window.Item.Path);
|
||||
@@ -150,6 +161,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
public void OnClean()
|
||||
{
|
||||
// Unlink
|
||||
EnablePreviewModelCache = false;
|
||||
PreviewModel = null;
|
||||
Window = null;
|
||||
Asset = null;
|
||||
@@ -287,12 +299,23 @@ namespace FlaxEditor.Windows.Assets
|
||||
UpdateToolstrip();
|
||||
}
|
||||
|
||||
private string GetPreviewModelCacheName()
|
||||
{
|
||||
return _asset.ID + ".PreviewModel";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnAssetLoaded()
|
||||
{
|
||||
_properties.OnLoad(this);
|
||||
_propertiesPresenter.BuildLayout();
|
||||
ClearEditedFlag();
|
||||
if (!_initialPreviewModel &&
|
||||
Editor.ProjectCache.TryGetCustomData(GetPreviewModelCacheName(), out string str) &&
|
||||
Guid.TryParse(str, out var id))
|
||||
{
|
||||
_initialPreviewModel = FlaxEngine.Content.LoadAsync<SkinnedModel>(id);
|
||||
}
|
||||
if (_initialPreviewModel)
|
||||
{
|
||||
_properties.PreviewModel = _initialPreviewModel;
|
||||
|
||||
Reference in New Issue
Block a user