Jump to content

scene.pick not worling with imported mesh?


Hagop
 Share

Recommended Posts

Help again :)

 

I have created a simple scene with a single cylinder.

The following code runs fine

 

 window.addEventListener("click", function () {
           // We try to pick an object
           var pickResult = scene.pick(scene.pointerX, scene.pointerY);
           console.log("HIT "+ pickResult.pickedPoint);
        });

 

However, if I import a mesh into the scene with BABYLON.SceneLoader.ImportMesh

the window.addEventListener returns a null , that is cannot hit the object.

 

Any clues?

Link to comment
Share on other sites

Hagop, did you declare the mesh you are importing outside of the BABYLON.SceneLoader.ImportMesh(....) function?

 

See an example here: A Sword

 

The bendy red bit is done with the BABYLON.SceneLoader.Load(....) function, and dad72's sword with the BABYLON.SceneLoader.ImportMesh(....) function.

 

If you look at the code, the variable sword is declared before/outside both those functions.

 

cheers, gryff :)

Link to comment
Share on other sites

Or look at how its done on Babylon Playground (change project in the top right to picking) : http://www.babylonjs-playground.com/#

 

In this example they use scene.onPointerDown = function(evt) {} instead of the addeventlistener.

 

I can't be sure why you are having your issue, but i think the problem is using window.addeventlistener (and i can't be sure why this is)

 

But i always use the canvas to add my listeners to.

Link to comment
Share on other sites

Try this, instead addEventListener:

scene.onPointerDown = function(evt, pickResult) {		if(pickResult.hit) {			var nameObjet = pickResult.pickedMesh.name;			console.log(nameObjet);			        console.log(pickResult.pickedPoint);		}				};

I've had this problem with Google Chrome or Firefox. But it is a compatibility histoir.

Link to comment
Share on other sites

OK, the problem is related to the mesh file itself (pantene.babylon exported from 3DSMax). Although I can import it into the scene, view, change its position, clone etc... can't pick it.

Here is a link to the file

http://www.ardzan.com/babylon_files/pantene.babylon

 

I tried another file (which I got from this forum) and it works

 

http://www.ardzan.com/babylon_files/myface4.babylon

 

 

 

However, none of the files has isPickable value...

Both files produce "not well formed" in the JS console

 

Link to comment
Share on other sites

Hi Hagop,

 

To be sure that your model is pickable, you can do this :

// Load the objectBABYLON.SceneLoader.ImportMesh("", "assets/", "model.babylon", scene, function (newMeshes) {    // For all meshes in this object    newMeshes.forEach(function(m) {        // Set the pickable parameter to true        m.isPickable = true;    });});

Hope this can help you :)

Link to comment
Share on other sites

However, none of the files has isPickable value...

 

 

Actually,Hagop,the pantene. babylon file has this right at the top of the file:

 

"meshes":[{"id":"b7b98bee-ac31-4209-9b73-f9b9a1495e02","parentId":null,"materialId":"4717f1ca-8435-40aa-bb10-522d839f1d3b","isEnabled":true,"isVisible":true,"pickable":false,"pivotMatrix":null,"positions":

 

 

Looking at both files, one seems to have been produced by 3dMax (pantene.babylon) and the other one with Blender (myface4.babylon). Looking at the way the materials are named, the Blender produced file maybe quite old as well.

 

cheers, gryff :)

Link to comment
Share on other sites

isPickable  solved my problem.

In case somebody has the same question and lands on this page the imported file from 3DSMax has the parameter set as follows

"pickable":true

However, unlike other properties, pickable is translated to isPickable in Babylon (this is the source of confusion),  so in order to check  this property use

BABYLON.SceneLoader.ImportMesh("", "scenes/", "pantene.babylon", scene, function (newMeshes) {
                        console.log(newMeshes[0].isPickable);            
                    });

Edited by Hagop
Further clarification
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.

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...
 Share

  • Recently Browsing   0 members

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