Procedural terrain

well I see the point… :confused: so to create such terrains either I make my code GPL or ask for permission… Thanks :slight_smile:

I think it’s time for a small update on this topic :slight_smile: I had a very exhausting time this week, so sorry, I need a few more days to finish. Some questions came up though:


  1. @Sploreg: can the TerrainQuad be changed, so it does not take an array of heights, but some object, so it can be backed by anything not having the need to load a concrete array? eg: ImageBasedHeightmap could be loaded without the need to load everything to an array first. Also the procedural part could be done more easily calculating only heights where it’s needed. As I took a look at the code, the HeightMap interface already has the methods needed for this:



    [java]

    public abstract float getInterpolatedHeight(float arg0, float arg1);

    public abstract float getScaledHeightAtPoint(int arg0, int arg1);

    public abstract float getTrueHeightAtPoint(int arg0, int arg1);

    [/java]



    Does it have overhead to call these methods instead of iterating over the array?


  2. I have some strange effects when moving the grid. I’ve created my class as an extension of TerrainQuad, and had the idea of using it as a real terrainQuad, only difference, I can replace it’s 4 quads as needed. This part works, and I can relocate the whole object by simply setTranslateLocal on the grid, but when I do so the following happens:



    http://www.novyon.org/ppx/imgs/TerrainQuadTest1.png

    http://www.novyon.org/ppx/imgs/TerrainQuadTest2.png

    http://www.novyon.org/ppx/imgs/TerrainQuadTest3.png



    As can be seen, some patches and subquads are misplaced.

ok… finally TerrainGrid is working. Needs some optimizations (TerrainQuad generation is still too slow, and something is slowly eating up memory), but it has the capability to load and unload terrain parts as the camera is moving around.



I’m still experiencing the strange misplaced quads effect. :confused:



http://www.novyon.org/ppx/imgs/TerrainQuadTest4.png

http://www.novyon.org/ppx/imgs/TerrainQuadTest5.png

http://www.novyon.org/ppx/imgs/TerrainQuadTest6.png



The last image shows, that the bullet physics are working there, and the camera does not fall, so the heightmap itself works as intended.



How am I supposed to commit the code?

1 Like

Cool, we can give you commit access to the jmonkeyengine repo, send me your googlecode mail via PM. I suppose this code is compatible to the current terrain and does not require breaking changes?

anthyon said:
1. @Sploreg: can the TerrainQuad be changed, so it does not take an array of heights, but some object, so it can be backed by anything not having the need to load a concrete array? eg: ImageBasedHeightmap could be loaded without the need to load everything to an array first. Also the procedural part could be done more easily calculating only heights where it's needed. As I took a look at the code, the HeightMap interface already has the methods needed for this:

[java]
public abstract float getInterpolatedHeight(float arg0, float arg1);
public abstract float getScaledHeightAtPoint(int arg0, int arg1);
public abstract float getTrueHeightAtPoint(int arg0, int arg1);
[/java]

Does it have overhead to call these methods instead of iterating over the array?

Yes this is a good idea. It would make the terrain quad much more flexible.
Most of the heightmap classes pre-load the data so there should not be a performance hit. It is only on startup, and only if the terrain is not saved to a j3o, so I wouldn't be too worried about it.

anthyon said:
2. I have some strange effects when moving the grid. I've created my class as an extension of TerrainQuad, and had the idea of using it as a real terrainQuad, only difference, I can replace it's 4 quads as needed. This part works, and I can relocate the whole object by simply setTranslateLocal on the grid, but when I do so the following happens:

http://www.novyon.org/ppx/imgs/TerrainQuadTest1.png
http://www.novyon.org/ppx/imgs/TerrainQuadTest2.png
http://www.novyon.org/ppx/imgs/TerrainQuadTest3.png

As can be seen, some patches and subquads are misplaced.

I would have to take a look at the code to see what is happening with the holes.
We should give you commit access. Do you have a test case example as part of your code?

I think my "real" work is starting to show signs of slowing down, so I should have some more time to look at this and help out. Fingers crossed.

What kind of test case you need? A working example, that shows how to do it is enough, like those in the Test project, or a real UnitTest? :slight_smile: Is there any coding or comment convention I should follow?



The misplacements of quads seem to be random, maybe just a synchronization problem in the update. Some of them disappear when the lodcalc has an effect on them, others remain until a new cell is loaded.

No not a unit test :stuck_out_tongue:

Just a test example like what currently exists under the terrain test classes.

Don’t worry about coding conventions yet. We can get it working and then comment it.

Tabs should be represented as 4 spaces however.

I have one more question before uploading: I have extended RigidBodyControl so it can update itself when the terrain changes. I called it TerrainBodyControl, but do not know where to place it…



I’ll clean up the test code, so it will work out of the box. Now it relies on some png outside the assets dir.

Why don’t you just do whatever you have to do from another control instead of modifying / replacing rigidbody control?

Well I was thinking of it, but I do not know how :slight_smile: All in all, there should be a listener interface, that can be added to the grid, cause different objects need to be notified of the changes. I thought it’s the part, where I can make a callback to update physics state as well. (the whole rigidbody needs to be recalculated)



How can I use controls to do the same?



The usecase:


  1. the grid’s update(Vector3f) method is called
  2. it determines whether the cam is approaching one of the edges or not
  3. if so, it updates the quads that make up the terrain, so new parts are loaded, others unloaded
  4. it calls every listener that’s registered with it, so they can modify their data according to changes
  5. calls super.update(Vector3f)



    I was planning to use a control class instead of my own listeners, but Spatial.getControl returns only the first instance of a given class, and I saw no way to iterate over the list. But I might be overlooking something. :slight_smile:

You can just make a new control and in its update method check the spatial its attached to for any kind of control that needs to be updated and perform the changes. About the access to the controls: you can iterate over all controls afaik.

I’ll have another round around this problem tomorrow, and wait with the upload until then :slight_smile:

OK… still not know how to do it with controls :frowning: I tried to commit my code, so others can help me out with that, but I get the following error:



org.tigris.subversion.javahl.ClientException: RA layer request failed

svn: Commit failed (details follow):

svn: Server sent unexpected return value (405 Method Not Allowed) in response to MKACTIVITY request for ‘/svn/!svn/act/5c6ccaa8-f182-424d-b8f1-4418fdc0a4e2’



This could have the following meaning(s):

  • the folder specified in the repository URL does not exist on the host
  • your proxy does not allow the svn command you have invoked



    I have worked with both cvs and svn before, but it’s something new for me :confused: What if I just simply put the class and two interfaces here?

You have to check out the repo using the https protocol, otherwise you cannot commit… Whats the problem with the controls? You create a new control, attach it to the spatial and then in its update() method you update the data of the RigidBodyControl if necessary and it exists…?

normen said:
You have to check out the repo using the https protocol, otherwise you cannot commit.. Whats the problem with the controls? You create a new control, attach it to the spatial and then in its update() method you update the data of the RigidBodyControl if necessary and it exists..?


ok... I guess it's simply not my week.. :D to update the physics that's easy to do... I think I don't even need a new control, just update the rigidbody from the grid update, if it exists. I need to check, how to update it's data, without removing and reataching it to the physicsspace.

But how do I broadcast a message to the whole world, that the terrain has changed? That is what I use the listener itnerface for. Any object can subscribe, and will be notified of terrain change events.

Just leave that to the user, its his application that will change the terrain anyway :wink:

I’m at the final testing, but the most recent update from svn created a file name “build” that is 143 megs. It stops me from building the project. Can I delete it, or is it intentional?

Sorry, I dont understand, what file is 143 megs?

got the following output from jMP build:



Building jar: D:work5JMEengine3trunkenginebuild

init:

deps-clean:

D:work5JMEengine3trunkenginenbprojectbuild-impl.xml:1198: Unable to create directory as a file already exists with that name: D:work5JMEengine3trunkenginebuild

BUILD FAILED (total time: 7 seconds)



and I have a file “%JME%/trunk/engine/build” that is a jar, and blocks creating the build directory.



Now I have updated the build xmls from svn, and it seems to work… Netbeans modified the build-impl.xml… :confused: