Reputation: 4327
I'm trying to add text labels to objects in a Trimesh scene
The following example does not work. My intent is to have text labels "box1", "box2" and "box3" to appear next to each created box. However, they don't show.
import numpy as np
import trimesh
names = ["box1", "box2", "box3"]
angles = [np.pi/2, -np.pi/2, np.pi/4]
sizes = [0.1, 0.2, 0.3]
transforms = [[0., 0., 2.], [1.0, 0.0, 0.0], [0.0, 3.0, 0.0]]
meshes = []
for n, angle, size, t in zip(names, angles, sizes, transforms):
transform = np.array([[np.cos(angle), 0, -np.sin(angle), t[0]],
[0, 1, 0, t[1]],
[np.sin(angle), 0, np.cos(angle), t[2]],
[0, 0, 0, 1]])
trm1 = trimesh.creation.box([size, size, size], transform, metadata={"name": n})
trm2 = trimesh.path.creation.box_outline(extents=[size, size, size], transform=transform, metadata={"name": n})
txt = trimesh.path.entities.Text(len(trm2.vertices), n, color='black')
meshes.extend([trm1, trm2])
meshes.append(txt)
scene = trimesh.scene.Scene(meshes)
scene.show()
Upvotes: 2
Views: 464