ToyFix Physics, Timelines, and Rendering

Physics, timelines, and rendering

Use physics to generate motion and signals. Interactive mode can generate them in response to the player. For a movie, capture a take so the editor and exporter can sample that same performance at any frame. Keep the renderer focused on evaluating the camera, poses, materials, and shader time for the requested sample.

ToyFix today

ToyFix already runs rigid bodies in Interactive mode through qu3e, ReactPhysics3D, or Bullet3. The common rigid-body loop advances at 60 Hz. Flooded Relay Station samples two keyed materials from a live Bullet3 hinge angle. The zombie labs can bake a fall into a skeletal clip with Enter. Lesson 5 captures rigid-body poses and evaluated material properties. Today export evaluates the authored timeline and placed recorded takes.

Physics for renderers

Think of a physics body as a pose plus velocities, mass and inertia. A collider is the geometry used to find contacts. A stair tread can use a box collider and a character can use a handful of capsules while retaining a detailed render mesh. The engine first finds pairs likely to touch, computes contacts for those pairs, then solves contacts and joints to update motion. A sleeping body has settled enough for the engine to skip much of its work until something wakes it.

ConceptToyFix example
Static bodyThe stair treads or station floor. They provide collision surfaces.
Dynamic bodyA canister or counterweight. The solver owns its motion while simulation is active.
Kinematic bodyA proposed timeline-driven elevator platform. The timeline supplies its target pose each tick, and moving contacts can push dynamic bodies.
JointThe relay floodgate hinge constrains motion to a single rotation axis.
SensorThe letter-office delivery detector reports overlaps without applying a collision response.
Continuous collision detection (CCD)The fast cyan capsule detects the thin flap between discrete samples. Use this selectively for small, fast bodies and thin obstacles.

A one-off kick is an impulse. A motor or gravity acts over time. Restitution controls bounce, friction resists sliding, and inertia determines how readily a body rotates. Start by checking collider shape, size, mass ratios, and timestep when a setup behaves strangely. In Last Train, run both tracks before changing settings so you have a side-by-side baseline. ReactPhysics3D user documentation.

Interactive mode

Real time gives you irregular wall-clock intervals. Accumulate that elapsed time and spend it in fixed simulation ticks. Draw at the display cadence. If the simulation has trouble keeping up, bound its work per display frame. ToyFix currently caps the elapsed time fed to the common rigid-body loop after a stall, so a long stall can slow simulation relative to the wall clock. For movie capture, use controlled ticks and advance every tick.

mouse press → queue impulse for a physics tick
physics tick → apply inputs → step world → collect contacts → store poses and signals
display      → sample poses and signals → render camera image → optional postprocess

Keep the previous and current physics snapshots. For a smoother preview, interpolate position and use quaternion interpolation for rotation. Interpolating both poses and material signals with the same fraction keeps the gate and water color synchronized. This display technique usually adds up to about one simulation tick of latency. Picking should use the displayed pose. A physics ray query can still report the current collision state if the interface clearly distinguishes the two. ReactPhysics3D time-stepping and interpolation guide.

Treat contact starts, contact ends, and sensor crossings as discrete events. A trigger should fire once when an overlap begins, even if four simulation ticks run before the next redraw or several redraws occur between ticks. Continuous values such as hinge angles can simply be sampled. Keep any authored shader time policy explicit. For a live installation it might advance with the run, while an edited shot uses the scene timeline.

Who owns each pose?

Give each transform a single writer at a given time. This prevents animation from teleporting a body back onto its track after the solver has moved it.

PhaseWriterExample
Before handoffAuthored trackA walking zombie or a platform rising toward a canister.
During a live takePhysics for dynamic bodies, timeline for kinematic targetsThe zombie falls while a separately authored camera move continues.
After bakingRecorded take over its intervalScrub directly to impact while still editing the camera cut and exposure.

For an animated-to-dynamic handoff, initialize the body from the evaluated pose and estimate linear and angular velocities from nearby animation samples. A moving body should carry its momentum into the solver. For a first general bake, use root-level rigid bodies, matching ToyFix’s current collider rules. Store translation and quaternion rotation in the captured take. If support expands to parented bodies later, convert the world-space physics pose to local space against the evaluated parent at the same sample time.

Give a take an explicit start and end. During that interval, let it override the affected transform or property tracks. Outside it, use the authored tracks. At the final sample, decide whether the shot needs a hold or a handoff back to animation. Flag a take as stale when a relevant collider, initial pose, or recorded input changes. Camera edits and render-only effects should leave the take usable.

Capture a take, then render it

  1. Record a rehearsal. Enter Interactive mode at a chosen playhead position. Press Shift+F5 to request recording on entry. Store each simulation tick’s body poses, any required signal values, and tick-stamped cues.
  2. Bake a timeline interval. Use the ragdoll bake as the interaction precedent. Initially save samples at the simulation cadence so a fast contact survives a 24 fps export. Keep the stored data in the scene bundle and give the user a clear way to remove or replace the take.
  3. Scrub the result. The main timeline reads the captured samples directly. Jumping backward should give the same view as playing forward to that frame. Compare the rendered result against the live take at a few visible milestones.
  4. Export with Shift+F12. At each output frame evaluate the camera cut, the baked poses, the material values, and scene shader time. Apply the project’s postprocess to the finished image and encode the result. Keep the filename and MP4 pipeline already used by ToyFix.

For a scene that starts at frame 1, frame 2 at 24 fps is 1/24 s after frame 1. At 60 simulation ticks per second that falls at tick 2.5, so interpolate ticks 2 and 3. Frame 3 lands on tick 5. Recording every tick preserves the information needed to resample at other rates. It also leaves room for motion blur later, where several shutter samples can read the same take. Keep cuts and one-shot events discrete even when the pose between ticks is interpolated.

A second useful workflow is an offline bake of authored cues. Put a release or impulse on a timeline frame, restart from a defined simulation origin, and step forward as fast as the engine allows. This gives repeatable shot staging without requiring a live mouse performance. Start from the same state each time and record the backend and tick rate. A fixed timestep helps repeatability, and a saved take preserves the actual results across engine or platform changes. If export starts midway through a shot, sample the existing take or pre-roll the offline simulation from its origin. Bullet stepping interface.

Physics-driven shaders

Use a small set of artist-facing signals. A hinge angle, distance between contacts, or speed is a continuous input. A sensor crossing or impact is an event. Interpret them in scene data and continue using ordinary material uniforms in GLSL. The renderer needs the evaluated value and the sample time.

LabMechanicVisible result
Flooded Relay StationMap the gate angle from −4° to −49° onto clip-local frames 0 to 48. Clamp outside that range.The window clouds and the caustics broaden. A rebound reverses the blend.
Last TrainMeasure spring-stop compression, or record one contact event and play a decay envelope.Show the rubber and steel stops with distinct lengths of route-display flicker.
Dead Letter OfficeSeparate flap impact from downstream sensor entry.Flash the dispatch ring on contact and light the receipt lamp only on delivery.
Notebook StairsBake the existing ragdoll, then cut from the top landing to a low camera near the final step.Review the same fall from both cameras with a consistent paper treatment.

Lesson 5 records the evaluated properties at each output frame. Recolor the source response to change a future run. A placed take retains its captured uniform values through scrubbing and export.

Suggested development order

  1. Finish Flooded Relay as a movie take. Record gate, weight, and canister poses with the shared material sample. Bake using the existing Enter convention, scrub through the release, save and reopen, then export a short MP4. Keep timing and body ownership clear before adding more signals.
  2. Add one authored physics cue. Schedule the counterweight release on the main timeline. Verify that scrubbing across the cue has no side effects, and that baking from the beginning executes it once.
  3. Add one kinematic collider. Animate a lift or moving platform through the existing transform tracks. Feed its pose to physics each tick and verify that a dynamic canister rides it and inherits motion on departure.
  4. Extend only where a shot needs it. The two stop surfaces motivate an impact-driven material envelope. The relay motivates continuous signals. A future close-up might justify motion blur. These can share the same take and sampling model.

For the first prototype, verify that a recorded take survives save and reopen, repeated seeks produce the same evaluated poses and material values, export from a later start frame matches the same frame in a full export, and camera or shader edits leave the captured motion intact. Measure CPU physics time and GPU render time separately with live postprocessing off and on. A costly screen shader and a solver that needs more substeps call for different fixes.

Technical reading