r/JavaFX • u/[deleted] • Aug 26 '20
Help JavaFX 3D object render
Hello. I started to learn how 3d works in javafx i had one questions.
I want to use a border pane to divide main screen in two views, one for a menu and the other to render my 3d object ¿how can i made that? i tried adding a anchor pane but, the render doesn't appear or the render shows up and the menu don't.
I watched some tutorials but all of them use the start method and only one scene.
3
u/SoulWanderer Aug 26 '20
You can use a scene with your panel (you can use whatever panel you want) and then create a subscene for the 3d object. When I am on my keyboard I'll see if I have some tutorial to share... But look for subscene and maybe it helps
2
u/SoulWanderer Aug 26 '20
So for my subscene I use this:
private Node create3dScene() throws LoadException{Group group = buildScene();SubScene scene = new SubScene(group, 1, 1, true, SceneAntialiasing.BALANCED);
scene.heightProperty().bind(((StackPane)mainPanel.getCenter()).heightProperty());scene.widthProperty().bind(((StackPane)mainPanel.getCenter()).widthProperty());scene.setFill(BACKGROUND);
PerspectiveCamera perspectiveCamera = new PerspectiveCamera();perspectiveCamera.setNearClip(0.01);perspectiveCamera.setFarClip(1000);
scene.setCamera(perspectiveCamera);zoomAndCenter();return scene;}On the buildscene I create the Mesh3d from an STL to show it.
Then I use a panel:
mainPanel = new BorderPane();
Node scene3D = create3dScene();panelEscena.getChildren().addAll(axis, scene3D);.....
Scene scene = new Scene(mainPanel, viewportSize, viewportSize+50, true, SceneAntialiasing.BALANCED);Hope it works for you ;)
I will try and answer if you ask more, but I am on european time...
1
Aug 26 '20
Thanks! i was looking for time like that. I gonna try to implement that and see if it works!
2
3
u/WhoMeWorried Aug 26 '20
The most convenient way is to use MenuButton, each of which would load some 3D object onto the center of your BorderPane.
Look up Menu/MenuItem and MenuButton, see which fits your requirement. You can fit the menu on the left, right, bottom or on top of the BorderPane. Try it out in Scene Builder.