Quellcode durchsuchen

fix avatar in gearvr

Nikolay Suslov vor 4 Jahren
Ursprung
Commit
8c0da4b096

+ 11 - 3
public/defaults/proxy/vwf.example.com/aframe/avatar.js

@@ -61,13 +61,19 @@ this.findWorldAvatarCostume = function () {
     return null
 } 
 
+this.updateYPositionForXR = function(height){
+
+    if(this.avatarNode) {
+            let position = goog.vec.Vec3.clone(this.avatarNode.position);
+            this.avatarNode.position = [position[0], height, position[2]]
+    }
+
+}
+
 this.createAvatarBody = function (nodeDef, modelSrc) {
 
     var userHeight = -1.6;
 
-    // if (AFRAME.utils.device.isGearVR()) {
-    //     userHeight = 0
-    // }
 
     let myColor = "white"; //this.getRandomColor();
     let myBodyDef = this.simpleBodyDef;
@@ -389,6 +395,8 @@ this.changeCostume = function(val, restore){
 
 this.resetAvatar = function(){
 
+    //TODO: add XR check
+
     if (this.avatarNode) {
         //myNameValue = this.avatarNode.children.myName.properties.value;
         this.children.delete(this.avatarNode);

+ 3 - 0
public/defaults/proxy/vwf.example.com/aframe/avatar.vwf.yaml

@@ -27,6 +27,9 @@ methods:
         parameters:
             - nodeDef
             - modelSrc
+    updateYPositionForXR:
+        parameters:
+            - height    
     followAvatarControl:
         parameters:
             - position

+ 11 - 1
public/vwf/model/aframe/addon/aframe-components.js

@@ -17,8 +17,14 @@ AFRAME.registerComponent('scene-utils', {
 
             //vwf_view.kernel.callMethod(vwf.application(), "enterVR");
             let avatarEl = document.querySelector('#avatarControlParent');
+            let avatarID = 'avatar-' + vwf_view.kernel.moniker();
             if (AFRAME.utils.device.isMobileVR()) {
 
+                 vwf_view.kernel.callMethod(avatarID, "updateYPositionForXR", [0.0]);
+                //avatarEl.setAttribute('position', '0 1.6 0');
+                // if (AFRAME.utils.device.isGearVR()){  
+                // }
+
             } else if (AFRAME.utils.device.isMobile()) {
                 avatarEl.setAttribute('position', '0 0 0')
             } else {
@@ -35,9 +41,13 @@ AFRAME.registerComponent('scene-utils', {
 
             //vwf_view.kernel.callMethod(vwf.application(), "exitVR");
             let avatarEl = document.querySelector('#avatarControlParent');
-
+            let avatarID = 'avatar-' + vwf_view.kernel.moniker();
+            
             if (AFRAME.utils.device.isMobileVR()) {
                 //avatarEl.setAttribute('position', '0 0 0');
+
+                vwf_view.kernel.callMethod(avatarID, "updateYPositionForXR", [-1.6]);
+
             } else if (AFRAME.utils.device.isMobile()) {
                 avatarEl.setAttribute('position', '0 1.6 0');
             } else {

+ 7 - 3
public/vwf/view/aframe.js

@@ -53,6 +53,8 @@ define(["module", "vwf/view"], function (module, view) {
             this.gearvr = options.gearvr !== undefined ? options.gearvr : false;
             this.wmrright = options.wmrright !== undefined ? options.wmrright : false;
             this.wmrleft = options.wmrleft !== undefined ? options.wmrleft : false;
+
+            this.xrType = undefined;
         },
 
         createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
@@ -80,13 +82,11 @@ define(["module", "vwf/view"], function (module, view) {
 
 
                 prepairAvatar.then(res => {
-                    // console.log(res);
-                    createAvatar.call(self, childID);                  
-                    postLoadAction.call(self, childID);
 
                     if (this.gearvr == true) {
                         console.log("CREATE GEARVR HERE!!");
                         if (AFRAME.utils.device.isMobileVR()) {
+                            this.xrType = 'mobileVR';
                             let nodeName = 'gearvr-' + self.kernel.moniker();
                             createGearVRControls();
                             createGearVRController.call(self, childID, nodeName);
@@ -116,6 +116,10 @@ define(["module", "vwf/view"], function (module, view) {
                         }
                     }
 
+                     // console.log(res);
+                     createAvatar.call(self, childID);                  
+                     postLoadAction.call(self, childID);
+
                 })
                 // this.state.appInitialized  = true;
 

+ 1 - 0
public/vwf/view/editor-new.js

@@ -621,6 +621,7 @@ define([
                                             "label": "Reset Avatar",
                                             "onclick": function (e) {
                                                 let avatarID = 'avatar-' + self.kernel.moniker();
+                                                //TODO: add XR check
                                                 vwf_view.kernel.callMethod(avatarID, "resetAvatar", []);
                                             }
                                         }