Home Technical Talk

[MAXScript] Invert Vertex Color - Different Results

polycounter lvl 15
Offline / Send Message
shabba polycounter lvl 15
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.)
for i=1 to myObj.numVerts do
	(
		my_color = getVertColor myObj i
		newVColor = 	color (255 - my_color.r) (255 - my_color.g) (255 - my_color.b)
		meshop.setVertColor myObj V_Channel i newVColor
	)

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
    Options
    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
    Options
    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.
    (
    	for myObj in selection do
    	(
    		defaultVCFaces myObj
    		vCount = getNumCPVVerts myObj
    		for i = 1 to vCount do
    		(
    			my_color = getVertColor myObj i
    			newVColor = 	color (255 - my_color.r) (255 - my_color.g) (255 - my_color.b)
    			meshOp.setVertColor myObj 0 i newVColor
    			
    			format "Old Color: %, New Color: %\n" my_color newVColor
    		)
    	)
    	
    	max views redraw
    )
    
  • shabba
    Options
    Offline / Send Message
    shabba polycounter lvl 15
    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
    Alpha_vCount = meshop.getNumMapVerts myObj -2
    format "# of Alphaverts = %\n"	Alpha_vCount	
    					
    for i = 1 to Alpha_vCount do 
    (
       my_color = meshop.getMapVert myObj V_Channel i
       newVColor = [(1 - my_color.x), (1 - my_color.y), (1 - my_color.z)]
       meshop.setMapVert myObj V_Channel i newVColor
    )
    
Sign In or Register to comment.