Support for picking complex (nested) meshes with ActionManager
See original GitHub issueIt would be nice if we had functionality that supports adding an action on a parent mesh that applies to interactions on child meshes.
Imagine I have a complex model that I’ve imported into a Babylon scene with many child meshes, let’s call it ‘myMesh’. I would like to be able to create an event that’s fires if the action occurs on any child mesh.
The API syntax would look something like the following - just pass recursive: true to indicate that the trigger should fire if the interaction occurs on any child meshes
//< Import model here >
myMesh.actionManager = new BABYLON.ActionManager(scene)
myMesh.actionManager.registerAction(
new BABYLON.ExecuteCodeAction(
{trigger: BABYLON.ActionManager.OnDoublePickTrigger, recursive: true}, () => {
console.log('My model clicked!')
}
)
);
Regarding performance - the implementation of such a feature would necessitate a more lightweight approach than registering all child meshes as observers for the action. I would recommend building a map of unique mesh Ids that are listening for events and for each event (picking, clicks, input, etc), just check the mapping to see if the pickedMesh is one of the meshes listening. (As opposed to checking if the actionManager for that particular mesh has a trigger)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:18 (12 by maintainers)
Top GitHub Comments
So it is done Slightly difference the isRecursive information has to be on actionManager for performance reason:
Nope only real meshes can have action manager