Chapter 4 · Recipes
4.15Simulate
-- simulate garment g up to frame f, one frame at a time from the first frame of the range, as playing does
global tpaSimTo
fn tpaSimTo g f = (
local n = 0
for t = (animationRange.start.frame as integer) to f do n = TnpixTool.sim g t
sliderTime = (f as time)
n -- how many frames are stored
)
-- tpaSimTo $Shirt 30 then capture; tpaSimTo $Shirt 60, capture again
- What
simdoes.TnpixTool.sim node frameevaluates the cloth up to a frame, as scrubbing does, for the node's whole Solver group. Frames already stored are read back from memory. - Frame by frame for Preserve. With a Tnpix Preserve, go frame by frame as above, so every frame follows the animation exactly.
- No Reset needed after a change. Any change to a simulation setting simulates again from the first frame. To simulate again without changing anything,
TnpixTool.reset()clears the stored frames, as Reset Simulation does. Ask first: it throws away what is in memory. - The demo simulates only the first 100 frames, and nothing at all while the simulating garments together have more than 25,000 vertices. Colliders do not count.
The start shape. A garment starts as modelled unless its Solver group has a start shape: a drape made with Live at frame 0, or a frame kept from a played simulation. A start shape never changes the fabric's pattern. Changing the start shape needs the artist's yes.
TnpixTool.live $Shirt "start" 8 -- Live in Fast preview; clears the simulated frames
for i = 1 to 30 do TnpixTool.live $Shirt "step" 1 -- the garments drape at frame 0
TnpixTool.live $Shirt "info" 0 -- show the drape: capture it
TnpixTool.live $Shirt "keep" 0 -- with the artist's yes: the drape becomes the start (one undo step)
-- "stop" ends Live and keeps nothing; "keepframe" keeps the frame shown; "clear" goes back to the modelled mesh