.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/scene_subplots1.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_subplots1.py: Subplots 1 ========== Example showing how to render to a subregion of a canvas. This is a feature necessary to implement e.g. subplots. This example uses a low-level approach without using the Viewport object. See scene_subplot2.py for a slightly higher-level approach. .. GENERATED FROM PYTHON SOURCE LINES 11-70 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_scene_subplots1_001.webp :alt: scene subplots1 :srcset: /_gallery/feature_demo/images/sphx_glr_scene_subplots1_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 anvas and a renderer canvas = RenderCanvas(size=(500, 300)) renderer = gfx.renderers.WgpuRenderer(canvas) # Compose a 3D scene scene1 = gfx.Scene() geometry1 = gfx.box_geometry(200, 200, 200) material1 = gfx.MeshPhongMaterial(color=(1, 1, 0, 1.0)) cube1 = gfx.Mesh(geometry1, material1) scene1.add(cube1) camera1 = gfx.PerspectiveCamera(70, 16 / 9, width=200) camera1.local.z = 400 scene1.add(camera1.add(gfx.DirectionalLight())) # Compose another scene scene2 = gfx.Scene() positions = np.array( [[-1, -1, 0], [-1, +1, 0], [+1, +1, 0], [+1, -1, 0], [-1, -1, 0], [+1, +1, 0]], np.float32, ) geometry2 = gfx.Geometry(positions=positions) material2 = gfx.LineMaterial(thickness=5.0, color=(0.8, 0.0, 0.2, 1.0)) line2 = gfx.Line(geometry2, material2) scene2.add(line2) camera2 = gfx.OrthographicCamera(2.2, 2.2) def animate(): rot = la.quat_from_euler((0.005, 0.01), order="XY") cube1.local.rotation = la.quat_mul(rot, cube1.local.rotation) w, h = canvas.get_logical_size() renderer.render(scene1, camera1, flush=False, rect=(0, 0, w / 2, h / 2)) renderer.render(scene2, camera2, flush=False, rect=(w / 2, 0, w / 2, h / 2)) renderer.render(scene2, camera2, flush=False, rect=(0, h / 2, w / 2, h / 2)) renderer.render(scene1, camera1, flush=False, rect=(w / 2, h / 2, w / 2, h / 2)) renderer.flush() 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.103 seconds) .. _sphx_glr_download__gallery_feature_demo_scene_subplots1.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: scene_subplots1.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: scene_subplots1.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: scene_subplots1.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