Chapter 4 · Recipes

4.3Fabric: materials, regions and presets

Standard or Advanced. Material Standard has the everyday dials and 12 stock fabrics: start there. Material Advanced is the full model: Shape Memory keeps modelled folds and rolls, plus the Fabric Curve and the mass modes. Use it when a garment or a region must keep its modelled shape, or when the artist asks for it. Both kinds carry their own Friction and Grip (3.7), and one garment can mix them by region.

Tnpix Material Standard has no MAXScript properties for its dials. An assignment such as mat.stretchBodyLimit = 1 does nothing at all, and does it silently. Read and write the dials by name, as listed in 7.6, and check that each call returns true. Index 0 is the top-most Standard material on the stack.

TnpixTool.goldPreset $Shirt 2                       -- Denim (approx); writes only the values that fabric carries
TnpixTool.goldSetAt  $Shirt 0 "weight" 400.0        -- g/m2, the number the panel shows
TnpixTool.goldSetAt  $Shirt 0 "bendGoldK" 120.0     -- K bend
TnpixTool.goldSetAt  $Shirt 0 "relDamp" 0.08        -- Relative Damp: about 0.08 for cotton, 0.2 leather, 0.02 silk
TnpixTool.goldSetAt  $Shirt 0 "matFriction" 0.5     -- this fabric's friction, on the body and on the other garments (3.7)
TnpixTool.goldSetAt  $Shirt 0 "matGrip" 3.0         -- its grip on colliders
TnpixTool.goldAt     $Shirt 0                       -- read it back

Tnpix Material Advanced takes the same approach with matSetAt and the other mat... functions; out-of-range values are refused, not clamped. A new Advanced material starts with the Medium Fabric values, and its default bend, Shape Memory, keeps the folds the garment was modelled with.

A region of its own (several fabrics on one garment). Bind an extra material to the region's channel. A material bound to a channel always keeps its region against a material without a channel, and where two channel-bound materials paint the same points, the higher one wins. Two examples for a collar painted in shirt_collar:

-- a) a stiffer Standard fabric on the collar
undo "TenPix: stiffer collar" on (
    local g = $Shirt
    local m = tpaAddBelowSolver g (Tnpix_Material_Standard())   -- directly below the Solver
    local k = tpaGoldIndex g m                                  -- its index for the gold functions
    TnpixTool.goldChanAt g k "shirt_collar"                      -- covers only the collar's paint
    if k == 0 do TnpixTool.goldPreset g 10                       -- Canvas; goldPreset writes the FIRST Standard material only
    TnpixTool.goldSetAt g k "bendGoldK" 500.0                    -- or any dial by name
)
-- b) a collar that keeps its modelled roll and the shirt's weight (Material Advanced)
undo "TenPix: collar keeps its roll" on (
    local g = $Shirt
    local m = tpaAddBelowSolver g (Tnpix_Material_Advanced())
    local k = tpaMatIndex g m
    TnpixTool.matChanAt g k "shirt_collar"
    TnpixTool.matSetBendModelAt g k 1          -- Shape Memory: every fold returns to its modelled angle
    TnpixTool.matSetPairAt g k "bend" 4.0 7    -- Bend Stiffness 4.0 x 1 000
    TnpixTool.matSetAt g k "massMode" 0        -- Unchanged: the collar keeps the weight of the material under it
)

Some values act per region and some do not:

  • Per region on a Standard material: weight, velocity damping, Motion Damping, max strain, K bend, K stretch, K shear, Relative Damp, the damping ratios, damp bend, friction and grip.
  • Friction per region on both kinds: a material bound to a channel brings its own friction and grip to the points it covers, so a jacket's shoulders can grip the body harder than its sleeves.
  • For the whole Solver: Accurate strain limit, Solve steps per iteration and Multi-res levels.
  • Per region on an Advanced material: Stretch Stiffness, Edge Stiffness, and Shear Stiffness under the Standard stretch type.
  • A garment with two materials and no channel: only the higher one acts. Give a garment one material without a channel.

Preset files. TnpixPreset saves and loads the same files as the Presets rollout: .tpstd for Standard, .tpadv for Advanced, .tpsoft for Soft Body. A preset stores the fabric, not its channel binding.

m = tpaFirst $Shirt Tnpix_Material_Standard
f = TnpixPreset.folder() + "\\Heavy denim.tpstd"
-- saving writes a file: check doesFileExist f first and ask before replacing one
TnpixPreset.save m f
TnpixPreset.load (tpaFirst $Jacket Tnpix_Material_Standard) f    -- values applied, or -1 if refused
TnpixPreset.why()                                                  -- what the last save or load did
TnpixPreset.names m                                                -- the Standard presets in the folder