Tile map with multiple textures

I have created a custom mesh made up of tiles that I generate with code and I am currently able to render the mesh as a single geometry. Each tile is split up into 7 parts, the center of the tile would consist of the primary texture for that tile, the other 6 parts would be used to show transitions to the neighboring tiles based on what those tiles are. The transitions would be part of the primary texture, I would be determining the texcoords for those as needed.

I am wondering how I can apply multiple textures to the geometry that uses this mesh. Different tiles would have different textures, some would be the same, but the textures used would be based on other inputs. The number of different textures is undefined. I have looked at texture atlas, but I don’t think that is what I need as it appears that it would be used to change the entire texture of a single geometry.

One option I have considered is creating a separate mesh for each texture, and thus a separate geometry, but from what I have read having many geometries is a bad idea, which is why I generated the single mesh.

Is there a better option for doing this?

You have a few options:

  1. Texture splatting using multiple textures.
  2. A Texture Atlas … this one would become increasingly more difficult with more and more tile types… unless you were creating the atlas dynamically.

I would suggest the first option and take a look at some of the stock JME shaders for how to accomplish this. It’s fairly straight forward and wil allow you to keep the single mesh if needed.