javajavafxjavafx-8java-83ds

JFX8 Mixed 2D and 3D, Scene Subscene incorrect drawing 3ds-file


Have some problems with using mixed 2D and 3D when i'm implementing a SubScene to my Scene. You can see the problem by clicking the links. Im using the Interactivemesh-Modelimporter.

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

}

}

Solution

  • You are using 3D models.

    That means your subscene needs a deapthBuffer not your primary scene. Thats why it works on the primary scene.

    Change

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

    to

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

    (SceneAntialiasing.DISABLED or SceneAntialiasing.BALANCED)