Shadow renderer and blender / jme3 handling *.obj or *.scene with materials and textures

Hi community, I’m new to jmonkey but I know java. I’ve just started to learn how to work with blender (basics).

Well, actually the whole application with jme went very well and I must say that this is a phantastic engine! I’ve never seen something that is simmilar to.



But there are some points I’d like to ask you:

  • Are you updateing the live-shadow-renderer or why can’t I see anything and without a single error (class is striked trough in the code).
  • When I worked with obj and or scene files within blender I don’t know how to set all settings right to have materials and textures exported - I’d like to see the object in jme same way like in blender (materials and textures)



    I’m working with Orgre3D (exporter) and with Blender 2.57 (latest version)



    Edit: I’m able to load the model in jme and set textures like: mat_test.setTexture(assetManager.loadTexture()) but isn’t there a way to import materials and textures with orgre (.scene) together?

    In Blender one is able to add textures to materials and materials to meshes but when I do that I can only see my diffuse material without the textures on it (after exporting and loading in jme)



    May someone can explain that things to me?



    Best,

    cm
Okay I fixed the 2nd issue with the ogre.

So this will be fixed in the next JME Version I guess?
About the OBJ, I was able to export a textured model and got it to work in jME3.

Me too, after plenty of test ^^
Well, it worked but what I don't understand is the texture path - have a look at the mtl and obj file:

untitled.obj
[java]# Blender v2.57 (sub 1) OBJ File: 'untitled.blend'
# www.blender.org
mtllib untitled.mtl
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
vt 0.500000 0.750000
vt 0.250000 0.750000
vt 0.250000 0.500000
vt 0.500000 0.500000
vt 0.499997 0.000000
vt 0.499998 0.250000
vt 0.249999 0.250001
vt 0.249998 0.000002
vt 0.500000 1.000000
vt 0.250000 1.000000
vt -0.000000 1.000000
vt -0.000000 0.750000
vt 0.750000 0.750000
vt 0.750000 1.000000
usemtl Mat_box_png
s off
f 1/1 2/2 3/3 4/4
f 5/5 8/6 7/7 6/8
f 1/1 5/9 6/10 2/2
f 2/2 6/10 7/11 3/12
f 3/3 7/7 8/6 4/4
f 5/9 1/1 4/13 8/14
[/java]

untitled.mtl

[java]# Blender MTL File: 'untitled.blend'
# Material Count: 1
newmtl Mat_box_png
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd C:Usersfmueller.BAMDocumentsjMonkeyProjectsPlayerTestassetsTexturesbox.png
[/java]

They are two big differences between your version and mine:

- In the obj file there are some more coordinates - why?
- See the mtl file - there is this parameter called map_Kd. I thought that my texture now has to be located in the textures folder of my project but in fact this doesn't work. Then I putted the texture called box.png into the same directory where my model lies. To my astonishment it worked fine.
But as I moved the texture it is no longer in the textures folder... shouldn't the material load from map_Kd?

Thanks for your help

For the shadow issue, make sure you set the shadow mode (Spatial.setShadowMode) to the appropriate value.

For the model importing issue, make sure you only specify 1 image-based texture for each material, you cannot use generated textures

1 Like

Thanks for your prompt response.



shadow issue: I took the code from the tutorial on this website (here: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:light_and_shadow under “Parallel-Split Shadow Map”) then I added the following line:



[java]rootNode.setShadowMode(ShadowMode.CastAndReceive);[/java]



Nothing happened at all. I also tried to set the shadow mode to a spatial directly - no successs.



importing issue: I took these steps:



within Blender

  • create a mesh (cube)
  • scale mesh local
  • add a new texture → load from file → set mapping to cubic
  • add a new material → set diffuse and specular color
  • select mesh → goto edit mode → assign material
  • press F12 to see how it renders the mesh (looks like expected)
  • export to *.obj (check all required options like: “export material” for an example) → put in asset folder of jme project



    within jme
  • convert *.obj to *.j3o
  • use following code to load model:



    [java] Spatial model = assetManager.loadModel("Models/model.j3o");

    mat.setFloat("Shininess", 5f);

    model.setMaterial(mat);

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

    rootNode.attachChild(model);[/java]



    Result: The model rendered but there was only a redish color (as I defined in blender) with a specular reflection but without the texture. Do I have to draw textures extra like with mat.setTexture…?


For the model importing issue, make sure you only specify 1 image-based texture for each material, you cannot use generated textures


You mean that I can't use one material with 2 textures like: diffuse map, normal map maybe and/or some others?

Best,
cm

You have to use UV coordinates, you cannot use generated coordinates.

E.g. under Textures menu, Mapping → Coordinates has to be set to UV

Tanks for you comment.



Hmm… I don’t understand what I am doing wrong mate I really don’t know.

I assigned the material with 2 textures (diffuse and bumpmap) then I unwrapped my cube and set mapping to uv (I’ve ever done this before) it fitted perfectly to the cube when I rendered it.



Well I think the blender part has been done correctly. But when I load to jme I can just see a single colored cube (gray). So maybe we misunderstanding eachother because as I said I know how to add textures to this cube in jm but I asked you if it is possible to load the object with textures (they should be already saved inside the *.obj modle shouldn’t they?) just by writing:

[java]Spatial model = assetManager.loadModel(“Models/model.obj”);

rootNode.attachChild(model)[/java]

I could define a material object to which I set the textures individually… but is this step neccessaire? I’d could be that obj is not the format for that but how about Ogre3D? It must work!



When I export my model to *.scene I get 5 files:



Cube.mesh

Cube.mesh.xml

Scene.material → I renamed it to Cube.material

stonewall.jpg

stonewallbump.jpg



But when I try to load I got an error code:

[java]WARNUNG: Unsupported pass directive: emissive

04.05.2011 21:39:05 com.jme3.app.Application handleError

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

java.util.InputMismatchException

at java.util.Scanner.throwFor(Scanner.java:840)

at java.util.Scanner.next(Scanner.java:1461)

at java.util.Scanner.nextFloat(Scanner.java:2319)

at com.jme3.scene.plugins.ogre.MaterialLoader.readColor(MaterialLoader.java:85)

at com.jme3.scene.plugins.ogre.MaterialLoader.readPassStatement(MaterialLoader.java:227)

at com.jme3.scene.plugins.ogre.MaterialLoader.readPass(MaterialLoader.java:283)

at com.jme3.scene.plugins.ogre.MaterialLoader.readTechnique(MaterialLoader.java:300)

at com.jme3.scene.plugins.ogre.MaterialLoader.readMaterialStatement(MaterialLoader.java:307)

at com.jme3.scene.plugins.ogre.MaterialLoader.readMaterial(MaterialLoader.java:329)

at com.jme3.scene.plugins.ogre.MaterialLoader.load(MaterialLoader.java:435)

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

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

at com.jme3.scene.plugins.ogre.MeshLoader.load(MeshLoader.java:805)

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

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

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

at mygame.Main.simpleInitApp(Main.java:205)

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

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

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

at java.lang.Thread.run(Thread.java:662)[/java]

please have a look at the Cube.material as well:

[java]

material missing_material

{

receive_shadows off

technique

{

pass

{

ambient 0.1 0.1 0.1 1.0

diffuse 0.8 0.0 0.0 1.0

specular 0.5 0.5 0.5 1.0 12.5

emissive 0.3 0.3 0.3 1.0

}

}

}

material mat

{

receive_shadows on

technique

{

pass

{

cull_hardware none

ambient vertexcolour

diffuse vertexcolour

specular 0.5 0.5 0.5 1.0 12.5

emissive 0.0 0.0 0.0 1.0

scene_blend one zero

texture_unit

{

texture stonewall.jpg

tex_address_mode wrap

scale 1.0 1.0

tex_coord_set 0

colour_op_ex blend_manual src_current src_texture 0.0

}

texture_unit

{

texture stonewallbump.jpg

tex_address_mode wrap

scale 1.0 1.0

tex_coord_set 0

colour_op_ex blend_diffuse_colour src_current src_texture

}

}

}

}

[/java]



What do you think about that?



Best,

cm

Okay I fixed the 2nd issue with the ogre.



About the OBJ, I was able to export a textured model and got it to work in jME3.



Here’s my files:



untitled.obj

[java]# Blender v2.57 (sub 0) OBJ File: ‘’

www.blender.org

mtllib untitled.mtl

o Cube

v 1.000000 -1.000000 -1.000000

v 1.000000 -1.000000 1.000000

v -1.000000 -1.000000 1.000000

v -1.000000 -1.000000 -1.000000

v 1.000000 1.000000 -1.000000

v 0.999999 1.000000 1.000001

v -1.000000 1.000000 1.000000

v -1.000000 1.000000 -1.000000

vt 0.000000 0.000000

vt 1.000000 0.000000

vt 1.000000 1.000000

vt 0.000000 1.000000

usemtl Material_t1.png

s off

f 1/1 2/2 3/3 4/4

f 5/1 8/2 7/3 6/4

f 1/2 5/3 6/4 2/1

f 2/2 6/3 7/4 3/1

f 3/2 7/3 8/4 4/1

f 5/4 1/1 4/2 8/3

[/java]



untitled.mtl

[java]# Blender MTL File: ‘’

Material Count: 1

newmtl Material_t1.png

Ns 96.078431

Ka 0.000000 0.000000 0.000000

Kd 0.640000 0.640000 0.640000

Ks 0.500000 0.500000 0.500000

Ni 1.000000

d 1.000000

illum 2

map_Kd t1.png[/java]



Texture:

http://i.imgur.com/13gQW.png



Result:

http://i.imgur.com/Gubx6.png



code used to load model:

[java]Spatial model = assetManager.loadModel("untitled.obj");

AmbientLight al = new AmbientLight();

rootNode.addLight(al);

rootNode.attachChild(model);[/java]

Due to the way the asset manager works, all paths are relative to your asset root. In other words, the asset manager doesn’t understand your system path like C: … etc etc. It has to be given a relative path to the assets folder in your project.

If you send your application to other people they won’t be able to run it because they dont have the texture in the exact path you have it at.



In the case of the OBJ loader, the texture must be in the same folder as the model to be loaded correctly.

Due to the way the asset manager works, all paths are relative to your asset root. In other words, the asset manager doesn’t understand your system path like C: …. etc etc. It has to be given a relative path to the assets folder in your project.
If you send your application to other people they won’t be able to run it because they dont have the texture in the exact path you have it at.


Well I know that, but blender created this file for me ;) so do I have to rewrite this line every time I export?

In the case of the OBJ loader, the texture must be in the same folder as the model to be loaded correctly.

Sounds a bit strange - we have extra folders for textures in the project so why put them together? it will become a mess though.

Isn't it possible to use a relative path like:
[java]map_KD /textures/texture.png[/java]

Just an idea but that won't affect me that much - I could create folders instead.

Best,
cm

The appropriate place to put the model’s textures would be in the model folder, e.g.

Models/MyModel/MyModel.obj + MyModel.png

This way all files that are needed by MyModel are located in Models/MyModel.

This is better organized than putting the texture for every model in Textures/

crazymonkey said:
Well I know that, but blender created this file for me so do I have to rewrite this line every time I export?

No. As you can see, the model can be loaded with the texture even though it has a full path. As long as the texture is in the same folder as the model.

Okay, okay well then so will I do.



Another question - a few minutes ago I tried to load my game (it always worked without any problems) but now it seems that all the assets from jme (the assets which are already included in the sdk) are gone - I got many errors foreach texture that I loaded from these locations.



E.g.: [java]rootNode.attachChild(SkyFactory.createSky(assetManager, “Textures/Sky/Bright/BrightSky.dds”, false));[/java]

or [java]mat_terrain.setTexture(“Alpha”, assetManager.loadTexture(“Textures/Terrain/splat/alphamap.png”));[/java]



they don’t work anymore - I haven’t done anything.



[java]05.05.2011 17:50:36 com.jme3.asset.DesktopAssetManager loadAsset

WARNUNG: Cannot locate resource: Textures/Sky/Bright/BrightSky.dds (Flipped) (Cube) (Mipmaped)

05.05.2011 17:50:36 com.jme3.material.MaterialDef <init>

INFO: Loaded material definition: Sky Plane

05.05.2011 17:50:36 com.jme3.app.Application handleError

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

java.lang.IllegalArgumentException: The given texture parameter is not set.

at com.jme3.material.Material.clearTextureParam(Material.java:375)

at com.jme3.material.Material.setTexture(Material.java:417)

at com.jme3.util.SkyFactory.createSky(SkyFactory.java:25)

at com.jme3.util.SkyFactory.createSky(SkyFactory.java:77)

at com.jme3.util.SkyFactory.createSky(SkyFactory.java:85)

at mygame.Main.simpleInitApp(Main.java:104)

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

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

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

at java.lang.Thread.run(Thread.java:662)[/java]



Is there something wrong with the code or what happened to the ressource files?



Thank you very much indeed.

If you are using jMP, the assets that come with jME3 are not included in your assets folder.

I just donwloaded the nightly builds - here are the sources I need. Maybe they are gone by installing jme3 alpha as I removed everything before the install.



How to reassign these sources? Where do I have to put these nightly-builds folder into?

This will be my last question then.



Thx.

The jme3 test assets are located in jme3testdata.jar last time I checked

You’re actually right. I found them under: [patch]C:/Program Files/jmonkeyplatform/jmonkeyplatform/libs[/patch]

but I can’t load a single texture or single material from it… always errors - what do I need to do to use them in the code?

You’re actually right. I found them under: C:Program Filesjmonkeyplatformjmonkeyplatformlibs



but I can’t load a single texture or single material from it… always errors - what do I need to do to use them in the code?

Is the test data jar on the classpath?

This is my classpath - I’ve never changed it and as I said it worked all well before I removed everything and installed jme3 alpha 4.

I extended the classpath just to be sure… unfortunately It isn’t working yet.



Classpath:

[java].;C:/Program Files/Java/jdk1.6.0_24;C:/Program Files/Java/workspace;C:/Program Files/Java/jre6/lib/ext/QTJava.zip;C:/Program Files/jmonkeyplatform/jmonkeyplatform/libs/jme3testdata.jar;[/java]



And here is a screenshot of the folder:

http://imageshack.us/photo/my-images/8/prtscrn.gif/



Best,



cm

This doesn’t look like a proper classpath … Most of the things in there should be jar files. Also I don’t see any of your project or library jars in there either

This doesn’t look like a proper classpath … Most of the things in there should be jar files. Also I don’t see any of your project or library jars in there either


Why do all files have to be jar files? Java is seaking within the classpath containing subfolders as well... so all my work with java (except jmonkey projects) are located under "C:/Program Files/Java/workspace". But that was not the question ^^
I included [java]C:/Program Files/jmonkeyplatform/jmonkeyplatform/libs/jme3testdata.jar;[/java] in the classpath and it doesn't work... so I don't know.
But what I found strange is that the first time I used jme was about a month ago and I never changed the classpath! And it worked so it can't be the source of this error.
Just to compare: What is your classpath like?

I try to reinstall jmonkey again maybe it will work by then. (I don't think so but lets give it a try).

Best,
cm

EDIT: do you know TeamViewer? Maybe you could help me better if you see my sources - you may send me an email to fabian.rmueller@bluewin.ch then I will tell you the id number and the password for the session