Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Set vertex colors to match materials

Set vertex colors to match materials

Anonymous
Not applicable
663 Views
4 Replies
Message 1 of 5

Set vertex colors to match materials

Anonymous
Not applicable
Basically, I would like to do the same exact thing as the assign vertex colors utility. Except I want to do it in maxscript so I can automate the process because I have a lot of files that need this procedure done.

Ideally I want to just access the assign vertex colors utility from maxscript. But there doesn't seem to be away to do this. I just need to figure out away to get the system to activate the "assign to selected" button. Is there a way to do this?

If not what set of functions should I investigate to get the vertex color to match the material color. The materials are all solid colors, so its nothing to complex (I hope) I just need to convert the colors for each objects material to its vertex colors.

Thanks
0 Likes
664 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
I think I might have found my solution

According to the maxscript guide:
This Interface lets you assign vertex colors to any number of nodes.
Methods:

<integer>ApplyNodes <node array>nodes 


vertexPaint default value: undefined
Assigns vertex colors to the specified nodes array.


however this is a little different format from what im used to when I write my script, can somebody tell me how to utilize this?
0 Likes
Message 3 of 5

Steve_Curley
Mentor
Mentor
Like all the function definitions in the Maxscript help, that is a generic description of the return type and value, the function name and the the number and type of parameters required.

It would appear to be little more than a function which adds a Vertex Paint Modifier to the node(s) provided and opens the Edit dialog (as if you had clicked the Edit button on an existing modifier).

I've not played with vertex colours (in maxscript) but I suspect you'll have to deal with the modifier directly in order to set the actual vertex colours.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 4 of 5

Anonymous
Not applicable
feel free to use this small script I wrote a while back.
It requires that the materials be standard materials.
If the materials has a diffuse texture then the average color of that texture is used, and if not, the diffuse color is used.

try(destroydialog solidCols)catch()

fn SetAvgColor o=
(
if o.material.diffuseMap!=undefined then
(
local cols=#()
local theBMP=rendermap o.material.diffuseMap
local chan=o.material.diffuseMap.coords.mapChannel
local theMesh=copy o.mesh
local getMV=meshop.getMapVert
for i = 1 to (meshop.getnummapverts theMesh chan) do
(
local UVvert=getMV theMesh chan i
local thecoords= 1)*(theBMP.width-1),(1-(mod UVvert 1))*(theBMP.height-1)]
local thePix=getPixels theBMP thecoords 1
append cols thePix
)
delete theMesh
local sum=black
for c = 1 to cols.count do sum+=cols
sum=sum/cols.count
)
else sum = o.material.diffuse
with redraw off
(
max modify mode
select o
if (classof o.modifiers==unwrap_UVW) and (o.modifiers.getVC()) then (local UVmod=o.modifiers) else
(
local UVmod=unwrap_UVW()
addModifier o UVmod
)
UVmod.setVC true
local setVP=UVmod.setVertexPosition
for v = 1 to UVmod.numberVertices() do UVmod.setVertexPosition currentTime v ((sum as point3)/255)
)
)

rollout solidCols "Block colors"
(
button convertIt "Convert selected to solid"

on convertIt pressed do if selection.count>0 do undo "Convert to solid" on
(
t1 = timestamp()
m1 = heapfree
setWaitCursor()
local VCMat=standardmaterial diffusemap:(vertexColor())
local sel = selection as array
for o in sel where (classof o.material==standardmaterial) do
(
SetAvgColor o
o.material=VCMat
)
setArrowCursor()
format "time:% leak:%\n" (timestamp() - t1) (m1 - heapfree)
)
)
createDialog solidCols
0 Likes
Message 5 of 5

Anonymous
Not applicable
thanks that helped out a lot
0 Likes