[英]Repeating Texture on Model/Mesh
When I just draw texture on SpriteBatch and set TextureWrap.Repeat everything is OK. 当我在SpriteBatch上绘制纹理并设置TextureWrap.Repeat时,一切正常。 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.
但是现在我有了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;
}
I have this code. 我有这个代码。 I use setWrap(TextureWrap.Repeat, TextureWrap.Repeat) , but textures are still streched.
我使用setWrap(TextureWrap.Repeat,TextureWrap.Repeat) ,但纹理仍然是拉伸的 。 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 - change to for example 20 if You want repeat it 20times 修改纹理坐标 - 如果要重复20次,则更改为例如20
Example: 例:
mesh.setVertices(new float[]
{ xs, 0f, zs, 0, 0,
xs, 0f, -zs, 0, 20,
-xs, 0f, zs, 20, 0,
-xs, 0f, -zs , 20,20
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.