Simple example of rigid asset.
We will create a sphere progammatically and render it several times.
ipyanimlab is working in cm.
ipyanimlab uses only np.float32 type to send data
ipyanimlab is column major for its matrices
[1]:
import numpy as np
from ipywidgets import widgets, interact, interactive
import ipyanimlab as lab
viewer = lab.Viewer(shadow_quality=lab.ShadowQuality.HIGH, move_speed=5, width=800, height=600)
Create a single sphere asset
[2]:
sphere = viewer.create_sphere(radius=10)
Display the asset at the default position
[3]:
# start the rendering of the shadow
viewer.begin_shadow()
# render the sphere at default position in the shadow
viewer.draw(sphere)
# end the shadow
viewer.end_shadow()
# start the rendering of the scene
viewer.begin_display()
# render the default ground
viewer.draw_ground()
# render the sphere at default position
viewer.draw(sphere)
# display the image
viewer.end_display()
# send all the command to webgl
viewer.execute_commands()
# show the viewer
viewer
[3]:
Render multiple assets.
By providing multiple matrices to the draw command we can do a batch rendering of the asset.
[5]:
xforms = np.eye(4, dtype=np.float32)[np.newaxis, ...].repeat(3, axis=0)
xforms[0, :3, 3] = [100, 50, 0]
xforms[1, :3, 3] = [0, 50, 0]
xforms[2, :3, 3] = [-100, 50, 0]
viewer.begin_shadow()
# drawing by providing the matrices for transforms
viewer.draw(sphere, xforms)
viewer.end_shadow()
viewer.begin_display()
viewer.draw_ground()
# drawing by providing the matrices for transforms
viewer.draw(sphere, xforms)
viewer.end_display()
viewer.execute_commands()
viewer
[5]: