[SOLVED] Jme3 Beginner: Importing .obj Model from Blender

So this topic has been discussed several times on the forum but I can’t seem to be able to make it work. I have basically the usual question concerning importing a simple .obj model into jme3. As I save the file as .obj from Blender and put it in my project folder under models (I am using Eclipse btw).



I know that the location is not Models/newobj.obj so how can I locate this file? I already spend some time on it and can’t seem to locate it even when I put the whole file path.





my code is:



[java]// create the geometry and attach it

Geometry teaGeom = (Geometry) assetManager.loadModel(“put location here”);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/ShowNormals.j3md”);

teaGeom.setMaterial(mat);

rootNode.attachChild(teaGeom);

[/java]

Just my remark:

When you export obj, so export NORMALS too (there is a check-box in the exporter).



About a path… just put your model to “assets” folder located in your project.

[java]Geometry teaGeom = (Geometry) assetManager.loadModel(“yourModel.obj”);[/java]



Or you can make a folder in the “assets” folder. For Example, “maModels”

[java]Geometry teaGeom = (Geometry) assetManager.loadModel(“maModels/yourModel.obj”);[/java]

mifth, I don’t have an asset folder, I am using Eclipse

well, if you know how assets work in netbeans/JMP… so they should work in the same way as in eclipse.

Here is a hint: http://hub.jmonkeyengine.org/groups/general-2/forum/topic/netbeans-eclipse/



or you can try Google: assets netbeans eclipse



Sorry, I use netbeans… and all core devs too.

@garnaut

in eclipse, go to project’s properties, choose Java Build Path, click Add External Class Folder and then just choose your assets directory (it will became visible in Referenced Libraries and jme founds your datas).

1 Like

Already tried that Larda and although it is visible there I still get a null pointer for a file not found



trace attached:



[java]aught exception thrown in Thread[LWJGL Renderer Thread,5,main]

com.jme3.asset.AssetNotFoundException: Models/F_Drive.mtl

at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:236)

at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:281)

at com.jme3.scene.plugins.OBJLoader.loadMtlLib(OBJLoader.java:324)

at com.jme3.scene.plugins.OBJLoader.readLine(OBJLoader.java:371)

at com.jme3.scene.plugins.OBJLoader.load(OBJLoader.java:555)

at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:240)

at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:373)

at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:383)

at com.kiva.sim.animation.Jme3Cinematics.create3dDrives(Jme3Cinematics.java:454)

at com.kiva.sim.animation.Jme3Cinematics.createScene(Jme3Cinematics.java:383)

at com.kiva.sim.animation.Jme3Cinematics.simpleInitApp(Jme3Cinematics.java:122)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:230)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:124)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:200)

at java.lang.Thread.run(Unknown Source)[/java]

imo you can just create your own JAR called assets.jar from folders you will create Eclipse: Export->Java->JAR. Then somethin like create executable Jar with classes and Assets(included).



BUT: Why you dont prefer to use JMP? JMP is on netbins engine, netbins and eclipse are very similar :slight_smile:

I just want it to recognize/read the assets folder I have, not sure why I need a jar file for that.



I really like JMP however, this project is just a small part (animation part) of a much larger project (simulation)

About Path:


In a jMonkeyPlatform project, jME3 seaches for models in the assets directory of your project

but for external assets you can:
[java] assetManager.registerLocator(URLtoZIP,
HttpZipLocator.class.getName());
Spatial scene = assetManager.loadModel("main.scene");
rootNode.attachChild(scene);[/java]
or
[java]
assetManager.registerLocator("town.zip", ZipLocator.class.getName());
Spatial scene = assetManager.loadModel("main.scene");
rootNode.attachChild(scene);
[/java]
JME3 offers ClasspathLocator, ZipLocator, FileLocator, HttpZipLocator, and UrlLocator (see com.jme3.asset.plugins).


its part of hello asset.

Can't you use external registerLocator to use assets?

but I want to include my file in my distribution. Don’t u use external assets if you didn’t want to include that file?



If I set the Models folder in my project classpath shouldn’t it read that folder automatically?

it should but:

i dont know how exacly assetManager works, but i think its problem becouse it propably “register automaticly” only folders included in “assets” folder/subfolders

and where’s the original one located?

i have it just in project folder



EDIT: i will try later to create working case on eclipse

so I’m running this in Eclipse and it works for:



[java]assetManager.loadModel(“Models/Teapot/Teapot.obj”);[/java]



I wonder where it’s reading that from!

“I wonder where it’s reading that from!”

when for example i develop it for windows(i mean executable version) i have:

  • exe
  • exetucable Jar
  • lib folder with libraries (Included lwjgl.jar, assets.jar, etc) → thats why it need assets.jar, just to use it(it weight less)



    but as i said you can also have other place for assets, you must just register it for assetManager

    so i think answer about assets is that assets are in assets.jar included into lib folder



    this assets.jar have itself standard folders(but it can have folders named as you wish):


  • Models, Materials, Effects, Scenes, Sounds, Textures, and more



    tip: you can open assets.jar via WinRAR and add new assets. or just create assets folder(with models, etc)



    About question. how do it automaticly and properly in eclipse?

    i dont know, you must seek in google

so ur telling me to put that asset folder in a jar file? I’ve never created my own jar so I tried zipping that folder (didn’t create a manifest file) and added it to my classpath so I can see the assets.jar in the classpath and under assets.Models there’s the spatial.obj I am lookig for however still I can’t get to read it :s

i never tried creating jar with winrar(i just know i can open and edit it) so i dont know if “zipped” folder as jar will work(it should have META-INF)

btw: try to have it in “lib” folder(this lib folder in place where you have executable jar) so maybe it will see it “automaticly”



as i see you already found topic:

http://hub.jmonkeyengine.org/groups/import-assets/forum/topic/assets-not-found-problem/



but solution of this topic was create project with JMP(maybe its good way, but then you have to adapt big project to it)

that didn’t do it…



I don’t get it… if I specify



[java]assetManager.loadModel(C:\Users\garnaout\Desktop\Accurev_workspace\MyModel\assets\Models\spatial.obj";);[/java]



specifically why won’t it work??? why doesn’t it read it… that’s weird.

it dont read it becouse it is not registered in assetManager

maybe you should try look here:



https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_asset?s[]=register&s[]=location

and here:

https://wiki.jmonkeyengine.org/legacy/doku.php/starter:hello_intersection?s[]=register&s[]=location


If a file is not located in the default location, you can register a custom Locator and load it from any path


if you have it in default location maybe you should write somethin like "/Models/model.obj" or "../Models/model.obj" not "c:// etc"

then shouldnt something like this fix it?



[java] assetManager.registerLocator(“C:\Users\garnaout\Desktop\Accurev_workspace\JSLDriveModel\assets\Models\spatial.obj”, ClasspathLocator.class.getName());



[/java]



wlel it doesn’t :S