Autodesk 3DS Max: Get Vertex Color From Every Vertex On Plane?

polycounter lvl 4
Offline / Send Message
MrQuetch polycounter lvl 4
Hello.

I'm trying to do exactly what the title of the thread states. I have a plane with black and white vertex colors - think of a height map.
The plane contains 4,225 vertices and 8,192 triangles in it. Basically, it has 64 x 64 segments on length and width.
Depending on the color, that's what gets saved to that specific vertex.

Although, I can manage to get the colors with this code:
obj = $
obj_mesh = obj.mesh
obj_mesh_verts = obj_mesh.numverts
obj_name = "heightmap.bin"

_fileDebug = newScript()

file = fopen obj_name "wb"

for i = 1 to obj_mesh_verts do
	(
	vertColor = getVertColor obj_mesh i
	
	format "% \n" (vertColor.r as integer) to:_fileDebug

	WriteByte file (vertColor.r)
	)

fclose file
What I should see in the hex editor is a grid of the same colors - in ASCII.
But, the output I get doesn't even relate to what I see in the plane.

Any ideas on what I can do to save each vertex / byte as the correct color (black and / or white)?
I cannot tell what vertex color is being saved to what vertex.

Thank you!

Replies

  • rollin
    Offline / Send Message
    rollin greentooth
    Wait, basically the problem is in saving to file?! So the "format ..." is outputting exactly what you want but writeByte does not what you want? Are you sure the color is already in one-byte size (internally)? 
    I'm just guessing here: but I would assume the color might be a float or something and will overflow or be clamped or whatever when converted to byte
  • monster
    Offline / Send Message
    monster Polycount Sponsor
    @rollin in MaxScript color.r should return a float between 0-255. And it auto converts to an int when needed.

    @MrQuetch  You may need to provide some sample files. This code snippet works me. (I just had to change "heightmap.bin" to "$temp/heightmap.bin") But it writes the bytes, and I can read them back in as ints. I didn't open the bin file in a hex viewer because I don't really have experience looking at hex files.
Sign In or Register to comment.