Attach model to terrain

Hi everyone,

I want to attach model to certain hight on terrain. Could you advise me a tutorial or guide me the way I need to move.


1 Like

Yeah, it is great. But How can I get coordinates from hight array of terrain?

The point is that I want to write code which locate objects(grass or something) on terrain according terrain’s hight.

English is not my native language, I mean code which place objects on terrain according terrain’s hight

from what i understand, you will want to examine either: translation.y of each bottommost (almost leaf, not sure if terrainpatch can offer coordinates) node in the terrain and then given a condition y> blah you attach an object to that node, or you could perhaps use ray collision at a certain height (Vector) but im not sure how to acquire coordinates from that.

note: depending on size of nodes (i.e. how many patches it contains) you may need to loop through the heightmap to see if this node contains a y (height) that fits the condition

1 Like

Yeas you are right, I need to find out coordinates of every terrain patch and then filter them by condition of y>100 for example.

I figured out how to work around my idea.




Well, I have another problem. I need to create a lot of clone of object(grass geometry) to place on terrain. Try to find out… any advise will be helpful

Why don’t you model the grass in a 3d modeling software?

I wand to place grass dynamically in case of different terrain. So I need single objects will be cloned, I believe there is way to do it in JME

glauco has a point, if you used a low poly model you just create a new instance of it where the terrain is above certain height, you would probably need to create some kind of spacing element to spread them evenly, for example

What do you mean?

for example,

[java] some node/self made path.add(new Geometry(“y:”+height, new Sphere(50, 50, 1)));[/java]

where geomerty is your grass model * i just used sphere as an example, basically, you “populate” your scene with these models to simulate grass,

take a look at this thread, (read it fully, dont just scim :stuck_out_tongue: )


1 Like

sorry for stupid question. I am a little confused by “path.add”, where I must put this “.add():”

ok, sorry i meant attachChild there, been using too many arrayLists recently,

you create an invisible node to hold these grass models, did you look at the glsl shader rendering of grass ? that looks more promising to me.

Actually, did not see ), thanks for help

Did you already see the shader-based grass contribuition by @canis85?

1 Like

I will try it a little bit later, thank you gays

I tried this, but see only 1 sphere((


for (int i = 0; i<=tsize; i++){

if (terrain.getHeight(vector) > -80f && terrain.getHeight(vector) < -70f){

System.out.println("Press " + terrain.getHeight(vector));

pivot.attachChild(new Geometry("y:"+i, new Sphere(50, 50, 5)));







if (terrain.getHeight(vector) > -80f && terrain.getHeight(vector) < -70f){


This condition is possible? How a float can be > -80f and in the same time < -70f? :? Are you a magician :)?