From c61b24aab7a749a73f0591bc78232f98d31e7d19 Mon Sep 17 00:00:00 2001 From: Marshall Quander <marshall@quander.me> Date: Tue, 26 Jun 2018 15:28:04 -0700 Subject: [PATCH] Update Hubs to new NAF --- src/network-schemas.js | 38 ++++++++++++++++++++++---------------- yarn.lock | 15 ++++++++++----- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/network-schemas.js b/src/network-schemas.js index 04275d491..ca4d0f401 100644 --- a/src/network-schemas.js +++ b/src/network-schemas.js @@ -1,10 +1,16 @@ function registerNetworkSchemas() { - const positionRequiresUpdate = (oldData, newData) => { - return !NAF.utils.almostEqualVec3(oldData, newData, 0.001); - }; - - const rotationRequiresUpdate = (oldData, newData) => { - return !NAF.utils.almostEqualVec3(oldData, newData, 0.5); + const vectorRequiresUpdate = epsilon => { + let prev = null; + return curr => { + if (prev === null) { + prev = new THREE.Vector3(curr.x, curr.y, curr.z); + return true; + } else if (!NAF.utils.almostEqualVec3(prev, curr, epsilon)) { + prev.copy(curr); + return true; + } + return false; + }; }; NAF.schemas.add({ @@ -12,11 +18,11 @@ function registerNetworkSchemas() { components: [ { component: "position", - requiresNetworkUpdate: positionRequiresUpdate + requiresNetworkUpdate: vectorRequiresUpdate(0.001) }, { component: "rotation", - requiresNetworkUpdate: rotationRequiresUpdate + requiresNetworkUpdate: vectorRequiresUpdate(0.5) }, "scale", "player-info", @@ -24,22 +30,22 @@ function registerNetworkSchemas() { { selector: ".camera", component: "position", - requiresNetworkUpdate: positionRequiresUpdate + requiresNetworkUpdate: vectorRequiresUpdate(0.001) }, { selector: ".camera", component: "rotation", - requiresNetworkUpdate: rotationRequiresUpdate + requiresNetworkUpdate: vectorRequiresUpdate(0.5) }, { selector: ".left-controller", component: "position", - requiresNetworkUpdate: positionRequiresUpdate + requiresNetworkUpdate: vectorRequiresUpdate(0.001) }, { selector: ".left-controller", component: "rotation", - requiresNetworkUpdate: rotationRequiresUpdate + requiresNetworkUpdate: vectorRequiresUpdate(0.5) }, { selector: ".left-controller", @@ -48,12 +54,12 @@ function registerNetworkSchemas() { { selector: ".right-controller", component: "position", - requiresNetworkUpdate: positionRequiresUpdate + requiresNetworkUpdate: vectorRequiresUpdate(0.001) }, { selector: ".right-controller", component: "rotation", - requiresNetworkUpdate: rotationRequiresUpdate + requiresNetworkUpdate: vectorRequiresUpdate(0.5) }, { selector: ".right-controller", @@ -80,11 +86,11 @@ function registerNetworkSchemas() { components: [ { component: "position", - requiresNetworkUpdate: positionRequiresUpdate + requiresNetworkUpdate: vectorRequiresUpdate(0.001) }, { component: "rotation", - requiresNetworkUpdate: rotationRequiresUpdate + requiresNetworkUpdate: vectorRequiresUpdate(0.5) }, "scale" ] diff --git a/yarn.lock b/yarn.lock index 589589dc6..22663266a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1643,9 +1643,9 @@ buffer@^5.0.2: base64-js "^1.0.2" ieee754 "^1.1.4" -buffered-interpolation@^0.2.3: - version "0.2.3" - resolved "https://registry.yarnpkg.com/buffered-interpolation/-/buffered-interpolation-0.2.3.tgz#6e723d44c4f4aa76704fc470654174e279591c31" +buffered-interpolation@^0.2.4: + version "0.2.4" + resolved "https://registry.yarnpkg.com/buffered-interpolation/-/buffered-interpolation-0.2.4.tgz#74210ccb57855e611d1dbb97b4689a3585caa4af" builtin-modules@^1.0.0: version "1.1.1" @@ -3277,6 +3277,10 @@ fast-deep-equal@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz#c053477817c86b51daa853c81e059b733d023614" +fast-deep-equal@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" + fast-diff@^1.1.1: version "1.1.2" resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.1.2.tgz#4b62c42b8e03de3f848460b639079920695d0154" @@ -5515,11 +5519,12 @@ neo-async@^2.5.0: "networked-aframe@https://github.com/mozillareality/networked-aframe#mr-social-client/master": version "0.6.1" - resolved "https://github.com/mozillareality/networked-aframe#7b88e49e855b60e376886abe23ea311b27acdffe" + resolved "https://github.com/mozillareality/networked-aframe#06236f794f83cfebdc4ea9f3a9e8a5804f5bdcf9" dependencies: - buffered-interpolation "^0.2.3" + buffered-interpolation "^0.2.4" easyrtc "1.1.0" express "^4.10.7" + fast-deep-equal "^2.0.1" serve-static "^1.8.0" socket.io "^1.4.5" socket.io-client "^1.4.5" -- GitLab