LiangliangNan / Easy3D

A lightweight, easy-to-use, and efficient C++ library for processing and rendering 3D data
GNU General Public License v3.0
1.37k stars 245 forks source link

Property transfer during surface mesh editing #137

Closed meiyy closed 2 years ago

meiyy commented 2 years ago

Seems that SurfaceMesh does not maintain the properties of face or edge, during mesh editing operations like face split. Is this intentionally designed or just not implemented? Thanks.

LiangliangNan commented 2 years ago

This is intended. Because SurfaceMesh does not know (in most cases) how a property should be maintained during editing. For example, when one splits a face by inserting a new vertex in the face, it is not clear how to assign the new vertex a color, or other properties. Of course, one can do linear interpolation, but this may not be desired by the user. So I believe this should be handled by the client code. If you have some good ideas, I'd be happy for discussion.

meiyy commented 2 years ago

What you said makes sense, though I still think, an option like bool copy_on_split on a specific face property is useful, and a default value =false can make old code unaffected. As for myself, I just want to maintain the segmentation property on faces, so simply copy the property from the source faces is enough. If you think this is not a good idea, just forget about it, it seems less complex to maintain the prop than I thought. But I suggest describing the relationship between new elements (like h0,t1,f0,f1,f2,f3) and the old ones in detail, maybe this will help the new users to implement the correct logic in client code.

LiangliangNan commented 2 years ago

Thanks for the thoughts. I actually tried something similar to your idea, but it wasn't easy to come up with an idea to handle properties for different element types (vertices, edges, faces), and all kinds of properties.

...the relationship between new elements (like h0,t1,f0,f1,f2,f3) and the old ones

Indeed, it is not clear what the new faces are. I will think about it and (may, if possible) add a few sentences to the function explanation. But for now, you can simply assign all faces (incident to the new vertex) the same property as the old face's.

I am closing this issue, please feel free to re-open it if you have any questions/suggestions.

LiangliangNan commented 2 years ago

Below is part of the split function. The new faces can be generated by adding the 3 lines marked "new line". But still, this has overhead for operations (like subdivisions) where properties are not considered. So I decide to leave the code as is without introducing an extra argument and return value, to keep the API the simplest.

        ...
        std::vector<Face> new_faces;    // new line
        while (h != hend)
        {
            Halfedge hnext = next(h);

            Face fnew = new_face();
            new_faces.push_back(fnew);   // new line
            ...

         }

         ...
         return new_faces;               // new line