{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Light Actors {#light_actors_example}\n\nPositional lights in PyVista have customizable beam shapes, see the\n`light_beam_shape_example`{.interpreted-text role=\"ref\"} example.\nSpotlights are special in the sense that they are unidirectional lights\nwith a finite position, so they can be visualized using a cone.\n\nThis is exactly the purpose of a `vtk.vtkLightActor`, the functionality\nof which can be enabled for spotlights:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n\nimport pyvista as pv\nfrom pyvista import examples\n\ncow = examples.download_cow()\ncow.rotate_x(90, inplace=True)\nplotter = pv.Plotter(lighting='none', window_size=(1000, 1000))\nplotter.add_mesh(cow, color='white')\nfloor = pv.Plane(center=(*cow.center[:2], cow.bounds[-2]), i_size=30, j_size=25)\nplotter.add_mesh(floor, color='green')\n\nUFO = pv.Light(position=(0, 0, 10), focal_point=(0, 0, 0), color='white')\nUFO.positional = True\nUFO.cone_angle = 40\nUFO.exponent = 10\nUFO.intensity = 3\nUFO.show_actor()\nplotter.add_light(UFO)\n\n# enable shadows to better demonstrate lighting\nplotter.enable_shadows()\n\nplotter.camera_position = [(28, 30, 22), (0.77, 0, -0.44), (0, 0, 1)]\nplotter.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Light actors can be very useful when designing complex scenes where\nspotlights are involved in lighting.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plotter = pv.Plotter(lighting='none')\nplane = pv.Plane(i_size=4, j_size=4)\nplotter.add_mesh(plane, color='white')\n\nrot120 = np.array([[-0.5, -np.sqrt(3) / 2, 0], [np.sqrt(3) / 2, -0.5, 0], [0, 0, 1]])\n\nposition = (-1.5, -1.5, 3)\nfocus = (-0.5, -0.5, 0)\ncolors = ['red', 'lime', 'blue']\nfor color in colors:\n position = rot120 @ position\n focus = rot120 @ focus\n light = pv.Light(position=position, focal_point=focus, color=color)\n light.positional = True\n light.cone_angle = 15\n light.show_actor()\n plotter.add_light(light)\n\nplotter.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One thing to watch out for is that the light actors are represented such\nthat their cone has a fixed height. This implies that for very large\ncone angles we typically end up with enormous light actors, in which\ncase setting a manual camera position before rendering is usually a good\nidea. Increasing the first example\\'s cone angle and omitting the manual\ncamera positioning exemplifies the problem:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plotter = pv.Plotter(lighting='none')\nplotter.add_mesh(cow, color='white')\nfloor = pv.Plane(center=(*cow.center[:2], cow.bounds[-2]), i_size=30, j_size=25)\nplotter.add_mesh(floor, color='green')\n\nUFO = pv.Light(position=(0, 0, 10), focal_point=(0, 0, 0), color='white')\nUFO.positional = True\nUFO.cone_angle = 89\nUFO.exponent = 10\nUFO.intensity = 3\nUFO.show_actor()\nplotter.add_light(UFO)\n\nplotter.show()" ] } ], "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.2" } }, "nbformat": 4, "nbformat_minor": 0 }