admin管理员组

文章数量:1221774

I have the following code which generally works for my trimesh.

    box = trimesh.creation.box(bounds=[[min_x, min_y, 0], [max_x, max_y, max_z]])
    cut_mesh = trimesh.intersections.slice_mesh_plane(mesh, -box.facets_normal, box.facets_origin)

My problem is that the color of my mesh is not copied with this code as seen in this github issue: .

Is there another easy way to do the slicing including the colors?

I have the following code which generally works for my trimesh.

    box = trimesh.creation.box(bounds=[[min_x, min_y, 0], [max_x, max_y, max_z]])
    cut_mesh = trimesh.intersections.slice_mesh_plane(mesh, -box.facets_normal, box.facets_origin)

My problem is that the color of my mesh is not copied with this code as seen in this github issue: https://github.com/mikedh/trimesh/issues/1125.

Is there another easy way to do the slicing including the colors?

Share Improve this question asked Feb 7 at 9:46 SGKleeSGKlee 821 silver badge9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

With the nearest neighbor method from scipy one can find the nearest vertex and then assign the color or other things to the sliced mesh.

from scipy.spatial import cKDTree

if hasattr(mesh.visual, 'vertex_colors') and mesh.visual.vertex_colors is not None:
        tree = cKDTree(mesh.vertices)
        _, indices = tree.query(cut_mesh.vertices)
        cut_mesh.visual.vertex_colors = mesh.visual.vertex_colors[indices]

本文标签: pythonHow to slice Trimesh including colorsStack Overflow