2017-05-29 95 views
1

我有兩個盒(集團),並且當我旋轉時,圖像顯示裝置是這樣的:盒3D JavaFX的旋轉

陳列盒 Display Boxes

旋轉盒 Rotate Boxes


當旋轉,盒子(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)變形

+0

ps:旋轉後的行(Box)不可見! –

回答

0

您有兩個盒子:一個1000x600x100立方體和一個600x340x100立方體。

當你把它們放在一個組中時,它們被放置在中間:較大的一個在X中從-500到500,在Y中-300到300,在Z中-50到50,並且相同對於較小的一個,也是從-50到50的Z.

當您在同一個精確的Z座標中渲染兩個形狀時,您將始終獲得這些工件。

artifacts

一個快速的解決方案,如果你想看到兩個形狀,只是把較小的一個稍微深一點:

JANELA_MEIO_BOX.setDepth(100.1); 

no artifacts

而且這也是方便的您將場景抗鋸齒設置爲平衡:

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

謝謝JoséPereda!完美!非常感謝你! –

+0

如果您將問題標記爲已接受,那將會很好,所以它可以對其他人有所幫助。 –

+0

好的,何塞佩雷達。完成!謝謝 ! –