[SOLVED] Error Loading .obj on android

Hi,

I am creating a sample AR App on android. I am trying to render the .obj model over the camera surface. The model is rendered but whole part of it is Black color when there is no texture for the relevant obj. When the model is assigned with texture, couldn’t see the texture over the model and error occurs.

Asset folder contains
Box_Image2.obj
Box_Image2.mtl
pixels.jpeg (texture image of box)

1st try was .
Spatial cube = assetManager.loadModel(“Models/Ninja/Box_Image2.obj”);
cube.scale(0.025f, 0.025f, 0.025f);
cube.rotate(0.0f, -3.0f, 0.0f);
cube.setLocalTranslation(0.0f, -2.5f, 0.0f);
rootNode.attachChild(cube);

    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);

2nd try was
Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
Spatial cube = assetManager.loadModel(“Models/Ninja/Box_Image2.obj”);
cube.scale(0.025f, 0.025f, 0.025f);
cube.rotate(0.0f, -3.0f, 0.0f);
cube.setLocalTranslation(0.0f, -2.5f, 0.0f);

   mat.setTexture("ColorMap", getAssetManager().loadTexture("Models/Ninja/pexels.jpeg"));
   cube.setMaterial(mat);
    rootNode.attachChild(cube);

    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);

in both scenario error was occurred as below
com.jm3.asset.AssetLoadException: An exception has occurred while loading asset
Exception thrown in Thread[GLThread3291,5,main] com.jme3asset.AssetLoadException : An exception has occurred while loading asset: Models/Ninja/pexels.jpeg(Flipped)(Mipmaped)
Please find the attached image

I compiling on Android 25(7 - Nougat), jme-3.1.0 Stable version.

1 Like

1)You said

then you refer to the image as “pexels.jpeg”

Make sure you’re not doing a typo mistake.

2)Make sure that your .obj,.mtl and .jpeg files are in the “Ninja” folder.

3)Make sure that your .mtl file references the .jpeg image.

4)Don’t use .obj files.Convert them to .j3o.

2 Likes

Thank you !

  1. here it was a typing mistake, in the asset folder image’s name is correct, pexels.jpeg
  2. Yeah it is in the same folder
  3. Yes it references the image correctly, through the .mtl file only program reads the image name , but showing error while loading.
  4. Yeah i just went through some conversations, as you said few people preferred to load the .j3o file. So that means .obj cannot be loaded? and how can i convert .obj into .j3o? is .j3o Jmonkey specific format ?
1 Like

Yes J3O is JMonkey-specific. You may be able to convert by right-clicking on the OBJ in the jME3 IDE and selecting “Convert to J3O Binary”.

1 Like

Here,just read this:
https://jmonkeyengine.github.io/wiki/jme3/intermediate/multi-media_asset_pipeline.html
It will solve most of your current and some of your future questions.
You’re welcome :slight_smile:

2 Likes

Hi Sir,
Thanks for your answer.

I could able to convert into .j3o .
Thanks.

2 Likes

HI,
it looks useful one for me.
Thank You!

1 Like

Hi,

I opened the Basicgame project and imported the .obj model(cube.obj), after the completion of import , it converted the .obj model into .j3o automatically and together with that .mtl and .png texture also got imported. I copied these files (.j3o,j3odata,.mtl,.png) to my android project’s asset folder that runs in android studio IDE.
But when I run the project , java.lang.OutOfMemoryError exception occurs . it says failed to allocate byte allocation with free bytes and 240MB until OOM. what could be the reason ?
FYI : image is 152*152 and size is just 49KB.

1 Like

The java.lang.OutOfMemoryError exception occurs due to the incorrect placement of models in asset folder.
Now its perfectly working.

3 Likes