Skip to content

Commit

Permalink
Enable support for snapping when using scripted tools
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Jan 3, 2025
1 parent b1ed976 commit e5e99e6
Show file tree
Hide file tree
Showing 2 changed files with 289 additions and 277 deletions.
11 changes: 9 additions & 2 deletions Assets/Scripts/API/Lua/LuaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,13 @@ public void DoToolScript(string fnName, TrTransform firstTr_CS, TrTransform seco
var result = CallActiveToolScript(fnName);
if (result == null) return;
List<List<TrTransform>> transforms = null;

var drawnVector_CS = secondTr_CS.translation - firstTr_CS.translation;
// Quantize the positions to the grid
// Rotation will be quantized later based on (non-quantized) drawnVector_CS
firstTr_CS.translation = SelectionManager.m_Instance.SnapToGrid_CS(firstTr_CS.translation);
secondTr_CS.translation = SelectionManager.m_Instance.SnapToGrid_CS(secondTr_CS.translation);
var quantizedVector_CS = secondTr_CS.translation - firstTr_CS.translation;

var tr_CS = new TrTransform();

switch (result._Space)
Expand All @@ -1223,7 +1228,7 @@ public void DoToolScript(string fnName, TrTransform firstTr_CS, TrTransform seco
tr_CS.translation = firstTr_CS.translation;
tr_CS.rotation = drawnVector_CS == Vector3.zero ?
Quaternion.identity : Quaternion.LookRotation(drawnVector_CS, upVector);
tr_CS.scale = drawnVector_CS.magnitude;
tr_CS.scale = quantizedVector_CS.magnitude;
transforms = result.AsMultiTrList();
break;
case ScriptCoordSpace.Canvas:
Expand All @@ -1235,6 +1240,8 @@ public void DoToolScript(string fnName, TrTransform firstTr_CS, TrTransform seco
}
float brushScale = 1f;

tr_CS.rotation = SelectionManager.m_Instance.QuantizeAngle(tr_CS.rotation);

if (transforms != null) DrawStrokes.DrawNestedTrList(transforms, tr_CS, result._Colors, brushScale);
if (result._Colors == null)
{
Expand Down
Loading

0 comments on commit e5e99e6

Please sign in to comment.