Rotating Trimesh mesh plane object

4.5k Views Asked by At

I'm starting to work with trimesh objects and i haven't been able to find good info on how to apply transformations to mesh objects (specifically,rotations).

I have a simple planar mesh object:

plane = trimesh.creation.box(extents=[20, 20, 0.01])

How can i rotate it -for example- over an axis?

1

There are 1 best solutions below

0
On

Take a look at this module and especially at this function.

The rotation_matrix requires the direction, angle and center of rotation (optional) as arguments to return the rotation matrix. Then, you can rotate your mesh by using the apply_transform method which requires the rotation_matrix as argument.

Here is the code:

import math
from trimesh import creation, transformations

plane = creation.box(extents=[20, 20, 0.01])

angle = math.pi / 4
direction = [1, 0, 0]
center = [0, 0, 0]

rot_matrix = transformations.rotation_matrix(angle, direction, center)

plane.apply_transform(rot_matrix)