Jump to content

OnPointerOverTrigger question


darcome
 Share

Recommended Posts

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!

Link to comment
Share on other sites

Glad it helped.

 

To your question - 

A few improvements (again, just personal suggestions, I think other might have a different way of seeing things):

  1. you can set the pickable flag straight in your babylon file (I know i wrote it already :-) ). 
  2. You can also add the sphere to the babylon file and save the few lines of code.
  3. 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).
  4. 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.
  5. 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?

Link to comment
Share on other sites

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 scene

4) 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!

Link to comment
Share on other sites

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.

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