public static void RasterizeTriangle( MTriangle triangle, Texture2D texture) { MUVVertex v1 = triangle.Vertices[0].Uv; MUVVertex v2 = triangle.Vertices[1].Uv; MUVVertex v3 = triangle.Vertices[2].Uv; fillBottomFlatTriangle(v1,v2,v3, texture); fillTopFlatTriangle(v1,v2,v3, texture); texture.Apply(); }
public static void DebugTriangle(MTriangle triangle, Texture2D texture) { List<Point2D> points = new List<Point2D>(); foreach(MVertex vertex in triangle.Vertices) { points.Add (vertex.Uv.ToPoint2D()); } int textureSize = texture.width; DrawLine(points[0] * textureSize,points[1]* textureSize,texture); DrawLine(points[1] * textureSize,points[2]* textureSize,texture); DrawLine(points[2] * textureSize,points[0]* textureSize,texture); }
public MMesh(Mesh mesh) { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); this.mesh = mesh; triangles = new List<MTriangle>(); uvTriangles = new List<MUVTriangle>(); vertices = new List<MVertex>(); uvVertices = new List<MUVVertex>(); uvEdges = new List<MUVEdge>(); bounds = new Bounds(Vector3.zero, Vector3.zero); // Temp for filling List<MVertex> vertexList = new List<MVertex>(); List<MUVVertex> UVVertexList = new List<MUVVertex>(); // Reference data int[] meshTriangles = mesh.triangles; Vector3[] meshVertices = mesh.vertices; Vector3[] meshNormals = mesh.normals; Vector2[] meshUV = mesh.uv; for (int triangle = 0; triangle < meshTriangles.Length; triangle += 3) { vertexList.Clear(); UVVertexList.Clear(); vertexList.Add(new MVertex(meshVertices[meshTriangles[triangle ]], meshNormals[meshTriangles[triangle ]], meshUV[meshTriangles[triangle ]])); vertexList.Add(new MVertex(meshVertices[meshTriangles[triangle + 1]], meshNormals[meshTriangles[triangle + 1]], meshUV[meshTriangles[triangle + 1]])); vertexList.Add(new MVertex(meshVertices[meshTriangles[triangle + 2]], meshNormals[meshTriangles[triangle + 2]], meshUV[meshTriangles[triangle + 2]])); UVVertexList.Add(new MUVVertex( meshUV[meshTriangles[triangle ]] )); UVVertexList.Add(new MUVVertex( meshUV[meshTriangles[triangle + 1]] )); UVVertexList.Add(new MUVVertex( meshUV[meshTriangles[triangle + 2]] )); MTriangle newTriangle = new MTriangle(this, vertexList); MUVTriangle newUVTriangle = new MUVTriangle(this, UVVertexList); } stopwatch.Stop(); UnityEngine.Debug.Log("Time taken: " + (stopwatch.Elapsed)); stopwatch.Reset(); }
private int SharedConnections(MTriangle checkTriangle) { int sharedConnections = 0; foreach(MVertex vertex in vertices) { if (checkTriangle.vertices.Contains(vertex)) sharedConnections += 1; } return sharedConnections; }