Source code for ddg.visualization.blender.light

import bpy

import ddg.visualization.blender.object


[docs]def light( name="Light", type="SUN", location=(0.0, 0.0, 0.0), collection=None, color=(1.0, 1.0, 1.0), specular=1.0, energy=10, ): """ Add a light. Parameters ---------- name : str (default='Light') Name of the created light type : str (default='SUN') Type of the light, 'POINT', 'SUN', 'SPOT' or 'AREA' location : Iterable of three floats (default=(0., 0., 0.)) location of the light collection : bpy.types.collection (default=None) Collection to link light to, If the parameter is not given or set to None the light gets linked to bpy.context.scene.collection color : Iterable of three floats (default=(1.,1.,1.)) RGB color of the light. specular : float (default=1.0) Specular value of the light in the illumination model. energy: float (default=10) Energy of the light in Watts. Returns ------- bpy.types.Light """ light_data = bpy.data.lights.new(name, type=type) light_data.color = color light_data.specular_factor = specular light_data.energy = energy if collection is None: collection = bpy.context.scene.collection light_bobj = bpy.data.objects.new(name, light_data) collection.objects.link(light_bobj) light_bobj.location = location return light_bobj
[docs]def look_at_point(bobj, point, world_up=(0, 0, 1), distance=None): """ Rotates light so that it points toward a given point. See ddg.visualization.blender.object.look_at_point for full documentation. """ light_front = (0, 0, -1) light_up = (0, 1, 0) ddg.visualization.blender.object.look_at_point( bobj, point, bobj_front=light_front, bobj_up=light_up, world_up=world_up, distance=distance, )
[docs]def clear(lights=None, do_unlink=True): """Delete all given lights. Parameters ---------- lights : Iterable of bpy.type.Light (default=None) Lights to be deleted. If the argument is not provided or None all lights will be deleted. do_unlink : bool (default=True) Unlink lights from their scenes, if needed, before deleting them. Returns ------- None """ if lights is None: lights = bpy.data.lights lights = list(lights) while lights: bpy.data.lights.remove(lights.pop(), do_unlink=do_unlink)