[SOLVED] Gltf error with textured mesh

I’m developing on android studio and i get this error whenever i am testing a textured gltf file. It works fine with untextured version of my model. Here’s the stacktrace:

com.jme3.asset.AssetLoadException: An error occurred loading Models/textured-cube.glb
at com.jme3.scene.plugins.gltf.GltfLoader.loadFromStream(GltfLoader.java:150)
at com.jme3.scene.plugins.gltf.GlbLoader.load(GlbLoader.java:47)
at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(DesktopAssetManager.java:260)
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:374)
at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:417)
at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:421)
at com.bluetowel.core.src.Game.simpleInitApp(Game.java:76)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:239)
at com.jme3.app.AndroidHarness.initialize(AndroidHarness.java:477)
at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:346)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
Caused by: java.lang.IllegalStateException: Stream already opened
at com.jme3.asset.StreamAssetInfo.openStream(StreamAssetInfo.java:54)
at com.jme3.texture.plugins.AndroidNativeImageLoader.load(AndroidNativeImageLoader.java:33)
at com.jme3.texture.plugins.AndroidNativeImageLoader.load(AndroidNativeImageLoader.java:18)
at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(DesktopAssetManager.java:260)
at com.jme3.asset.DesktopAssetManager.loadAssetFromStream(DesktopAssetManager.java:342)
at com.jme3.scene.plugins.gltf.GltfLoader.readImage(GltfLoader.java:724)
at com.jme3.scene.plugins.gltf.GltfLoader.readTexture(GltfLoader.java:695)
at com.jme3.scene.plugins.gltf.GltfLoader.readTexture(GltfLoader.java:679)
at com.jme3.scene.plugins.gltf.GltfLoader.readMaterial(GltfLoader.java:609)

Where is “textured-cube.glb” located at runtime?

1 Like

I downloaded a boilerplate off github “https://github.com/leader94/JmeWithAndroid”, so the model is located under the assets/Models folder

1 Like

Pawan’s boilerplate project doesn’t have an assets folder. So it’s likely the project doesn’t support locating assets there.

JMonkeyEngine’s default asset locator looks for assets on the classpath. When you develop in the JMonkeyEngine SDK, the SDK automatically copies assets from your project’s asset folder into the class jar, so they are accessible to the application. Android Studio doesn’t do this—at least, not by default.

1 Like

is there a way i can bypass this without using the jmonkey sdk?

Please use code block to display the stack trace.

Can you try with a .gltf file with separated texture instead of .glb.

Also does it load fine on desktop?

1 Like

it loads fine on desktop.
Thanks! I will try the .gltf and .bin format

It finally worked :smiley:

4 Likes

The assets are located here https://github.com/leader94/JmeWithAndroid/tree/master/app/src/main/assets/Textures instead of core probably.

The SDK will have a new Android Template for 3.4

2 Likes

Glad it worked. So did you use .gltf and .bin ?

It seems there is an issue when using glb loader so.

Caused by: java.lang.IllegalStateException: Stream already opened
at com.jme3.asset.StreamAssetInfo.openStream(StreamAssetInfo.java:54)
at 

Just took a look at AndroidNativeImageLoader and seems it opens stream two times.

@waverider404 can you please try to change the above code to this locally and test if it will work with glb?

in = info.openStream();
return load(in, flip, tmpArray);

Edit:
But curious why this error only happens with glb and not gltf + bin? @Darkchaos any thought?

1 Like
Multiple dex files define Lcom/jme3/texture/plugins/AndroidNativeImageLoader;

It seems i can’t directly override the plugin in android studio :disappointed:

Okay, submitted a patch that should hopefully fix the Android issue with glb loader that uses StreamAssetInfo for textures.

Edit:
Merged.

@waverider404 the fix is now available on master branch in case you want to try it out.

5 Likes

Your contributions are really appreciated @Ali_RS - great work :heart:

2 Likes

I would’ve expected the opposite or something, but I guess it’s because loading textures differs there.
Probably textures in gltf+bin get loaded manually.
A breakpoint on this method would tell you why, but you’d need to setup an android project first etc pp.

I’ll take a quick look at the GLTF Code

Edit: I guess https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinLoader.java is already the solution.

It reads the whole bin file into memory here: https://github.com/jMonkeyEngine/jmonkeyengine/blob/e31a0477468d5130e16f66c9034f32adec6b8308/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java#L553

Edit2: Forgot what I was saying:


GLB just loads the sections into memory and then uses the regular gltfloader I think.

We could now compare those specific glb and gltf/bin files or we just hope it works now :stuck_out_tongue:

1 Like

Thanks @jayfella, glad to hear that. :slightly_smiling_face:

Happy that I am able to help with improving the engine and will keep doing so as far as my time and knowledge let me.

5 Likes

Still the same error, i am using jme 3.3.0-stable

No, it’s not 3.3.0-stable. You need to locally build jme3-android package with gradle from the source code on master branch. After build you should get jme3-android-3.4.0-SNAPSHOT.jar.

But wait, in case you want, I can upload it for you so you won’t need to build it yourself.

1 Like

And just to be clear, 3.3.0-stable is fixed in stone. it will never again change for all of future-time. 10 years from now, 3.3.0-stable will have the exact same bytes in it that it does today.

Any new released code would have a new version when it’s eventually released.

So any new fixes that are posted will not be in 3.3.0-stable… but some future 3.3.1 or 3.4.0 or whatever. (or a local 3.4.0-SNAPSHOT if you build from source).

1 Like

Thanks for the clarification :smiley: :smiley: