Scale Material from inside a scene

I have a scene with a quad that I want to have the material repeating. I could not get that to work so I made a new scene with only a quad. I put the material on the quad and I can see the image, just not repeating. I made a control to attach to the quad so I can try to make the image repeat. It’s a shame I cannot do it from the material file itself. Here is the material file:

Material MyMaterial : Common/MatDefs/Light/Lighting.j3md {
    MaterialParameters {
        BackfaceShadows : true
        DiffuseMap : Repeat Models/floor/floor.png
        UseInstancing : false
        UseMaterialColors : false
        SteepParallax : false
        Shininess : 5.0
    AdditionalRenderState {
      PointSprite On
      FaceCull Back
      AlphaTestFalloff 0.0
      DepthWrite On
      ColorWrite On
      PolyOffset 0.0 0.0
      DepthTest On
      Blend Off
      Wireframe Off

I made the control so I can get the material to repeat. I tried several things from quite a few forum posts but I only found one that I could use. When I try to use it the material of the quad goes from the image to a light grey color. here is the code from the control.

package mygame;

import com.jme3.math.Vector2f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;

public class repeatTexControl extends AbstractControl {
    public int factor = 10;
    protected void controlUpdate(float tpf) {

    protected void controlRender(RenderManager rm, ViewPort vp) {
    public Control cloneForSpatial ( Spatial spatial ) {
        Control control = new repeatTexControl();
        control.setSpatial( spatial );
        Geometry geom = (Geometry) spatial;
        geom.getMesh().scaleTextureCoordinates( new Vector2f( factor, factor ) );

        return control;

Is there a better way? What did I miss with this approach? Thank you in advance.

I don’t think cloneForSpatial() is used… and certainly not like you expect it to be here.

If you want a quad with repeating texture:

  1. create the quad
  2. call quad.scaleTextureCoordinates() in it with the number of times you want it to repeat
  3. create the geometry with material, texture, etc. where the texture is set to repeat

That’s it.

If you are loading the quad from a 3D editor then make sure the UVs are set right in the 3d editor.

1 Like

Here’s an example of what Paul’s suggesting: jmonkeyengine/ at 16a3e7630c32cf95bca1218f5c85133cf58398b1 · jMonkeyEngine/jmonkeyengine · GitHub

Thank you for replying. the example you posted creates all of the objects in code and not the scene. That would work for the second scene I made but the first scene is more complicated. Is there not a way to do that in the scene? is there a way to access the code for the scene? I want to be able to position it in the scene view.

The geometry needs proper UVs. Where did the geometry come from?

I created the primitive in the scene view.

Then you are stuck. The scene view is not really a 3D editor. You’d probably be happier making your geometry in Blender instead of constructing it from quads in the scene composer.

If I made the quad in blender I would still need to apply the material and set it to repeat. Is there really no way to get the material to repeat in geometry in the scene view?

I blender, though, you can edit the UV coordinates to go from 0...#times_texture_should_repeat Which is what the code examples above are trying to do…

If you made a quad in blender then you could set the texture to repeat in blender, set proper UVs, etc. then export it as gltf = done.

I see, thank you for your reply. Would it be possible to add image size x and y to the material wish list? I will proceed with that approach. Thank you for every one who assisted with this.