Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

[MAXScript] Invert Vertex Color - Different Results

polycounter lvl 16
Offline / Send Message
shabba polycounter lvl 16
The script I have made inverts the vertex color per vert on an EditableMesh object using Meshop's.

(ex:This is the meat and potatoes of the script.)
  1. for i=1 to myObj.numVerts do
  2. (
  3. my_color = getVertColor myObj i
  4. newVColor = color (255 - my_color.r) (255 - my_color.g) (255 - my_color.b)
  5. meshop.setVertColor myObj V_Channel i newVColor
  6. )

However, the result is different depending on how the vertex colors were applied.

QUESTION: Anyone know what the difference is between these two vert color workflows? And why I get a different result?

EXAMPLE: Vert color applied using VertPaint modifier vs Vert color applied using the "Edit Vertex Color" in Vert Properties of editable poly.

Strange_Issue.jpg

Replies

  • Amatobahn
    Offline / Send Message
    Amatobahn polycounter lvl 7
    So, Your script is fine. Its merely something to do with how the VertexPaint modifier works. I think maybe the best route to go about this is to get the values from channel 0 (RGB Vertex Color) and invert that way. That way it will work with editable mesh and editable poly.
  • monster
    Offline / Send Message
    monster polycounter
    The number of VC verts doesn't always match the number of geometry verts. You can use a command to match them up, and use getNumCPVVerts instead of numVerts.

    http://docs.autodesk.com/3DSMAX/16/ENU/MAXScript-Help/files/GUID-5702AD16-5D90-4B74-A7E7-F49A8B6903C0.htm

    I was able to reproduce your problem with your code, and the following code works for me at least.
    1. (
    2. for myObj in selection do
    3. (
    4. defaultVCFaces myObj
    5. vCount = getNumCPVVerts myObj
    6. for i = 1 to vCount do
    7. (
    8. my_color = getVertColor myObj i
    9. newVColor = color (255 - my_color.r) (255 - my_color.g) (255 - my_color.b)
    10. meshOp.setVertColor myObj 0 i newVColor
    11. format "Old Color: %, New Color: %\n" my_color newVColor
    12. )
    13. )
    14. max views redraw
    15. )
  • shabba
    Offline / Send Message
    shabba polycounter lvl 16
    Thanks for the reply guys! That really helped a ton Monster, thank you. After doing more research and seeing that I was getting strange values for alpha/illum, I opted to use this to get point3 information representing the UVW space as color values.

    I really learned a ton with this one. But I want to add the ability to compare the MapVerts that are all the same MeshVert, and get the weighted value of each MapVerts color to determine what the actual color should be and set each similar Mapvert to that value, instead of just overwriting previous values based on vert order.

    Thanks again! If you are interested, the script can be found here: MAXScript Adventures: Invert Vertex Colors
    1. Alpha_vCount = meshop.getNumMapVerts myObj -2
    2. format "# of Alphaverts = %\n" Alpha_vCount
    3. for i = 1 to Alpha_vCount do
    4. (
    5. my_color = meshop.getMapVert myObj V_Channel i
    6. newVColor = [(1 - my_color.x), (1 - my_color.y), (1 - my_color.z)]
    7. meshop.setMapVert myObj V_Channel i newVColor
    8. )
Sign In or Register to comment.