Home Coding, Scripting, Shaders

Copying Alpha Value of Selected Vert (Maxscript)

Hi,
I've been trying to copy the alpha value of a selected vert in 3dsmax (via a tool UI) and I'm almost there but something isn't working how I expected. It seems that I need to get the index of that vert in its array and not its ID# ?

Here is the code that I have so far for the "Copy Alpha" button; the variable "sV" is the ID of the selected vert but I think I need its index position in the array and not its ID...but I don't know how to do get it.

I did a test to get all the alpha values of the selected mesh (with 1 selected vertex that I manually set with a different value (88.0) while the rest are at 0.0). The selected vert ID is #3, but it shows up at index 15 in that array (so manually setting sV to "15" returns the proper alpha value of 88.0).

However, If I leave sV as-is (so in this case its value will be its ID #3), it will return the wrong alpha value sCopiedVal of 0.0...(I guess it selects another vert).

What am I doing wrong, how can I fix this?
--------------------------------------
sCopiedVal = #()
selVert = #{}
selVert = polyop.getVertSelection $ as array
if selVert.count != 1 then messageBox "Select just one vertex to copy alpha values"
else
(
sV = selVert[1]
obj = selection[1]

polyOp.setMapSupport obj -2 true

sCopiedVal = (polyOp.getMapVert obj -2 sV)[1] * 100.0
rlSetVertexAlpha.sldVA.value = sCopiedVal
rlSetVertexAlpha.spVA.value = sCopiedVal
)

Replies

  • Klunk
    Options
    Offline / Send Message
    Klunk ngon master
    as with all things max and mapping it is very possible for geometry vert index <≠> mapping vert index 

    to get the correct vert and it's associated mapping vert you go by face and corner
    so in psuedo code...

    geo_face[1].vert[2] <=> map_face[1].vert[2]

    and in mxs
    
    fn setmapverts poly chan verts val =
    (
    	if not polyop.getmapsupport poly chan then polyop.Setmapsupport poly chan true;
    		
    	nverts = polyop.getnumverts poly;
    	nfaces = polyop.getnumfaces poly;
    	visited = #{};
    	visited.count = nverts;
    	
    	for f = 1 to nfaces do
    	(
    		geo_fverts = polyop.getfaceverts poly f;
    		map_fverts = polyop.getMapFace poly chan f;
    		
    		for v = 1 to geo_fverts.count where verts[geo_fverts[v]] and not visited[geo_fverts[v]] do
    		(	
    			visited[geo_fverts[v]] = true; -- stops us repeating 
    			polyop.setMapVert poly chan map_fverts[v] val;
    		)
    	)
    )	
    
    setmapverts $ 0 (polyop.getVertSelection $) [0,0,0]


    this is how it might be approached (done as vertex color channel as it's visually easy to check)

Sign In or Register to comment.