2014-02-13 68 views
0

當我在我的場景中實現SubScene時,使用混合2D和3D有一些問題。 您可以通過單擊鏈接查看問題。我使用Interactivemesh-Modelimporter。JFX8混合二維和三維,場景子場景不正確的繪圖3ds文件

http://s3.postimg.org/nsef8o1f3/without_Subscene.png

http://s3.postimg.org/y16wehpgv/with_Subscene.png

import com.interactivemesh.jfx.importer.ImportException; 
import com.interactivemesh.jfx.importer.tds.TdsModelImporter; 

import javafx.application.Application; 
import javafx.event.ActionEvent; 
import javafx.event.EventHandler; 
import javafx.scene.Camera; 
import javafx.scene.Group; 
import javafx.scene.Node; 
import javafx.scene.PerspectiveCamera; 
import javafx.scene.Scene; 
import javafx.scene.SubScene; 
import javafx.scene.control.Button; 
import javafx.scene.layout.AnchorPane; 
import javafx.scene.layout.HBox; 
import javafx.scene.layout.Pane; 
import javafx.scene.layout.VBox; 
import javafx.scene.transform.Rotate; 
import javafx.scene.transform.Translate; 
import javafx.stage.Stage; 



public class JavaFX7 extends Application { 

HBox hBoxControls; 
Group model3D; 
double y_Axis; 
double x_Axis; 
double rotate; 
public Rotate cameraXRotate; 
public Rotate cameraYRotate; 
public Translate cameraPosition2; 

Camera camera; 



public void controls() { 
    ... 
      ... 
} 

public void model() { 

    // 
    // importing 3ds Modell 
    // 

    TdsModelImporter myModel = new TdsModelImporter(); 
     try { 
      String path = "C:/Users/Corvin/Downloads/DUC916_L.3DS/DUC916_L.3DS"; 
      myModel.read(path); 
     } 
     catch (ImportException e) 
     { 
      System.out.println("Error importing 3ds model: "+e.getMessage()); 
      return; 
     } 

    final Node[] myMesh = myModel.getImport(); 
    myModel.close(); 
    model3D = new Group(myMesh);   

} 

public static void main(String[] args) { 

    launch(); 
} 

@Override 
public void start(Stage stage) throws Exception { 

    y_Axis = 0.0; 
    controls(); 
    model(); 

    Camera camera = new PerspectiveCamera(); 

    //------------------- 
    cameraXRotate = new Rotate(-5,Rotate.X_AXIS); 
    cameraYRotate = new Rotate(-50,Rotate.Y_AXIS); 
    cameraPosition2 = new Translate(0,-1900,-14000);  

    camera.getTransforms().add(cameraXRotate); 
    camera.getTransforms().add(cameraYRotate); 
    camera.getTransforms().add(cameraPosition2); 
    //------------------- 

    Pane sub = new Pane(); 
    AnchorPane root = new AnchorPane();  

    AnchorPane.setRightAnchor(hBoxControls, 10.0); 
    AnchorPane.setBottomAnchor(hBoxControls, 10.0); 
    root.getChildren().add(hBoxControls); 

    // --------------------------------------- 
    Scene scene = new Scene(root, 800, 600, true); 
    SubScene subScene = new SubScene (sub, 800, 600); 

    subScene.setCamera(camera); 

    sub.getChildren().add(model3D); 

    root.getChildren().add(subScene); 

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

} 

} 

回答

2

您正在使用3D模型。

這意味着你的subscene需要一個deapthBuffer而不是你的主場景。這就是爲什麼它適用於主要場景。

變化

SubScene subScene = new SubScene (sub, 800, 600); 

SubScene subScene = new SubScene(sub, 800, 600,true, SceneAntialiasing.DISABLED); 

(SceneAntialiasing.DISABLED或SceneAntialiasing.BALANCED)