.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/01_introductory/viz_morphing.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_morphing.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_01_introductory_viz_morphing.py:


============================
Morphing Animation in a glTF
============================
In this tutorial, we will show how to use morphing in a glTF model in FURY.

.. GENERATED FROM PYTHON SOURCE LINES 7-10

.. code-block:: Python


    import fury








.. GENERATED FROM PYTHON SOURCE LINES 11-13

Retrieving the model with morphing in it (look at Khronoos samples).
We're choosing the `MorphStressTest` model here.

.. GENERATED FROM PYTHON SOURCE LINES 13-17

.. code-block:: Python


    fury.data.fetch_gltf(name="MorphStressTest", mode="glTF")
    filename = fury.data.read_viz_gltf("MorphStressTest")








.. GENERATED FROM PYTHON SOURCE LINES 18-20

Initializing the glTF object, You can additionally set `apply_normals=True`.
Note: Normals might not work as intended with morphing.

.. GENERATED FROM PYTHON SOURCE LINES 20-23

.. code-block:: Python


    gltf_obj = fury.gltf.glTF(filename, apply_normals=True)








.. GENERATED FROM PYTHON SOURCE LINES 24-27

Get the morph timeline using `morph_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 27-30

.. code-block:: Python


    animation = gltf_obj.morph_animation()["TheWave"]








.. GENERATED FROM PYTHON SOURCE LINES 31-33

Call the `update_morph` method once, This moves initialise the morphing at
timestamp 0.0 seconds and ensures that camera fits all the actors perfectly.

.. GENERATED FROM PYTHON SOURCE LINES 33-36

.. code-block:: Python


    gltf_obj.update_morph(animation)








.. GENERATED FROM PYTHON SOURCE LINES 37-40

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 40-49

.. 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 50-53

define a timer_callback.
Use the `update_morph` method again, It updates the timeline and applies
morphing).

.. GENERATED FROM PYTHON SOURCE LINES 53-60

.. code-block:: Python



    def timer_callback(_obj, _event):
        gltf_obj.update_morph(animation)
        showm.render()









.. GENERATED FROM PYTHON SOURCE LINES 61-62

Optional: `timeline.play()` auto plays the animations.

.. GENERATED FROM PYTHON SOURCE LINES 62-73

.. 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_morphing.png", size=(900, 768))



.. image-sg:: /auto_examples/01_introductory/images/sphx_glr_viz_morphing_001.png
   :alt: viz morphing
   :srcset: /auto_examples/01_introductory/images/sphx_glr_viz_morphing_001.png
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.163 seconds)


.. _sphx_glr_download_auto_examples_01_introductory_viz_morphing.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: viz_morphing.ipynb <viz_morphing.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: viz_morphing.py <viz_morphing.py>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_