BrunoLevy / GraphiteThree

Experimental 3D modeler
GNU General Public License v2.0
212 stars 18 forks source link

Preserve structure after remeshing #20

Open Nicolaus93 opened 2 days ago

Nicolaus93 commented 2 days ago

Hi again,

I have the following problem. I have different meshes that I want to read and then merge, remesh using graphite/geogram. The different meshes have been split from one original single mesh. Think for example of a cube, then I have 6 different faces. Is there a way to preserve the original (exterior) edges when remeshing? This is roughly what I've been trying:

def gompy_append(nb_points=100):
    scene_graph = gom.create(classname='OGF::SceneGraph', interpreter=gom)
    scene_graph.clear()

    faces = [scene_graph.load_object(f"/tmp/cube_face_{i}.obj") for i in range(6)]

    # merge only some faces of the cube
    for i in range(1, 4):
        f = faces[i]
        f.I.Surface.remesh_smooth(nb_points=nb_points, tri_shape_adapt=2.0, adjust=True)
        remesh = scene_graph.resolve('remesh')
        faces[0].I.Mesh.append(remesh)

    ps.init()
    ps.register_surface_mesh(
        "merge",
        np.asarray(faces[0].I.Editor.find_attribute('vertices.point')),
        np.asarray(faces[0].I.Editor.get_triangles()),
    )
    ps.show()

If you try to increase the number of points, the quality of the final result will improve. However, I would like to know if there's a way to reproduce the original structure after merging all the faces. If I skip the remesh step, then just merging the faces gives back the original single mesh.

image

BrunoLevy commented 2 days ago

Hello ! If the different parts of the mesh are planar, what you need is a constrained Delaunay triangulation, to make sure that the border of each part is preserved. It exists in geogram, CDT_2d, unfortunately, there is no Python/gompy binding yet for it (you'll need to deep-dive into the C++). You will need also a way of generating the additional points, for instance CVT. Another possibility is to use Jonathan Shewchuk's Triangle program. It does both constrained Delaunay triangulation and point insertion. To use it in a Python program, you will need to write the polygonal contour of your part into a file, spawn triangle, then read the result back (but it may be easier than diving into geogram C++ classes).

Nicolaus93 commented 2 days ago

Thank you for the detailed answer! Then I'm looking forward to the python bindings for geogram even more :smile: But I might try to give a shot to the original geogram in C++

Nicolaus93 commented 1 day ago

It seems there's a python wrapper also for Triangle https://rufat.be/triangle/ For constrained Delaunay triangulation, I believe an example is described here https://rufat.be/triangle/delaunay.html