.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/helpers_gizmo.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__gallery_feature_demo_helpers_gizmo.py: Gizmo to transform world objects ================================ Example to demonstrate the Gizmo that can be used to transform world objects. Click the center sphere to toggle between object-space, world-space, and screen-space. .. GENERATED FROM PYTHON SOURCE LINES 8-49 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_helpers_gizmo_001.webp :alt: helpers gizmo :srcset: /_gallery/feature_demo/images/sphx_glr_helpers_gizmo_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx canvas = RenderCanvas() renderer = gfx.renderers.WgpuRenderer(canvas) viewport = gfx.Viewport(renderer) scene = gfx.Scene() cube = gfx.Mesh( gfx.box_geometry(1, 1, 1), gfx.MeshPhongMaterial(color="#336699"), ) scene.add(cube) scene.add(gfx.GridHelper()) camera = gfx.PerspectiveCamera(70, 16 / 9) camera.show_object(scene) controller = gfx.OrbitController(camera, register_events=renderer) scene.add(gfx.AmbientLight(), camera.add(gfx.DirectionalLight())) gizmo = gfx.TransformGizmo(cube) gizmo.add_default_event_handlers(viewport, camera) def animate(): # We render the scene, and then the gizmo on top, # as an overlay, so that it's always on top. viewport.render(scene, camera) viewport.render(gizmo, camera) renderer.flush() if __name__ == "__main__": canvas.request_draw(animate) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.382 seconds) .. _sphx_glr_download__gallery_feature_demo_helpers_gizmo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: helpers_gizmo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: helpers_gizmo.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: helpers_gizmo.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_ .. only:: html Interactive example ------------------- Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser's console for details. .. raw:: html