.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_introductory/viz_gltf_export.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_01_introductory_viz_gltf_export.py: ============================== Exporting scene as a glTF file ============================== In this tutorial, we will show how to create a glTF file for a scene. .. GENERATED FROM PYTHON SOURCE LINES 7-12 .. code-block:: Python import numpy as np from fury import actor, gltf, window from fury.data import fetch_gltf, read_viz_gltf .. GENERATED FROM PYTHON SOURCE LINES 13-15 Specifying centers and colors for actors. We will use these parameters later. .. GENERATED FROM PYTHON SOURCE LINES 15-19 .. code-block:: Python centers = np.zeros((3, 3)) colors = np.array([1, 1, 1]) .. GENERATED FROM PYTHON SOURCE LINES 20-21 Create a scene. .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python scene = window.Scene() .. GENERATED FROM PYTHON SOURCE LINES 25-26 Creating actors and adding to scene. .. GENERATED FROM PYTHON SOURCE LINES 26-39 .. code-block:: Python cube = actor.cube(np.add(centers, np.array([2, 0, 0])), colors=colors / 2) scene.add(cube) sphere = actor.sphere(np.add(centers, np.array([0, 2, 0])), colors=colors) scene.add(sphere) fetch_gltf('BoxTextured', 'glTF') filename = read_viz_gltf('BoxTextured') gltf_obj = gltf.glTF(filename) box_actor = gltf_obj.actors() scene.add(box_actor[0]) .. GENERATED FROM PYTHON SOURCE LINES 40-41 Setting camera to the scene. .. GENERATED FROM PYTHON SOURCE LINES 41-46 .. code-block:: Python scene.set_camera( position=(4.45, -21, 12), focal_point=(4.45, 0.0, 0.0), view_up=(0.0, 0.0, 1.0) ) .. GENERATED FROM PYTHON SOURCE LINES 47-48 Exporting scene as a glTF file .. GENERATED FROM PYTHON SOURCE LINES 48-51 .. code-block:: Python gltf.export_scene(scene, filename='viz_gltf_export.gltf') .. image-sg:: /auto_examples/01_introductory/images/sphx_glr_viz_gltf_export_001.png :alt: viz gltf export :srcset: /auto_examples/01_introductory/images/sphx_glr_viz_gltf_export_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-53 Reading the newly created glTF file and get actors. .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python gltf_obj = gltf.glTF('viz_gltf_export.gltf') actors = gltf_obj.actors() .. GENERATED FROM PYTHON SOURCE LINES 58-59 Add all the actor from list of actors to the scene. .. GENERATED FROM PYTHON SOURCE LINES 59-68 .. code-block:: Python scene.add(*actors) interactive = False if interactive: window.show(scene, size=(1280, 720)) window.record(scene, out_path='viz_gltf_export.png', size=(1280, 720)) .. image-sg:: /auto_examples/01_introductory/images/sphx_glr_viz_gltf_export_002.png :alt: viz gltf export :srcset: /auto_examples/01_introductory/images/sphx_glr_viz_gltf_export_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.120 seconds) .. _sphx_glr_download_auto_examples_01_introductory_viz_gltf_export.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_gltf_export.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_gltf_export.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_