14

« **on:** March 08, 2016, 08:08:06 pm »
Raxx,

When I calculate the face normals from the average of the face vertex normals (calculated from the edge vectors from each point of the face), I do get different values than your script returns. The edge vector calculated values return symmetrical normals for mirrored faces on your attached mesh. I modified your script to add the manually calculated normals to the output. You can see the variation in the individual vertex based face normals. It seems the algorithm that Anim8or is using is significantly different or is suffering from a precision problem.

`file $c;`

shape $s, $childShapes[0];

int $i, $j, $k;

int $numSides;

point3 $faceNormal;

//added

int $l,$back,$fwd;

point3 $facePoint[0];

point3 $facePointNormal[0];

point3 $fPNavg;

$c.open("$console", "w");

project.curObject.GetShapes($childShapes);

for $i = 0 to $childShapes.size - 1 do

{

if($childShapes[$i].GetKind() == SHAPE_KIND_MESH)

{

$s = $childShapes[$i];

for $j = 0 to $s.GetNumFaces() - 1 do

{

if ($s.GetFaceSelected($j) == 1)

{

//$faceNormal = $s.GetNormal($s.GetFaceNormalIndex($j, 0));

$faceNormal=(0.0,0.0,0.0);

$fPNavg=(0.0,0.0,0.0);

$numSides = $s.GetNumSides($j);

$facePoint.size = $numSides;

$facePointNormal.size = $numSides;

for $k = 0 to $numSides - 1 do

{

$faceNormal = $faceNormal + $s.GetNormal($s.GetFaceNormalIndex($j, $k));

$facePoint[$k]=$s.GetPoint($s.GetFacePointIndex($j,$k));

$facePointNormal[$k]=(0.0,0.0,0.0);

}

$faceNormal = normalize(($faceNormal.x/(1.0 * $numSides), $faceNormal.y/(1.0 * $numSides), $faceNormal.z/(1.0 * $numSides)));

for $k = 0 to $numSides-1 do

{

$back = $k - 1;

if ($back < 0) $back = $numSides - 1;

$fwd = $k + 1;

if ($fwd > ($numSides - 1)) $fwd = 0;

$facePointNormal[$k] = normalize(cross(($facePoint[$back]-$facePoint[$k]),($facePoint[$fwd]-$facePoint[$k])));

$c.print("Calc FP %d Normal (%.3f,%.3f,%.3f)\n",$k,$facePointNormal[$k]);

$fPNavg = $fPNavg + $facePointNormal[$k];

}

$fPNavg = normalize(($fPNavg.x / (1.0 * $numSides),$fPNavg.y / (1.0 * $numSides),$fPNavg.z / (1.0 * $numSides)));

$c.print("Face %d Anim8or normals (%.3f, %.3f, %.3f) Calc (%.3f, %.3f, %.3f)\n", $j, $faceNormal, $fPNavg);

}

}

}

}

$c.close();

NickE