Jump to content

getHeightAtCoordinates error


jurito
 Share

Recommended Posts

Hello,
I am quite a BabylonJS noob so sorry if it's a stupid question.
After creating a GroundMesh and updating the vertices' positions with CreateGroundFromHeightMap, I'm trying to locate dinamically the height of the ground at defined positions, but using the getHeightAtCoordinates method results in the error:

TypeError: Cannot read property 'slope' of undefined
    at i._getFacetAt...

Am i missing something obvious?

TIA

Link to comment
Share on other sites

@jurito welcome to the forum. Sorry I am not able to help with the getHeightAtCoordinates issue. I just wanted to point out to those checking out the PG that adjusting the  position of the camera and taking out the problem line 'console.log(getHeightAtCoordinates)` does show that the code is working. With current position of camera mesh appears hidden.

https://playground.babylonjs.com/#CPX1GV#1

Link to comment
Share on other sites

The error comes from the fact you don't initially use MeshBuilder.CreateGroundFromHeightMap() as it's expected but directly VertexData.CreateGroundFromHeightMap() instead what is, like, a semi-public method. This means that some expected properties aren't initialized, in particular subdivisionsX and subdivisionsY.

I would recommend either to call first MeshBuilder.CreateGroundFromHeightMap(), then to modify the vertices, then to update the heights if you're not sure about all the internals,

either to check what's is required before calling directly VertexData.CreateGroundFromHeightMap() if you prefer it

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