Author Topic: Texture tiling on plane  (Read 3197 times)

Offline quixote_arg

  • byte
  • *
  • Posts: 9
    • View Profile
Texture tiling on plane
« on: February 07, 2006, 09:18:38 pm »

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:

Code: [Select]

wall = Primitives.getPlane(15, 20);
wall.setOrigin(new SimpleVector(800, -150, -300));        wall.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12066
    • View Profile
Texture tiling on plane
« Reply #1 on: February 08, 2006, 06:57:02 pm »
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:

Code: [Select]

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);
      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 *