private static Vector3[] MakeFaceNormals(CullingFaces face, int x, int y, int z) { var q = GetRotation(face); var r = new[] { q *new Vector3(-.5f, .5f, -.5f).normalized, q *new Vector3(.5f, .5f, -.5f).normalized, q *new Vector3(-.5f, -.5f, -.5f).normalized, q *new Vector3(.5f, -.5f, -.5f).normalized, // q*Vector3.back, // q*Vector3.back, // q*Vector3.back, // q*Vector3.back }; return(r); }
public override Vector2[] BuildUV(ref int count, ref CullingFaces c, ref Voxel v, int x, int y, int z) { var l = 4 * (6 - ((byte)c).PopCount()); count += l; var r = new Vector2[l]; for (int i = r.Length - 4; i >= 0; i -= 4) { r [i + 0] = new Vector2(0, 1); r [i + 1] = new Vector2(1, 1); r [i + 2] = new Vector2(0, 0); r [i + 3] = new Vector2(1, 0); } return(r); }
private static Quaternion GetRotation(CullingFaces face) { switch (face) { case CullingFaces.West: return(Quaternion.Euler(0, 90, 0)); case CullingFaces.North: return(Quaternion.Euler(0, 180, 0)); case CullingFaces.East: return(Quaternion.Euler(0, 270, 0)); case CullingFaces.Up: return(Quaternion.Euler(90, 0, 0)); case CullingFaces.Down: return(Quaternion.Euler(-90, 0, 0)); } return(Quaternion.identity); }
private static int[] MakeTriangles(CullingFaces face, ref int start) { var count = 6 * (6 - ((byte)face).PopCount()); var triangles = new int[count]; var index = 0; foreach (var f in Enum.GetValues(typeof(CullingFaces))) { if (((byte)(CullingFaces)f).PopCount() != 1) { continue; } if (!face.HasFlag((CullingFaces)f)) { Array.Copy(MakeFaceTriangles((CullingFaces)f, start), 0, triangles, index, 6); index += 6; start += 4; } } return(triangles); }
public override int[] BuildTrianlges(ref int count, ref CullingFaces c, ref Voxel v, ref int triangleIndex, int x, int y, int z) { var l = 6 * (6 - ((byte)c).PopCount()); count += l; var triangles = new int[l]; var index = 0; for (byte f = 1 << 0; f <= (byte)CullingFaces.Down; f = (byte)(f << 1)) { if (((byte)f).PopCount() != 1) { continue; } if (!c.HasFlag(f)) { Array.Copy(MakeFaceTriangles((CullingFaces)f, triangleIndex), 0, triangles, index, 6); index += 6; triangleIndex += 4; } } return(triangles); }
public virtual Vector2[] BuildUV2(ref int count, ref CullingFaces c, ref Voxel v, int x, int y, int z) { throw new NotImplementedException(); }
public virtual Color[] BuildColors( ref int count, ref CullingFaces c, ref Voxel v, int x, int y, int z) { throw new NotImplementedException(); }
public abstract int[] BuildTrianlges( ref int count, ref CullingFaces c, ref Voxel v, ref int triangleIndex, int x, int y, int z);
public abstract Vector3[] BuildVertices( ref int count, ref CullingFaces c, ref Voxel v, int x, int y, int z);
private static int[] MakeFaceTriangles(CullingFaces face, int i) { return(new[] { i + 0, i + 1, i + 2, i + 3, i + 2, i + 1 }); }