1

So I need a 3D SkyBox. I tried to scale up the Sphere, but when the camera is in it, it disappears.

Here's a code where the camera is moving into the Sphere:

package application;

import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.*;
import javafx.scene.shape.Sphere;
import javafx.scene.transform.*;
import javafx.stage.Stage;
import javafx.util.Duration;

public class Main2 extends Application {    
    public static AnchorPane gui = new AnchorPane();
    public static Scene scene = new Scene(gui, 800, 400, true);
    public static Group root3D = new Group();
    public static SubScene subscene = new SubScene(root3D,800, 400,true,SceneAntialiasing.BALANCED);
    public static PerspectiveCamera camera = new PerspectiveCamera(true);
    
    @Override public void start(Stage stage) throws Exception {     
        PhongMaterial mat = new PhongMaterial();
        mat.setDiffuseMap(new Image("SkyBox.png"));
        
        Sphere s = new Sphere(1);
        s.setMaterial(mat);
        s.setTranslateZ(-15);
        root3D.getChildren().add(s);
        camera.setFarClip(2000.0);

        camera.getTransforms().addAll(new Rotate(0, Rotate.X_AXIS), new Translate(0, 0, -20));
        subscene.setCamera(camera);
        gui.getChildren().add(subscene);
        
        TranslateTransition move = new TranslateTransition();
        move.setNode(camera);
        move.setByZ(10);
        move.setDuration(Duration.millis(10000));
        move.setCycleCount(move.INDEFINITE);
        move.setAutoReverse(true);
        move.play();
        
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String[] args) {launch(args);}
}

Problem: The Sphere will be invisible when the camera is in it.

How can I see the texture of the Sphere from inside.

tommY
  • 109
  • 4
  • Does setting the [`cullFace`](https://openjfx.io/javadoc/17/javafx.graphics/javafx/scene/shape/Shape3D.html#setCullFace(javafx.scene.shape.CullFace)) property of the sphere to `NONE` help? – jewelsea Sep 17 '21 at 21:50
  • No, nothing changed – tommY Sep 17 '21 at 21:53
  • ```s.setCullFace(CullFace.NONE);``` When I used this code, it works but I can't see anything when the camera is in the ```Sphere```, everything is black – tommY Sep 17 '21 at 22:11
  • ```CullFace.BACK``` With this code the ```sphere``` will be invisible when the camera is in it. – tommY Sep 17 '21 at 22:25
  • 2
    This [question](https://stackoverflow.com/questions/28806286/create-photo-sphere-similar-to-google-map-photo-sphere-javafx-3d) might help you. – José Pereda Sep 17 '21 at 22:43
  • 1
    Exactly what I was looking for, thank you! – tommY Sep 17 '21 at 22:48

0 Answers0