PDA

View Full Version : vertex(<polygon>,<index>)



cestrum
04-20-2004, 02:15 AM
I need to obtain the coordinates of an object's vertexes.
The method is vertex(<polygon>,<index>). How can I identifie the <polygon> parameter inside the Layout in a generic script (or master script)?

Tom Speed
04-23-2004, 02:35 AM
Hi,

Here's how to visit each poly and access its points:



// In Modeler, there exists 2 automatic arrays when editing a mesh
// points[] and polygons[], in Layout we don't have such arrays
// here's how to get a list of point IDs for a mesh, without duplicate points
// NOTE: I'm assuming a 1 layer object, check lscriptreference.pdf for more
// info when working with layered objects and using .pointcount() or .polycount()

@warnings
@script generic
@name point_poly_test

generic
{
(obj) = Scene().getSelect(); // current mesh

pntCnt = obj.pointCount(); // its pointcount
polCnt = obj.polygonCount(); // its polycount

for(p = 1; p <= polCnt; p++) // for each poly
{
polyId = obj.polygons[p]; // polyID
thisPolysPntCount = obj.vertexCount(polyId); // this polys pointcount

for(pnt = 1; pnt <= thisPolysPntCount; pnt++) // for each point on this poly
{
pointId = obj.vertex(polyId,pnt); // get its ID
if(!meshPoints.contains(pointId)) // if our meshPoints array already lists this point
meshPoints += pointId; // then ignore it (polys share points, we don't want duplicates!)
}
}

info(meshPoints.size()); // should be the same as 'pntCnt'
}


To get the points position:

object.position(point);

I've no idea if that gets the correct position of a deformed point though.

Cya!
Tom

cestrum
04-23-2004, 03:24 AM
thank you Tom.

I'll try the code later....
...I think it is what I need.

cestrum
04-26-2004, 07:03 AM
Hi Tom,

The code you sent is perfect!

...but I have a question:
what's the meaning of the brackets for the obj variable?

Tom Speed
04-26-2004, 07:31 AM
Hi,

Some commands return arrays, like getSelect(), or lyrfg() and many others.

If you enclose the variable name within brackets, you can tell LScript to assign to non-array variables:

obj = Scene().getSelect(); // obj is an array of items

(obj) = Scene().getSelect(); // gets ONLY the first selected item, obj is NOT an array

(obj1,obj2,obj3) = Scene().getSelect(); // gets the first 3 selected items and assigns them to obj1, obj2 and obj3

It's called 'associative assignment', comes in very useful too!

Cya!
Tom