Jump to content

Ground mesh disappear on pickWithRay returning true


Recommended Posts

This code :

function getGroundHeight(x, z){x = new BABYLON.Vector3(x,50,z);height_of_ground=10;var rayPick = new BABYLON.Ray(x, new BABYLON.Vector3(0, -1, 0));var meshFound = scene.pickWithRay(rayPick, function (item) {if (item.id == 'ground'){return true;}});if (meshFound.pickedPoint != null) {height_of_ground = meshFound.pickedPoint.y;}return height_of_ground;}

makes the 'ground' mesh disappear
the 'ground' mesh is built from a heightmap

groundMaterial = new BABYLON.StandardMaterial("ground", scene);groundMaterial.emissiveTexture = new BABYLON.Texture('world/'+zone_id+'_tex.png', scene);groundMaterial.emissiveTexture.uScale = 1;groundMaterial.emissiveTexture.vScale = 1;land = BABYLON.Mesh.CreateGroundFromHeightMap("ground", 'world/'+zone_id+'.jpg', 100, 100, 15, 0, 20, scene, false);land.material = groundMaterial;

this didn't happen when the mesh was on smaller positions (x,z <~ 1000), but my positions range between 0 and 40000 for x or z values (0-50 for y)


removing 'height_of_ground = meshFound.pickedPoint.y;' does not solve the problem. but removing `return true;` from


`if (item.id == 'ground'){

return true;

does solve it ... but then i have no use !

no errors in the console regarding this error. but still before starting to receive it sometimes i get "WebGL: INVALID_OPERATION: drawElements: no ELEMENT_ARRAY_BUFFER bound"


any help would be aprreciated. i guess it's a bug in babylon js for large x,z values for positioning


thanks :)

Link to comment
Share on other sites

I am not able to upload the content anywhere atm, nor even on jsfiddle (little bit complex and uses some external files and images). but when i replaced the heightmaps with planes, everything was working fine. on top of that some heightmaps are not rendering, and they break the webgl engine to show empty space (nothing is rendered), but sometimes they show when moving around the world!. i am attaching some of the heightmaps i am using, maybe there's something wrong with the image files?


Link to comment
Share on other sites

Hi Ron! 


I'm quite sure that the current webGL spec does not allow more than 65536 vertices on a single piece of ground.  See http://stackoverflow.com/questions/4998278/is-there-a-limit-of-vertices-in-webgl .  You can have more than one piece of ground, but then you will need to do some magic to "stitch the seams" so the ground sections smoothly integrate with each other (possibly by cutting your heightMap texture into multiple sections).  Keep in mind that you can position mesh, cameras and lights in ANY location, with infinite granularity.  But as far as vertices per mesh... 65536 is the maximum.  MS Train Simulator - one of my favorite games, uses a topography sectioning system like that, and a technique called 'incremental loading'.


I am not sure if this is the problem you are having, but maybe.


Some other informative links:








At the main babylon.js website ... down in the Feature Tests section, there is a choice called 'heightmap' and I think that is the 100-subdivision heightMap ground from the 'convincing world' post (3rd link above).  It is large and smooth, and if you keep the rest of your meshes small, it will provide a nice large scene area for any project.


Take a look at http://www.babylonjs.com/playground/#RP6O4


I think THAT is the 250-subdivision heightMap ground from the heightMap tutorial (2nd link above).  Click that 'fullscreen' button, and mousewheel in/out, and pan around.  It is also quite a large play area.  :)  With a small character, it might take 3-4 LIFETIMES to explore all of that. (And lots of resources.)  :)


I don't know if any of this helps your problem, but I hope so.  Keep us posted.  Zip and attach your entire scene if you can, and want.  We want to help, but we don't have enough information yet.  :)  Be well.

Link to comment
Share on other sites

Thanks for the information, but actually i am using maximum of 20 pieces per ground, and it even fails to load one. more info: i am building the ground of heightmap while moving the camera:


  engine.runRenderLoop(function () {
move_camera function reads mouse inputs and moves the camera to positions, when moving outside of a ground mesh it loads the next ground mesh via the code i posted above. sometimes it works (5% of cases) sometimes it doesn't ... but the ground height returns the correct height underneath the camera, but it's kind of "invisible"! ... and sometimes everything in the scene just disappears with "too many errors" in console "on chromium/ubuntu"
maybe you might reproduce this? i have attached the heightmaps i use!
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.

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.


  • Recently Browsing   0 members

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