From 0b55dcfbeddd4d47deefc4b0aaad73d51a9929bc Mon Sep 17 00:00:00 2001
From: joni <johnfshaughnessy@gmail.com>
Date: Tue, 17 Jul 2018 17:43:36 -0700
Subject: [PATCH] Fix delete button

---
 .../position-at-box-shape-border.js           | 32 +++++++++++--------
 src/hub.html                                  |  4 +--
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/src/components/position-at-box-shape-border.js b/src/components/position-at-box-shape-border.js
index 59776bf6d..65b3d32d2 100644
--- a/src/components/position-at-box-shape-border.js
+++ b/src/components/position-at-box-shape-border.js
@@ -1,3 +1,5 @@
+import { getBox } from "../utils/auto-box-collider.js";
+
 const PI = Math.PI;
 const HALF_PI = PI / 2;
 const THREE_HALF_PI = 3 * PI / 2;
@@ -47,25 +49,34 @@ AFRAME.registerComponent("position-at-box-shape-border", {
     const targetPosition = new THREE.Vector3();
     const pointOnBoxFace = new THREE.Vector3();
     return function() {
-      if (!this.shape) {
-        this.shape = this.el.components["shape"];
-        if (!this.shape) return;
-      }
       if (!this.target) {
         this.target = this.el.querySelector(this.data.target).object3D;
         if (!this.target) return;
       }
-      const halfExtents = this.shape.data.halfExtents;
+      if (!this.halfExtents || this.mesh !== this.el.getObject3D("mesh") || this.shape !== this.el.components.shape) {
+        this.mesh = this.el.getObject3D("mesh"); //...
+        const box = getBox(this.el, this.mesh);
+        if (this.el.components.shape) {
+          this.shape = this.el.components.shape;
+          this.halfExtents = this.shape.data.halfExtents.clone();
+        } else {
+          this.halfExtents = box.min
+            .clone()
+            .negate()
+            .add(box.max)
+            .multiplyScalar(0.51 / this.el.object3D.scale.x);
+        }
+      }
       this.cam.getWorldPosition(camWorldPos);
 
       let minSquareDistance = Infinity;
       let targetDir = this.dirs[0].dir;
-      let targetHalfExtent = halfExtents[this.dirs[0].halfExtent];
+      let targetHalfExtent = this.halfExtents[this.dirs[0].halfExtent];
       let targetRotation = this.dirs[0].rotation;
 
       for (let i = 0; i < this.dirs.length; i++) {
         const dir = this.dirs[i].dir;
-        const halfExtent = halfExtents[this.dirs[i].halfExtent];
+        const halfExtent = this.halfExtents[this.dirs[i].halfExtent];
         pointOnBoxFace.copy(dir).multiplyScalar(halfExtent);
         this.el.object3D.localToWorld(pointOnBoxFace);
         const squareDistance = pointOnBoxFace.distanceToSquared(camWorldPos);
@@ -77,12 +88,7 @@ AFRAME.registerComponent("position-at-box-shape-border", {
         }
       }
 
-      this.target.position.copy(
-        targetPosition
-          .copy(targetDir)
-          .multiplyScalar(targetHalfExtent)
-          .add(this.shape.data.offset)
-      );
+      this.target.position.copy(targetPosition.copy(targetDir).multiplyScalar(targetHalfExtent));
       this.target.rotation.set(0, targetRotation, 0);
     };
   })()
diff --git a/src/hub.html b/src/hub.html
index 2c997842f..523b9dcb7 100644
--- a/src/hub.html
+++ b/src/hub.html
@@ -171,8 +171,8 @@
                     position-at-box-shape-border="target:.delete-button"
                     destroy-at-extreme-distances
                 >
-                    <a-entity class="delete-button" visible-while-frozen scale="0.08 0.08 0.08">
-                        <a-entity mixin="rounded-text-button" remove-object-button position="0 0 0"> </a-entity>
+                    <a-entity class="delete-button" visible-while-frozen scale="1.00 1.00 1.00">
+                        <a-entity mixin="rounded-text-button" remove-networked-object-button position="0 0 0"> </a-entity>
                         <a-entity text=" value:Delete; width:2.5; align:center;" text-raycast-hack position="0 0 0.01"></a-entity>
                     </a-entity>
                 </a-entity>
-- 
GitLab