Repeated texture inside a geometry

I have a PNG image file 180x180 that fits well in a block 1f sized. If I increase this block size for 20f for example I would like to repeat the texture along the boundaries without any stretch and scale.



I had tried it using WrapMode but didn´t works.



[java] Texture tex = am.loadTexture(new TextureKey("Textures/" + texture, false));

tex.setWrap(Texture.WrapMode.Repeat);[/java]



Legend:

am – assetManager

texture – the texture path



I have no idea how to make it works repeating texture image along the geometry size form.

Any tips will be very welcome. Thanks and sorry about my english.

Obviously it doesn’t, you have to scale the texture coordinates on the mesh, theres a method for that.

[java]mesh.scaleTextureCoordinates(Vector2f scaleFactor)[/java]

I tried that before. But how to know exactly the coordinations of the texture?



Thanks again!

Well 0.5 x and 0.5 y is the middle of the texture… But why you want to know that? Just scale it by 0.5 if you want the texture to appear 4x on the cube…

I will try this approach. Thanks, normen.

To scale UV you need something like:



Texture tex = assetManager.loadTexture( new TextureKey(“Models/guide.png”, false) );

tex.setWrap(Texture.WrapMode.Repeat);

((Geometry)((Node) spatial).getChild(0)).getMesh().scaleTextureCoordinates(new Vector2f(40,40));

mat.setTexture(“DiffuseMap”, tex);

The important bits being tex.setWrap and scaleTextureCoordinates – the 40,40 means tile the texture 40 times on both U and V.



Taken from: http://hub.jmonkeyengine.org/groups/general-2/forum/topic/repeat-textures-jmonkey-alpha-4/

1 Like

Thanks for reply, I give you guys a feedback soon!

http://hub.jmonkeyengine.org/groups/import-assets/forum/topic/tile-texture-on-spatial