PDA

View Full Version : MEL - Insert Edge Loop Tool


cppgraphics
11-25-2010, 01:59 PM
Hello folks,

I'm trying to create playing cards in MEL script.

How can I use Insert Edge Loop Tool in MEL script to create a round corner for the geometry? There is a command polySplitRing, but when I use it i couldn't specify the mouse location to select an edge of the geometry in the script. But in Maya, we can interactively select the particular position we need.

Please give me your suggestion, how can I resolve it?

Thanks,

Sebek128
11-25-2010, 03:22 PM
Command apart from tool does not work interactively.
When You use tool, You spot the place on insertion and then the command is being run with proper parameters.

Try reading polySpolitRing at http://download.autodesk.com/us/maya/2011help/index.html

The example of using it shows that You need to select edges first, then run command.


polyCube;
select pCube1.e[0:3];
polySplitRing -sma 180 -wt 0.2 ;

cppgraphics
11-25-2010, 03:33 PM
Command apart from tool does not work interactively.
When You use tool, You spot the place on insertion and then the command is being run with proper parameters.

Try reading polySpolitRing at http://download.autodesk.com/us/maya/2011help/index.html

The example of using it shows that You need to select edges first, then run command.


polyCube;
select pCube1.e[0:3];
polySplitRing -sma 180 -wt 0.2 ;




Thanks Sebek128 (http://forums.cgsociety.org/member.php?u=443880),

The I tired the above method, but the problem is I need to insert 4 polySplitRings, 2 each on near to both ends.

When I insert the first one, for the second one edges divided into small parts. and I couldn't get the equal size of the first edge loop.

Here's code I used and the result I got is

Code:

polyCube -ch on -o on -w 3.5 -h 0.01 -d 2.25 -cuv 4 ; select pCube1.e[6:7];
select -tgl pCube1.e[10:11];
polySplitRing -ch off -sma 30 -wt 0.1 -fixQuads 1;
select -cl;
select pCube1.e[6:7];
select -tgl pCube1.e[10:11];
polySplitRing -ch off -sma 30 -wt 0.1 -fixQuads 1;


Result:
http://d.imagehost.org/0625/polySplitRing.jpg

Nyro
11-25-2010, 05:50 PM
if you need multiple, evenly spaced edgeloops, you don't want to perform the polySplitRing command multiple times (since it works with weights, which is simply a percentage of the distance between surrounding edgeloops).
Well, strictly, you *could* do it that way, by adapting the weight of each subsequent step to reflect the same absolute percentage with regards to the new (now smaller) distance between surrounding edgeloops. you start with edgeloops A and B.


|---------------------| //split with weight of 0.5

//result: edgeloops A, B, C (left to right)

|----------|----------| //split again with the same weight

//result: edgeloops A, B, C, D (left to right)

|----|----|-----------| //edge position not really accurate here

etc.

so if you wanted 4 splits that means you'd end up with a total of 6 edgeloops, first at 0, last at 1, 4 inbetween. So each loop would have to be positioned at a weight of (i * 1/6), where i is the current number of the edge you're inserting.
But, as I mentioned, each subsequent step has a reduced distance between the edgeloops A and B as sketched above. So you have to take that into account, because you're after evenly spaced edgeloops.

So the second iteration, for example, has a distance of ( 4/6 * AB). The absolute weight at step 2 is 2/6 * AB.
Let AB be 1. The second step edgeloops shoudl be inserted at approx. 0.333 (in terms of weight of the original edge distance AB). If you look at my ASCII sketch above, we're asking: x * BC = AC.
...
I just realised I'm too tired to go further with this explanation, because eventually it really just leads to this one line of code:

int $i = 4; //how many evenly spaced loops do you want?

polySplitRing -stp 2 -div $i


Maya operates on the same commands that are available to you in MEL. Its reasonable to assume, then, that if you can define 'Multiple Edgeloops' in the Insert Edgeloop Tool's tool settings window, then the related command has that kind of option too.

Problem solved?

cppgraphics
11-25-2010, 06:46 PM
Thanks Nyro,

I can understand your explanation, but my need is I have insert edge loops in the following order.

http://d.imagehost.org/0211/MG_5404.jpg

My problem is when I insert the first edgeloop, the previously selected edges are spiliting and getting assigned new edge numbers.

how to solve this?

Sebek128
11-25-2010, 08:12 PM
Only one of new edges gets new number.
Maybe this is a satisfying solution for You?


polyCube -ch on -o on -w 3.5 -h 0.01 -d 2.25 -cuv 4 ;
polySelect -er 7;
polySplitRing -ch off -sma 30 -wt 0.9 -fixQuads 1;
polySelect -er 1;
polySplitRing -ch off -sma 30 -wt 0.9 -fixQuads 1;
polySelect -er 5;
polySplitRing -ch off -sma 30 -wt 0.9 -fixQuads 1;
polySelect -er 7;
polySplitRing -ch off -sma 30 -wt 0.1 -fixQuads 1;
polySelect -er 1;
polySplitRing -ch off -sma 30 -wt 0.1 -fixQuads 1;
polySelect -er 5;
polySplitRing -ch off -sma 30 -wt 0.1 -fixQuads 1;


For precise division 0.1 should be replaced with something like 0.111111 I think.

Nyro
11-25-2010, 08:45 PM
I'm sorry, I absolutely mis-read your original post. I now understand what your problem is.

Here's a solution.

float $cornerSharpness = 0.8;
float $cardThickness = 0.1;

// create Plane object
string $plane[] = `polyPlane -w 10 -h 16 -sx 1 -sy 1`;

// select first two opposite edges
select ($plane[0] + ".e[0]");
select -add ($plane[0] + ".e[3]");

//insert two edgeloops
polySplitRing -stp 2 -div 2;

// the new edgeloops are selected directly after split
// so simply perform a pickwalk left
pickWalk -d left -type edgeLoop;

// store the edges contributing to this edgeloop (just one at the moment)
string $vLeftLoop[] = `ls -sl -fl`;

// do the same in the other direction for second edgeloop
pickWalk -d right -type edgeLoop;
string $vRightLoop[] = `ls -sl -fl`;

// convert to edgeRing to select the other edges
// that need to be split. Convenient.
pickWalk -d left -type edgeRing;

// insert edgeloops again
polySplitRing -stp 2 -div 2;

//store the edges representing the edgeloop
pickWalk -d left -type edgeLoop;
string $hBottomLoop[] = `ls -sl -fl`;
// and again, as described above
pickWalk -d right -type edgeLoop;
string $hTopLoop[] = `ls -sl -fl`;

// the vLeftLoop and vRightLoop are now out-of-date.
// New Edges have been created and need to be included
// in the storage variable.
//
// To do this, simply select each edge via variable, then
// perform a pickwalk to convert to the complete edgeloop
// Finally, store again.

select $vLeftLoop;
pickWalk -d left -type edgeLoop;
$vLeftLoop = `ls -sl -fl`;

select $vRightLoop;
pickWalk -d left -type edgeLoop;
$vRightLoop = `ls -sl -fl`;

// The last steps (updating the variable) might have been
// skipped, to instead simply perform the following steps
// while the respective edgeloops were selected. But we
// like to make sure everything is in order, no?


// This should work, yet does nothing. No idea why.
polySlideEdge -ed $cornerSharpness -d 0 -a $vLeftLoop;
polySlideEdge -ed $cornerSharpness -d 1 -a $vRightLoop;

polySlideEdge -ed $cornerSharpness -d 0 -a $hTopLoop;
polySlideEdge -ed $cornerSharpness -d 1 -a $hBottomLoop;

// finally, extrude the object for some thickness
select $plane[0];
polyExtrudeFacet -ltz $cardThickness;



Note the code in red. I've hit a wall here. I have absolutely no idea why performing an edgeSlide via MEL simply doesn't work. I'm stumped. But the theory is sound. Sliding each edgeloop in the right direction by the right amount (which you can set in the first line's variable) should position each edgeloop just how you want them, independant of the object's size.

If someone else can figure out why this isn't working, you'll be all set.

cppgraphics
11-26-2010, 12:53 PM
Hi Nyro & Sebek128,

Thank you guys for your solutions. Both methods are working fine, from Nyro's method I learned how to travel through a selection. Sebek's approach bit simpler.

Cheers,
Suresh

Nyro
11-26-2010, 12:59 PM
Well, the easiest approach to something like this, i.e. when you can't figure out a way to know which components are needed or what the logical order of steps is, would be to simply create the object and perform all the steps manually. You then simply need to 'record' whatever it is you did (using the script output as reference) and replicate that in your code, generalizing wherever you can.

cppgraphics
11-26-2010, 04:00 PM
Well, the easiest approach to something like this, i.e. when you can't figure out a way to know which components are needed or what the logical order of steps is, would be to simply create the object and perform all the steps manually. You then simply need to 'record' whatever it is you did (using the script output as reference) and replicate that in your code, generalizing wherever you can.

Actually I tried that, by default in maya they use the following commands.
hilite pCube1 ; selectMode -component ;
polySplitRing -ch on -splitType 1 -weight 0.2 -smoothingAngle 30 -fixQuads 1 ;




But when I use the same in MEL, I'm getting this error.
// Error: This command requires at least 1 argument(s) to be specified or selected; found 0. //

Nyro
11-26-2010, 04:20 PM
Yeah, well you shouldn't simply copy and paste. That seldomly works. Just like there is no magic 'create awesome 3D model and render it' button, using the script Editors output as reference does require some thinking on the user's part :)

The error tells you all you need to know: you need to select an object (rather: component) before you can perform a polySplitRing. Or, you have to supply a selectionList at the end of the command.

If you do it manually in Maya, you probably just clicked somewhere with the InsertEdgeLoop command, presumably on an edge. THis is because by clicking 'Insert Edge Loop', you're actually entering a special Context, which only allows for special selections and automatically passes these selections on the command linked to the context.

Read the commands reference for more info on how Contexts work.

cppgraphics
11-26-2010, 06:46 PM
If you do it manually in Maya, you probably just clicked somewhere with the InsertEdgeLoop command, presumably on an edge. THis is because by clicking 'Insert Edge Loop', you're actually entering a special Context, which only allows for special selections and automatically passes these selections on the command linked to the context.

Read the commands reference for more info on how Contexts work.

Of course, you are right.

When I saw the error message, I thought we have approach this issue by capture mouse point position as like manual creation.

But later from you guys explanation about different selection methods in polygon and the use of weight, I realised everything.

FYI: This is my first MEL scipt. :)

CGTalk Moderation
11-26-2010, 06:46 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.