PDA

View Full Version : Scaling Combined Objects


Daemonecles
05-30-2012, 11:32 PM
So I was working on this code today for the following situation:

I have a ton of cubes that are combined and skinned to a joint setup and I wanted to make a blendshape for it for random cube sizes. (So I can't separate the mesh, scale, then recombine or the vert orders will change to screw up the blend. So I needed a solution that dealt with the preexisting combined mesh.)

I wrote this script to take a combined object and given a number of verts and a min/max size for randomness, it would scale all of the objects broken up in increments of whatever the vert number is. This works GREAT on small numbers of cubes around 400 or so but then it gets SERIOUS memory issues and freezes up my entire machine. I tried to deal with that by throwing the history deleting line in there but it did nothing. Any help pleaaaaaaase? :cry:

P.S. - If anyone can point me to why the progress bar never actually works while hitting escape that'd be nice too!

edit: Trimmed down to only the necessary code.
global proc aw_combScale(int $vertIncr, float $min, float $max){
//Store Selection
for ($obj in `ls -sl`){
print ("Working on object: "+$obj+"\nFollow the Progress Bar\n");
//Setting local variables
int $vertTmp[1] = `polyEvaluate -v $obj`; //Store verts in current object in an array
int $vertCount = $vertTmp[0]; //Store verts in an int
int $incrVal = $vertIncr-1, $counter, $objCounter=0; //Initialize counters and array based incremental value (-1)
for ($counter=0; $counter < $vertCount; $counter+=$incrVal ){
print ("Scaling combined object number: "+$objCounter+"\n");
//Clear select, select a cube's vertex, grow selection to the whole cube
select -cl;
select -tgl ($obj+".vtx["+$counter+"]");
GrowPolygonSelectionRegion;
GrowPolygonSelectionRegion;
//Randomly move the verticies out locally to simulate scaling.
int $randVal = rand($min,$max);
polyMoveVertex -ltz $randVal;
$objCounter++;
delete -ch $obj; //Delete object history to keep object clean every time
}
}
}

gtbull80
06-02-2012, 09:18 PM
I think I need a little more instructions on how the script works.

I tried:
aw_combScale(1, 1, 3)

I got an infinite loop. How would you suggest I reproduce your issue?

Daemonecles
06-05-2012, 05:25 PM
Sorry about the dangerous code ;).

Basically what I do to test it is:
Create a bunch of cubes and move them around space so you can see all of them.
Combine the cubes
Delete the history
Run the script with these settings: aw_combScale(8,2,3);
It will take the combined mesh, and scale every 8 verticies in the object by a number between 2-3. So after running it you should see all your cubes different sizes.

procanic
06-05-2012, 06:41 PM
Have you tried turning undo off?

Daemonecles
06-05-2012, 07:05 PM
That has never occurred to me even once...let me check it out, but I'm not sure that's going to do it...sounds like voodoo ;)

Edit: Well who knew...I'd love to optimize my script so I don't have to do that when running it but it seems to have at least freed up all the memory while running the script. Cheers!!

procanic
06-05-2012, 07:48 PM
glad it works! :)
if you don't want to turn it off and on manually all the time, you can put this at the beginning of your procedure:


int $undoState = `undoInfo -q -state`;
undoInfo -state off;

and this at the end:

undoInfo -state $undoState;

that way it always switches back to its former state.
i always do this in procedures that do heavy operations like moving lots of vertices ...

Daemonecles
06-05-2012, 08:42 PM
Haha yeah, I threw that in there for good measure already. Thanks for the tip!

CGTalk Moderation
06-05-2012, 08:42 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.