import k3d
import numpy as np
from ipywidgets import interact, IntSlider
width = height = length = 3
color_map = (0xFF0000, 0x00FF00, 0x0000FF)
voxels = np.ones(width * height * length, dtype=np.uint8).reshape((length, height, width))
obj = k3d.voxels(voxels, color_map)
plot = k3d.plot(voxel_paint_color=2)
plot += obj
@interact(color=IntSlider(value=plot.voxel_paint_color, min=0, max=len(color_map)))
def color(color):
plot.voxel_paint_color = color
plot.display()
interactive(children=(IntSlider(value=2, description='color', max=3), Output()), _dom_classes=('widget-interac…
Output()
obj.voxels.flatten() # initial data
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=uint8)
Edit object (add/remove some voxels)
plot.mode = 'change'
obj.fetch_data('voxels') # this is an async operation
obj.voxels.flatten() # updated data
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=uint8)
obj.visible = False
obj.visible = True