Assets not found problem

I’m a noob in JME.

I was following the tutorial about assets https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_asset

It works perfectly but when I try to change a little bit it doesn’t work.

Here is the original part

[java]package jme3test.helloworld;



import com.jme3.app.SimpleApplication;

import com.jme3.font.BitmapText;

import com.jme3.light.DirectionalLight;

import com.jme3.material.Material;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.Spatial;

import com.jme3.scene.shape.Box;



/** Sample 3 - how to load an OBJ model, and OgreXML model,

  • a material/texture, or text. */

    public class HelloAssets extends SimpleApplication {



    public static void main(String[] args) {

    HelloAssets app = new HelloAssets();

    app.start();

    }



    @Override

    public void simpleInitApp() {



    Spatial teapot = assetManager.loadModel(“Models/Teapot/Teapot.obj”);

    Material mat_default = new Material(

    assetManager, “Common/MatDefs/Misc/ShowNormals.j3md”);

    teapot.setMaterial(mat_default);

    rootNode.attachChild(teapot);



    // Create a wall with a simple texture from test_data

    Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f);

    Spatial wall = new Geometry(“Box”, box );

    Material mat_brick = new Material(

    assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

    mat_brick.setTexture(“ColorMap”,

    assetManager.loadTexture(“Textures/Terrain/BrickWall/BrickWall.jpg”));

    wall.setMaterial(mat_brick);

    wall.setLocalTranslation(2.0f,-2.5f,0.0f);

    rootNode.attachChild(wall);



    // Display a line of text with a default font

    guiNode.detachAllChildren();

    guiFont = assetManager.loadFont(“Interface/Fonts/Default.fnt”);

    BitmapText helloText = new BitmapText(guiFont, false);

    helloText.setSize(guiFont.getCharSet().getRenderedSize());

    helloText.setText(“Hello World”);

    helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);

    guiNode.attachChild(helloText);



    // Load a model from test_data (OgreXML + material + texture)

    Spatial ninja = assetManager.loadModel(“Models/Ninja/Ninja.mesh.xml”);

    ninja.scale(0.05f, 0.05f, 0.05f);

    ninja.rotate(0.0f, -3.0f, 0.0f);

    ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);

    rootNode.attachChild(ninja);

    // You must add a light to make the model visible

    DirectionalLight sun = new DirectionalLight();

    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));

    rootNode.addLight(sun);



    }

    }[/java]









    when I change this part [java] // Create a wall with a simple texture from test_data

    Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f);

    Spatial wall = new Geometry(“Box”, box );

    Material mat_brick = new Material(

    assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

    mat_brick.setTexture(“ColorMap”,

    assetManager.loadTexture(“Textures/Terrain/BrickWall/BrickWall.jpg”));

    wall.setMaterial(mat_brick);

    wall.setLocalTranslation(2.0f,-2.5f,0.0f);

    rootNode.attachChild(wall);[/java]



    to

    [java] // Create a wall with a simple texture from test_data

    Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f);

    Spatial wall = new Geometry(“Box”, box );

    Material mat_brick = new Material(

    assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

    mat_brick.setTexture(“ColorMap”,

    assetManager.loadTexture(“Textures/Wall.jpg”)); //The only line changes

    wall.setMaterial(mat_brick);

    wall.setLocalTranslation(2.0f,-2.5f,0.0f);

    rootNode.attachChild(wall);[/java]

    and I’ve put Wall.jpg file (another texture) under assets/Textures in the root of the project

    and I get the following exception com.jme3.asset.AssetNotFoundException



    I have tried to put Textures/Wall.jpg everywhere and still the same error.







    Looking forward to your help

    Thanks.

Just double checking… are you using JMP (the JME IDE) or some other development environment?



The part that automatically packages up the assets directory into an assets.jar file is part of the JMP ANT build scripts… and it should “just work” in that case. Assuming the file names are identical including upper and lower case, that is.

pspeed said:
Just double checking... are you using JMP (the JME IDE) or some other development environment?

The part that automatically packages up the assets directory into an assets.jar file is part of the JMP ANT build scripts... and it should "just work" in that case. Assuming the file names are identical including upper and lower case, that is.

No I'm using Eclipse.

Did you refresh your ws, do you have build automatically turned on and is the texture located in your workspace root(check if in the bin folder after refresh). The default asset manager uses the classpath locator. So it must be in a loc. for your classloader.

[java]assetManager.loadTexture("assets/Textures/Wall.jpg"));[/java]

kidneytrader said:
[java]assetManager.loadTexture("assets/Textures/Wall.jpg"));[/java]

It didn't work neither.


But I got it to work anyway I made a project with the JMP and I opened it with Eclipse and it work fine

is there a “right” way of doing this? I am having a similar issue and I am also using Eclipse as my IDE.



I even tried to create a jar with my assets but still getting asset not found!

The assets are normally loaded from the class path while the project is mostly executed from the project directory, hence the differences in deployment / running from the IDE. So you probably import the jme3-testdata.jar to the class path (which is why you can load the example models) and don’t do anything about the assets folder. Hence the application cannot access the data. What jMP does is it adds the assets folder to the run class path of the project and on deployment it creates a jar file from the folder which is added to the class path. If thats too much to understand its probably best to create the project using jMP even if you want to use Eclipse for coding because “you know it better” :stuck_out_tongue:

I don’t know how to do this in Eclipse as I just took the easy route.



In general, the assets have to be in an assets.jar and the assets.jar has to be on the classpath. (Actually, the jar can be anything as long as its on the classpath.) As I understand it, by default the AssetManager will look in the classpath, ie: load class resources. You can register other locators if you want different behavior.

so i still can’t understand why if I add the assets folder to the classpath (or add it as assets.jar) I cannot get the resource located?



Normen, I dont wanna switch to JMP just to locate one resource, that simply does not seem logical. How can I explicitly put that obj file in the project to be read in other IDEs such as Eclipse? If i understood u correctly, I did add the assets folder to the run class path of the project and also created a jar file (called assets.jar) from the folder which is added to the class path as well. That still doesn’t do it.

Well when you create an Android or any other project with eclipse then that project is also created by some external tool and eclipse just shows you the content of the files etc. A jMP generated project makes sure you get all the benefits of the deployment options and extensions for the SDK, so you are sure to have a “standard” jME3 project that people can easily help you with. Eclipse can handle ant-based projects fine normally.



As for the paths, theres no other magic going on, just make sure your IDE and/or distribution jar knows its class path and that you use correct case… Also if you add the “assets” folder to the class path then you don’t need to prefix the path with “assets” obviously.

As a test… do something like this:



[java]

URL u = SomeClass.class.getResource( “/com/jme3/math/Vector3f.class” );

System.out.println( “Test1:” + u );

u = SomeClass.class.getResource( “Textures/OneOfYourTextures.jpg” );

System.out.println( “Test2:” + u );

[/java]



Filling in SomeClass and “OneOfYourTextures” as appropriate. Note: make sure to not include the “assets” part unless you also strangely put that in your jar for some reason.

[java]URL u = Jme3Cinematics.class.getResource( "/com/jme3/math/Vector3f.class" );

System.out.println( "Test1:" + u );

u = Jme3Cinematics.class.getResource( "Models/spatial.obj" );

System.out.println( "Test2:" + u );[/java]



Test1:jar:file:/C:/Users/garnaout/Desktop/My%20Work%2032/jME3_08-04-2011/jMonkeyEngine3.jar!/com/jme3/math/Vector3f.class

Test2:null

So obviously the assets folder is not on your classpath. Check the Eclipse manual again.

garnaout said:
[java]URL u = Jme3Cinematics.class.getResource( "/com/jme3/math/Vector3f.class" );
System.out.println( "Test1:" + u );
u = Jme3Cinematics.class.getResource( "Models/spatial.obj" );
System.out.println( "Test2:" + u );[/java]

Test1:jar:file:/C:/Users/garnaout/Desktop/My%20Work%2032/jME3_08-04-2011/jMonkeyEngine3.jar!/com/jme3/math/Vector3f.class
Test2:null



Yes, as Normen points out, this test illustrates one absolutely irrevocable and irrefutable fact: Models/spatial.obj is not on the classpath in any conceivable way that Java knows about. Figure that out and the asset manager will be able to find your asset.

I’m no expert in Eclipse but I am pretty sure I added the assets folder to my project classpath.



note that the trace shows:

[java]SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

com.jme3.asset.AssetNotFoundException: Models/F_Drive.mtl[/java]

instead of F_Drive.obj (what I called my object)









Discussion being followed here:

http://hub.jmonkeyengine.org/groups/import-assets/forum/topic/jme3-beginner-importing-obj-model-from-blender/?topic_page=2#post-142211

garnaout said:
[java]URL u = Jme3Cinematics.class.getResource( "/com/jme3/math/Vector3f.class" );
System.out.println( "Test1:" + u );
u = Jme3Cinematics.class.getResource( "Models/spatial.obj" );
System.out.println( "Test2:" + u );[/java]

Test1:jar:file:/C:/Users/garnaout/Desktop/My%20Work%2032/jME3_08-04-2011/jMonkeyEngine3.jar!/com/jme3/math/Vector3f.class
Test2:null



snipped potentially incorrect random ranting. ;)

Important edit I just noticed: The getResource() line for the model needs to have a "/" in front of it. So that could be causing the miss in this case... though it should not cause a problem with AssetManager. It took my clearly stating the "as quoted in the above getResource()" line to make me look at it again. :P

this wouldn’t change anything though :S could it be something from the file itself (.obj) ? from Blender? why am I getting:



[java]

Sep 14, 2011 11:24:26 PM com.jme3.material.MaterialDef <init>

INFO: Loaded material definition: Phong Lighting

Unknown statement in OBJ! o

Sep 14, 2011 11:24:26 PM com.jme3.scene.plugins.OBJLoader createGeometry

WARNING: OBJ mesh F_Drive-geom-0 doesnt contain normals! It might not display correctly

Sep 14, 2011 11:24:26 PM com.jme3.scene.Node attachChild[/java]

So now it’s finding the asset and something else is wrong?

well added the / still getting null but now it reads it (so guess yeah it finds the asset) but I get

Unknown statement in OBJ! 0 in my

full log:

[java]NFO: Child (BitmapFont) attached to this node (null)

Sep 14, 2011 11:37:29 PM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Gui Node)

Test1:jar:file:/C:/Users/garnaout/Desktop/My%20Work%2032/jME3_08-04-2011/jMonkeyEngine3.jar!/com/jme3/math/Vector3f.class

Test2:null

Sep 14, 2011 11:37:29 PM com.jme3.material.MaterialDef <init>

INFO: Loaded material definition: Phong Lighting

Unknown statement in OBJ! o

Sep 14, 2011 11:37:29 PM com.jme3.scene.plugins.OBJLoader createGeometry

WARNING: OBJ mesh F_Drive-geom-0 doesnt contain normals! It might not display correctly

Sep 14, 2011 11:37:29 PM com.jme3.scene.Node attachChild

INFO: Child (F_Drive-geom-0) attached to this node (F_Drive-objnode)

Sep 14, 2011 11:37:29 PM com.jme3.scene.plugins.OBJLoader createGeometry

WARNING: OBJ mesh F_Drive-geom-1 doesnt contain normals! It might not display correctly

Sep 14, 2011 11:37:29 PM com.jme3.scene.Node attachChild

INFO: Child (F_Drive-geom-1) attached to this node (F_Drive-objnode)

Sep 14, 2011 11:37:29 PM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.ClassCastException: com.jme3.scene.Node cannot be cast to com.jme3.scene.Geometry[/java]

error happening here:

Geometry geo = (Geometry)spatial_geom; // this is a spatial and this line was working before so problem is not here