VertexPaint : Modifier

VertexPaint - superclass: modifier; super-superclass:MAXWrapper - 12:0 - classID: #(2126202437, 2078409803)

The original VertexPaint Class from older 3ds Max versions has been renamed to OldVertexPaint in 3ds Max 6. The new implementation has exactly the same class name but a different classID and completely replaces the old one.

Constructors:

vertexPaint ... PaintLayerMod...

Properties:

<VertexPaint>.ignoreBackfacing BooleanClass default: false -- boolean; Ignore_Backfacing

Get/Set the ignore backfacing option.

<VertexPaint>.mapChannel Integer default: 0 -- integer; Map_Channel

Get/Set the Map Channel.

<VertexPaint>.layerMode String default: "Normal" -- string; Layer_Mode

Get/Set the Layer Mode.

<VertexPaint>.layerOpacity Float default: 100.0 -- animatable; float; Layer_Opacity

Get/Set the Layer Opacity.

<VertexPaint>.layerIsolated BooleanClass default: false -- boolean; Layer_Isolated

Get/Set the Layer Isolated mode. Corresponds to the "Ignore Underlying Color" option in the UI.

<VertexPaint>.surviveCondense BooleanClass default: false -- boolean; Survive_Condense

Get/Set the Survive Condense mode. Corresponds to the "Preserve Layer" option in the UI.

<VertexPaint>.lightingModel Integer default: 1 -- integer; Lighting_Model

Get/Set the Lighting model. Possible values are:

  1. - Lighting + Diffuse

  2. - Lighting Only

  3. - Diffuse Only

<VertexPaint>.colorBy Integer default: 0 -- integer; Color_By

Get/Set the Color Assignment mode. Possible values are:

  1. - Color By Face

  2. - Color By Vertex

<VertexPaint>.castShadows BooleanClass default: false -- boolean; Cast_Shadows

Get/Set the Cast Shadows option state. Corresponds to the "Shadows" option in the UI.

<VertexPaint>.useMaps BooleanClass default: false -- boolean; Use_Maps

Get/Set the Use Maps option state. Corresponds to the "Mapping" option in the UI.

<VertexPaint>.useRadiosity BooleanClass default: false -- boolean; Use_Radiosity

Get/Set the Use Radiosity option state. Corresponds to the "Use Radiosity" option in the UI.

<VertexPaint>.radiosityOnly BooleanClass default: false -- boolean; Radiosity_Only

Get/Set the Radiosity Only option state. Corresponds to the "Radiosity Only" option in the UI.

<VertexPaint>.radiosityOption Integer default: 0 -- integer; Lighting_Model

Get/Set the Radiosity Lighting Model index.

<VertexPaint>.hideUnselSubobjs BooleanClass default: false --  boolean; Hide_Unselected_Subobjects

Hides or shows unselected sub objects. This option is not exposed in the UI.

Interface: IVertexPaint

This interface provides paint state access for the VertexPaint modifier. To work with this interface:

  1. Obtain the paint state with AcquirePaintState(). This is a copy of the current state.
  2. Modify the state as desired.
  3. Re-apply the state using ApplyPaintState().
  4. Optionally use MergeVertexColors() to capture baked vertex colors from below the VertexPaint modifier in the stack.

Available in 3ds Max 2019.3 Update and later.

Methods:

<Interface>AcquirePaintState <node>node

Gets a copy of the VertexPaintState object for the specified node. You need to get this object in order to modify it.

<void>ApplyPaintState <node>node <Interface>state

Applies the specified VertexPaintState to the specified node. You must do this after you've modified a VertexPaintState object and want to apply the changes back to the modified node.

<void>ReleasePaintState <node>node <Interface>state

Releases the specified VertexPaintState from the specified node.

<void>MergeVertexColors <node>node

Merges any baked vertex colors on the specified node from below the VertexPaint modifier into the modfier's Paint.

Interface: VertexPaintState

This interface exposes methods to edit colors on a VertexPaintState object. There are two types of methods:

The color parameter for these methods is a Point4, in the format of [R,G,B,A], where the alpha channel affects the amount of paint applied, with 0.0 having no effect, and 1.0 is maximum (100%) effect.

Available in 3ds Max 2019.3 Update and later.

Methods:

<node>ReleasePaintState()

Releases the current paint state object.

<integer>GetNumRawColors()

Returns the number of raw color entries held by the VertexPaintState object. This is the number of raw indices in the exploded topology.

<index>GetRawIndex <index>faceIndex <index>vertIndex

Returns the raw index for the vertex specified by face index and vertex index. This is the index for the color value held by the vertex in the internal "exploded topology", where each vertex holds a separate color value for each adjacent face. You need this index to call GetRawColor() or SetRawColor(). The raw index is 1-based.

<point4>GetRawColor <index>rawIndex

Returns the raw color for the specified vertex. Use GetRawIndex() to get the raw index for a specific vertex/face combination.

<point4>GetVertAverageColor <index>vertIndex

Gets the average color for all the color entries (one per adjacent face) the specified vertex.

<point4>GetFaceAverageColor <index>faceIndex

Gets the average color (the color value for that face held by all its vertices), for the face specified by faceIndex.

<point4>GetFaceVertColor <index>faceIndex <index>vertIndex

Gets the color for

<void>SetRawColor <index>rawIndex <point4>color

Set the color of a single vertex entry via its "raw" index. You can obtain this index using GetRawIndex().

<void>SetVertColor <index>vertIndex <point4>color

Sets the color for the specified vertex, affecting all entries held by the vertex. The vertex holds a color entry for each adjacent face. A vertex with four edges has six color entries in a trimesh, four in a polymesh.

<void>SetFaceColor <index>faceIndex <point4>color

Sets the color for all entries for the specified face. A face with four edges has six color entries in a trimesh, and four entries in a polymesh.

<void>SetFaceVertColor <index>faceIndex <index>vertIndex <point4>color

Set the color entry for a single face/vertex combination. This is a convenience method that is functionally equivalent to getting the raw index for the face/index combination, and calling SetRawColor().

For Example

-- Demo: VertexPaint Scripting

fn doYourThing = (print "doing my thing")

-- Create an object and VertexPaint
g = Box() -- geometry object
    v = PaintLayerMod()
    addModifier g v
    g.showVertexColors = on



-- ---------- PAINT COLOR STATE ----------
-- Create a VertexPaint State object
-- This captures the current state into the object for editing.
-- Note:  Necessary to pass the node as a parameter to disambiguate,
-- since the modifier could be applied on multiple objects.
    s = v.AcquirePaintState g



-- ---------- RAW COLOR ACCESS ----------
-- Check how many color entries are in the state
    s.GetNumRawColors()
-- Each vertex has multiple entries, one for each face surrounding the vert.
-- VertexPaint maintain an "exploded topology" at all times.
-- Set a raw color entry, index is 1-based (not 0-based)
    s.SetRawColor 1 [1, 0.5, 0, 1]
    v.ApplyPaintState g s
-- Four entries are R,G,B and Amount, which is the amount of paint applied, and acts
-- like a mask in Photoshop terms.  Amount of zero means the paint has no effect.
-- Red 1.0 (maximum), Green 0.5, Blue 0.0 = Orange



-- ---------- VERTEX COLOR ACCESS ----------
-- Set a vertex color, affects all entries for the vert.
-- A vert with four visible edges has about six entries in a trimesh, four in a polymesh
    s.SetVertColor 1 [1, 0.5, 0, 1]
-- Apply the state back to the modifier
    v.ApplyPaintState g s
-- Get a vertex color, this takes the average of all entries for the vert
    c = s.GetVertAverageColor 1
    if( c != [1, 0.5, 0, 1] ) do UhOh()



-- ---------- FACE COLOR ACCESS ----------
-- Set a face color, affects all entries for the face.
-- A face with four edges has six color entries in a trimesh,  four in a polymesh
    s.SetFaceColor 1 [1, 0.5, 0, 1]
-- Apply the state back to the modifier
    v.ApplyPaintState g s
-- Get a face color, this takes the averaage of all entries for the face
    c = s.GetFaceAverageColor 1
    if( c != [1, 0.5, 0, 1] ) do UhOh()



-- ---------- FACE VERT COLOR ACCESS ----------
-- Specify both a face and a vert (in that order) to indicate a single raw entry
    faceNum=2
    vertNum=4
    s.SetFaceVertColor faceNum vertNum [1, 0, 0, 1]
-- OR, get the equivalent index to use with SetRawColor()
    x = s.GetRawIndex faceNum vertNum
    s.SetRawColor x [0, 1, 0, 1]
-- Apply the state back to the modifier
    v.ApplyPaintState g s



-- ---------- CAPTURE COLORS ----------
-- Capture any existing vertex colors on an object into a new VertexPaint.
-- Specify the map channel you're interested to capture
    v.mapChannel = 3
    v.MergeVertexColors g
-- This is similar to "Condense to Single Layer",
-- however it does not delete any modifiers.
-- Fetch the state again for editing
    s = v.AcquirePaintState g



-- ---------- !! WARNING !! ----------
-- ---------- SELECTIONS ----------
-- The sub-object selection masks the operation of ApplyPaintState(),
-- just like it masks the effect of brush strokes.
-- If you do not want this behavior, make sure to clear the selection
    selHoldSubobjLevel = 0
    if( (finditem (selection as array) g) > 0 )  do -- are we selected?
    (
        selHoldSubobjLevel = subobjectLevel -- remember subobject level
        subobjectLevel = 0 -- go to object level
    )
-- Do your thing
    doYourThing()
-- Revert selection after
    if( selHoldSubobjLevel > 0 ) do (
        subobjectLevel = selHoldSubObjLevel
    )

Below is the original definition of the old VertexPaint Modifier:

OldVertexPaint : Modifier

OldVertexPaint - superclass: modifier; super-superclass:MAXWrapper - classID: #(1715171243, 1945400197)

Class instances not creatable in 3ds Max 6 and higher.