From 7a736bb251b694dfecd3fa1d16cf90351b97d29c Mon Sep 17 00:00:00 2001
From: joni <johnfshaughnessy@gmail.com>
Date: Fri, 6 Jul 2018 10:36:20 -0700
Subject: [PATCH] Respond to PR feedback

---
 src/components/auto-box-collider.js           |  5 ++-
 .../auto-scale-cannon-physics-body.js         |  8 +++--
 src/components/image-plus.js                  |  6 +---
 src/components/input-configurator.js          |  2 +-
 .../remove-networked-object-button.js         |  3 --
 src/components/sticky-object.js               | 33 ++++++++++-------
 src/hub.html                                  | 35 +------------------
 src/vendor/GLTFLoader.js                      |  1 +
 8 files changed, 34 insertions(+), 59 deletions(-)

diff --git a/src/components/auto-box-collider.js b/src/components/auto-box-collider.js
index 2d3d2f53b..220ad92ed 100644
--- a/src/components/auto-box-collider.js
+++ b/src/components/auto-box-collider.js
@@ -9,8 +9,11 @@ AFRAME.registerComponent("auto-box-collider", {
     this.el.addEventListener("model-loaded", this.onLoaded);
   },
 
-  onLoaded() {
+  remove() {
     this.el.removeEventListener("model-loaded", this.onLoaded);
+  },
+
+  onLoaded() {
     const rotation = this.el.object3D.rotation.clone();
     this.el.object3D.rotation.set(0, 0, 0);
     const { min, max } = new THREE.Box3().setFromObject(this.el.object3DMap.mesh);
diff --git a/src/components/auto-scale-cannon-physics-body.js b/src/components/auto-scale-cannon-physics-body.js
index e3ab60400..1633dffef 100644
--- a/src/components/auto-scale-cannon-physics-body.js
+++ b/src/components/auto-scale-cannon-physics-body.js
@@ -4,6 +4,10 @@ function almostEquals(epsilon, u, v) {
 
 AFRAME.registerComponent("auto-scale-cannon-physics-body", {
   dependencies: ["body"],
+  schema: {
+    equalityEpsilon: { default: 0.001 },
+    debounceDelay: { default: 100 }
+  },
 
   init() {
     this.body = this.el.components["body"];
@@ -14,9 +18,9 @@ AFRAME.registerComponent("auto-scale-cannon-physics-body", {
   tick(t) {
     const scale = this.el.object3D.scale;
     // Note: This only checks if the LOCAL scale of the object3D changes.
-    if (!almostEquals(0.001, scale, this.prevScale)) {
+    if (!almostEquals(this.data.equalityEpsilon, scale, this.prevScale)) {
       this.prevScale.copy(scale);
-      this.nextUpdateTime = t + 100;
+      this.nextUpdateTime = t + this.data.debounceDelay;
     }
 
     if (this.nextUpdateTime > 0 && t > this.nextUpdateTime) {
diff --git a/src/components/image-plus.js b/src/components/image-plus.js
index c168789bb..744020534 100644
--- a/src/components/image-plus.js
+++ b/src/components/image-plus.js
@@ -118,7 +118,6 @@ AFRAME.registerComponent("image-plus", {
     const cacheItem = textureCache.get(url);
     cacheItem.count--;
     if (cacheItem.count <= 0) {
-      console.log("removing from cache");
       // Unload the video element to prevent it from continuing to play in the background
       if (texture.image instanceof HTMLVideoElement) {
         const video = texture.image;
@@ -179,7 +178,7 @@ AFRAME.registerComponent("image-plus", {
 
       const texture = new THREE.VideoTexture(videoEl);
       texture.minFilter = THREE.LinearFilter;
-      videoEl.addEventListener("loadedmetadata", () => resolve(texture));
+      videoEl.addEventListener("loadedmetadata", () => resolve(texture), { once: true });
       videoEl.onerror = reject;
 
       // If iOS and video is HLS, do some hacks.
@@ -225,13 +224,10 @@ AFRAME.registerComponent("image-plus", {
         if (url === "error") {
           texture = errorTexture;
         } else if (contentType === "image/gif") {
-          console.log("load gif", contentType);
           texture = await this.loadGIF(url);
         } else if (contentType.startsWith("image/")) {
-          console.log("load image", contentType);
           texture = await this.loadImage(url);
         } else if (contentType.startsWith("video")) {
-          console.log("load video", contentType);
           texture = await this.loadVideo(url);
         } else {
           throw new Error(`Unknown centent type: ${contentType}`);
diff --git a/src/components/input-configurator.js b/src/components/input-configurator.js
index 1609b20c7..df36b38d8 100644
--- a/src/components/input-configurator.js
+++ b/src/components/input-configurator.js
@@ -69,7 +69,7 @@ AFRAME.registerComponent("input-configurator", {
     this.eventHandlers = [];
     this.actionEventHandler = null;
     if (this.lookOnMobile) {
-      this.lookOnMobile.el.removeComponent("look-on-mobile");
+      this.lookOnMobile.el.removeAttribute("look-on-mobile");
       this.lookOnMobile = null;
     }
     this.cursorRequiresManagement = false;
diff --git a/src/components/remove-networked-object-button.js b/src/components/remove-networked-object-button.js
index ff9034357..39ec27b75 100644
--- a/src/components/remove-networked-object-button.js
+++ b/src/components/remove-networked-object-button.js
@@ -1,9 +1,6 @@
 AFRAME.registerComponent("remove-networked-object-button", {
   init() {
     this.onClick = () => {
-      // const texture = this.targetEl.getObject3D("mesh").material.map;
-      // console.log(texture);
-      // texture.image.src = "";
       this.targetEl.parentNode.removeChild(this.targetEl);
     };
     NAF.utils.getNetworkedEntity(this.el).then(networkedEl => {
diff --git a/src/components/sticky-object.js b/src/components/sticky-object.js
index 31f84a3be..d41577907 100644
--- a/src/components/sticky-object.js
+++ b/src/components/sticky-object.js
@@ -79,20 +79,27 @@ AFRAME.registerComponent("sticky-object-zone", {
     this.bootImpulse = new CANNON.Vec3();
     this.bootImpulse.copy(dir);
 
-    this.el.addEventListener("collisions", e => {
-      e.detail.els.forEach(el => {
-        const stickyObject = el.components["sticky-object"];
-        if (!stickyObject) return;
-        this._setStuckObject(stickyObject);
-      });
-      if (this.stuckObject) {
-        e.detail.clearedEls.forEach(el => {
-          if (this.stuckObject && this.stuckObject.el === el) {
-            this._unstickObject();
-          }
-        });
-      }
+    this._onCollisions = this._onCollisions.bind(this);
+    this.el.addEventListener("collisions", this._onCollisions);
+  },
+
+  remove() {
+    this.el.removeEventListener("collisions", this._onCollisions);
+  },
+
+  _onCollisions(e) {
+    e.detail.els.forEach(el => {
+      const stickyObject = el.components["sticky-object"];
+      if (!stickyObject) return;
+      this._setStuckObject(stickyObject);
     });
+    if (this.stuckObject) {
+      e.detail.clearedEls.forEach(el => {
+        if (this.stuckObject && this.stuckObject.el === el) {
+          this._unstickObject();
+        }
+      });
+    }
   },
 
   _setStuckObject(stickyObject) {
diff --git a/src/hub.html b/src/hub.html
index 4c9f692a5..f71396377 100644
--- a/src/hub.html
+++ b/src/hub.html
@@ -33,7 +33,7 @@
     <a-scene
         renderer="antialias: true"
         networked-scene="adapter: janus; audio: true; debug: true; connectOnLoad: false;"
-        physics="gravity: -6; debug: true;"
+        physics="gravity: -6;"
         mute-mic="eventSrc: a-scene; toggleEvents: action_mute"
         freeze-controller="toggleEvent: action_freeze"
         personal-space-bubble="debug: false;"
@@ -409,39 +409,6 @@
             static-body="shape: none;"
         ></a-entity>
 
-        <a-entity
-            geometry="primitive: box;"
-            static-body="shape: box;"
-            collision-filter="collisionForces: false;"
-            physics-collider
-            sticky-object-zone
-            position="1.25 2 -5.9"
-            visible="false"
-            scale="1 1 0.5"
-        >
-        </a-entity>
-        <a-entity
-            geometry="primitive: box;"
-            static-body="shape: box;"
-            collision-filter="collisionForces: false;"
-            physics-collider
-            sticky-object-zone
-            position="0 2 -5.9"
-            visible="false"
-            scale="1 1 0.5"
-        >
-        </a-entity>
-        <a-entity
-            geometry="primitive: box;"
-            static-body="shape: box;"
-            collision-filter="collisionForces: false;"
-            physics-collider
-            sticky-object-zone
-            position="-1.25 2 -5.9"
-            visible="false"
-            scale="1 1 0.5"
-        >
-        </a-entity>
     </a-scene>
 
     <div id="ui-root"></div>
diff --git a/src/vendor/GLTFLoader.js b/src/vendor/GLTFLoader.js
index 906bb9465..754ae5d94 100644
--- a/src/vendor/GLTFLoader.js
+++ b/src/vendor/GLTFLoader.js
@@ -7,6 +7,7 @@
  * @author Tony Parisi / http://www.tonyparisi.com/
  * @author Takahiro / https://github.com/takahirox
  * @author Don McCurdy / https://www.donmccurdy.com
+ * @author netpro2k / https://github.com/netpro2k
  */
 
  import { resolveFarsparkUrl } from "../utils/media-utils"
-- 
GitLab