cardinal dir snapping
This commit is contained in:
parent
85b040bdfe
commit
6f1d1acbfb
5 changed files with 47 additions and 13 deletions
|
@ -43,8 +43,8 @@ public class Monolith : MonoBehaviour
|
|||
break;
|
||||
|
||||
case Scene.Pixelgon:
|
||||
// toolNewQuad.Frame(input, pixelgon);
|
||||
// render.ToolNewQuad(toolNewQuad);
|
||||
// toolNewQuad.Frame(input, pixelgon);
|
||||
// render.ToolNewQuad(toolNewQuad);
|
||||
if (input.offCon.two.down)
|
||||
{
|
||||
toolNewVector.Reset();
|
||||
|
@ -125,6 +125,30 @@ public static class StaticMethods
|
|||
}
|
||||
}
|
||||
|
||||
static Vector3[] snappingDir = new Vector3[] { Vector3.right, Vector3.up, Vector3.forward };
|
||||
public static Vector3 DirSnap(Vector3 a, Vector3 c)
|
||||
{
|
||||
for (int i = 0; i < snappingDir.Length; i++)
|
||||
{
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
Vector3 snapDir = snappingDir[i];
|
||||
if (j == 1)
|
||||
{
|
||||
snapDir = snappingDir[i] * -1f; // right -> left etc.
|
||||
}
|
||||
|
||||
Vector3 dir = (c - a).normalized;
|
||||
if (Vector3.Angle(snapDir, dir) < 8f) // dir snapping margin
|
||||
{
|
||||
return a + snapDir * Vector3.Distance(a, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public static Vector3 EdgeSnap(Vector3 a, Vector3 b, Vector3 c)
|
||||
{
|
||||
Quaternion perspective = Quaternion.LookRotation(b - a);
|
||||
|
@ -144,6 +168,8 @@ public static class StaticMethods
|
|||
// snapping margin, where is this variable?
|
||||
// idk becuase this snapping system will be reused in tools and quads
|
||||
// scalable 0-1 * design (0 == no snapping) set parameter in ORIEL UI
|
||||
|
||||
// min distance to handle 2+ conflicting snaps
|
||||
if (dist < 0.02f)
|
||||
{
|
||||
pC.x = pA.x;
|
||||
|
|
|
@ -6,6 +6,7 @@ using UnityEngine;
|
|||
[Serializable]
|
||||
public class Pixelgon
|
||||
{
|
||||
// Just Data
|
||||
// public List<Mesh> quads = new List<Mesh>(); // one material, one texture, map uv accordingly
|
||||
public List<Vector3> vectors = new List<Vector3>(); // mapped to one List with null break vectors
|
||||
}
|
|
@ -6,5 +6,6 @@ using System.Collections.Generic;
|
|||
[Serializable]
|
||||
public class StretchSilo
|
||||
{
|
||||
// Just Data
|
||||
public Vector3 structure;
|
||||
}
|
|
@ -19,6 +19,7 @@ public class ToolNewVector
|
|||
|
||||
public void Frame(Input input, Pixelgon pixelgon)
|
||||
{
|
||||
bool snapped = false;
|
||||
cursorPos = input.twistCursor;
|
||||
|
||||
int length = 0;
|
||||
|
@ -32,9 +33,6 @@ public class ToolNewVector
|
|||
{
|
||||
if (length > 0)
|
||||
{
|
||||
// how to switch between edge snap and direction snap
|
||||
// can you have them both happening at the same time?
|
||||
// is it a priority based system?
|
||||
cursorPos = StaticMethods.EdgeSnap(
|
||||
pixelgon.vectors[i - 1],
|
||||
pixelgon.vectors[i],
|
||||
|
@ -42,6 +40,10 @@ public class ToolNewVector
|
|||
);
|
||||
if (cursorPos != input.twistCursor)
|
||||
{
|
||||
// how to switch between edge snap and direction snap
|
||||
// can you have them both happening at the same time?
|
||||
// is it a priority based system?
|
||||
snapped = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +52,18 @@ public class ToolNewVector
|
|||
}
|
||||
}
|
||||
|
||||
if (!snapped && vector.Count > 1)
|
||||
{
|
||||
cursorPos = StaticMethods.DirSnap(vector[vector.Count - 2], cursorPos);
|
||||
if (cursorPos != input.twistCursor)
|
||||
{
|
||||
// how to switch between edge snap and direction snap
|
||||
// can you have them both happening at the same time?
|
||||
// is it a priority based system?
|
||||
snapped = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.mainCon.trigger.down)
|
||||
{
|
||||
vector.Add(cursorPos);
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a5b4216e803c33a4fb96579e8f0d4bef
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Reference in a new issue