Hagop Posted September 23, 2015 Share Posted September 23, 2015 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.ImportMeshthe window.addEventListener returns a null , that is cannot hit the object. Any clues? Quote Link to comment Share on other sites More sharing options...
gryff Posted September 23, 2015 Share Posted September 23, 2015 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 Quote Link to comment Share on other sites More sharing options...
ChrisR Posted September 23, 2015 Share Posted September 23, 2015 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. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted September 23, 2015 Share Posted September 23, 2015 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. Quote Link to comment Share on other sites More sharing options...
adam Posted September 24, 2015 Share Posted September 24, 2015 Make sure you are using hand.js. https://github.com/deltakosh/handjs Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 24, 2015 Share Posted September 24, 2015 and make sure isPickable is true :-) this is usually the problem. You can see the parameter in your .babylon file. My assumption - it is set to false... Jaskar 1 Quote Link to comment Share on other sites More sharing options...
Hagop Posted September 24, 2015 Author Share Posted September 24, 2015 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 filehttp://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 Quote Link to comment Share on other sites More sharing options...
Jaskar Posted September 24, 2015 Share Posted September 24, 2015 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 Hagop 1 Quote Link to comment Share on other sites More sharing options...
gryff Posted September 24, 2015 Share Posted September 24, 2015 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 Hagop 1 Quote Link to comment Share on other sites More sharing options...
Hagop Posted September 24, 2015 Author Share Posted September 24, 2015 (edited) 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 January 24, 2016 by Hagop Further clarification RaananW 1 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.