Hello guys,
since I want to keep performance as hight as possible I am using offscreen canvas for my scenes. In some cases I give the user the capability to drag and move an object along a plane (x&z-axis). I accomplished that by creating a drag behavior with:
new PointerDragBehavior({ dragPlaneNormal: new Vector3(0,0,1) })
That works fine with onscreen canvas but some problems appear if I use offscreen canvas.
My worker is initiated like this:
Init: https://xcraft.net/tutorial/lab/babylon_worker/init.js
Worker: https://xcraft.net/tutorial/lab/babylon_worker/worker.js
That makes it possible to call addEventListener or removeEventListener from the worker which is nice for attaching or detaching camera controls.
I noticed that adding the behavior to the object breaks camera controls as well as scene.onPointerObservable. Even after removing the behavior the pointer observer and camera control is broken.
It seems the problem is that pointerDragBehavior creates a new scene. Following adjustments fix it.
PointerDragBehavior._planeScene = this._scene
this._dragPlane.isVisible = false
Using the same scene allows me to continuously observe pointer events with offscreen canvas. I don’t know why but using the same scene makes the plane visible. Setting isVisible to false solves this. It works but I don’t want to edit the bjs source files. So how am I able to do that with my code?
I appreciate your help!
Best