PDA

View Full Version : mel: get coordinates from an edge


iC4
05-25-2002, 02:11 PM
after I tryed the demo version of nendo I really like the connect edge tool (hope thats the right name)

it works like this: you select for example 2 edges, press the connect edge button and the edges get splitted in the middel (also the face)

Now I want tro write my own connect edge script and I think it can't be that hard (I hope so :bounce: )

To do this all I need is to get the middle coordinates of the selected edges and use then the polySplit command.

So my question is how I get the coordinates from the two vertexes which are at the end of the edge, or how I get the middle point of the edge

klod
05-25-2002, 05:08 PM
Hi,

You can do that:

select -r $edge;
PolySelectConvert 3; // Converts the selection to vertices
string $verts[] = `ls -sl -fl`;
float $posVert0[] = `pointPosition -w $verts[0]`;
float $posVert1[] = `pointPosition -w $verts[1]`;

// And for the midpoint:
float $midPoint[] = { ($posVert0[0]+$posVert1[0])/2,
($posVert0[0]+$posVert1[0])/2,
($posVert0[0]+$posVert1[0])/2 };

I hope this helps.
Klod

klod
05-25-2002, 05:09 PM
oups, I was to fast for the midpoint:

// And for the midpoint:
float $midPoint[] = { ($posVert0[0]+$posVert1[0])/2,
($posVert0[1]+$posVert1[1])/2,
($posVert0[2]+$posVert1[2])/2 };

-wT-
05-25-2002, 05:11 PM
I've been planning on doing a connect script too :)
One idea I've had, is that first the script would save all the verticles to a string, then the script would do a subdivide to the select edges, so now the edges have a verticle in the middle, then it would compare the string with all the previous verticles with a new "ls -sl" command and selecting them, so now we have the subdivided verticles selected, I think polysplit (or whatever the name was for that command) can work with verticles as the parameters?

Other way would be to convert the edge selection to verticles, then someway avarage the coordinates of the verticles from same edge, to get the middlepoint, and then using polysplit.


I'm not an expert in MEL, but tell me if those were any help? :)

klod
05-25-2002, 05:17 PM
isn't there such a mel script in the new Game Bonus package released this week by A|W ?

Mikkel Jans
05-25-2002, 07:54 PM
I have tryed to make a script like that ones.
But i ran into a problem.. Maya dosen't return the edges the way you selected them.
It will allways work with only 2 edges. But if you have more then 2 edges it will not allways work.
I have never relly understood how Connect Edge Scripts work. If you just select some edges in some random order it will connect them anyway. How does the computer know which edges it's gonna split together? It has nothing to do with the order you select them and nothing to do with the distance from eachother. I can't see how they relly works.

But heres my mini script..

string $input[] = `filterExpand -sm 32`;
string $first[];
string $second[];
int $edgeNum[0] = {0};
for ($step = 0; $step < size($input); $step++)
{
tokenize $input[$step] "[" $first;
tokenize $first[1] "]" $second;
$edgeNum[$step] = $second[0];
}
print $edgeNum;
string $polySplitThis = "polySplit";
string $epFlag = "-ep";
float $newEdgeLength = 0.5;

for ($split = 0; $split < size($edgeNum); $split++)
{
$polySplitThis += " " + $epFlag + " " + $edgeNum[$split] + " " + $newEdgeLength;
}

eval ($polySplitThis);
select -cl;

-wT-
05-25-2002, 10:41 PM
(Damn I'm getting pissed 'cos I have so much ideas for all kinds of stuff, but can't code them in... ARGH!)

Well Mikkel, I have this one idea, as I was just thinking about that one myself yesterday... so, to connect two edges, they must share the same face right? Well you could make a brute force test of converting the edge selections to face for every edge separately, and then check which of the other edges (if any at all) share the same face, then connect these two edges, and then move to the next edge in the selection...
I hope even someone understood any of that ;)

Mikkel Jans
05-26-2002, 08:04 AM
Ah thats a good idea. But it wont work before you have a Connect Vertex Script.
But how can you create a script that connect 2 vertices?.
You just need such a script and it will be possible to make a Connect Vertices and Connect Edges script.

Mikkel Jans
05-26-2002, 08:46 AM
I think i know how to do it now.. But i think the script would be relly slow that way..

-wT-
05-26-2002, 01:05 PM
I think we should share the scripts we've done so far, so we can improve them all together?

Mikkel Jans
05-26-2002, 01:16 PM
I have made a script which connect 2 vertices together:

www.maya3d.dk/temp/connectVert.mel

It wont work with more then 2 vertices.
I don't know how to connect more vertices..
It works this way:

First it convert each vertex to Edge and remember them.
Then it converts the 2 vertices to Faces and remember them.
Then it take the face that they both share and convert it to edges and remember them.
Then it finds the edges that they both share from each vertex.
Then it takes to random edges from each vertex side and split them.
It then takes the new vertices and snap them to the vertices to selected in the begining and merge them together.

But i can't see how to get it work with more then 2 vertices.

Mikkel Jans
05-26-2002, 08:50 PM
Ok now you can connect more then 2 vertices:

www.maya3d.dk/temp/connectVertex.mel

But it is a bit slow.

Goristro
05-28-2002, 05:38 AM
Try:
Edit Polygon > Merge Vertice

You can merge many vertices, within a thresh-hold. I'm not sure if that's what you guys are looking for, but give it a whirl.

:buttrock:

-wT-
05-28-2002, 02:25 PM
Heh, thanks for the tip, though that's not what we're trying to do ;)
Merge verticles merge the two into one, connect connects the two with a new edge.

Mikkel Jans
05-28-2002, 02:28 PM
Haven't you tryed my script?
It should connect your selected Vertices. But it's slow and you can't select vertices which share face with more then 2 other vertices... but i think i know how to fix that.

Mikkel Jans
05-30-2002, 06:33 PM
I have made a Connect Edges script now that isen't slow.
You can download it at Highend3d.com.

iC4
05-30-2002, 07:16 PM
THATS GREAT! Thx very much :beer:

-wT-
05-30-2002, 07:19 PM
Are you planning on developing it more? It's just that I'm just doing my own script, and I think I'll finish this just for practice, and I'm planning on adding some other features too, but would like to know if my work will be completely useless?

Mikkel Jans
05-30-2002, 07:24 PM
I'm planning to make a Slice Attribute which can control all the Edge[x] attributes in the polySplitX node.

-wT-
05-30-2002, 08:15 PM
Ok, just wanted to know, as I'm trying to make this as complete as possible, with error messages/different procedures if some verticles don't get connected, the selection is wrong, there are both verticles and edges selected and so on.
I think I'll do it even if you make it a perfect MeshTools 4 Maya, just for practice :thumbsup:

CGTalk Moderation
01-13-2006, 06:00 AM
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.