在模型/网格上重复纹理 [英] Repeating Texture on Model/Mesh

查看:17
本文介绍了在模型/网格上重复纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 SpriteBatch 上绘制纹理并设置 TextureWrap.Repeat 时,一切正常.但现在我有 3D 场景,我想要地面和纹理必须在模型/网格上重复,但这不起作用.

When I just draw texture on SpriteBatch and set TextureWrap.Repeat everything is OK. But now I have 3D scene and I want have ground and texture must be repeated on model/mesh and this just don' t work.

public static StillModel createPlainMesh(float xs, float zs, Texture texture) {
        final Mesh mesh = new Mesh(true, 4, 6, new VertexAttribute(
                Usage.Position, 3, "a_position"), new VertexAttribute(
                Usage.TextureCoordinates, 2, "a_texCoords")); 
        mesh.setVertices(new float[]
                { xs, 0f, zs, 0, 0,
                xs, 0f, -zs, 0, 1,
                -xs, 0f, zs, 1, 0,
                -xs, 0f, -zs , 1,1
                });
        mesh.setIndices(new short[] { 0, 1, 2, 1, 2, 3 });
        final StillModel model = new StillModel(new StillSubMesh(
                "ground", mesh, GL10.GL_TRIANGLES, new Material()));    

        texture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
        model.setMaterial(new Material("material", new TextureAttribute(texture, 0, "s_tex")));

        return model;
    }

我有这个代码.我使用 setWrap(TextureWrap.Repeat, TextureWrap.Repeat),但纹理仍然被拉伸.我不知道为什么,但它看起来很糟糕.

I have this code. I use setWrap(TextureWrap.Repeat, TextureWrap.Repeat), but textures are still streched. I don't know why, but it looks terrible.

推荐答案

我解决了.如果你想在模型上重复纹理,你必须修改这个:

I solved it. If you want repeat texture on model, You must modify this:

mesh.setVertices(new float[]
                { xs, 0f, zs, 0, 0,
                xs, 0f, -zs, 0, 1,
                -xs, 0f, zs, 1, 0,
                -xs, 0f, -zs , 1,1
                });

Modify Texture Coords - 如果您想重复 20 次,请更改为例如 20

Modify Texture Coords - change to for example 20 if You want repeat it 20times

示例:

mesh.setVertices(new float[]
                { xs, 0f, zs, 0, 0,
                xs, 0f, -zs, 0, 20,
                -xs, 0f, zs, 20, 0,
                -xs, 0f, -zs , 20,20
                });

这篇关于在模型/网格上重复纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆