Cylinder - planar mapping

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...

Are you calling updateRenderState() on the cylinder after settings the new coords?

You should try updateGeometricState() as well.

I tried both, to no avail… It's just not happening.

I tried verifying the coord changes by setting all tex coords to (0,0). Nothing changes.

Is it possible that you've locked the cylinder?  (so it's already a display list and changes to the tex coords don't matter)


Hi guys,



thanx a lot for the input. I didn't manage to get this to work. Since I only needed a 2-dimensional circle with a map on both sides I reverted to using a quad with a circular alpha map. That works and looks quite nice…



Thanks again :smiley: