Home Technical Talk

Maxscript - scripting Vertex Colour fails unless I do a manual assign once

polycounter lvl 18
Offline / Send Message
Rick Stirling polycounter lvl 18
Cross posting from the maxscript forum on CG Talk


I've written a script that takes lighting from a skylight and bakes ambient occlusion in the (any) vertex colour channel of a mesh.

I can't seen a problem with the script, however when I first run it I always get a pure black bake on the mesh UNLESS I manually assign the bake using the Assign Vertex Colours tool in the tool panel. After this the script works perfectly. I only need to do this once per max session, I can then load any model that I want, rebuild my lighting, pretty much do anything in max and the scripted assign vertex colours works.


The (stripped down) command to assign the colours is simple enough:

AssignVertexColors.ApplyNodes $ vertexPaint:$.modifiers[#VertexPaint]


Can anyone help me understand why I need to manually run the bake once per session? Is it just a max foible?

Replies

  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    I recently mixed a script that uses vertex colors and then bake it using RTT - and it works in just 1 click. It is based on this script:
    http://www.scriptspot.com/3ds-max/pits-peaks

    the order of things is something like this:
    for i = 1 to $.numVerts do(
    	local colr = color (random 0 255) (random 0 255) (random 0 255);
    	setVertColor $ i colr;-- apply vertex color
    )
    $.showVertexColors = true;
    $.vertexColorsShaded = false;	
    update $;
    

    hope that snippet gets you further
  • Rick Stirling
    Options
    Offline / Send Message
    Rick Stirling polycounter lvl 18
    Max has died at home, so I can't test if that 'update $' line will do the trick.

    I don't bake to a texture, I bake the AO into a vertex colour channel.

    I think it's just an initialisation thing, because after I manually assign the vertex colours once to any mesh in the scene the script works perfectly after that, and works until I next open max.
Sign In or Register to comment.