Again ressource loading problem on Android sorry :)

Hello everyone , I am new on jmonkey and I have a problem with loading textures on Android.

All examples work perfectly on the pc, cool :slight_smile:
Android on all who do not use as texture, cool :slight_smile:

only :

I try to run the example of Terrain on my tablet and I can not load the textures :, bad :frowning:

matRock.setTexture ( “Alpha” , assetManager.loadTexture ( " Textures / Terrain / splat / alphamap.png "));

I saw that it was necessary to add jme3 - testdata.jar the project, what I 've done, I 'm in my textures folder asset too.

If I understand correctly , when jme3 export my project in the release jar (in my case) , it does not directly attached resources ( texure etc …) with the project and I must first convert models texture and then load them with a AssetManager class , is the solution on android ?

if yes is there a simple and concrete example for android (not for pc) somewhere on the forum, or can you give me a simple example that I could reproduce :slight_smile:

Thank you very much and long life jmonkey

Christelle

Ctrl-C / Ctrl-V the assets you need from the example jar (Libraries node of the project) to your assets folder, then remove the example jar from the project.

1 Like

Ok, it works, thank you for your help, the frame rate is 40 frames per second for example ground on a tablet entered game in debug mode and 1024 x 768 for info, exactly what I need, thank you and good Sunday

Christelle

Unfortunately,

I have a problem but this time with Nifty api always about loading an image ( I decidedly do not have luck :slight_smile:

the way in my xml file is good, and I apply the same procedure as you said for png files, I copied my png file in the asset folder of the mobile folder that corresponds to my file path, but it do not always want to work, I clean and build and I AssetNotFoundException on android , for against AC works perfectly for other textures on 3D objects and when I test a sample that does not charge a png image with the xml file, example a button with nifty , ca works perfectly.

my xml file:

<? xml version = “1.0” encoding = “UTF -8” ? >
< nifty xmlns = " http://nifty-gui.sourceforge.net/nifty-1.3.xsd "
xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance "
xsi: schemaLocation = " http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd ">
<screen id=“start” controller=“mygame.Main”>
<layer id=“layer” childLayout=“center”>
<image filename=“Interface/fong.png”> < / image >
</ layer >
</ screen>
</ nifty >

Java code :

public class Main extends SimpleApplication implements ScreenController {

private TerrainQuad terrain;
Material matRock;
Material matWire;
boolean wireframe = false;
boolean triPlanar = false;
protected BitmapText hintText;
PointLight pl;
Geometry lightMdl;
private float grassScale = 64;
private float dirtScale = 16;
private float rockScale = 128;
private Nifty nifty;

public static void main(String[] args) {
    Main app = new Main();
    app.setPauseOnLostFocus(false);
    app.start();
    
}


@Override
public void initialize() {
    super.initialize();

    loadHintText();
}

@Override
public void simpleInitApp() {
    setupKeys();

    // First, we load up our textures and the heightmap texture for the terrain

    // TERRAIN TEXTURE material
    matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
    matRock.setBoolean("useTriPlanarMapping", false);

    // ALPHA map (for splat textures)
    matRock.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));

    // HEIGHTMAP image (for the terrain heightmap)
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");

    // GRASS texture
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(Texture.WrapMode.Repeat);
    matRock.setTexture("Tex1", grass);
    matRock.setFloat("Tex1Scale", grassScale);

    // DIRT texture
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(Texture.WrapMode.Repeat);
    matRock.setTexture("Tex2", dirt);
    matRock.setFloat("Tex2Scale", dirtScale);

    // ROCK texture
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(Texture.WrapMode.Repeat);
    matRock.setTexture("Tex3", rock);
    matRock.setFloat("Tex3Scale", rockScale);

    // WIREFRAME material
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);

    // CREATE HEIGHTMAP
    AbstractHeightMap heightmap = null;
    try {
        //heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);

        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f);
        heightmap.load();

    } catch (Exception e) {
        e.printStackTrace();
    }

    /*
     * Here we create the actual terrain. The tiles will be 65x65, and the total size of the
     * terrain will be 513x513. It uses the heightmap we created to generate the height values.
     */
    /**
     * Optimal terrain patch size is 65 (64x64).
     * The total size is up to you. At 1025 it ran fine for me (200+FPS), however at
     * size=2049, it got really slow. But that is a jump from 2 million to 8 million triangles...
     */
    terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
    TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
    control.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
    terrain.addControl(control);
    terrain.setMaterial(matRock);
    terrain.setLocalTranslation(0, -100, 0);
    terrain.setLocalScale(2f, 0.5f, 2f);
    rootNode.attachChild(terrain);

    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
    rootNode.addLight(light);

    cam.setLocation(new Vector3f(0, 10, -10));
    cam.lookAtDirection(new Vector3f(0, -1.5f, -1).normalizeLocal(), Vector3f.UNIT_Y);
    
    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
                                                      inputManager,
                                                      audioRenderer,
                                                      guiViewPort);
    nifty = niftyDisplay.getNifty();
    nifty.fromXml("Interface/welcome.xml", "start", this);

    // attach the nifty display to the gui view port as a processor
    guiViewPort.addProcessor(niftyDisplay);

    // disable the fly cam

// flyCam.setEnabled(false);
flyCam.setDragToRotate(true);
inputManager.setCursorVisible(true);
}

public void bind(Nifty nifty, Screen screen) {
    System.out.println("bind( " + screen.getScreenId() + ")");
}

public void onStartScreen() {
    System.out.println("onStartScreen");
}

public void onEndScreen() {
    System.out.println("onEndScreen");
}

public void quit(){
    nifty.gotoScreen("end");
}


public void loadHintText() {
    hintText = new BitmapText(guiFont, false);
    hintText.setSize(guiFont.getCharSet().getRenderedSize());
    hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
    hintText.setText("Hit T to switch to wireframe,  P to switch to tri-planar texturing");
    guiNode.attachChild(hintText);
}

private void setupKeys() {
    flyCam.setMoveSpeed(50);
    inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
    inputManager.addListener(actionListener, "wireframe");
    inputManager.addMapping("triPlanar", new KeyTrigger(KeyInput.KEY_P));
    inputManager.addListener(actionListener, "triPlanar");
}
private ActionListener actionListener = new ActionListener() {

    public void onAction(String name, boolean pressed, float tpf) {
        if (name.equals("wireframe") &amp;&amp; !pressed) {
            wireframe = !wireframe;
            if (!wireframe) {
                terrain.setMaterial(matWire);
            } else {
                terrain.setMaterial(matRock);
            }
        } else if (name.equals("triPlanar") &amp;&amp; !pressed) {
            triPlanar = !triPlanar;
            if (triPlanar) {
                matRock.setBoolean("useTriPlanarMapping", true);
                // planar textures don't use the mesh's texture coordinates but real world coordinates,
                // so we need to convert these texture coordinate scales into real world scales so it looks
                // the same when we switch to/from tr-planar mode
                matRock.setFloat("Tex1Scale", 1f / (float) (512f / grassScale));
                matRock.setFloat("Tex2Scale", 1f / (float) (512f / dirtScale));
                matRock.setFloat("Tex3Scale", 1f / (float) (512f / rockScale));
            } else {
                matRock.setBoolean("useTriPlanarMapping", false);
                matRock.setFloat("Tex1Scale", grassScale);
                matRock.setFloat("Tex2Scale", dirtScale);
                matRock.setFloat("Tex3Scale", rockScale);
            }
        }
    }
};

}

Thank you in advance, because I read the manual and look nifty on the forum and nobody seems to have this problem to load a png image :slight_smile:

Oh I’m sorry, I saw my mistake in posting this query: (, thank you very much for your help :slight_smile:

Christelle

Hello, a strange problem with the images on android , I did the test with or without nifty and I feel that when I added a new image to my project , and I use it with a file xml or directly into a jme3 application, resources are still not available , here is a simple example with nifty :

<screen id=“start” controller=“mygame.Main”>
<layer id=“layer” childLayout=“center”>
<image filename=“Interface/fong.png”> < / image >

it works my image is loaded on the screen, by cons if I change the name of the image with another png file on the same interface file , I have a null pointer , the result is the same in the code :

Picture p2 = new Picture ( " fond.png ");
p2.setImage ( AssetManager , "Interface / fond.png " , false);

ca also works but if I change to another png, NullPointerException

I copy the files to the mobile folder , I changed and returned to the ownership of the project assets.jar name , clean build , raise jmonkey … anyways I tried everything , it’s really a big problem. I 'm stuck in my project , please help me

Christelle