Box with tiled texture

I want Box with tiled texture. Tile sizes should be the same size on each face also when box is not a cube.

I use Texture.WrapMode.Repeat and I have changed texture coordinates. The result looks still bad. Texture tiling brakes on face triangles. Any ideas how to make this work?



Here a simple test code for this:



import java.nio.FloatBuffer;

import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.FirstPersonHandler;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;

public class TestTiledBox extends SimpleGame {


    public static void main(String[] args) {
        TestTiledBox app = new TestTiledBox();
        app.setConfigShowMode(ConfigShowMode.AlwaysShow);
        app.start();
    }

    protected void simpleInitGame() {
        display.setTitle("Test Tiled Box");
       
        float xSize = 4;
        float ySize = 6;
        float zSize = 8;
        float texSize = 2;
       
        Box box = new Box("Box", new Vector3f(), xSize, ySize, zSize);
        box.setModelBound(new BoundingBox());
        box.updateModelBound();
       
        float x = xSize / texSize;
        float y = ySize / texSize;
        float z = zSize / texSize;
        System.out.println(x + " " + y + " " + z);
       
        float[] texCoordinates = {
              y, 0, 0, 0, 0, y, x, y, // back
              z, 0, 0, 0, 0, z, y, z, // right
                y, 0, 0, 0, 0, y, x, y, // front
                z, 0, 0, 0, 0, z, y, z, // left
                x, 0, 0, 0, 0, x, z, x, // top
                x, 0, 0, 0, 0, x, z, x,  // bottom
              
            };
       
        FloatBuffer buffer = box.getTextureCoords().get(0).coords;
        buffer.rewind();
        buffer.put(texCoordinates);
       
        input = new FirstPersonHandler(cam, 10f, 1f);
       
        rootNode.attachChild(box);
       
        TextureState ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        ts.setTexture(TextureManager.loadTexture(TestTiledBox.class
                .getClassLoader().getResource("jmetest/data/texture/decalimage.png"),
                Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));
        ts.getTexture().setWrap(Texture.WrapMode.Repeat);
        rootNode.setRenderState(ts);

        lightState.setTwoSidedLighting(false);
    }
}

Seems like you just messed up a bit with xyz.

Does the code below give what you wish?


      float[] texCoordinates = { x, 0, 0, 0, 0, y, x, y, // back
            z, 0, 0, 0, 0, y, z, y, // right
            x, 0, 0, 0, 0, y, x, y, // front
            z, 0, 0, 0, 0, y, z, y, // left
            z, 0, 0, 0, 0, x, z, x, // top
            z, 0, 0, 0, 0, x, z, x // bottom

      };



Thanks a lot :smiley: It works perfectly.