Skip to content

Commit

Permalink
Object snap
Browse files Browse the repository at this point in the history
  • Loading branch information
pzgulyas committed Dec 9, 2023
1 parent a3221d4 commit 1b88d7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions Source/Contrib/TrackViewer/UserInterface/SceneView.xaml.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -438,6 +441,7 @@ void CancelObjectMove()
HandlePosition.CopyFrom(HandleOriginalPosition);
else
HandlePosition = null;
Viewer.EditorShapes.BoundingBoxShapes.Clear();
EditorState = EditorState.ObjectSelected;
}

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

DeltaContext = UndoStack.Peek();
MovedObject = null;
Viewer.EditorShapes.BoundingBoxShapes.Clear();
EditorState = EditorState.ObjectSelected;
}

Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/RunActivity/Viewer3D/EditorPrimitives.cs
Expand Up @@ -48,7 +48,7 @@ public class EditorShapes : StaticShape, IDisposable
public WorldPosition MovedObjectLocation { get; set; }
BoundingBoxPrimitive MovedObjectPrimitive;

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

Expand Down

0 comments on commit 1b88d7a

Please sign in to comment.