Android Skybox and Skyspheres not working Cardboard

I am working on a small test application for Android that uses Cardboard VR and JME and I simply can’t get Skyboxes/Skyspheres to work. I know that DDS does not work but something is still weird. I have tried with both png and jpg at both 512x512 and 2048x2048 with and without a scene and the built in tools. I am on JME 3.1. With skybox it just crashes. With skyspheres (aka. skydome) it is completely bugged when rendering but it does start. It is all gray flickering lines. My other nodes, some flying blocks, renders flawless. This is on a real device btw, a Xperia Z1C. I have also tried on a Galaxy S5. Honestly, I have no idea what is happening. All my libs are up to date. It works flawless on desktop. I am using the skycreator when doing it using code.

If no one have a solution I will have to move to unity, which I would like to avoid.

If it “just crashes” theres no way we could help you - too few information.

I’ll get an error log asap.

I’m using a Skybox created by SkyFactory.createSky in Asteroid Belt Travel VR . Haven’t had any crashes reported, so skyboxes were definitely working a couple of months ago when I published the app.
I’m not familiar with Skycreator.

I’d love to hear anyone’s experiences with Android Cardboard. Is this worth trying?

How easy can I get a test app up and running with this?

@BigBob

  1. Add jme-cardboard.jar to your project.
  2. Turn on Android deployment for your project (Properties/Application/Android)
  3. Follow these instructions to run jme in a fragment: Software Pioneering: Running jMonkeyEngine 3 on Android using AndroidHarnessFragment
    But instead of extending AndroidHarnessFragment, extend
    CardboardHarnessFragment instead. MainActivity should extend
    CardboardActivity

Edit: I see that I recommend using Cardboard 0.5.3 on the wiki. It should be any version other than 0.5.4 (current is 0.5.7). I’ll try to update that tonight.

Edit2: I’ll also look at moving the essence of the blog post to the jme wiki.

        String neb = "Textures/nebula/";
        Texture back = assetManager.loadTexture(neb+"Nebula_back6.jpg");
        Texture bottom = assetManager.loadTexture(neb+"Nebula_bottom4.jpg");
        Texture front = assetManager.loadTexture(neb+"Nebula_front5.jpg");
        Texture left = assetManager.loadTexture(neb+"Nebula_left2.jpg");
        Texture right = assetManager.loadTexture(neb+"Nebula_right1.jpg");
        Texture top = assetManager.loadTexture(neb+"Nebula_top3.jpg");
        rootNode.attachChild(SkyFactory.createSky(assetManager, left, right, front, back, top, bottom));

I just ran the above code and it worked on desktop but it did not actually crash on android. Before when I used a scene it crashed. I can’t find any errors however, not anthing relevant. I am not too used to logcat however, nor android development at all really.

As I don’t care about the secrecy regarding the current source code would @rickard mind taking a look? As I am not sure I got that fragment part done correctly. As far as I can see, it already runs in fragments when you create the project which confused me a lot when reading that blog post. It seems you are the author of jme-cardboard (?) and I tried using your flying box thing to test rendering.

Here is the DL link. I will keep the DL link active for a while so future readers might find something useful from this discussion.

Sorry for the delay btw, I have been busy. (EDIT: Game has nothing to do with stalin, it is just a placeholder name.)

In what way isn’t it working? You said it ‘did not actually crash’. Is it just black? Screenshot?

Please post any relevant code in the thread so that anyone can help investigating. If you think it’s related to the fragment code, post it.

(It may be that the blog post is outdated now when 3.1 Alpha has been released)

It is just black. The flying cubes render but nothing else.

Here is the layout:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical">
    <fragment android:id="@+id/game_fragment" android:layout_height="match_parent" android:layout_width="match_parent" android:name="com.philipborg.stalinator.ExamplesFragment"/>
</LinearLayout>

Here is the MainActivity

public class MainActivity extends CardboardActivity {
    public MainActivity(){
        LogManager.getLogManager().getLogger("").setLevel(Level.INFO);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

My current fragment

public class ExamplesFragment extends CardboardHarnessFragment{
    public ExamplesFragment(){
        appClass = "com.philipborg.stalinator.Main";
    }
}

Here is the Application file

public class Main extends SimpleApplication {
    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }
    private Material mat;
    private Node observer;
    private Node stars;
    private SpotLight light;
    private float maxDistance = 75f;
    @Override
    public void simpleInitApp() {
        Box b = new Box(1, 1, 1);
        Geometry geom = new Geometry("Box", b);
        mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setColor("Diffuse", ColorRGBA.White);
        geom.setMaterial(mat);
        rootNode.attachChild(geom);
        observer = new Node("");
        rootNode.attachChild(observer);
        getRenderManager().removePostView(guiViewPort);
        guiNode.detachAllChildren();
        stars = new Node();
        rootNode.attachChild(stars);
        String neb = "Textures/nebula/";
        Texture back = assetManager.loadTexture(neb+"Nebula_back6.jpg");
        Texture bottom = assetManager.loadTexture(neb+"Nebula_bottom4.jpg");
        Texture front = assetManager.loadTexture(neb+"Nebula_front5.jpg");
        Texture left = assetManager.loadTexture(neb+"Nebula_left2.jpg");
        Texture right = assetManager.loadTexture(neb+"Nebula_right1.jpg");
        Texture top = assetManager.loadTexture(neb+"Nebula_top3.jpg");
        rootNode.attachChild(SkyFactory.createSky(assetManager, left, right, front, back, top, bottom));
        initStars();
        light = new SpotLight();
        light.setSpotOuterAngle(FastMath.QUARTER_PI);
        stars.addLight(light);
    }
    @Override
    public void simpleUpdate(float tpf) {
        super.simpleUpdate(tpf);
        List<Spatial> starList = stars.getChildren();
        for (Spatial s : starList) {
            s.move(0, 0, -.4f);
            if (s.getWorldTranslation().z < -maxDistance) {
                s.setLocalTranslation(FastMath.nextRandomFloat() * 100 - 50, FastMath.nextRandomFloat() * 100 - 50, maxDistance);
            }
        }
        light.setDirection(cam.getDirection());
    }
    private void initStars() {
        Geometry star;
        for (int i = 0; i < 100; i++) {
            star = new Geometry("Star" + i, new Box(1, 1, 1));
            star.setMaterial(mat);
            star.rotate(FastMath.nextRandomFloat() * FastMath.TWO_PI, FastMath.nextRandomFloat() * FastMath.TWO_PI, FastMath.nextRandomFloat() * FastMath.TWO_PI);
            star.setLocalTranslation(FastMath.nextRandomFloat() * 100 - 50, FastMath.nextRandomFloat() * 100 - 50, FastMath.nextRandomFloat() * maxDistance * 2 - maxDistance);
            stars.attachChild(star);
        }
    }
}

If you want I can give you how it looked when I created the project before I replaced the harness and activity. Also, if someone knows how to spoiler things, as [spoiler] does not work, please tell me how and I will spoiler this asap. Atm. it is simply not rendering the skybox but everything else, including the lightning, seems to work fine. The whole application is available for DL here, same link as the previous post.

Thanks a lot for the help, I really appreciate it.

I think we can rule out that there’s something wrong with the setup, then. Things are being displayed.
Are the textures power of 2? Can you try with any of the skyboxes that are part of the jMonkeyEngine?

Yes, the original textures were 2048x2048 but for debugging I am currently using 512x512. I just double checked all images, they are correct in terms of resolution.

I seem unable to find the default skyboxes? They are not available from the scene editor and I have no idea what their names are.

.dds dont works in android for me. Use .jpg, .png for skys and split it in the needed images.
Also be careful with the memory-limit in android-phones.

I can’t help you with any more information right now.
I tried to update to the latest cardboard 0.5.7 and have some issues with my app as well.
It’s entirely black when starting the jme app. However, if I flip it upside down (and sometimes back again) it sometimes shows up.
I have a vague memory of encountering this before, and my guess is it’s somehow taking too long to initialize. And then when the activity is restarted it’s cached and it’s quicker. Well, it’s a theory.
Once my app shows up, it does display the skybox.

It doesn’t match with your issue though since you see the boxes.

Examples flying cubes work fine with 0.5.7 too

@hermetic It is jpg and the resolution is just 512x512 per side so I don’t think that it is a memory limit.
@rickard Wow, your problem seems really strange as well. My phone refuses to flip cardboard for some reason and is only available in one direction so I can’t try your solution. Do you think pre-loading everything before application starts will solve it? I will try adding the skybox after everything is initialized and see if that helps, maybe on a separate thread. Would you mind testing my application and see if you get the same problem as you get or the same as I get? It is available for DL in my previous post and is just your flying cubes example with skybox. Also, could you link an older version of cardboard which I can work with until we figure this problem out? I can’t seem to find it. I am really grateful for your assistance and I will gladly help trying to figure out a solution for this strange problem.

Best regards, Philip.

You can find the history for cardboard.jar here:
cardboard.jar