Skip to content

Instantly share code, notes, and snippets.

@wkentaro
Created November 21, 2018 00:42
Show Gist options
  • Save wkentaro/a2e92f6e52c418080c00ef8992c46e37 to your computer and use it in GitHub Desktop.
Save wkentaro/a2e92f6e52c418080c00ef8992c46e37 to your computer and use it in GitHub Desktop.
Example of creating scene by primitives on Trimesh
#!/usr/bin/env python
import numpy as np
import trimesh
scene = trimesh.Scene()
# plane
plane = trimesh.creation.box(extents=[1, 1, 0.01])
plane.visual.face_colors = [0.5, 0.5, 0.5, 0.5]
scene.add_geometry(plane)
scene.add_geometry(trimesh.creation.axis())
# object-1 (box)
box = trimesh.creation.box(extents=[0.3, 0.3, 0.3])
box.visual.face_colors = [0, 1., 0, 0.5]
axis = trimesh.creation.axis(origin_color=[1., 0, 0])
translation = [-0.2, 0, 0.15 + 0.01] # box offset + plane offset
box.apply_translation(translation)
axis.apply_translation(translation)
rotation = trimesh.transformations.rotation_matrix(
np.deg2rad(30), [0, 0, 1], point=box.centroid
)
box.apply_transform(rotation)
axis.apply_transform(rotation)
scene.add_geometry(box)
scene.add_geometry(axis)
# object-2 (cylinder)
cylinder = trimesh.creation.cylinder(radius=0.1, height=0.3)
cylinder.visual.face_colors = [0, 0, 1., 0.5]
axis = trimesh.creation.axis(origin_color=[1., 0, 0])
translation = [0.1, -0.2, 0.15 + 0.01] # cylinder offset + plane offset
cylinder.apply_translation(translation)
axis.apply_translation(translation)
scene.add_geometry(cylinder)
scene.add_geometry(axis)
scene.show()
@RezaRob
Copy link

RezaRob commented Mar 27, 2020

Thank you very much. This was really helpful and works in Colab:
https://colab.research.google.com/drive/11Cy36YHkQHga0_8g-hiFIgdlvZ2jsHCk

However (see the Colab) I'm trying to dynamically modify and refresh the scene. It's not really working. How do you do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment