.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/validation/validate_line_thickness_space.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_validation_validate_line_thickness_space.py: Lines drawn with different thickness_space ========================================== This example draws 3 rows of cubes, each with thickness 10, but each row in a different thickness_space (and color). The left column is positioned directly in the scene. The next two columns are smaller cubes, but placed in scaled containers. * The red cubes have thickness in screen space, and all look the same. * The green cubes have thickness in world space, and look the same, but thicker than the red. * The blue cubes have thickness in model space, and become thicker in each column. .. GENERATED FROM PYTHON SOURCE LINES 13-150 .. image-sg:: /_gallery/validation/images/sphx_glr_validate_line_thickness_space_001.webp :alt: validate line thickness space :srcset: /_gallery/validation/images/sphx_glr_validate_line_thickness_space_001.webp :class: sphx-glr-single-img .. code-block:: Python import numpy as np from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx canvas = RenderCanvas(size=(1000, 1000)) renderer = gfx.WgpuRenderer(canvas) position_pairs = [ [-1, -1, -1], [-1, -1, 1], [-1, -1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1], [1, 1, -1], [1, 1, 1], [1, 1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1], [-1, 1, 1], [-1, 1, -1], [-1, 1, 1], [-1, -1, 1], [-1, 1, 1], [1, 1, 1], [1, -1, 1], [1, -1, -1], [1, -1, 1], [1, 1, 1], [1, -1, 1], [-1, -1, 1], ] position_pairs = 50 * np.array(position_pairs, np.float32) if True: # use segment Material = gfx.LineSegmentMaterial positions = np.array(position_pairs, np.float32) else: # use nans Material = gfx.LineMaterial positions = np.zeros((3 * len(position_pairs) // 2, 3), np.float32) positions[0::3] = position_pairs[0::2] positions[1::3] = position_pairs[1::2] positions[2::3] = np.nan def add_three_cubes(parent, material): line1 = gfx.Line( gfx.Geometry(positions=positions), material, ) container1 = gfx.Scene() parent.add(container1.add(line1)) line2 = gfx.Line( gfx.Geometry(positions=positions / 2), material, ) container2 = gfx.Scene() parent.add(container2.add(line2)) line2.local.scale = 2 line3 = gfx.Line( gfx.Geometry(positions=positions / 3.3333), material, ) container3 = gfx.Scene() parent.add(container3.add(line3)) container3.local.scale = 3.3333 # Positioning container1.local.position = -150, 0, 0 container3.local.position = 150, 0, 0 top = gfx.Scene() # screen middle = gfx.Scene() # world bottom = gfx.Scene() # model top.local.position = 0, 150, 0 bottom.local.position = 0, -150, 0 scene = gfx.Scene() scene.add(top, middle, bottom) add_three_cubes( top, Material( thickness=10, thickness_space="screen", dash_pattern=[0, 2], color=(1.0, 0.0, 0.0), alpha_mode="blend", opacity=0.5, aa=True, ), ) add_three_cubes( middle, Material( thickness=10, thickness_space="world", dash_pattern=[0, 2], color=(0.0, 1.0, 0.0), alpha_mode="blend", opacity=0.5, aa=True, ), ) add_three_cubes( bottom, Material( thickness=10, thickness_space="model", dash_pattern=[0, 2], color=(0.0, 0.0, 1.0), alpha_mode="blend", opacity=0.5, aa=True, ), ) camera = gfx.PerspectiveCamera(90) camera.show_object(scene) controller = gfx.OrbitController(camera, register_events=renderer) canvas.request_draw(lambda: renderer.render(scene, camera)) if __name__ == "__main__": print(__doc__) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.934 seconds) .. _sphx_glr_download__gallery_validation_validate_line_thickness_space.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: validate_line_thickness_space.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: validate_line_thickness_space.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: validate_line_thickness_space.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