我正在构建一个具有2个子场景的应用程序,一个用于GUI,一个用于显示3D模型(在我的情况下是OBJ)。
对于OBJ文件的导入,我使用ObjModelImporterJFX library by InteractiveMesh。
就像标题中所说的那样,如this picture所示,当模型由SubScene处理时,它们就会开始出现毛刺。看起来有些不应该看到的覆盖部分已经像以前那样渲染了。只是为了进行比较,this是模型在场景直接处理时的外观。
这是我的代码:
public class Main extends Application{
@Override
public void start(Stage stage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
PerspectiveCamera camera = new PerspectiveCamera(true);
Group model = loadOBJ("course.obj");
Group course = new Group(model);
BorderPane borderPane = new BorderPane();
Pane pane1 = new Pane(course);
Pane pane2 = new Pane(root);
SubScene subScene1 = new SubScene(pane1, 1000, 720);
subScene1.setCamera(camera);
SubScene subScene2 = new SubScene(pane2,500,500);
borderPane.setLeft(subScene1);
borderPane.setRight(subScene2);
Scene scene = new Scene(borderPane, 1280,720, true);
stage.setScene(scene);
stage.show();
}
private Group loadOBJ(String fileName){
URL url = getClass().getResource(fileName);
Group modelRoot = new Group();
ObjModelImporter importer = new ObjModelImporter();
importer.read(url);
for (MeshView view : importer.getImport()){
modelRoot.getChildren().add(view);
}
return modelRoot;
}
public static void main(String[] args){
launch(args);
}
}
我希望有人知道为什么会这样。在此先感谢:)
更新:要通过更改SubScene的构造函数自
来解决此启用问题depthBufferSubScene subScene1 = new SubScene(pane1, 1000, 720);
到
SubScene subScene1 = new SubScene(pane1, 1000, 720, true, null);