From 1b88d7a75d0634fdad1d0a685281721199f9140f Mon Sep 17 00:00:00 2001 From: Peter Gulyas Date: Sat, 9 Dec 2023 19:50:45 +0100 Subject: [PATCH] Object snap --- .../TrackViewer/UserInterface/SceneView.xaml.cs | 14 ++++++++++---- Source/RunActivity/Viewer3D/EditorPrimitives.cs | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Source/Contrib/TrackViewer/UserInterface/SceneView.xaml.cs b/Source/Contrib/TrackViewer/UserInterface/SceneView.xaml.cs index 25ff054c88..31ae872264 100644 --- a/Source/Contrib/TrackViewer/UserInterface/SceneView.xaml.cs +++ b/Source/Contrib/TrackViewer/UserInterface/SceneView.xaml.cs @@ -109,13 +109,16 @@ public void Update(GameTime gameTime) { if (ObjectSnap && Camera.PickByMouse(out var snappedObject)) { + if (snappedObject != SnappedObject) + Viewer.EditorShapes.BoundingBoxShapes.RemoveAll(s => s == SnappedObject); SnappedObject = snappedObject; - Viewer.EditorShapes.BoundingBoxShapes.Add(SnappedObject); + if (!Viewer.EditorShapes.BoundingBoxShapes.Contains(SnappedObject)) + Viewer.EditorShapes.BoundingBoxShapes.Add(SnappedObject); } else { + Viewer.EditorShapes.BoundingBoxShapes.RemoveAll(s => s == SnappedObject); SnappedObject = null; - Viewer.EditorShapes.BoundingBoxShapes.TryTake(out _); } MovedObject.Location.XNAMatrix = GetMovingMatrix(MovedObjectOriginalPosition, HandleOriginalPosition, HandlePosition); Viewer.EditorShapes.MovedObject = MovedObject; @@ -438,6 +441,7 @@ void CancelObjectMove() HandlePosition.CopyFrom(HandleOriginalPosition); else HandlePosition = null; + Viewer.EditorShapes.BoundingBoxShapes.Clear(); EditorState = EditorState.ObjectSelected; } @@ -457,6 +461,7 @@ void ApplyObjectMove() DeltaContext = UndoStack.Peek(); MovedObject = null; + Viewer.EditorShapes.BoundingBoxShapes.Clear(); EditorState = EditorState.ObjectSelected; } @@ -472,12 +477,14 @@ void CancelHandleMove() { HandlePosition = null; HandleOriginalPosition = null; + Viewer.EditorShapes.BoundingBoxShapes.Clear(); EditorState = EditorState.ObjectSelected; } void ApplyHandleMove() { HandleOriginalPosition = new WorldPosition(HandlePosition); + Viewer.EditorShapes.BoundingBoxShapes.Clear(); EditorState = EditorState.ObjectSelected; } @@ -486,8 +493,7 @@ void SelectedObjectChanged() Viewer.EditorShapes.SelectedObject = SelectedObject; Viewer.EditorShapes.MovedObject = null; Viewer.EditorShapes.HandleLocation = null; - while (!Viewer.EditorShapes.BoundingBoxShapes.IsEmpty) - Viewer.EditorShapes.BoundingBoxShapes.TryTake(out _); + Viewer.EditorShapes.BoundingBoxShapes.Clear(); HandlePosition = null; HandleOriginalPosition = null; SnappedObject = null; diff --git a/Source/RunActivity/Viewer3D/EditorPrimitives.cs b/Source/RunActivity/Viewer3D/EditorPrimitives.cs index 64d55ae524..3ffc48749d 100644 --- a/Source/RunActivity/Viewer3D/EditorPrimitives.cs +++ b/Source/RunActivity/Viewer3D/EditorPrimitives.cs @@ -48,7 +48,7 @@ public class EditorShapes : StaticShape, IDisposable public WorldPosition MovedObjectLocation { get; set; } BoundingBoxPrimitive MovedObjectPrimitive; - public ConcurrentBag BoundingBoxShapes = new ConcurrentBag(); + public readonly List BoundingBoxShapes = new List(); readonly ConcurrentDictionary<(int tileX, int tileZ, int uid, Matrix matrix, int number), BoundingBoxPrimitive> BoundingBoxPrimitives = new ConcurrentDictionary<(int, int, int, Matrix, int), BoundingBoxPrimitive>(); readonly ConcurrentBag UnusedPrimitives = new ConcurrentBag();