Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Babylon.js Mesh Picking & Ignoring Some Meshes

I am currently working on a small project using the new Babylon.js framework. One of the issues I have run into is that I basically have two meshes. One of the meshes is supposed to be the background, and the other is supposed to follow the cursor to mark where on the other mesh you are targeting. The problem is that when I move the targeting mesh to the position of the cursor, it blocks the background mesh when I use scene.pick, resulting in the other mesh having its position set on its self.

Is there any way to ignore the targeting mesh when using scene.pick so that I only pick the background mesh or is there some other method I could use? If not, what would be the steps to implement this sort of feature to essentially raycast only through certain meshes?

If you need code samples or any other forms of description, let me know. Thanks!

like image 788
Zerocaliber Avatar asked Nov 13 '13 03:11

Zerocaliber


1 Answers

Ok, it's easy.

So, we have two meshes. One is called "ground", the second "cursor". If you want to pick only on the ground you have two solutions :

First:

var ground = new BABYLON.Mesh("ground",scene);
ground.isPickable = true ; 
var cursor = new BABYLON.Mesh("cursor", scene);
cursor.isPickable = false;  

...

var p = scene.pick(event.clientX, event.clientY); // it return only "isPickable" meshes
...

Second:

var ground = new BABYLON.Mesh("ground",scene);
var cursor = new BABYLON.Mesh("cursor", scene);

...

var p = scene.pick(event.clientX, event.clientY, function(mesh) {
    return mesh.name == "ground";  // so only ground will be pickable
}); 
...

regards.

like image 96
Sayris Avatar answered Sep 28 '22 07:09

Sayris