Hello,
After having finnished to draw a demonatration map with the build in terrain editor. The result is a Map_demo1.j3o in the “Scenes” folder and the used taxtures in the “Textures” folder.
Now i started programming a simple MapLoader class which now should only load the map. (I have also tryed to implement the water as specified in the watermonkey tutorial, but thats not the current problem.)
No matter what i do, a call to any assetManager function results in a null pointer exeption. I am extending SimpleApplication so i guess i don’t need to call super.initialize() (if i do the application crashes during runtime).
Can you see the error, or how do i initialize to AssetManager correctly? here is the code:
Main.java:
[java]
package Startup;
import com.jme3.app.SimpleApplication;
import com.jme3.math.Vector3f;
/**
- test
-
@author normenhansen
/
public class Main extends SimpleApplication {
private MapLoader MapManager;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
this.MapManager=new MapLoader();
this.rootNode.attachChild(this.MapManager.doLoadNewMap("", new Vector3f(-4.9f, -1.3f, 5.9f),0.1f, true, this));
}
@Override
public void simpleUpdate(float tpf){
//this.MapManager.doUpdateMap(tpf);
}
}
[/java]
MapLoader.java:
[java]
/
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package Startup;
import com.jme3.asset.AssetManager;
import com.jme3.bounding.BoundingVolume;
import com.jme3.collision.Collidable;
import com.jme3.collision.CollisionResults;
import com.jme3.collision.UnsupportedCollisionException;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.scene.Node;
import com.jme3.scene.SceneGraphVisitor;
import com.jme3.scene.Spatial;
import com.jme3.water.WaterFilter;
import java.util.Queue;
/**
*
-
@author zzuegg
*/
public class MapLoader {
Node map;
private FilterPostProcessor ffp;
private WaterFilter water;
private Vector3f lightDirection;
private boolean waves;
private float waterHeight;
private float waterHeightMod;
private float time;
private Main master;
private AssetManager assetManager;
void MapLoader(Main program){
this.master=program;
this.assetManager=master.getAssetManager();
}
Node doLoadNewMap(String mapname, Vector3f ld, float waterInit, boolean waves,Main program){
this.lightDirection= new Vector3f(-4.9f, -1.3f, 5.9f);
this.waves=waves;
this.waterHeight=waterInit;
this.time=0;
this.map=new Node();
System.out.println(this.assetManager.toString());
Spatial terrain=this.assetManager.loadModel("Scenes/Map_demo1.j3o");
map.attachChild(terrain);
//this.ffp=new FilterPostProcessor(this.assetManager);
//this.water=new WaterFilter(this.map,this.lightDirection);
//this.water.setWaterHeight(this.waterHeight);
//this.ffp.addFilter(this.water);
//master.getViewPort().addProcessor(this.ffp);
return map;
}
void doUpdateMap(float tpf){
master.simpleUpdate(tpf);
time+=tpf;
waterHeightMod = (float) Math.cos(((time * 0.6f) % FastMath.TWO_PI)) * 1.5f;
water.setWaterHeight(waterHeight+waterHeightMod);
}
}
[/java]