I achieved some good results with offscreenCanvas so far and I am able to pass most information like pointer events between threads. Right now I try to include some 2d gui to the scene but this leads to a problem with my offscreenCanvas because I cannot call .getContext(“2d”).
import { AdvancedDynamicTexture } from '@babylonjs/gui/2D'
const adt = AdvancedDynamicTexture.CreateFullscreenUI("UI")
“Uncaught (in promise) DOMException: Failed to execute ‘getContext’ on ‘HTMLCanvasElement’: Cannot get context from a canvas that has transferred its control to offscreen.”
… in canvasGenerator. Can you adjust the way bjs determines if it is an offscreenCanvas? In my case document is defined and I am still using offscreenCanvas.
But if you specify all the object in JS Babylon can not detect it which is normal and expected which is kind of expected. I guess other functionalities would be not working
Could you not simply in your code undefined the document before the creation and then reassign it ?
Basically on the main thread or even offline you run the function I pasted before. Then you take what is in _ FontHeightSizes and send this to the worker or hard code it in. So that the function uses the cache instead of trying to compute it. If that works I ll make a public function to prepopulate it.