Hi there,

I am new to jME and I ran into a problem: I created a cylinder, which I am trying to map with a texture. I want to do a planar mapping along the Z-axis, so that the texture is displayed properly on the caps.

I wrote a function that creates a new TexCoords object:

public static TexCoords getPlanarMappingZ(FloatBuffer vertices, int vertexCount) {

TexCoords result;

Vector2f[] newCoords = new Vector2f[vertexCount];

float minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE, minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE;

float scaleX, scaleY;

vertices.rewind();

for(int i = 0; i<newCoords.length; i++) {

float x = vertices.get();

float y = vertices.get();

float z = vertices.get();

newCoords[i] = new Vector2f(x, y);

if(x > maxX) maxX = x;

if(x < minX) minX = x;

if(y > maxY) maxY = y;

if(y < minY) minY = y;

}

scaleX = 1 / (maxX - minX);

scaleY = 1 / (maxY - minY);

for(Vector2f vec : newCoords) {

vec.x = (vec.x - minX) * scaleX;

vec.y = (vec.y - minY) * scaleY;

}

result = TexCoords.makeNew(newCoords);

return result;

}

However, the cylinder.setTextureCoords(...) does not seem to have any effect on the result. It is always rendered with the original tex coords. cylinder.reconstruct(...) doesn't have any effect either.

Is it that setting new coords on primitives isn't possible at all? Or do I have to use some "magic" switch?

Thanks in advance...