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");
mat_outer.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Front);
Texture white = assetManager.loadTexture(new TextureKey("Materials/white.jpg", false));
white.setWrap(Texture.WrapMode.Repeat);
mat_outer.setTexture("ColorMap", white);
outer.setMaterial(mat_outer);
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(Mesh.java:1226)
at mygame.Main.setTextureScale(Main.java:318)
at mygame.Main.setTextureScale(Main.java:312)
at mygame.Main.simpleInitApp(Main.java:103)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:744)
I’m at a loss here.