darcome Posted November 3, 2014 Share Posted November 3, 2014 Hello everyone! One simple question: as you can see here: http://ludem.net/babylon/index.html I have put up a little demo... My question is: why the OnPointerOverTrigger function works on the sphere and not on the other meshes? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 4, 2014 Share Posted November 4, 2014 Hi darcome, welcome to the forum! Your scene works perfectly (I would personally change the way the scene is loaded and the action manager added to all meshes, but this is just different taste).Your only problem is that all other meshes are not Pickable. Set their isPickable property to true (you can do it in the for loop you have created, or straight in the .babylon file). It will then work. tl;dr : scene.meshes.forEach(function(mesh) { mesh.isPickable = true; });(not the best solution, but since you are already doing something similar, adding this extra line of code would solve it :-) )Hope this helps! Quote Link to comment Share on other sites More sharing options...
darcome Posted November 4, 2014 Author Share Posted November 4, 2014 thank you very much! Now it works perfectly! But... How would you do what I did with a for? Please explain to me! As you've seen I just started to play with BabylonJS and any help is really appreciated! Thanks in advance! Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 4, 2014 Share Posted November 4, 2014 Glad it helped. To your question - A few improvements (again, just personal suggestions, I think other might have a different way of seeing things):you can set the pickable flag straight in your babylon file (I know i wrote it already :-) ). You can also add the sphere to the babylon file and save the few lines of code. If you do "2", you can load the entire scene using BABYLON.SceneLoader.Load (and not with import mesh, which ignores everything in the file except for meshes). If you load the entire scene (and not only ImportMesh), you can use scene.executeWhenReady to register a function that will initiate all action managers. There is no escape here - You would have to use a for loop, but in this case it will be in the right position. If, however, you want to keep on using the ImportMesh function, make sure you create action managers only to the meshes you just added (you get a wonderful "newMeshes" variable in the success callback of the ImportMesh function, which contains all new meshes that were just added to the scene). The other action managers for the existing meshes should be created before, right after the mesh is created (in your case, the only mesh I am referring to is the sphere).Eh, I guess this is it? Quote Link to comment Share on other sites More sharing options...
darcome Posted November 4, 2014 Author Share Posted November 4, 2014 Thank you for your reply! 1) I didn't know I could do it, and so I don't know how to do it. (I am using the exporter for 3ds max)2) The sphere is there just to understand why on the sphere the actionmanager works and not on the model I imported (but you told me it was for isPickable property).3) I am using ImportMesh, because I want to be able to import Meshes dinamically and not only once, and don't want to load a whole scene, but only meshes. Because, what I have understood is that Load replaces the whole scene4) I use the "WhenReady" callback of the ImportMesh function, or is it different than "WhenReady" of the sceneloader?5) Yes, you are right! I did that, but since it didn't work, I tried with the "global" meshes Infact in the callback I created, I sued the "meshes" So, could you answer to point 1) and 4) and clarify point 3) ? Again, thanks in advance!You are very kind! Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 4, 2014 Share Posted November 4, 2014 Hola, to 1 :I don't know how to do it in 3ds (anyone?=, but a simple find and replace using any text editor will work. Search for '"pickable":false' , change it to '"pickable":true' To 3&4:The success callback of import mesh will work wonderfully. Just make sure not to use scene.meshes in the for loop. Use the newMeshes variable the success callback is giving you. This way, you won't initiate new action managers to all objects constantly. In your case (taken and from your code with a slight change):var OnMeshesLoaded = function (newMeshes){ newMeshes.forEach(function(mesh) { mesh.actionManager = new BABYLON.ActionManager (scene); mesh.actionManager.registerAction (action); mesh.actionManager.registerAction (action2); })Silly editor left this one out:}Haven't tested, but should work. I prefer the forEach loop (i find it elegant), but a simple for with newMeshes.length will of course work as well. Quote Link to comment Share on other sites More sharing options...
darcome Posted November 4, 2014 Author Share Posted November 4, 2014 Ok, thank you very much! 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.