Visualizing a glTF file#

In this tutorial, we will show how to display a simple animated glTF in a scene.

import fury

Create a scene.

scene = fury.window.Scene()

showm = fury.window.ShowManager(
    scene, size=(900, 768), reset_camera=False, order_transparent=True
)
showm.initialize()
/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__)

Retrieving the gltf model.

fury.data.fetch_gltf("InterpolationTest", "glTF")
filename = fury.data.read_viz_gltf("InterpolationTest")
/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__)

Initialize the glTF object and get actors using actors method. Get the main_timeline (which contains multiple Timeline objects).

gltf_obj = fury.gltf.glTF(filename)
timeline = gltf_obj.main_animation()

Add the timeline to the scene (No need to add actors separately).

scene.add(timeline)

define a timer_callback that updates the timeline.

interactive = False


def timer_callback(_obj, _event):
    timeline.update_animation()
    showm.render()


showm.add_timer_callback(True, 10, timer_callback)

if interactive:
    showm.start()

fury.window.record(scene, out_path="viz_gltf_animated.png", size=(900, 768))
viz gltf animated
/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.172 seconds)

Gallery generated by Sphinx-Gallery