Question about MESH face Index behaviour when adding/deleting faces

just want to make sure my current assumptions are correct:

  • When I append a face to a existing mesh, the index of the new “appended” face is always the highest. i.e. it behaves like “Adding” element to an array in C# or appending an element to a list in python.

  • When I delete a face, the face indexes behave like poping an element in a python list. I.e. If in a four face mesh I delete face oldIndex[1], then oldIndex[2] becomes newIndex[1] and oldIndex[3] becomes oldIndex[2]

Could please anyone confirm if those asserts are right? So far my hypothesis is working fine but I would like to be 100% sure.

Should I expect the same behaviour from breps?

Still not sure to adopt meshes or breps as datastructures to obtain adjacency information in an algorithm I’m working on.

thanks

Those assumptions are correct

1 Like

thanks @stevebaer, so it’s the same for breps?

I believe so.

Hi @stevebaer,

if this applies to breps too, then i think there is a potential error in the rs.ExtractSurface method. If it removes faces by index one by one using this code:

if not copy:
    for index in face_indices: brep.Faces.RemoveAt(index)
    id = rhutil.coerceguid(object_id)
    scriptcontext.doc.Objects.Replace(id, brep)

then the passed face_indices should increment to -1 for each subsequent removal.

Somehow, i have exactly this problem while you answered this question. I’ve found cases where brep.Faces.RemoveAt(index) works as expected when used multiple times in a loop as above, but there are cases where it removes the wrong faces.

The only way to make it work properly (extracting faces by multiple indices) is to first extract, then create new brep(s) by joining all remaining faces into one or more breps.

I wish there would be a method in RhinoCommon to extract multiple faces at once.

EDIT: if the face_indices to extract using brep.Faces.RemoveAt(index) are sorted before with reverse=True, above error does not occur. It seems the rs method does this and i missed it…

_
c.

if the face_indices to extract using brep.Faces.RemoveAt(index) are sorted before with reverse=True

Every time you remove at an index, all the indices above that number get decremented by one. So to do this properly, as you found to be the case, you should remove at indices in descending order.

1 Like