.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_introductory/viz_skinning.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end <sphx_glr_download_auto_examples_01_introductory_viz_skinning.py>` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_01_introductory_viz_skinning.py: ================================= Skeletal Animation in a glTF file ================================= In this tutorial, we will show how to use skeletal animations (skinning) in a glTF model in FURY. .. GENERATED FROM PYTHON SOURCE LINES 8-11 .. code-block:: Python import fury .. GENERATED FROM PYTHON SOURCE LINES 12-14 Retrieving the model with skeletal animations. We're choosing the `RiggedFigure` model here. .. GENERATED FROM PYTHON SOURCE LINES 14-18 .. code-block:: Python fury.data.fetch_gltf(name="RiggedFigure", mode="glTF") filename = fury.data.read_viz_gltf("RiggedFigure") .. GENERATED FROM PYTHON SOURCE LINES 19-21 Initializing the glTF object, You can additionally set `apply_normals=True`. Note: Normals might not work well as intended with skinning animations. .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python gltf_obj = fury.gltf.glTF(filename, apply_normals=False) .. GENERATED FROM PYTHON SOURCE LINES 25-28 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 .. GENERATED FROM PYTHON SOURCE LINES 28-39 .. code-block:: Python 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) .. GENERATED FROM PYTHON SOURCE LINES 40-43 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). .. GENERATED FROM PYTHON SOURCE LINES 43-51 .. code-block:: Python scene = fury.window.Scene() showm = fury.window.ShowManager( scene=scene, size=(900, 768), reset_camera=True, order_transparent=True ) showm.initialize() scene.add(animation) .. GENERATED FROM PYTHON SOURCE LINES 52-55 define a timer_callback. Use the `update_skin` method, It updates the timeline and applies skinning to actors (and bones). .. GENERATED FROM PYTHON SOURCE LINES 55-62 .. code-block:: Python def timer_callback(_obj, _event): gltf_obj.update_skin(animation) showm.render() .. GENERATED FROM PYTHON SOURCE LINES 63-64 Optional: `timeline.play()` auto plays the animations. .. GENERATED FROM PYTHON SOURCE LINES 64-75 .. code-block:: Python showm.add_timer_callback(True, 20, timer_callback) scene.reset_camera() interactive = False if interactive: showm.start() fury.window.record(scene=scene, out_path="viz_skinning.png", size=(900, 768)) .. image-sg:: /auto_examples/01_introductory/images/sphx_glr_viz_skinning_001.png :alt: viz skinning :srcset: /auto_examples/01_introductory/images/sphx_glr_viz_skinning_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.054 seconds) .. _sphx_glr_download_auto_examples_01_introductory_viz_skinning.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_skinning.ipynb <viz_skinning.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_skinning.py <viz_skinning.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_