Accessing the Viewport Vertex Alpha Values

3ds Max supports 100 map channels that can be used for storing mapping coordinates.

Historically,

3ds Max 1.0 supported only one texture channel which is currently Channel 1.

3ds Max 2.0 added support for a second channel which could be used either for texture coordinates or for storing vertex colors. Currently it is stored as Channel 0.

3ds Max 3.0 increased the number of channels to 100. The channels are numbered from 1 to 99 plus the already mentioned Vertex Colors Channel 0.

All these Channels can be accessed by the Unwrap_UVW, by the Maps in the Material Editor etc. The channels support map vertices and faces connecting them. For details, you can see Understanding Texture Coordinates. For related methods, see General Meshop Mapping Methods

3ds Max 4.0 added support for Alpha in the Viewports. This new internal channel has been given the index -2.

In addition, 3ds Max 4.0 introduced 100 user data channels with indices from 1 to 100. These channels can be used to store arbitrary Point3 data per vertex, for example special data for game models that can be exported to game engines. They do not have face arrays, only vertex data arrays. For related methods, see Meshop Vertex Data Methods

Warning: Mapping channels and Vertex Data channels are not the same thing!

While the User Data Channel 3 is dedicated to Alpha values, it is unrelated to the Viewport Vertex Alpha channel which is the internal map channel with index -2.

In the following example we will create a sphere with 4 segments (only 6 vertices) and access its Viewport Alpha values. You can try and increase the number of sphere segments to get more vertices anytime.

EXAMPLE

   s = sphere segs:4 -- create a sphere
   convertToMesh s -- collapse to Editable Mesh
   s.showVertexColors = true -- enable Vertex Colors in Viewport
   s.vertexColorType = #alpha -- set Vertex Color type to Alpha

   --Read the number of mesh vertices
   mesh_verts = s.numverts
   --Set the map vertices for the first and last mesh vertex to black
   --Note that this access will automatically enable channel -2 and
   --build its internal vertex and face arrays.
   meshop.setVertAlpha s -2 #(1, mesh_verts) 0.0

   --Read the number of map vertices in Channel -2
   --Since the channel -2 is now enabled, you will get a valid result.
   --Evaluating this line BEFORE the previous one would lead to
   --an error message telling you Channel -2 is not enabled...
   map_verts = meshop.getNumMapVerts s -2
   --Go through all map vertices except the first and last and change
   --their Alpha value to a non-greyscale color using direct access
   --to the Mapping Channel -2
   for i = 2 to map_verts-1 do
       meshop.setMapVert s -2 i [i*0.1,i*0.05,1.0-i*0.1]
   --Update the mesh:
   update s

   --Go through all map vertices and print their values by
   --reading directly from Channel -2
   for i = 1 to map_verts do format "Map Vertex % = %\n" i (meshop.getMapVert s -2 i)

RESULTS:

   $Sphere:Sphere01 @ [0.000000,0.000000,0.000000]
   $Editable_Mesh:Sphere01 @ [0.000000,0.000000,0.000000]
   true
   #Alpha
   6
   OK
   6
   OK
   OK
   Map Vertex 1 = [0,0,0]
   Map Vertex 2 = [0.2,0.1,0.8]
   Map Vertex 3 = [0.3,0.15,0.7]
   Map Vertex 4 = [0.4,0.2,0.6]
   Map Vertex 5 = [0.5,0.25,0.5]
   Map Vertex 6 = [0,0,0]
   OK
   OK
Note: The array #(1, mesh_verts) specifies the Mesh Vertex Indices and not the Map Vertex indices! The meshop.setVertAlpha will find all corresponding Map Vertices in the channel and affect them all without the need to look for them!

On the other hand, the index supplied to meshop.setMapVert is the Map Vertex index and not the Mesh Index as in the case of meshop.setVertAlpha . If there are more Map Vertices corresponding to a single Mesh Vertex, you would have to find them all and read their values separately. In this simple case though, there are 6 Mesh Vertices and corresponding 6 Map Vertices, so the indices are the same.

meshop.getMapVert reads the actually stored value from a specific Map Vertex which is always a Point3 value.

As you see from the example, you can use meshop.setMapVert to set the value of Map Vertices in the Alpha Channel -2 to a color which will be displayed as color in the viewport! The Alpha Channel -2 is just a regular mapping channel used in a similar way to the Vertex Color Channel 0.

meshop.setVertAlpha lets the user set all Point3 components to single value at once for all Map Vertices related to the supplied array of Mesh Vertices. This ensures the Alpha channel contains a greyscale value and not an RGB value and shields the user from additional work to provide Point3 values and find out which Map Vertices to affect.

The reason there is NO meshop.getVertAlpha counterpart is that a single Mesh Vertex could have any number of corresponding Map Vertices, all with possibly different values, and all values having 3, possible different, components. It would be difficult to return meaningful values for a group of Mesh Vertices, each with multiple results and multiple Point3 components.

Using meshop.getMapVert , you will always get the exact Point3 value for the exact Map Vertex of interest, and will be able to use it the way you want.