From 455fc9794c68d9c7856064774658f1ccf9ebcb4b Mon Sep 17 00:00:00 2001 From: netpro2k <netpro2k@gmail.com> Date: Wed, 4 Apr 2018 13:06:13 -0700 Subject: [PATCH] Hack to handle controller hiding --- src/components/ik-controller.js | 7 ++++++- src/systems/personal-space-bubble.js | 15 ++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/components/ik-controller.js b/src/components/ik-controller.js index 3fffb2666..23f2dbf79 100644 --- a/src/components/ik-controller.js +++ b/src/components/ik-controller.js @@ -182,7 +182,12 @@ AFRAME.registerComponent("ik-controller", { const handMatrix = handObject3D.matrix; const controllerObject3D = controller.object3D; - handObject3D.visible = controllerObject3D.visible; + // TODO: This coupling with personal-space-invader is not ideal. + // There should be some intermediate thing managing multiple opinions about object visibility + const spaceInvader = hand.components["personal-space-invader"]; + const handHiddenByPersonalSpace = spaceInvader && spaceInvader.invading; + + handObject3D.visible = !handHiddenByPersonalSpace && controllerObject3D.visible; if (controllerObject3D.visible) { handMatrix.multiplyMatrices(this.invRootToChest, controllerObject3D.matrix); diff --git a/src/systems/personal-space-bubble.js b/src/systems/personal-space-bubble.js index 266e05035..1f6d9b388 100644 --- a/src/systems/personal-space-bubble.js +++ b/src/systems/personal-space-bubble.js @@ -49,7 +49,7 @@ AFRAME.registerSystem("personal-space-bubble", { for (let i = 0; i < this.invaders.length; i++) { this.invaders[i].el.object3D.updateMatrixWorld(true); - this.invaders[i].setVisibility(true); + this.invaders[i].setInvading(false); } // Loop through all of the space bubbles (usually one) @@ -69,7 +69,7 @@ AFRAME.registerSystem("personal-space-bubble", { const distanceSquared = bubblePos.distanceToSquared(invaderPos); const radius = bubbleRadius + invader.data.radius; if (distanceSquared < radius * radius) { - invader.setVisibility(false); + invader.setInvading(true); } } } @@ -120,8 +120,8 @@ AFRAME.registerComponent("personal-space-invader", { if (mesh) { this.targetMaterial = mesh.material; } - console.log("invader mesh", this.targetMesh); } + this.invading = false; }, update() { @@ -132,13 +132,14 @@ AFRAME.registerComponent("personal-space-invader", { this.el.sceneEl.systems["personal-space-bubble"].unregisterInvader(this); }, - setVisibility(visible) { + setInvading(invading) { if (this.targetMaterial) { - this.targetMaterial.opacity = visible ? 1 : 0.3; - this.targetMaterial.transparent = !visible; + this.targetMaterial.opacity = invading ? 0.3 : 1; + this.targetMaterial.transparent = invading; } else { - this.el.object3D.visible = visible; + this.el.object3D.visible = !invading; } + this.invading = invading; } }); -- GitLab