Feature request for TerrainGrid, getQuadAt

I keep hacking away at the “Inspector” that gets terrain-heightmap information from a running application. Still don’t know what it’s good for but that has never been a reason to stop hacking :slight_smile:



Anyway, It would be really helpful if there was some way to get a TerrainQuad child from the terrain grid given a coordinate in “cell space”.

Something like [java]TerrainQuad q = terrainGrid.getQuadAt(terrainGrid.getCurrentCell()) ;[/java] is what I’m looking for. Returning null if the quad isn’t in the grid cache.



The ways of getting the “current” quad I know of currently is using a ray test, or (what I do currently) register a listener and cache them myself with known keys, or getting the children of the terrain grid and finding the right one.



  • The problem with the ray-test is that I don't really know the world coordinates to test against. I'm using TerrainGrid#getCurrentCell() which returns a "cell space" coordinate. This is piggybacking on the LodControls camera I think. Also it seems a bit awkward to have to do the intersection-runabout when the grid already knows the "current" quad.


  • The problem with using a listener is that I can't make sure the listener is registered before the grid starts loading cells in the background, so I miss them.


  • I got stuck with the getChildren() approach because I don't know how to pick the right one. TerrainQuad exposes no identifier that can help me match against "current" cell. Which seems right because why should a TerrainQuad have knowledge about grid cell space (although it appears to have a protected offset-member).



Anyone know other ways I haven't thought about?

And since this is a wish-list I might as well wish for:
  • Tuple2 as return-type for getCurrentCell, and getCamCell so it is a bit more clear what coordinate system they return.

  • And maybe even a Tuple2 getCellSpaceFromWorldSpace(Vector3f). I think that might be useful if you want to synchronize resource loading/saving with the terraingrid. Like you listen for grid detach and want to know what "enemies" to persist with the quad when it is detached.



I can whip up a patch if these seems like reasonable features to have.

I added 4 new methods

public Terrain getTerrainAt(Vector3f worldLocation);

public Terrain getTerrainAtCell(Vector3f cellCoordinate);

public Vector3f toCellSpace(Vector3f worldLocation);

Vector3f toWorldSpace(Vector3f cellLocation);



I would like to leave the cell space as a Vector3f, at least for the time being. The intent is to allow for a lower terrain, and an upper terrain. So you can make an underground cavern or cave system (a floor and ceiling).



Keep up the work on the the heightmap inspector. Oh, do you have a way yet of exporting a heightmap to an image? I know some people have asked for that, although I’m not sure what use it would provide except to export the heightmap to another program.

1 Like
Sploreg said:
I added 4 new methods
public Terrain getTerrainAt(Vector3f worldLocation);
public Terrain getTerrainAtCell(Vector3f cellCoordinate);
public Vector3f toCellSpace(Vector3f worldLocation);
Vector3f toWorldSpace(Vector3f cellLocation);

I would like to leave the cell space as a Vector3f, at least for the time being. The intent is to allow for a lower terrain, and an upper terrain. So you can make an underground cavern or cave system (a floor and ceiling).

Keep up the work on the the heightmap inspector. Oh, do you have a way yet of exporting a heightmap to an image? I know some people have asked for that, although I'm not sure what use it would provide except to export the heightmap to another program.


Wow! Thanks a lot! Yes, when you say it I recall it has been discussed before about keeping a "height" value to make roofs and such. That would be such a kick-ass feature to have in the future :)

I haven't coded an export in the inspector but I'll look into the easiest way to expose the callback so it's possible to add more listeners in the SDK for the terrain data. That way one can write both a "click a button to take a snapshot" or "stream all images to a directory" plugin :)