import bpy
# Wrapper for look_at_point
from ddg.visualization.blender.object import look_at_point as lap
[docs]def camera(name="Camera", type="PERSP", location=(0.0, 0.0, 0.0), collection=None):
"""
Add a camera.
Parameters
----------
name : string, default='Camera'
Name of the created camera
type : string, default='PERSP'
Type of the camera, 'PERSP', 'ORTHO' or 'PANO'
location : iterable of three floats, default=(0., 0., 0.)
location of the camera
collection : bpy.types.collection, default=None
Collection to link camera to,
If the parameter is not given or set to None the camera
gets linked to bpy.context.scene.collection
Returns
-------
bpy.types.Camera
"""
cam = bpy.data.cameras.new(name)
cam.type = type
if collection is None:
collection = bpy.context.scene.collection
cam_ob = bpy.data.objects.new(name, cam)
collection.objects.link(cam_ob)
cam_ob.location = location
return cam_ob
[docs]def look_at_point(camera_bobj, point, world_up=(0, 0, 1), distance=None):
"""
Rotates camera such that it looks at the given point.
See ddg.visualization.blender.object.look_at_point for full documentation.
"""
bobj_front = (0, 0, -1)
bobj_up = (0, 1, 0)
lap(
camera_bobj,
point,
obj_front=bobj_front,
obj_up=bobj_up,
world_up=world_up,
distance=distance,
)