Multi texture on the same custom mesh

Hi :smiley:, I’m a new entry in JM’s world, but I see that this forum contain a lot of really good and helpful people :smile:
I have a problem (first of all with my english, I’sorry…) with a custom mesh, it rappresent a polygon with 6 faces, my objective (target) is to apply different texture to each face…
To solve this problem i tryed to create an other Vectorbuffer (Example: for an other face) and to set it as a mesh’s buffer with Type’s arguments = “Type.TexCoord2” but I don’t know how i can set the second texture to mesh using this new buffer instead of the original…
Any suggestions?
Thanks you in advance :blush:

One way, use jme3tools.optimize.TextureAtlas to combining multiple textures into one texture atlas. Please see:

The other way, seperate your model into several geometries, each use one texture.

Thank you for your fast reply :smile:
So, I need to create a mesh for each face: it’s seem absurd O.O…
What’s the utility of other texture buffer? (2,3…)
I don’t know if i was clear, I only need to set an other texture (example 2 ColorMap) to the same mesh using the the second texture buffer (if it’s possible…) in which there are all texture coordinates refered to the second face, and so on…
Create multiple mesh implies that i need to have multiple copy of each “sub”-mesh’s vertext, texture coord and indexes… it seem a waste…

When I tried the multiple UV channels (UV buffer) in early 2014, it had some errors (I was trying to use a lightmap in the second UV set).

It also seems that the standard jME materials only support one UV channel (UV buffer). So you need to make a new material.

One idea for new material with new shader: Have a buffer (e.g. use the vertex colors, or just create your own “material id buffer”) and then in the new shader select the texture.

Maybe the better idea is what yan said: Combine all your textures in an atlas (watch out for problems with mipmapping) and then just set the UV coords in the UV buffer to these textures - this would work out of the box and you don’t need to write a custom shader. What you might want to write is a better TextureAtlas that uses a margin around the textures (similar to what Blender does during baking) - this solves mipmapping problems.

And I agree that having several meshes for each texture is a very bad idea (unless you can achieve some kind of batching over all meshes with the same textures). You must keep the number of draw calls low - and thus the number of meshes.

Agree with Ogil.

I’m trying making a plugin which can import *.ASE or .3ds model into jME, the most dirty part is how to support multi-UV in jME. I wrote a code to seperate one mesh into several mesh and foreach one I give it a material. I know it isn’t the best way but it works somehow. :joy:

I spend a lot of time to understand a simple fact: jME is a 3D GAME engine. It seems that one mesh one UV is the best practice in game developing area. Maybe we just need a right tool to do such thing.

…you don’t need to create mesh for each face…it can be one mesh properly unwrapped with one texture which contains texture parts aimed for specific mesh areas…result will be visually same, but performance wise, will be rendering 6(individual textures used) vs. 1 surface(1 unwrapped texture)…

Thanks for all your replies… my problem is that i’ m not able to use a static texture and to divide them for each face; in my case I have a (general) circular sector mesh and this may be generated with different angles, so it is no possible to use (i think) in a dynamic context a texture atlas or similar solution… so… i’ve divided my mesh in more mesh :frowning:

JME doesn’t create texture atlas automaticaly so you will have to create your own.

I see two solutions :

  • the first already given : create a geometry for each part of your mesh that have a different texture file
  • create a composite texture with all the needed textures, in code or in a image editing software.

in the second solution, you will have to manage the texture coordinates manualy for each vertices of your mesh. Depending on what you’re attempting to do, it may become a little tricky.

If the texture is generated in code, like for the reflexion of a mirror, you may look at shaders too.

The more details you give, the better we can help ^^

It doesn’t do it automatically but it does have utility code that can help: