Note
Go to the end to download the full example code
Keyframes Spline Interpolator#
Tutorial on making keyframe-based animation in FURY using Spline interpolators.
import numpy as np
import fury
scene = fury.window.Scene()
showm = fury.window.ShowManager(
scene, size=(900, 768), reset_camera=False, order_transparent=True
)
/opt/homebrew/Caskroom/miniforge/base/envs/py39/lib/python3.9/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the __init__ function in future versions of FURY.
Here's how to call the Function __init__: __init__(self_value, scene='value', title='value', size='value', png_magnify='value', reset_camera='value', order_transparent='value', interactor_style='value', stereo='value', multi_samples='value', max_peels='value', occlusion_ratio='value')
exec(self.code, self.fake_main.__dict__)
Position keyframes as a dict object containing timestamps as keys and positions as values.
creating FURY dots to visualize the position values.
pos_dots = fury.actor.dot(np.array(list(position_keyframes.values())))
creating two timelines (one uses linear and the other uses’ spline interpolator), each timeline controls a sphere actor
sphere_linear = fury.actor.sphere(np.array([[0, 0, 0]]), (1, 0.5, 0.2), 0.5)
linear_anim = fury.animation.Animation()
linear_anim.add_actor(sphere_linear)
linear_anim.set_position_keyframes(position_keyframes)
/opt/homebrew/Caskroom/miniforge/base/envs/py39/lib/python3.9/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the sphere function in future versions of FURY.
Here's how to call the Function sphere: sphere(centers_value, colors_value, radii='value', phi='value', theta='value', vertices='value', faces='value', opacity='value', use_primitive='value')
exec(self.code, self.fake_main.__dict__)
Note: linear_interpolator is used by default. So, no need to set it for this first animation that we need to linearly interpolate positional animation.
creating a second timeline that translates another larger sphere actor using spline interpolator.
sphere_spline = fury.actor.sphere(np.array([[0, 0, 0]]), (0.3, 0.9, 0.6), 1)
spline_anim = fury.animation.Animation(sphere_spline)
spline_anim.set_position_keyframes(position_keyframes)
/opt/homebrew/Caskroom/miniforge/base/envs/py39/lib/python3.9/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the __init__ function in future versions of FURY.
Here's how to call the Function __init__: __init__(self_value, actors='value', length='value', loop='value', motion_path_res='value')
exec(self.code, self.fake_main.__dict__)
Setting 5th degree spline interpolator for position keyframes.
spline_anim.set_position_interpolator(fury.animation.spline_interpolator, degree=5)
Wrapping animations up!#
Adding everything to a Timeline
to control the two timelines.
First we create a timeline with a playback panel:
timeline = fury.animation.Timeline(playback_panel=True)
Add visualization dots actor to the scene.
scene.add(pos_dots)
Adding the animations to the timeline (so that it controls their playback).
timeline.add_animation([linear_anim, spline_anim])
Adding the timeline to the show manager.
showm.add_animation(timeline)
Now that these two animations are added to timeline, if the timeline is played, paused, …, all these changes will reflect on the animations.
interactive = False
if interactive:
showm.start()
fury.window.record(scene, out_path="viz_keyframe_animation_spline.png", size=(900, 768))
/opt/homebrew/Caskroom/miniforge/base/envs/py39/lib/python3.9/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the record function in future versions of FURY.
Here's how to call the Function record: record(scene='value', cam_pos='value', cam_focal='value', cam_view='value', out_path='value', path_numbering='value', n_frames='value', az_ang='value', magnification='value', size='value', reset_camera='value', screen_clip='value', stereo='value', verbose='value')
exec(self.code, self.fake_main.__dict__)
Total running time of the script: (0 minutes 0.107 seconds)