Slice mesh with trimesh

2.1k views Asked by At

I work on a big .stl file which I want to cut into pieces using a bounding box. For this purpose, I use trimesh python package to load the .stl.

Here is the piece of code used to generate the bounding box :

box = trimesh.creation.box(extents=[1.5, 1.5, 1.5])
    print(box.facets_origin)
    print(box.facets_normal)

So I get as a return :

print(box.facets_origin)
[[-0.75 -0.75  0.75]
 [ 0.75 -0.75 -0.75]
 [-0.75  0.75 -0.75]
 [-0.75 -0.75  0.75]
 [-0.75  0.75  0.75]
 [ 0.75  0.75 -0.75]]

print(box.facets_normal)
 [[-1.  0.  0.]
 [ 0. -1.  0.]
 [ 0.  0. -1.]
 [ 0.  0.  1.]
 [ 0.  1.  0.]
 [ 1.  0.  0.]]

This means that the box's center of gravity is at (0, 0, 0)

And then I plan to cut the big stl using slice_plane function. However, I would like to change the location of the bounding box's center of mass, or facets' location.

How this could be done using trimesh ? Or another Python package ?

Thanks in advance for your help !

Joachim

1

There are 1 answers

1
Amiga500 On

Can you not translate the box using

mesh.apply_transform(trimesh.transformations.scale_and_translate())

https://github.com/mikedh/trimesh/blob/master/trimesh/transformations.py