new quad tool implemented but not integrated into serialization/save system
This commit is contained in:
parent
92f3fc5df2
commit
39acb700e1
7 changed files with 139 additions and 79 deletions
|
@ -196,11 +196,14 @@ MonoBehaviour:
|
||||||
held: 0
|
held: 0
|
||||||
up: 0
|
up: 0
|
||||||
twistCursor: {x: 0, y: 0, z: 0}
|
twistCursor: {x: 0, y: 0, z: 0}
|
||||||
|
stretchCursor: {x: 0, y: 0, z: 0}
|
||||||
pixelgon:
|
pixelgon:
|
||||||
vectors: []
|
vectors: []
|
||||||
|
quads:
|
||||||
assetSpace:
|
assetSpace:
|
||||||
folderPath: C:/dofdev/Pixelgon/Assets/AssetSpace
|
folderPath: C:/dofdev/Pixelgon/Assets/AssetSpace
|
||||||
name: draft
|
name: draft
|
||||||
|
loadedNames: []
|
||||||
toolNewVector:
|
toolNewVector:
|
||||||
cursorPos: {x: 0, y: 0, z: 0}
|
cursorPos: {x: 0, y: 0, z: 0}
|
||||||
vector: []
|
vector: []
|
||||||
|
@ -211,6 +214,12 @@ MonoBehaviour:
|
||||||
fromCorner: {x: 0, y: 0, z: 0}
|
fromCorner: {x: 0, y: 0, z: 0}
|
||||||
toCorner: {x: 0, y: 0, z: 0}
|
toCorner: {x: 0, y: 0, z: 0}
|
||||||
selected:
|
selected:
|
||||||
|
toolNewQuad:
|
||||||
|
cursorPos: {x: 0, y: 0, z: 0}
|
||||||
|
indexQuad: 0
|
||||||
|
quad:
|
||||||
|
tris:
|
||||||
|
uvs: []
|
||||||
toolEraser:
|
toolEraser:
|
||||||
cursorPos: {x: 0, y: 0, z: 0}
|
cursorPos: {x: 0, y: 0, z: 0}
|
||||||
selected:
|
selected:
|
||||||
|
@ -244,9 +253,11 @@ MonoBehaviour:
|
||||||
type: 3}
|
type: 3}
|
||||||
meshBoxSelect: {fileID: -9071155252399151903, guid: dc6240c783ee7974e8811c10e071e0cc,
|
meshBoxSelect: {fileID: -9071155252399151903, guid: dc6240c783ee7974e8811c10e071e0cc,
|
||||||
type: 3}
|
type: 3}
|
||||||
|
meshToolNewQuad: {fileID: 6254183033293086303, guid: dc6240c783ee7974e8811c10e071e0cc,
|
||||||
|
type: 3}
|
||||||
meshToolEraser: {fileID: -2868880653068191277, guid: dc6240c783ee7974e8811c10e071e0cc,
|
meshToolEraser: {fileID: -2868880653068191277, guid: dc6240c783ee7974e8811c10e071e0cc,
|
||||||
type: 3}
|
type: 3}
|
||||||
scene: 0
|
scene: 1
|
||||||
--- !u!1 &162671503
|
--- !u!1 &162671503
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -82,7 +82,8 @@ public class AssetSpace
|
||||||
|
|
||||||
if (input.mainCon.one.held)
|
if (input.mainCon.one.held)
|
||||||
{
|
{
|
||||||
assets[held].rot *= input.offCon.physical.Rot() * Quaternion.Inverse(oldOffConRot);
|
Quaternion rotDelta = input.offCon.physical.Rot() * Quaternion.Inverse(oldOffConRot);
|
||||||
|
assets[held].rot = rotDelta * assets[held].rot;
|
||||||
// assets[held].rot *= Quaternion.LookRotation(cursorPos - assets[held].pos) *
|
// assets[held].rot *= Quaternion.LookRotation(cursorPos - assets[held].pos) *
|
||||||
// Quaternion.Inverse(Quaternion.LookRotation(oldCursorPos - assets[held].pos));
|
// Quaternion.Inverse(Quaternion.LookRotation(oldCursorPos - assets[held].pos));
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,12 @@ public class Monolith : MonoBehaviour
|
||||||
[Button] public void Load() { pixelgon = assetSpace.Load(); }
|
[Button] public void Load() { pixelgon = assetSpace.Load(); }
|
||||||
|
|
||||||
// Tools/Systems
|
// Tools/Systems
|
||||||
// public ToolNewQuad toolNewQuad;
|
|
||||||
public ToolNewVector toolNewVector;
|
public ToolNewVector toolNewVector;
|
||||||
public ToolEditVector toolEditVector;
|
public ToolEditVector toolEditVector;
|
||||||
|
|
||||||
|
public ToolNewQuad toolNewQuad;
|
||||||
|
// public ToolEditQuad toolEditQuad;
|
||||||
|
|
||||||
public ToolEraser toolEraser;
|
public ToolEraser toolEraser;
|
||||||
|
|
||||||
// stretch-silo
|
// stretch-silo
|
||||||
|
@ -49,8 +52,12 @@ public class Monolith : MonoBehaviour
|
||||||
{
|
{
|
||||||
toolNewVector.Reset();
|
toolNewVector.Reset();
|
||||||
toolEditVector.Reset();
|
toolEditVector.Reset();
|
||||||
|
|
||||||
|
toolNewQuad.Reset();
|
||||||
|
|
||||||
toolEraser.Reset();
|
toolEraser.Reset();
|
||||||
if (toolIndex < 2)
|
|
||||||
|
if (toolIndex < 3)
|
||||||
{
|
{
|
||||||
toolIndex++;
|
toolIndex++;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +78,10 @@ public class Monolith : MonoBehaviour
|
||||||
render.ToolEditVector(toolEditVector);
|
render.ToolEditVector(toolEditVector);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
toolNewQuad.Frame(input, pixelgon);
|
||||||
|
render.ToolNewQuad(toolNewQuad, pixelgon);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
toolEraser.Frame(input, pixelgon);
|
toolEraser.Frame(input, pixelgon);
|
||||||
render.ToolEraser(toolEraser);
|
render.ToolEraser(toolEraser);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -7,6 +7,6 @@ using UnityEngine;
|
||||||
public class Pixelgon
|
public class Pixelgon
|
||||||
{
|
{
|
||||||
// Just Data
|
// 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
|
public List<Vector3> vectors = new List<Vector3>(); // mapped to one List with null break vectors
|
||||||
|
public List<int> quads = new List<int>();
|
||||||
}
|
}
|
|
@ -13,6 +13,7 @@ public class Render
|
||||||
List<int> selectedJoints = new List<int>();
|
List<int> selectedJoints = new List<int>();
|
||||||
Matrix4x4 orielM4 = new Matrix4x4();
|
Matrix4x4 orielM4 = new Matrix4x4();
|
||||||
Matrix4x4 axisM4 = new Matrix4x4();
|
Matrix4x4 axisM4 = new Matrix4x4();
|
||||||
|
Mesh quads;
|
||||||
public void Pixelgon(Pixelgon pixelgon)
|
public void Pixelgon(Pixelgon pixelgon)
|
||||||
{
|
{
|
||||||
orielM4.SetTRS(Vector3.zero, Quaternion.identity, new Vector3(0.6f, 0.4f, 0.4f));
|
orielM4.SetTRS(Vector3.zero, Quaternion.identity, new Vector3(0.6f, 0.4f, 0.4f));
|
||||||
|
@ -33,6 +34,43 @@ public class Render
|
||||||
}
|
}
|
||||||
selectedJoints.Clear();
|
selectedJoints.Clear();
|
||||||
|
|
||||||
|
if (quads == null)
|
||||||
|
{
|
||||||
|
quads = new Mesh();
|
||||||
|
}
|
||||||
|
|
||||||
|
// w/triangle seam between the two closest points
|
||||||
|
List<int> tris = new List<int>();
|
||||||
|
for (int i = 0; i < pixelgon.quads.Count; i += 4)
|
||||||
|
{
|
||||||
|
if (Vector3.Distance(pixelgon.vectors[pixelgon.quads[i + 0]], pixelgon.vectors[pixelgon.quads[i + 2]])
|
||||||
|
< Vector3.Distance(pixelgon.vectors[pixelgon.quads[i + 1]], pixelgon.vectors[pixelgon.quads[i + 3]]))
|
||||||
|
{
|
||||||
|
tris.Add(pixelgon.quads[i + 0]);
|
||||||
|
tris.Add(pixelgon.quads[i + 1]);
|
||||||
|
tris.Add(pixelgon.quads[i + 2]);
|
||||||
|
|
||||||
|
tris.Add(pixelgon.quads[i + 2]);
|
||||||
|
tris.Add(pixelgon.quads[i + 3]);
|
||||||
|
tris.Add(pixelgon.quads[i + 0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tris.Add(pixelgon.quads[i + 0]);
|
||||||
|
tris.Add(pixelgon.quads[i + 1]);
|
||||||
|
tris.Add(pixelgon.quads[i + 3]);
|
||||||
|
|
||||||
|
tris.Add(pixelgon.quads[i + 3]);
|
||||||
|
tris.Add(pixelgon.quads[i + 1]);
|
||||||
|
tris.Add(pixelgon.quads[i + 2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
quads.SetVertices(pixelgon.vectors);
|
||||||
|
quads.SetTriangles(tris, 0);
|
||||||
|
|
||||||
|
Graphics.DrawMesh(quads, Vector3.zero, Quaternion.identity, matVertexLit, 0);
|
||||||
|
|
||||||
// Now for pixels!
|
// Now for pixels!
|
||||||
// float pixelsPerMeter = 24;
|
// float pixelsPerMeter = 24;
|
||||||
// int texDiameter = Mathf.RoundToInt(
|
// int texDiameter = Mathf.RoundToInt(
|
||||||
|
@ -107,6 +145,22 @@ public class Render
|
||||||
selectedJoints.AddRange(toolEditVector.selected);
|
selectedJoints.AddRange(toolEditVector.selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Mesh meshToolNewQuad;
|
||||||
|
Mesh newQuad;
|
||||||
|
public void ToolNewQuad(ToolNewQuad toolNewQuad, Pixelgon pixelgon)
|
||||||
|
{
|
||||||
|
Graphics.DrawMesh(meshToolNewQuad,
|
||||||
|
toolNewQuad.cursorPos,
|
||||||
|
Quaternion.identity,
|
||||||
|
matVertexLit, 0
|
||||||
|
);
|
||||||
|
|
||||||
|
if (toolNewQuad.indexQuad > 0)
|
||||||
|
{
|
||||||
|
selectedJoints.AddRange(toolNewQuad.quad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Mesh meshToolEraser;
|
public Mesh meshToolEraser;
|
||||||
public void ToolEraser(ToolEraser toolEraser)
|
public void ToolEraser(ToolEraser toolEraser)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,49 +6,47 @@ using UnityEngine;
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ToolNewQuad
|
public class ToolNewQuad
|
||||||
{
|
{
|
||||||
public Transform planar;
|
|
||||||
|
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
public Vector3 cursorPos;
|
public Vector3 cursorPos;
|
||||||
[HideInInspector]
|
|
||||||
public Mesh mesh;
|
|
||||||
[HideInInspector]
|
|
||||||
public Vector3[] quad = new Vector3[4];
|
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
public int indexQuad = 0;
|
public int indexQuad = 0;
|
||||||
|
[HideInInspector]
|
||||||
|
public int[] quad = new int[4];
|
||||||
|
|
||||||
int[] tris = new int[6];
|
// [HideInInspector]
|
||||||
Vector2[] uvs = new Vector2[4];
|
// public Vector2[] uvs = new Vector2[4];
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
indexQuad = 0;
|
||||||
|
|
||||||
|
quad = new int[4];
|
||||||
|
}
|
||||||
|
|
||||||
public void Frame(Input input, Pixelgon pixelgon)
|
public void Frame(Input input, Pixelgon pixelgon)
|
||||||
{
|
{
|
||||||
List<Mesh> quads = new List<Mesh>();
|
|
||||||
// pixelgon.quads; // for convenience
|
|
||||||
cursorPos = input.twistCursor; // can do more ^-^
|
cursorPos = input.twistCursor; // can do more ^-^
|
||||||
|
|
||||||
|
List<Vector3> vectors = pixelgon.vectors;
|
||||||
|
|
||||||
|
if (vectors.Count < 3)
|
||||||
|
{
|
||||||
|
Debug.Log("Not enough vectors, to form a Quad");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// vertice snapping
|
// vertice snapping
|
||||||
if (input.mainCon.one.held)
|
int closestVector = 0;
|
||||||
|
for (int i = 0; i < vectors.Count; i++)
|
||||||
{
|
{
|
||||||
Vector3 closestVertice = Vector3.one * 666; // lol
|
if ((vectors[i] - cursorPos).sqrMagnitude < (vectors[closestVector] - cursorPos).sqrMagnitude)
|
||||||
for (int i = 0; i < quads.Count; i++)
|
|
||||||
{
|
{
|
||||||
for (int j = 0; j < quads[i].vertices.Length; j++)
|
closestVector = i;
|
||||||
{
|
|
||||||
if ((quads[i].vertices[j] - cursorPos).sqrMagnitude <
|
|
||||||
(closestVertice - cursorPos).sqrMagnitude)
|
|
||||||
{
|
|
||||||
closestVertice = quads[i].vertices[j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((closestVertice - cursorPos).magnitude < 0.02f) // hard coded
|
|
||||||
{
|
|
||||||
cursorPos = closestVertice;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
planar.position = (quad[0] + quad[1] + quad[2] + quad[3]) / 4;
|
cursorPos = vectors[closestVector];
|
||||||
|
|
||||||
switch (indexQuad)
|
switch (indexQuad)
|
||||||
{
|
{
|
||||||
|
@ -57,14 +55,14 @@ public class ToolNewQuad
|
||||||
{
|
{
|
||||||
for (int i = 0; i < quad.Length; i++)
|
for (int i = 0; i < quad.Length; i++)
|
||||||
{
|
{
|
||||||
quad[i] = cursorPos;
|
quad[i] = closestVector;
|
||||||
}
|
}
|
||||||
|
|
||||||
indexQuad++;
|
indexQuad++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (1):
|
case (1):
|
||||||
quad[indexQuad] = cursorPos;
|
quad[indexQuad] = closestVector;
|
||||||
|
|
||||||
if (input.mainCon.trigger.down)
|
if (input.mainCon.trigger.down)
|
||||||
{
|
{
|
||||||
|
@ -72,7 +70,7 @@ public class ToolNewQuad
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (2):
|
case (2):
|
||||||
quad[indexQuad] = cursorPos;
|
quad[indexQuad] = closestVector;
|
||||||
|
|
||||||
if (input.mainCon.trigger.down)
|
if (input.mainCon.trigger.down)
|
||||||
{
|
{
|
||||||
|
@ -80,56 +78,41 @@ public class ToolNewQuad
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (3):
|
case (3):
|
||||||
Vector3 v3 = Vector3.Cross(quad[0] - quad[1], quad[2] - quad[1]).normalized;
|
quad[indexQuad] = closestVector;
|
||||||
planar.rotation = Quaternion.LookRotation(v3, quad[2] - quad[1]);
|
|
||||||
cursorPos = planar.InverseTransformPoint(cursorPos);
|
|
||||||
cursorPos.z = 0;
|
|
||||||
cursorPos = planar.TransformPoint(cursorPos);
|
|
||||||
|
|
||||||
quad[indexQuad] = cursorPos;
|
|
||||||
|
|
||||||
if (input.mainCon.trigger.down)
|
if (input.mainCon.trigger.down)
|
||||||
{
|
{
|
||||||
// w/triangle seam between the two closest points
|
// int furthest = 0;
|
||||||
if (Vector3.Distance(quad[0], quad[2]) < Vector3.Distance(quad[1], quad[3]))
|
// for (int i = 1; i < quad.Length; i++)
|
||||||
{
|
// {
|
||||||
tris[0] = 0; tris[3] = 2;
|
// if ((vectors[quad[i]] - planar.position).magnitude >
|
||||||
tris[1] = 1; tris[4] = 3;
|
// (vectors[quad[furthest]] - planar.position).magnitude)
|
||||||
tris[2] = 2; tris[5] = 0;
|
// {
|
||||||
}
|
// furthest = i;
|
||||||
else
|
// }
|
||||||
{
|
// }
|
||||||
tris[0] = 0; tris[3] = 3;
|
|
||||||
tris[1] = 1; tris[4] = 1;
|
|
||||||
tris[2] = 3; tris[5] = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
int furthest = 0;
|
// float scale = planar.InverseTransformPoint(vectors[quad[furthest]]).magnitude;
|
||||||
for (int i = 1; i < quad.Length; i++)
|
|
||||||
{
|
|
||||||
if ((quad[i] - planar.position).magnitude >
|
|
||||||
(quad[furthest] - planar.position).magnitude)
|
|
||||||
{
|
|
||||||
furthest = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float scale = planar.InverseTransformPoint(quad[furthest]).magnitude;
|
// for (int i = 0; i < quad.Length; i++)
|
||||||
|
// {
|
||||||
|
// uvs[i] = ((Vector2)planar.InverseTransformPoint(
|
||||||
|
// vectors[quad[i]]) / (scale * 2)) + new Vector2(0.5f, 0.5f
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// only tris!
|
||||||
|
// that makes everything so much easier
|
||||||
|
// the abstraction then follows the model
|
||||||
|
// vectors = vertices
|
||||||
|
// quads = tri pairs
|
||||||
|
// pixels = uvs
|
||||||
|
|
||||||
for (int i = 0; i < quad.Length; i++)
|
for (int i = 0; i < quad.Length; i++)
|
||||||
{
|
{
|
||||||
uvs[i] = ((Vector2)planar.InverseTransformPoint(
|
pixelgon.quads.Add(quad[i]);
|
||||||
quad[i]) / (scale * 2)) + new Vector2(0.5f, 0.5f
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh = new Mesh();
|
|
||||||
mesh.SetVertices(quad);
|
|
||||||
mesh.SetTriangles(tris, 0);
|
|
||||||
mesh.SetUVs(0, uvs);
|
|
||||||
|
|
||||||
quads.Add(mesh);
|
|
||||||
|
|
||||||
indexQuad = 0;
|
indexQuad = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -79,6 +79,8 @@ public class ToolNewVector
|
||||||
vector.Add(cursorPos);
|
vector.Add(cursorPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector[vector.Count - 1] = cursorPos;
|
||||||
|
|
||||||
if (input.mainCon.two.down)
|
if (input.mainCon.two.down)
|
||||||
{
|
{
|
||||||
if (vector.Count > 2)
|
if (vector.Count > 2)
|
||||||
|
@ -90,8 +92,6 @@ public class ToolNewVector
|
||||||
vector.Clear();
|
vector.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector[vector.Count - 1] = cursorPos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.mainCon.trigger.up)
|
if (input.mainCon.trigger.up)
|
||||||
|
|
Loading…
Add table
Reference in a new issue