meshmash / Plankton

A C# half-edge mesh data structure, and components for using this in Grasshopper/Rhino
http://meshmash.github.io/Plankton
GNU Lesser General Public License v3.0
216 stars 66 forks source link

Adding a face to existing mesh #29

Closed danhambleton closed 8 years ago

danhambleton commented 9 years ago

I've been getting -1 everytime when I do this (just to test):

            //get old face info
            var faceCirculator = pMesh.Halfedges.GetFaceCirculator(pMesh.Faces[id].FirstHalfedge);
            var faceVerts = new List<int>();
            foreach (var idx in faceCirculator)
            {
                faceVerts.Add(pMesh.Halfedges[idx].StartVertex);
            }

            //delete old face
            pMesh.Faces.RemoveFace(id);
            //pMesh.Compact();
            var res = pMesh.Faces.AddFace(faceVerts);

The error is thrown in here in the AddFace method:

            // Check vertices
            foreach (int i in array)
            {
                // Check that all vertex indices exist in this mesh
                if (i < 0 || i >= vs.Count)
                    throw new IndexOutOfRangeException("No vertex exists at this index.");
                // Check that all vertices are on a boundary
                int outgoing = vs[i].OutgoingHalfedge;
                if (outgoing != -1 && hs[outgoing].AdjacentFace != -1)
                    return -1;
            }

Am I using the methods incorrectly? Shouldn't removing a face create a boundary region (i.e. update the half edges)?

KurtLoeffler commented 8 years ago

I noticed this too. I think its because this check is looking at only a single half edge used by a given vertex, instead of checking ALL half edges used by that vertex.