Orienting Objects

Direction Orientation

One can reorient any blender objet to look at a point of interest by using the function look_at_point().

For example, to make the created camera and light look at the point (0,5,0), one would run

>>> from ddg.visualization.blender.object import look_at_point
>>> point = (0, 5, 0)
>>> look_at_point(li, point)  
>>> look_at_point(cam, point)  

One can even specify a distance to look_at_point(). For example to adjust the distance of the camera just run

>>> look_at_point(cam, point, distance=3)  

Note that it is also possible to add a negative distance to move the object past the target point.

By default cameras and lights in blender always look “down”, that is in direction (0,0,-1). look_at_point() was written with cameras and lights in mind, so it is adapted to these by default. However some objects have another default view direction than lights and camera. For example the arrow() object points by default in direction (0,0,1), so look_at_point() needs to get informed of it. One can provide a view_direction argument to look_at_point() to achive this.

>>> from ddg.datastructures.halfedge.surface_generator import arrow  
>>> arrow = ddg.to_blender_object(arrow())  
>>> look_at_point(arrow, point, view_direction=(0, 0, 1))  

Note that by giving the opposite view_direction, one can make an object look away from the point.

>>> look_at_point(arrow, point, view_direction=(0, 0, -1))  
>>> # will make the arrow point in the opposite direction to the point.

Up Orientation

Another thing that should be adjusted when orienting objects is the up direction. This is typically not needed for objects having an axial symetry along the view direction like arrows and most lights, but for cameras for example it is required and determines “how the screen is oriented”.

By default look_at_point() is built to orient a camera so that the top and bottom of the camera frame are parallel to the XY-plane with the top above the bottom. You can adjust this with the optional parameter target_up_direction. One use case would set the up direction to be the normal of an object when the camera is above its surface.

The optional argument up_direction informs look_at_point() about the original position of the up direction, that is where the up is in the object space, or before any transformation is applied to it.