方框 3D JavaFX 旋转

Box 3D JavaFX Rotate

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

展示盒

旋转框


旋转时,盒子(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();
}

旋转时,方框 (JANELA_MEIO_BOX) 会变形

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

当你把它们放在一组时,它们被放在中间:较大的在 X 中从 -500 到 500,在 Y 中从 -300 到 300,在 Z 中从 -50 到 50,而较小的也一样,在 Z 中也是从 -50 到 50。

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

一个快速的解决方案,如果您想看到两种形状,只需将较小的形状加深一点:

JANELA_MEIO_BOX.setDepth(100.1);

将场景抗锯齿设置为平衡也很方便:

final Scene scene = new Scene(cameraView, 1000, 800, true, SceneAntialiasing.BALANCED);