Suggestion: Associate user data with heightmap

This is probalby best described as a feature request.



I am currently playing around with TerrainQuad/Grid. My goal is to procedurally generate terrain that have layers. Like snow on top of dirt on top of rock. This is because I want to be able to interact with the terrain. Sort of resource gathering like “pick up” the snow would mean poking at the height map to lower a few points and change the alpha map and splatting to reveal the dirt.



It would be really handy if there was a heightmap implementation that had something like



[java]

public interface HeightMap<T> {

public void setUserData(T data, float x, float z) ; // World coordinates

public T getUserData(float x, float z); // World coordinates

[/java]



As it is now I store the “UserData” in an array outside the terrain classes and calculate backwards from world coordinates to an offset in the UserData-array. But the terrain already knows how to do that and even better than I do. If I could associate some data with each point in the height-map I do not need to know anything about terrain-scaling and translation.



So what do you all think?



Cheers,

Johan Maasing

Thats not a good idea as this would mean a static link between terrain array and game tiles. Might sound handy for a small project but its totally not the way for a real game/application.

I agree with Normen. You can always put your own type of object that accepts coordinates into the user data. Then just pull coordinate-specific values out of that object.



As for actually associating what type of terrain (grass dirt etc) is under a certain point, there are several ways to do it and none can fit all requirements people might have. I looked into it a few times and decided it would be best to let each implementation take care of it.

Yes, it would totally mean a hard link between terrain and game tiles. With added difficulties for loading/saving terrain chunks, caching terrain and all that. I see the benefit of keeping concerns separate. It is just sooo tempting to find a way to reuse the calculations to go from world coordinates to array offsets (like in TerrainQuad.getHeightmapHeight :slight_smile:



Thanks for your time and thoughts, these forums are great.

you get this kind of reusing when you just do normal picking to find the position on the terrain, from whatever other system