Action Manager triggered from a menu

I only used Action Manager triggers via direct Mesh triggers (roll over, click):

var doit = function (mesh) {
mesh.actionManager
.registerAction(
new BABYLON.InterpolateValueAction(
BABYLON.ActionManager.OnPointerOutTrigger,
mesh,
‘visibility’,
1,
200
)
);
doit(mymodel);

I am looking to trigger the effect using a button click from an html block:

var b1 = document.createElement(‘button’);
b1.id = “mybutton”;
b1.textContent = “Click me”;
b1.style.display = “block”;
b1.style.width = “100%”;
b1.style.fontSize = “0.7em”;
buttonbox.appendChild(b1);
b1.onclick = function() {
callFunction();
}

Thanks !

You can call this
'scene.simulatePointerDown(pickResult)`

some examples:https://playground.babylonjs.com/#1GLEJK#16

Another option, if you want to trigger an action that isn’t easily triggered by a simulated pointer action, is to call .processTrigger() on actionManager.

Here’s an example playground that shows an OnPointerOutTrigger running when the pointer leaves a mesh, as well as when the user clicks a GUI button:

1 Like

Thanks, the example did not work. How would you trigger an effect like the fade below using a registered action?

var doit = function (mesh) {
mesh.actionManager.registerAction(
new BABYLON.InterpolateValueAction(
BABYLON.ActionManager.OnPointerOutTrigger,
mesh,
‘visibility’,
1,
200
)
);

             mesh.actionManager.registerAction(
                new BABYLON.InterpolateValueAction(
                    BABYLON.ActionManager.OnPointerOverTrigger,
                    mesh,
                    'visibility',
                    0,
                    150
                )
            );         
        }

doit(MyMesh);

Thanks,
How would you trigger an effect like this using a mesh using a name “myMesh” -

.registerAction(
new BABYLON.InterpolateValueAction(
BABYLON.ActionManager.OnPointerOutTrigger,
mesh,
‘visibility’,
1,
200

Hi Adam_A,
The playground I linked to above just wrote to the console (either when the mouse left the sphere or when you click the button).

This updated version will run the animation you provided, when the user either mouses over the sphere or clicks the button.

Does that help?

Thanks!

2 Likes

Thats a good way of doing it thanks!

You’re welcome, glad it was helpful!