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.0, ): """ 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.0) Energy of the light in Watts. Returns ------- bpy.types.Object """ if collection is None: collection = bpy.context.scene.collection 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. Parameters ---------- bobj : bpy.types.Object Blenders object to move. point : iterable of 3 floats Point of reference to turn object. world_up : iterable of 3 floats (default=(0,0,1)) Where the up direction should end up. distance : float (default=None) Distance the object should have from the point. See Also -------- ddg.visualization.blender.object.look_at_point """ bobj_front = (0, 0, -1) bobj_up = (0, 1, 0) ddg.visualization.blender.object.look_at_point( bobj, point, bobj_front=bobj_front, bobj_up=bobj_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. """ if lights is None: lights = bpy.data.lights lights = list(lights) while lights: bpy.data.lights.remove(lights.pop(), do_unlink=do_unlink)