Get an offscreen canvas renderloop working in a PG?

I am trying to get a offscreen scene rendering in a Playground, but it looks like the worker does not have access to any of the BABYLON classes.

This is a continuation of:

Is there a better way to do this that will get the loop to run? I’m trying to make a proof of concept for something and this is a blocker.

1 Like

your worker needs to load the various babylon scripts as well

Yeah but how? I know they do but it does not have access to imports or require and no scope to BABYLON like the Playground has. If it does then Im not sure how.

you need to use importScripts in your js https://playground.babylonjs.com/#85AHZJ#7

3 Likes

Just getting an error on this :
BJS - [19:51:11]: Babylon.js v7.3.1 - WebGL2 - Parallel shader compilation
/#85AHZJ#7:1 Third-party cookie will be blocked. Learn more in the Issues tab.
763a2cfa-9943-4fb0-9b34-d7589b50bb13:5 DedicatedWorkerGlobalScope {name: ‘’, onmessage: null, onmessageerror: null, cancelAnimationFrame: ƒ, close: ƒ, …}
thinEngine.ts:403 Uncaught TypeError: _this._gl.getContextAttributes is not a function
at Engine.ThinEngine [as constructor] (thinEngine.ts:403:1)
at new Engine (engine.ts:355:1)
at self.onmessage (763a2cfa-9943-4fb0-9b34-d7589b50bb13:13:22)

Is that normal?

Yup there is a typo in the code, it should be https://playground.babylonjs.com/#85AHZJ#12

1 Like