1

我有两个框(组),当我旋转时,图像显示如下:

展示盒 展示盒

旋转框 旋转框


旋转时,Box (JANELA_MEIO_BOX) 被扭曲:

public class Demo1 extends Application {

private PhongMaterial texturedMaterial = new PhongMaterial();
private Image texture = new Image("/T3D/mapfooter.JPG");
private final PhongMaterial redMaterial = new PhongMaterial();

public static void main(String[] args) {
    Application.launch(args);
}

@Override
public void start(final Stage stage) {

    redMaterial.setSpecularColor(Color.ORANGE);
    redMaterial.setDiffuseColor(Color.RED);

    texturedMaterial.setDiffuseMap(texture);
    javafx.scene.shape.Box JANELA_MEIO_BOX = new javafx.scene.shape.Box();

    /*  rotate  */
    JANELA_MEIO_BOX.setWidth(600.0); 
    JANELA_MEIO_BOX.setHeight(340.0);
    JANELA_MEIO_BOX.setDepth(100.0);
    JANELA_MEIO_BOX.setMaterial(texturedMaterial);

    Group JANELA_001 = new Group();

    stage.setTitle("Cube");

    final CameraView cameraView = new CameraView();


    final Scene scene = new Scene(cameraView, 1000, 800, true);
     scene.setFill(new RadialGradient(225, 0.85, 300, 300, 500, false,
            CycleMethod.NO_CYCLE, new Stop[]{new Stop(0f, Color.BLUE),
                new Stop(1f, Color.LIGHTBLUE)}));
    PerspectiveCamera camera = new PerspectiveCamera();
    scene.setCamera(camera);
    scene.setOnScroll((final ScrollEvent e) -> {
        camera.setTranslateZ(camera.getTranslateZ() + e.getDeltaY());
    });


    javafx.scene.shape.Box JAN_MAIN = new javafx.scene.shape.Box();
    JAN_MAIN.setMaterial(redMaterial);
    JAN_MAIN.setWidth(1000.0);
    JAN_MAIN.setHeight(600.0);
    JAN_MAIN.setDepth(100.0);

     JAN_MAIN.getTransforms().add(new Translate(1, 1, 1));


    JANELA_MEIO_BOX.getTransforms().add(new Translate(1, 1, 1));

    JANELA_001.getChildren().addAll(JAN_MAIN, JANELA_MEIO_BOX);

    cameraView.add(JANELA_001);

            /*  mouse events */


    cameraView.frameCam(stage, scene);
     MouseHandler mouseHandler = new MouseHandler(scene, cameraView);
    KeyHandler keyHandler = new KeyHandler(stage, scene, cameraView);
    /*  scene */

    stage.setScene(scene);
    stage.show();
}

旋转时,Box (JANELA_MEIO_BOX) 扭曲

4

1 回答 1

0

你有两个盒子:一个 1000x600x100 的立方体和一个 600x340x100 的立方体。

当你把它们都放在一个组中时,它们被放置在中心:较大的在 X 方向从 -500 到 500,在 Y 方向从 -300 到 300,在 Z 方向从 -50 到 50,较小的也一样一,也在 Z 从 -50 到 50。

当您在相同的精确 Z 坐标中渲染两个形状时,它们的面总是会得到这些伪像。

人工制品

如果您想同时查看这两种形状,一种快速的解决方案就是让较小的形状更深一点:

JANELA_MEIO_BOX.setDepth(100.1);

无伪影

将 Scene Antialiasing 设置为 Balanced 也很方便:

final Scene scene = new Scene(cameraView, 1000, 800, true, SceneAntialiasing.BALANCED);
于 2017-05-30T19:36:01.190 回答