Adds one or more 3D people to an existing rayshader scene. The
bundled person models use meter-based coordinates and are scaled using the
scene's effective zscale, including vertical_exaggeration, so that their
native 1.8-meter standing stature remains correctly sized relative to the terrain.
Choose from several bundled poses with pose and select the model variant
with sex. The bundled Wavefront OBJ models use .txt file extensions
for R package compatibility.
When line is supplied, or location contains line geometry, people are
placed along each line component at regular intervals. Their local +Z axes
follow the direction of the line. Use line_pattern to repeat male and female
variants along the sampled positions.
Cache fallback messages are disabled by default. Set
options(rayshader.verbose_scene_cache = TRUE) to print when cached metadata
is reused.
render_people(
location = NULL,
pose = "standing",
sex = "male",
line = NULL,
line_spacing = 2,
line_terrain_spacing = TRUE,
line_pattern = NULL,
line_align_terrain = TRUE,
color = "white",
angle = c(0, 0, 0),
lit = TRUE,
load_normals = TRUE,
clear_previous = FALSE,
x = NULL,
y = NULL,
altitude = NULL,
xyz = NULL,
offset = 0,
lat = NULL,
long = NULL,
crs = NULL,
filter_to_extent = TRUE,
extent = NULL,
panel = NULL,
zscale = 1,
vertical_exaggeration = 1,
heightmap = NULL,
simple_rgl = FALSE,
...
)Default NULL. Spatial input used to place people in the
scene. Accepts sf, sfc, sfg, or sp POINT, MULTIPOINT, LINESTRING, or
MULTILINESTRING geometries. Point inputs place one model at every point. Line
inputs generate placements according to line_spacing. If the input carries a
CRS, it is transformed automatically into the active scene CRS. If it has no
CRS, supply crs.
Default "standing". Bundled pose to render. Supply one value
for every person or a single value to use for all people. Options are
"clapping", "ironman", "slipping", "stack", "standing", "stop",
"stop_one_hand", "stretch", "walking", "rocky", and "yelling".
Default "male". Person model variant. Options are "male"
and "female".
Default NULL. Spatial line input along which to place people.
Accepts sf, sfc, sfg, or sp LINESTRING or MULTILINESTRING geometry.
Line geometry may alternatively be supplied through location.
Default 2. Distance in meters between people placed along a
spatial line. For CRS-less lines, this is interpreted in the line's coordinate
units. Sampling starts at the beginning of every line component.
Default TRUE. If TRUE, line spacing is measured
along the rendered terrain surface using the heightmap and effective zscale.
This keeps neighboring models together on slopes. If terrain metadata is not
available, spacing falls back to plan-view distance. Set to FALSE to always
use plan-view distance.
Default NULL. Repeating male/female line_pattern used for line
placement. Supply a single string containing M and F, such as "MF" or
"FMF". Overrides sex for line placements.
Default TRUE. If TRUE, line placements are tilted
so each person's local +Y up vector matches the terrain normal. The local +Z
forward vector is lifted along the terrain without changing its plan-view
alignment with the line direction.
Default "white". Color of the person model. For line
placement, supply one color per generated person or one color per entry in
line_pattern; pattern colors are repeated with the pattern. Use "height" to
color placed models by the cached plot_gg() height aesthetic palette.
Default c(0, 0, 0). Rotation around the x, y, and z axes. A
matrix or list can specify a separate rotation for each person. For line
placement, these rotations are added to the automatic line orientation.
Default TRUE. Whether to light the model polygons.
Default TRUE. Whether to load normals from the model.
Default FALSE. If TRUE, remove previously rendered
people before rendering the new ones. A clear-only call returns without
rendering a replacement.
Default NULL. Vector of x coordinates (or coordinates in the same
coordinate reference system as extent).
Default NULL. Vector of y coordinates (or coordinates in the same
coordinate reference system as extent).
Default NULL. Elevation of each person, in units of the
elevation matrix. If left NULL, each person is placed on the surface plus
offset. A single value places every person at that altitude. When one
horizontal location is supplied with multiple altitude values, that location
is repeated to place one person at each altitude.
Default NULL. A three-column numeric matrix in which each row
specifies the raw rgl x/y/z coordinates of a person. Overrides coordinate
placement and altitude.
Default 0. Offset from the surface when altitude = NULL.
Default NULL. Alias for y for geographic workflows.
Default NULL. Alias for x for geographic workflows.
Default NULL. CRS of numeric x/y coordinates, or a CRS to assign
to CRS-less spatial data before transforming it into the active scene CRS.
Default TRUE. If TRUE, placements outside the
scene extent are omitted.
Default NULL. Either an object representing the spatial
extent of the scene (from the raster, terra, sf, or sp packages), a
length-4 numeric vector specifying c("xmin", "xmax", "ymin", "ymax"), or a
spatial object that can be converted to an extent. If omitted, rayshader uses
extent metadata cached by plot_3d() or plot_gg().
Default NULL. Facet panel identifier for scenes created with
plot_gg(). Required to disambiguate faceted ggplot scenes when
panel-specific cached metadata is needed. Ignored for non-ggplot scenes.
Default 1. Ratio between horizontal spacing and the elevation
units in the original heightmap. If omitted, rayshader uses the cached scene
value when available.
Default 1. Multiplier applied to the effective
visual relief. If omitted, rayshader uses the cached scene value from
plot_3d() or plot_gg() when available; pass explicitly to override it for
this call.
Default NULL. Height matrix for the current scene. If
omitted, rayshader uses the cached scene heightmap from plot_3d() or
plot_gg(). Terrain elevations and existing NA cells are read directly
from this matrix.
Default FALSE. Show one colored point per person in rgl
instead of expanding the person meshes. render_highquality() replaces these
points with full instances grouped by model and material. Use this for large
crowds; positions, poses, colors, and rotations are retained.
Additional arguments passed to render_obj() and then to
rgl::triangles3d().
# Example 1
# Build a stepped pose gallery.
flat_heightmap = matrix(1:16 / 2, nrow = 4, byrow = TRUE) |>
rayimage::render_reorient(flipy = TRUE, transpose = TRUE) |>
rayimage::render_resized(mag = 50, method = "box")
scene_zscale = 1 / 25
flat_heightmap |>
constant_shade("#800") |>
plot_3d(
heightmap = flat_heightmap,
zscale = scene_zscale,
vertical_exaggeration = 1,
shadow_depth = 0,
solid_depth = 0,
solid_color = "#800",
window_size = c(800, 800)
)
render_camera(
theta = -28,
phi = 16,
zoom = 0.70,
fov = 0,
shift_vertical = -10
)
# Place every pose on the podium. The ironman model is raised to
# clear its step, and the tenth person will support a second stack model.
# These x/y values use the raw matrix's cached 1-based extent.
gallery_positions = expand.grid(
x = seq(25, 175, by = 50),
y = seq(25, 125, by = 50)
)
gallery_poses = c(
"standing",
"walking",
"stop",
"stop_one_hand",
"clapping",
"yelling",
"stretch",
"slipping",
"stack",
"stack",
"ironman",
"rocky"
)
gallery_positions$offset = 0
gallery_positions$offset[gallery_poses == "ironman"] = 1
stack_index = 10L
stack_position = gallery_positions[stack_index, , drop = FALSE]
person_height = 2
label_clearance = 0.1
# Render and label male pose gallery
render_people(
pose = gallery_poses,
sex = "male",
clear_previous = TRUE,
x = gallery_positions$x,
y = gallery_positions$y,
offset = gallery_positions$offset
)
render_people(
pose = "stack",
sex = "male",
x = stack_position$x,
y = stack_position$y,
offset = stack_position$offset + person_height
)
# Label the standalone models first, then label the completed tower above
# its upper person without relying on negative indexing.
regular_label_indices = setdiff(seq_along(gallery_poses), stack_index)
render_label(
text = gallery_poses[regular_label_indices],
font = "Helvetica",
family = "serif",
font_type = "standard",
text_color = "white",
line = FALSE,
clear_previous = TRUE,
x = gallery_positions$x[regular_label_indices],
y = gallery_positions$y[regular_label_indices],
altitude = gallery_positions$offset[regular_label_indices] +
person_height + label_clearance,
relative_z = TRUE
)
render_label(
text = "stack",
font = "Helvetica",
family = "serif",
font_type = "standard",
text_color = "white",
line = FALSE,
x = stack_position$x,
y = stack_position$y,
altitude = stack_position$offset + 2 * person_height + label_clearance,
relative_z = TRUE
)
# Produce an 800-by-800 high-quality image of the male pose variants.
render_highquality(
width = 800,
height = 800,
sky_sun_elevation = 10,
sky_sun_azimuth = 160,
iso = 5,
samples=16
)
# Female models
render_people(
pose = gallery_poses,
sex = "female",
clear_previous = TRUE,
x = gallery_positions$x,
y = gallery_positions$y,
offset = gallery_positions$offset
)
render_people(
pose = "stack",
sex = "female",
x = stack_position$x,
y = stack_position$y,
offset = stack_position$offset + person_height
)
render_highquality(
width = 800,
height = 800,
sky_sun_elevation = 10,
sky_sun_azimuth = 160,
iso = 5,
samples=16
)
# Example 2
# Show the scale of the "volcano" 3D dataset
volcano_dem = volcano_spatial()
volcano_dem |>
height_shade() |>
plot_3d(
window_size = c(800, 800)
)
render_trails(
volcano_trails,
color = "grey50",
width = 2,
preview = "mesh",
width_units = "meters"
)
summit_walk = volcano_trails[
!is.na(volcano_trails$name) &
volcano_trails$name == "Puhi Huia Road",
]
render_snapshot()
render_people(
line = summit_walk,
pose = "walking",
line_spacing = 5,
offset=0.2,
line_pattern = "MF",
color = c("#F6E8C3", "white"),
clear_previous = TRUE
)
render_camera(theta = -36, phi = 15, zoom = 0.08, fov=100)
render_snapshot()
# Example 3
# Arrange alternating models around a closed line. Models orient themselves
# according to the local normal and orient the people along the line
bump_heightmap = rayimage::generate_2d_gaussian(dim = c(30,30)) * 1000
bump_heightmap |>
height_shade() |>
plot_3d()
circle_r = function(x) {
theta = seq(0, 2 * pi, length.out = 200)
sf::st_linestring(cbind(
15.5 + x * cos(theta),
15.5 + x * sin(theta)
))
}
people_line = sf::st_sfc(
circle_r(12.5),
circle_r(10.5),
circle_r(8.5),
circle_r(6.5),
circle_r(4.5),
circle_r(2.5)
)
render_people(
line = people_line,
pose = "stretch",
line_pattern = "MF",
line_spacing = 2,
color = c("dodgerblue", "tomato"),
)
render_people(
x = c(13.5, 15.5, 17.5),
y = rep(15.5, 3),
offset = c(2,0,2),
angle = list(c(30,45,0),c(0,0,0),c(30,-45,0)),
pose = c("ironman", "rocky", "ironman"),
color = "white"
)
render_camera(location = c(15.5,15.5), theta = 0, phi = 10,zoom=0.2,fov=80)
render_highquality(light_direction = 225,samples=16)