From 97d44228b63ffb7aaba8e40d21ddfe4b2a8a86db Mon Sep 17 00:00:00 2001 From: Federico Gratti Date: Sat, 14 May 2022 03:03:25 +0200 Subject: [PATCH] Support XR --- .version | 2 +- package.json | 2 +- src/Graphics.js | 11 +++++++++-- src/RenderLoop.js | 8 +++----- types/RenderLoop.d.ts | 1 - 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.version b/.version index 7cede92..62014a4 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -v6.9.0 +v6.10.0 diff --git a/package.json b/package.json index b15ee08..a932c6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ohzi-core", - "version": "6.9.0", + "version": "6.10.0", "description": "OHZI Core Library", "source": "src/index.js", "module": "build/index.module.js", diff --git a/src/Graphics.js b/src/Graphics.js index 607a6b0..4df4f7b 100644 --- a/src/Graphics.js +++ b/src/Graphics.js @@ -34,12 +34,14 @@ class Graphics premultipliedAlpha: true, preserveDrawingBuffer: true, powerPreference: 'high-performance', - logarithmicDepthBuffer: false + logarithmicDepthBuffer: false, + force_webgl2: true, + xr_enabled: false }; Object.assign(this.context_attributes, context_attributes); - if (context_attributes.force_webgl2) + if (this.context_attributes.force_webgl2) { this.canvas_context = canvas.getContext('webgl2', this.context_attributes) || canvas.getContext('webgl', this.context_attributes) || @@ -60,6 +62,11 @@ class Graphics context: this.canvas_context }); + if (this.context_attributes.xr_enabled) + { + this._renderer.xr.enabled = true; + } + this._renderer.autoClear = false; this._renderer.setPixelRatio(1); diff --git a/src/RenderLoop.js b/src/RenderLoop.js index 6614c62..6db4fde 100644 --- a/src/RenderLoop.js +++ b/src/RenderLoop.js @@ -12,8 +12,6 @@ export default class RenderLoop { target_application = target_application || new BaseApplication(); - this._frame_id = -1; - this.target_application = target_application; this.graphics = graphics; @@ -50,7 +48,6 @@ export default class RenderLoop // ###### END CYCLE ####### - this._frame_id = requestAnimationFrame(this.update.bind(this)); this.target_application.on_frame_end(); this.frames_passed++; @@ -69,7 +66,8 @@ export default class RenderLoop } this.is_running = true; - this.update(); + + this.graphics._renderer.setAnimationLoop(this.update.bind(this)); } stop() @@ -79,7 +77,7 @@ export default class RenderLoop this.is_running = false; this.target_application.on_exit(); - cancelAnimationFrame(this._frame_id); + this.graphics._renderer.setAnimationLoop(null); } set_state(new_state) diff --git a/types/RenderLoop.d.ts b/types/RenderLoop.d.ts index c09e51e..53c3ff5 100644 --- a/types/RenderLoop.d.ts +++ b/types/RenderLoop.d.ts @@ -1,6 +1,5 @@ export class RenderLoop { constructor(target_application: any, graphics: any); - _frame_id: number; target_application: any; graphics: any; is_running: boolean;