Texture not stretching over cube

Hi,

I’m trying to load texture from the Image and not from assets and they behave different. From asset my texture is stretched to each side of the cube, but from Image its cutting it on each side and not stretching it. Here is my code:

private Material createMaterialFromImage(String name, Image image) {
        Material material = new Material(assetManager,
                "Common/MatDefs/Misc/Unshaded.j3md");
        Texture tex = new Texture2D();
        tex.setMinFilter(Texture.MinFilter.Trilinear);
        tex.setAnisotropicFilter(Integer.MAX_VALUE);
        tex.setName(name);
        tex.setImage(image);
        material.setTexture("ColorMap", tex);
        return material;
}

private Geometry createPicture(Image image) {
    Material material = createMaterialFromImage("mat", image);
    Geometry geometry =new Geometry("picture", new Box(1f, 1f, 0.01f));
    geometry.setMaterial(material);
    return geometry;
}

Can someone please help me?

Hard to compare the working and non-working cases when you only provide one.

Here is the working case:

Geometry picture = new Geometry("picture", new Box(1.5f, 0.01f, 1f));
Texture fireTex = assetManager.loadTexture("Textures/fire.png");
Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setTexture("ColorMap", fireTex);
picture.setMaterial(material);

Try to set the Texture Wrap mode, i guess it is set in the assetmanager in the second case.

So, what happens if you pass fireTex.getImage() to the first code? Does it still have the same issue?

That will tell us if it’s your image (which we don’t know where it comes from) or your material setup.

I’m not home right not - but I’ll try after work. How would the code look?
Thank you

I try it at home and let you know, thank you for helping

Step 1: open the JME javadoc
Step 2: click on Texture
Step 3: scroll down to the setWrap() method.
http://javadoc.jmonkeyengine.org/com/jme3/texture/Texture.html#setWrap(com.jme3.texture.Texture.WrapMode)
Step 4: never close the javadoc again because it should be open 100% of the time. :slight_smile:

1 Like

Awesome thank you :grinning:

My problem was that I wasn’t positioning the objects correctly so they were overlapping making me thing that the texture was not stretching… I also have another question - When I was testing it on android I was getting errors AWTLoader not found. Am I missing some library for android?

Thank you for being patient with me

AWTLoader is only on Desktop because AWT is only on desktop I guess. You may have to cut and paste the converter code you are using from that class.

I made a little library with ImageLoader class that works on both using the AWTLoader if on desktop and the android Bitmap if in android.