Notifications
Clear all

[Closed] Get vertex color from map

Hi maxscripters,
I have an object with UV mapping, this object has a material with a map in the diffuse slot. I would like to get the color for each vertex from that map, how should I do it?

13 Replies

step #1:
we have to build faces of a vertex color channel the same as they are built in the texture map channel

can you do this yourself?

after that there are another four steps…

I can’t.
I know how to set and get vertex color of a vertex, I just need to get this color from map considering the uv coords.

i exactly know what you need. but you have to match the vertex channel topology with the texture map channel first.

Okay, but how to do it?
I came up with an idea to use Assign Vertex Colors from utilities, is it possible to execute it via maxscript? It does exactly what I need.

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

well… i can put here the code what you want. you will copy and paste it into yours code… tool… homework…
fine… but before that could you answer me a question… what is the default vertex channel number?

(@tamyl)
Joined: 11 months ago

Posts: 0

you mean mapping channel? it’s 1 and 0 is the vertex color channel

here is a first step


mapped fn copyMapChannelTopology node sourceChannel:0 targetChannel:1 = if iskindof node Editable_Poly do
(
	if (polyop.getmapsupport node targetChannel) do
	(
		polyop.setmapsupport node sourceChannel on
		polyop.defaultmapfaces node sourceChannel
		polyop.setnummapverts node sourceChannel (polyop.getnummapverts node targetChannel)
		
		num = polyop.getnumfaces node
		for f=1 to num do polyop.setmapface node sourceChannel f (polyop.getmapface node targetChannel f)
		update node
	)
)

and there is the next step

fn bakeStandardMaterial node mat: sourceChannel:0 targetChannel:1 = if iskindof node Editable_Poly do
(
	if mat == unsupplied do mat = node.mat
	if iskindof mat Standard and iskindof (bmp = try(mat.diffusemap.bitmap) catch()) Bitmap do
	(
		if (polyop.getmapsupport node targetChannel) and (polyop.getmapsupport node targetChannel) do
		(
			num = polyop.getnumfaces node
			for f=1 to num while not keyboard.escpressed do 
			(
				vv = polyop.getmapface node targetChannel f
				for v in vv do
				(
					tv = polyop.getmapvert node targetChannel v
					cc = getpixels bmp [(mod (tv.x + 1.0) 1.0)*bmp.width, (mod (2.0 - tv.y) 1.0)*bmp.height] 1
					polyop.setmapvert node sourceChannel v (cc[1] as point4)
				)
			)
			setCVertMode node on
			setShadeCVerts node on
			node.vertexColorType = #map_channel
			node.vertexColorMapChannel = sourceChannel

			update node
		)
	)
)  

the code has to be optimized but i left it to you…

Ok, but what if I don’t have a bitmap in diffuseMap? Is there an universal method for every kind of map?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

if there is no bitmap set black, or any default, or the material diffuse color

My biggest problem now is to get a color from any kind of texture map, let’s say that I have an checker map in my diffuse channel, I choose one face, calculate barycentric coords of some point in this face and want to get the color at that point from this checker map, I already know how to do it with bitmap.

you can render any TextureMap to Bitmap using renderMap (see mxs help for details)

Page 1 / 2