Texture is flipped if creating material programatically

If load a model with this material everything is fine.

[xml]

material Test

{

receive_shadows on

technique

{

pass

{

cull_hardware none

ambient 1.0 1.0 1.0 1.0

diffuse 1.0 1.0 1.0 1.0

specular 0.0 0.0 0.0 1.0 12.5

scene_blend alpha_blend

scene_blend 1

texture_unit

{

texture test.png

tex_address_mode wrap

scale 1.0 1.0

colour_op replace

}

}

}

}

[/xml]



But if I create this material in code it appears as if the textures is flipped vertically on the UV.

[java]

AssetManager assetManager = app.getAssetManager();

Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

Texture tex_ml = assetManager.loadTexture("textures/test.png");

mat_stl.setTexture("ColorMap", tex_ml);

front.setMaterial(mat_stl);[/java]



Any ideas what would cause that?

I have the same problem. I have terrain created from heightMap. Setting cull mode, as expected, makes the texture to appear on the second side of terrain plane. So that I don’t have hills but I have valleys…There must be some other way to do it…



And the cause: I think there is difference between coordinate systems of texture images and JME(or OpenGL) system.

Unflip it :



[java]

mat_stl.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);

[/java]



If that doesn’t work try with others face cull modes.

glaucomardano said:
Unflip it :
[java]
mat_stl.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
[/java]
If that doesn't work try with others face cull modes.

Tried all the Cull modes and they don't flip the UV vertical component.

This works…

http://hub.jmonkeyengine.org/groups/graphics/forum/topic/flipped-textures/

delaney said:
Tried all the Cull modes and they don't flip the UV vertical component.


Hmm! My apologizes, I thought you wanted to flip the face normals, forget what i said at my past post ;P.
glaucomardano said:
Hmm! My apologizes, I thought you wanted to flip the face normals, forget what i said at my past post ;P.


Yep, obviously my searching missed that thread! Using texture key fixed my problem for sure, thanks!

Also on a separate note, any reason why Spatial has setMaterial but not getMaterial(s)?

Because not all Spatial’s sub classes needs to have the “getMaterial()”. For example, the Node…it doesn’t need to the “getMaterial()” because nodes doesn’t has material, just its geometries. Unlike Geometry that has material. Spatials has the “setMaterial(material)” because this make sense. Node.setMaterial(material) propagate the material down to the geometries in the scene graph. Geometry Applies the given material to itself.