Texture is displayed in a weird way

I am new to Jmonkey and tried loading a model from Blender into Jmonkey using the Ogre Xml Exporter. I have already read a lot articles on this site how to do it, and which kind of errors could happen. But nonetheless I didn’t manage to display the Texture the right way.



http://i.imgur.com/2wkjF.png



On the programming part I did the following steps:

  • loaded the modell
  • created a material
  • loaded a texture for the material
  • applied the texture to the material
  • added the material to the model





    Help is very appreciated

    Oraclefile

What texturing method are you using in blender? UV Texture Mapping? For ogre xml and blend models, when you import it to jME, the material is automatically applied to the model when you convert it to j3o. If you don’t use the SDK, just load your model and the material will be automatically applied :



[java]

assetManager.loadModel(Models/myModel.mesh.xml);

[/java]

Doing that results in a complete red Modell for me. I already checked the material file, if the link to the texture was wrong, but couldn’t find anything wrong about it.

Ok. For importing ogre models for jME, there’s a rule :



“Make sure the material have the same name of the model. Rename it in blender before exporting”.



EDIT: rule 2: “Make sure the model, material and textures are in the same asset folder (e.g /Models)”.

Okay, thanks to your help I managed now to display the Texture quite fine, but it seems like it is scaled a bit too small now.

http://dl.dropbox.com/u/13497625/redMenace/couch.png



Any way to fix that, or can you tell me, what’s wrong about it?



EDIT: Here is a screenshot of the UV Coordinates in Blender

http://dl.dropbox.com/u/13497625/redMenace/couchBlender.png

Very weird. I’ve never seem anything like this. Try applying scale to the mesh in blender "ctrl+a


>apply scale".

You need to generate tangents on the model. After you convert it to a j3o, right click on it in the scene explorer window and select tools → Generate Tangents. Then save the file again.

Sure? I thought it’s only needed for normal maps.

Not positive, but I believe I have had to do that for all models I have loaded in. From the picture there is does look like it doesn’t have the tangents generated. That or oraclefile might have to update his graphics drivers. The other possibility could be that the UV map is has some surfaces of zero area on the black part of the texture. To test this last case, set the background color of the UV texture to bright pink or something and see if the black areas are now pink.

generating tangents is only needed when using normal mapping.



I think the issue there is that the texture is flipped.



@oraclefile when you load the texture, make sure to set the flipY parameter to false, the default is true

like this

[java]

TextureKey key = new TextureKey(“path/to/your/texture.whatever”, false);

Texture t = assetManager.loadTexture(key);

[/java]

After loading a different model, I noticed it might be a problem of the model, as the new one is displayed in the right way. flipping didn’t seem to help. But another question, dunno if I should post it in here:



How can you clone an object? I don’t think the perfomance would be to good, if I load a model like a thousand time. Didn’t seem to be able to find a way to do that. And another question as well: Can you convert a few loaded models to one to save performance?

Models are cached and a new instance is created, without having to reload the file, the next time you access the model from the asset manager.

So just load it again with the asset manager.



You can combine models, if they use the same material, by using the GeometryBatchFactory.

For cloning, load your model once and clone it : mySpatial.clone() and for performance you can optimize your geometries, you can do what sploreg suggested : GeometryBatchFactory.optimize(); if you are going to do a minecraft / mythruna / 3070 based game, then you have to look for voxels.

No, I am not going to do anything like that. I am just generating my world based on some different objects, which are static in the final game. Therefore I only need those different models in the beginning.

As Sploreg said, you can just load it each time from the assetManager, it will be cached/cloned automatically.