Merge branch 'FlaxEngine:master' into master
This commit is contained in:
@@ -13,6 +13,7 @@ namespace FlaxEditor.GUI.Docking
|
||||
public class DockPanelProxy : ContainerControl
|
||||
{
|
||||
private DockPanel _panel;
|
||||
private double _dragEnterTime = -1;
|
||||
|
||||
/// <summary>
|
||||
/// The is mouse down flag (left button).
|
||||
@@ -256,8 +257,8 @@ namespace FlaxEditor.GUI.Docking
|
||||
else
|
||||
{
|
||||
tabColor = style.BackgroundHighlighted;
|
||||
Render2D.DrawLine(tabRect.BottomLeft - new Float2(0 , 1), tabRect.UpperLeft, tabColor);
|
||||
Render2D.DrawLine(tabRect.BottomRight - new Float2(0 , 1), tabRect.UpperRight, tabColor);
|
||||
Render2D.DrawLine(tabRect.BottomLeft - new Float2(0, 1), tabRect.UpperLeft, tabColor);
|
||||
Render2D.DrawLine(tabRect.BottomRight - new Float2(0, 1), tabRect.UpperRight, tabColor);
|
||||
}
|
||||
|
||||
if (tab.Icon.IsValid)
|
||||
@@ -477,11 +478,7 @@ namespace FlaxEditor.GUI.Docking
|
||||
var result = base.OnDragEnter(ref location, data);
|
||||
if (result != DragDropEffect.None)
|
||||
return result;
|
||||
|
||||
if (TrySelectTabUnderLocation(ref location))
|
||||
return DragDropEffect.Move;
|
||||
|
||||
return DragDropEffect.None;
|
||||
return TrySelectTabUnderLocation(ref location);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -490,11 +487,15 @@ namespace FlaxEditor.GUI.Docking
|
||||
var result = base.OnDragMove(ref location, data);
|
||||
if (result != DragDropEffect.None)
|
||||
return result;
|
||||
return TrySelectTabUnderLocation(ref location);
|
||||
}
|
||||
|
||||
if (TrySelectTabUnderLocation(ref location))
|
||||
return DragDropEffect.Move;
|
||||
/// <inheritdoc />
|
||||
public override void OnDragLeave()
|
||||
{
|
||||
_dragEnterTime = -1;
|
||||
|
||||
return DragDropEffect.None;
|
||||
base.OnDragLeave();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -503,17 +504,25 @@ namespace FlaxEditor.GUI.Docking
|
||||
rect = new Rectangle(0, DockPanel.DefaultHeaderHeight, Width, Height - DockPanel.DefaultHeaderHeight);
|
||||
}
|
||||
|
||||
private bool TrySelectTabUnderLocation(ref Float2 location)
|
||||
private DragDropEffect TrySelectTabUnderLocation(ref Float2 location)
|
||||
{
|
||||
var tab = GetTabAtPos(location, out _);
|
||||
if (tab != null)
|
||||
{
|
||||
// Auto-select tab only if drag takes some time
|
||||
var time = Platform.TimeSeconds;
|
||||
if (_dragEnterTime < 0)
|
||||
_dragEnterTime = time;
|
||||
if (time - _dragEnterTime < 0.3f)
|
||||
return DragDropEffect.Link;
|
||||
_dragEnterTime = -1;
|
||||
|
||||
_panel.SelectTab(tab);
|
||||
Update(0); // Fake update
|
||||
return true;
|
||||
return DragDropEffect.Move;
|
||||
}
|
||||
|
||||
return false;
|
||||
_dragEnterTime = -1;
|
||||
return DragDropEffect.None;
|
||||
}
|
||||
|
||||
private void ShowContextMenu(DockWindow tab, ref Float2 location)
|
||||
|
||||
@@ -106,5 +106,11 @@ namespace FlaxEditor.Gizmo
|
||||
/// </summary>
|
||||
/// <param name="nodes">The nodes to select</param>
|
||||
void Select(List<SceneGraph.SceneGraphNode> nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Spawns the actor in the viewport hierarchy.
|
||||
/// </summary>
|
||||
/// <param name="actor">The new actor to spawn.</param>
|
||||
void Spawn(Actor actor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1084,7 +1084,7 @@ namespace FlaxEditor.Surface.Archetypes
|
||||
},
|
||||
Elements = new[]
|
||||
{
|
||||
NodeElementArchetype.Factory.Input(0, string.Empty, true, typeof(void), 0),
|
||||
NodeElementArchetype.Factory.Input(0, string.Empty, false, typeof(void), 0),
|
||||
NodeElementArchetype.Factory.Input(1, string.Empty, true, ScriptType.Null, 1, 1),
|
||||
NodeElementArchetype.Factory.Output(0, string.Empty, typeof(void), 2, true),
|
||||
NodeElementArchetype.Factory.ComboBox(2 + 20, 0, 116)
|
||||
|
||||
@@ -86,6 +86,9 @@ namespace FlaxEditor.Viewport
|
||||
/// <inheritdoc />
|
||||
public abstract void Select(List<SceneGraphNode> nodes);
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract void Spawn(Actor actor);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool IsControllingMouse => Gizmos.Active?.IsControllingMouse ?? false;
|
||||
|
||||
|
||||
@@ -5,9 +5,7 @@ using System.Collections.Generic;
|
||||
using FlaxEditor.Content;
|
||||
using FlaxEditor.Gizmo;
|
||||
using FlaxEditor.GUI.ContextMenu;
|
||||
using FlaxEditor.GUI.Drag;
|
||||
using FlaxEditor.SceneGraph;
|
||||
using FlaxEditor.SceneGraph.Actors;
|
||||
using FlaxEditor.Scripting;
|
||||
using FlaxEditor.Viewport.Cameras;
|
||||
using FlaxEditor.Viewport.Modes;
|
||||
@@ -37,28 +35,8 @@ namespace FlaxEditor.Viewport
|
||||
private readonly ViewportWidgetButton _rotateSnapping;
|
||||
private readonly ViewportWidgetButton _scaleSnapping;
|
||||
|
||||
private readonly DragAssets<DragDropEventArgs> _dragAssets;
|
||||
private readonly DragActorType<DragDropEventArgs> _dragActorType = new DragActorType<DragDropEventArgs>(ValidateDragActorType);
|
||||
|
||||
private SelectionOutline _customSelectionOutline;
|
||||
|
||||
/// <summary>
|
||||
/// The custom drag drop event arguments.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.GUI.Drag.DragEventArgs" />
|
||||
public class DragDropEventArgs : DragEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The hit.
|
||||
/// </summary>
|
||||
public SceneGraphNode Hit;
|
||||
|
||||
/// <summary>
|
||||
/// The hit location.
|
||||
/// </summary>
|
||||
public Vector3 HitLocation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The editor sprites rendering effect.
|
||||
/// </summary>
|
||||
@@ -137,15 +115,12 @@ namespace FlaxEditor.Viewport
|
||||
private bool _lockedFocus;
|
||||
private double _lockedFocusOffset;
|
||||
private readonly ViewportDebugDrawData _debugDrawData = new ViewportDebugDrawData(32);
|
||||
private StaticModel _previewStaticModel;
|
||||
private int _previewModelEntryIndex;
|
||||
private BrushSurface _previewBrushSurface;
|
||||
private EditorSpritesRenderer _editorSpritesRenderer;
|
||||
|
||||
/// <summary>
|
||||
/// Drag and drop handlers
|
||||
/// </summary>
|
||||
public readonly DragHandlers DragHandlers = new DragHandlers();
|
||||
public readonly ViewportDragHandlers DragHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// The transform gizmo.
|
||||
@@ -219,7 +194,7 @@ namespace FlaxEditor.Viewport
|
||||
: base(Object.New<SceneRenderTask>(), editor.Undo, editor.Scene.Root)
|
||||
{
|
||||
_editor = editor;
|
||||
_dragAssets = new DragAssets<DragDropEventArgs>(ValidateDragItem);
|
||||
DragHandlers = new ViewportDragHandlers(this, this, ValidateDragItem, ValidateDragActorType);
|
||||
var inputOptions = editor.Options.Options.Input;
|
||||
|
||||
// Prepare rendering task
|
||||
@@ -408,9 +383,6 @@ namespace FlaxEditor.Viewport
|
||||
ViewWidgetButtonMenu.AddSeparator();
|
||||
ViewWidgetButtonMenu.AddButton("Create camera here", CreateCameraAtView);
|
||||
|
||||
DragHandlers.Add(_dragActorType);
|
||||
DragHandlers.Add(_dragAssets);
|
||||
|
||||
// Init gizmo modes
|
||||
{
|
||||
// Add default modes used by the editor
|
||||
@@ -430,7 +402,11 @@ namespace FlaxEditor.Viewport
|
||||
InputActions.Add(options => options.TranslateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Translate);
|
||||
InputActions.Add(options => options.RotateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Rotate);
|
||||
InputActions.Add(options => options.ScaleMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Scale);
|
||||
InputActions.Add(options => options.ToggleTransformSpace, () => { OnTransformSpaceToggle(transformSpaceToggle); transformSpaceToggle.Checked = !transformSpaceToggle.Checked; });
|
||||
InputActions.Add(options => options.ToggleTransformSpace, () =>
|
||||
{
|
||||
OnTransformSpaceToggle(transformSpaceToggle);
|
||||
transformSpaceToggle.Checked = !transformSpaceToggle.Checked;
|
||||
});
|
||||
InputActions.Add(options => options.LockFocusSelection, LockFocusSelection);
|
||||
InputActions.Add(options => options.FocusSelection, FocusSelection);
|
||||
InputActions.Add(options => options.RotateSelection, RotateSelection);
|
||||
@@ -530,20 +506,9 @@ namespace FlaxEditor.Viewport
|
||||
|
||||
private void OnCollectDrawCalls(ref RenderContext renderContext)
|
||||
{
|
||||
if (_previewStaticModel)
|
||||
{
|
||||
_debugDrawData.HighlightModel(_previewStaticModel, _previewModelEntryIndex);
|
||||
}
|
||||
if (_previewBrushSurface.Brush != null)
|
||||
{
|
||||
_debugDrawData.HighlightBrushSurface(_previewBrushSurface);
|
||||
}
|
||||
|
||||
DragHandlers.CollectDrawCalls(_debugDrawData, ref renderContext);
|
||||
if (ShowNavigation)
|
||||
{
|
||||
Editor.Internal_DrawNavMesh();
|
||||
}
|
||||
|
||||
_debugDrawData.OnDraw(ref renderContext);
|
||||
}
|
||||
|
||||
@@ -942,78 +907,14 @@ namespace FlaxEditor.Viewport
|
||||
base.OnLeftMouseButtonUp();
|
||||
}
|
||||
|
||||
private void GetHitLocation(ref Float2 location, out SceneGraphNode hit, out Vector3 hitLocation, out Vector3 hitNormal)
|
||||
{
|
||||
// Get mouse ray and try to hit any object
|
||||
var ray = ConvertMouseToRay(ref location);
|
||||
var view = new Ray(ViewPosition, ViewDirection);
|
||||
var gridPlane = new Plane(Vector3.Zero, Vector3.Up);
|
||||
var flags = SceneGraphNode.RayCastData.FlagTypes.SkipColliders | SceneGraphNode.RayCastData.FlagTypes.SkipEditorPrimitives;
|
||||
hit = Editor.Instance.Scene.Root.RayCast(ref ray, ref view, out var closest, out var normal, flags);
|
||||
if (hit != null)
|
||||
{
|
||||
// Use hit location
|
||||
hitLocation = ray.Position + ray.Direction * closest;
|
||||
hitNormal = normal;
|
||||
}
|
||||
else if (Grid.Enabled && CollisionsHelper.RayIntersectsPlane(ref ray, ref gridPlane, out closest) && closest < 4000.0f)
|
||||
{
|
||||
// Use grid location
|
||||
hitLocation = ray.Position + ray.Direction * closest;
|
||||
hitNormal = Vector3.Up;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use area in front of the viewport
|
||||
hitLocation = ViewPosition + ViewDirection * 100;
|
||||
hitNormal = Vector3.Up;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetDragEffects(ref Float2 location)
|
||||
{
|
||||
if (_dragAssets.HasValidDrag && _dragAssets.Objects[0].IsOfType<MaterialBase>())
|
||||
{
|
||||
GetHitLocation(ref location, out var hit, out _, out _);
|
||||
ClearDragEffects();
|
||||
var material = FlaxEngine.Content.LoadAsync<MaterialBase>(_dragAssets.Objects[0].ID);
|
||||
if (material.IsDecal)
|
||||
return;
|
||||
|
||||
if (hit is StaticModelNode staticModelNode)
|
||||
{
|
||||
_previewStaticModel = (StaticModel)staticModelNode.Actor;
|
||||
var ray = ConvertMouseToRay(ref location);
|
||||
_previewStaticModel.IntersectsEntry(ref ray, out _, out _, out _previewModelEntryIndex);
|
||||
}
|
||||
else if (hit is BoxBrushNode.SideLinkNode brushSurfaceNode)
|
||||
{
|
||||
_previewBrushSurface = brushSurfaceNode.Surface;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearDragEffects()
|
||||
{
|
||||
_previewStaticModel = null;
|
||||
_previewModelEntryIndex = -1;
|
||||
_previewBrushSurface = new BrushSurface();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override DragDropEffect OnDragEnter(ref Float2 location, DragData data)
|
||||
{
|
||||
ClearDragEffects();
|
||||
|
||||
DragHandlers.ClearDragEffects();
|
||||
var result = base.OnDragEnter(ref location, data);
|
||||
if (result != DragDropEffect.None)
|
||||
return result;
|
||||
|
||||
result = DragHandlers.OnDragEnter(data);
|
||||
|
||||
SetDragEffects(ref location);
|
||||
|
||||
return result;
|
||||
return DragHandlers.DragEnter(ref location, data);
|
||||
}
|
||||
|
||||
private bool ValidateDragItem(ContentItem contentItem)
|
||||
@@ -1042,167 +943,29 @@ namespace FlaxEditor.Viewport
|
||||
/// <inheritdoc />
|
||||
public override DragDropEffect OnDragMove(ref Float2 location, DragData data)
|
||||
{
|
||||
ClearDragEffects();
|
||||
|
||||
DragHandlers.ClearDragEffects();
|
||||
var result = base.OnDragMove(ref location, data);
|
||||
if (result != DragDropEffect.None)
|
||||
return result;
|
||||
|
||||
SetDragEffects(ref location);
|
||||
|
||||
return DragHandlers.Effect;
|
||||
return DragHandlers.DragEnter(ref location, data);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnDragLeave()
|
||||
{
|
||||
ClearDragEffects();
|
||||
|
||||
DragHandlers.ClearDragEffects();
|
||||
DragHandlers.OnDragLeave();
|
||||
|
||||
base.OnDragLeave();
|
||||
}
|
||||
|
||||
private Vector3 PostProcessSpawnedActorLocation(Actor actor, ref Vector3 hitLocation)
|
||||
{
|
||||
// Refresh actor position to ensure that cached bounds are valid
|
||||
actor.Position = Vector3.One;
|
||||
actor.Position = Vector3.Zero;
|
||||
|
||||
// Place the object
|
||||
//var location = hitLocation - (box.Size.Length * 0.5f) * ViewDirection;
|
||||
var editorBounds = actor.EditorBoxChildren;
|
||||
var bottomToCenter = actor.Position.Y - editorBounds.Minimum.Y;
|
||||
var location = hitLocation + new Vector3(0, bottomToCenter, 0);
|
||||
|
||||
// Apply grid snapping if enabled
|
||||
if (UseSnapping || TransformGizmo.TranslationSnapEnable)
|
||||
{
|
||||
float snapValue = TransformGizmo.TranslationSnapValue;
|
||||
location = new Vector3(
|
||||
(int)(location.X / snapValue) * snapValue,
|
||||
(int)(location.Y / snapValue) * snapValue,
|
||||
(int)(location.Z / snapValue) * snapValue);
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
private void Spawn(Actor actor, ref Vector3 hitLocation, ref Vector3 hitNormal)
|
||||
{
|
||||
actor.Position = PostProcessSpawnedActorLocation(actor, ref hitLocation);
|
||||
var parent = actor.Parent ?? Level.GetScene(0);
|
||||
actor.Name = Utilities.Utils.IncrementNameNumber(actor.Name, x => parent.GetChild(x) == null);
|
||||
Editor.Instance.SceneEditing.Spawn(actor);
|
||||
Focus();
|
||||
}
|
||||
|
||||
private void Spawn(AssetItem item, SceneGraphNode hit, ref Float2 location, ref Vector3 hitLocation, ref Vector3 hitNormal)
|
||||
{
|
||||
if (item.IsOfType<MaterialBase>())
|
||||
{
|
||||
var material = FlaxEngine.Content.LoadAsync<MaterialBase>(item.ID);
|
||||
if (material && !material.WaitForLoaded(100) && material.IsDecal)
|
||||
{
|
||||
var actor = new Decal
|
||||
{
|
||||
Material = material,
|
||||
LocalOrientation = RootNode.RaycastNormalRotation(ref hitNormal),
|
||||
Name = item.ShortName
|
||||
};
|
||||
DebugDraw.DrawWireArrow(PostProcessSpawnedActorLocation(actor, ref hitNormal), actor.LocalOrientation, 1.0f, Color.Red, 1000000);
|
||||
Spawn(actor, ref hitLocation, ref hitNormal);
|
||||
}
|
||||
else if (hit is StaticModelNode staticModelNode)
|
||||
{
|
||||
var staticModel = (StaticModel)staticModelNode.Actor;
|
||||
var ray = ConvertMouseToRay(ref location);
|
||||
if (staticModel.IntersectsEntry(ref ray, out _, out _, out var entryIndex))
|
||||
{
|
||||
using (new UndoBlock(Undo, staticModel, "Change material"))
|
||||
staticModel.SetMaterial(entryIndex, material);
|
||||
}
|
||||
}
|
||||
else if (hit is BoxBrushNode.SideLinkNode brushSurfaceNode)
|
||||
{
|
||||
using (new UndoBlock(Undo, brushSurfaceNode.Brush, "Change material"))
|
||||
{
|
||||
var surface = brushSurfaceNode.Surface;
|
||||
surface.Material = material;
|
||||
brushSurfaceNode.Surface = surface;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (item.IsOfType<SceneAsset>())
|
||||
{
|
||||
Editor.Instance.Scene.OpenScene(item.ID, true);
|
||||
return;
|
||||
}
|
||||
{
|
||||
var actor = item.OnEditorDrop(this);
|
||||
actor.Name = item.ShortName;
|
||||
Spawn(actor, ref hitLocation, ref hitNormal);
|
||||
}
|
||||
}
|
||||
|
||||
private void Spawn(ScriptType item, SceneGraphNode hit, ref Float2 location, ref Vector3 hitLocation, ref Vector3 hitNormal)
|
||||
{
|
||||
var actor = item.CreateInstance() as Actor;
|
||||
if (actor == null)
|
||||
{
|
||||
Editor.LogWarning("Failed to spawn actor of type " + item.TypeName);
|
||||
return;
|
||||
}
|
||||
actor.Name = item.Name;
|
||||
Spawn(actor, ref hitLocation, ref hitNormal);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override DragDropEffect OnDragDrop(ref Float2 location, DragData data)
|
||||
{
|
||||
ClearDragEffects();
|
||||
|
||||
DragHandlers.ClearDragEffects();
|
||||
var result = base.OnDragDrop(ref location, data);
|
||||
if (result != DragDropEffect.None)
|
||||
return result;
|
||||
|
||||
// Check if drag sth
|
||||
Vector3 hitLocation = ViewPosition, hitNormal = -ViewDirection;
|
||||
SceneGraphNode hit = null;
|
||||
if (DragHandlers.HasValidDrag)
|
||||
{
|
||||
GetHitLocation(ref location, out hit, out hitLocation, out hitNormal);
|
||||
}
|
||||
|
||||
// Drag assets
|
||||
if (_dragAssets.HasValidDrag)
|
||||
{
|
||||
result = _dragAssets.Effect;
|
||||
|
||||
// Process items
|
||||
for (int i = 0; i < _dragAssets.Objects.Count; i++)
|
||||
{
|
||||
var item = _dragAssets.Objects[i];
|
||||
Spawn(item, hit, ref location, ref hitLocation, ref hitNormal);
|
||||
}
|
||||
}
|
||||
// Drag actor type
|
||||
else if (_dragActorType.HasValidDrag)
|
||||
{
|
||||
result = _dragActorType.Effect;
|
||||
|
||||
// Process items
|
||||
for (int i = 0; i < _dragActorType.Objects.Count; i++)
|
||||
{
|
||||
var item = _dragActorType.Objects[i];
|
||||
Spawn(item, hit, ref location, ref hitLocation, ref hitNormal);
|
||||
}
|
||||
}
|
||||
|
||||
DragHandlers.OnDragDrop(new DragDropEventArgs { Hit = hit, HitLocation = hitLocation });
|
||||
|
||||
return result;
|
||||
return DragHandlers.DragDrop(ref location, data);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -1211,6 +974,14 @@ namespace FlaxEditor.Viewport
|
||||
_editor.SceneEditing.Select(nodes);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Spawn(Actor actor)
|
||||
{
|
||||
var parent = actor.Parent ?? Level.GetScene(0);
|
||||
actor.Name = Utilities.Utils.IncrementNameNumber(actor.Name, x => parent.GetChild(x) == null);
|
||||
Editor.Instance.SceneEditing.Spawn(actor);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnDestroy()
|
||||
{
|
||||
|
||||
@@ -5,9 +5,7 @@ using System.Collections.Generic;
|
||||
using FlaxEditor.Content;
|
||||
using FlaxEditor.Gizmo;
|
||||
using FlaxEditor.GUI.ContextMenu;
|
||||
using FlaxEditor.GUI.Drag;
|
||||
using FlaxEditor.SceneGraph;
|
||||
using FlaxEditor.SceneGraph.Actors;
|
||||
using FlaxEditor.Scripting;
|
||||
using FlaxEditor.Viewport.Cameras;
|
||||
using FlaxEditor.Viewport.Previews;
|
||||
@@ -56,9 +54,11 @@ namespace FlaxEditor.Viewport
|
||||
|
||||
private readonly ViewportDebugDrawData _debugDrawData = new ViewportDebugDrawData(32);
|
||||
private PrefabSpritesRenderer _spritesRenderer;
|
||||
private readonly DragAssets _dragAssets;
|
||||
private readonly DragActorType _dragActorType = new DragActorType(ValidateDragActorType);
|
||||
private readonly DragHandlers _dragHandlers = new DragHandlers();
|
||||
|
||||
/// <summary>
|
||||
/// Drag and drop handlers
|
||||
/// </summary>
|
||||
public readonly ViewportDragHandlers DragHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// The transform gizmo.
|
||||
@@ -81,7 +81,7 @@ namespace FlaxEditor.Viewport
|
||||
_window.SelectionChanged += OnSelectionChanged;
|
||||
Undo = window.Undo;
|
||||
ViewportCamera = new FPSCamera();
|
||||
_dragAssets = new DragAssets(ValidateDragItem);
|
||||
DragHandlers = new ViewportDragHandlers(this, this, ValidateDragItem, ValidateDragActorType);
|
||||
ShowDebugDraw = true;
|
||||
ShowEditorPrimitives = true;
|
||||
Gizmos = new GizmosCollection(this);
|
||||
@@ -228,14 +228,15 @@ namespace FlaxEditor.Viewport
|
||||
_gizmoModeScale.Toggled += OnGizmoModeToggle;
|
||||
gizmoMode.Parent = this;
|
||||
|
||||
_dragHandlers.Add(_dragActorType);
|
||||
_dragHandlers.Add(_dragAssets);
|
||||
|
||||
// Setup input actions
|
||||
InputActions.Add(options => options.TranslateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Translate);
|
||||
InputActions.Add(options => options.RotateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Rotate);
|
||||
InputActions.Add(options => options.ScaleMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Scale);
|
||||
InputActions.Add(options => options.ToggleTransformSpace, () => { OnTransformSpaceToggle(transformSpaceToggle); transformSpaceToggle.Checked = !transformSpaceToggle.Checked; });
|
||||
InputActions.Add(options => options.ToggleTransformSpace, () =>
|
||||
{
|
||||
OnTransformSpaceToggle(transformSpaceToggle);
|
||||
transformSpaceToggle.Checked = !transformSpaceToggle.Checked;
|
||||
});
|
||||
InputActions.Add(options => options.FocusSelection, ShowSelectedActors);
|
||||
|
||||
SetUpdate(ref _update, OnUpdate);
|
||||
@@ -267,6 +268,7 @@ namespace FlaxEditor.Viewport
|
||||
|
||||
private void OnCollectDrawCalls(ref RenderContext renderContext)
|
||||
{
|
||||
DragHandlers.CollectDrawCalls(_debugDrawData, ref renderContext);
|
||||
_debugDrawData.OnDraw(ref renderContext);
|
||||
}
|
||||
|
||||
@@ -306,6 +308,7 @@ namespace FlaxEditor.Viewport
|
||||
var orient = ViewOrientation;
|
||||
((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents, ref orient);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public EditorViewport Viewport => this;
|
||||
|
||||
@@ -354,6 +357,12 @@ namespace FlaxEditor.Viewport
|
||||
_window.Select(nodes);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Spawn(Actor actor)
|
||||
{
|
||||
_window.Spawn(actor);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool IsControllingMouse => Gizmos.Active?.IsControllingMouse ?? false;
|
||||
|
||||
@@ -669,11 +678,11 @@ namespace FlaxEditor.Viewport
|
||||
/// <inheritdoc />
|
||||
public override DragDropEffect OnDragEnter(ref Float2 location, DragData data)
|
||||
{
|
||||
DragHandlers.ClearDragEffects();
|
||||
var result = base.OnDragEnter(ref location, data);
|
||||
if (result != DragDropEffect.None)
|
||||
return result;
|
||||
|
||||
return _dragHandlers.OnDragEnter(data);
|
||||
return DragHandlers.DragEnter(ref location, data);
|
||||
}
|
||||
|
||||
private bool ValidateDragItem(ContentItem contentItem)
|
||||
@@ -685,7 +694,6 @@ namespace FlaxEditor.Viewport
|
||||
if (assetItem.IsOfType<MaterialBase>())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -697,86 +705,21 @@ namespace FlaxEditor.Viewport
|
||||
/// <inheritdoc />
|
||||
public override DragDropEffect OnDragMove(ref Float2 location, DragData data)
|
||||
{
|
||||
DragHandlers.ClearDragEffects();
|
||||
var result = base.OnDragMove(ref location, data);
|
||||
if (result != DragDropEffect.None)
|
||||
return result;
|
||||
|
||||
return _dragHandlers.Effect;
|
||||
return DragHandlers.DragEnter(ref location, data);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnDragLeave()
|
||||
{
|
||||
_dragHandlers.OnDragLeave();
|
||||
|
||||
DragHandlers.ClearDragEffects();
|
||||
DragHandlers.OnDragLeave();
|
||||
base.OnDragLeave();
|
||||
}
|
||||
|
||||
private Vector3 PostProcessSpawnedActorLocation(Actor actor, ref Vector3 hitLocation)
|
||||
{
|
||||
// Place the object
|
||||
//var location = hitLocation - (box.Size.Length * 0.5f) * ViewDirection;
|
||||
var location = hitLocation;
|
||||
|
||||
// Apply grid snapping if enabled
|
||||
if (UseSnapping || TransformGizmo.TranslationSnapEnable)
|
||||
{
|
||||
float snapValue = TransformGizmo.TranslationSnapValue;
|
||||
location = new Vector3(
|
||||
(int)(location.X / snapValue) * snapValue,
|
||||
(int)(location.Y / snapValue) * snapValue,
|
||||
(int)(location.Z / snapValue) * snapValue);
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
private void Spawn(AssetItem item, SceneGraphNode hit, ref Float2 location, ref Vector3 hitLocation)
|
||||
{
|
||||
if (item is BinaryAssetItem binaryAssetItem)
|
||||
{
|
||||
if (typeof(MaterialBase).IsAssignableFrom(binaryAssetItem.Type))
|
||||
{
|
||||
if (hit is StaticModelNode staticModelNode)
|
||||
{
|
||||
var staticModel = (StaticModel)staticModelNode.Actor;
|
||||
var ray = ConvertMouseToRay(ref location);
|
||||
if (staticModel.IntersectsEntry(ref ray, out _, out _, out var entryIndex))
|
||||
{
|
||||
var material = FlaxEngine.Content.LoadAsync<MaterialBase>(item.ID);
|
||||
using (new UndoBlock(Undo, staticModel, "Change material"))
|
||||
staticModel.SetMaterial(entryIndex, material);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
{
|
||||
var actor = item.OnEditorDrop(this);
|
||||
actor.Name = item.ShortName;
|
||||
Spawn(actor, ref hitLocation);
|
||||
}
|
||||
}
|
||||
|
||||
private void Spawn(Actor actor, ref Vector3 hitLocation)
|
||||
{
|
||||
actor.Position = PostProcessSpawnedActorLocation(actor, ref hitLocation);
|
||||
_window.Spawn(actor);
|
||||
Focus();
|
||||
}
|
||||
|
||||
private void Spawn(ScriptType item, SceneGraphNode hit, ref Vector3 hitLocation)
|
||||
{
|
||||
var actor = item.CreateInstance() as Actor;
|
||||
if (actor == null)
|
||||
{
|
||||
Editor.LogWarning("Failed to spawn actor of type " + item.TypeName);
|
||||
return;
|
||||
}
|
||||
actor.Name = item.Name;
|
||||
Spawn(actor, ref hitLocation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Focuses the viewport on the current selection of the gizmo.
|
||||
/// </summary>
|
||||
@@ -814,57 +757,11 @@ namespace FlaxEditor.Viewport
|
||||
/// <inheritdoc />
|
||||
public override DragDropEffect OnDragDrop(ref Float2 location, DragData data)
|
||||
{
|
||||
DragHandlers.ClearDragEffects();
|
||||
var result = base.OnDragDrop(ref location, data);
|
||||
if (result != DragDropEffect.None)
|
||||
return result;
|
||||
|
||||
// Check if drag sth
|
||||
Vector3 hitLocation = ViewPosition;
|
||||
SceneGraphNode hit = null;
|
||||
if (_dragHandlers.HasValidDrag)
|
||||
{
|
||||
// Get mouse ray and try to hit any object
|
||||
var ray = ConvertMouseToRay(ref location);
|
||||
var view = new Ray(ViewPosition, ViewDirection);
|
||||
hit = _window.Graph.Root.RayCast(ref ray, ref view, out var closest, SceneGraphNode.RayCastData.FlagTypes.SkipColliders);
|
||||
if (hit != null)
|
||||
{
|
||||
// Use hit location
|
||||
hitLocation = ray.Position + ray.Direction * closest;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use area in front of the viewport
|
||||
hitLocation = ViewPosition + ViewDirection * 100;
|
||||
}
|
||||
}
|
||||
|
||||
// Drag assets
|
||||
if (_dragAssets.HasValidDrag)
|
||||
{
|
||||
result = _dragAssets.Effect;
|
||||
|
||||
// Process items
|
||||
for (int i = 0; i < _dragAssets.Objects.Count; i++)
|
||||
{
|
||||
var item = _dragAssets.Objects[i];
|
||||
Spawn(item, hit, ref location, ref hitLocation);
|
||||
}
|
||||
}
|
||||
// Drag actor type
|
||||
else if (_dragActorType.HasValidDrag)
|
||||
{
|
||||
result = _dragActorType.Effect;
|
||||
|
||||
// Process items
|
||||
for (int i = 0; i < _dragActorType.Objects.Count; i++)
|
||||
{
|
||||
var item = _dragActorType.Objects[i];
|
||||
Spawn(item, hit, ref hitLocation);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return DragHandlers.DragDrop(ref location, data);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
257
Source/Editor/Viewport/ViewportDraggingHelper.cs
Normal file
257
Source/Editor/Viewport/ViewportDraggingHelper.cs
Normal file
@@ -0,0 +1,257 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FlaxEditor.Content;
|
||||
using FlaxEditor.Gizmo;
|
||||
using FlaxEditor.GUI.Drag;
|
||||
using FlaxEditor.SceneGraph;
|
||||
using FlaxEditor.SceneGraph.Actors;
|
||||
using FlaxEditor.Scripting;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
|
||||
namespace FlaxEditor.Viewport
|
||||
{
|
||||
/// <summary>
|
||||
/// Utility to help managing dragging assets, actors and other objects into the editor viewport.
|
||||
/// </summary>
|
||||
public class ViewportDragHandlers : DragHandlers
|
||||
{
|
||||
/// <summary>
|
||||
/// The custom drag drop event arguments.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.GUI.Drag.DragEventArgs" />
|
||||
public class DragDropEventArgs : DragEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The hit.
|
||||
/// </summary>
|
||||
public SceneGraphNode Hit;
|
||||
|
||||
/// <summary>
|
||||
/// The hit location.
|
||||
/// </summary>
|
||||
public Vector3 HitLocation;
|
||||
}
|
||||
|
||||
private readonly IGizmoOwner _owner;
|
||||
private readonly EditorViewport _viewport;
|
||||
private readonly DragAssets<DragDropEventArgs> _dragAssets;
|
||||
private readonly DragActorType<DragDropEventArgs> _dragActorType;
|
||||
|
||||
private StaticModel _previewStaticModel;
|
||||
private int _previewModelEntryIndex;
|
||||
private BrushSurface _previewBrushSurface;
|
||||
|
||||
internal ViewportDragHandlers(IGizmoOwner owner, EditorViewport viewport, Func<AssetItem, bool> validateAsset, Func<ScriptType, bool> validateDragActorType)
|
||||
{
|
||||
_owner = owner;
|
||||
_viewport = viewport;
|
||||
Add(_dragAssets = new DragAssets<DragDropEventArgs>(validateAsset));
|
||||
Add(_dragActorType = new DragActorType<DragDropEventArgs>(validateDragActorType));
|
||||
}
|
||||
|
||||
internal void ClearDragEffects()
|
||||
{
|
||||
_previewStaticModel = null;
|
||||
_previewModelEntryIndex = -1;
|
||||
_previewBrushSurface = new BrushSurface();
|
||||
}
|
||||
|
||||
internal void CollectDrawCalls(ViewportDebugDrawData debugDrawData, ref RenderContext renderContext)
|
||||
{
|
||||
if (_previewStaticModel)
|
||||
debugDrawData.HighlightModel(_previewStaticModel, _previewModelEntryIndex);
|
||||
if (_previewBrushSurface.Brush != null)
|
||||
debugDrawData.HighlightBrushSurface(_previewBrushSurface);
|
||||
}
|
||||
|
||||
internal DragDropEffect DragEnter(ref Float2 location, DragData data)
|
||||
{
|
||||
var result = OnDragEnter(data);
|
||||
SetDragEffects(ref location);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal DragDropEffect DragMove(ref Float2 location, DragData data)
|
||||
{
|
||||
SetDragEffects(ref location);
|
||||
return Effect;
|
||||
}
|
||||
|
||||
internal DragDropEffect DragDrop(ref Float2 location, DragData data)
|
||||
{
|
||||
Vector3 hitLocation = _viewport.ViewPosition, hitNormal = -_viewport.ViewDirection;
|
||||
SceneGraphNode hit = null;
|
||||
if (HasValidDrag)
|
||||
{
|
||||
GetHitLocation(ref location, out hit, out hitLocation, out hitNormal);
|
||||
}
|
||||
|
||||
var result = DragDropEffect.None;
|
||||
if (_dragAssets.HasValidDrag)
|
||||
{
|
||||
result = _dragAssets.Effect;
|
||||
foreach (var asset in _dragAssets.Objects)
|
||||
Spawn(asset, hit, ref location, ref hitLocation, ref hitNormal);
|
||||
}
|
||||
else if (_dragActorType.HasValidDrag)
|
||||
{
|
||||
result = _dragActorType.Effect;
|
||||
foreach (var actorType in _dragActorType.Objects)
|
||||
Spawn(actorType, hit, ref location, ref hitLocation, ref hitNormal);
|
||||
}
|
||||
|
||||
OnDragDrop(new DragDropEventArgs { Hit = hit, HitLocation = hitLocation });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SetDragEffects(ref Float2 location)
|
||||
{
|
||||
if (_dragAssets.HasValidDrag && _dragAssets.Objects[0].IsOfType<MaterialBase>())
|
||||
{
|
||||
GetHitLocation(ref location, out var hit, out _, out _);
|
||||
ClearDragEffects();
|
||||
var material = FlaxEngine.Content.LoadAsync<MaterialBase>(_dragAssets.Objects[0].ID);
|
||||
if (material.IsDecal)
|
||||
return;
|
||||
|
||||
if (hit is StaticModelNode staticModelNode)
|
||||
{
|
||||
_previewStaticModel = (StaticModel)staticModelNode.Actor;
|
||||
var ray = _viewport.ConvertMouseToRay(ref location);
|
||||
_previewStaticModel.IntersectsEntry(ref ray, out _, out _, out _previewModelEntryIndex);
|
||||
}
|
||||
else if (hit is BoxBrushNode.SideLinkNode brushSurfaceNode)
|
||||
{
|
||||
_previewBrushSurface = brushSurfaceNode.Surface;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GetHitLocation(ref Float2 location, out SceneGraphNode hit, out Vector3 hitLocation, out Vector3 hitNormal)
|
||||
{
|
||||
// Get mouse ray and try to hit any object
|
||||
var ray = _viewport.ConvertMouseToRay(ref location);
|
||||
var view = new Ray(_viewport.ViewPosition, _viewport.ViewDirection);
|
||||
var gridPlane = new Plane(Vector3.Zero, Vector3.Up);
|
||||
var flags = SceneGraphNode.RayCastData.FlagTypes.SkipColliders | SceneGraphNode.RayCastData.FlagTypes.SkipEditorPrimitives;
|
||||
hit = _owner.SceneGraphRoot.RayCast(ref ray, ref view, out var closest, out var normal, flags);
|
||||
var girdGizmo = (GridGizmo)_owner.Gizmos.FirstOrDefault(x => x is GridGizmo);
|
||||
if (hit != null)
|
||||
{
|
||||
// Use hit location
|
||||
hitLocation = ray.Position + ray.Direction * closest;
|
||||
hitNormal = normal;
|
||||
}
|
||||
else if (girdGizmo != null && girdGizmo.Enabled && CollisionsHelper.RayIntersectsPlane(ref ray, ref gridPlane, out closest) && closest < 4000.0f)
|
||||
{
|
||||
// Use grid location
|
||||
hitLocation = ray.Position + ray.Direction * closest;
|
||||
hitNormal = Vector3.Up;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use area in front of the viewport
|
||||
hitLocation = view.GetPoint(100);
|
||||
hitNormal = Vector3.Up;
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 PostProcessSpawnedActorLocation(Actor actor, ref Vector3 hitLocation)
|
||||
{
|
||||
// Refresh actor position to ensure that cached bounds are valid
|
||||
actor.Position = Vector3.One;
|
||||
actor.Position = Vector3.Zero;
|
||||
|
||||
// Place the object
|
||||
//var location = hitLocation - (box.Size.Length * 0.5f) * ViewDirection;
|
||||
var editorBounds = actor.EditorBoxChildren;
|
||||
var bottomToCenter = actor.Position.Y - editorBounds.Minimum.Y;
|
||||
var location = hitLocation + new Vector3(0, bottomToCenter, 0);
|
||||
|
||||
// Apply grid snapping if enabled
|
||||
var transformGizmo = (TransformGizmo)_owner.Gizmos.FirstOrDefault(x => x is TransformGizmo);
|
||||
if (transformGizmo != null && (_owner.UseSnapping || transformGizmo.TranslationSnapEnable))
|
||||
{
|
||||
float snapValue = transformGizmo.TranslationSnapValue;
|
||||
location = new Vector3(
|
||||
(int)(location.X / snapValue) * snapValue,
|
||||
(int)(location.Y / snapValue) * snapValue,
|
||||
(int)(location.Z / snapValue) * snapValue);
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
private void Spawn(Actor actor, ref Vector3 hitLocation, ref Vector3 hitNormal)
|
||||
{
|
||||
actor.Position = PostProcessSpawnedActorLocation(actor, ref hitLocation);
|
||||
_owner.Spawn(actor);
|
||||
_viewport.Focus();
|
||||
}
|
||||
|
||||
private void Spawn(ScriptType item, SceneGraphNode hit, ref Float2 location, ref Vector3 hitLocation, ref Vector3 hitNormal)
|
||||
{
|
||||
var actor = item.CreateInstance() as Actor;
|
||||
if (actor == null)
|
||||
{
|
||||
Editor.LogWarning("Failed to spawn actor of type " + item.TypeName);
|
||||
return;
|
||||
}
|
||||
actor.Name = item.Name;
|
||||
Spawn(actor, ref hitLocation, ref hitNormal);
|
||||
}
|
||||
|
||||
private void Spawn(AssetItem item, SceneGraphNode hit, ref Float2 location, ref Vector3 hitLocation, ref Vector3 hitNormal)
|
||||
{
|
||||
if (item.IsOfType<MaterialBase>())
|
||||
{
|
||||
var material = FlaxEngine.Content.LoadAsync<MaterialBase>(item.ID);
|
||||
if (material && !material.WaitForLoaded(500) && material.IsDecal)
|
||||
{
|
||||
var actor = new Decal
|
||||
{
|
||||
Material = material,
|
||||
LocalOrientation = RootNode.RaycastNormalRotation(ref hitNormal),
|
||||
Name = item.ShortName
|
||||
};
|
||||
DebugDraw.DrawWireArrow(PostProcessSpawnedActorLocation(actor, ref hitNormal), actor.LocalOrientation, 1.0f, Color.Red, 1000000);
|
||||
Spawn(actor, ref hitLocation, ref hitNormal);
|
||||
}
|
||||
else if (hit is StaticModelNode staticModelNode)
|
||||
{
|
||||
var staticModel = (StaticModel)staticModelNode.Actor;
|
||||
var ray = _viewport.ConvertMouseToRay(ref location);
|
||||
if (staticModel.IntersectsEntry(ref ray, out _, out _, out var entryIndex))
|
||||
{
|
||||
using (new UndoBlock(_owner.Undo, staticModel, "Change material"))
|
||||
staticModel.SetMaterial(entryIndex, material);
|
||||
}
|
||||
}
|
||||
else if (hit is BoxBrushNode.SideLinkNode brushSurfaceNode)
|
||||
{
|
||||
using (new UndoBlock(_owner.Undo, brushSurfaceNode.Brush, "Change material"))
|
||||
{
|
||||
var surface = brushSurfaceNode.Surface;
|
||||
surface.Material = material;
|
||||
brushSurfaceNode.Surface = surface;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (item.IsOfType<SceneAsset>())
|
||||
{
|
||||
Editor.Instance.Scene.OpenScene(item.ID, true);
|
||||
return;
|
||||
}
|
||||
{
|
||||
var actor = item.OnEditorDrop(this);
|
||||
actor.Name = item.ShortName;
|
||||
Spawn(actor, ref hitLocation, ref hitNormal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,7 +190,7 @@ namespace FlaxEditor.Windows
|
||||
};
|
||||
_addPluginProjectButton = new Button
|
||||
{
|
||||
Text = "Create Plugin Project",
|
||||
Text = "Create Project",
|
||||
TooltipText = "Add new plugin project.",
|
||||
AnchorPreset = AnchorPresets.TopLeft,
|
||||
LocalLocation = new Float2(70, 18),
|
||||
@@ -201,7 +201,7 @@ namespace FlaxEditor.Windows
|
||||
|
||||
_cloneProjectButton = new Button
|
||||
{
|
||||
Text = "Clone Plugin Project",
|
||||
Text = "Clone Project",
|
||||
TooltipText = "Git Clone a plugin project.",
|
||||
AnchorPreset = AnchorPresets.TopLeft,
|
||||
LocalLocation = new Float2(70 + _addPluginProjectButton.Size.X + 8, 18),
|
||||
|
||||
@@ -423,6 +423,7 @@ namespace FlaxEditor.Windows
|
||||
var actor = item.OnEditorDrop(this);
|
||||
actor.Name = item.ShortName;
|
||||
Level.SpawnActor(actor);
|
||||
Editor.Scene.MarkSceneEdited(actor.Scene);
|
||||
}
|
||||
result = DragDropEffect.Move;
|
||||
}
|
||||
@@ -440,6 +441,7 @@ namespace FlaxEditor.Windows
|
||||
}
|
||||
actor.Name = item.Name;
|
||||
Level.SpawnActor(actor);
|
||||
Editor.Scene.MarkSceneEdited(actor.Scene);
|
||||
}
|
||||
result = DragDropEffect.Move;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "String.h"
|
||||
#include "StringView.h"
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
|
||||
/// <summary>
|
||||
@@ -138,6 +139,11 @@ public:
|
||||
_data.Add(*str, str.Length());
|
||||
return *this;
|
||||
}
|
||||
StringBuilder& Append(const StringView& str)
|
||||
{
|
||||
_data.Add(*str, str.Length());
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Append int to the string
|
||||
// @param val Value to append
|
||||
|
||||
@@ -67,7 +67,8 @@ void GraphicsSettings::Apply()
|
||||
Graphics::AllowCSMBlending = AllowCSMBlending;
|
||||
Graphics::GlobalSDFQuality = GlobalSDFQuality;
|
||||
Graphics::GIQuality = GIQuality;
|
||||
Graphics::PostProcessSettings = PostProcessSettings;
|
||||
Graphics::PostProcessSettings = ::PostProcessSettings();
|
||||
Graphics::PostProcessSettings.BlendWith(PostProcessSettings, 1.0f);
|
||||
}
|
||||
|
||||
void Graphics::DisposeDevice()
|
||||
|
||||
@@ -31,19 +31,19 @@ public:
|
||||
/// <summary>
|
||||
/// Directional light that is used to simulate the sun.
|
||||
/// </summary>
|
||||
API_FIELD(Attributes="EditorOrder(10), DefaultValue(null), EditorDisplay(\"Sun\")")
|
||||
API_FIELD(Attributes="EditorOrder(10), DefaultValue(null), EditorDisplay(\"Sky\")")
|
||||
ScriptingObjectReference<DirectionalLight> SunLight;
|
||||
|
||||
/// <summary>
|
||||
/// The sun disc scale.
|
||||
/// </summary>
|
||||
API_FIELD(Attributes="EditorOrder(20), DefaultValue(2.0f), EditorDisplay(\"Sun\"), Limit(0, 100, 0.01f)")
|
||||
API_FIELD(Attributes="EditorOrder(20), DefaultValue(2.0f), EditorDisplay(\"Sky\"), Limit(0, 100, 0.01f)")
|
||||
float SunDiscScale = 2.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The sun power.
|
||||
/// </summary>
|
||||
API_FIELD(Attributes="EditorOrder(30), DefaultValue(8.0f), EditorDisplay(\"Sun\"), Limit(0, 1000, 0.01f)")
|
||||
API_FIELD(Attributes="EditorOrder(30), DefaultValue(8.0f), EditorDisplay(\"Sky\"), Limit(0, 1000, 0.01f)")
|
||||
float SunPower = 8.0f;
|
||||
|
||||
private:
|
||||
|
||||
@@ -1064,6 +1064,7 @@ bool Level::loadScene(rapidjson_flax::Value& data, int32 engineBuild, Scene** ou
|
||||
}
|
||||
}
|
||||
}
|
||||
prefabSyncData.InitNewObjects();
|
||||
}
|
||||
|
||||
// /\ all above this has to be done on an any thread
|
||||
|
||||
@@ -403,6 +403,15 @@ SceneObjectsFactory::PrefabSyncData::PrefabSyncData(Array<SceneObject*>& sceneOb
|
||||
{
|
||||
}
|
||||
|
||||
void SceneObjectsFactory::PrefabSyncData::InitNewObjects()
|
||||
{
|
||||
for (int32 i = 0; i < NewObjects.Count(); i++)
|
||||
{
|
||||
SceneObject* obj = SceneObjects[InitialCount + i];
|
||||
obj->Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
void SceneObjectsFactory::SetupPrefabInstances(Context& context, const PrefabSyncData& data)
|
||||
{
|
||||
PROFILE_CPU_NAMED("SetupPrefabInstances");
|
||||
|
||||
@@ -78,6 +78,7 @@ public:
|
||||
ISerializeModifier* Modifier;
|
||||
|
||||
PrefabSyncData(Array<SceneObject*>& sceneObjects, const ISerializable::DeserializeStream& data, ISerializeModifier* modifier);
|
||||
void InitNewObjects();
|
||||
|
||||
private:
|
||||
struct NewObj
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <dlfcn.h>
|
||||
#if CRASH_LOG_ENABLE
|
||||
#include <execinfo.h>
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
CPUInfo Cpu;
|
||||
@@ -502,20 +503,42 @@ Array<ApplePlatform::StackFrame> ApplePlatform::GetStackFrames(int32 skipCount,
|
||||
{
|
||||
char** names = backtrace_symbols(callstack + skipCount, useCount);
|
||||
result.Resize(useCount);
|
||||
Array<StringAnsi> parts;
|
||||
int32 len;
|
||||
#define COPY_STR(str, dst) \
|
||||
len = Math::Min<int32>(str.Length(), ARRAY_COUNT(frame.dst) - 1); \
|
||||
Platform::MemoryCopy(frame.dst, str.Get(), len); \
|
||||
frame.dst[len] = 0
|
||||
for (int32 i = 0; i < useCount; i++)
|
||||
{
|
||||
char* name = names[i];
|
||||
const StringAnsi name(names[i]);
|
||||
StackFrame& frame = result[i];
|
||||
frame.ProgramCounter = callstack[skipCount + i];
|
||||
frame.ModuleName[0] = 0;
|
||||
frame.FileName[0] = 0;
|
||||
frame.LineNumber = 0;
|
||||
int32 nameLen = Math::Min<int32>(StringUtils::Length(name), ARRAY_COUNT(frame.FunctionName) - 1);
|
||||
Platform::MemoryCopy(frame.FunctionName, name, nameLen);
|
||||
frame.FunctionName[nameLen] = 0;
|
||||
|
||||
|
||||
// Decode name
|
||||
parts.Clear();
|
||||
name.Split(' ', parts);
|
||||
if (parts.Count() == 6)
|
||||
{
|
||||
COPY_STR(parts[1], ModuleName);
|
||||
const StringAnsiView toDemangle(parts[3]);
|
||||
int status = 0;
|
||||
char* demangled = __cxxabiv1::__cxa_demangle(*toDemangle, 0, 0, &status);
|
||||
const StringAnsiView toCopy = demangled && status == 0 ? StringAnsiView(demangled) : StringAnsiView(toDemangle);
|
||||
COPY_STR(toCopy, FunctionName);
|
||||
if (demangled)
|
||||
free(demangled);
|
||||
}
|
||||
else
|
||||
{
|
||||
COPY_STR(name, FunctionName);
|
||||
}
|
||||
}
|
||||
free(names);
|
||||
#undef COPY_STR
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
|
||||
@@ -633,14 +633,21 @@ String PlatformBase::GetStackTrace(int32 skipCount, int32 maxDepth, void* contex
|
||||
for (const auto& frame : stackFrames)
|
||||
{
|
||||
StringAsUTF16<ARRAY_COUNT(StackFrame::FunctionName)> functionName(frame.FunctionName);
|
||||
const StringView functionNameStr(functionName.Get());
|
||||
if (StringUtils::Length(frame.FileName) != 0)
|
||||
{
|
||||
StringAsUTF16<ARRAY_COUNT(StackFrame::FileName)> fileName(frame.FileName);
|
||||
result.AppendFormat(TEXT(" at {0}() in {1}:line {2}\n"), functionName.Get(), fileName.Get(), frame.LineNumber);
|
||||
result.Append(TEXT(" at ")).Append(functionNameStr);
|
||||
if (!functionNameStr.EndsWith(')'))
|
||||
result.Append(TEXT("()"));
|
||||
result.AppendFormat(TEXT("in {0}:line {1}\n"),fileName.Get(), frame.LineNumber);
|
||||
}
|
||||
else if (StringUtils::Length(frame.FunctionName) != 0)
|
||||
{
|
||||
result.AppendFormat(TEXT(" at {0}()\n"), functionName.Get());
|
||||
result.Append(TEXT(" at ")).Append(functionNameStr);
|
||||
if (!functionNameStr.EndsWith(')'))
|
||||
result.Append(TEXT("()"));
|
||||
result.Append('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -249,11 +249,17 @@ namespace Flax.Build
|
||||
if (dotnetSdkVersions == null)
|
||||
dotnetSdkVersions = GetVersions(Path.Combine(dotnetPath, "sdk"));
|
||||
if (dotnetRuntimeVersions == null)
|
||||
dotnetRuntimeVersions = GetVersions(Path.Combine(dotnetPath, "shared/Microsoft.NETCore.App"));
|
||||
dotnetRuntimeVersions = GetVersions(Path.Combine(dotnetPath, "shared", "Microsoft.NETCore.App"));
|
||||
|
||||
dotnetSdkVersions = dotnetSdkVersions.Where(x => IsValidVersion(Path.Combine(dotnetPath, "sdk", x)));
|
||||
dotnetRuntimeVersions = dotnetRuntimeVersions.Where(x => IsValidVersion(Path.Combine(dotnetPath, "shared", "Microsoft.NETCore.App", x)));
|
||||
|
||||
dotnetSdkVersions = dotnetSdkVersions.OrderByDescending(ParseVersion);
|
||||
dotnetRuntimeVersions = dotnetRuntimeVersions.OrderByDescending(ParseVersion);
|
||||
|
||||
Log.Verbose($"Found the following .NET SDK versions: {string.Join(", ", dotnetSdkVersions)}");
|
||||
Log.Verbose($"Found the following .NET runtime versions: {string.Join(", ", dotnetRuntimeVersions)}");
|
||||
|
||||
string dotnetSdkVersion = dotnetSdkVersions.FirstOrDefault(x => ParseVersion(x).Major >= MinimumVersion.Major && ParseVersion(x).Major <= MaximumVersion.Major);
|
||||
string dotnetRuntimeVersion = dotnetRuntimeVersions.FirstOrDefault(x => ParseVersion(x).Major >= MinimumVersion.Major && ParseVersion(x).Major <= MaximumVersion.Major);
|
||||
if (string.IsNullOrEmpty(dotnetSdkVersion))
|
||||
@@ -276,7 +282,7 @@ namespace Flax.Build
|
||||
// Pick SDK runtime
|
||||
if (!TryAddHostRuntime(platform, architecture, rid) && !TryAddHostRuntime(platform, architecture, ridFallback))
|
||||
{
|
||||
var path = Path.Combine(RootPath, $"packs/Microsoft.NETCore.App.Host.{rid}/{RuntimeVersionName}/runtimes/{rid}/native");
|
||||
var path = Path.Combine(RootPath, "packs", $"Microsoft.NETCore.App.Host.{rid}", RuntimeVersionName, "runtimes", rid, "native");
|
||||
Log.Warning($"Missing .NET SDK host runtime for {platform} {architecture} ({path}).");
|
||||
return;
|
||||
}
|
||||
@@ -465,6 +471,11 @@ namespace Flax.Build
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
private static bool IsValidVersion(string versionPath)
|
||||
{
|
||||
return File.Exists(Path.Combine(versionPath, ".version"));
|
||||
}
|
||||
|
||||
private static string SearchForDotnetLocationLinux()
|
||||
{
|
||||
if (File.Exists("/etc/dotnet/install_location")) // Officially recommended dotnet location file
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "7.0.0",
|
||||
"rollForward": "latestMinor"
|
||||
"rollForward": "latestMajor"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "7.0.0",
|
||||
"rollForward": "latestMinor"
|
||||
"rollForward": "latestMajor"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user