I created a terrain in the SDK and painted three different textures on it. What I know is, that you can also use an alpha map to “set” the locations of the textures, but since I create my terrain in the SDK, I don’t need to set this alpha map texture.
I want to know where I painted which texture, in order to play a specific footstep sound when the player walks over that area.
I found this sentence in the wiki:
You can paint textures on the terrain and the plugin saves the resulting splat textures as alphamap(s).
So I tried the following
// result is a ray cast result (tile of terrain)
TerrainQuad quad = (TerrainQuad) result.getGeometry().getParent();
Material mat = quad.getMaterial();
System.out.println("Mat: " + mat); // Mat: Material[name=null, def=Terrain Lighting, tech=Default]
System.out.println(mat.getTextureParam("Alpha")); // null
I think I misunderstood something here! Where is the information saved where each texture is painted on the terrain and how can I access it?
Thanks in advance,
Okay, I got one step further: I did a stupid mistake, I get the alpha map via
The problem I have no is how to get the correct color depending on the player position. If someone did this already, I would be really happy when that person can share it with me. Else I will do my best and find a solution …
One idea might be to do a ray cast from player foot to terrain, then get collision triangle index then by having index i think you can get corresponding 2D texture coordinate from VertexBuffer and by having 2D texture coordinate you can get pixel color from alpha map ?? (Have not tried it my self )
Or an other thought might be to use Navigation mesh for each area and let JME AI detect it for you if player is in a specific area.
Or you can use Bounding Volumes for each area and check if player is inside a specific area. (This is limited though , you can use some primitive bounding volumes like Box volume ) .
There are ways to find texture coordinates using the barycentric coordinates of a triangle intersection… but really when the terrain is one giant quad covered by one giant quad texture, finding the texture coordinate should be trivial just using x,z.
It’s like (64,0,64). I use the normal terrain provided by JME.
Excuse me, but what do you mean by that.
Okay, let’s assume I get a vector from this, but I am still struggling with how do I get the texture coordinates from that. Sorry, but I haven’t made click in my brain The texture is 1024x1024 pixels, terrain size is 512
I mean… how big is the geometry? The terrain quad. How many units wide? I’m not sure how else to ask how big something is. Seems like a simple enough question.
You might be kind of in over your head on this and may want to find a mentor to help you through it.
This is mostly straight forward 3D stuff. Texture coordinates run from 0 to 1. Your coordinates on your geometry run from 0 to geometry size… or -halfGeometrySize to halfGeometrySize… or whatever. I don’t know how the terrain quad stuff is setup. If the corner is 0 then you can literally get the texture coordinate just by:
Vector3f v = cr.getGeometry().worldToLocal(cr.getContactPoint().scale(1f/terrainQuadSize);
Vector2f texCoord = new Vector2f(v.x, v.z);
Or something like that.
…and if you can’t figure it out from there then you may want to seek a mentor who can work with you more directly.