Basic on sphere

Hello I am new in 3D and jmonkey so maybe my question will look stupid …

I want to be able to create a sphere and from this sphere loop through each vertex of the sphere and update vertex that I will modifiy. (it is not all, it just some that I will pick up randomly)

I did something like this :

[java]Mesh sphereMesh = new Sphere(32, 32, 500, false, false);

Triangle tri = new Triangle();

sphereMesh.getTriangle(i, tri); // where i is a random indice of triangle.

Vector3f vertex = tri.get1(); // I get one on 3 points of the triangle … let’s say point 1[/java]

first : this is correct? Is it one vertex of the sphere?

Second: And then if I want to modify it and put it back in the sphere, for example I change coordinates of the vertex, how I can make it update in the sphere?

I saw this line


Please some one can help me on this?

Thanks and I start to really like to play with Jmonkey !! Great job !

Thanks for the fast reply. :slight_smile:

So it means that Sphere (and the other shapes provided by default) cannot be used for little more complex case and I have to create my own Mesh?

Because I do not understand why I cannot use directly this Sphere Class as Sphere extends from Mesh.

sorry I think I reply too quick:

[java]m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));

m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));

m.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes));


I suppose that I can use it by using direclty the method :

[java]sphereMesh.getBuffer(Type.Position) [/java]

Thanks :slight_smile:

After you modify the VertexBuffer, you have to call setRefreshNeeded() to force it to update

Hi MF,

I did not call this method, and it woks as expected. (vertices have been updated) … probably because I am doing only it once at the initialization of the sphere.

Just to show you what I am currently doing :

another planet generator - but note that I do not have any competence in 3D art … (unfortunatly :slight_smile:

so a view of the planet:

And as you can see, some mountains / island are available too.

The water looks crapy, because it is just a stupid sphere with a color blue … and as you can see, intersection on picture 1 does not look nice … when you come closer to the planet, this unplaisant effect disapears but I am convice that there is probably a proper way to do correct water representation.

Can someone can tell me what I should do for putting water on a sphere?

I saw that the nice WaterFilter cannot be used for none plane shapes. But oviously if you go on internet there is a lot of people that succeed to do this - for example :

planet generation

Any idea ?

1 Like

Cool :slight_smile:

Spherical mirrors are not exactly easy to simulate, you’d have to tweak the reflection camera and shader settings quite a bit I guess… Right now I can’t even completely imagine how to do it at all… maybe its not even possible, thats why most of the time environment maps are used for that… When you have a planet you mostly reflect the sky I guess, so having an environment map of some sky might work for you…

1 Like

Ah and also, jME3 has some helper classes for mercator projection. When you don’t know what that is google it, its probably helpful for what you want to do :slight_smile:

There’s no need to do reflection on a planet scale, just make the water brighter and give it a lighting material so it shines in the sun

1 Like

thanks to your answers guys :slight_smile:

I agree for reflexion - only ligth of the sun will be enough (for the moment :D)

I would like to have your advices of both of you:

Do you think it is the best way to generate water level/shape on the all planet with just a simple sphere like I did?

because I notice a nasty effect of blinking on intersections of the sphere(water) and the planet ground (a computed mesh based on another sphere).

The ground under the sea level is present too.

I did a video to let you see the problem to make it clear to undestand. I just moved in direction of the planet. As you can see the effect is really unpleasant.

ground is blinking video

How I can fix it ?

Other points, any advice about animation of this water surface too? The effect should look close as you have on the waterFilter (minus the reflexion around) should I calculate modification for each frame via the update method or via shader? (that - for the moment I do not have any knowledge! :slight_smile:


PS: Really it is a pleasure to have people that answers to so fast! Great community! I feel that I start to more and more a … monkey :slight_smile:

The flickering is due to Z-Buffer Fighting either higher the depth buffer(z buffer) precision or use a smaller scale. Also highering the Near frustum of the camera might yield better results.

Hi EmpirePhoenix,

About the Z-buffer solution :

I did not test yet the solution, but it means that I have to change it dynamically when I run the application? I mean, I need a large (huge) in fact the maximum as possible or at least, give this impression.

Because if I am rendering a planet, it means I wld like to run a solar system. (I think it should not be bigger than that … :D) but it represents a lot of km² … the question is how to manage this change in a smart way ? let say that I have a near at 1 and a far at 1000 (on the surface of the planet it could be good enough I think) but when I star to go out of the planet I have to increase far to 1000000 for example and the near at 10000. but what about object that will pass just near of the camera? it not make any pb ? (for example I am far from my planet and an asteroid is passing close to me in direction of the planet … how to handle this for example?

Another point, this pb could be solved may be with LOD technic and keep the same near/far buffer?

Sorry if my questions looks like “beginner level” but it is the case for me :smiley:

Is there any technic to handle this kind of common scale pb?

Well I use for my game a 64bit calculation of everything, then the cam stays always at zero and the map (converted to 32 bit player coordinate system) is used to render the stuff. I specify for the depth buffer a 32 bit, wich are not supported on many older cards (most only use a 24bit or even 16) this reduces all z zbuffer issues (or at least most of them) For the planets I use Normalmaps + Parralax for distance rendering, wich means that the sphere is just a sphere and has no z fighting that way.

Near far are always the same, I use a 1meter near frustrum and made the player collision zone at the with the same size, to ensure nothing intersects the 1 meter radius.

yes, but it means in such conditions you can only fly around and never land on them - yes I am ambitious :smiley:

but it is quite common.

to tell you the truth I already start something similar but stop this way of doing because, yes indeed you have only a spheres.

Even if the result what not so bad I was not happy with the fact you are stuck in space and not able to land.

here it was my previous work with only a java application + LWJGL.

But as beginner it was hard to get nice result quickly due to the huge of work : you have to implement everything almost :slight_smile:

That s why I swith to an engine that has already in-build so more common needs for games.

I will try to continue to investigate and post to help people that are interesting by what I want to accomplish.


Well if you use some ind of atmosphere you could hide a scene switch in it.

I will do the switch with a more simple solution either some docking station in low orbit , where you get teleported to planet then or a docking ring systme, that teleports you in another scene high above ground. Not sure how excactly I will make this. (With such defined switches, you could also adjust the frustrum values for onplanet and of planet. But far befor that you get the problem of relative sizes between planets and ships and surface models. (As you cant even model a small part of a planet with 32 bit without much tricks.