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 badges1 Answer
Reset to default 0With 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
版权声明:本文标题:python - How to slice Trimesh including colors? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739336463a2158728.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论