.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/scene/mesh_normals.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_scene_mesh_normals.py: Display Mesh Normals ==================== Show how to display mesh normals on a mesh. .. GENERATED FROM PYTHON SOURCE LINES 13-59 .. image-sg:: /gallery/scene/images/sphx_glr_mesh_normals_001.png :alt: mesh normals :srcset: /gallery/scene/images/sphx_glr_mesh_normals_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Key bindings: f : toggle face normals v : toggle vertex normals | .. code-block:: Python from vispy import app, scene from vispy.io import read_mesh, load_data_file from vispy.scene.visuals import Mesh, MeshNormals from vispy.visuals.filters import WireframeFilter mesh_file = load_data_file('orig/triceratops.obj.gz') vertices, faces, _, _ = read_mesh(mesh_file) mesh = Mesh(vertices, faces, shading='flat') meshdata = mesh.mesh_data wireframe_filter = WireframeFilter(color='lightblue') mesh.attach(wireframe_filter) face_normals = MeshNormals(meshdata, primitive='face', color='yellow') vertex_normals = MeshNormals(meshdata, primitive='vertex', color='orange', width=2) canvas = scene.SceneCanvas(keys='interactive', bgcolor='white') view = canvas.central_widget.add_view() view.camera = 'arcball' view.add(mesh) face_normals.parent = mesh vertex_normals.parent = mesh @canvas.events.key_press.connect def on_key_press(event): if event.key == 'f': face_normals.visible = not face_normals.visible canvas.update() elif event.key == 'v': vertex_normals.visible = not vertex_normals.visible canvas.update() canvas.show() if __name__ == "__main__": print('Key bindings:') print(' f : toggle face normals') print(' v : toggle vertex normals') app.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.227 seconds) .. _sphx_glr_download_gallery_scene_mesh_normals.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: mesh_normals.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: mesh_normals.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_