Browse Source

avatar fixes

Nikolay Suslov 4 years ago
parent
commit
0cd842fd71

+ 40 - 14
public/defaults/proxy/vwf.example.com/aframe/avatar.js

@@ -37,6 +37,7 @@ this.modelBodyDef = {
 }
 
 this.findWorldAvatarCostume = function () {
+    
     let scene = this.getScene();
     let def = scene.defaultAvatarCostume;
 
@@ -72,12 +73,16 @@ this.createAvatarBody = function (nodeDef, modelSrc) {
     let myBodyDef = this.simpleBodyDef;
     //let myHandDef = this.simpleVrControllerDef;
 
+    if(!this.displayName)
+        this.displayName = 'Avatar ' + this.random().toString(36).substr(2, 9);
+
     myBodyDef.children.material.properties.color = myColor;
 
     var defaultNode = {
         "extends": "http://vwf.example.com/aframe/aentity.vwf",
         "properties": {
-            "position": [0, userHeight, 0] //-userHeight
+            "position": [0, userHeight, 0], //-userHeight
+            "meta": "avatarCostume"
         },
         "methods": {
             "randomize":{
@@ -243,18 +248,18 @@ this.createAvatarBody = function (nodeDef, modelSrc) {
    if (nodeDef){
     newNode = Object.assign({}, nodeDef);
     newNode.properties.position = [0, userHeight, 0];
-    newNode.children.myName.properties.value = this.displayName;
+    //newNode.children.myName.properties.value = this.displayName;
    //newNode = Object.assign(defaultNode, nodeDef);
 }
 
     //2. check for default avatar costume in world...
-    let defaultWorldCostume = this.findWorldAvatarCostume();
-    if(defaultWorldCostume) {
-        newNode = Object.assign({}, defaultWorldCostume);
-        newNode.properties.visible = true;
-        newNode.properties.position = [0, userHeight, 0];
-        newNode.children.myName.properties.value = this.displayName;
-    }
+    // let defaultWorldCostume = this.findWorldAvatarCostume();
+    // if(defaultWorldCostume) {
+    //     newNode = Object.assign({}, defaultWorldCostume);
+    //     newNode.properties.visible = true;
+    //     newNode.properties.position = [0, userHeight, 0];
+    //     newNode.children.myName.properties.value = this.displayName;
+    // }
     
 
      //3. check for model...
@@ -294,7 +299,9 @@ this.createAvatarBody = function (nodeDef, modelSrc) {
 
     this.children.create("avatarNode", newNode, function(child){
 
-       child.randomize();
+        if (!nodeDef) {
+          child.randomize();
+        }
 
     });
 
@@ -359,11 +366,14 @@ this.setUserAvatar = function(aName){
 
 }
 
-this.changeCostume = function(val){
+this.changeCostume = function(val, restore){
 
     let userHeight = -1.6;
 
+    var myNameValue = this.displayName;
+
     if (this.avatarNode) {
+        myNameValue = this.avatarNode.children.myName.properties.value;
         this.children.delete(this.avatarNode);
         //this.children.delete(this.interpolation);
     }
@@ -371,25 +381,41 @@ this.changeCostume = function(val){
     newNode.properties.position = [0, userHeight, 0];
     newNode.properties.visible = true;
     newNode.properties.meta = "avatarCostume";
-    newNode.children.myName.properties.value = this.displayName;
+    if(!restore)
+        newNode.children.myName.properties.value = myNameValue;
     this.children.create("avatarNode", newNode);
 
 }
 
+this.resetAvatar = function(){
+
+    if (this.avatarNode) {
+        //myNameValue = this.avatarNode.children.myName.properties.value;
+        this.children.delete(this.avatarNode);
+        this.children.delete(this.interpolation);
+    }
+
+    this.createAvatarBody();
+
+}
+
 this.createSimpleAvatar = function(){
        if (this.avatarNode.myBody) {
         this.avatarNode.children.delete(this.avatarNode.myBody);
+       }
+
         var myColor = this.getRandomColor();
         if (this.avatarNode.myHead){
             myColor = this.avatarNode.myHead.visual.material.color;
         }
+
         let myBodyDef = this.simpleBodyDef;
         myBodyDef.children.material.properties.color = myColor;
 
         this.avatarNode.children.create("myBody", myBodyDef);
         this.avatarNode.myHead.visual.properties.visible = true;
 
-       }
+       
 }
 
 this.createAvatarFromGLTF = function(modelSrc){
@@ -497,4 +523,4 @@ this.setMyName = function(val){
 
 this.randomizeAvatar = function() {
     this.avatarNode.randomize();
-}
+}

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

@@ -19,6 +19,7 @@ methods:
         parameters:
             - bool
     createSimpleAvatar:
+    resetAvatar:
     createAvatarFromGLTF:
         parameters:
             - modelSrc
@@ -60,5 +61,6 @@ methods:
     changeCostume:
          parameters:
             - val
+            - restore
 scripts:
 - source: "http://vwf.example.com/aframe/avatar.js"

+ 8 - 2
public/vwf/view/aframe.js

@@ -926,7 +926,7 @@ define(["module", "vwf/view"], function (module, view) {
                "properties": {
                    "localUrl": '',
                    "remoteUrl": '',
-                   "displayName": 'Avatar ' + randId(),
+                  // "displayName": 'Avatar ' + randId(),
                    "sharing": { audio: true, video: true },
                    "selectMode": false,
                    "position": [0, 1.6, 0]
@@ -955,7 +955,13 @@ define(["module", "vwf/view"], function (module, view) {
                                    var myNode = null;
                                    if (res) {
                                        //myNode = JSON.parse(res.avatarNode);
-                                       myNode = res;
+
+                                       var myNode = res;
+
+                                       if (_app.helpers.testJSON(res)){
+                                           myNode = JSON.parse(res);
+                                       }  
+
                                        vwf_view.kernel.callMethod(avatarName, "createAvatarBody", [myNode, null]);
                                    } else {
                                        vwf_view.kernel.callMethod(avatarName, "createAvatarBody", []);

+ 16 - 2
public/vwf/view/editor-new.js

@@ -474,8 +474,13 @@ define([
                         let nodeID = 'avatar-' + self.kernel.moniker();
                         _LCSUSER.get('profile').get('avatarNode').once(res => {
                             if (res) {
-                                //myNode = JSON.parse(res.avatarNode);
-                                vwf_view.kernel.callMethod(nodeID, "changeCostume", [res]);
+                                var myNode = res;
+
+                                if (_app.helpers.testJSON(res)){
+                                    myNode = JSON.parse(res);
+                                }  
+
+                                vwf_view.kernel.callMethod(nodeID, "changeCostume", [myNode, true]);
                             }
                         })
                     }
@@ -584,6 +589,15 @@ define([
                                                 //controlEl.setAttribute('visible', !vis);
                                             }
                                         }
+                                    ),
+                                    self.widgets.buttonStroked(
+                                        {
+                                            "label": "Reset Avatar",
+                                            "onclick": function (e) {
+                                                let avatarID = 'avatar-' + self.kernel.moniker();
+                                                vwf_view.kernel.callMethod(avatarID, "resetAvatar", []);
+                                            }
+                                        }
                                     )