From 1045836aed8b0466d3020321d7152d579d4ae414 Mon Sep 17 00:00:00 2001 From: Tibor Udvari Date: Thu, 7 Mar 2024 19:31:07 +0100 Subject: [PATCH] Bump p5 to ^1.9.0, handle webgl2 p5 context --- package-lock.json | 14 +++++++------- package.json | 2 +- src/p5xr/core/p5xrViewer.js | 2 +- src/p5xr/p5ar/p5ar.js | 2 +- src/p5xr/p5vr/p5vr.js | 2 +- tests/unit/p5xr/core/raycasting.js | 13 +++++++++++-- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index f67814b..3ab9861 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47,7 +47,7 @@ "karma-sinon": "^1.0.5", "mocha": "^10.2.0", "openssl": "^2.0.0", - "p5": "^1.5.0", + "p5": "^1.9.0", "parcel": "^2.6.2", "sinon": "^7.5.0", "watchify": "^4.0.0" @@ -12901,9 +12901,9 @@ } }, "node_modules/p5": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/p5/-/p5-1.5.0.tgz", - "integrity": "sha512-zZFMVUmGkXe2G5H6Sw7xsVhgdxMyEN/6SZnZqYdQ51513kTqPslLnukkwTbGf8YtW0RetTU0FTjYQMXnFD7KnQ==", + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/p5/-/p5-1.9.1.tgz", + "integrity": "sha512-TpuCll0KwyY8jyQbY9j4wCt+pA3Qv0egd4MqkrhJ58pBgdj5im5XsKpP/64gepDilJXTk126vWXiNAPeSezNdg==", "dev": true }, "node_modules/package-json": { @@ -26153,9 +26153,9 @@ "dev": true }, "p5": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/p5/-/p5-1.5.0.tgz", - "integrity": "sha512-zZFMVUmGkXe2G5H6Sw7xsVhgdxMyEN/6SZnZqYdQ51513kTqPslLnukkwTbGf8YtW0RetTU0FTjYQMXnFD7KnQ==", + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/p5/-/p5-1.9.1.tgz", + "integrity": "sha512-TpuCll0KwyY8jyQbY9j4wCt+pA3Qv0egd4MqkrhJ58pBgdj5im5XsKpP/64gepDilJXTk126vWXiNAPeSezNdg==", "dev": true }, "package-json": { diff --git a/package.json b/package.json index 8dcc989..050fa24 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "karma-sinon": "^1.0.5", "mocha": "^10.2.0", "openssl": "^2.0.0", - "p5": "^1.5.0", + "p5": "^1.9.0", "parcel": "^2.6.2", "sinon": "^7.5.0", "watchify": "^4.0.0" diff --git a/src/p5xr/core/p5xrViewer.js b/src/p5xr/core/p5xrViewer.js index 136f3a8..436229c 100644 --- a/src/p5xr/core/p5xrViewer.js +++ b/src/p5xr/core/p5xrViewer.js @@ -28,7 +28,7 @@ class p5xrViewer { */ set pose(newPose) { this._pose = newPose; - this.poseMatrix.set(newPose.poseModelMatrix); + this.poseMatrix.set(newPose.transform.matrix); } get pose() { diff --git a/src/p5xr/p5ar/p5ar.js b/src/p5xr/p5ar/p5ar.js index be70d56..389eefa 100644 --- a/src/p5xr/p5ar/p5ar.js +++ b/src/p5xr/p5ar/p5ar.js @@ -132,7 +132,7 @@ export default class p5ar extends p5xr { * @ignore */ __onRequestSession() { - this.gl = this.canvas.getContext('webgl', { + this.gl = this.canvas.getContext(p5.instance.webglVersion, { xrCompatible: true, }); this.gl.makeXRCompatible().then(() => { diff --git a/src/p5xr/p5vr/p5vr.js b/src/p5xr/p5vr/p5vr.js index 83b5138..39bc1cb 100644 --- a/src/p5xr/p5vr/p5vr.js +++ b/src/p5xr/p5vr/p5vr.js @@ -115,7 +115,7 @@ export default class p5vr extends p5xr { p5.instance._renderer._curCamera.cameraType = 'custom'; const refSpaceRequest = this.isImmersive ? 'local' : 'viewer'; - this.gl = this.canvas.getContext('webgl'); + this.gl = this.canvas.getContext(p5.instance.webglVersion); this.gl .makeXRCompatible() .then(() => { diff --git a/tests/unit/p5xr/core/raycasting.js b/tests/unit/p5xr/core/raycasting.js index eb8c7b3..d023c33 100644 --- a/tests/unit/p5xr/core/raycasting.js +++ b/tests/unit/p5xr/core/raycasting.js @@ -1,3 +1,11 @@ +function approxEqual(arr1, arr2, epsilon = 0.0001) { + if (arr1.length !== arr2.length) return false; + for (let i = 0; i < arr1.length; i++) { + if (Math.abs(arr1[i] - arr2[i]) > epsilon) return false; + } + return true; +} + suite('raycasting', function() { let myp5; @@ -53,7 +61,8 @@ suite('raycasting', function() { let uMVMatrix = [0.9991118311882019, 0.010332025587558746, 0.04085145890712738, -0, -0.032737694680690765, 0.8007082939147949, 0.5981592535972595, 0, -0.026529904454946518, -0.5989654064178467, 0.8003354072570801, 0, -43.66838073730469, 568.6730346679688, -75.510009765625, 1]; myp5._renderer.uMVMatrix.set([...uMVMatrix]); let intersects = intersectsSphere(70); - assert.deepEqual(myp5._renderer.uMVMatrix.mat4, uMVMatrix); + + assert.isTrue(approxEqual(myp5._renderer.uMVMatrix.mat4, uMVMatrix), 'uMVMatrix is approximately equal'); }); }); @@ -100,7 +109,7 @@ suite('raycasting', function() { let uMVMatrix = [0.9991118311882019, 0.010332025587558746, 0.04085145890712738, -0, -0.032737694680690765, 0.8007082939147949, 0.5981592535972595, 0, -0.026529904454946518, -0.5989654064178467, 0.8003354072570801, 0, -43.66838073730469, 568.6730346679688, -75.510009765625, 1]; myp5._renderer.uMVMatrix.set([...uMVMatrix]); let intersects = intersectsBox(70); - assert.deepEqual(myp5._renderer.uMVMatrix.mat4, uMVMatrix); + assert.isTrue(approxEqual(myp5._renderer.uMVMatrix.mat4, uMVMatrix), 'uMVMatrix is approximately equal'); }); }); });