public void RemoveAdjacentTriangle(WedgeTriangle triangle) { if (HasAdjacentTriangle(triangle)) { m_adjacentTriangles.Remove(triangle); } }
/** * Recompute the list of adjacent triangles using the list of child vertices **/ //public void InvalidateAdjacentTriangles() //{ // m_adjacentTriangles.Clear(); // for (int i = 0; i != m_vertices.Count; i++) // { // for (int j = 0; j != m_vertices[i].AdjacentTriangles.Count; j++) // { // if (!HasAdjacentTriangle(m_vertices[i].AdjacentTriangles[j])) // m_adjacentTriangles.Add(m_vertices[i].AdjacentTriangles[j]); // } // } //} public void AddAdjacentTriangle(WedgeTriangle triangle) { if (!HasAdjacentTriangle(triangle)) { m_adjacentTriangles.Add(triangle); } }
/** * Build neighbourly relations between vertices and wedges using the triangles of the model **/ private void BuildNeighbourlyRelations(List <Wedge> wedges, Vertex[] vertices, List <int> tris) { for (int i = 0; i != tris.Count; i += 3) { Vertex v0 = vertices[tris[i]]; Vertex v1 = vertices[tris[i + 1]]; Vertex v2 = vertices[tris[i + 2]]; Triangle triangle = new Triangle(v0, v1, v2); //m_triangles.Add(triangle); //Set this triangle as an adjacent triangle for every vertex //v0.AddAdjacentTriangle(triangle); //v1.AddAdjacentTriangle(triangle); //v2.AddAdjacentTriangle(triangle); //for each triangle vertex, set the 2 opposite points as neighbors //v0.AddNeighbor(v1); //v0.AddNeighbor(v2); //v1.AddNeighbor(v0); //v1.AddNeighbor(v2); //v2.AddNeighbor(v0); //v2.AddNeighbor(v1); Wedge w0 = GetWedgeHoldingVertex(wedges, v0); Wedge w1 = GetWedgeHoldingVertex(wedges, v1); Wedge w2 = GetWedgeHoldingVertex(wedges, v2); w0.AddNeighbor(w1); w0.AddNeighbor(w2); w1.AddNeighbor(w0); w1.AddNeighbor(w2); w2.AddNeighbor(w0); w2.AddNeighbor(w1); WedgeTriangle wedgeTriangle = new WedgeTriangle(w0, w1, w2); wedgeTriangle.m_mappedVertexTriangle = triangle; //map here the vertex triangle to the wedge triangle if (wedges == m_initialWedges) //populate the m_originalTriangles using the m_initialWedges list only { m_originalTriangles.Add(wedgeTriangle); } w0.AddAdjacentTriangle(wedgeTriangle); w1.AddAdjacentTriangle(wedgeTriangle); w2.AddAdjacentTriangle(wedgeTriangle); } }
public bool HasAdjacentTriangle(WedgeTriangle triangle) { return(m_adjacentTriangles.Contains(triangle)); }
/** * Return a list of vertices and indices where player has specified a maximum count of vertices for the initial model **/ public void CutMeshPolygons(out Vector3[] cutVertices, out int[] cutTriangles, int maxWedges) { //no work to do here if (maxWedges >= m_initialWedges.Count) { cutVertices = m_data.Verts.ToArray(); cutTriangles = m_data.Tris.ToArray(); return; } Vertex[] vertices = new Vertex[m_data.Verts.Count]; //build the triangle list List <int> triangles = new List <int>(); List <int> dismissedVerticesIDs = new List <int>(); for (int i = 0; i != m_originalTriangles.Count; i++) { WedgeTriangle triangle = m_originalTriangles[i]; int p0 = triangle.Wedges[0].ID; int p1 = triangle.Wedges[1].ID; int p2 = triangle.Wedges[2].ID; //int p0 = m_data.Tris[i]; //int p1 = m_data.Tris[i + 1]; //int p2 = m_data.Tris[i + 2]; int collapsedP0 = Map(p0, maxWedges); int collapsedP1 = Map(p1, maxWedges); int collapsedP2 = Map(p2, maxWedges); if (collapsedP0 == -1) { collapsedP0 = p0; } if (collapsedP1 == -1) { collapsedP1 = p1; } if (collapsedP2 == -1) { collapsedP2 = p2; } //one-dimensional (flat) triangle, dismiss it if (collapsedP0 == collapsedP1 || collapsedP1 == collapsedP2 || collapsedP2 == collapsedP0) { continue; } Triangle vertexTriangle = triangle.m_mappedVertexTriangle; Vertex v0 = vertexTriangle.Vertices[0]; Vertex v1 = vertexTriangle.Vertices[1]; Vertex v2 = vertexTriangle.Vertices[2]; if (vertices[v0.ID] == null) { //v0.m_position = WedgeForID(m_initialWedges, collapsedP0).m_position; v0.m_position = m_initialWedges[collapsedP0].m_position; vertices[v0.ID] = v0; } if (vertices[v1.ID] == null) { //v1.m_position = WedgeForID(m_initialWedges, collapsedP1).m_position; v1.m_position = m_initialWedges[collapsedP1].m_position; vertices[v1.ID] = v1; } if (vertices[v2.ID] == null) { //v2.m_position = WedgeForID(m_initialWedges, collapsedP2).m_position; v2.m_position = m_initialWedges[collapsedP2].m_position; vertices[v2.ID] = v2; } triangles.Add(v0.ID); triangles.Add(v1.ID); triangles.Add(v2.ID); } //traverse vertices array and find holes in it and extract positions int numVertices = 0; for (int i = 0; i != vertices.Length; i++) { if (vertices[i] == null) { dismissedVerticesIDs.Add(i); } else { numVertices++; } } cutVertices = new Vector3[numVertices]; for (int i = 0; i != vertices.Length; i++) { if (vertices[i] != null) { int shiftedID = GetShiftedID(dismissedVerticesIDs, i); cutVertices[shiftedID] = vertices[i].m_position; } } //do the same thing for triangles for (int i = 0; i != triangles.Count; i++) { triangles[i] = GetShiftedID(dismissedVerticesIDs, triangles[i]); } cutTriangles = triangles.ToArray(); }