From 73659479abd2f96f34f852d90de2597a39634275 Mon Sep 17 00:00:00 2001 From: Robert Long <robert@robertlong.me> Date: Tue, 26 Sep 2017 18:48:43 -0700 Subject: [PATCH] Add rig-selector. --- public/index.html | 47 +++++++++++++++++++++++---- src/components/rig-selector.js | 59 ++++++++++++++++++++++++++++++++++ src/index.js | 3 +- 3 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 src/components/rig-selector.js diff --git a/public/index.html b/public/index.html index df4d62415..25bcec865 100644 --- a/public/index.html +++ b/public/index.html @@ -24,14 +24,49 @@ <script id="hand-template" type="text/html"> <a-box scale="0.1 0.1 0.1"></a-box> </script> - </a-assets> - <a-entity id="player" networked="template:#player-template;showLocalTemplate:false;" wasd-controls> - <a-entity camera="userHeight: 1.6" look-controls networked="template:#head-template;showLocalTemplate:false;"></a-entity> + <script id="vive-rig" type="text/html"> + <a-entity id="player" networked="template:#player-template;showLocalTemplate:false;" wasd-controls> + <a-entity camera="userHeight: 1.6" look-controls networked="template:#head-template;showLocalTemplate:false;"></a-entity> + + <a-entity hand-controls="left" teleport-controls="cameraRig: #player" networked="template:#hand-template;showLocalTemplate:true;"></a-entity> + <a-entity hand-controls="right" teleport-controls="cameraRig: #player" networked="template:#hand-template;showLocalTemplate:true;"></a-entity> + </a-entity> + </script> + + <script id="oculus-rig" type="text/html"> + <a-entity id="player" networked="template:#player-template;showLocalTemplate:false;" wasd-controls> + <a-entity camera="userHeight: 1.6" look-controls networked="template:#head-template;showLocalTemplate:false;"></a-entity> + + <a-entity oculus-touch-controls="left" teleport-controls="cameraRig:#player;button:trigger;" networked="template:#hand-template;showLocalTemplate:true;"></a-entity> + <a-entity oculus-touch-controls="right" teleport-controls="cameraRig:#player;button:trigger;" networked="template:#hand-template;showLocalTemplate:true;"></a-entity> + </a-entity> + </script> + + <script id="daydream-rig" type="text/html"> + <a-entity id="player" networked="template:#player-template;showLocalTemplate:false;" wasd-controls> + <a-entity camera="userHeight: 1.6" look-controls networked="template:#head-template;showLocalTemplate:false;"></a-entity> + + <a-entity daydream-controls networked="template:#hand-template;showLocalTemplate:true;"></a-entity> + </a-entity> + </script> + + <script id="gearvr-rig" type="text/html"> + <a-entity id="player" networked="template:#player-template;showLocalTemplate:false;" wasd-controls> + <a-entity camera="userHeight: 1.6" look-controls networked="template:#head-template;showLocalTemplate:false;"></a-entity> + + <a-entity gearvr-controls networked="template:#hand-template;showLocalTemplate:true;"></a-entity> + </a-entity> + </script> + + <script id="dolly-rig" type="text/html"> + <a-entity id="player" networked="template:#player-template;showLocalTemplate:false;" wasd-controls> + <a-entity camera="userHeight: 1.6" look-controls networked="template:#head-template;showLocalTemplate:false;"></a-entity> + </a-entity> + </script> + </a-assets> - <a-entity hand-controls="left" networked="template:#hand-template;showLocalTemplate:true;"></a-entity> - <a-entity hand-controls="right" networked="template:#hand-template;showLocalTemplate:true;"></a-entity> - </a-entity> + <a-entity rig-selector="vive:#vive-rig;oculus:oculus-rig;daydream:#daydream-rig;desktop:#dolly-rig;mobile:dolly-rig;"></a-entity> <a-plane src="#ground" color="#7BC8A4" height="100" width="100" rotation="-90 0 0"></a-plane> <a-sky color="#ECECEC"></a-sky> diff --git a/src/components/rig-selector.js b/src/components/rig-selector.js new file mode 100644 index 000000000..f27a7bba4 --- /dev/null +++ b/src/components/rig-selector.js @@ -0,0 +1,59 @@ +AFRAME.registerComponent("rig-selector", { + schema: { + vive: { default: "" }, + oculus: { default: "" }, + daydream: { default: "" }, + gearvr: { default: "" }, + mobile: { default: "" }, + desktop: { default: "" } + }, + init: function() { + var vrDevice = this.el.sceneEl.effect.getVRDisplay(); + var rigEl = document.createElement("a-entity"); + + if (vrDevice !== undefined) { + var displayName = vrDevice.displayName; + + if (displayName.indexOf("Oculus") !== -1) { + rigEl.setAttribute( + "template", + "src:" + this.data.oculus || this.data.desktop + ); + } else if (displayName.indexOf("OpenVR") !== -1) { + rigEl.setAttribute( + "template", + "src:" + this.data.vive || this.data.desktop + ); + } else if (displayName.indexOf("Daydream") !== -1) { + rigEl.setAttribute( + "template", + "src:" + this.data.daydream || this.data.mobile + ); + } else { + rigEl.setAttribute( + "template", + "src:" + this.data.desktop || this.data.mobile + ); + } + } else { + if (AFRAME.utils.device.isGearVR()) { + rigEl.setAttribute( + "template", + "src:" + this.data.gearvr || this.data.mobile + ); + } else if (AFRAME.utils.device.isMobile()) { + rigEl.setAttribute( + "template", + "src:" + this.data.mobile || this.data.desktop + ); + } else { + rigEl.setAttribute( + "template", + "src:" + this.data.desktop || this.data.mobile + ); + } + } + + this.el.appendChild(rigEl); + } +}); diff --git a/src/index.js b/src/index.js index 29c73e321..45c194af9 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,2 @@ require("networked-aframe"); - -console.log("test2"); +require("./components/rig-selector"); -- GitLab