From 26feca79864a3aa83f8682851d69c87dcc4990ad Mon Sep 17 00:00:00 2001 From: joni <johnfshaughnessy@gmail.com> Date: Tue, 26 Jun 2018 18:13:26 -0700 Subject: [PATCH] lint --- src/components/auto-box-collider.js | 2 +- src/components/position-at-box-border.js | 36 ++++++++++++------------ src/hub.html | 4 +-- src/react-components/ui-root.js | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/components/auto-box-collider.js b/src/components/auto-box-collider.js index e6a78c6b0..63ba09a22 100644 --- a/src/components/auto-box-collider.js +++ b/src/components/auto-box-collider.js @@ -15,7 +15,7 @@ AFRAME.registerComponent("auto-box-collider", { const rotation = this.el.getAttribute("rotation"); this.el.setAttribute("rotation", { x: 0, y: 0, z: 0 }); const { min, max } = new THREE.Box3().setFromObject(this.el.object3DMap.mesh); - let halfExtents = new THREE.Vector3() + const halfExtents = new THREE.Vector3() .addVectors(min.clone().negate(), max) .multiplyScalar(0.5 / this.el.object3D.scale.x); this.el.setAttribute("shape", { diff --git a/src/components/position-at-box-border.js b/src/components/position-at-box-border.js index 8485b496a..273bd1379 100644 --- a/src/components/position-at-box-border.js +++ b/src/components/position-at-box-border.js @@ -7,9 +7,6 @@ const left = new THREE.Vector3(-1, 0, 0); const back = new THREE.Vector3(0, 0, -1); const dirs = [left, right, forward, back]; const rotations = [THREE_PI_HALF, PI_HALF, 0, PI]; -function almostEquals(u, v, eps) { - return Math.abs(u.x - v.x) < eps && Math.abs(u.y - v.y) < eps && Math.abs(u.z - v.z) < eps; -} AFRAME.registerComponent("position-at-box-border", { schema: { @@ -36,29 +33,32 @@ AFRAME.registerComponent("position-at-box-border", { const halfExtentDirs = [halfExtents.x, halfExtents.x, halfExtents.z, halfExtents.z]; this.cam.getWorldPosition(this.camWorldPos); - let minDistance = Infinity; - let minDir = dirs[0]; - let minHalfExtentDir = halfExtentDirs[0]; - let minRotation = rotations[0]; + let minSquareDistance = Infinity; + const targetInfo = { + dir: dirs[0], + halfExtent: halfExtentDirs[0], + rotation: rotations[0] + }; + for (let i = 0; i < dirs.length; i++) { const dir = dirs[i]; - let dirOfObject = dir.clone().multiplyScalar(halfExtentDirs[i]); - this.el.object3D.localToWorld(dirOfObject); - const distanceSquared = dirOfObject.distanceToSquared(this.camWorldPos); - if (distanceSquared < minDistance) { - minDistance = distanceSquared; - minDir = dir; - minHalfExtentDir = halfExtentDirs[i]; - minRotation = rotations[i]; + const pointOnBoxFace = dir.clone().multiplyScalar(halfExtentDirs[i]); + this.el.object3D.localToWorld(pointOnBoxFace); + const squareDistance = pointOnBoxFace.distanceToSquared(this.camWorldPos); + if (squareDistance < minSquareDistance) { + minSquareDistance = squareDistance; + targetInfo.dir = dir; + targetInfo.halfExtent = halfExtentDirs[i]; + targetInfo.rotation = rotations[i]; } } this.target.position.copy( - minDir + targetInfo.dir .clone() - .multiplyScalar(minHalfExtentDir) + .multiplyScalar(targetInfo.halfExtent) .add(this.shape.data.offset) ); - this.target.rotation.set(0, minRotation, 0); + this.target.rotation.set(0, targetInfo.rotation, 0); } }); diff --git a/src/hub.html b/src/hub.html index 221240c6b..9ac6abc9d 100644 --- a/src/hub.html +++ b/src/hub.html @@ -183,10 +183,10 @@ hoverable sticky-object="autoLockOnRelease: true; autoLockOnLoad: true;" auto-box-collider - position-at-box-border="target:.deleteButton" + position-at-box-border="target:.delete-button" auto-scale-cannon-physics-body > - <a-entity class="deleteButton" visible-while-frozen scale="0.08 0.08 0.08"> + <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 text=" value:Delete; width:2.5; align:center;" text-raycast-hack position="0 0 0.01"></a-entity> </a-entity> diff --git a/src/react-components/ui-root.js b/src/react-components/ui-root.js index 5014d6af4..663f0ad1a 100644 --- a/src/react-components/ui-root.js +++ b/src/react-components/ui-root.js @@ -319,7 +319,7 @@ class UIRoot extends Component { mediaSource: "screen", // Work around BMO 1449832 by calculating the width. This will break for multi monitors if you share anything // other than your current monitor that has a different aspect ratio. - width: (screen.width / screen.height) * 720, + width: 720 * screen.width / screen.height, height: 720, frameRate: 30 } -- GitLab