diff --git a/packages/core/src/input/InputManager.ts b/packages/core/src/input/InputManager.ts index 0a1268e32..15491bc2d 100644 --- a/packages/core/src/input/InputManager.ts +++ b/packages/core/src/input/InputManager.ts @@ -170,7 +170,7 @@ export class InputManager { constructor(engine: Engine) { // @ts-ignore const canvas = engine._canvas._webCanvas; - if (canvas instanceof HTMLCanvasElement) { + if (!(canvas instanceof OffscreenCanvas)) { this._wheelManager = new WheelManager(canvas); this._pointerManager = new PointerManager(engine, canvas); this._keyboardManager = new KeyboardManager(); diff --git a/packages/rhi-webgl/src/WebCanvas.ts b/packages/rhi-webgl/src/WebCanvas.ts index 01e545e12..4d81966e0 100644 --- a/packages/rhi-webgl/src/WebCanvas.ts +++ b/packages/rhi-webgl/src/WebCanvas.ts @@ -47,7 +47,7 @@ export class WebCanvas implements Canvas { */ get scale(): Vector2 { const webCanvas = this._webCanvas; - if (webCanvas instanceof HTMLCanvasElement) { + if (!(webCanvas instanceof OffscreenCanvas)) { this._scale.set( (webCanvas.clientWidth * devicePixelRatio) / webCanvas.width, (webCanvas.clientHeight * devicePixelRatio) / webCanvas.height @@ -58,7 +58,7 @@ export class WebCanvas implements Canvas { set scale(value: Vector2) { const webCanvas = this._webCanvas; - if (webCanvas instanceof HTMLCanvasElement) { + if (!(webCanvas instanceof OffscreenCanvas)) { webCanvas.style.transformOrigin = `left top`; webCanvas.style.transform = `scale(${value.x}, ${value.y})`; } @@ -70,7 +70,7 @@ export class WebCanvas implements Canvas { */ resizeByClientSize(pixelRatio: number = window.devicePixelRatio): void { const webCanvas = this._webCanvas; - if (webCanvas instanceof HTMLCanvasElement) { + if (!(webCanvas instanceof OffscreenCanvas)) { this.width = webCanvas.clientWidth * pixelRatio; this.height = webCanvas.clientHeight * pixelRatio; } diff --git a/packages/rhi-webgl/src/WebGLRenderer.ts b/packages/rhi-webgl/src/WebGLRenderer.ts index b6ce70250..70ab081d9 100644 --- a/packages/rhi-webgl/src/WebGLRenderer.ts +++ b/packages/rhi-webgl/src/WebGLRenderer.ts @@ -114,7 +114,7 @@ export class WebGLRenderer implements IHardwareRenderer { if (webGLMode == WebGLMode.Auto || webGLMode == WebGLMode.WebGL2) { gl = webCanvas.getContext("webgl2", option); - if (!gl && webCanvas instanceof HTMLCanvasElement) { + if (!gl && !(webCanvas instanceof OffscreenCanvas)) { gl = webCanvas.getContext("experimental-webgl2", option); } this._isWebGL2 = true; @@ -128,7 +128,7 @@ export class WebGLRenderer implements IHardwareRenderer { if (!gl) { if (webGLMode == WebGLMode.Auto || webGLMode == WebGLMode.WebGL1) { gl = webCanvas.getContext("webgl", option); - if (!gl && webCanvas instanceof HTMLCanvasElement) { + if (!gl && !(webCanvas instanceof OffscreenCanvas)) { gl = webCanvas.getContext("experimental-webgl", option); } this._isWebGL2 = false; diff --git a/rollup.miniprogram.plugin.js b/rollup.miniprogram.plugin.js index 92cdf8e47..009fb4538 100644 --- a/rollup.miniprogram.plugin.js +++ b/rollup.miniprogram.plugin.js @@ -35,7 +35,8 @@ const adapterArray = [ "WebGLRenderingContext", "WebGL2RenderingContext", "ImageData", - "location" + "location", + "OffscreenCanvas" ]; const adapterVars = {};