Sign in to follow this  
Dud

pickedPoint is null even though pickWithRay finds heightmap?

Recommended Posts

Hi all,

 

I am trying to find the intersection of a ray with a height map in order to be able to place point sprites at various locations on my height map.  I have read the various forum postings on the subject and I believe I have everything set up correctly.  My heightmap is 100x100 with 50 subdivisions and is called "ground".  When I call scene.pickWithRay in the function below I *do* hit the ground and I do have a pickInfo object - however the  pickInfo.pickedPoint object is always null.  Have I made a mistake somewhere?

Map.prototype.createPointSprite = function (scene, spriteManager, name, x, z) {                       var spritePosition = new BABYLON.Vector3(0, 10, 0);            //Shoot a ray to get height of map at required sprite position            var ray = new BABYLON.Ray(spritePosition, new BABYLON.Vector3(0, -1, 0));            var pickInfo = scene.pickWithRay(ray, function (item) {                if (item.id == "ground")                     return true;            });                        //Only place a point sprite if our ray hit the ground            if (pickInfo != null && pickInfo.pickedPoint != null) {                var sprite = new BABYLON.Sprite(name, spriteManager);                spritePosition.y = pickInfo.pickedPoint.y;                sprite.position = spritePosition;            }                    };

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.