Scale and tile texture on spatial

I have a spatial, imported as ogre from blender, to which I want to apply an image texture. I want this texture to be tiled, and I want to scale it down. Here’s my code so far:

mat_outer = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Texture white = assetManager.loadTexture(new TextureKey("Materials/white.jpg", false));
    mat_outer.setTexture("ColorMap", white); 
    setTextureScale(outer,new Vector2f(0.1f, 0.1f));

This is the setTextureScale method:

public void setTextureScale(Spatial spatial, Vector2f vector) {
    if (spatial instanceof Node) {
        Node findingnode = (Node) spatial;
        for (int i = 0; i < findingnode.getQuantity(); i++) {
            Spatial child = findingnode.getChild(i);
            setTextureScale(child, vector);
    } else if (spatial instanceof Geometry) {
            ((Geometry) spatial).getMesh().scaleTextureCoordinates(vector);

When I run this, I get the following exception:

java.lang.IllegalStateException: The mesh has no texture coordinates
at com.jme3.scene.Mesh.scaleTextureCoordinates(
at mygame.Main.setTextureScale(
at mygame.Main.setTextureScale(
at mygame.Main.simpleInitApp(
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(

I’m at a loss here.

1 Like

The problem is that the mesh has no texture coordinates. Its not a UV mapped texture.


Meaning? How do I give it texture coordinates?

Ok I reexported it from blender after applying a UV texture first, and now it runs, but I still can’t get it to look anywhere near what I want. My picture is a small picture of black and white noise, like static. It shows up on the model like almost a solid color.

Setting the texture coordinate scale to 0.1 means you want the texture to appear 10x bigger than normal. See, if the texture coordinates were 0 to 1.0 before then now they will be 0 to 0.1.

I think you probably want to scale by 10 not 0.1.

1 Like

Yes that did make it seem closer to what I want. I thought it was the other way around. The problem now is that its distorted all around the mesh. Isn’t there a way to set the projection to cubic or flat or window as I would do in blender?

JME only knows UVs… so if you get your UVs right in Blender then JME will display that.

1 Like

Uh-huh. Got it then. I’ll start working on that .Thanks!