Camera¶
Qualified name: algan.rendering.camera.Camera
- class Camera(orthographic=False, screen_distance=5, screen_half_height=2.5, fov=None, near=0.0, far=0.0, *args, **kwargs)[source]¶
Bases:
MobThe Scene’s viewpoint. A Mob, so it animates like one.
Positioning¶
Use
move_to()(ormovefor a relative step) – they set the camera’s own location and carry its screen along. Do not usemove_center_to(): that centres a bounding box, and a Camera’s box spans it and its internal screen plane, so the camera lands half the screen distance behind where you asked.Field of view and aspect ratio¶
fov/set_fov()are vertical, matching Three.js’sPerspectiveCamera. The horizontal field of view is derived from it and the output aspect ratio, so changing the resolution’s shape changes how wide the camera sees while the vertical stays put. The default 53 degree vertical fov gives about 82 degrees horizontally at 16:9, but about 119 degrees on a 3.4:1 banner – wide enough that an off-axis sphere is visibly projected as an ellipse (stretched by1 / cos(angle off axis), so ~1.9x at that frame’s edge). That is correct perspective, not a bug, but it is rarely what a wide still is after: for the near-orthographic look of a long lens, narrow the fov and pull back by the same factor, keepingdistance * tan(fov / 2)constant:camera = Scene.get_camera() camera.set_fov(math.degrees(2 * math.atan(3.5 / 70))) camera.move_to(OUT * 70) # was OUT * 7, so 10x the distance
Alternatively
set_near_orthographic()flattens it almost completely – it is an approximation, not true parallel projection; see Renderer Limitations.Methods
Move the camera so a Mob fills the frame, centred.
Get the four corners of the visible frame, in world space.
Far clip distance (world units of ray travel from the camera); geometry farther than this shows the background/environment instead.
The camera's vertical field of view in degrees (like Three.js's
PerspectiveCamera.fov), derived from the screen size and the camera-to-screen distance.Near clip distance (world units from the camera along its forward axis); geometry closer than this is not rendered.
Find where a point would leave the frame travelling in a direction.
Moves the camera focus to be the given distance away from its screen, thereby changing the perspective.
Point the camera using three Euler rotations about the origin.
Set the far clip distance (0 disables far clipping).
Set the vertical field of view (degrees).
Set the near clip plane distance (0 disables near clipping).
Flatten perspective by moving the camera far from its screen.
Attributes
animation_managerThis mob's scene-owned animation manager.
basisThe Mob's orientation and scale, as a flattened 3x3 matrix of shape
(*, 9).casts_shadowsWhether this Mob's geometry blocks light on its way from a light source to another surface -- whether it casts a shadow.
childrenThe Mobs attached below this one, in attachment order.
closed_shellWhether this Mob's triangles form a CLOSED shell -- every camera ray that enters the geometry crosses a second time on its way out.
draws_descendantsWhether
get_render_primitivesreturns geometry belonging to this Mob's DESCENDANTS as well as its own.Far clip distance (world units of ray travel from the camera); geometry farther than this shows the background/environment instead.
forwardGet the direction the Mob is facing.
The camera's vertical field of view in degrees (like Three.js's
PerspectiveCamera.fov), derived from the screen size and the camera-to-screen distance.lifespanThis mob's [spawn, despawn) interval on its Scene timeline (a
Lifespan).locationThe Mob's position in world space, shape
(*, 3).Near clip distance (world units from the camera along its forward axis); geometry closer than this is not rendered.
normalized_basisThe Mob's orientation with scale divided out, shape
(*, 9).parentsThe Mobs this one is attached to, in attachment order.
Current normalized screen height represented by one output pixel.
Current normalized screen width represented by one output pixel.
receives_shadowsWhether this Mob's surfaces are darkened by shadows cast onto them.
rightGet the Mob's own rightward direction.
scale_coefficientThe Mob's scale along its own right, up and forward axes, shape
(*, 3).two_sidedWhether this Mob's geometry should be lit from whichever side the ray arrives on.
upGet the Mob's own upward direction.
xThe Mob's x coordinate in world units, shape
(*, 1).xyThe Mob's x and y coordinates in world units, shape
(*, 2).yThe Mob's y coordinate in world units, shape
(*, 1).zThe Mob's z coordinate in world units, shape
(*, 1).- center_on(mob, buffer_portion=0.7)[source]¶
Move the camera so a Mob fills the frame, centred.
The camera slides sideways to centre the Mob and in or out until the Mob just fits, leaving
buffer_portionof margin. It does not rotate, so the viewing angle you set is preserved.Animation
Recorded as an animation: the moves run together inside a
Sync, over the current context’s runtime (1 second by default). The Mob’s extent is measured when the call is recorded, so a Mob that changes size afterwards will not stay framed.- Parameters:
mob – The Mob to frame.
buffer_portion (float) – Extra margin around the Mob, as a fraction of its size. Defaults to
0.7, i.e. the framed area is 1.7 times the Mob’s extent.
- Returns:
This camera, so calls can be chained.
- Return type:
- property far¶
Far clip distance (world units of ray travel from the camera); geometry farther than this shows the background/environment instead. 0 = disabled.
- property fov¶
The camera’s vertical field of view in degrees (like Three.js’s
PerspectiveCamera.fov), derived from the screen size and the camera-to-screen distance.
- get_corner_pixels()[source]¶
Get the four corners of the visible frame, in world space.
The corners of the camera’s screen plane, accounting for the current aspect ratio, ordered around the frame. Screen-relative layout is built on these.
- Returns:
The four corner points, shape
(4, *, 3).- Return type:
torch.Tensor
- get_far()[source]¶
Far clip distance (world units of ray travel from the camera); geometry farther than this shows the background/environment instead. 0 = disabled.
- get_fov()[source]¶
The camera’s vertical field of view in degrees (like Three.js’s
PerspectiveCamera.fov), derived from the screen size and the camera-to-screen distance.
- get_near()[source]¶
Near clip distance (world units from the camera along its forward axis); geometry closer than this is not rendered. 0 = disabled.
- property near¶
Near clip distance (world units from the camera along its forward axis); geometry closer than this is not rendered. 0 = disabled.
- property pixel_height¶
Current normalized screen height represented by one output pixel.
- property pixel_width¶
Current normalized screen width represented by one output pixel.
- project_point_onto_screen_border(point, direction)[source]¶
Find where a point would leave the frame travelling in a direction.
Casts from
pointalongdirectionand returns the intersection with the edge of the visible frustum. This is what the screen-edge placement methods use to know where “against the edge” is.- Parameters:
point (Tensor) – Starting point, shape
(*, 3).direction (Tensor) – Direction to travel, shape
(*, 3), e.g.RIGHTorUP.
- Returns:
The point on the frame border, shape
(*, 3).- Return type:
torch.Tensor
- set_distance_to_screen(distance)[source]¶
Moves the camera focus to be the given distance away from its screen, thereby changing the perspective.
- Parameters:
distance – The camera focus will be set to be this distance away from the screen.
- set_euler_angles(yaw, pitch, roll, *, degrees=True)[source]¶
Point the camera using three Euler rotations about the origin.
The rotations are applied about the world x, y and z axes and are performed together, so the camera swings around the origin rather than turning in place. Note these are added to the camera’s current orientation rather than replacing it, despite the name.
Animation
Recorded as an animation: all three rotations run inside a
Sync, over the current context’s runtime (1 second by default).- Parameters:
yaw (float | Tensor) – Rotation about the world x axis (
RIGHT).pitch (float | Tensor) – Rotation about the world y axis (
UP).roll (float | Tensor) – Rotation about the world z axis (
OUTWARD).degrees (bool) – Whether the three angles are in degrees. Defaults to True; pass False to give them in radians.
- Returns:
This camera, so calls can be chained.
- Return type:
- set_fov(fov)[source]¶
Set the vertical field of view (degrees). The camera stays where it is; its screen moves along the forward axis so that the given angle is spanned (small fov = telephoto, large fov = wide angle). Animatable.
The horizontal field of view follows from this and the output aspect ratio, so a wide frame sees much wider than this angle – see the
Cameraclass docstring.- Parameters:
fov – Vertical field of view in degrees, in (0, 180).