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
    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
    1.  
    2. fn setmapverts poly chan verts val =
    3. (
    4. if not polyop.getmapsupport poly chan then polyop.Setmapsupport poly chan true;
    5. nverts = polyop.getnumverts poly;
    6. nfaces = polyop.getnumfaces poly;
    7. visited = #{};
    8. visited.count = nverts;
    9. for f = 1 to nfaces do
    10. (
    11. geo_fverts = polyop.getfaceverts poly f;
    12. map_fverts = polyop.getMapFace poly chan f;
    13. for v = 1 to geo_fverts.count where verts[geo_fverts[v]] and not visited[geo_fverts[v]] do
    14. (
    15. visited[geo_fverts[v]] = true; -- stops us repeating
    16. polyop.setMapVert poly chan map_fverts[v] val;
    17. )
    18. )
    19. )
    20.  
    21. 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.