TriMesh: Can I set textures / renderStates / etc. for a part of a TriMesh?


I want to build a wall (TriMesh) with an inner side, an outer side and the top.

Each one should be textured differently.

Because of historical reasons I want to use a TriMesh (once in JME1

it was a Geometry with TriangleBatch objects, the TriangleBatch

had been textured separately).

Is it possible to treat sections of a TriMesh separately?

Let's say the first 6 vertices inside the TriMesh are green,

the next 6 vertices are blue, and so on.

Or do I have to build a TriMesh array (or collection) ?

This would mean big changes in my code, so I wanted to avoid that.

TriangleMesh wallMesh;
int[] leftSideIndices, float[] leftSideVertices, float[] leftSideCoords;
int[] rightSideIndices, float[] rightSideVertices, float[] rightSideCoords;
int[] topIndices, float[] topVertices, float[] topCoords;
final int LEFT, RIGHT, TOP;

addBatch(wallMesh, LEFT, leftSideIndices, leftSideVertices, leftSideCoords);
addBatch(wallMesh, RIGHT, rightSideIndices, rightSideVertices, rightSideCoords);
addBatch(wallMesh, TOP, topIndices, topVertices, topCoords);

// this is pseudo-code
private void addBatch(TriMesh mesh, int batchIndex, int[] indices, float[] vertices, float[] texCoords) {
    mesh.add(BufferUtils.createFloatBuffer(vertices), null, null,
         new TexCoords(BufferUtils.createFloatBuffer(texCoords)),
         BufferUtils.createIntBuffer(indices)); // pseudo, but should behave like mesh.reconstruct
    if (batchIndex == LEFT) // left texture
    else if (batchIndex == RIGHT) // right texture
    else if (batchIndex == RIGHT) // no texture


Did you ever get a reply to this I have a simular question about texturing the faces of a mesh with different textures. I’ll keep searching the forums. Unless some kind soul can direct me to some info that would help me.

UV map, different textures only with a shader probably (see texture splatting for terrain). Its not efficient for live rendering.


Did you ever get a reply to this…

No. I changed the legacy JME1 code (which wasn’t even mine) to JME2 code.

Which was a major feat, btw.

Thanks to you and to Normen for the responses.