Sign in to follow this  
kevzettler

How to use Scene.pickWithRay ?

Recommended Posts


I'm trying to pick a mesh with Scene.pickWithRay and having problems.

	    var pickResult = scene.pickWithRay(ray, function (mesh) {
	      if (mesh.voxelData) {
	        debugger;
	        return mesh;
	      };
	    });

	    var mesh = pickResult.pickedMesh; //Get the mesh picked


I can trigger the debugger statement no problem with the mesh I want.

The mesh looks like it has the required properties:
 

mesh.isPickable
true
mesh.isEnabled
function (){return!!this._isEnabled&&(!this.parent||this.parent.isEnabled())}
mesh.isEnabled()
true
mesh.isVisible
true


I'm not sure what to do in the predicate function. The docs could be more clear: http://doc.babylonjs.com/classes/2.5/scene#pickwithray-ray-predicate-fastcheck-rarr-pickinginfo-classes-2-5-pickinginfo-

I've tried returning true and returning the mesh. Both situations `pickResult.pickedMesh` is undefined.

Share this post


Link to post
Share on other sites

In the predicate function you write your own logic of what meshes should be valid or not for picking.

In your case that is if the mesh has voxelData so what you should do there is return true. As long as mesh has voxelData it will be checked against the ray. Just because the predicate function returns true doesn't mean the ray will hit.
So as RaananW said if your debugger statement is executed the ray most likely doesn't hit your mesh.
 

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.