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(MUVTriangle checkTriangle) { int sharedConnections = 0; foreach (MUVVertex vertex in vertices) { if (checkTriangle.vertices.Contains(vertex)) sharedConnections += 1; } return sharedConnections; }