Home Technical Talk

Maxscript : animation and progress bar

polycounter lvl 6
Offline / Send Message
TweaK polycounter lvl 6
Hi :)

I wrote a simple maxscript to animate Vertex Colors in 3dsmax.
What it does is : copy color, illumination and alpha vertex channels to different frames, making a vertex color animation :)

Now that it is working, I added a progress bar to let the user know 3ds is actually doing something. I did this also to allow operation cancelling, since the easiest way to do this is to use the Cancel button near the progress bar.

And then, surprise : the script does work, some animation curve are created, but vertex colors are not (I see no animation in viewport).

Here's what I do (simplified) :
--setting up progress bar

local cancelOps = false
progressStart "Converting vertex channels"

--loop trough object array

for i=1 to nbObj while not cancelOps do
(

local o = objectSelection[i]

--adding an unwrap_UVW modifier to the object

local uvwPaint = unwrap_UVW()
uvwPaint.name = "Vertex Channels Anim"
addModifier o uvwPaint

--
--(retrieving data in arrays)
--
--vertex arrays are built like this :
--[face 1]
-- [vertex 1] vertex map ID, color
-- [vertex 2] vertex map ID, color
-- [vertex 3] vertex map ID, color
--[face 2]
-- [vertex 1] vertex map ID, color
-- [vertex 2] vertex map ID, color
-- [vertex 3] vertex map ID, color
--etc...
--
--
--color array is like this :
--[vertex 1] vertex map ID, color1, color2, color3
--[vertex 2] vertex map ID, color1, color2, color3
--etc...
--

--auto key on
--this is needed to paste colors on different frames but I wonder why

animButtonState = true
		
--paste each color on a different frame using the unwrap_UVW modifier !

mapCurrVert = 1
for k=1 to colorIndex.count while not cancelOps do --loop trough faces array
(
	for v=1 to colorIndex[k].count while not cancelOps do --loop trough vertices array
	(
		uvwPaint.setVertexPosition 0f channelColor[mapCurrVert][1] channelColor[mapCurrVert][4]
		uvwPaint.setVertexPosition 1f channelColor[mapCurrVert][1] channelColor[mapCurrVert][3]
		uvwPaint.setVertexPosition 2f channelColor[mapCurrVert][1] channelColor[mapCurrVert][2]
			
		if not (progressUpdate totProgressPercent) then
		(
			cancelOps = true
		)
				
		mapCurrVert += 1
	)
)

animButtonState = false --auto key off
)

--remove progress bar
progressEnd()

This piece of code works if I just comment out the progress bar related stuff, but as soon as I active it, it stops. Not completely anyway, since I HAVE an animation in the modifier, but nothing happens in the viewport :(

Did I do something wrong ?? :)


Also, I don't understand why I have to set Auto Key to "on" in order to paste vertex uvw animation... The script is sloooowweeer too !

If someone have any suggestion, feel free to drop it ^^
I'm really stuck with this... :(

Thanks in advance :poly121:

Replies

  • monster
    Options
    Offline / Send Message
    monster polycounter
    You'll need to paste working code if you want help debugging. My guess is that the progress bar disables the command panel, and the unwrap modifier is dependant on the command panel being active. Nothing you can do about that. Maybe you can create a dialog with a progressbar, but of course this won't have a cancel button. I usually just set EscapeEnable to true and tell users to hold escape if they need to quit the process.

    Here's a few tips to speed things up.

    Try uvwPaint.setVertexPosition2 with the hold and update variables set to false.
    Don't use .count in the for loop. Instead save the .count to a variable and use the variable.
    Try using:
    for i=1 to nbObj while not cancelOps do with animate on with redraw off with undo off
    
  • TweaK
    Options
    Offline / Send Message
    TweaK polycounter lvl 6
    Hi ! :)

    Thank you for the tip, I used escapeEnable and it's working great with a progress bar in a dialog :)
    I also tried to use uvwPaint.setVertexPosition2 but I didn't see any difference.

    Also, I came across this thread : http://forums.cgsociety.org/archive/index.php/t-1042236.html
    I tried to do it that way, and it seems really faster (even if I have to make one loop per frame to create the animation).

    ps : I didn't paste the whole code because it's actually messy after a lot of back and forth trying to find a way to make it work, so I'd thought it would be cleaner that way :)


    EDIT : I came across another problem : it seems that sometimes, the amount of polygons on an object is not accurate : if I activate the viewport statistics, there's more polygons than if I select every polygons using an editable poly.

    Does anyone know how to solve this bug ?
Sign In or Register to comment.