SkyBox works - how about SkySphere?

I have SkyBox working - but the visual effect is very obviously a box (especially when you wish to show a 3d star scape). What I am looking for is a sphere based star map to project around my view - it doesn’t need to move (interstellar distances could be handled by regenerating the images when a great distance is moved). At present it doesn’t need to be accurate, just work!

Ideally I would project 6 different sphere views onto the sphere. The box doesn’t seem to work well - the angles of the box give different perspective and rotate stangely…

I’ve put my code below - but it’s probably miles off - thanks to William Denis for a starter with SkyBox…

The loaded object is a simple sphere with an image texture mapped to it (using art of illusion).

Cheers
Andy Stratton


public class StarSphere extends Background {

public StarSphere (String filename) {
        
        BranchGroup starSphere = getSphere(filename);

        // Sets the geometry of this Background node to be the created sphere
        setGeometry(starSphere);
}

public BranchGroup getSphere(String filename)
{
        BranchGroup result = null;
    try {
            result = new OBJLoader().load("./starsphere.obj");
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(0);
    }
    Object obj = result.getChild(0);
    BranchGroup bg = null;
    while ((obj != null) && (obj instanceof BranchGroup))
    {
          bg = (BranchGroup)obj;
                 obj = bg.getChild(0);
    }
        for (int i = 0; i < bg.getChildren().size(); i++) {
              // Set texture and disable depth buffer
              Appearance a = new Appearance();
              a.setRenderingAttributes(new RenderingAttributes());
              a.getRenderingAttributes().setDepthBufferWriteEnable(false);
              ((Shape3D)bg.getChild(i)).setAppearance(a);
        }
        return result;
      
}

}

Hi,

You are quite correct, visually one can tell it is a box. By generating SkyBox friendly textures (using a camera, or virtual camera with a 90 degree FOV), this effect can be lessened.

Is your SkySphere (I believe the lingo is SkyDome :)) code working? It doesn’t look like you’re setting any textures.

Cheers,

Will.

No - you’ve correctly guessed - it’s not working. I was hoping someone might spot an obvious error!

The obj that is imported has an mtl file associated that has the texture set on it. If I add the object to the top (root) branchgroup, it works (except that it is lit from one side of course). At this point, it is just a standard branchgroup, as listed next:


        root.addChild(getStarSphere());


private BranchGroup getStarSphere() {
BranchGroup result = null;
try {
result = new OBJLoader().load("./starsphere.obj");
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
return result;
}

Of course - when you move, you move outside the sphere and see it from the outside.

If I do:


        SkyBox s = new SkyBox("stars.jpg");
        root.addChild(s);

Then I get a skybox with the associated distortion on rotating the box (which I’m trying to avoid).

If I do:

        StarSphere s = new StarSphere("stars.jpg");

Instead of the skybox line above, then I get a white background.

Finally, here is the class for the StarSphere (should be the same as before - but I don’t want to assume anything…:):


public class StarSphere extends Background {

public StarSphere (String filename) {
        
        BranchGroup starSphere = getSphere(filename);

        // Sets the geometry of this Background node to be the created sphere
        setGeometry(starSphere);
}

public BranchGroup getSphere(String filename)
{
        BranchGroup result = null;
    try {
            result = new OBJLoader().load("./starsphere.obj");
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(0);
    }

    Object obj = result.getChild(0);
    BranchGroup bg = null;
    while ((obj != null) && (obj instanceof BranchGroup))
    {
          bg = (BranchGroup)obj;

          obj = bg.getChild(0);
    }
        for (int i = 0; i < bg.getChildren().size(); i++) {
              // Disable depth buffer
              Appearance a = new Appearance();
              a.setRenderingAttributes(new RenderingAttributes());
              a.getRenderingAttributes().setDepthBufferWriteEnable(false);
              ((Shape3D)bg.getChild(i)).setAppearance(a);
        }
        return result;
}

}


I also tried constructing a sphere and setting the material directly at one point - but didn’t get anywhere and ended up wiping the code…

Cheers
Andy Stratton