Skip to content

Commit

Permalink
Create object at axes position
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Jun 27, 2024
1 parent 8317b2c commit 463b611
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Assets/VoxelEditor/VoxelArrayEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public enum SelectMode
private Substance boxSelectSubstance = null;
// dummy Substance to use for boxSelectSubstance when selecting objects
private readonly Substance selectObjectSubstance = new Substance();
// Used for: box selection, axes placement, object creation
// Used for: box selection, measurement UI
public Bounds selectionBounds = new Bounds(Vector3.zero, Vector3.zero);

public Substance substanceToCreate = null;
Expand Down Expand Up @@ -272,7 +272,7 @@ public void TouchDown(Selectable thing)
// avoid issues when tapping things with overlapping bounds
//UpdateBoxSelection();
SelectThing(thing);
SetMoveAxes(selectionBounds.center);
SetMoveAxesSelectionBounds();
}
DisableMoveAxes();
}
Expand Down Expand Up @@ -380,6 +380,11 @@ private void SetMoveAxes(Vector3 position)
axes.position = position;
}

private void SetMoveAxesSelectionBounds()
{
SetMoveAxes(selectionBounds.center);
}

private void DisableMoveAxes()
{
if (axes == null)
Expand Down Expand Up @@ -555,8 +560,8 @@ public void ClearStoredSelection()

private void UpdateBoxSelection()
{
SetMoveAxesSelectionBounds();
var bounds = selectionBounds;
SetMoveAxes(bounds.center);

// update selection...
var toDeselect = new List<Selectable>();
Expand Down Expand Up @@ -687,7 +692,7 @@ private void FaceSelectFloodFill(VoxelFaceLoc start, bool stayOnPlane, bool matc
selectionBounds.Encapsulate(Voxel.FaceBounds(faceLoc));
}

SetMoveAxes(start.position + new Vector3(0.5f, 0.5f, 0.5f) - Voxel.OppositeDirectionForFaceI(start.faceI) / 2);
SetMoveAxes(Voxel.FaceBounds(start).center);
}

public void FillSelectPaint()
Expand Down Expand Up @@ -1499,7 +1504,7 @@ public int GetSelectedFaceNormal()

public void PlaceObject(ObjectEntity obj)
{
Vector3 createPosition = selectionBounds.center; // not int
Vector3 createPosition = axes.position; // not int
Vector3 createDirection = Vector3.up;
int faceNormal = GetSelectedFaceNormal();
if (faceNormal != -1) // same normal for all faces
Expand Down

0 comments on commit 463b611

Please sign in to comment.