cardinal dir snapping

This commit is contained in:
spatialfree 2020-06-10 10:57:16 -07:00
parent 85b040bdfe
commit 6f1d1acbfb
5 changed files with 47 additions and 13 deletions

View file

@ -43,8 +43,8 @@ public class Monolith : MonoBehaviour
break; break;
case Scene.Pixelgon: case Scene.Pixelgon:
// toolNewQuad.Frame(input, pixelgon); // toolNewQuad.Frame(input, pixelgon);
// render.ToolNewQuad(toolNewQuad); // render.ToolNewQuad(toolNewQuad);
if (input.offCon.two.down) if (input.offCon.two.down)
{ {
toolNewVector.Reset(); 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) public static Vector3 EdgeSnap(Vector3 a, Vector3 b, Vector3 c)
{ {
Quaternion perspective = Quaternion.LookRotation(b - a); Quaternion perspective = Quaternion.LookRotation(b - a);
@ -144,6 +168,8 @@ public static class StaticMethods
// snapping margin, where is this variable? // snapping margin, where is this variable?
// idk becuase this snapping system will be reused in tools and quads // idk becuase this snapping system will be reused in tools and quads
// scalable 0-1 * design (0 == no snapping) set parameter in ORIEL UI // scalable 0-1 * design (0 == no snapping) set parameter in ORIEL UI
// min distance to handle 2+ conflicting snaps
if (dist < 0.02f) if (dist < 0.02f)
{ {
pC.x = pA.x; pC.x = pA.x;

View file

@ -6,6 +6,7 @@ using UnityEngine;
[Serializable] [Serializable]
public class Pixelgon public class Pixelgon
{ {
// Just Data
// public List<Mesh> quads = new List<Mesh>(); // one material, one texture, map uv accordingly // 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 public List<Vector3> vectors = new List<Vector3>(); // mapped to one List with null break vectors
} }

View file

@ -6,5 +6,6 @@ using System.Collections.Generic;
[Serializable] [Serializable]
public class StretchSilo public class StretchSilo
{ {
// Just Data
public Vector3 structure; public Vector3 structure;
} }

View file

@ -19,6 +19,7 @@ public class ToolNewVector
public void Frame(Input input, Pixelgon pixelgon) public void Frame(Input input, Pixelgon pixelgon)
{ {
bool snapped = false;
cursorPos = input.twistCursor; cursorPos = input.twistCursor;
int length = 0; int length = 0;
@ -32,9 +33,6 @@ public class ToolNewVector
{ {
if (length > 0) 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( cursorPos = StaticMethods.EdgeSnap(
pixelgon.vectors[i - 1], pixelgon.vectors[i - 1],
pixelgon.vectors[i], pixelgon.vectors[i],
@ -42,6 +40,10 @@ public class ToolNewVector
); );
if (cursorPos != input.twistCursor) 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; 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) if (input.mainCon.trigger.down)
{ {
vector.Add(cursorPos); vector.Add(cursorPos);

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: a5b4216e803c33a4fb96579e8f0d4bef
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: