.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/transparency2.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_transparency2.py: Transparency 2 ============== Example showing transparency using three orthogonal planes. Press space to toggle the order of the planes. Press 1-6 to select the blend mode. .. GENERATED FROM PYTHON SOURCE LINES 9-68 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_transparency2_001.png :alt: transparency2 :srcset: /_gallery/feature_demo/images/sphx_glr_transparency2_001.png :class: sphx-glr-single-img .. code-block:: default from wgpu.gui.auto import WgpuCanvas, run import pygfx as gfx import pylinalg as la canvas = WgpuCanvas() renderer = gfx.renderers.WgpuRenderer(canvas) scene = gfx.Scene() sphere = gfx.Mesh(gfx.sphere_geometry(10), gfx.MeshPhongMaterial()) geometry = gfx.plane_geometry(50, 50) plane1 = gfx.Mesh(geometry, gfx.MeshBasicMaterial(color=(1, 0, 0, 0.3))) plane2 = gfx.Mesh(geometry, gfx.MeshBasicMaterial(color=(0, 1, 0, 0.5))) plane3 = gfx.Mesh(geometry, gfx.MeshBasicMaterial(color=(0, 0, 1, 0.7))) plane1.local.rotation = la.quat_from_axis_angle((1, 0, 0), 1.571) plane2.local.rotation = la.quat_from_axis_angle((0, 1, 0), 1.571) plane3.local.rotation = la.quat_from_axis_angle((0, 0, 1), 1.571) scene.add(plane1, plane2, plane3, sphere) camera = gfx.PerspectiveCamera(70, 16 / 9) camera.show_object(scene, view_dir=(-1, -2, -3)) controller = gfx.OrbitController(camera, register_events=renderer) scene.add(camera.add(gfx.DirectionalLight())) @renderer.add_event_handler("key_down") def handle_event(event): if event.key == " ": print("Rotating scene element order") scene.add(scene.children[0]) canvas.request_draw() elif event.key in "0123456789": m = [ None, "opaque", "ordered1", "ordered2", "weighted", "weighted_depth", "weighted_plus", ] mode = m[int(event.key)] renderer.blend_mode = mode print("Selecting blend_mode", mode) def animate(): renderer.render(scene, camera) canvas.request_draw() if __name__ == "__main__": print(__doc__) canvas.request_draw(animate) run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.273 seconds) .. _sphx_glr_download__gallery_feature_demo_transparency2.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: transparency2.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: transparency2.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_