[Solved] Texture repeat setting issue

Hi, have issue setting texture repeat values to have my box looking good. Not sure what I’m missing.

        final Box floor = new Box(15, 1, 1);

        final Texture floorTexture = this.assetManager.loadTexture("Textures/grass/grass-color-1_512x512.jpg");
        floorTexture.setWrap(Texture.WrapMode.Repeat);
        floor.scaleTextureCoordinates(new Vector2f(10, 1));

        final Material floorMat = new Material(this.assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        floorMat.setTexture("ColorMap", floorTexture);

        final Geometry floorGeom = new Geometry("Floor", floor);
        floorGeom.move(new Vector3f(posX, posY, 0));
        floorGeom.setMaterial(floorMat);

        return floorGeom;

texture is 512x512 and result looks like this:

As you can see on the image, front and back are ok but anything else is repeating the texture.
What would be the right way to set texture wrap mode and texture coords values.
Or should I create individual boxes one next to each other?

It’s doing more or less exactly what you told it:

For every texture coordinate, multiply u by 10 and v by 1. So for every different side, the horizontal part will be repeated 10 times and the vertical part will be repeated 1 time. Which is what you want only on one face.

Either look into the box class and figure out how reset the texture coordinates for each side to what you want… or create 6 different quads in the arrangement of a box and set each of those… or create a custom mesh where each side is exactly the way you want it.

…or make the box in blender.

Those are your options. We don’t know what you are actually trying to do so that’s the best advice I can give. The answer for “I’m trying to make a block world game” will be substantially different than the one for “I just need a floating island for my characters to run on”

2 Likes

I see. Thanks a lot for the details and diff alternatives. Was curious on how to get proper textured rectangular prism (I think it is also called cuboid in english) using the Box class.
No block world game :slight_smile: . Just playing a bit with random things.

1 Like

Marked as solved

1 Like