Jump to content

.getHeightAtCoordinates() with .updateMeshPositions()


bma73
 Share

Recommended Posts

Hi,

I'm manipulating the vertices of a ground mesh using the .updateMeshPositions() method and  now i want to get the height at a specific point (x,z) on the mesh with .getHeightAtCoordinates().

Unfortunately, this doesn't seem to work...

Here is a playground example:
http://www.babylonjs-playground.com/#1JXJVF#2
 

What am I doing wrong? 

Thank you!

BMA

 

 

Link to comment
Share on other sites

The altitudes are computed, for performance reasons, once on the first call to getHeightAtCoordinates() because the height map, designed from an image, wasn't supposed to be updated then

Nevertheless, if you want to force the altitude recomputation at will, just use the private method _computeHeightQuads() : https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.groundMesh.ts#L109

heightMap._computeHeightQuads();

This will generate a new underlying pre-computed altitude array.

Note well that, for now, this is not optimized to be used in the render loop because a new big array is generated each call. Your GC will shout !

Until I find a way to fix this, you should use a ribbon instead (if you don't need the heights from an image) and the same dedicated user function than in this example : 

 

Link to comment
Share on other sites

I just PRed an optimization, regarding the GC, with a new public method called updateCoordinateHeights() to force the height array reomputation on demand without any memory reallocation.

I'll show a PG example as soon as the fix is pushed in the PG engine.

 

[EDIT] :

 

Link to comment
Share on other sites

  • 3 months later...

please have a look a this example : http://jerome.bousquie.fr/BJS/demos/getHeightAtCoordinates.html

 

code here : http://jerome.bousquie.fr/BJS/demos/getHeightAtCoordinates.js

the boxes are rotated according the terrain normals : just a cross product (two actually) between the box direction (velocity) and the current terrain normal. 

 

ground API doc : http://doc.babylonjs.com/classes/2.4/GroundMesh

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