1

I have two Boxes (Group), and when I rotate, the image displays like this:

Display Boxes Display Boxes

Rotate Boxes Rotate Boxes


When rotating, the Box (JANELA_MEIO_BOX) is distorted:

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();
}

When rotating, the Box (JANELA_MEIO_BOX) is distorted

José Pereda
  • 44,311
  • 7
  • 104
  • 132

1 Answers1

0

You have two boxes: a 1000x600x100 cube, and a 600x340x100 cube.

When you put both of them in a group, they are placed in the center: the bigger one goes from -500 to 500 in X, -300 to 300 in Y, -50 to 50 in Z, and the same goes for the smaller one, also in Z from -50 to 50.

When you render two shapes with their faces in the same exact Z coordinate you will always get these artifacts.

artifacts

One quick solution, if you want to see both shapes, is just making the smaller one a little bit deeper:

JANELA_MEIO_BOX.setDepth(100.1);

no artifacts

And it is also convenient that you set Scene Antialiasing to Balanced:

final Scene scene = new Scene(cameraView, 1000, 800, true, SceneAntialiasing.BALANCED);
José Pereda
  • 44,311
  • 7
  • 104
  • 132