198 lines
No EOL
5 KiB
C#
198 lines
No EOL
5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
public class Render
|
|
{
|
|
public PolyVector polyVector;
|
|
public Mesh meshOriel, meshAxis, meshCursor, meshJointSelect;
|
|
public Material matOriel, matCursor, matUnlit, matQuad, matVertexLit, matSelect;
|
|
|
|
List<int> selectedJoints = new List<int>();
|
|
Matrix4x4 orielM4 = new Matrix4x4();
|
|
Matrix4x4 axisM4 = new Matrix4x4();
|
|
public void Pixelgon(Pixelgon pixelgon)
|
|
{
|
|
orielM4.SetTRS(Vector3.zero, Quaternion.identity, new Vector3(0.6f, 0.4f, 0.4f));
|
|
Graphics.DrawMesh(meshOriel, orielM4, matOriel, 0);
|
|
|
|
axisM4.SetTRS(Vector3.zero, Quaternion.identity, Vector3.one * 0.2f);
|
|
Graphics.DrawMesh(meshAxis, axisM4, matUnlit, 0);
|
|
|
|
polyVector.AddVectors(pixelgon.vectors);
|
|
|
|
for (int i = 0; i < selectedJoints.Count; i++)
|
|
{
|
|
Graphics.DrawMesh(meshJointSelect,
|
|
pixelgon.vectors[selectedJoints[i]],
|
|
Quaternion.identity,
|
|
matSelect, 0
|
|
);
|
|
}
|
|
selectedJoints.Clear();
|
|
|
|
// Now for pixels!
|
|
// float pixelsPerMeter = 24;
|
|
// int texDiameter = Mathf.RoundToInt(
|
|
// planar.InverseTransformPoint(quad[furthest]).magnitude * 2 * pixelsPerMeter
|
|
// );
|
|
// if (texDiameter % 2 != 0) // Round up to Even
|
|
// {
|
|
// texDiameter++;
|
|
// }
|
|
|
|
// // TextureFormat.Alpha8 for revolutionary pallette painting
|
|
// Texture2D tex = new Texture2D(texDiameter, texDiameter);
|
|
// tex.filterMode = FilterMode.Point;
|
|
|
|
// int count = 0;
|
|
// for (int y = 0; y < texDiameter; y++) // Draw tiled placeholder texture
|
|
// {
|
|
// count++;
|
|
// for (int x = 0; x < texDiameter; x++)
|
|
// {
|
|
// if ((count++ % 2) == 0)
|
|
// {
|
|
// tex.SetPixel(x, y, new Color32(255, 255, 255, 255));
|
|
// }
|
|
// else
|
|
// {
|
|
// tex.SetPixel(x, y, new Color32(0, 0, 0, 255));
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// tex.Apply();
|
|
// quadMaterial.mainTexture = tex;
|
|
}
|
|
|
|
|
|
public Mesh meshToolNewVector;
|
|
public void ToolNewVector(ToolNewVector toolNewVector)
|
|
{
|
|
Graphics.DrawMesh(meshToolNewVector,
|
|
toolNewVector.cursorPos,
|
|
Quaternion.identity,
|
|
matVertexLit, 0
|
|
);
|
|
|
|
polyVector.AddVectors(toolNewVector.vector);
|
|
}
|
|
|
|
public Mesh meshToolEditVector, meshBoxSelect;
|
|
public void ToolEditVector(ToolEditVector toolEditVector)
|
|
{
|
|
Graphics.DrawMesh(meshToolEditVector,
|
|
toolEditVector.cursorPos,
|
|
Quaternion.identity,
|
|
matVertexLit, 0
|
|
);
|
|
|
|
|
|
if (toolEditVector.selecting)
|
|
{
|
|
Matrix4x4 boxMatrix = new Matrix4x4();
|
|
boxMatrix.SetTRS(
|
|
Vector3.Lerp(toolEditVector.fromCorner, toolEditVector.toCorner, 0.5f),
|
|
Quaternion.identity,
|
|
new Vector3(toolEditVector.toCorner.x - toolEditVector.fromCorner.x,
|
|
toolEditVector.toCorner.y - toolEditVector.fromCorner.y,
|
|
toolEditVector.toCorner.z - toolEditVector.fromCorner.z
|
|
)
|
|
); Graphics.DrawMesh(meshBoxSelect, boxMatrix, matSelect, 0);
|
|
}
|
|
|
|
selectedJoints.AddRange(toolEditVector.selected);
|
|
}
|
|
|
|
public Mesh meshToolEraser;
|
|
public void ToolEraser(ToolEraser toolEraser)
|
|
{
|
|
Graphics.DrawMesh(meshToolEraser,
|
|
toolEraser.cursorPos,
|
|
Quaternion.identity,
|
|
matVertexLit, 0
|
|
);
|
|
|
|
selectedJoints.AddRange(toolEraser.selected);
|
|
}
|
|
|
|
// public void ToolNewQuad(ToolNewQuad toolNewQuad)
|
|
// {
|
|
// int indexQuad = toolNewQuad.indexQuad;
|
|
// Vector3[] quad = toolNewQuad.quad;
|
|
|
|
// // Render cursor
|
|
// Graphics.DrawMesh(meshCursor,
|
|
// toolNewQuad.cursorPos, Quaternion.identity,
|
|
// matCursor, 0
|
|
// );
|
|
|
|
// Graphics.DrawMesh(toolNewQuad.mesh,
|
|
// Vector3.zero, Quaternion.identity,
|
|
// matQuad, 0
|
|
// );
|
|
|
|
// if (indexQuad > 0 && indexQuad < 4)
|
|
// {
|
|
// polyVector.Draw(quad);
|
|
|
|
// if (indexQuad > 1)
|
|
// {
|
|
// polyVector.Draw(new Vector3[2] { quad[0], toolNewQuad.cursorPos });
|
|
// }
|
|
|
|
// if (indexQuad == 3)
|
|
// {
|
|
// if (Vector3.Distance(quad[0], quad[2]) < Vector3.Distance(quad[1], quad[3]))
|
|
// {
|
|
// polyVector.Draw(new Vector3[2] { quad[0], quad[2] });
|
|
// }
|
|
// else
|
|
// {
|
|
// polyVector.Draw(new Vector3[2] { quad[1], quad[3] });
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
public void StretchSilo(StretchSilo stretchSilo, AssetSpace assetSpace)
|
|
{
|
|
Graphics.DrawMesh(assetSpace.assets["draft"].mesh,
|
|
stretchSilo.structure,
|
|
Quaternion.identity,
|
|
polyVector.matVector, 0
|
|
);
|
|
}
|
|
|
|
public void Frame(Input input)
|
|
{
|
|
Graphics.DrawMesh(meshCursor,
|
|
input.WorldPos(input.mainCon),
|
|
Quaternion.identity,
|
|
matCursor, 0
|
|
);
|
|
|
|
Graphics.DrawMesh(meshCursor,
|
|
input.WorldPos(input.offCon),
|
|
Quaternion.identity,
|
|
matCursor, 0
|
|
);
|
|
|
|
Graphics.DrawMesh(meshCursor,
|
|
input.twistCursor,
|
|
Quaternion.identity,
|
|
matCursor, 0
|
|
);
|
|
|
|
Graphics.DrawMesh(meshCursor,
|
|
input.stretchCursor,
|
|
Quaternion.identity,
|
|
matCursor, 0
|
|
);
|
|
|
|
polyVector.Frame();
|
|
}
|
|
} |