How to access each vertex of a polyCube and move it randomly??

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  06 June 2009
Smile How to access each vertex of a polyCube and move it randomly??

Hi MEL Masters,

I have a query for all MEL experts. I am new to MEL, so I am in a learning phase right now.

The problem is that I have created a polyCube in Maya. Like all cubes, it has 8 vertices. What I'm trying to do is that I want each and every vertex of the polyCube to move at a random X,Y,Z position thereby creating a deformed cube.

The solution in my mind is that first i create three variables as;

float $Xpos = rand(-12,12)
float $Ypos = rand(-12,12)
float $Zpos = rand(-12,12)

and then assign these variables as X,Y,Z position of each vertex like;

move $Xpos $Ypos $Zpos;

I understand that for this I have to use the for() loop so that each time a distorted cube is created it will have a different shape.

Finally i will make a procedure that will accept the number of distorted cubes as input form the user and gives the result. Something like;

global proc CreateDistortedCubes(int $NoOfCubes)


If anyone can write me a MEL for this or at least give me a clue in the form of a chunk of code, i'll be greatful.

I can handle the for() loop on my own. I just want to know how to access each vertex of a polyCube through MEL, and move each vertex dynamically through rand() command.

Thank you.
 
  06 June 2009
Hi,

Here's a crude example.

You might want to mess about with the move command flag, -relative & -absolute.
You could also load the procedure into memory, and place distortObj(-1, 1) in an expression to
get some random animation going.
Should work for any number of objects selected.

 
global proc distortObj(float $randomA, float $randomB)
{
float $Xpos;
float $Ypos;
float $Zpos;
string $sel[] = `ls -sl`;
int $vtxCount[];
int $k = 0;
for ($each in $sel)
{
int $vtxInfo[] = `polyEvaluate -vertex $each`;
$vtxCount[$k] = $vtxInfo[0];
$k++;
}
for ($i=0;$i<size($vtxCount);$i++)
{
	for($j=0;$j<($vtxCount[$i]);$j++)
	{
	 $Xpos = rand($randomA, $randomB);
	 $Ypos = rand($randomA, $randomB);
	 $Zpos = rand($randomA, $randomB);
	 move -r $Xpos $Ypos $Zpos ($sel[$i] + ".vtx["+$j+"]");
	}
}
}
 
//example
distortObj(-1, 1)


Hope that helps.


__________________
vimeo
blog

Last edited by mlefevre : 06 June 2009 at 09:47 AM.
 
  06 June 2009
Thumbs up Thanks

Hey it worked. Thank you so much. I owe you bro..

Can I have your email address??
 
  06 June 2009
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 09:31 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.