jupyter-widgets / pythreejs

A Jupyter - Three.js bridge
https://pythreejs.readthedocs.io
Other
943 stars 188 forks source link

Animation without play/pause control #370

Closed atmalik123 closed 2 years ago

atmalik123 commented 2 years ago

The animation examples on the pythreejs docs have play/pause controls.

image

Is there a way to hide these controls and just have the animation play when the cell is run?

Here is the corresponding code from the docs:

from pythreejs import *
import ipywidgets
from IPython.display import display

view_width = 600
view_height = 400

sphere = Mesh(
    SphereBufferGeometry(1, 32, 16),
    MeshBasicMaterial(color='red')
)

cube = Mesh(
    BoxBufferGeometry(1, 1, 1),
    MeshBasicMaterial(color='green'),
    position=[2, 0, 4]
)

camera = PerspectiveCamera( position=[10, 6, 10], aspect=view_width/view_height)

position_track = VectorKeyframeTrack(name='.position',
    times=[0, 2, 5],
    values=[10, 6, 10,
            6.3, 3.78, 6.3,
            -2.98, 0.84, 9.2,
           ])

rotation_track = QuaternionKeyframeTrack(name='.quaternion',
    times=[0, 2, 5],
    values=[-0.184, 0.375, 0.0762, 0.905,
            -0.184, 0.375, 0.0762, 0.905,
            -0.0430, -0.156, -0.00681, 0.987,
           ])

camera_clip = AnimationClip(tracks=[position_track, rotation_track])
camera_action = AnimationAction(AnimationMixer(camera), camera_clip, camera)

scene = Scene(children=[sphere, cube, camera])
controller = OrbitControls(controlling=camera)
renderer = Renderer(camera=camera, scene=scene, controls=[controller],
                    width=view_width, height=view_height)

renderer
vidartf commented 2 years ago

You should be able to call the .play() function on the AnimationAction.

vidartf commented 2 years ago

Closing as answered.