Does anyone know why the actionManager isn’t working here ? I want to simply change the material of a mesh when the user hovers their mouse over it or with touch events and get the name of the mesh.
Babylon.js Playground - Line 59
This scene has 581 meshes and when the user hovers over each mesh (there will be hundreds of meshes) I want to be able to use the action manager to change the material and run custom code depending on the name or the id of the mesh but I get callback errors when I try to do it.
It looks to me like the action manager itself is working just fine!
With just lines 59 and 61 uncommented you can see that it’s working.
So there’s some conflicting problem between the different actions that you’re trying to register.
One other thing to note, since you’re not filtering out the UK, the UK mesh also gets the same treatment (turns white). And because each dot shares the same material, when you hover over one dot, they will all update.
You might consider having a “deselected” material and a “selected” material, and swap the materials out on hover, rather than updating the material itself.
Hope that helps a little bit!
I was looking into this earlier and noticed that, with lines 59 through 63 uncommented, I only got the call that logs mesh indices twice. I briefly debugged into it (putting a
debugger; command just after the console log), and it looked like there was some problem setting up the second mesh; whatever happened on line 60 in the second iteration caused the debugger to hang, and I ended up taking the whole browser down. I then had to switch to another priority, so I haven’t followed up on this yet; but in case you get back to it before I do, my guess is that at least one of the meshes in the scene isn’t set up the way the code is expecting to; that’s causing an error, which is causing your
for loop to early out. Thus, it looks like the
ActionManager isn’t working because
ActionManagers aren’t getting attached to the vast majority of your meshes because the
for loop aborts early. I may get a chance to look at this again later today, but in case you get back to this sooner than that, hope this helps, and best of luck!
I need each mesh to respond individually on hover which is why I added the action manager in a for loop to give each mesh a unique action with its own “pointer space”. This won’t work if all the meshes have their material changed at the same time (although its a neat technique to manipulate many meshes … one for the future perhaps).
I need each mesh to change on its own on hover. Anyone have any ideas how to do that if not with actionManager? How would you change the material of a mesh on hover for hundreds of meshes?
@syntheticmagus - ok I will try this again with only a few meshes and see if I can spot any problems with the meshes. They are all just simple spheres created at coordinates in a blender python script I wrote. The UK map svg conversion might be problematic as there is a lot of ngons in the county meshes I suppose.
You CAN have many actions controlled by a single action manager!
I don’t think that’s the problem. I think the problem is that the specific actions you created are somehow cancelling each other out. Perhaps try a few different random actions to make sure?
Here’s a playground example pulled from the docs that you can also reference:
I’d definitely recommend putting a
debugger statement in the script so that you can inspect the code as it runs in-browser in a debug window (opened by pressing F12). That’s what I did, and it makes it much easier to look directly at what’s going on.
The problem – at least the first one, I didn’t dig past this – is on line 60, specifically with the following statement.
scene.meshes.material is null, so trying to query the
emissiveColor from null throws an error, which causes the
for loop to abort and stop setting
ActionManagers on meshes. The reason it worked for PirateJC is because he uncommented line 61 and left line 60 commented. 61 is still problematic because it sets an action with a null target, but it doesn’t cause an error that will abort the
I can use actions fine on their own. But I cannot get this to work inside “BABYLON.SceneLoader” . I have deleted the line that was causing that error but I still cannot get this to work. I am now looking at using raycast on a setInterval to do this. I know that’s not ideal but i need to get a demo working fast to get this job approved.
Does anyone else know how to add onhover and onhoverout events to a bunch of meshes with or without actionManager in BABYLON.SceneLoader?
Pointer observable and scene.pick or what ever it’s called with the cursor position.
Store what the last object the ray hit was, if that changes then update what’s highlighted accordingly