Digital humans the art of the digital double
Ever wanted to know how digital doubles are created in the movie industry? This course will give you an insight into how it's done.
# 1 19-10-2011 , 06:13 PM
iamcreasy's Avatar
Registered User
Join Date: Jun 2008
Location: Dhaka, Bangladesh
Posts: 168

Re positioning objects centering a certain point

Say I have several objects centering a certain point. Now I want to randomize their circular arrangement.

For example, say, X is the center and from 12'o clock position if you start picking clockwise, you get the following arrangement, A B C D E F

Now, what is the easiest method, so I can randomize their arrangement. Like C A B F E D or anything. They will still center the point X. I just want to interchange their positions randomly.

any script or any method is maya to do that?

Thanks!

# 2 19-10-2011 , 08:13 PM
publicFunction's Avatar
Senior Software Developer
Join Date: Jan 2005
Location: Livingston, Scotland
Posts: 1,701
Creasy,

I am not 100% sure what you want, but Maya's Duplication Options allow you to duplicate an object a number of times around the X, Y or Z co-ords specified by the number of degrees in those co-ords. The option is in Edit > Duplicate Special, see how that foots your bill. Otherwise it's time to learn MEL or Python to do it.


Chris (formerly R@nSiD)
Twitter
When the power of love overcomes the love of power the world will truely know peace - Jimmy Hendrix
Winner SM VFX Challenge 1
3rd Place SM SteamPunk Challenge (May 2007)
# 3 19-10-2011 , 08:17 PM
iamcreasy's Avatar
Registered User
Join Date: Jun 2008
Location: Dhaka, Bangladesh
Posts: 168

Creasy,

I am not 100% sure what you want, but Maya's Duplication Options allow you to duplicate an object a number of times around the X, Y or Z co-ords specified by the number of degrees in those co-ords. The option is in Edit > Duplicate Special, see how that foots your bill. Otherwise it's time to learn MEL or Python to do it.

Hmm, I know about that one. But, I was asking otherwise. Like you select all those objects(their pivot is the same) and click the magic function, and all their position is randomized. But, on only Y-axis, retaining the same pivot.

# 4 19-10-2011 , 09:29 PM
ctbram's Avatar
Moderator
Join Date: Jan 2004
Location: Michigan, USA
Posts: 2,998
one appraoch would be to ...

create an array of objects O[] from 1 to n.

subroutine swap
{
pick a random index i from 1 to n
if i != n then swap O[i] with O[n]
pick a random index i from 1 to n-1
if i != n-1 then swap O[i] with O[n-1]
now swap the <x,y,z> attributes of the objects in O[n] and O[n-1]
}

every time you call swap() two objects will swap positions

I will leave it to you to create the python or mel code.


"If I have seen further it is by standing on the shoulders of giants." Sir Isaac Newton, 1675

Last edited by ctbram; 19-10-2011 at 09:34 PM.
# 5 20-10-2011 , 02:21 AM
ctbram's Avatar
Moderator
Join Date: Jan 2004
Location: Michigan, USA
Posts: 2,998
Okay I keep wanting to learn mel so this is as good a way as any.

I listed some pseudo above for an algorithm to randomly swap the positions and orientations of pairs of objects. Below is the code I came up with. It takes the current selection of objects and each time it is run two objects positions are swapped.

Keep in mind I have never spent much time writing mel and every thing in this script I learned in about 10 minutes of googling things on the net so I am pretty sure anyone that really knows the proper way to write mel will realize it is probably total crap so feel free to make improvements but please do not beat me up to much for the effort.



string $select[] = `ls -sl`; // get current selection
int $l = size($select); // get the number of objects in the selection
int $i;
string $temp;

/*
pick a random index from 0 to $l-1
if it's not the index of the last item
swap the items at $i and $l-1
*/
$i = rand(0,$l-1);
if ($i != $l-1)
{
swap($i, $l-1, $select);
}

/*
pick a random index from 0 to $l-2
if it's not the index of the second to last item
swap the items at $i and $l-2
*/
$i = rand(0,$l-2);
if ($i != $l-2)
{
swap($i, $l-2, $select);
}

print $select; // print the selection array, the last two items will be swapped
swapPos($select[$l-1], $select[$l-2]);
print ".....................";


// procedure to swap two objects in the array $select[]
proc swap(int $i1, int $i2, string $select[])
{
string $temp;
$temp = $select[$i2];
$select[$i2] = $select[$i1];
$select[$i1] = $temp;
}

// procedure to swap the position and orientation of two objects
proc swapPos(string $obj1, string $obj2)
{
float $tx,$ty,$tz;
float $rx,$ry,$rz;

$tx = `getAttr($obj1 + ".translateX")`;
$ty = `getAttr($obj1 + ".translateY")`;
$tz = `getAttr($obj1 + ".translateZ")`;
$rx = `getAttr($obj1 + ".rotateX")`;
$ry = `getAttr($obj1 + ".rotateY")`;
$rz = `getAttr($obj1 + ".rotateZ")`;

setAttr($obj1 + ".translateX") `getAttr($obj2 + ".translateX")`;
setAttr($obj1 + ".translateY") `getAttr($obj2 + ".translateY")`;
setAttr($obj1 + ".translateZ") `getAttr($obj2 + ".translateZ")`;
setAttr($obj1 + ".rotateX") `getAttr($obj2 + ".rotateX")`;
setAttr($obj1 + ".rotateY") `getAttr($obj2 + ".rotateY")`;
setAttr($obj1 + ".rotateZ") `getAttr($obj2 + ".rotateZ")`;

setAttr($obj2 + ".translateX") $tx;
setAttr($obj2 + ".translateY") $ty;
setAttr($obj2 + ".translateZ") $tz;
setAttr($obj2 + ".rotateX") $ry;
setAttr($obj2 + ".rotateY") $ry;
setAttr($obj2 + ".rotateZ") $rz;
}

and here is a short video showing how it works...

how to mel scripte to randomly swap obj positions - YouTube


"If I have seen further it is by standing on the shoulders of giants." Sir Isaac Newton, 1675

Last edited by ctbram; 20-10-2011 at 02:36 AM.
# 6 20-10-2011 , 03:14 PM
iamcreasy's Avatar
Registered User
Join Date: Jun 2008
Location: Dhaka, Bangladesh
Posts: 168
Thank you very much. You are awesome user added image

I would edit this script for my need.

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads