.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/scene_overlay.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_scene_overlay.py: Scene Overlay ============= Example showing a 3D scene, with an object overload via ``Material.depth_test``, and a 2D scene overlay over it all using an overlay render pass. .. GENERATED FROM PYTHON SOURCE LINES 9-80 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_scene_overlay_001.webp :alt: scene overlay :srcset: /_gallery/feature_demo/images/sphx_glr_scene_overlay_001.webp :class: sphx-glr-single-img .. code-block:: Python import numpy as np from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx import pylinalg as la # Create a canvas and renderer canvas = RenderCanvas(size=(500, 300)) renderer = gfx.renderers.WgpuRenderer(canvas) # Compose a 3D scene scene1 = gfx.Scene() cube1 = gfx.Mesh( gfx.box_geometry(200, 200, 200), gfx.MeshPhongMaterial(color="#ff0"), ) scene1.add(cube1) camera = gfx.OrthographicCamera(300, 300) scene1.add(camera.add(gfx.DirectionalLight())) # Add an object that is drawn on top, even though it's inside the bigger cube cube2 = gfx.Mesh( gfx.box_geometry(75, 75, 75), gfx.MeshPhongMaterial(color="#00f", depth_test=False, side="front"), ) scene1.add(cube2) # Compose another scene, a 2D overlay scene2 = gfx.Scene() positions = np.array( [ [-1, -1, 0.5], [-1, +1, 0.5], [+1, +1, 0.5], [+1, -1, 0.5], [-1, -1, 0.5], [+1, +1, 0.5], ], np.float32, ) line2 = gfx.Line( gfx.Geometry(positions=positions * 100), gfx.LineMaterial(thickness=5.0, color="#f0f", depth_test=False), ) scene2.add(line2) def animate(): rot = la.quat_from_euler((0.005, 0.01), order="XY") cube1.local.rotation = la.quat_mul(rot, cube1.local.rotation) cube2.local.rotation = cube1.local.rotation renderer.render(scene1, camera, flush=False) renderer.render(scene2, camera) canvas.request_draw() if __name__ == "__main__": canvas.request_draw(animate) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.197 seconds) .. _sphx_glr_download__gallery_feature_demo_scene_overlay.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: scene_overlay.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: scene_overlay.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: scene_overlay.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