Hello guys, So I loaded a model using import mesh async in my scene. I want to add a listener on it so that when I click on it, a function should work. Wherever I click on the model, it should run. How should I do it.?
I would recommend reading through this post, where ways for general and certain mesh picking are shown:
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:
How to use Observables:
To enable/disable c…
Depending on your needs you might also want to read Mesh Picking Docs, where you can utilize predicate: