Visualizing a glTF file#

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

import fury

Create a scene.

scene = fury.window.Scene()
scene.SetBackground(0.1, 0.1, 0.4)

Retrieving the gltf model.

fury.data.fetch_gltf("Duck", "glTF")
filename = fury.data.read_viz_gltf("Duck")
/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. Note: You can always manually create actor from polydata, and apply texture or materials manually afterwards. Experimental: For smooth mesh/actor you can set apply_normals=True.

gltf_obj = fury.gltf.glTF(filename, apply_normals=False)
actors = gltf_obj.actors()

Add all the actor from list of actors to the scene.

scene.add(*actors)

Applying camera

cameras = gltf_obj.cameras
if cameras:
    scene.SetActiveCamera(cameras[0])

interactive = False

if interactive:
    fury.window.show(scene, size=(1280, 720))

fury.window.record(scene, out_path="viz_gltf.png", size=(1280, 720))
viz gltf
/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.280 seconds)

Gallery generated by Sphinx-Gallery