Skip to content

Instantly share code, notes, and snippets.

@wkentaro
Created August 7, 2020 14:38
Show Gist options
  • Save wkentaro/0e1a9c4fb08e36daf99db64368eb60ef to your computer and use it in GitHub Desktop.
Save wkentaro/0e1a9c4fb08e36daf99db64368eb60ef to your computer and use it in GitHub Desktop.
import trimesh
import numpy as np
voxel_size = 0.01 # 1cm
encoding = np.random.randint(0, 2, size=(32, 32, 32), dtype=bool)
colors = np.random.random((32, 32, 32, 3))
transform = trimesh.transformations.scale_and_translate(
scale=voxel_size, translate=(0, 0, 0)
)
voxel_grid = trimesh.voxel.VoxelGrid(encoding=encoding, transform=transform)
geometry = voxel_grid.as_boxes(colors=colors)
# voxel_grid.show()
# geometry.show()
scene = trimesh.Scene()
scene.add_geometry(geometry)
scene.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment