PDA

View Full Version : how to make a loop to select components of Polygon objects in turn?


Joscoon
10-19-2008, 06:51 PM
Hi, I'm very new to Mel and am trying to figure out a script to do the following:

Let's say I have a Poly sphere made up of over 500 vertices, and I have about 500 Poly planes that I want to snap to each of those vertices on the Sphere. The poly sphere is called pSphere1 and the planes are numbered pPlane1 to pPlane500. Now I can select a vertex of a plane and then shift select a vertex of the sphere and choose Modify>snap align objects> point to point. But, I don't want to have to do this 500 times http://www.digitaltutors.com/chit_chat/images/smilies/smile.gif. Can anyone help me write a script to loop the procedure? Thanks so much! http://www.digitaltutors.com/chit_chat/images/smilies/bow.gif

nelsonteixeira
10-20-2008, 08:19 AM
I could write something like thiss for you. But I guess you should be more precise, otherwise Iīll write something that is useless. You mean the 500 hundred planes are already positioned? and you only need to align 1 vertice to each vertex on sphere???

Forgot to ask... is this for sort of a feather thing?? You could extrude the edges out... and even use a ranomize attribute on extrude node. Anyway... Iīm shooting in the dark... how am I supposed to guess? :D

Joscoon
10-20-2008, 09:34 PM
Hey thanks for the response,
Well, you're actually right I want this to add feathers to a character and I don't think maya fur will be convincing enough. Or render that well. Here's and example:

http://www.youtube.com/watch?v=rkzJ6ntjE-E

Does not necessarily have to be that complex.. just something to line up the feathers so I can attach them.

As far as the extruding edges I'm worried that texturing will be a problem...

Any help you can offer I will be most grateful for.

nelsonteixeira
10-21-2008, 09:25 PM
Still about the extruding edge... about texturing you would have to select all the feather faces, open the UV-editor and select Polygons>Unitize.

Unless you are going to make the dynamic... but using 400 or more constraints show slow the things up.

Sorry... I didīnt have the time to write the loop thing. Could not be useful on this specific task but, it will be priceless on many others. Thatīs how I started scripting in MEL.

Iīll try to write out a cool example for you, OK??

Joscoon
10-22-2008, 06:12 AM
sure would appreciate an example. In the meantime I think i'm gonna just bump map the feathers! lol

nelsonteixeira
10-23-2008, 10:34 PM
The example on how to automate repetitive tasks...

//ntCubesOnVertices

{
// grab the current selection

$sel = `ls -sl `;


// get how many vertices exist in the polygon object selected

int $eval[] = `polyEvaluate -v`;

// storing the number on a variable
int $countVertices = $eval[0];

// loop to cycle thru all vertices, and create a cube on each oneīs position


for ($i=0; $i<$countVertices; $i++)
{
// creates a cube (personal options just to make it smaller than the default one)
// the "-n" flag is to rename it proprerly based on name and current vertex

$currentCube = `polyCube -w 0.1 -h 0.1 -d 0.1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1 -n ("ntCube_" + $i)`;

// get the world position of the current vertex

$pos = `xform -q -ws -t ($sel[0] + ".vtx[" + $i + "]")`;


// move the new created cube to the world position collected before.

move -a $pos[0] $pos[1] $pos[2] $currentCube;
}

}



In your case you would need to create a plane instead and set the pivot point to its proper edge.
But you still would have to figure out orientation to aligns the plane perpendicular to the edge,
and get the effect of being extruded out from the edge.

Thereīs several other ways... one thing thatīs coming to my mind now is for each selected vertex create a cluster,
create a temporary point constraint like:


delete `pointConstraint currentCluster currentPlane`;

I still guess (for the feather thing), its easier (duplicate the object first), extruding the edges
with keep faces together OFF, then delete the "non-feather faces", last, mapping the feathers using
unify UVs.

Hope this help in any way.


Cheers,

Nelson

Joscoon
10-28-2008, 05:30 PM
Thanks so much for the example man. I will definitely give it a try. Right now I'm just focussing on the animation. Cheers.

CGTalk Moderation
10-28-2008, 05:30 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.