Splitting separate components of Mesh Arrangements result #20
-
|
Hi, I've been investigating your library with the Python bindings and the performance is very impressive! I have a quick question about the easiest way to determine the separate components after generating a Mesh Arrangement from two open (non-watertight) meshes? In my case I have two meshes that cross each other and I want to split the first mesh into the separate components that are on either side of the other mesh. I can see from the result returned from Using Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
@graphic-goose faces_a, points_a = tf.make_plane_mesh(2.0, 2.0)
# Second plane: rotate 90 deg around X so it lies in the XZ plane (y = 0).
R = np.array([
[1, 0, 0],
[0, 0, -1],
[0, 1, 0],
], dtype=points_a.dtype)
points_b = points_a @ R.T
faces_b = faces_a.copy()
mesh_a = tf.Mesh(faces_a, points_a)
mesh_b = tf.Mesh(faces_b, points_b)
# Compute the arrangement of the two meshes.
(faces, points), tag_labels, face_labels = tf.mesh_arrangements(
[mesh_a, mesh_b])
arr = tf.Mesh(faces, points)
n_components, comp_labels = tf.label_connected_components(
arr.manifold_edge_link)
print(f"manifold-edge connected components: {n_components}")
assert n_components == 4, f"expected 4 components, got {n_components}"
# Split into one sub-mesh per component.
components, ids = tf.split_into_components(arr, comp_labels)
mesh_0_component_ids = np.unique(comp_labels[tag_labels == 0])
mesh_1_component_ids = np.unique(comp_labels[tag_labels == 1])
for cid, (cf, cp) in zip(ids, components):
src = int(tag_labels[comp_labels == cid][0]) # which input mesh
centroid = cp.mean(axis=0)
print(
f" component {cid}: source={src}, faces={len(cf)}, "
f"centroid=({centroid[0]:+.3f}, {centroid[1]:+.3f}, {centroid[2]:+.3f})"
)
Is this what you had in mind?
In Lunar: arrangement-components.mp4 |
Beta Was this translation helpful? Give feedback.

@graphic-goose In c++ it would be trivial. Python does not yet expose all the low-level API. So there is no recommended way yet. But we can do it. Here is the plan:
Get non manifold edges of the arrangement (we have this in python) and the incident faces on those edges (missing from python, but we can use numpy). We know from
tag_labelswhich original mesh which face is from, and we know which component it belongs to. On each edge, take the 2 faces fromtag0and the original face the the 2 faces fromtag1belonged to. Classify both faces fromtag0against its plane.For increased robustness, we do this on every edge, and produce a distribution (bincounts) of votes for each component (in c…