mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
3.02k stars 583 forks source link

Edges overlapping issue #2292

Open m-fabregue opened 2 months ago

m-fabregue commented 2 months ago

Hello !

I am currently playing with trimesh in the context of a CAD project. I started to implement an algorithm able to chamfer mesh vertices given a list of vertex indices.

In order to construct a chamfer for a vertex, I need to know outgoing edges (excluding edges shared by two co-planar faces) from this vertex and then compute a new vertex in the direction of the edge at a specific distance (the chamfer size)

Now I am facing an issue I didn't anticipated. Some edges are overlaping and I dont know how to get rid of that. Meshes are generated by applying boolean operations on some basic shapes, using "manifold" engine.

The following code & image highlight the issue on the vertex 7 and the edges [[3, 11], [7 12]]. I would expect, instead, [[3, 7], [7 11], [11, 12]]. Cubes are currently not considered adjacent by some edges. Is there an option for the manifold engine or another trimesh function that is able to solve this ?

Regards

image

import trimesh
import vedo

make_cuboid = lambda extents: trimesh.creation.box(extents=extents)

# create two cubes that overlap on the border
bottom_cube = make_cuboid([20, 10, 10])
top_cube = make_cuboid([10, 10, 10])
top_cube.apply_translation([10, 10, 10])

# merge cubes together to create a single mesh
merged = trimesh.boolean.union([bottom_cube, top_cube])

# display mesh skeleton & vertex indices
vedo_mesh = vedo.Mesh([merged.vertices, merged.faces])
points = vedo_mesh.vertices
labels = [vedo.Text3D(str(i), pos=points[i], s=1, c="red") for i in range(len(points))]
vedo.show(vedo_mesh.wireframe(), *labels, axes=1)