.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/mesh_slice.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_mesh_slice.py: Mesh Slice Material =================== Example showing off the mesh slice material. .. GENERATED FROM PYTHON SOURCE LINES 7-64 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_mesh_slice_001.webp :alt: mesh slice :srcset: /_gallery/feature_demo/images/sphx_glr_mesh_slice_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx canvas = RenderCanvas() renderer = gfx.renderers.WgpuRenderer(canvas) scene = gfx.Scene() geometry = gfx.torus_knot_geometry(1, 0.3, 128, 16) material1 = gfx.MeshPhongMaterial(color=(0.5, 0.5, 1.0, 0.5)) material2 = gfx.MeshSliceMaterial(thickness=8, color=(1, 1, 0, 1), plane=(0, 0, 1, 0)) obj1 = gfx.Mesh(geometry, material1) obj2 = gfx.Mesh(geometry, material2) scene.add(obj1) obj2.cast_shadow = True # It's actually the mesh slice casting a shadow scene.add(obj2) container = gfx.Mesh( gfx.box_geometry(10, 10, 10), gfx.MeshPhongMaterial(), ) container.receive_shadow = True scene.add(container) camera = gfx.PerspectiveCamera(70, 2) camera.local.position = (0, 4, 4) camera.look_at((0, 0, 0)) scene.add(gfx.AmbientLight(0.15)) light1 = gfx.PointLight("#fff", 0.7) light1.local.position = (0, 0, 4) light1.cast_shadow = True light2 = gfx.PointLight("#fff", 0.7) light2.local.position = (0, 4, 0) light2.cast_shadow = True scene.add(light1) scene.add(light2) light2.visible = True def animate(): dist = material2.plane[3] dist += 0.02 if dist > 2.2: dist = -2.2 material2.plane = 1, 0, 1, dist renderer.render(scene, 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 1.136 seconds) .. _sphx_glr_download__gallery_feature_demo_mesh_slice.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: mesh_slice.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: mesh_slice.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: mesh_slice.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