Repeating a texture on a face

A material that is assigned to a geometry is usually stretched over an entire face, so that the material details become blurred (especially with bigger faces).

Is there a way to make a geometry repeat a material over a face?

Normal:

________
|       |
|  (A)  | Texture is stretched over entire face (A)
|       |
|_______|

What I want:

________
|   |   |
|___|___| Face (A) is divided into sections,
|   |   | and the texture covers each section individually.
|___|___|
 (A) ^

Use the #scaleTextureCoordinates(Vector2f) method on the Mesh of the Geometry.

1 Like

Or proper UVs from the modeler where the mesh came from.

Or… or…

We’d have to know where the mesh data came from, etc…

(Because if it’s just a JME quad or your own custom mesh, you can set the texture coordinates however you like.)

1 Like

My mesh is a JME Box.

I tried, but it doesn’t seem to work (note that I use v3.2.4).

code + results if you want our help.

Sorry, I keep forgetting to do that.

Box b = new Box(map.get(0).size()*size, 5, map.size()*size);
float texSection = 10;
b.scaleTextureCoordinates(new Vector2f(texSection, texSection));
Geometry g = new Geometry("BoxFloor", b);
g.setLocalTranslation(map.get(0).size()*size/2, -5-5, map.size()*size/2);
Material m = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
m.setTexture("DiffuseMap", assetManager.loadTexture("Textures/warning strip 2.png"));
/*m.setBoolean("UseMaterialColors", true);
m.setColor("Ambient", ColorRGBA.Gray);
m.setColor("Diffuse", ColorRGBA.Orange);*/
g.setMaterial(m);
g.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
enviro.attachChild(g);

Image “warning strip 2.png” has white, yellow, and black.

What I imagine should be happening is “warning strip 2” should be displayed every so often on the floor. Instead, the area around the player is white, and (if texSection is high enough) you can see a gradient of black and yellow in the distance.

In this picture, you can see that the player is surrounded by white, but there is a gradient in the distance. Please note that the walls use “warning strip 2”, and please ignore the big red thing.

As texSection is increased, the gradient moves closer to the player, and vise versa. This snapshot was taken at texSection = 100.

Probably you also need to set the wrap mode of the texture.

1 Like

Yes, that worked. Thanks!

1 Like