Error effect from UV to VertexColor

Error effect from UV to VertexColor

haoze0221
Contributor Contributor
725 Views
2 Replies
Message 1 of 3

Error effect from UV to VertexColor

haoze0221
Contributor
Contributor

I intended to use UV position control and generate gradient vertex colors on the model, but got the wrong effect.VertexColor.jpg

I get a different coordinate value from each vertex of the UV to get the axial gradient relationship.

polyop.getMapVert obj 2 vertIndex

An error occurred when I tried to map UV vertices to the model, and I found that the index of the point in the model UV did not match the index of the point on the model,

This results in the wrong vertex color effect.

polyop.setVertColor obj 0 #{vertIndex} vertColor

vertex.jpg

I'm new to using Maxscript.
Please let me know if there is a better solution. Thank you~

0 Likes
Accepted solutions (1)
726 Views
2 Replies
Replies (2)
Message 2 of 3

klvnk
Collaborator
Collaborator
Accepted solution

uv vert indices != vert color indices != vert indices

 

but UV face corner 1  == color face corner 1 == face vert corner 1

and UV face corner 2 == color face corner 2 == face vert corner 2

and UV face corner 3 == color face corner 3 == face vert corner 3

 

 

 

 

fn uv_to_vcol mobj mapchannel  = 
(	
	meshop.setMapSupport mobj 0 true;

	visited = #{};
	visited.count = mobj.numverts;
	
	for f = 1 to mobj.numfaces do
	(
		uvfverts = meshop.getMapFace mobj mapchannel f;
		clrfverts = meshop.getMapFace mobj 0 f;

		for v = 1 to 3 where not visited[clrfverts[v]] do
		(	
			uvvert = meshop.getmapvert mobj mapchannel uvfverts[v];
			meshop.setmapvert mobj 0 clrfverts[v] [uvvert.y,0,0]; 
			visited[clrfverts[v]] = true;
		)		
	)
)	

uv_to_vcol $ 1

 

 

 

 

 

Message 3 of 3

haoze0221
Contributor
Contributor

Hi,@klvnk this is great! I'm going to learn from you.
Through your method, I realized the vertex color effect of three RGB channels.

 

fn uv_to_vcol mobj mapchannel mrgb = 
(	
	meshop.setMapSupport mobj 0 true

	visited = #{};
	visited.count = mobj.numverts;
	
	for f = 1 to mobj.numfaces do
	(
		uvfverts = meshop.getMapFace mobj mapchannel f;
		clrfverts = meshop.getMapFace mobj 0 f;

		for v = 1 to 3 where not visited[clrfverts[v]] do
		(	
			uvvert = meshop.getmapvert mobj mapchannel uvfverts[v];
			
			meshop.setmapvert mobj 0 clrfverts[v] (case mrgb of 
				(
					1:[uvvert.y,0,0]
					2:[0,uvvert.y,0]
					3:[0,0,uvvert.y]
				)
			);
			visited[clrfverts[v]] = true;
		)		
	)
)	

uv_to_vcol $ 2 1

 

I have a new conundrum, is there a way to mix the three colors of RBG together?
Just like the triangle on the left.This way I can achieve different effects through the RGB control model.

 

Snipaste_2023-02-20_22-31-27.png

0 Likes