Chapter 3 · Reading a scene
3.2Helpers
Load these once per 3ds Max session; they stay defined until 3ds Max closes. They find modifiers by class, and they place a new modifier where the stack order says it belongs. The other examples in this guide use them.
global tpaFirst, tpaIndex, tpaUsers, tpaAddBelowSolver, tpaAddAboveSolver, tpaGoldIndex, tpaMatIndex
-- the first modifier of class cls on o's stack, from the top (undefined if none)
fn tpaFirst o cls = (
local r = undefined
if isValidNode o do for m in o.modifiers where r == undefined and (classOf m) == cls do r = m
r
)
-- the stack index of that modifier (1 = the top of the stack), 0 if none
fn tpaIndex o cls = (
local k = 0
for i = 1 to o.modifiers.count where k == 0 and (classOf o.modifiers[i]) == cls do k = i
k
)
-- the objects that share modifier m; for a Tnpix Solver, its whole Solver group
fn tpaUsers m = ( makeUniqueArray (for n in (refs.dependentNodes m) where isValidNode n collect n) )
-- put m directly below o's Tnpix Solver, where the modifiers that describe the cloth go (on top if o has no Solver)
fn tpaAddBelowSolver o m = (
local s = tpaIndex o Tnpix_Solver
if s == 0 then addModifier o m else addModifier o m before:s
m
)
-- put m directly above o's Tnpix Solver (Tnpix Cache, Tnpix Threads)
fn tpaAddAboveSolver o m = (
local s = tpaIndex o Tnpix_Solver
if s <= 1 then addModifier o m else addModifier o m before:(s - 1)
m
)
-- the index that goldAt, goldSetAt and goldChanAt use for Material Standard m on o (0 = the top-most); -1 if not found
fn tpaGoldIndex o m = (
local k = -1, n = 0
for x in o.modifiers where (classOf x) == Tnpix_Material_Standard do ( if x == m do k = n; n += 1 )
k
)
-- the same for a Material Advanced (matAt, matSetAt, matChanAt and the other mat functions)
fn tpaMatIndex o m = (
local k = -1, n = 0
for x in o.modifiers where (classOf x) == Tnpix_Material_Advanced do ( if x == m do k = n; n += 1 )
k
)
addModifier o m before:k places m directly below the modifier at stack index k. Index 1 is the top of the stack.