Bläddra i källkod

fix save; allow avatar costumes in world

Nikolay Suslov 6 år sedan
förälder
incheckning
119e10677a

+ 9 - 40
public/app.js

@@ -1358,40 +1358,7 @@ class App {
     var timestamp = state["queue"].time;
     timestamp = Math.round(timestamp * 1000);
 
-    var objectIsTypedArray = function (candidate) {
-      var typedArrayTypes = [
-        Int8Array,
-        Uint8Array,
-        // Uint8ClampedArray,
-        Int16Array,
-        Uint16Array,
-        Int32Array,
-        Uint32Array,
-        Float32Array,
-        Float64Array
-      ];
-
-      var isTypedArray = false;
-
-      if (typeof candidate == "object" && candidate != null) {
-        typedArrayTypes.forEach(function (typedArrayType) {
-          isTypedArray = isTypedArray || candidate instanceof typedArrayType;
-        });
-      }
-
-      return isTypedArray;
-    };
-
-    var transitTransformation = function (object) {
-      return objectIsTypedArray(object) ?
-        Array.prototype.slice.call(object) : object;
-    };
-
-
-    let jsonValuePure = require("vwf/utility").transform(
-      state, transitTransformation
-    );
-
+    let jsonValuePure = _app.helpers.replaceFloatArraysInNodeDef(state);
     //remove all Ohm generated grammarsfrom state
 
     let jsonValue = _app.helpers.removeGrammarObj(jsonValuePure);
@@ -1428,11 +1395,17 @@ class App {
       "publish": true
     };
 
+    let rev =  JSON.stringify(saveRevision);
+    var docNameRev = 'savestate_' + rev + '/' + root + '/' + filename + '_vwf_json';
+    let stateWithRev = Object.assign({},stateForStore);
+    stateWithRev.revs = {[docNameRev]: stateForStore};
+    stateWithRev.revs[docNameRev].revision = saveRevision;
+
+
     //let objName = loadInfo[ 'save_name' ] +'/'+ "savestate_" + loadInfo[ 'save_revision' ];
     // "savestate_" + loadInfo[ 'save_revision' ] + '/' + loadInfo[ 'save_name' ] + '_vwf_json'
-
     var docName = 'savestate_/' + root + '/' + filename + '_vwf_json';
-    _LCSDB.user().get('documents').get(root).get(docName).put(stateForStore, function(res) {
+    _LCSDB.user().get('documents').get(root).get(docName).put(stateWithRev, function(res) {
 
       if (res) {
 
@@ -1480,10 +1453,6 @@ class App {
       }
     }, {wait: 200});
 
-    var docNameRev = 'savestate_' + saveRevision.toString() + '/' + root + '/' + filename + '_vwf_json';
-    _LCSDB.user().get('documents').get(root).get(docName).get('revs').get(docNameRev).put(stateForStore)
-      .path("revision").put(saveRevision);
-
 
     // Save Config Information
     var config = { "info": {}, "model": {}, "view": {} };

+ 109 - 0
public/defaults/assets/nodes/defaultAvatarCostume.yaml

@@ -0,0 +1,109 @@
+  defaultAvatarCostume:
+    extends: "http://vwf.example.com/aframe/aentity.vwf"
+    properties:
+      position: [0, -10, 0]
+      visible: false
+    methods:
+      randomize:
+        body: |
+                let myColor = this.getRandomColor();
+                this.myName.color = myColor;
+                this.myBody.material.color = myColor;
+                this.myHead.visual.material.color = myColor;
+                this.myHead.myCursor.vis.material.color = myColor;
+                this.myHead.myCursor.line.color = myColor;
+    children:
+      myBody:
+        extends: "http://vwf.example.com/aframe/abox.vwf"
+        properties:
+          position: [0, 0.66, 0.7]
+          height: 1.3
+          width: 0.65
+          depth: 0.1
+        children:
+          material:
+            extends: "http://vwf.example.com/aframe/aMaterialComponent.vwf"
+            type: "component"
+            properties:
+              color: "white"
+      myName:
+        extends: "http://vwf.example.com/aframe/atext.vwf"
+        properties:
+          color: "white"
+          value: "avatar"
+          side: "double"
+          rotation: [0, 180, 0]
+          position: [0.3, 2.05, 0.5]
+      myHead:
+        extends: "http://vwf.example.com/aframe/aentity.vwf"
+        properties:
+          position: [0, 1.6, 0.7]
+          visible: true
+        children:
+          interpolation:
+            extends: "http://vwf.example.com/aframe/interpolation-component.vwf"
+            type: "component"
+            properties:
+              enabled: true
+          visual:
+            extends: "http://vwf.example.com/aframe/abox.vwf"
+            properties:
+              height: 0.5
+              width: 0.5
+              depth: 0.1
+              visible: true
+            children:
+              material:
+                extends: "http://vwf.example.com/aframe/aMaterialComponent.vwf"
+                type: "component"
+                properties:
+                  color: "white"
+          myCamera:
+            extends: "http://vwf.example.com/aframe/acamera.vwf"
+            properties:
+              position: [0, 0, -0.7]
+              look-controls-enabled: false
+              wasd-controls-enabled: false
+              user-height: 0
+          myCursor:
+            extends: "http://vwf.example.com/aframe/aentity.vwf"
+            children:
+              vis:
+                extends: "http://vwf.example.com/aframe/abox.vwf"
+                properties:
+                  position: [0, 0, -3]
+                  height: 0.05
+                  width: 0.05
+                  depth: 0.01
+                  visible: true
+                children:
+                  material:
+                    extends: "http://vwf.example.com/aframe/aMaterialComponent.vwf"
+                    type: "component"
+                    properties:
+                      color: "white"            
+                  aabb-collider:
+                    extends: "http://vwf.example.com/aframe/aabb-collider-component.vwf"
+                    type: "component"
+                    properties:
+                      debug: false
+                      interval: 10
+                      objects: ".hit"
+              line:
+                extends: "http://vwf.example.com/aframe/lineComponent.vwf"
+                type: "component"
+                properties:
+                  start: "0 0 -1"
+                  end: "0 0 -3"
+                  color: "white"
+              myRayCaster:
+                extends: "http://vwf.example.com/aframe/aentity.vwf"
+                children:
+                  raycaster:
+                    extends: "http://vwf.example.com/aframe/raycasterComponent.vwf"
+                    type: "component"
+                    properties:
+                      recursive: false
+                      interval: 100
+                      far: 3
+                      objects: ".intersectable"

+ 16 - 0
public/defaults/proxy/vwf.example.com/aframe/aentity.js

@@ -3,6 +3,11 @@ this.getChildByName = function (name) {
     return nodes[0]
 }
 
+this.getScene =  function () {
+    let scene = this.find("/")[0];
+    return scene
+}
+
 this.setGizmoMode = function (mode) {
     if (this.gizmo) {
         this.gizmo.properties.mode = mode
@@ -41,6 +46,8 @@ this.translationFromValue = function (propertyValue) {
     else if (typeof propertyValue === 'string') {
         let val = AFRAME.utils.coordinates.parse(propertyValue);
         value = goog.vec.Vec3.createFromValues(val.x, val.y, val.z)
+    } else if (propertyValue.hasOwnProperty('0')) {
+        value = goog.vec.Vec3.createFromValues(propertyValue[0], propertyValue[1], propertyValue[2])
     }
 
     return value
@@ -188,4 +195,13 @@ this.changeVisual = function() {
 
 this.resetVisual = function() {
 
+}
+
+this.getRandomColor = function () {
+    var letters = '0123456789ABCDEF';
+    var color = '#';
+    for (var i = 0; i < 6; i++) {
+        color += letters[Math.floor(this.random() * 16)];
+    }
+    return color;
 }

+ 1 - 0
public/defaults/proxy/vwf.example.com/aframe/aentity.vwf.yaml

@@ -49,6 +49,7 @@ properties:
   stepping:
   stepTime:
   globalBeat:
+  getRandomColor:
 events:
   positionChanged:
   rotationChanged:

+ 59 - 21
public/defaults/proxy/vwf.example.com/aframe/avatar.js

@@ -1,7 +1,7 @@
 this.simpleBodyDef = {
     "extends": "http://vwf.example.com/aframe/abox.vwf",
     "properties": {
-        "position": "0 0.66 0.7",
+        "position": [0, 0.66, 0.7],
         "height": 1.3,
         "width": 0.65,
         "depth": 0.1,
@@ -21,8 +21,8 @@ this.modelBodyDef = {
     "extends": "http://vwf.example.com/aframe/agltfmodel.vwf",
     "properties": {
         "src": "#avatar",
-        "position": "0 0 0.8",
-        "rotation": "0 180 0"
+        "position": [0, 0, 0.8],
+        "rotation": [0, 180, 0]
     },
     "children": {
         "animation-mixer": {
@@ -36,6 +36,20 @@ this.modelBodyDef = {
     }
 }
 
+this.findWorldAvatarCostume = function () {
+
+    let scene = this.getScene();
+    let def = scene.defaultAvatarCostume
+
+    if (def) {
+        let defID = def.id;
+        let avatarNode = _app.helpers.getNodeDef(defID);
+        return avatarNode
+    }
+
+    return null
+} 
+
 
 this.createAvatarBody = function (nodeDef, modelSrc) {
 
@@ -45,7 +59,7 @@ this.createAvatarBody = function (nodeDef, modelSrc) {
     //     userHeight = 0
     // }
 
-    let myColor = this.getRandomColor();
+    let myColor = "white"; //this.getRandomColor();
     let myBodyDef = this.simpleBodyDef;
     //let myHandDef = this.simpleVrControllerDef;
 
@@ -56,6 +70,11 @@ this.createAvatarBody = function (nodeDef, modelSrc) {
         "properties": {
             "position": [0, userHeight, 0] //-userHeight
         },
+        "methods": {
+            "randomize":{
+                "body":"let myColor = this.getRandomColor(); \n this.myName.color = myColor; \n this.myBody.material.color = myColor; \n this.myHead.visual.material.color = myColor; \n this.myHead.myCursor.vis.material.color = myColor; \n this.myHead.myCursor.line.color = myColor;"
+            }
+        },
         children: {
            
             "myBody": myBodyDef,
@@ -96,7 +115,7 @@ this.createAvatarBody = function (nodeDef, modelSrc) {
                     
                     "myCamera":
                     {
-                        "id": 'camera-' + this.id,
+                        //"id": 'camera-' + this.id,
                         "extends": "http://vwf.example.com/aframe/acamera.vwf",
                         "properties": {
                             "position": [0, 0, -0.7],
@@ -107,14 +126,14 @@ this.createAvatarBody = function (nodeDef, modelSrc) {
                     },
                     "myCursor":
                     {
-                        "id": 'myCursor-' + this.id,
+                        //"id": 'myCursor-' + this.id,
                         "extends": "http://vwf.example.com/aframe/aentity.vwf",
                         "properties": {},
                         "children": {
                             "vis": {
                                 "extends": "http://vwf.example.com/aframe/abox.vwf",
                                 "properties": {
-                                    "position": "0 0 -3",
+                                    "position": [0, 0, -3],
                                     "height": 0.05,
                                     "width": 0.05,
                                     "depth": 0.01,
@@ -198,8 +217,8 @@ this.createAvatarBody = function (nodeDef, modelSrc) {
                     "color": myColor,
                     "value": this.displayName,
                     "side": "double",
-                    "rotation": "0 180 0",
-                    "position": "0.3 2.05 0.5"
+                    "rotation": [0, 180, 0],
+                    "position": [0.3, 2.05, 0.5]
                 }
             }
 
@@ -207,12 +226,29 @@ this.createAvatarBody = function (nodeDef, modelSrc) {
         }
     }
 
+
+
     var newNode  = Object.assign({}, defaultNode);
 
-    if (nodeDef){
-       newNode = Object.assign(defaultNode, nodeDef);
+   //1. check for default user saved avatar...
+   if (nodeDef){
+    newNode = Object.assign({}, nodeDef);
+    newNode.properties.position = [0, userHeight, 0];
+    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;
     }
+    
 
+     //3. check for model...
     if (modelSrc) {
 
         let myBodyDef = this.modelBodyDef;
@@ -247,7 +283,11 @@ this.createAvatarBody = function (nodeDef, modelSrc) {
     //this.children.create( "avatarCamera", camera );
     // this.children.create( "avatarNameNode", avatarNameNode );
 
-    this.children.create("avatarNode", newNode);
+    this.children.create("avatarNode", newNode, function(child){
+
+       child.randomize();
+
+    });
 
     // this.localUrl = '';
     // this.remoteUrl = '';
@@ -263,15 +303,6 @@ this.createAvatarBody = function (nodeDef, modelSrc) {
 
 }
 
-this.getRandomColor = function () {
-    var letters = '0123456789ABCDEF';
-    var color = '#';
-    for (var i = 0; i < 6; i++) {
-        color += letters[Math.floor(this.random() * 16)];
-    }
-    return color;
-}
-
 this.followAvatarControl = function (position, rotation) {
     // this.position = AFRAME.utils.coordinates.stringify(position);
     // this.rotation = AFRAME.utils.coordinates.stringify(rotation);
@@ -434,3 +465,10 @@ this.initialize = function() {
 };
 
 
+this.setMyName = function(val){
+    this.avatarNode.myName.value = val
+}
+
+this.randomizeAvatar = function() {
+    this.avatarNode.randomize();
+}

+ 5 - 1
public/defaults/proxy/vwf.example.com/aframe/avatar.vwf.yaml

@@ -26,7 +26,6 @@ methods:
         parameters:
             - nodeDef
             - modelSrc
-    getRandomColor:
     followAvatarControl:
         parameters:
             - position
@@ -53,5 +52,10 @@ methods:
     setUserAvatar:
         parameters:
             - val
+    findWorldAvatarCostume:
+    setMyName:
+        parameters:
+            - val
+    randomizeAvatar:
 scripts:
 - source: "http://vwf.example.com/aframe/avatar.js"

+ 1 - 1
public/defaults/worlds/ohmlang-lsys/appui.js

@@ -11,7 +11,7 @@ function createApp() {
 
     function getNewPosition() {
         //let allChild = vwf.find("","/*")
-        let cursorVisID = vwf.find("myCursor-avatar-" + vwf.moniker_, "./vis")[0]
+        let cursorVisID = vwf.find("avatar-" + vwf.moniker_, "./avatarNode/myHead/myCursor/vis")[0];
         let avPos = AFRAME.utils.coordinates.parse(vwf.callMethod(cursorVisID, 'worldPosition'));
         let newPos = [avPos.x, avPos.y, avPos.z]
         return newPos

+ 0 - 9
public/defaults/worlds/webrtc/appui.js

@@ -5,20 +5,11 @@ function createApp() {
         let self = this
     
     
-    
         function makeSetter(val) {
             let setstr = 'this.' + val + '= value; this.redrawEvent();'
             return setstr
         }
     
-        function getNewPosition() {
-            //let allChild = vwf.find("","/*")
-            let cursorVisID = vwf.find("myCursor-avatar-" + vwf.moniker_, "./vis")[0]
-            let avPos = AFRAME.utils.coordinates.parse(vwf.callMethod(cursorVisID, 'worldPosition'));
-            let newPos = [avPos.x, avPos.y, avPos.z]
-            return newPos
-        }
-    
         return {
             $cell: true,
             $type: "div",

+ 44 - 1
public/helpers.js

@@ -291,7 +291,50 @@ class Helpers {
         let node = vwf.getNode(nodeID, true);
         let nodeDefPure = this.removeProps(node);
         let nodeDef = this.removeGrammarObj(nodeDefPure);
-        return nodeDef
+
+        let finalDef = this.replaceFloatArraysInNodeDef(nodeDef); 
+
+        return finalDef
+    }
+
+    replaceFloatArraysInNodeDef(state){
+
+        var objectIsTypedArray = function (candidate) {
+            var typedArrayTypes = [
+              Int8Array,
+              Uint8Array,
+              // Uint8ClampedArray,
+              Int16Array,
+              Uint16Array,
+              Int32Array,
+              Uint32Array,
+              Float32Array,
+              Float64Array
+            ];
+      
+            var isTypedArray = false;
+      
+            if (typeof candidate == "object" && candidate != null) {
+              typedArrayTypes.forEach(function (typedArrayType) {
+                isTypedArray = isTypedArray || candidate instanceof typedArrayType;
+              });
+            }
+      
+            return isTypedArray;
+          };
+      
+          var transitTransformation = function (object) {
+            return objectIsTypedArray(object) ?
+              Array.prototype.slice.call(object) : object;
+          };
+      
+      
+          let value = require("vwf/utility").transform(
+            state, transitTransformation
+          );
+      
+          return value
+
     }
 
     removeGrammarObj(obj) {

+ 4 - 0
public/vwf/model/aframe.js

@@ -73,6 +73,8 @@ define(["module", "vwf/model", "vwf/utility"], function (module, model, utility)
                             aframeObject.setAttribute(propertyName, { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] })
                         } else if (typeof propertyValue === 'string') {
                             aframeObject.setAttribute(propertyName, AFRAME.utils.coordinates.parse(propertyValue))
+                        } else if (propertyValue.hasOwnProperty('0')) {
+                            aframeObject.setAttribute(propertyName, { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] })
                         }
 
                 },
@@ -88,6 +90,8 @@ define(["module", "vwf/model", "vwf/utility"], function (module, model, utility)
                     else if (typeof propertyValue === 'string') {
                         let val = AFRAME.utils.coordinates.parse(propertyValue);
                         value = goog.vec.Vec3.createFromValues(val.x, val.y, val.z)
+                    }  else if (propertyValue.hasOwnProperty('0')) {
+                        value = goog.vec.Vec3.createFromValues(propertyValue[0], propertyValue[1], propertyValue[2])
                     }
 
                     return value

+ 32 - 14
public/vwf/view/aframe.js

@@ -434,22 +434,40 @@ define(["module", "vwf/view"], function (module, view) {
                 }
 
                 if (!self.state.nodes[avatarName]) {
+                   
 
                     if (_LCSUSER.is) {
-                        _LCSUSER.get('profile').once(res => {
-                            var myNode = null;
-                            if (res.avatarNode) {
-                                myNode = JSON.parse(res.avatarNode);
-                            }
-                            newNode.properties.displayName = res.alias;
 
-                            vwf_view.kernel.createChild(nodeID, avatarName, newNode);
-                            vwf_view.kernel.callMethod(avatarName, "createAvatarBody", [myNode, null]);
-                            //"/../assets/avatars/male/avatar1.gltf"
-
-
-                            //vwf_view.kernel.callMethod(avatarName, 'setUserAvatar', [res] );
-                        })
+                        _LCSUSER.get('profile').get('alias').once(alias => {
+                                if (alias){
+
+                                    newNode.properties.displayName = alias;
+                                    //vwf_view.kernel.callMethod(avatarName, "setMyName", [alias]);
+                                }
+                                vwf_view.kernel.createChild(nodeID, avatarName, newNode);
+                                });
+
+                                    _LCSUSER.get('profile').get('avatarNode').once(res => {
+                                        var myNode = null;
+                                        if (res) {
+                                            //myNode = JSON.parse(res.avatarNode);
+                                            myNode = res;
+                                            vwf_view.kernel.callMethod(avatarName, "createAvatarBody", [myNode, null]);
+                                        } else {
+                                            vwf_view.kernel.callMethod(avatarName, "createAvatarBody", []);
+                                        }
+                                       // newNode.properties.displayName = res.alias;
+            
+                                        
+                                        //"/../assets/avatars/male/avatar1.gltf"
+            
+            
+                                        //vwf_view.kernel.callMethod(avatarName, 'setUserAvatar', [res] );
+                                    });
+
+
+                                
+                      
                     } else {
 
                         vwf_view.kernel.createChild(nodeID, avatarName, newNode);
@@ -458,7 +476,7 @@ define(["module", "vwf/view"], function (module, view) {
                     }
 
                     //
-
+                    
 
                 }
 

+ 14 - 31
public/vwf/view/editor-new.js

@@ -555,7 +555,8 @@ define([
                                             "onclick": function (e) {
                                                 //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
                                                 let avatarID = 'avatar-' + self.kernel.moniker();
-                                                let cursorID = 'myCursor-' + avatarID;
+                                                let cursorID = vwf.find(avatarID, "./avatarNode/myHead/myCursor")[0];
+                                                //let cursorID = 'myCursor-' + avatarID;
                                                 let controlEl = document.querySelector("[id='" + cursorID + "']");
                                                 let vis = controlEl.getAttribute('visible');
                                                 this.$text = vis ? 'Show cursor' : 'Hide cursor';
@@ -1862,36 +1863,18 @@ define([
                                             //vwf_view.kernel.callMethod(node.parentID, "deleteNode", [node.name])
                                         }
                                     }),
-                                    self.widgets.floatActionButton({
-                                        label: "person",
-                                        styleClass: "mdc-fab--mini",
-                                        onclickfunc: function () {
-                                            var nodeID = document.querySelector('#currentNode')._currentNode;
-                                            let node = self.nodes[nodeID];
-                                            //vwf_view.kernel.deleteChild(node.parentID, node.name);
-
-                                            let me = self.kernel.moniker();
-                                            vwf_view.kernel.setProperty(nodeID, 'ownedBy', me);
-
-                                            // let me = self.kernel.moniker();
-                                            // let viewDriver = vwf.views["vwf/view/aframe"];
-                                            // let nodeComponents = viewDriver.nodes[nodeID].components;
-                                            // let raycasterID = Object.entries(nodeComponents).find(el => 
-                                            //     el[0] == 'raycaster'
-                                            //   )[1];
-                                            //  if (raycasterID){
-                                            //     vwf_view.kernel.setProperty(raycasterID, 'ownedby', me);
-                                            //  }
-                                            //   else {
-                                            //       console.log("no raycaster component on: " + nodeID);
-                                            //   }
-
-
-                                            //let nodeComponents = node.components
-                                           
-                                            //vwf_view.kernel.callMethod(node.parentID, "deleteNode", [node.name])
-                                        }
-                                    }),
+                                    // self.widgets.floatActionButton({
+                                    //     label: "person",
+                                    //     styleClass: "mdc-fab--mini",
+                                    //     onclickfunc: function () {
+                                    //         var nodeID = document.querySelector('#currentNode')._currentNode;
+                                    //         let node = self.nodes[nodeID];
+                                    //         //vwf_view.kernel.deleteChild(node.parentID, node.name);
+
+                                    //         let me = self.kernel.moniker();
+                                    //         vwf_view.kernel.setProperty(nodeID, 'ownedBy', me);
+                                    //     }
+                                    // }),
 
                                     saveGUI