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
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.