.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorial/03_figures/b_shading.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 or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorial_03_figures_b_shading.py: .. _shading_example: Types of Shading ~~~~~~~~~~~~~~~~ Comparison of default, flat shading vs. smooth shading. .. GENERATED FROM PYTHON SOURCE LINES 9-13 .. code-block:: Python import pyvista as pv from pyvista import examples .. GENERATED FROM PYTHON SOURCE LINES 15-19 PyVista supports two types of shading: flat and smooth shading that uses VTK's Phong shading algorithm. This is a plot with the default flat shading. .. GENERATED FROM PYTHON SOURCE LINES 19-23 .. code-block:: Python mesh = examples.load_nut() mesh.plot() .. image-sg:: /tutorial/03_figures/images/sphx_glr_b_shading_001.png :alt: b shading :srcset: /tutorial/03_figures/images/sphx_glr_b_shading_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 24-25 Here's the same sphere with smooth shading. .. GENERATED FROM PYTHON SOURCE LINES 25-28 .. code-block:: Python mesh.plot(smooth_shading=True) .. image-sg:: /tutorial/03_figures/images/sphx_glr_b_shading_002.png :alt: b shading :srcset: /tutorial/03_figures/images/sphx_glr_b_shading_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 29-37 Note how smooth shading makes edges that should be sharp look odd, it's because the points of these normals are averaged between two faces that have a sharp angle between them. You can avoid this by enabling ``split_sharp_edges``. .. note:: You can configure the splitting angle with the optional ``feature_angle`` keyword argument. .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python mesh.plot(smooth_shading=True, split_sharp_edges=True) .. image-sg:: /tutorial/03_figures/images/sphx_glr_b_shading_003.png :alt: b shading :srcset: /tutorial/03_figures/images/sphx_glr_b_shading_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 41-43 We can even plot the edges that will be split using :func:`extract_feature_edges `. .. GENERATED FROM PYTHON SOURCE LINES 43-57 .. code-block:: Python # extract the feature edges exceeding 30 degrees edges = mesh.extract_feature_edges( boundary_edges=False, non_manifold_edges=False, feature_angle=30, manifold_edges=False ) # plot both the edges and the smoothed mesh pl = pv.Plotter() # pl.enable_anti_aliasing() pl.add_mesh(mesh, smooth_shading=True, split_sharp_edges=True) pl.add_mesh(edges, color='k', line_width=5) pl.show() .. image-sg:: /tutorial/03_figures/images/sphx_glr_b_shading_004.png :alt: b shading :srcset: /tutorial/03_figures/images/sphx_glr_b_shading_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-60 The ``split_sharp_edges`` keyword argument is compatible with physically based rendering as well. .. GENERATED FROM PYTHON SOURCE LINES 60-67 .. code-block:: Python # plot both the edges and the smoothed mesh pl = pv.Plotter() # pl.enable_anti_aliasing() pl.add_mesh(mesh, color='w', split_sharp_edges=True, pbr=True, metallic=1.0, roughness=0.5) pl.show() .. image-sg:: /tutorial/03_figures/images/sphx_glr_b_shading_005.png :alt: b shading :srcset: /tutorial/03_figures/images/sphx_glr_b_shading_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 68-75 .. raw:: html
Open In Colab
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.345 seconds) .. _sphx_glr_download_tutorial_03_figures_b_shading.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/pyvista/pyvista-tutorial/gh-pages?urlpath=lab/tree/notebooks/tutorial/03_figures/b_shading.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: b_shading.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: b_shading.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_