{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lighting Properties {#ref_lighting_properties_example}\n\nControl aspects of the rendered mesh\\'s lighting such as Ambient,\nDiffuse, and Specular. These options only work if the `lighting`\nargument to `add_mesh` is `True` (it\\'s `True` by default).\n\nYou can turn off all lighting for the given mesh by passing\n`lighting=False` to `add_mesh`.\n\nSee the `add_mesh` docs for lighting options:\n<https://docs.pyvista.org/api/plotting/_autosummary/pyvista.Plotter.add_mesh.html>\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pyvista as pv\nfrom pyvista import examples\n\nmesh = examples.download_st_helens().warp_by_scalar()\n\ncpos = [(575848.0, 5128459.0, 22289.0), (562835.0, 5114981.5, 2294.5), (-0.5, -0.5, 0.7)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, lets take a look at the mesh with default lighting conditions\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "mesh.plot(cpos=cpos, show_scalar_bar=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What about with no lighting?\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "mesh.plot(lighting=False, cpos=cpos, show_scalar_bar=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Demonstration of the specular property\n\nFeel free to adjust the specular value in the `s` variable.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pl = pv.Plotter(shape=(1, 2), window_size=[1500, 500])\n\npl.subplot(0, 0)\npl.add_mesh(mesh, show_scalar_bar=False)\npl.add_text(\"No Specular\")\n\npl.subplot(0, 1)\nspecular = 1.0\npl.add_mesh(mesh, specular=specular, show_scalar_bar=False)\npl.add_text(f\"Specular of {specular}\")\n\npl.link_views()\npl.view_isometric()\npl.show(cpos=cpos)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Specular power (feel free to adjust)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "mesh.plot(specular=0.5, specular_power=15, cpos=cpos, show_scalar_bar=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Demonstration of all diffuse, specular, and ambient in use together\n(feel free to adjust)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "mesh.plot(diffuse=0.5, specular=0.5, ambient=0.5, cpos=cpos, show_scalar_bar=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For detailed control over lighting conditions in general see the\n[lighting\nexamples](https://docs.pyvista.org/examples/index.html#lighting)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```{=html}\n<center>\n <a target=\"_blank\" href=\"https://colab.research.google.com/github/pyvista/pyvista-tutorial/blob/gh-pages/notebooks/tutorial/03_figures/solutions/b_lighting_mesh.ipynb\">\n <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/ width=\"150px\">\n </a>\n</center>\n```\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.11" } }, "nbformat": 4, "nbformat_minor": 0 }