PDA

View Full Version : polygon slope

Svenart
10-23-2009, 11:38 PM
hello,

i´m trying to write a script that calculates the slope of an polygon. I tried it with angle and 2points at first only, but its somehow not working for me. Sometimes it works, sometimes script will not start anymore.

Blypht
11-07-2009, 05:11 PM
If I understand your question correctly, it sounds like what you may want to do is use the cross3d function described in the LScript Reference (under Common Commands). That will give you the normal vector of the polygon. Then you can use the normal to calculate a "slope".

Here's an example of getting normals for the first 10 polys in a mesh:

// Normals
// Determine the normals of a mesh's polygons

@version 2.2
@warnings
@script generic
@name "Normals v1.0.0"

@define ID_VER "Normals v1.0.0"

@define POLYGON_LIMIT 10

generic
{
// Get the first mesh
if ((objMesh = Mesh()) != nil)
{
for (i = 1; (i <= objMesh.polygonCount()) && (i <= POLYGON_LIMIT); i++)
{
// Get the polygon
objPolygon = objMesh.polygons[i];

// Get the polygon's points
arrPoint = nil;
if ((numVertexCount = objMesh.vertexCount(objPolygon)) > 2)
{
// Get the vertices
for (j = 1; j <= numVertexCount; j++)
arrPoint[j] = objMesh.position(objMesh.vertex(objPolygon,j));

// Get the cross-product
vecCrossProduct = cross3d(arrPoint[3] - arrPoint[2],arrPoint[1] - arrPoint[2]);

// Show normal
info(format("The normal of polygon #\$1 is \$2",i,vecCrossProduct));
}
else
warn(format("Polygon #\$1 contains only \$2 vertices.",i,numVertexCount));
}
}
else
error("No mesh to use");
}