.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/scene_camlink2.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_camlink2.py: Camera linking 2 ================ Example demonstating the partial linking of two cameras in 3D. The left and right view use an orbit- and fly-controller, respectively. Yet, manipulating one also updates the othe camera. This demonstrates how the controllers are stateless (except during interaction). .. GENERATED FROM PYTHON SOURCE LINES 11-81 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_scene_camlink2_001.webp :alt: scene camlink2 :srcset: /_gallery/feature_demo/images/sphx_glr_scene_camlink2_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx import numpy as np renderer = gfx.renderers.WgpuRenderer(RenderCanvas(size=(900, 600))) # Create a scene to display multiple times. It contains a point cloud scene = gfx.Scene() scene.add(gfx.Background.from_color("#ddd")) n = 1000 positions = np.random.normal(0, 50, (n, 3)).astype(np.float32) sizes = np.random.rand(n).astype(np.float32) * 50 colors = np.random.rand(n, 4).astype(np.float32) points = gfx.Points( gfx.Geometry(positions=positions, sizes=sizes, colors=colors), gfx.PointsMaterial(color_mode="vertex", size_mode="vertex", size_space="world"), ) scene.add(points) # Background viewport0 = gfx.Viewport(renderer) camera0 = gfx.NDCCamera() scene0 = gfx.Background.from_color("#fff") # Create view 1 viewport1 = gfx.Viewport(renderer) camera1 = gfx.PerspectiveCamera(50) camera1.show_object(scene) controller1 = gfx.OrbitController(camera1, register_events=viewport1) # Create view 2 viewport2 = gfx.Viewport(renderer) camera2 = gfx.PerspectiveCamera(50) camera2.show_object(scene) controller2 = gfx.FlyController(camera2, register_events=viewport2) # Link cameras controller1.add_camera(camera2, include_state={"position", "rotation"}) controller2.add_camera(camera1, include_state={"position", "rotation"}) @renderer.add_event_handler("resize") def layout(event=None): w, h = renderer.logical_size w2 = (w - 30) / 2 viewport1.rect = 10, 10, w2, h - 20 viewport2.rect = w2 + 20, 10, w2, h - 20 # Initialize layout layout() def animate(): viewport0.render(scene0, camera0) viewport1.render(scene, camera1) viewport2.render(scene, camera2) renderer.flush() if __name__ == "__main__": renderer.request_draw(animate) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.552 seconds) .. _sphx_glr_download__gallery_feature_demo_scene_camlink2.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: scene_camlink2.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: scene_camlink2.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: scene_camlink2.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