JMonkey Equivalent of QuadArray

Hello,

I recently (today) decided to switch from Java3D to jmonkeyengine and while looking through my code I was wondering what the best way to go about creating an array of Quads was. I have an array of vertices which are coordinates for a planet type sphere and in Java3D I just set the coordinates of a quadarray to these vertices and voila…the only easy thing about that library. I was just wondering how I should go about doing the same thing with this library…should I use a Terrain mesh? Thanks for any responses.

Yeah, why not. Set the heightmap like the quads height.

Would the terrain mesh map to a sphere?



You will need to split the quads into triangles…can’t really avoid it although it’s not hard to do.

Thanks for the replies, after reading the Java Docs over I decided to just use a mesh with a triangle strip array…one slight issue though when I attempt to run the program I get a null pointer exception at the initiation of the material…here is the code for it…

[java]Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

mat.setColor("Color", ColorRGBA.Green);

mat.getAdditionalRenderState().setWireframe(true);[/java]

what would be the cause of this?

@okelly4408 said:
Thanks for the replies, after reading the Java Docs over I decided to just use a mesh with a triangle strip array....one slight issue though when I attempt to run the program I get a null pointer exception at the initiation of the material...here is the code for it..
[java]Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Green);
mat.getAdditionalRenderState().setWireframe(true);[/java]
what would be the cause of this?

that would be line 1?
id say the assetmanager is null, but i cant tell why w/o more code.
1 Like

Yeah, post the stack trace and say what line in your listing corresponds to what line in the stack trace.



NPE are one of the most basic coding exceptions though - you should be able to track down what causes it if you stop and look.

Well from what I can tell from the stack trace it is assetManager that is causing this… Here is the code that I think is relevant:

[java]Mesh mesh = new Mesh();

mesh.setMode(Mode.TriangleStrip);

mesh.setBuffer(Type.Position,3,BufferUtils.createFloatBuffer(vertices));

mesh.updateBound();

Geometry geo = new Geometry(“PlanetMesh”,mesh);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat.setColor(“Color”, ColorRGBA.Green);

mat.getAdditionalRenderState().setWireframe(true);

geo.setMaterial(mat);

rootNode.attachChild(geo);

System.out.println("Triangles: "+mesh.getTriangleCount());



}



public static void main(String[] args){

CubeJME app = new CubeJME();

app.start();

}

public void simpleInitApp() {

new CubeJME();



}

[/java]

and here is the stack trace not that it is really helpful…



Exception in thread “main” java.lang.NullPointerException

at com.jme3.material.Material.(Material.java:116)

at CubeJME.(CubeJME.java:254)

at CubeJME.main(CubeJME.java:264)

Um… CubeJME seems to be relevant according to the stack trace :slight_smile:

assetManager is null.

@okelly4408 said:

[java]
*snip*
public static void main(String[] args){
CubeJME app = new CubeJME();
app.start();
}
public void simpleInitApp() {
new CubeJME();

}
[/java]

ok first things first, what are you trying to do? First you create a new CubeJME instance and start it. Then in SimpleInitApp (which is called when the app is started) you start another one? ... which would then start another one?


and here is the stack trace not that it is really helpful...

Exception in thread "main" java.lang.NullPointerException
at com.jme3.material.Material.(Material.java:116)
at CubeJME.(CubeJME.java:254)
at CubeJME.main(CubeJME.java:264)

well it tells me you want to use the assetmanager in the constructor, but it is not initialised yet, because this happens after the object is fully created.
Move your code to the simpleAppInit and you'll be fine.
Also as far as i remember the only thing that is ever done in the apps constructor in the tutorials is calling the super constructor with different appstates.
In general you'll want to use the initialize method instead of a contructor for apps and appstates.