Source code for ddg.visualization.blender.light

import bpy

from ddg.visualization.blender.object import look_at_point as lap


[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, ): """ Add a light. Parameters ---------- name : string, default='Light' Name of the created light type : string, default='SUN' Type of the light, 'POINT', 'SUN', 'Sport' 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. Specular value of the light in the illumination model. Returns ------- bpy.types.Light """ light_data = bpy.data.lights.new(name, type=type) light_data.color = color light_data.specular_factor = specular 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) lap( bobj, point, obj_front=light_front, obj_up=light_up, world_up=world_up, distance=distance, )