/// <summary> /// This function is cool, just stick in a set of points, it'll add them to the /// array, and create a face. It will take account of duplicate vertices too! /// </summary> /// <param name="vertexData">A set of vertices to make into a face.</param> public virtual void SetFacesFromVertexData(Vertex[] vertexData) { // Create a face. Face newFace = new Face(); // Go through the vertices... foreach (Vertex v in vertexData) { // Do we have this vertex already? int at = VertexSearch.Search(vertices, 0, v, 0.00001f); // Add the vertex, and index it. if (at == -1) { newFace.Indices.Add(new Index(vertices.Count)); vertices.Add(v); } else { newFace.Indices.Add(new Index(at)); } } // Add the face. faces.Add(newFace); }
/// <summary> /// Call this function as soon as you change the polygons geometry, it will /// re-generate normals, etc. /// </summary> /// <param name="regenerateNormals">Regenerate Normals.</param> public virtual void Validate(bool regenerateNormals) { if (regenerateNormals) { normals.Clear(); } // Go through each face. foreach (Face face in faces) { if (regenerateNormals) { // Find a normal for the face. Vertex normal = face.GetSurfaceNormal(this); // Does this normal already exist? int index = VertexSearch.Search(normals, 0, normal, 0.001f); if (index == -1) { index = normals.Count; normals.Add(normal); } // Set the index normal. foreach (Index i in face.Indices) { i.Normal = index; } } } }