kevzettler Posted March 3, 2017 Share Posted March 3, 2017 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. Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 3, 2017 Share Posted March 3, 2017 Hi, might it be that the ray is not hitting this mesh? Wanna share a simple playground? Quote Link to comment Share on other sites More sharing options...
kevzettler Posted March 3, 2017 Author Share Posted March 3, 2017 @RaananWWould the mesh show up in the predicate if it wasn't being hit? scene.pickWithRay(ray, function (mesh) { //The mesh I want is available here }); Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 3, 2017 Share Posted March 3, 2017 the predicate is a function that is executed on each and every mesh in the scene. this is how you filter your meshes. if you return true, all meshes will be inspected using this ray. Quote Link to comment Share on other sites More sharing options...
haestflod Posted March 3, 2017 Share Posted March 3, 2017 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. Quote Link to comment Share on other sites More sharing options...
getzel Posted March 3, 2017 Share Posted March 3, 2017 Hello, there is a predicate part in my raycast tutorial : http://doc.babylonjs.com/tutorials/raycasts draw the ray : ray.show(scene, new BABYLON.Color3(1, 1, 0.1)); Quote Link to comment Share on other sites More sharing options...
kevzettler Posted March 3, 2017 Author Share Posted March 3, 2017 Ok thanks for clarifying. Is there a helper I can use to draw the Ray to confirm? Quote Link to comment Share on other sites More sharing options...
adam Posted March 3, 2017 Share Posted March 3, 2017 This PG doesn't use scene.pickWithRay, but it could still be helpful: http://www.babylonjs-playground.com/#ZHDBJ#36 Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 6, 2017 Share Posted March 6, 2017 On 3/3/2017 at 9:11 PM, kevzettler said: Ok thanks for clarifying. Is there a helper I can use to draw the Ray to confirm? Funny you say that, it is actually called RayHelper Quote Link to comment Share on other sites More sharing options...
kevzettler Posted March 6, 2017 Author Share Posted March 6, 2017 @RaananW hahah yeah I should have looked harder. Got it all sorted out though thanks for the help everyone! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.