I’m trying to change the scale of texture for my material, but in result get an exception Material parameter is not defined: DiffuseMap_scale
I’ve tried to use different types of code, but none of them works
if (textureInstanceMap.containsKey("textureScale")) {
Vector2f textureScale = parseVector2f((String) textureInstanceMap.get("textureScale"));
String scaleParamName = mapName + "_scale";
getMaterial().setVector2(scaleParamName, textureScale);
consumer.accept(mapName, textureInstanceMap);
}
This one doesn’t crash, but nothing changes
if (textureInstanceMap.containsKey("textureScale")) {
Vector2f textureScale = parseVector2f((String) textureInstanceMap.get("textureScale"));
getMaterial().setVector2(mapName, textureScale);
consumer.accept(mapName, textureInstanceMap);
}
sgold
August 13, 2023, 4:25pm
2
Not every JME material implements texture scaling. In fact, most don’t.
Material parameters are defined in the .j3md file of the material. For instance, to see the parameters of the “Unshaded” material, browse to https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.j3md . As you can see, there’s no texture scaling there.
Texture scaling is more common in terrain textures. For instance, the “Terrain” texture includes this feature: jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Terrain.j3md
If you need texture scaling in an ordinary unshaded or lit material, you might consider defining a custom material.
Looks like I’ll need to write my own material, right?
Yes, that’s what I need!
Thank you!
1 Like
Ali_RS
August 13, 2023, 4:45pm
4
What about Mesh.scaleTextureCoordinates()
?
You need to set texture WrapMode to Repeat.
4 Likes
No that doesn’t work for TerrainQuad, bigger terain I make, bigger texture will be, without scalling or repeating, while creating a material, I set TextureWrapType
private void wrapType(TextureWrap wrapType, Texture thisTexture) {
switch (wrapType) {
case REPEAT:
thisTexture.setWrap(Texture.WrapMode.Repeat);
break;
case MIRRORED_REPEAT:
thisTexture.setWrap(Texture.WrapMode.MirroredRepeat);
break;
case EDGE_CLAMP:
thisTexture.setWrap(Texture.WrapMode.EdgeClamp);
break;
case NONE:
break;
}
}
I suppose I have to create a Vector2f(x,y) to specify an amount of scaling