I'm working on a 3D maze game using libGDX. I'm using MeshBuilder to render the walls. All walls are a single part made using a ModelBuilder in the create():

    ModelBuilder modelBuilder = new ModelBuilder();
    MeshPartBuilder meshBuilder;
    Vector3 corner00 = new Vector3(),
            corner10 = new Vector3(),
            corner11 = new Vector3(),
            corner01 = new Vector3(),
            normal = new Vector3();

    Texture wallTexture = new Texture("wall.PNG");
    wallTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
    wallTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    Material material = new Material(new Material(TextureAttribute.createDiffuse(wallTexture)));
    meshBuilder = modelBuilder.part("room1", GL20.GL_TRIANGLES,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal |
                    VertexAttributes.Usage.TextureCoordinates, material);
    Array<Wall> walls = level.getWalls();
    for (Wall wall : walls) {
        Vertex v1 = wall.getV1();
        Vertex v2 = wall.getV2();
        meshBuilder.rect(corner00.set(v1.getX(), v1.getY(), 0), corner10.set(v2.getX(), v2.getY(), 0),
                corner11.set(v2.getX(), v2.getY(), 10), corner01.set(v1.getX(), v1.getY(), 10),
                normal.set(wall.getNormal(), 0));
    Model worldModel = modelBuilder.end();
    instance = new ModelInstance(worldModel);

I do this in order to decrease the number of draw calls. But I came across a texture-mapping problem: enter image description here The wall texture is stretched. How can I make it repeat the texture instead of stretching? Thanks


After spending time learning more the libGDX 3D structure, I managed to fix it:


While building the mesh part, I set the UV range from (0,0) to (n,1) - n is the number of times the texture image can fit inside the rect.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.