Jump to content

new getHeightAtCoordinates() and getNormalAtCoordinates() functions


jerome
 Share

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

 

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

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

Link to comment
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)

Link to comment
Share on other sites

Wait please

 

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.

Link to comment
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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...