Expand description
Optional presentation-only intro/result rails, sampled at caller-owned seconds.
Cubics use polynomial parameter time, not arc length. Routes use their
measured polyline arc length (including a closed route’s seam). Convert a
curve with tessellate_route_into for approximate constant-distance travel;
an incomplete tessellation never replaces the last good route. Neither path
aims the camera along its tangent: orientation, roll, view distance and FOV
come from authored RailKey3 poses through the existing Transition3.
Segments prepare one normalized transition at construction. Each query samples
a copy once; it never retargets a live transition or steps hidden simulation.
Time is finite, nonnegative f64 seconds since this rail’s start. Seeking is allowed, including backward and across many loops. Boundaries are right continuous: all zero-duration cuts at a boundary apply before the following segment starts. Once mode clamps at the exact final key; loop mode wraps at the exact duration, reporting an absolute cycle number. These are observations, not queued events or evidence of gameplay completion. Reduced motion always returns the exact final key as a finished cut, even for loops and held players.
A raw sample reports cuts at start, exact authored cut boundaries and loop
seams. RailPlayer3 additionally marks backward seeks, crossed cuts/loops,
initialization and reset as discontinuities. Hold retains the displayed sample;
the host must freeze/rebase its own playhead before resume (no automatic clock
offset). Reset forgets the pose/hold; the next query initializes at supplied
time. Renderer interpolation/history must honor cuts. Subject history,
collisions, accepted teleports, lens matrices and look-input tuning stay host
owned. Local menus must continue authoritative network/replay progression.
Storage/work: at most 64 borrowed segments, 1024 batch samples, 4096 route points and 8191 tessellation work nodes. Queries allocate nothing. Orientation fraction rounds to f32 (as in Transition3); position uses f64 path progress. Pose/lens bounds and shortest-arc half-turn ties are Transition3’s conventions. Intermediate target rounding can still fail; errors preserve player state and the entire batch destination. A valid endpoint pair is not a guarantee of all interior samples. Loop counts >= 2^53 are rejected rather than cast/saturated; f64 time’s existing loss of fractional precision cannot be recovered. Loop phase uses remainder of the supplied binary seconds, without epsilon snapping to decimal boundaries (for example, 1 second is just under ten stored 0.1s durations). Cycle counting follows that same remainder convention.
§Executable optional intro/result recipe
The host chooses this optional view without changing game defaults or ticks. This headless recipe exercises real authoring, sampling, hold, restart and an accepted Rig3 teleport handoff. No wall clock, renderer or subject mutation.
use ferravex_math::{Vec3, curves::{CubicBezier3, TessellationOptions}, projection::NdcDepth};
use ferravex_play::{navigation::Route3, camera::{Pose3, Rig3, Input3, Mode3,
Target3, NoObstructions, transition::{Perspective3, Transition3, ViewHandedness}, rail::*}};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let lens = Perspective3 { aspect: 16./9., near: 0.1, far: 1000.,
handedness: ViewHandedness::Right, depth: NdcDepth::ZeroToOne };
let key = |x| RailKey3 { pose: Pose3 { position: Vec3::X*x,
target: Vec3::X*x - Vec3::Z*4., ..Pose3::default() }, projection: lens };
let curve = CubicBezier3::new([Vec3::ZERO, Vec3::Y, Vec3::X*4.+Vec3::Y, Vec3::X*4.])?;
let mut route = Route3::new(128).map_err(RailError::Route)?;
let mut scratch = [Vec3::ZERO; 128];
tessellate_route_into(curve, &mut route, &mut scratch, TessellationOptions {
tolerance: 0.01, max_depth: 16, max_work: 1023 })?;
let segments = [RailSegment3::new(RailPath3::Route(&route), key(0.), key(4.), 2.)?];
let rail = Rail3::new(&segments, RailMode::Once)?;
let mut intro = RailPlayer3::new(rail);
assert!(intro.sample_at(0., false)?.cut);
let visible = intro.sample_at(0.5, false)?;
intro.hold();
assert_eq!(intro.sample_at(90., false)?, visible);
intro.resume(); // The host discarded paused time, retaining playhead 0.5.
assert_eq!(intro.sample_at(0.5, false)?.pose, visible.pose);
assert!(intro.sample_at(2., false)?.finished);
intro.reset(); // Restart also resets host simulation/subject history.
assert_eq!(intro.displayed(), None);
assert!(intro.sample_at(0., false)?.cut);
intro.hold();
let result = intro.sample_at(0.2, true)?; // Motion preference overrides hold.
assert!(result.cut && result.finished);
assert_eq!(result.pose, key(4.).pose);
// The host has accepted a teleport and reset its subject history first.
let mut rig = Rig3::default();
let accepted = rig.snap(Input3 { target: Target3::at(Vec3::X*100.),
mode: Mode3::Follow { eye_offset: Vec3::Z*5., look_offset: Vec3::ZERO },
fov_y: 1. }, &NoObstructions)?;
let mut live = Transition3::new();
live.cut(result.pose, result.projection)?;
live.retarget_frame(&accepted, lens, 1.)?;
assert_eq!(live.pose(), Some(accepted.pose));
Ok(())
}Structs§
- Rail3
- Bounded immutable timeline over caller-owned prepared segments.
- Rail
Key3 - Authored world-space look pose and explicit host projection intent. See module recipe. Existing public camera literals/defaults are unchanged.
- Rail
Player3 - Optional retained display/hold/discontinuity adapter over a fixed rail. No clock, accumulator or simulation ownership. See executable module recipe.
- Rail
Sample3 - A presentation observation; never an obstruction-tested camera frame.
cycleis an absolute loop count, not a count of events since the last call.loopeddenotes an exact loop seam for raw queries, or any crossed loop for a player.cutrequests renderer history discard. See module time semantics. - Rail
Segment3 - Immutable prepared segment. Borrowed routes cannot change during playback. See module recipe; construction allocates nothing, as do subsequent samples.
Enums§
- Rail
Error - Rejected authoring/query; no partial player or batch output is committed.
- Rail
Mode - Playback topology. Loop seams are explicit cuts, even if poses happen to match.
- Rail
Path3 - Position source; orientation is independent. See
RailSegment3::new.
Constants§
- MAX_
RAIL_ SAMPLES - Maximum times accepted by one atomic batch. See
Rail3::sample_into. - MAX_
RAIL_ SEGMENTS - Maximum authored segments, including zero-duration cuts. See module recipe.
- MAX_
RAIL_ TESSELLATION_ WORK - Maximum curve subdivision work accepted by
tessellate_route_into.
Functions§
- tessellate_
route_ into - Transactionally replace an open route only after a complete curve tessellation.