An animated model combines reusable geometry with an internal animation, such as a robot arm reaching or a bird flapping. Its placement in the scene is independent: two copies can follow different paths and play the same clip at different speeds.
This workflow builds an articulated inspection robot from rayrender primitives. It uses all five model functions, queries poses without rendering, and renders two independently animated copies. The five supplied images were rendered with rayrender; the code that generates them is included below. Building this vignette evaluates the model and pose examples but uses the supplied images.
| Function | What you supply | What you get |
|---|---|---|
animation_model_node() |
A part, its parent ID, and rest transform | One part of the hierarchy |
animation_model_clip() |
Named animation tracks targeting node IDs | A reusable internal motion |
animation_model_asset() |
The nodes and clips | A shared model definition |
animation_model_instance() |
An asset, outer path, and clip player | A scene object with its own placement and clock |
animation_model_pose() |
An instance and scene times | Evaluated transforms and morph weights for inspection |
These functions serve different workflows. Importing a GLB constructs
its asset, nodes, and clips for you; the last section shows that shorter
route. The unprefixed model_*() names have been removed.
Use animation_model_*().
Our robot has a base, an upper arm, a forearm, and a gripper. Each moving part is authored with its joint at its local origin. Its geometry extends along local positive Y. This lets a rotation bend the part around the joint, instead of spinning around the center of its geometry.
# Build each part in its own coordinates, with its joint at the origin.
blue = diffuse("#287F94")
orange = diffuse("#E6A045")
dark = diffuse("#263745")
base_geometry = cylinder(
y = .10,
radius = .43,
length = .20,
material = dark
) |>
add_object(cylinder(y = .23, radius = .29, length = .10, material = blue))
upper_geometry = sphere(radius = .15, material = orange) |>
add_object(cube(
y = .45,
xwidth = .17,
ywidth = .90,
zwidth = .22,
material = blue
))
forearm_geometry = sphere(radius = .14, material = dark) |>
add_object(cube(
y = .40,
xwidth = .14,
ywidth = .80,
zwidth = .19,
material = orange
))
gripper_geometry = sphere(radius = .12, material = dark) |>
add_object(cube(
y = .17,
xwidth = .46,
ywidth = .12,
zwidth = .19,
material = blue
)) |>
add_object(cube(
x = -.20,
y = .33,
xwidth = .08,
ywidth = .30,
zwidth = .13,
material = dark
)) |>
add_object(cube(
x = .20,
y = .33,
xwidth = .08,
ywidth = .30,
zwidth = .13,
material = dark
))animation_model_node() gives a part a stable ID and
attaches it to a parent. The upper arm starts 0.32 units above the base.
The forearm starts at the upper arm’s endpoint, 0.90 units along its
local Y axis. The gripper similarly starts at the end of the
forearm.
base = animation_model_node("base", base_geometry)
upper = animation_model_node(
"upper",
upper_geometry,
parent = "base",
transform = animation_transform_track(
0,
position = c(0, .32, 0),
angle = c(0, 0, -25)
)
)
forearm = animation_model_node(
"forearm",
forearm_geometry,
parent = "upper",
transform = animation_transform_track(
0,
position = c(0, .90, 0),
angle = c(0, 0, 65)
)
)
gripper = animation_model_node(
"gripper",
gripper_geometry,
parent = "forearm",
transform = animation_transform_track(
0,
position = c(0, .80, 0),
angle = c(0, 0, -30)
)
)The hierarchy is
base -> upper -> forearm -> gripper. Moving the
upper arm carries its descendants along. Rotating the forearm leaves the
upper arm alone. The transform values above describe the
rest pose, before a clip is selected. Geometry’s own
static transforms remain inside these node transforms.
animation_model_clip() groups tracks into a named
motion. Each name in channels is a target node ID. The
example uses rotation tracks with different key schedules: the elbow
does not have to change direction at the same time as the shoulder.
Angles are in degrees; key times are seconds within the clip.
# Channels are named by node ID. These rotations replace the rest rotations;
# the absent position channels retain each joint's rest offset.
reach = animation_model_clip(
"reach",
channels = list(
upper = animation_transform_track(
c(0, .5, 1, 1.5, 2),
angle = rbind(
c(0, 0, -25),
c(0, 0, -55),
c(0, 0, -25),
c(0, 0, 15),
c(0, 0, -25)
),
rotation_interpolation = "smooth"
),
forearm = animation_transform_track(
c(0, .7, 1.3, 2),
angle = rbind(c(0, 0, 65), c(0, 0, 105), c(0, 0, 30), c(0, 0, 65)),
rotation_interpolation = "smooth"
),
gripper = animation_transform_track(
c(0, .4, 1, 1.6, 2),
angle = rbind(
c(0, 0, -30),
c(0, 45, -10),
c(0, 0, -30),
c(0, -45, -50),
c(0, 0, -30)
),
rotation_interpolation = "smooth"
)
),
name = "Reach and turn"
)An animated property replaces that node’s rest property. For example, the upper arm’s first animated rotation is -25 degrees, not an extra -25 degrees added to its rest rotation. Missing properties retain their rest values, so the joint offsets remain attached throughout the motion.
"smooth" interpolates rotations smoothly through
interior keys. The first and last poses here match, allowing repetition
without a position jump. Matching endpoint poses alone does not
guarantee matching velocity at the loop seam. All channels share the
complete clip’s two-second clock; shorter tracks would hold their
endpoint values until that clock wraps.
animation_model_asset() assembles and validates the
hierarchy and clip targets. The resulting asset holds the source
geometry, rest transforms, and animation data for reuse. It does not
itself place a robot in a scene.
robot = animation_model_asset(
nodes = list(base, upper, forearm, gripper),
clips = list(reach),
name = "Inspection robot"
)
animation_list_clips(robot)
#> id name start end duration targets
#> 1 reach Reach and turn 0 2 2 upper, forearm, gripperA default animation_model_instance(robot) uses the rest
pose. It does not automatically select the first available clip. Add a
floor, a light, and a scene camera to see the model before
animation.
# No selected clip means the authored rest pose, even when clips are available.
rest = animation_model_instance(robot)
studio = xz_rect(xwidth = 200, zwidth = 200, material = diffuse("#DDD7CC")) |>
add_object(sphere(
x = -3,
y = 6,
z = 4,
radius = 1.4,
material = light("#FFF3DF", intensity = 5)
))
rest_scene = add_object(studio, rest) |>
add_camera(
camera(
lookfrom = c(3.7, 2.9, 5),
lookat = c(0, 1.1, 0),
fov = 32,
aperture = 0
),
name = "rest"
)The authored rest pose. Blue and orange links meet at visible joints; the open gripper is a child of the forearm.
These outer paths use scene time, not clip time. Each has four keys and its own timing. Position uses cubic interpolation; orientation uses smooth rotation interpolation. The bases slide and turn on the floor without changing the joint animation.
# Both bases stay on the floor. Paths use scene seconds, independently of clips.
left_path = animation_transform_track(
c(0, 1.2, 2.8, 4),
position = rbind(
c(-1.4, 0, .2),
c(-1.7, 0, -.5),
c(-.9, 0, -.7),
c(-1.4, 0, .2)
),
angle = rbind(c(0, -15, 0), c(0, 25, 0), c(0, 50, 0), c(0, -15, 0)),
position_interpolation = "cubic",
rotation_interpolation = "smooth"
)
right_path = animation_transform_track(
c(0, .8, 2.4, 4),
position = rbind(c(1.4, 0, -.3), c(1.7, 0, .3), c(.9, 0, .5), c(1.4, 0, -.3)),
angle = rbind(c(0, -35, 0), c(0, -5, 0), c(0, 25, 0), c(0, -35, 0)),
position_interpolation = "cubic",
rotation_interpolation = "smooth"
)Both instances reference robot. The left robot plays
"reach" at normal speed. The right starts 0.7 seconds into
that clip and plays at half speed. loop = "repeat" repeats
the internal clip; it does not wrap either outer path.
left_robot = animation_model_instance(
robot,
transform = left_path,
animation = animation_clip_player("reach", loop = "repeat")
)
right_robot = animation_model_instance(
robot,
transform = right_path,
animation = animation_clip_player(
"reach",
offset = .7,
speed = .5,
loop = "repeat"
)
)
scene = add_object(studio, left_robot) |>
add_object(right_robot) |>
add_camera(
camera(
lookfrom = c(3.7, 3.2, 7),
lookat = c(0, 1, 0),
fov = 31,
aperture = 0
),
name = "pair"
)Conceptually, each part’s world transform is:
outer placement(scene time) * parent transforms(clip time) * local pose(clip time)
Sharing an asset shares the model definition, not the instances’
playback state. Each instance can be placed, phased, or reversed
independently. For a reversed clip, use a negative player
speed and an explicit offset selecting where
to start. A player speed of zero freezes its internal pose while its
outer path can continue moving.
animation_model_pose() evaluates an instance at the
supplied scene times in any order. At scene time 1, the left robot uses
clip time 1; the right uses 0.5 * 1 + 0.7 = 1.2 seconds.
Seeking backward does not accumulate transforms.
# Query forward, backward, and again. Compare pose values, not change flags.
requested_times = c(1.5, .25, 1.5)
poses = animation_model_pose(left_robot, requested_times)
stopifnot(identical(poses[[1]]$world, poses[[3]]$world))
left_pose = animation_model_pose(left_robot, 1)[[1]]
right_pose = animation_model_pose(right_robot, 1)[[1]]
data.frame(
instance = c("left", "right"),
scene_time = 1,
clip_time = c(left_pose$clip_time, right_pose$clip_time)
)
#> instance scene_time clip_time
#> 1 left 1 1.0
#> 2 right 1 1.2
# The translation column gives the gripper origin in world coordinates.
left_pose$world$gripper[1:3, 4]
#> [1] -1.8478712 1.7233226 -0.3565673Each result contains:
local: node transforms relative to their parents.global: composed node transforms in asset coordinates,
excluding placement.world: composed transforms including the instance’s
outer placement.clip_time and weights: the selected local
time and any morph weights.placement_changed and pose_changed: change
flags relative to the previous requested result, useful for
diagnostics.The flags can depend on query order; the evaluated matrices do not.
This is an inspection function: it does not return a
static scene or baked mesh. Use render_scene(time = ...) to
render a snapshot directly.
The snapshot figures use a fixed camera, explicit scene times, CPU
path tracing, and a zero-width shutter. Run these chunks from the
vignettes directory to regenerate the supplied images. No
Blender installation, downloaded asset, or Metal GPU is required.
# Fixed settings make the supplied figures reproducible on the CPU renderer.
render_settings = list(
width = 720,
height = 480,
samples = 128,
sample_method = "sobol",
min_variance = 0,
max_depth = 12,
ambient_light = TRUE,
backgroundhigh = "#C7D9E8",
backgroundlow = "#E5E1D9",
preview = FALSE,
progress = FALSE,
plot_scene = FALSE,
denoise = FALSE,
bloom = FALSE,
tonemap = "raw",
integrator_type = "nee",
shutter_offsets = c(0, 0)
)set.seed(20261018)
rest_image = do.call(
render_scene,
c(
list(scene = rest_scene, time = 0),
render_settings
)
)
rayimage::ray_write_image(rest_image, "figures/model-animation/rest.png")render_animation() takes the same scene and a vector of
requested times. The camera stored in the scene stays still. The
returned images are in the order of times, which may also
be nonmonotonic.
# One scene, four requested times, one static scene camera.
frame_times = c(0, .5, 1, 1.5)
set.seed(20261018)
frames = do.call(
render_animation,
c(
list(scene = scene, times = frame_times),
render_settings
)
)
for (i in seq_along(frames)) {
rayimage::ray_write_image(
frames[[i]],
sprintf("figures/model-animation/pair-%02d.png", i)
)
}Scene times 0, 0.5, 1, and 1.5 seconds, in reading order. Each copy has its own base path and internal phase; the source asset is shared.
For a regular animation at 24 frames per second over four seconds,
replace frame_times with (0:95) / 24. Setting
output cadence does not change the clip’s speed. A different ordering of
those same times changes the output ordering, not the poses evaluated at
each time.
With shutter_offsets = c(0, 0), each image is an
exact-time snapshot. A nonzero interval now integrates the full pose,
including articulated nodes, skinning and morphs. Each image sample
evaluates the complete scene at one shutter time and accumulates linear
radiance before denoising and tone mapping. Existing mesh buffers and
BVH topology are retained; changing poses tight-refit the bounds. The
total ray budget remains samples. More samples improve
temporal smoothness, and adaptive stopping is disabled for full-pose
exposures. To retain the old frame-frozen internal pose, select
animation_motion_blur = "placement".
For a centered 1/8-second exposure on the CPU:
render_animation(scene, times = (0:47) / 12, fps = 12,
width = 360, height = 240,
samples = 64, integrator_type = "nee",
shutter_offsets = c(-1, 1) / 16,
animation_motion_blur = "full")The checkout’s
dev/animation/render-native-full-pose-blur.R produces a
complete 48-frame CPU video using these settings (or a half-second
exposure when requested).
This 360 by 240 CPU preview uses 64 samples and a 1/8-second exposure; the articulated links blur along with their independent outer paths.
On a system with an interactive display, this opens the existing timeline UI. Seek in either direction, play forward or backward, and adjust playback speed. Pausing lets the selected time accumulate more samples.
When a model is already authored in Blender or another tool, the
importer constructs the nodes, clips, and asset. You only need to select
a clip and create instances. This optional example requires your own
walk.glb file:
walker = animation_read_gltf("walk.glb")
clips = animation_list_clips(walker)
clips
# Select the desired row's stable ID after inspecting the available clips.
walker_instance = animation_model_instance(
walker,
transform = left_path,
animation = animation_clip_player(clips$id[1], loop = "repeat")
)
animation_model_pose(walker_instance, c(1, .25, 1))Use the node, clip, and asset constructors when authoring articulated models in R. Use the importer when those structures already exist in a file. Both routes produce assets for the same instance, pose, preview, and rendering interfaces.
From the repository root, with this version of rayrender installed:
setwd("vignettes")
dir.create("figures/model-animation", recursive = TRUE, showWarnings = FALSE)
source("scripts/model-animation.R")
rmarkdown::render("model-animation.Rmd")The script contains the same named chunks displayed here. Figure generation does real path tracing; ordinary vignette builds reuse the PNG files and do not launch rendering or a preview window.