new getHeightAtCoordinates() and getNormalAtCoordinates() functions

Recommended Posts

Iiceman asked once what was the potential utility of the method getNormalAtCoordinates() ...

http://www.babylonjs-playground.com/#RBXBG#1

No physic engine.

Actually I compute 3 orthogonal axis (with the cross product) from the particle plane velocity vector and the current ground normal. These 3 axis are the target system where I want to rotate each particle into.

So then the power of RotationFromAxisToRef() and that's all.

I need to optimize this method a bit so it won't allocate any temporary vector3 : currently only 6 per call. That's not that much, but if you call it 8000 times per frame for 8000 particles for instance, I guess the GC will start to shout.

[EDIT] : this one has 2000 boxes and still run at 60 fps on my computer

http://www.babylonjs-playground.com/#RBXBG#2

Share on other sites

http://www.babylonjs-playground.com/#1LEGTP#1

Commented code : each rolling ball has a tiny line on its top, normal to terrain.

Is it wrong to say this looks cute for some reason it reminds me of Pikmin or something (I know it's just to demonstrate the feature, but still somehow it seems expressive despite being so simple, lol)

Share on other sites

This seems to have broken something for me... all my trees started floating on the 0 plane when I updated :S

Does it take into account if the groundmesh is translated?

Share on other sites

No, the returned height is the height from the ground, so in the ground local system. This makes sense because the passed x,z are the coordinates an the ground map also.

I should document this better.

Just add the ground position to your passed or return values : tree.position = ground.position.add(new BABYLON.Vector3(x, y, z);

where x, y, z are the coordinates passed and returned from the function

or just tree.position.y = ground.position.y + ground.getHeightAtCoordinates(x, z);

if you have just a vertical translation

Unless everyone prefer that I switch everything to the World system ?

I asked this before recoding it but got no answer, so I guessed my assumption was the expected one because of my arguments (local system)

Share on other sites

As the former version of this function used the ray intersection, so World coordinates, I will change the new function behavior so you can pass (x, y) in the World system and get y in the World system also.

I'll do it as from monday.

fix PRed

Share on other sites

• 1 month later...

I just added a new complementary method called : updateCoordinateHeights()

This function can be called at any time, even within the render loop, and recomputes quickly all the heights of your ground if this ground has been updated (morphed, etc).

``````myMorphFunction(ground);
ground.updateCoordinateHeights();
ground.getHeightAtCoordinates(x, z);``````

Moreover, all the algo under the hood now never reallocate any new memory, so the GC is happy and you can morph your ground and recompute the heights in the render loop as many times you want

[EDIT] commented PG : http://www.babylonjs-playground.com/#1JXJVF#3

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.