Custom Mesh update performance problems

Hi,

I’ve made a big custom mesh like in this tutorial:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes?s[]=custom&s[]=mesh



I want to change certain point positions by clicking on the map so this is what I’m doing:

  • update the point positions when I’ve clicked on the mesh
  • Set the new coordinates in my mesh like this:

    mapMesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
  • Create a new collision data:

    mapMesh.createCollisionData();
  • Update the Mesh geometry

    mapgeom.updateModelBound();



    I need this process to be fast but mapMesh.createCollisionData(); is veeeery slow and if i don’t call it the collision data doesn’t update.



    I’ve taken a look into TerrainTestModifyHeight but this didn’t help since it is using a TerrainQuad and not a custom Mesh like me.

    Does someone know how to speed this process up?



    greetz

    Drollian

So you use a Heightmap-Terrain but create your own mesh? What has your mesh to do with a TerrainQuad?

So you use a Heightmap-Terrain but create your own mesh?

No, im using a Mesh() which i put into a Geometry(). I cant use a Heightmap-Terrain because it doesn't fit my needs.
What has your mesh to do with a TerrainQuad?


Nothing, but theoretically, changing the point positions in TerrainTestModifyHeight works like a charm, its done by calling these Meths:
terrain.adjustHeight(locs, heights);
terrain.updateModelBound();

So in my mind, when I'm doing this:
mapMesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mapgeom.updateModelBound();

Everything should work just fine (be fast). And it does, its fast, but it doesn't recalculate the collision data.

Adding this: mapMesh.createCollisionData(); makes my computer lag.

You think wrong, calculating the collision data for terrain (which is a heightmap, probably the reason why it “doesn’t fit” for you) is much less work than for an arbitrary mesh.

thanks for the info

@normen , i would love to use TerrainQuad an its heightmap but the mesh have to look like this:







And its LOD should always stay the same (which should be no prob)



Any idea how to do this?



edit: why am i getting thumb down for this? I would not ask if i knew how to do it and if i havend tried everything i could think of.

Why do you need the mesh to look this way? The terrain mesh isn’t “crappy”, it deforms much nicer than your “awesome” mesh. If you need the mesh data anyway, why do you need collision? At any instance using normal triangle collision with such a mesh is less than ideal, I suggest doing your own bresenham picking if you absolutely need the mesh to look this way (which sounds like a design flaw if its not for visual issues).

1 Like

Normen is right, you won’t get a better look with the way your mesh is stripped. Believe me, I tried both. Unless there is some research you can find to back up your mesh design, then it will be a waste of time.

Generating a collision mesh on something that is not a heightfield will be slow with that number of vertices. Also and if your terrain is large, you will need LOD. Or at least many of your users will.

TerrainQuad is also smart in what it changes when the mesh is updated. It is actually a whole bunch of Geometries, not one big one. So it just changes the ones it needs and updates the physics of those ones.

1 Like
Why do you need the mesh to look this way? The terrain mesh isn’t “crappy”, it deforms much nicer than your “awesome” mesh. If you need the mesh data anyway, why do you need collision? At any instance using normal triangle collision with such a mesh is less than ideal, I suggest doing your own bresenham picking if you absolutely need the mesh to look this way (which sounds like a design flaw if its not for visual issues).

Thanks for he answer. I know my Mesh is the crappy Mesh, i was just joking.

Yes its 100% for Visual issues, the player should be able to edit certain height points. For that it would be great if the mesh looks the same from every direction:



Of curse i could use terrain mesh without any problems, and it seems like i have to, but its graphically not looking as i wanted it to look.
... and doing my own bresenham picking, well, im in my 3rd Semester of studying computer science so this will be kinda hard to do.

greetz
drolli
2 Likes

on your odd spaced points you will have a completely different looking hill than on your even spaced points.



But either way, no matter which mesh you use, you won’t notice how the underlying mesh is structured because you will have smooth normals that hide this fact.

1 Like

Thanks @Sploreg for the great explanation, this really cleared some things up.


on your odd spaced points you will have a completely different looking hill than on your even spaced points.

Yeah i've noticed this, but thought thats ok.

But either way, no matter which mesh you use, you won’t notice how the underlying mesh is structured because you will have smooth normals that hide this fact.

Oh, ok, well in this case i guess i'll use TerrainMesh.

Thanks a lot u guys are awesome.

After 1 day of thinking about this, it seems like i can’t use the TerrainMesh like it is.



Here is why, I want to make a Tile-Based strategy building game (like command and conquer 1, or the old sim city games), but i want the terrain to be full editable by the player, like in this game (maybe someone reminds):







The idea is: The player can raise and lower the points of the mesh.

Therefore 1 Tile will be exactly one quad on the mesh → looking at the current Terrain Mesh, one building direction is “missing”:







And this will look weird.



While trying to edit TerrainMesh myself i stumbled upon a Method in LODGeomap saying “* This is a scary method!!! It will break your mind.”, which, after a few hours of reading, made me feel like this.



Until now i’ve not managed to implement my wanted mesh and it looks like if i finally got it implemented something else will go wrong.

For someone who’s completly new to 3d game programming its kinda hard to figure out what exactly is going on in and arround TerrainMesh. Expecially figuring out which Mesh buffer is doing what in LODGeomap.createMesh and how it’s all fitting together in Mesh seems like a inhuman task.



Now i have no clue how to go on… i thought of creating my own Mesh with all that magic it needs but reading about what i have to do made me feel like this again.



Also, from my point of knowledge it would take months to do this and my Mesh would just have the same functionality like TerrainQuad except of LOD control (i don’t need it → limited bird view). Is there any way to alter TerrainQuad in a nice and way easy to fit my needs?



In gerneral, is there any “good” and fast way to realize what i want in Jmonkey without re-inventing the wheel?

1 Like

I don’t think it will look weird.

Have you tried it or just decided it won’t work without trying it?

@normen said:
I don't think it will look weird.

@zarch said:
Have you tried it or just decided it won't work without trying it?

I've tried it. Maybe I've to explain more what i mean with "look weird".
For example: The current Mesh will always be able produce triangles with one side "looking weird".

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

Because of this:
http://i.imgur.com/OrZqE.jpg

Shure, with my Mesh i'll have the same problem on the odd spaced points, but I've tried TerrainMesh and it felt like 1 direction is missing.
Also, i think for the user who has no clue how such a mesh is constructed, my version is the more user friendly one for my needs as it provides more artistic freedom regarding to the possibilities of drawn shapes.
1 Like
@Sploreg said:
no matter which mesh you use, you won't notice how the underlying mesh is structured because you will have smooth normals that hide this fact.
@normen said:
you won’t notice how the underlying mesh is structured because you will have smooth normals that hide this fact.

I don't get this - if it is like this then why i am perfectly aware of how the underlying Mesh is constructed? I can clearly see the unwanted gaps i mentioned before:
edit: i dont think normals have much to do with my problem...



How it would be nice:
1 Like

yes there is a straight line possible there, just raise the points in between.



And this is yours shifted over by just 1 point:

http://i.imgur.com/MqIaM.png

It fails on all edges then.

1 Like
@drollian said:
I don't get this - if it is like this then why i am perfectly aware of how the underlying Mesh is constructed? I can clearly see the unwanted gaps i mentioned before:
edit: i dont think normals have much to do with my problem...




I think the problem is that you are trying to sculpt with single points instead of multiple. For example if you raised/lowered a group of 4 points at a time. Also have you tried that with smooth shading on to see how it changes the look?
3 Likes

Note that with any grid shape there will always be lines that cannot directly follow the edges, that is unavoidable. Adding the lines you have makes one extra shape possible but as someone else already demonstrated if instead you group points you can then make any shape you like using the standard mesh.

1 Like

If it is a grid then why are you running your lines diagonally instead of along the grid? I’m just kind of curious.



Or are you planning to support building in 8 directions versus the 4 that that sim-city like games have?