Chapter 4 · Recipes

4.16Cache

Tnpix Cache saves the simulation to a file and plays it back:

  • Format. The file's extension decides the format: .tnc (TenPix) or .abc (Alembic; the demo saves .tnc only).
  • What it keeps. The cache holds the whole mesh: points, faces, every map channel, material IDs and smoothing groups.
  • One cache per garment. Give each garment its own Tnpix Cache. One instanced across objects that depend on each other is refused by 3ds Max, so some garments would be skipped.
  • Shared Solver. On a shared Solver, one save records the whole Solver group.
  • Shared Cache. A Tnpix Cache shared by several garments writes one file per garment, named <file>_<garment>.
-- cache every garment of $Shirt's Solver group, each into its own file in one folder (the artist's folder)
(
    local folder = "D:\\Shots\\sh010\\cloth"
    local gs = tpaUsers (tpaFirst $Shirt Tnpix_Solver)
    local taken = for g in gs where doesFileExist (folder + "\\" + g.name + ".tnc") collect g.name
    local shared = for g in gs where (tpaFirst g Tnpix_Cache) != undefined and (tpaUsers (tpaFirst g Tnpix_Cache)).count > 1 collect g.name
    if taken.count > 0 then ("These files exist - ask before replacing them: " + (taken as string))
    else if shared.count > 0 then ("These garments share one Tnpix Cache - give each its own first (the Cache Manager does): " + (shared as string))
    else (
        makeDir folder all:true
        for g in gs do (
            local cm = tpaFirst g Tnpix_Cache
            if cm == undefined do cm = tpaAddAboveSolver g (Tnpix_Cache())
            cm.file = folder + "\\" + g.name + ".tnc"
            cm.specificRange = false          -- the whole animation range; or true with cm.start / cm.end
        )
        local n = TnpixTool.cacheSave gs[1]   -- frames written, or -1 (the reason is in cacheInfo)
        local s = "cacheSave: " + (n as string) + "\n"
        for g in gs do s += g.name + ": " + (TnpixTool.cacheInfo g) + "\n"
        s
    )
)
  • Save. cacheSave records from the first frame of the range wherever the slider is, simulates any missing frames, and turns Play from cache on when it succeeds.
  • Load. cacheLoad opens the Cache's file and plays it; cacheClear stops playing and forgets the file, deleting nothing.
  • Missing files. If a garment's file was not written by the group's save, save that garment on its own and check cacheInfo again.
  • Progress. Define a global tnpixCacheProgressHook done total function and the save calls it after every frame.
  • Retime and posterize without simulating again: retime (animatable; 0 freezes), posterizeStep, posterizeHold, frameOffset.
  • Motion blur from Alembic. writeVelocities (Alembic only) adds per-point velocities.
  • Order above the Cache. Put Tnpix Post Process above the Cache. A threads object gets a Tnpix Cache of its own.

The Cache Manager (toolbar) is the artist's window for many garments at once:

  • Add gives each highlighted garment its own Tnpix Cache.
  • Load always asks. With one garment highlighted it asks for a file, opening at the garment's own file. With several it asks for a folder, in which each garment takes the file named after it, or the shot file a Batch Sim run wrote there (<garment>_<shot>). Cancel changes nothing; a garment with no file in the folder keeps what it plays.
  • Save records into each garment's own file, or into a folder as <object name>.tnc / .abc. A garment on a shared Solver is saved with its whole Solver group.
  • Clear stops playing and forgets the file. Nothing is deleted.

Open it for the artist with tpaOpenTool "TenPix_03_CacheManager.ms" (7.7).

The Tnpix Cache panel's "..." opens, on a Cache with no file yet, in the last folder any Tnpix Cache was given, with the garment's name ready. On a Cache that has a file, it opens at that file.