2013-05-16 69 views
1

當我在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),但紋理仍然拉伸。我不知道爲什麼,但它看起來很糟糕。

+0

嘿我有和你一樣的問題。你能解釋一下什麼是StillModel類嗎?它是你的課程還是你在libgdx中找到的? – Veljko

+0

嘿。 StillModel是LibGDX類。它在舊的LibGDX 3D API中。我也不知道它是否在新的API中。 – kolek

回答

3

我解決了它。如果你想重複的模型貼圖,你必須修改此:

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

修改紋理COORDS - 改變例如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 
       });