BabylonJS / Extensions

Extensions for Babylon.js
175 stars 154 forks source link

How to change the _scene of PointerEventsCaptureBehavior when using multiple scenes and switch scene. #277

Open hpyou opened 3 months ago

hpyou commented 3 months ago

I took a look at the existing code in pointer-events-capture-behavior.ts. It seems that after setting _scene for the first time, it cannot be changed.

const startCaptureOnEnter = (scene: Scene) => {
    ...
    if (captureOnEnterCount === 0) {
        document.addEventListener("pointermove", onPointerMove);
       // If there is _scene, it cannot be changed.
        _scene = _scene ?? scene;
        ....
    }
    captureOnEnterCount++;
};

If the mesh is not in _scene,the event cannot be captured

const onPointerMove = (evt: PointerEvent) => {
    ...
    // If the mesh is not in _scene, it cannot be picked.
    const pickResult = _scene.pick(pointerScreenX, pointerScreenY, (mesh) => {
        ...
    });
    ...
};
ericwood73 commented 2 months ago

Yes. We'll have to have a way to get notified when the scene is destroyed and clear the scene so it will get reset on the next call. I'll have to look and see if there is an observable we can use.