| camera_auto | R Documentation |
Computes a camera position that frames the entire mesh in view. The camera looks along the given direction, positioned at a distance that ensures the mesh fits within the field of view.
camera_auto(
mesh,
direction = c(0, 0, -1),
up = c(0, 1, 0),
fov = 45,
margin = 1.1,
rgl_compat = FALSE,
projection = c("perspective", "orthographic")
)
mesh |
Either an Nx3 numeric matrix of vertex positions, or a
mesh descriptor list with a |
direction |
The view direction as a length-3 vector. For
example, |
up |
The up vector as a length-3 vector. Default |
fov |
Field of view in degrees. Default 45° (30° when
|
margin |
Extra margin factor (1.0 = tight fit, 1.1 = 10% margin). |
rgl_compat |
Logical. If |
projection |
Projection type: |
When rgl_compat = TRUE, the camera mimics rgl's default
auto-framing behaviour: a 30° FOV, 15° elevation, and the distance
is computed from the bounding sphere of the mesh (the
half-diagonal of the axis-aligned bounding box), reproducing the
formula distance = sphere_radius / sin(FOV/2) used by rgl.
A camera list, with S3 class "scimesh_camera".
verts <- matrix(c(-1,-1,-1, 1,-1,-1, 1,1,-1, -1,1,-1,
-1,-1, 1, 1,-1, 1, 1,1, 1, -1,1, 1), ncol = 3, byrow = TRUE)
tris <- matrix(c(0L,3L,2L, 0L,2L,1L, 4L,5L,6L, 4L,6L,7L,
0L,1L,5L, 0L,5L,4L, 2L,3L,7L, 2L,7L,6L,
0L,4L,7L, 0L,7L,3L, 1L,2L,6L, 1L,6L,5L), ncol = 3, byrow = TRUE)
mesh <- list(vertices = verts, triangles = tris)
cam <- camera_auto(mesh, direction = c(1, 1, 1))
cam_rgl <- camera_auto(mesh, rgl_compat = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.