Jump to content

mesh.intersects(ray) not working with heightmap


iiceman
 Share

Recommended Posts

Hey guys,

 

I am trying to place some boxes randomly on a heightmap. Easy, eh? Well, therefor I want to determine the current altitude at some random coordinates by casting a ray to see where it intersects with the ground mesh as suggested here: http://www.html5gamedevs.com/topic/2248-retrieve-heightmap-altitude/

 

That's what I got so far: http://www.babylonjs-playground.com/#HLQ0L#0

 

But it always returns a hit: false ... I feel like I am missing something here or just doing it wrong but I can't seem to figure out what. Any idea?

Link to comment
Share on other sites

http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#ground-from-a-height-map

 

I guess you should get the altitudes in the CreateGroundFromHeightMap() callback function. Indeed, it takes some time to download the heightmap image file, so the mesh isn't yet computed when the function CreateGroundFromHeightMap() returns.

 

You could also use the dedicated method getHeightAtCoordinates(x, y) which returns the y value (x, z and y are the coordinates in the ground system).

I re-implemented this method yesterday, I don't think the last version is still in the PG.

Link to comment
Share on other sites

Wingut : eagle eyes !

can find a bug from 20000 feet high :lol:

 

I'm implementing a new method for height maps : getNormalAtCoordinates()

This will return you the vector normal to the map at the current (x, z) coordinates.

This will be useful for having meshes waving under the surface : y + val only is not efficient when the mesh is moving above a very inclined facet for instance, you may want to shift it along the normal.

This will be useful to compute a slope also : dot product (normal,  axis Y) if we want to give a mesh a direction according to the ground inclination for instance... almost physics, but without any engine ;)

 

[EDIT] : PRed

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