Listening to click events on mesh

One way is to create an ActionManager for your mesh and register i.e. ExecuteCodeAction with OnPickTrigger:

Another solution would be to create onPointerObservable for your scene:

scene.onPointerDown = () =>
{
  if(...) // scene.meshUnderPointer is equal to your mesh
    {
      // your code
    }
}

You could also use onPointerUp or onPointerObservable with PointerEventTypes.POINTERDOWN or -UP tag.

meshUnderPointer-property of Scene:

https://doc.babylonjs.com/typedoc/classes/BABYLON.Scene#meshUnderPointer

How to use Observables:

Edit:

To enable/disable camera rotation, you can add/remove or customize i.e. mouse input from camera:

Also here is an example playground, how camera mouse input is customized by checkInputs() of FreeCameraMouseInput:

To enable/disable mesh rotation by mouse input, you can add/remove observer for i.e. onPointerMove or onPointerObservable with PointerEventTypes.POINTERMOVE tag.

4 Likes