外積を使うことで三角形の表面積を計算することができる。


Divide SOPですべてのプリミティブを事前に三角形に分割しておく。
// Run Over: Detail
float sum = 0;
for(int i = 0; i < nprimitives(0); i++)
{
int npts[] = primpoints(0, i);
vector p0 = point(0, "P", npts[0]);
vector p1 = point(0, "P", npts[1]);
vector p2 = point(0, "P", npts[2]);
vector cross = cross(p0 - p1, p2 - p1);
float area = length(cross) / 2;
sum += area;
}
f@area = sum;