如何使用JavaFX,JCSG和FXyz进行差分运算后得到封闭的3D网格?

时间:2016-06-10 08:03:24

标签: java 3d geometry javafx-8 javafx-3d

我正在使用JCSG库来剪切3D对象,但是在差异操作之后,合成的3D网格没有完全关闭,即切割表面的许多边缘是打开的,它们不属于任何三角形。

我使用以下源代码剪切3D网格。

MeshView box = new MeshView(cube);
CSG boxCSG = MeshUtils.mesh2CSG(box);
CSG testmesh = MeshUtils.mesh2CSG(test.getMesh());
CSG cutCSG = testmesh.difference(boxCSG.transformed(Transform.unity().translateZ(-10000)));
CSGMesh cutMesh = new CSGMesh(cutCSG);

测试对象显示如下here

在测试网格上执行差异操作后,结果网格看起来像:this

在上图中,如果看到切割面,则只有5个三角形,许多边都是打开的。顶面上的三角形也会扭曲。

是否有任何其他API可以获得完全闭合的曲面,并且在差分运算后还保持三角形的对称性?

初始3D形状的点和面如下:

    Points : [3143.0,643.8,-3391.5,2843.1,643.8,-3391.0,3143.0,-643.8,-3391.5,2000.0,-227.0,-3367.2,2000.0,227.0,-3367.2,2000.0,559.9,-3367.2,2000.0,-559.9,-3367.2,2843.1,-643.8,-3391.0,3143.0,0.0,-3391.5,2264.4,586.2,-3378.7,2273.1,-587.1,-3379.0,3143.0,378.2,-3391.5,2560.1,-615.6,-3387.1,3143.0,-381.1,-3391.5,2525.3,612.2,-3386.4,2433.3,28.1,-3384.3,2788.8,84.0,-3390.5,2670.6,347.8,-3389.0,2751.3,-352.0,-3390.1,2312.6,-300.8,-3380.4,2373.0,329.8,-3382.4,2000.0,559.9,-3000.0,3205.0,650.0,-3000.0,2905.0,650.0,-3000.0,2276.6,587.4,-3000.0,2560.3,615.7,-3000.0,2000.0,-559.9,-3000.0,3205.0,-650.0,-3000.0,2905.0,-650.0,-3000.0,2298.6,-589.6,-3000.0,2653.1,-624.9,-3000.0,3205.0,332.5,-3000.0,3205.0,16.6,-3000.0,3205.0,-237.5,-3000.0,2000.0,-227.0,-3000.0,2000.0,227.0,-3000.0,2287.6,104.2,-3000.0,2635.5,238.3,-3000.0,2273.2,-151.8,-3000.0,2650.8,-252.1,-3000.0,2912.7,239.9,-3000.0,2922.2,-23.5,-3000.0,2937.4,-339.6,-3000.0,]
    Faces : [6, 0, 26, 0, 3, 0, 26, 0, 34, 0, 3, 0, 5, 0, 4, 0, 21, 0, 21, 0, 4, 0, 35, 0, 4, 0, 3, 0, 34, 0, 35, 0, 4, 0, 34, 0, 35, 0, 36, 0, 21, 0, 38, 0, 36, 0, 34, 0, 38, 0, 34, 0, 26, 0, 39, 0, 36, 0, 38, 0, 40, 0, 31, 0, 37, 0, 31, 0, 23, 0, 37, 0, 31, 0, 22, 0, 23, 0, 31, 0, 40, 0, 32, 0, 32, 0, 40, 0, 41, 0, 39, 0, 37, 0, 36, 0, 39, 0, 41, 0, 37, 0, 37, 0, 41, 0, 40, 0, 39, 0, 32, 0, 41, 0, 39, 0, 33, 0, 32, 0, 28, 0, 42, 0, 39, 0, 28, 0, 27, 0, 42, 0, 28, 0, 39, 0, 30, 0, 39, 0, 42, 0, 33, 0, 38, 0, 29, 0, 39, 0, 39, 0, 29, 0, 30, 0, 29, 0, 38, 0, 26, 0, 34, 0, 36, 0, 35, 0, 25, 0, 37, 0, 23, 0, 24, 0, 21, 0, 36, 0, 24, 0, 37, 0, 25, 0, 24, 0, 36, 0, 37, 0, 33, 0, 42, 0, 27, 0, 8, 0, 31, 0, 32, 0, 11, 0, 31, 0, 8, 0, 13, 0, 32, 0, 33, 0, 8, 0, 32, 0, 13, 0, 27, 0, 2, 0, 33, 0, 33, 0, 2, 0, 13, 0, 31, 0, 0, 0, 22, 0, 11, 0, 0, 0, 31, 0, 12, 0, 7, 0, 28, 0, 29, 0, 10, 0, 12, 0, 30, 0, 29, 0, 12, 0, 30, 0, 12, 0, 28, 0, 28, 0, 2, 0, 27, 0, 28, 0, 7, 0, 2, 0, 29, 0, 6, 0, 10, 0, 26, 0, 6, 0, 29, 0, 9, 0, 21, 0, 24, 0, 22, 0, 0, 0, 23, 0, 24, 0, 14, 0, 9, 0, 25, 0, 14, 0, 24, 0, 1, 0, 14, 0, 25, 0, 1, 0, 25, 0, 23, 0, 9, 0, 5, 0, 21, 0, 0, 0, 1, 0, 23, 0, 5, 0, 9, 0, 4, 0, 15, 0, 4, 0, 9, 0, 15, 0, 9, 0, 20, 0, 9, 0, 17, 0, 20, 0, 10, 0, 6, 0, 3, 0, 3, 0, 15, 0, 19, 0, 15, 0, 16, 0, 18, 0, 10, 0, 19, 0, 18, 0, 16, 0, 11, 0, 8, 0, 17, 0, 1, 0, 11, 0, 1, 0, 9, 0, 14, 0, 1, 0, 16, 0, 9, 0, 1, 0, 17, 0, 16, 0, 7, 0, 13, 0, 2, 0, 7, 0, 18, 0, 13, 0, 19, 0, 10, 0, 3, 0, 15, 0, 3, 0, 4, 0, 17, 0, 15, 0, 20, 0, 8, 0, 18, 0, 16, 0, 17, 0, 9, 0, 16, 0, 17, 0, 16, 0, 15, 0, 13, 0, 18, 0, 8, 0, 15, 0, 18, 0, 19, 0, 12, 0, 18, 0, 7, 0, 12, 0, 10, 0, 18, 0, 15, 0, 16, 0, 17, 0, 15, 0, 17, 0, 16, 0, 1, 0, 0, 0, 11, 0, 16, 0, 17, 0, 11, 0,]

1 个答案:

答案 0 :(得分:1)

JCSG(JCSG-MeshExtensions)有一个扩展库,可以解决这个问题。它可用于在执行CSG操作后优化网格。这是一个链接:https://github.com/miho/JCSG-MeshExtensions

Optimization