结合 JavaFX 3D 形状看起来透明

Combining JavaFX 3D Shapes seem transparent

我正在 JavaFX 8 中进行一个 3D 项目。我已经用几个 TriangleMesh 对象构建了一个 Car 3d 模型,我还使用了其他几个 JavaFX 'Shape 3D' 来创建轮子和轴。

问题是 MeshViews 元素看起来是透明的。我可以通过它看到其他 Shape3D 对象

2 个圆柱体可见,即使 MeshView 在它前面

这是我制作的 TriangleMesh 之一的示例

// =============================  ROOF ============================= // 

    TriangleMesh roofMesh = new TriangleMesh(VertexFormat.POINT_TEXCOORD);

    roofMesh.getPoints().addAll(
            /* X */ -roofWidth/2.f,  /* Y */    roofHeight + wheelDiameter / 2  + wheelGap + doorHeight, /* Z */ - roofLength/2,    //PT0
            /* X */ roofWidth/2.f,   /* Y */    roofHeight + wheelDiameter / 2  + wheelGap + doorHeight, /* Z */ - roofLength/2,    //PT1
            /* X */ -roofWidth/2.f,  /* Y */    roofHeight + wheelDiameter / 2  + wheelGap + doorHeight, /* Z */  roofLength/2,     //PT2
            /* X */ roofWidth/2.f,   /* Y */    roofHeight + wheelDiameter / 2  + wheelGap + doorHeight, /* Z */  roofLength/2      //PT3
            );

    roofMesh.getTexCoords().addAll(
            0, 0,  //  t0
            1, 0,  //  t1
            0, 1,  //  t2
            1, 1   //  t3
            );

    roofMesh.getFaces().addAll(
            1,1, 0,0,2,2,
            3,3, 1,2 ,2,1
            );

创建网格后,我正在创建一个新的 MeshView 对象

        meshViewMap.put("roof",          new MeshView(roofMesh));

我还对 MeshViews 应用了 Material:

private void setTexColor(Shape3D shape, Color c, String imagePath )
{
    PhongMaterial pm = new PhongMaterial();
    pm.setDiffuseColor(c);
    pm.setSpecularColor(c);
    shape.setMaterial(pm);
}

这些是您在图片中看到的圆柱体:

    //Create Axles
            Cylinder frontCylinder = new Cylinder(0.5, bodyWidth);
            Cylinder rearCylinder = new Cylinder(0.5, bodyWidth);
            PhongMaterial cylinderMat = new PhongMaterial();
            cylinderMat.setDiffuseColor(Color.BLACK);
            cylinderMat.setSpecularColor(Color.BLACK);

            frontCylinder.setMaterial(cylinderMat);
            rearCylinder.setMaterial(cylinderMat);

            frontCylinder.setRotate(90);
            rearCylinder.setRotate(90);
            frontCylinder.setTranslateZ( 0.7f * (bodyLength/2 + hoodLength/2));
            rearCylinder.setTranslateZ( -0.4f * (bodyLength/2 + hoodLength/2));

            frontCylinder.setTranslateY(wheelDiameter/2);
            rearCylinder.setTranslateY(wheelDiameter/2);
            this.getChildren().add(frontCylinder);
            this.getChildren().add(rearCylinder);

我尝试将不透明度设置为 1,即使它是默认值。

Java 版本 8.0.121-b13

默认情况下,JavaFX Scene doesn't include a depth buffer。当用于 3D 时,这可能会导致奇怪的 Escherian 伪像,即远离相机的对象或表面绘制在靠近相机的对象或表面之上。

An application may request depth buffer support or scene anti-aliasing support at the creation of a Scene. A scene with only 2D shapes and without any 3D transforms does not need a depth buffer nor scene anti-aliasing support.

要启用深度缓冲区,请使用one of the constructors that takes a boolean depthBuffer argument

对于 SubScene, the corresponding constructor also requires a SceneAntialiasing 参数。 (默认值为 SceneAntialiasing.DISABLED。)

(基于,不仔细看评论的人。)