diff --git a/src/components/ik-controller.js b/src/components/ik-controller.js index 3fffb26668251905f25faf1876c175b12f7c21d7..23f2dbf799f59558fd261eaa615f1bd2d37a66d2 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 266e050353f979a6eb22f0e8190820470190ce4d..1f6d9b388813217b91982c45bb09da4d68c1a95e 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; } });