Simple voxel engine starter kit

moonkey said:
as you saw in my code 256x256x128 is possible, and you can probably go even higher then that, perhaps 300x300x128. Notice also that memory usage is not that crazy, I get around 500MB, same as minecraft which is not bad, you can go up to 1.2 gb before java crashes, it doesn't deal so good with higher memory even if you specify in Xmx1024m...


I'm playing currently with "perlin noise" to fill the empty hills with content ... this is not so easy. Render surefaces (heightmap based) is easy. But in such a sandbox editor the user should remove the sureface box and then he should see the next underground leven and so on ... my last idea was to use a octree to store the internal content of the chunks to save memory, this could be the way.

regards
andreas

Hello ahoehma,

i checked out your project homepage and I am really fascinated by your work.

Also i admit it would be better for achievings to workt together.

Its my first time programming with 3D, but i programming for some years now and surely can help you with some things.

Or if possible, youse youre engine for some RPG game of mine.

Would be great if you can send me an PN with your ICQ, E-Mail or something.

regards

nemercry

Hi, tell me how to make removal and addition of ā€œcubesā€?

At first, when I have not seen your topic, I tried to make a map consisting of boxes and there I was able to make removal of the cubes, but it was too low fps = ( In your example, as I understand it, uses a polyhedron, and then I do not know how to do it = (

PS: Sorry for bad english

@moonkey said:
Hi

here are two pictures that can help you, they helped me alot when I was trying to understand what I was doing:

http://i.imgur.com/of75u.jpg

http://i.imgur.com/3LMTC.jpg

If you dont understand it, its important to put in on paper and I disected just 1 box on paper and understood how to build it properly my self. When you can build 1 box your self and you understand what you are doing, its easy to scale it up :)

So just look at those drawings if you get confused, or just draw some your self and take time to understand...

You can optimize this by adding chunks, I mean breaking big mesh you got there into smaller chunks, that would speed it up even more and would allow for bigger terrain then you got now. You'd have to figure that part out your self. Best is to do it first on really really small scale. I like to do things on small scale cos my brain can understand it better, and then its easy to scale up... So you could limit the mesh to be 9x9x9and then work on that scale and create chunks that are just 3x3. its much easier to visualse whats going wrong when something goes wrong :)

When you get it right on really small scale you can easiliy scale it up to big numbers :)

You could do physics, but you would need to limit it. If you dont need endless terrain then you dont need chunks, if you have limited area like 100x100x100 you are fine with what I gave you, you can start experimenting with physics and learning that! :)

Sorry to dig this post up from the grave but @moonkey I really wanted to thank you for this - I was about to give up with trying to produce my voxel landscape project and when I saw your pictures hand-drawn I realised and was inspired with new methods and ideas.
This topic was started a while ago but if you have achieved anything with your engine I would love to see it :D
Thanks again

@ollie



Hi ollie, I dont mind being awakend from a 1000 year sleep :slight_smile:



Iā€™ havenā€™t gotten arround to finish that sucka, but I still have urge and desire to make voxel engine that can scale up and down and which can be used to implement anykind of game. Well problem is that Iā€™ve got a full time job and this stuff does require energy and lots of focus so I put it on ice for a while. I hope to get back to it again soon :slight_smile: Meanwhile I wish you best and keep us updated. Glad that my pics helped, you can also look at the code I posted there should be enough there to make you understand some stuff which you need to be able to have large terrains! :slight_smile:

@moonkey

Thanks :slight_smile: I will be sure to keep you updated - I have re-written it slightly to suit the kind of game I am going to make and I have added in the ability to remove and add blocks. I will need to use picking now to decide which block should be added or removed. :smiley:

Funny thing is my interest in voxel has awoken yesterday for some reason, just few hours before you posted :d Iā€™m now looking again into it, its like a virus, it gets hold of me and I spend to much time reading forums learning how people all over the net tried to handle the problem, what algorithms they used for optimisation and for lights&shadows, etc. Iā€™ve learned alot but still I miss extensive knowledge of language like java or c++ to be able to fully optimize everything, so if Iā€™m to make real progress Iā€™d need to learn some more language specific things, etc :slight_smile: Anyways good luck I know how you feel :slight_smile:

@moonkey

Yeah - your engine inspired me a lot. Thank you again so much :slight_smile:

I have one question about a small part in your code:

At this line of code:

[java]for (int y = 0; y < (heightmap.getTrueHeightAtPoint(x, z)*0.08f); y++)[/java]

Where you are creating the cells, what is the logic behind multiplying the value by 0.08f? I realise when you remove it you get an ArrayIndexOutOfBounds exception but how did you figure out that number?

Thanks :slight_smile:

well Iā€™m not really sure how I decided on that number, I guess its just experiemented forward, since you have certain number of elements in your array that you canā€™t go above and you know that bitmap has values from 0-255 if I remember correctly which would give you at most height of 20 units, so when you remove it you are getting probably height of 255 units which is then out of bounds since array maybe goes as much as 128 elements or something like that? So that number is used to scale the height, you want higher height you increase that number :slight_smile:

Well @moonkey, this looks great dude. Keep up with this good work, it will be a good place for many developers to start!

I donā€™t really understand what happened here :stuck_out_tongue:

I tried downloading it and opened the projectā€¦ There were no errors found in the

code or anythingā€¦ But when I went to run it, it would shut down as soon as I

opened itā€¦ and then give me a long line of errorsā€¦ do you know what happened?


init:
Deleting: /Users/duprasinc/Desktop/Boxfun/build/built-jar.properties
deps-jar:
Updating property file: /Users/duprasinc/Desktop/Boxfun/build/built-jar.properties
compile:
run:
Jan 6, 2012 6:14:33 PM com.jme3.system.JmeSystem initialize
INFO: Running on jMonkeyEngine 3.0.0 Beta
Jan 6, 2012 6:14:33 PM com.jme3.system.Natives extractNativeLibs
INFO: Extraction Directory: /Users/duprasinc/Desktop/Boxfun
Jan 6, 2012 6:14:33 PM com.jme3.system.lwjgl.LwjglAbstractDisplay run
INFO: Using LWJGL 2.8.2
Jan 6, 2012 6:14:33 PM com.jme3.system.lwjgl.LwjglDisplay createContext
INFO: Selected display mode: 640 x 480 x 0 @0Hz
Jan 6, 2012 6:14:33 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Adapter: null
Jan 6, 2012 6:14:33 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Driver Version: null
Jan 6, 2012 6:14:33 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Vendor: NVIDIA Corporation
Jan 6, 2012 6:14:33 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: OpenGL Version: 2.1 NVIDIA-1.6.36
Jan 6, 2012 6:14:33 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Renderer: NVIDIA GeForce 9400M OpenGL Engine
Jan 6, 2012 6:14:33 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: GLSL Ver: 1.20
Jan 6, 2012 6:14:33 PM com.jme3.system.lwjgl.LwjglTimer
INFO: Timer resolution: 1,000 ticks per second
Jan 6, 2012 6:14:33 PM com.jme3.renderer.lwjgl.LwjglRenderer initialize
INFO: Caps: [FrameBuffer, FrameBufferMRT, FrameBufferMultisample, OpenGL20, OpenGL21, ARBprogram, GLSL100, GLSL110, GLSL120, VertexTextureFetch, TextureArray, FloatTexture, FloatColorBuffer, FloatDepthBuffer, PackedFloatTexture, SharedExponentTexture, PackedFloatColorBuffer, NonPowerOfTwoTextures]
Jan 6, 2012 6:14:33 PM com.jme3.asset.DesktopAssetManager
INFO: DesktopAssetManager created.
Jan 6, 2012 6:14:33 PM com.jme3.renderer.Camera
INFO: Camera created (W: 640, H: 480)
Jan 6, 2012 6:14:33 PM com.jme3.renderer.Camera
INFO: Camera created (W: 640, H: 480)
Jan 6, 2012 6:14:33 PM com.jme3.input.lwjgl.LwjglMouseInput initialize
INFO: Mouse created.
Jan 6, 2012 6:14:33 PM com.jme3.input.lwjgl.LwjglKeyInput initialize
INFO: Keyboard created.
Jan 6, 2012 6:14:34 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: AudioRenderer supports 64 channels
Jan 6, 2012 6:14:34 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
WARNING: OpenAL EFX not available! Audio effects won't work.
Jan 6, 2012 6:14:34 PM com.jme3.material.MaterialDef
INFO: Loaded material definition: Unshaded
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Gui Node)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
Jan 6, 2012 6:14:34 PM com.jme3.scene.Node attachChild
INFO: Child (Statistics View) attached to this node (Gui Node)
Jan 6, 2012 6:14:37 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
com.jme3.asset.AssetNotFoundException: Textures/grass.png (Flipped) (Mipmaped)
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:268)
at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:325)
at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:344)
at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:356)
at mygame.Map.build(Map.java:293)
at mygame.Map.(Map.java:89)
at mygame.Main.simpleInitApp(Main.java:44)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:231)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)
at java.lang.Thread.run(Thread.java:680)
Jan 6, 2012 6:14:37 PM com.jme3.renderer.lwjgl.LwjglRenderer cleanup
INFO: Deleting objects and invalidating state
Jan 6, 2012 6:14:37 PM com.jme3.input.lwjgl.LwjglMouseInput destroy
INFO: Mouse destroyed.
Jan 6, 2012 6:14:37 PM com.jme3.input.lwjgl.LwjglKeyInput destroy
INFO: Keyboard destroyed.
Jan 6, 2012 6:14:37 PM com.jme3.system.lwjgl.LwjglAbstractDisplay deinitInThread
INFO: Display destroyed.
BUILD SUCCESSFUL (total time: 10 seconds)

com.jme3.asset.AssetNotFoundException: Textures/grass.png (Flipped) (Mipmaped)



thereā€™s your problem, missing image.

thank you :slight_smile:

hi, are there any way to use different materials (textures) onto the blocks? the only way iā€™ve found was to create itā€™s own mesh for every block. but the heavy amount of the ā€œnew Geometryā€ command takes to much performance while creating the whole chunk.

@alrik said:
hi, are there any way to use different materials (textures) onto the blocks? the only way i've found was to create it's own mesh for every block. but the heavy amount of the "new Geometry" command takes to much performance while creating the whole chunk.

You use one texture atlas with all tiles and then set the texture coordinates of the single faces to point at the contained tiles.
1 Like

hi, first of all thank you for the quick reply.

i have some bugs with texturing the blocks:



www.alrik-online.de/texbugs.jpg



i use this code

[java]

mat_terrain = new Material(assetManager, ā€œCommon/MatDefs/Light/Lighting.j3mdā€);

Texture diffuse = assetManager.loadTexture(ā€œTextures/terrain.pngā€);

diffuse.setMagFilter(Texture.MagFilter.Nearest);

diffuse.setMinFilter(Texture.MinFilter.Trilinear);

diffuse.setAnisotropicFilter(16);

mat_terrain.setTexture(ā€œDiffuseMapā€, diffuse);

ā€¦

float scale = 0.0625f;

mesh.scaleTextureCoordinates(new Vector2f(scale, scale));

ā€¦

private void createBox(int faces[], float x, float z, float y, Vector2f texOffset){

ā€¦

List<Vector2f> TEXCOORD = Arrays.asList(new Vector2f(texOffset.x, texOffset.y), new Vector2f(1 + texOffset.x, texOffset.y), new Vector2f(texOffset.x, 1 + texOffset.y), new Vector2f(1 + texOffset.x, 1 + texOffset.y));

ā€¦

}

[/java]



what happend?

You might want to be clear what is wrong with that picture. Looks like pretty standard texture bleeding to me.

i mean the red,blue,green colored lines. i use the standard minecraft terrain.png.



here is another screenshot:

it looks very strange when i fly out

http://www.alrik-online.de/texbugs2.jpg

Minecraft doesnā€™t use any mip-mapping or filtering at all as far as I remember.



You could try using the JME texture atlas class instead since it takes care of some of this placement for you.



ā€¦but itā€™s hard to tell if itā€™s just a filtering problem. I canā€™t think of what else it would be, though.

@normen said:
You use one texture atlas with all tiles and then set the texture coordinates of the single faces to point at the contained tiles.

Hello, I have been developing a voxel engine recently as well. But I m currently stuck on texturing blocks with different textures. Do you mind to explain more details on "using texture atlas to set the texture coordinates of the single faces to point at contained tiles"? Thx