在 SketchUp 和 3DSMax 之间制作导出/导入插件时必须解决完全相同的问题。Sketchup 使用概念或外部和内部循环,而 3DS Max 是纯几何。
可悲的是,我没有插件,所以我会尽量记住它:
foreach point in outerLoop
{
// Loop over all other point to find the nearest valid one
foreach otherPoint in both outerLoop and all innerLoops where otherPoint is not point
{
if otherPoint is adjacent to point
reject otherPoint
if distance between point and otherPoint is bigger than previous distance
reject otherPoint
// Test is vector is point outside the geometry in case of convexe shapes
if cross product of vector from (point - adjacent point) and (point - nearest point) is pointing away from cross product of vectors of (point - both adjacents point)
reject otherPoint
nearestPoint = otherPoint
}
for the two adjacentPoint of nearestPoint
{
if adjacentPoint is also adjacent to point
make triangle(point, adjacentPoint, nearestPoint)
if cross product of vector from (point - adjacent point) and (point - nearest point) is pointing in the same direction as cross product of vectors of (point - both adjacents point)
make triangle(point, adjacentPoint, nearestPoint)
}
}
repeat the above for innerLoops point while only checking against other innerLoops
make triangle function should check if the triangle already exist from previous iteration.
它不是超级漂亮而且有点粗鲁,但它可以与无限数量的内部循环一起使用,并且总是尽可能地创建最好的三角形。
我很确定会有办法提高它的性能,但我从来没有给它足够的时间。