From 375bae1d39a365c31c9c1ced79f7177832d8555b Mon Sep 17 00:00:00 2001 From: Robert Long <robert@robertlong.me> Date: Mon, 30 Oct 2017 14:32:47 -0700 Subject: [PATCH] Added hand-controls-child-visibility component and network schema. --- public/index.html | 6 +++--- .../hand-controls-child-visibility.js | 21 +++++++++++++++++++ src/index.js | 6 ++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/components/hand-controls-child-visibility.js diff --git a/public/index.html b/public/index.html index 6bcedf148..3b58ef6ce 100644 --- a/public/index.html +++ b/public/index.html @@ -2,7 +2,7 @@ <head> <title>A-Frame Social VR Demo</title> - <script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script> + <script src="https://aframe.io/releases/0.7.0/aframe.js"></script> <script src="./app.bundle.js"></script> </head> @@ -58,7 +58,7 @@ <a-entity id="nametag" networked="template:#nametag-template;showLocalTemplate:false;"></a-entity> - <a-entity id="left-hand" hand-controls="left" axis-dpad="centerZone: 1" teleport-controls="cameraRig: #player-rig; teleportOrigin: #head; button: action_teleport_" + <a-entity id="left-hand" hand-controls="left" visible="false" hand-controls-child-visibility axis-dpad="centerZone: 1" teleport-controls="cameraRig: #player-rig; teleportOrigin: #head; button: action_teleport_" networked="template:#hand-template;showLocalTemplate:false;"> <a-entity id="watch" gltf-model="assets/hud/watch.gltf" position="0 0.0015 0.147" rotation="3.5 0 0"> <a-circle mute-state-indicator scale-audio-feedback="analyserSrc: #head; minScale: 0.035; maxScale: 0.08;" position="0 0.023 0" @@ -67,7 +67,7 @@ </a-entity> </a-entity> - <a-entity id="right-hand" hand-controls="right" axis-dpad teleport-controls="cameraRig: #player-rig; teleportOrigin: #head; hitEntity: #telepor-indicator; button: action_teleport_;" + <a-entity id="right-hand" hand-controls="right" visible="false" hand-controls-child-visibility axis-dpad teleport-controls="cameraRig: #player-rig; teleportOrigin: #head; hitEntity: #telepor-indicator; button: action_teleport_;" networked="template:#hand-template;showLocalTemplate:false;"></a-entity> </a-entity> diff --git a/src/components/hand-controls-child-visibility.js b/src/components/hand-controls-child-visibility.js new file mode 100644 index 000000000..75b79bb21 --- /dev/null +++ b/src/components/hand-controls-child-visibility.js @@ -0,0 +1,21 @@ +AFRAME.registerComponent("hand-controls-child-visibility", { + init() { + this.onControllerConnected = this.onControllerConnected.bind(this); + this.onControllerDisconnected = this.onControllerDisconnected.bind(this); + this.el.addEventListener("controllerconnected", this.onControllerConnected); + this.el.addEventListener( + "controllerdisconnected", + this.onControllerDisconnected + ); + + this.el.setAttribute("visible", false); + }, + + onControllerConnected() { + this.el.setAttribute("visible", true); + }, + + onControllerDisconnected() { + this.el.setAttribute("visible", false); + } +}); diff --git a/src/index.js b/src/index.js index fabb513a4..d230f3e3e 100644 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,7 @@ import "./components/audio-feedback"; import "./components/nametag-transform"; import "./components/avatar-customization"; import "./components/mute-state-indicator"; +import "./components/hand-controls-child-visibility"; import { generateName } from "./utils"; @@ -24,6 +25,11 @@ NAF.schemas.add({ ] }); +NAF.schemas.add({ + template: "#hand-template", + components: ["position", "rotation", "visible"] +}); + AFRAME.registerInputMappings({ default: { common: { -- GitLab