Note
Go to the end to download the full example code
Skeletal Animation in a glTF file#
In this tutorial, we will show how to use skeletal animations (skinning) in a glTF model in FURY.
import fury
Retrieving the model with skeletal animations. We’re choosing the RiggedFigure model here.
fury.data.fetch_gltf("RiggedFigure", "glTF")
filename = fury.data.read_viz_gltf("RiggedFigure")
/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 fetch_gltf function in future versions of FURY.
Here's how to call the Function fetch_gltf: fetch_gltf(name='value', mode='value')
exec(self.code, self.fake_main.__dict__)
Initializing the glTF object, You can additionally set apply_normals=True. Note: Normals might not work well as intended with skinning animations.
gltf_obj = fury.gltf.glTF(filename, apply_normals=False)
Get the skinning timeline using skin_timeline method, Choose the animation name you want to visualize. Note: If there’s no name for animation, It’s stored as anim_0, anim_1 etc
animation = gltf_obj.skin_animation()["anim_0"]
# After we get the timeline object, We want to initialise the skinning process.
# You can set `bones=true` to visualize each bone transformation. Additionally,
# you can set `length` of bones in the `initialise_skin` method.
# Note: Make sure to call this method before you initialize ShowManager, else
# bones won't be added to the scene.
gltf_obj.initialize_skin(animation, bones=False)
Create a scene, and show manager. Initialize the show manager and add timeline to the scene (No need to add actors to the scene separately).
scene = fury.window.Scene()
showm = fury.window.ShowManager(
scene, size=(900, 768), reset_camera=True, order_transparent=True
)
showm.initialize()
scene.add(animation)
/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__)
define a timer_callback. Use the update_skin method, It updates the timeline and applies skinning to actors (and bones).
def timer_callback(_obj, _event):
gltf_obj.update_skin(animation)
showm.render()
Optional: timeline.play() auto plays the animations.
showm.add_timer_callback(True, 20, timer_callback)
scene.reset_camera()
interactive = False
if interactive:
showm.start()
fury.window.record(scene, out_path="viz_skinning.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.583 seconds)