From 1d0a9946683231945ed0d5cb29f352026f376693 Mon Sep 17 00:00:00 2001
From: Brian Peiris <brianpeiris@gmail.com>
Date: Sat, 17 Feb 2018 00:56:36 +0000
Subject: [PATCH] AR tweaks

---
 src/components/character-controller.js | 12 +++++++++++-
 src/network-schemas.js                 |  4 ++++
 templates/room.hbs                     | 12 ++++++++----
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/components/character-controller.js b/src/components/character-controller.js
index bd0a6617a..3631c2a1e 100644
--- a/src/components/character-controller.js
+++ b/src/components/character-controller.js
@@ -1,3 +1,5 @@
+import queryString from "query-string";
+const qs = queryString.parse(location.search);
 const CLAMP_VELOCITY = 0.01;
 const MAX_DELTA = 0.2;
 
@@ -8,7 +10,8 @@ AFRAME.registerComponent("character-controller", {
     easing: { default: 10 },
     pivot: { type: "selector" },
     snapRotationDegrees: { default: THREE.Math.DEG2RAD * 45 },
-    rotationSpeed: { default: -3 }
+    rotationSpeed: { default: -3 },
+    arScale: { type: 'number' }
   },
 
   init: function() {
@@ -23,6 +26,8 @@ AFRAME.registerComponent("character-controller", {
   },
 
   update: function() {
+    const qsArScale = parseInt(qs.arScale, 10);
+    this.arScale = {x: qsArScale || this.data.arScale, y: qsArScale || this.data.arScale, z: qsArScale || this.data.arScale};
     this.leftRotationMatrix = new THREE.Matrix4().makeRotationY(
       this.data.snapRotationDegrees
     );
@@ -131,6 +136,11 @@ AFRAME.registerComponent("character-controller", {
 
       this.el.setAttribute("position", root.position);
 
+      // Apply AR scale
+      if (this.data.arScale && qs.arScale) {
+          this.el.setAttribute('scale', this.arScale);
+      }
+
       this.pendingSnapRotationMatrix.identity(); // Revert to identity
     };
   })(),
diff --git a/src/network-schemas.js b/src/network-schemas.js
index d93c552cb..ddb1538de 100644
--- a/src/network-schemas.js
+++ b/src/network-schemas.js
@@ -1,4 +1,8 @@
 function registerNetworkSchemas() {
+  NAF.schemas.add({
+    template: "#player-template",
+    components: ["position", 'rotation', 'scale']
+  });
   NAF.schemas.add({
     template: "#nametag-template",
     components: [
diff --git a/templates/room.hbs b/templates/room.hbs
index 8635f6656..7c45add06 100644
--- a/templates/room.hbs
+++ b/templates/room.hbs
@@ -60,6 +60,10 @@
             <img id="water-normal-map" src="{{asset "assets/waternormals.jpg"}}"></a-asset-item>
 
             <!-- Templates -->
+            <script id="player-template" type="text/html">
+                <a-entity></a-entity>
+            </script>
+
             <script id="head-template" type="text/html">
                 <a-entity
                     class="head"
@@ -122,10 +126,10 @@
         <!-- Player Rig -->
         <a-entity
             id="player-rig"
-            networked
+            networked="template: #player-template;"
             spawn-controller="radius: 4;"
             wasd-to-analog2d
-            character-controller="pivot: #head"
+            character-controller="pivot: #head; arScale: 4"
         >
             <a-entity
                 id="head"
@@ -139,6 +143,7 @@
             <a-entity
                 id="body"
                 body-controller="eyeNeckOffset: 0 -0.11 0.09; neckHeight: 0.05"
+                xr="ar: false"
                 networked="template: #body-template;"
             ></a-entity>
             <a-entity
@@ -181,7 +186,6 @@
             id="meeting-space"
             cached-gltf-model="#meeting-space1-mesh"
             position="0 0 0"
-            xr="ar: false"
         ></a-entity>
 
         <a-entity
@@ -218,7 +222,7 @@
 
         <a-entity
             id="water"
-            water="normalMap:#water-normal-map"
+            water="forceMobile: true; normalMap:#water-normal-map"
             rotation="-90 0 0"
             position="0 -88.358 -332.424"
             xr="ar: false"
-- 
GitLab