Complex UV Layout in Maya
Over the last couple of years UV layout in Maya has changed for the better. In this course we're going to be taking a look at some of those changes as we UV map an entire character
# 16 20-07-2007 , 09:57 AM
Alan's Avatar
Moderator
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Code:
string $stem = "dupes_";
string $suffix= "_GEO";

string $obj = "pTorus1";
string $dupeSel[] = `ls ($stem + "*" + $suffix)`;
int $numbVerts[] = `polyEvaluate -v $obj`;
int $i = 0;

for($i; $i < $numbVerts[0]; $i++)
{

//pick an object to duplicate
int $dupeInt = rand(0, size($dupeSel));

$dupeInt++;



float $pos[] = `xform -q -ws -t ($obj + ".vtx["+$i+"]")`;
string $new[] = `duplicate -rr ($stem + $dupeInt + $suffix)`;

setAttr ($new[0] + ".translateX") $pos[0];
setAttr ($new[0] + ".translateY") $pos[1];
setAttr ($new[0] + ".translateZ") $pos[2];


normalConstraint -weight 1 -aimVector 0 0 1 -upVector 0 1 0 -worldUpType "vector" -worldUpVector 0 1 0 $obj  $new[0];

}
you can delete the normal constraint if your object doesn't deform. If it does deform the objects should stick to the skin.

Alan


Technical Director - Framestore

Currently working on: Your Highness

IMDB
# 17 20-07-2007 , 10:09 AM
Falott's Avatar
Registered User
Join Date: Jan 2005
Location: vienna
Posts: 1,095
goddamnit! I seriously have to get into MEL soon!

thank you and have a nice day!


everything starts and ends in the right place at the right time.
# 18 07-08-2007 , 01:46 PM
Falott's Avatar
Registered User
Join Date: Jan 2005
Location: vienna
Posts: 1,095
I have another question concerning this script. I modified it a littel and it´s allmost working. my aim is to point+orientConstrain an array of objects to another.
this is the code -


string $stem = "dupe_";
string $suffix= "_GEO";
string $dupeSel[] = `ls ($stem + "*" + $suffix)`;
string $Leaves[] = `ls -sl`;
int $selCount = size($Leaves);


for($i = 1; $i <=$selCount; $i++)
{

int $dupeInt = rand(0, size($dupeSel));
$dupeInt++;
string $new[] = `duplicate -rr ($stem + $dupeInt + $suffix)`;

pointConstraint -offset 0 0 0 -weight 1 ($leaves)($new);
orientConstraint -offset 0 0 0 -weight 1 ($leaves)($new);


}





problem as you might have allready seen - the duped leaves get constrained, but only to the very first object in the list (string $Leaves[] = `ls -sl`; ). probably this command has to be changed, but I don´t know how to make use of all items of that array. I´m really stuck now.

tia!


everything starts and ends in the right place at the right time.

Last edited by Falott; 07-08-2007 at 01:50 PM.
# 19 07-08-2007 , 02:16 PM
Falott's Avatar
Registered User
Join Date: Jan 2005
Location: vienna
Posts: 1,095
btw - can anybody tell me some good books or other ressources for starting with MEL. I mean something for really non-logic thinking people like me.


everything starts and ends in the right place at the right time.
# 20 07-08-2007 , 05:27 PM
Alan's Avatar
Moderator
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
well remember that $leaves is an array. So you need to give it an element in the array to constrain to. I'm surprised that using $leaves as you are even works user added image

so you need to do something like

pointConstraint -offset 0 0 0 -weight 1 $leaves[5] $new;


or you could build up a string like what you have done for the $new variable where you add a suffix and stem to a randomly selected array index. does that make sense?

And as for resources I never bought a book or anything like that. Giving yourself projects like this and using the mel script resources are the best ways of learning IMHO

Alan


Technical Director - Framestore

Currently working on: Your Highness

IMDB
# 21 07-08-2007 , 08:42 PM
Falott's Avatar
Registered User
Join Date: Jan 2005
Location: vienna
Posts: 1,095
this

pointConstraint -offset 0 0 0 -weight 1 $leaves[5] $new;

would be nice if I just want to take the 5th element out of the array each time I suppose, but when trying to cycle through the complete array (I don´t know ho0w to) I get this error

// Error: pointConstraint -offset 0 0 0 -weight 1 ($Leaves[])($new); //
// Error: Line 15.50: Syntax error //


cause if I put a number into the [] it only constrains 1 element and then stops. it´s allmost the same when just using ($Leaves)($new), where it duplicates correctly but places all dupes onto one single object.


I too thought about using "stem" for the selected items. but I have some modeled branches with lots of different leaves with different shaders which I dont want to screw up each time. and as I have to repeat this procedure very often it would be nice to script it over the ls-sl command which is so very handy in this case.

I know what you mean Alan by learning with each project. but I am deeply intuitiv thinking. that´s why modeling fits me perfect. but as soon as code comes into place I start over and over again. code doesn´t like me. the above lines took me about 3 hours to get it "kind of" working.

thx for your help


everything starts and ends in the right place at the right time.
# 22 07-08-2007 , 09:53 PM
Alan's Avatar
Moderator
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
I meant you had to use a variable to randomly select an ID the same way you did above!! You need to do another random int and then use that to pick the correct one from the array.

Dont get disheartened. You'll get it eventually! user added image

Alan


Technical Director - Framestore

Currently working on: Your Highness

IMDB
# 23 08-08-2007 , 03:06 AM
Falott's Avatar
Registered User
Join Date: Jan 2005
Location: vienna
Posts: 1,095
HAHA! this one gave me a sleepless night ^^

($Leaves[$i])($new) user added image


BUT!

the only thing is now - the procedure starts with the 2nd item - constrainig them all is fine! but after duplicating the last Leave this one doesn´t get constrained and maya says:

// Error: line 15: No object matches name: //


guess I have it soon user added image


everything starts and ends in the right place at the right time.
# 24 08-08-2007 , 03:08 AM
Falott's Avatar
Registered User
Join Date: Jan 2005
Location: vienna
Posts: 1,095
!!!!!!


($Leaves[$i-1])($new)


woohooo!


your way of teaching is awesome!


everything starts and ends in the right place at the right time.
# 25 31-08-2007 , 04:17 AM
Registered User
Join Date: Aug 2007
Posts: 4
Hi,
how to get the immediate neighbor of some vertex v ??

please, help me!!

# 26 31-08-2007 , 04:43 AM
Alan's Avatar
Moderator
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Code:
global proc string[] getVertexNeighbours()
{
	string $res[];	
	string $myVertex[] = `ls -sl`;
	string $obj = `substitute "\.vtx.*" $myVertex[0] ""`;	
	

	select -cl;
	if(size($myVertex) > 1)
	{
		error("Select only one vertex!");
	}
	else
	{
		string $tmp[] = `polyInfo -vertexToEdge $myVertex[0]`;
		string $buffer[];
		
		tokenize $tmp[0] " " $buffer;

		string $connectedEdges[]; 
		
		int $i = 2;
		for($i; $i<size($buffer); $i++ )
		{
			if(strip($buffer[$i]) != "")
			{
				select -add ($obj + ".e["+$buffer[$i]+"]");
			}
		}
		

		string $ev[] = `polyInfo -edgeToVertex`;

		int $ii = 0;
		for($ii; $ii<size($ev); $ii++)
		{
			string $buffer[];
			tokenize $ev[$ii] " " $buffer;
			$res[size($res)] = ($obj + ".vtx[" + $buffer[2] + "]");
			$res[size($res)] = ($obj + ".vtx[" + $buffer[3] + "]");
		}
	}

	select $res;
	return $res;

}
try that
it's untested really but I just wrote it now.

user added image
Alan


Technical Director - Framestore

Currently working on: Your Highness

IMDB
# 27 01-09-2007 , 06:38 AM
Registered User
Join Date: Aug 2007
Posts: 4
thak u by help, 100% functioned!!!

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