Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b88d7a

Browse files
committed
Object snap
1 parent a3221d4 commit 1b88d7a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Source/Contrib/TrackViewer/UserInterface/SceneView.xaml.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,16 @@ public void Update(GameTime gameTime)
109109
{
110110
if (ObjectSnap && Camera.PickByMouse(out var snappedObject))
111111
{
112+
if (snappedObject != SnappedObject)
113+
Viewer.EditorShapes.BoundingBoxShapes.RemoveAll(s => s == SnappedObject);
112114
SnappedObject = snappedObject;
113-
Viewer.EditorShapes.BoundingBoxShapes.Add(SnappedObject);
115+
if (!Viewer.EditorShapes.BoundingBoxShapes.Contains(SnappedObject))
116+
Viewer.EditorShapes.BoundingBoxShapes.Add(SnappedObject);
114117
}
115118
else
116119
{
120+
Viewer.EditorShapes.BoundingBoxShapes.RemoveAll(s => s == SnappedObject);
117121
SnappedObject = null;
118-
Viewer.EditorShapes.BoundingBoxShapes.TryTake(out _);
119122
}
120123
MovedObject.Location.XNAMatrix = GetMovingMatrix(MovedObjectOriginalPosition, HandleOriginalPosition, HandlePosition);
121124
Viewer.EditorShapes.MovedObject = MovedObject;
@@ -438,6 +441,7 @@ void CancelObjectMove()
438441
HandlePosition.CopyFrom(HandleOriginalPosition);
439442
else
440443
HandlePosition = null;
444+
Viewer.EditorShapes.BoundingBoxShapes.Clear();
441445
EditorState = EditorState.ObjectSelected;
442446
}
443447

@@ -457,6 +461,7 @@ void ApplyObjectMove()
457461

458462
DeltaContext = UndoStack.Peek();
459463
MovedObject = null;
464+
Viewer.EditorShapes.BoundingBoxShapes.Clear();
460465
EditorState = EditorState.ObjectSelected;
461466
}
462467

@@ -472,12 +477,14 @@ void CancelHandleMove()
472477
{
473478
HandlePosition = null;
474479
HandleOriginalPosition = null;
480+
Viewer.EditorShapes.BoundingBoxShapes.Clear();
475481
EditorState = EditorState.ObjectSelected;
476482
}
477483

478484
void ApplyHandleMove()
479485
{
480486
HandleOriginalPosition = new WorldPosition(HandlePosition);
487+
Viewer.EditorShapes.BoundingBoxShapes.Clear();
481488
EditorState = EditorState.ObjectSelected;
482489
}
483490

@@ -486,8 +493,7 @@ void SelectedObjectChanged()
486493
Viewer.EditorShapes.SelectedObject = SelectedObject;
487494
Viewer.EditorShapes.MovedObject = null;
488495
Viewer.EditorShapes.HandleLocation = null;
489-
while (!Viewer.EditorShapes.BoundingBoxShapes.IsEmpty)
490-
Viewer.EditorShapes.BoundingBoxShapes.TryTake(out _);
496+
Viewer.EditorShapes.BoundingBoxShapes.Clear();
491497
HandlePosition = null;
492498
HandleOriginalPosition = null;
493499
SnappedObject = null;

Source/RunActivity/Viewer3D/EditorPrimitives.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class EditorShapes : StaticShape, IDisposable
4848
public WorldPosition MovedObjectLocation { get; set; }
4949
BoundingBoxPrimitive MovedObjectPrimitive;
5050

51-
public ConcurrentBag<StaticShape> BoundingBoxShapes = new ConcurrentBag<StaticShape>();
51+
public readonly List<StaticShape> BoundingBoxShapes = new List<StaticShape>();
5252
readonly ConcurrentDictionary<(int tileX, int tileZ, int uid, Matrix matrix, int number), BoundingBoxPrimitive> BoundingBoxPrimitives = new ConcurrentDictionary<(int, int, int, Matrix, int), BoundingBoxPrimitive>();
5353
readonly ConcurrentBag<EditorPrimitive> UnusedPrimitives = new ConcurrentBag<EditorPrimitive>();
5454

0 commit comments

Comments
 (0)