Texture tiling on plane

Started by quixote_arg, February 07, 2006, 09:18:38 PM

Previous topic - Next topic

quixote_arg

Hi!

I've created a plane using Primitives class. When I apply a texture, it strechtes it all over it. I would like the texture to be tiled on the object. Is there an easy way to do this? I searched the forum, with no luck...

Here's the code:


wall = Primitives.getPlane(15, 20);
wall.setOrigin(new SimpleVector(800, -150, -300));        wall.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
wall.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
wall.setTexture("wall");
theWorld.addObject(wall);


Thanks

EgonOlsen

This isn't possible with the primitives-class itself. So you either have to build the plane yourself out of triangles or use this little helper on the plane created by Primitives:


import com.threed.jpct.*;

public class ReMapper {
 
 public static void tileTexture(Object3D obj, float tileFactor) {
   PolygonManager pm=obj.getPolygonManager();
   
   int end=pm.getMaxPolygonID();
   for (int i=0; i<end; i++) {
     SimpleVector uv0=pm.getTextureUV(i,0);
     SimpleVector uv1=pm.getTextureUV(i,1);
     SimpleVector uv2=pm.getTextureUV(i,2);
     
     uv0.scalarMul(tileFactor);
     uv1.scalarMul(tileFactor);
     uv2.scalarMul(tileFactor);
     
     int id=pm.getPolygonTexture(i);
     
     TextureInfo ti=new TextureInfo(id, uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
     pm.setPolygonTexture(i, ti);
   }
 }
}


To use it, you need the latest preview version of jPCT 1.10, which fixes a bug in the PolygonManager. You can download it here (it's a stripped zip, you may still need some things from the official release like LWJGL and the examples and stuff): Edit * Link removed *