【问题标题】:Repeating Texture on Model/Mesh在模型/网格上重复纹理
【发布时间】:2013-05-16 19:43:02
【问题描述】:

当我在 SpriteBatch 上绘制纹理并设置 TextureWrap.Repeat 时,一切正常。但是现在我有 3D 场景,我想要在模型/网格上重复地面和纹理,这根本行不通。

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),但纹理仍然被拉伸。我不知道为什么,但它看起来很糟糕。

【问题讨论】:

  • 嘿,我遇到了和你一样的问题。你能解释一下什么是 StillModel 类吗?是你的课还是你在 libgdx 中找到的?
  • 嘿。 StillModel 是 LibGDX 类。它在旧的 LibGDX 3D API 中。我不知道它是否也在新 API 中。

标签: java android 3d libgdx


【解决方案1】:

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

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

修改纹理坐标 - 如果您想重复 20 次,请更改为例如 20

例子:

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

【讨论】:

    猜你喜欢
    • 2014-03-21
    • 2012-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多