question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for picking complex (nested) meshes with ActionManager

See original GitHub issue

It 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:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
deltakoshcommented, Jan 31, 2019

So it is done Slightly difference the isRecursive information has to be on actionManager for performance reason:

BABYLON.SceneLoader.ImportMesh("", "/playground/scenes/BoomBox/", "BoomBox.gltf", scene, function(meshes) {

        // The first parameter can be used to specify which mesh to import. Here we import all meshes
        BABYLON.SceneLoader.ImportMesh("", "/playground/scenes/", "skull.babylon", scene, function(newMeshes) {
            var root = new BABYLON.Mesh('Name', scene);
            newMeshes[0].parent = root;
            meshes[0].parent = root;

            newMeshes[0].enablePointerMoveEvents = true;
            meshes[0].enablePointerMoveEvents = true;
            meshes[1].enablePointerMoveEvents = true;

            root.actionManager = new BABYLON.ActionManager(scene);
            root.actionManager.isRecursive = true;

            root.actionManager.registerAction(new BABYLON.ExecuteCodeAction(
                { trigger: BABYLON.ActionManager.OnPointerOverTrigger },
                function() {
                    alert('Mouse over!');
                }));
        });
    })
0reactions
deltakoshcommented, Apr 11, 2019

Nope only real meshes can have action manager

Read more comments on GitHub >

github_iconTop Results From Across the Web

Action Manager Left pick and right pick event not working on ...
So I was trying to attach and use the action manager for complex meshes. The left pick and right pick triggers work when...
Read more >
How to create the 2 nested mesh with the different resolution
Hi everyone, I'm a new user of MPAS model. After I read many tutorials of this model, I realized that the available mesh...
Read more >
https://unpkg.com/babylonjs@4.0.0-alpha.17/babylon...
attachControl() and it is called BEFORE the 3D engine process anything (mesh/sprite picking for instance). * You have the possibility to skip the...
Read more >
The COMSOL Multiphysics Physics Builder Manual
Double-array inputs are far more complex to design GUI components for, and some combinations are not supported. The table below summarizes the behavior...
Read more >
Jmol Files - SourceForge
bug fix (improvement): the Help>User Guide window was too narrow. ... fix: arrays of hashtables and other more complex variables not being saved...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found