View Full Version : Random Variation in geometry via scripting
WACOMalt 02-24-2008, 12:30 AM Hello, I need a little help in a model I am making. I have modeled a shack for an asset in compositing. I have individual bricks making up the walls (Lots of bricks, and for a good reason) Anyways, all of th ebricks are layed perfectly flat right now, which looks unnatural.
I need to add random xforms to all of the bricks individually to add slight imperfections overall.
I have the following mel script written, which adds my current selected objects to an array, then run a for-in loop on the array. However it it not working as I had hoped. It is moving the whole selection at once. Can anybody see what changes I need to make?
string $buildingparts[] = `ls -sl`;
for ($current in $buildingparts)
{
move (rand (-1, 1)) (rand (-1, 1)) (rand (-1, 1));
}
thanks in advance!
| |
Troy McClure
02-24-2008, 02:33 PM
I guess that your wall is in a group, isn't it?
When you select the group the command "ls -sl" return only the selected group
Wall---- //Select this
|-Brick1
|-Brick2
|-Brick3
\_Brick4
ls -sl will return "Wall"
You can select the brick by hand (boring) or you can let MEL do the boring work :)
select -replace -hi; // this will select all the children of your selection
//You have to add the -tr flag to select only the transform node ^_^
string $buildingparts[] = `ls -sl -tr`;
for ($current in $buildingparts){
move (rand (-1, 1)) (rand (-1, 1)) (rand (-1, 1));
}
WACOMalt
02-25-2008, 11:28 AM
Thanks for the help, I will defanitely try this.
Thing is though, I select them via a marquee, not a group, so isn't that the same as selecting one at a time? and thus, shouldn't my script work?
what seems to be the problem, is that when maya generates the random numbers, it uses the same numbers on all objects in the loop., I was under the influence that since it runs the random number command again for each brick it would get a different set of numbers, which seems to not be the case. would me not haveing the -tr be causing what I was seeing?
anyways, like I said I will try your suggestion when I get to school today, and other good ways to get random movement? I was actually thinking turn them all to rigid bodies with collisions off, and apply a turbulance field. then delete history.
WACOMalt
02-26-2008, 11:53 PM
Ok, so I tried the script with the changes you suggested, and I still get the same problem: everything selected is moving as though it's one object.
I am now at a loss, anyone got any other ideas?
bunker
02-29-2008, 01:07 PM
Simple, you need to use "xform";
that little script of mine apply a slight random offset in Y coordinate :)
here you are :
// random offset in Y axis
float $randomOffset;
string $objectArray[] = `ls -sl`;
// loop through the selected objects
for ($oo=0;$oo<size($objectArray);$oo++)
{
$randomOffset = (rand(100)/100.00) - (rand(100)/100.00);
string $currentObject = $objectArray[$oo];
// xform -relative -translate x y z objectname
eval xform -r -t 0 $randomOffset 0 $currentObject;
}
hope you like it :)
Troy McClure
02-29-2008, 01:28 PM
Ups, I almost forgot this post...
I didn't try the bunker solution but the real problem in the first script is that you/we forgot to specify the object that you want to move.
select -replace -hi;
string $buildingparts[] = `ls -sl -tr`;
for ($current in $buildingparts){
move -r (rand (-1, 1)) (rand (-1, 1)) (rand (-1, 1)) $current;
};
So maya apply the translation to every object n times.
bunker
02-29-2008, 01:41 PM
Troy ! that works too and the code is smaller - nice one !
The good thing about using xform is that you can also get(query) the values
of translation/rotation/scale/pivots - it's like an all-in-one function :)
WACOMalt
02-29-2008, 06:25 PM
Thank you guys, those worked like a charm!
I also found another script out there that is made for what I needed. It is called jcChannelRandomizer Window.
here is a link (http://highend3d.com/maya/downloads/mel_scripts/modeling/misc/jcChannelRandomizerWindow-4252.html)
It basically lets you select any objects, select channels, and then type in your desired range of randomness, and hit randomize.
Thank you for helping me with my script as well. I am quite rusty with mel now it would seem.
Cindy123
03-03-2008, 07:20 AM
I said I will try your suggestion when I get to school today, and other good ways to get random movement? I was actually thinking turn them all to rigid bodies with collisions off, and apply a turbulance field. then delete history.
Cindy.
CGTalk Moderation
03-03-2008, 07:20 AM
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.
vBulletin v3.0.5, Copyright ©2000-2009, Jelsoft Enterprises Ltd.