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
|
||||
up: 0
|
||||
twistCursor: {x: 0, y: 0, z: 0}
|
||||
stretchCursor: {x: 0, y: 0, z: 0}
|
||||
pixelgon:
|
||||
vectors: []
|
||||
quads:
|
||||
assetSpace:
|
||||
folderPath: C:/dofdev/Pixelgon/Assets/AssetSpace
|
||||
name: draft
|
||||
loadedNames: []
|
||||
toolNewVector:
|
||||
cursorPos: {x: 0, y: 0, z: 0}
|
||||
vector: []
|
||||
|
@ -211,6 +214,12 @@ MonoBehaviour:
|
|||
fromCorner: {x: 0, y: 0, z: 0}
|
||||
toCorner: {x: 0, y: 0, z: 0}
|
||||
selected:
|
||||
toolNewQuad:
|
||||
cursorPos: {x: 0, y: 0, z: 0}
|
||||
indexQuad: 0
|
||||
quad:
|
||||
tris:
|
||||
uvs: []
|
||||
toolEraser:
|
||||
cursorPos: {x: 0, y: 0, z: 0}
|
||||
selected:
|
||||
|
@ -244,9 +253,11 @@ MonoBehaviour:
|
|||
type: 3}
|
||||
meshBoxSelect: {fileID: -9071155252399151903, guid: dc6240c783ee7974e8811c10e071e0cc,
|
||||
type: 3}
|
||||
meshToolNewQuad: {fileID: 6254183033293086303, guid: dc6240c783ee7974e8811c10e071e0cc,
|
||||
type: 3}
|
||||
meshToolEraser: {fileID: -2868880653068191277, guid: dc6240c783ee7974e8811c10e071e0cc,
|
||||
type: 3}
|
||||
scene: 0
|
||||
scene: 1
|
||||
--- !u!1 &162671503
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
@ -82,7 +82,8 @@ public class AssetSpace
|
|||
|
||||
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) *
|
||||
// Quaternion.Inverse(Quaternion.LookRotation(oldCursorPos - assets[held].pos));
|
||||
|
||||
|
|
|
@ -15,9 +15,12 @@ public class Monolith : MonoBehaviour
|
|||
[Button] public void Load() { pixelgon = assetSpace.Load(); }
|
||||
|
||||
// Tools/Systems
|
||||
// public ToolNewQuad toolNewQuad;
|
||||
public ToolNewVector toolNewVector;
|
||||
public ToolEditVector toolEditVector;
|
||||
|
||||
public ToolNewQuad toolNewQuad;
|
||||
// public ToolEditQuad toolEditQuad;
|
||||
|
||||
public ToolEraser toolEraser;
|
||||
|
||||
// stretch-silo
|
||||
|
@ -49,8 +52,12 @@ public class Monolith : MonoBehaviour
|
|||
{
|
||||
toolNewVector.Reset();
|
||||
toolEditVector.Reset();
|
||||
|
||||
toolNewQuad.Reset();
|
||||
|
||||
toolEraser.Reset();
|
||||
if (toolIndex < 2)
|
||||
|
||||
if (toolIndex < 3)
|
||||
{
|
||||
toolIndex++;
|
||||
}
|
||||
|
@ -71,6 +78,10 @@ public class Monolith : MonoBehaviour
|
|||
render.ToolEditVector(toolEditVector);
|
||||
break;
|
||||
case 2:
|
||||
toolNewQuad.Frame(input, pixelgon);
|
||||
render.ToolNewQuad(toolNewQuad, pixelgon);
|
||||
break;
|
||||
case 3:
|
||||
toolEraser.Frame(input, pixelgon);
|
||||
render.ToolEraser(toolEraser);
|
||||
break;
|
||||
|
|
|
@ -7,6 +7,6 @@ using UnityEngine;
|
|||
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
|
||||
public List<int> quads = new List<int>();
|
||||
}
|
|
@ -13,6 +13,7 @@ public class Render
|
|||
List<int> selectedJoints = new List<int>();
|
||||
Matrix4x4 orielM4 = new Matrix4x4();
|
||||
Matrix4x4 axisM4 = new Matrix4x4();
|
||||
Mesh quads;
|
||||
public void Pixelgon(Pixelgon pixelgon)
|
||||
{
|
||||
orielM4.SetTRS(Vector3.zero, Quaternion.identity, new Vector3(0.6f, 0.4f, 0.4f));
|
||||
|
@ -33,6 +34,43 @@ public class Render
|
|||
}
|
||||
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!
|
||||
// float pixelsPerMeter = 24;
|
||||
// int texDiameter = Mathf.RoundToInt(
|
||||
|
@ -107,6 +145,22 @@ public class Render
|
|||
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 void ToolEraser(ToolEraser toolEraser)
|
||||
{
|
||||
|
|
|
@ -6,49 +6,47 @@ using UnityEngine;
|
|||
[Serializable]
|
||||
public class ToolNewQuad
|
||||
{
|
||||
public Transform planar;
|
||||
|
||||
[HideInInspector]
|
||||
public Vector3 cursorPos;
|
||||
[HideInInspector]
|
||||
public Mesh mesh;
|
||||
[HideInInspector]
|
||||
public Vector3[] quad = new Vector3[4];
|
||||
|
||||
[HideInInspector]
|
||||
public int indexQuad = 0;
|
||||
[HideInInspector]
|
||||
public int[] quad = new int[4];
|
||||
|
||||
int[] tris = new int[6];
|
||||
Vector2[] uvs = new Vector2[4];
|
||||
// [HideInInspector]
|
||||
// public Vector2[] uvs = new Vector2[4];
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
indexQuad = 0;
|
||||
|
||||
quad = new int[4];
|
||||
}
|
||||
|
||||
public void Frame(Input input, Pixelgon pixelgon)
|
||||
{
|
||||
List<Mesh> quads = new List<Mesh>();
|
||||
// pixelgon.quads; // for convenience
|
||||
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
|
||||
if (input.mainCon.one.held)
|
||||
int closestVector = 0;
|
||||
for (int i = 0; i < vectors.Count; i++)
|
||||
{
|
||||
Vector3 closestVertice = Vector3.one * 666; // lol
|
||||
for (int i = 0; i < quads.Count; i++)
|
||||
if ((vectors[i] - cursorPos).sqrMagnitude < (vectors[closestVector] - cursorPos).sqrMagnitude)
|
||||
{
|
||||
for (int j = 0; j < quads[i].vertices.Length; j++)
|
||||
{
|
||||
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;
|
||||
closestVector = i;
|
||||
}
|
||||
}
|
||||
|
||||
planar.position = (quad[0] + quad[1] + quad[2] + quad[3]) / 4;
|
||||
cursorPos = vectors[closestVector];
|
||||
|
||||
switch (indexQuad)
|
||||
{
|
||||
|
@ -57,14 +55,14 @@ public class ToolNewQuad
|
|||
{
|
||||
for (int i = 0; i < quad.Length; i++)
|
||||
{
|
||||
quad[i] = cursorPos;
|
||||
quad[i] = closestVector;
|
||||
}
|
||||
|
||||
indexQuad++;
|
||||
}
|
||||
break;
|
||||
case (1):
|
||||
quad[indexQuad] = cursorPos;
|
||||
quad[indexQuad] = closestVector;
|
||||
|
||||
if (input.mainCon.trigger.down)
|
||||
{
|
||||
|
@ -72,7 +70,7 @@ public class ToolNewQuad
|
|||
}
|
||||
break;
|
||||
case (2):
|
||||
quad[indexQuad] = cursorPos;
|
||||
quad[indexQuad] = closestVector;
|
||||
|
||||
if (input.mainCon.trigger.down)
|
||||
{
|
||||
|
@ -80,56 +78,41 @@ public class ToolNewQuad
|
|||
}
|
||||
break;
|
||||
case (3):
|
||||
Vector3 v3 = Vector3.Cross(quad[0] - quad[1], quad[2] - quad[1]).normalized;
|
||||
planar.rotation = Quaternion.LookRotation(v3, quad[2] - quad[1]);
|
||||
cursorPos = planar.InverseTransformPoint(cursorPos);
|
||||
cursorPos.z = 0;
|
||||
cursorPos = planar.TransformPoint(cursorPos);
|
||||
|
||||
quad[indexQuad] = cursorPos;
|
||||
quad[indexQuad] = closestVector;
|
||||
|
||||
if (input.mainCon.trigger.down)
|
||||
{
|
||||
// w/triangle seam between the two closest points
|
||||
if (Vector3.Distance(quad[0], quad[2]) < Vector3.Distance(quad[1], quad[3]))
|
||||
{
|
||||
tris[0] = 0; tris[3] = 2;
|
||||
tris[1] = 1; tris[4] = 3;
|
||||
tris[2] = 2; tris[5] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
tris[0] = 0; tris[3] = 3;
|
||||
tris[1] = 1; tris[4] = 1;
|
||||
tris[2] = 3; tris[5] = 2;
|
||||
}
|
||||
// int furthest = 0;
|
||||
// for (int i = 1; i < quad.Length; i++)
|
||||
// {
|
||||
// if ((vectors[quad[i]] - planar.position).magnitude >
|
||||
// (vectors[quad[furthest]] - planar.position).magnitude)
|
||||
// {
|
||||
// furthest = i;
|
||||
// }
|
||||
// }
|
||||
|
||||
int furthest = 0;
|
||||
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(vectors[quad[furthest]]).magnitude;
|
||||
|
||||
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++)
|
||||
{
|
||||
uvs[i] = ((Vector2)planar.InverseTransformPoint(
|
||||
quad[i]) / (scale * 2)) + new Vector2(0.5f, 0.5f
|
||||
);
|
||||
pixelgon.quads.Add(quad[i]);
|
||||
}
|
||||
|
||||
mesh = new Mesh();
|
||||
mesh.SetVertices(quad);
|
||||
mesh.SetTriangles(tris, 0);
|
||||
mesh.SetUVs(0, uvs);
|
||||
|
||||
quads.Add(mesh);
|
||||
|
||||
indexQuad = 0;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -79,6 +79,8 @@ public class ToolNewVector
|
|||
vector.Add(cursorPos);
|
||||
}
|
||||
|
||||
vector[vector.Count - 1] = cursorPos;
|
||||
|
||||
if (input.mainCon.two.down)
|
||||
{
|
||||
if (vector.Count > 2)
|
||||
|
@ -90,8 +92,6 @@ public class ToolNewVector
|
|||
vector.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
vector[vector.Count - 1] = cursorPos;
|
||||
}
|
||||
|
||||
if (input.mainCon.trigger.up)
|
||||
|
|
Loading…
Add table
Reference in a new issue