Chapter 4 · Recipes
4.5Painting a channel from script
Painting needs three things:
- the object selected, with its Tnpix Channel as the current object in the Modify panel;
- that Channel on exactly one object; an instanced Channel refuses;
- dab centres in the object's own space: the coordinates its vertices have before the node is moved.
A dab lands on the channel selected on the panel; after chanAdd, that is the new channel. Painting works reliably on a Tnpix Channel added through modPanel.addModToSelection while the object is selected in the Modify panel.
(
local g = $Shirt
max modify mode
clearSelection()
select g
local ch = tpaFirst g Tnpix_Channel
if ch != undefined then (
modPanel.setCurrentObject ch -- paint into the garment's own Tnpix Channel
completeRedraw()
) else (
local below = tpaFirst g Tnpix_Garment -- the new Channel goes directly above Tnpix Garment ...
if below == undefined and g.modifiers.count > 0 do below = g.modifiers[g.modifiers.count] -- ... or above the bottom modifier
if below != undefined do modPanel.setCurrentObject below -- 3ds Max adds a modifier above the current one
modPanel.addModToSelection (Tnpix_Channel())
)
local ok = TnpixTool.chanAdd g "shirt_collar" 0.0 -- every point at 0; the new channel is selected
if ok do (
TnpixTool.chanStroke g true -- the dabs count as one stroke
for p in #([0, -6, 58], [4, -5, 58], [8, -3, 58]) do TnpixTool.chanPaint g p 2.0 0 1.0 -- centre, radius, mode 0 Add, strength
TnpixTool.chanStroke g false
)
"shirt_collar: " + ((TnpixTool.chanCount g "shirt_collar" 0.5) as string) + " points at 0.5 or more"
)
- Approval. Where a part lies is the artist's judgement. Show the weights (3.6) and get their OK before you bind anything to the channel. The artist can also paint the region themselves, which is often faster.
- Modes and strength. The modes are 0 Add, 1 Subtract, 2 Replace and 3 Smooth. The strength is how far one dab moves the weight toward the panel's Value.
- Check the result with
chanCountat several levels (for example 0.99, 0.5 and 0.01). - One layer only.
(tpaFirst g Tnpix_Channel).pick = 1sets the paint brush's Picks to On the surface: it paints only the points the cloth reaches from the point pressed on, not a layer lying over or under it. Check script dabs withchanCountand the weights display. - Painting into an existing channel. The documented interface has no call that selects an existing channel. Ask the artist to click it in the Channel list;
TnpixTool.chansshows which row is selected. - Mirror.
TnpixTool.chanMirror g 1 0.1copies the selected channel's weights from the −X side to the +X side. Sides 0 to 5 are listed in 7.6. - A tear line.
TnpixTool.tearCut g "tear_line" #([-40,0,0], [-20,4,0], [0,0,0]) [0,0,-1] 2.0cuts a line into the mesh and marks it in the channel. It needs no Modify panel, andTnpixTool.tearRemove g 0removes the last cut. - Deleting a channel.
TnpixTool.chanRemovedeletes a channel together with its tear-brush lines. Ask first. - Changing the mesh. If the mesh below the Channel changes (another Edge length, for example), every channel carries its paint over by position.