Generating primatives with a 3d array

Hello JME World!



Ive been reading up on JME3 for a few days now, mucking around with code, reading alot…so so much reading…and experimenting with primatives. The game my team and I are developing requires maps that look…less sophisticated than those pretty terrain maps, and eventually we will need to produce an editor to pass on to our map makers. So i came up with a rough idea on how to generate maps made out of primative slabs arranged in a grid. I tossed together a sample bit of code, and it doesnt work. Im clearly forgetting to do something. The code is supposed to create a 100 x 100 arrangement of “Boxes”, along the X and Z axis. No effects or textures, just simple 3d arrays. Heres the code:



[java]

import com.jme3.app.SimpleApplication;

import com.jme3.light.*;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;



public class HelloJME3 extends SimpleApplication {



public Vector3f[][] vh1; //height lvl 1 vectors

public Box[][] bh1; //height lvl 1 boxes

public Geometry[][] gh1; //height lvl 1 geometry



public final float BOX_X = 0.5f, //constant box dimensions

BOX_Y = 0.125f, BOX_Z = 0.5f;



public static void main(String[] args){

HelloJME3 app = new HelloJME3();

app.start(); // start the game

}



@Override

public void simpleInitApp() {



//map object arrays

vh1 = new Vector3f[100][100];

bh1 = new Box[100][100];

gh1 = new Geometry[100][100];



Material mat = new Material(assetManager,

“Common/MatDefs/Misc/Unshaded.j3md”); // create a simple material

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





//generate vector data for map squares

for(int i=0;i==99;i++){

for(int e=0;e==99;e++){

vh1[e].set(e, 0, -i);

}

}



//generate box objects at relative vectors

for(int i=0;i==99;i++){

for(int e=0;e==99;e++){

bh1[e].updateGeometry(vh1[e], BOX_X, BOX_Y, BOX_Z);

gh1[e].setUserData(“Box”, bh1[e]);

//gh1[e].setLocalTranslation(vh1[e]);

gh1[e].setMaterial(mat);

rootNode.attachChild(gh1[e]);

}

}



Vector3f vStart = new Vector3f(0,2,5);

cam.setLocation(vStart);





}

}



[/java]

Define “doesn’t work.” It looks to me like this code will crash because the arrays are created but they will be full of nulls because the elements were never filled.



If this is more than a simple oversight then you might want to brush up on your Java skills before tackling a 3D game using a Java engine.

This supposed to be a minecraft like game? In that case: Box worlds are not made from boxes!

@pspeed said:
Define "doesn't work." It looks to me like this code will crash because the arrays are created but they will be full of nulls because the elements were never filled.

If this is more than a simple oversight then you might want to brush up on your Java skills before tackling a 3D game using a Java engine.

Of course... -.- yes its a "simple oversight"...i feel a little embarrassed about it.... It works fine now....

@normen said:
This supposed to be a minecraft like game? In that case: Box worlds are not made from boxes!

no its not a "minecraft like" game.

Ok, so for my first post in this community ive made myself look pretty stupid. Thanks for helping.

Even if it’s not a minecraft game, you will want to somehow have one mesh instead of 10,000 meshes as 10,000 separate objects will really kill performance.



There are a few ways to accomplish this but they are well covered elsewhere on the forum, etc.

1 Like
@fatesauce said:
Ok, so for my first post in this community ive made myself look pretty stupid. Thanks for helping.

Haha, don't worry, your post was well written and had all the info but the actual error/exception you got. Believe me, when I got problems with some stuff and after hours of fighting with myself finally post somewhere it it also always something ultra-stupid ;)
@pspeed said:
Even if it's not a minecraft game, you will want to somehow have one mesh instead of 10,000 meshes as 10,000 separate objects will really kill performance.

There are a few ways to accomplish this but they are well covered elsewhere on the forum, etc.


this is true, i wont lie to you, ive been coding in java for years but havent explored 3D in detail until now. Can you provide a link?

Check under “best practices”, also check the “custom meshes” page as ideally you should generate the surface mesh yourself. Also check the forum for “voxels” as basically what you want to do is a voxel engine (basically creating the mesh that “wraps” some volumes, like boxes).

ok thanks a bunch