Browse Source

add xrcontroller costume support

Nikolay Suslov 4 years ago
parent
commit
96e126b73a

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

@@ -3,6 +3,16 @@ this.getChildByName = function (name) {
     return nodes[0]
     return nodes[0]
 }
 }
 
 
+this.nodeDef = function () {
+    let def = _app.helpers.getNodeDef(this.id);
+    return def
+ }
+
+this.clone = function () {
+   let nodeDef = _app.helpers.getNodeDef(this.id);
+   return nodeDef
+}
+
 this.getScene =  function () {
 this.getScene =  function () {
     let scene = this.find("/")[0];
     let scene = this.find("/")[0];
     return scene
     return scene

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

@@ -105,5 +105,6 @@ methods:
   step:
   step:
   do:
   do:
   randomize:
   randomize:
+  nodeDef:
 scripts:
 scripts:
   - source: "http://vwf.example.com/aframe/aentity.js"
   - source: "http://vwf.example.com/aframe/aentity.js"

+ 65 - 0
public/defaults/proxy/vwf.example.com/aframe/ascene.js

@@ -1,5 +1,6 @@
 this.initialize = function () {
 this.initialize = function () {
     this.future(3).clientWatch();
     this.future(3).clientWatch();
+    //this.createDefaultXRCostume();
 };
 };
 
 
 this.clientWatch = function () {
 this.clientWatch = function () {
@@ -1147,4 +1148,68 @@ this.enterVR = function(){
 
 
 this.exitVR = function(){
 this.exitVR = function(){
     console.log("EXIT VR");
     console.log("EXIT VR");
+}
+
+this.getChildByName = function (name) {
+    let nodes = this.children.filter(el => el.displayName == name);
+    return nodes[0]
+}
+
+this.getAllChildsByName = function (name) {
+    let nodes = this.children.filter(el => el.displayName == name);
+    return nodes
+}
+
+this.getDefaultXRCostume = function(){
+    
+    let defaultXRCostume = {
+        "extends": "http://vwf.example.com/aframe/abox.vwf",
+        "properties": {
+            displayName: "defaultXRCostume",
+            "position": "0 0 0",
+            "height": 0.01,
+            "width": 0.01,
+            "depth": 1
+        },
+        "methods":{
+            triggerdown:{
+                body:'\/\/do on trigger down \n this.pointer.material.color = "red"',
+                type: "application/javascript"
+            },
+            triggerup:{
+                body:'\/\/do on trigger up \n this.pointer.material.color = "green"',
+                type: "application/javascript"
+            }
+        },
+        children: {
+            "material": {
+                "extends": "http://vwf.example.com/aframe/aMaterialComponent.vwf",
+                "type": "component",
+                "properties":{
+                    "color": "white"
+                }
+            },
+            "pointer": {
+                "extends": "http://vwf.example.com/aframe/abox.vwf",
+                "properties": {
+                    "position": "0 0 -0.7",
+                    "height": 0.1,
+                    "width": 0.1,
+                    "depth": 0.1
+                },
+                children: {
+                    "material": {
+                        "extends": "http://vwf.example.com/aframe/aMaterialComponent.vwf",
+                        "type": "component",
+                        "properties":{
+                            "color": "green"
+                        }
+                    }
+                }
+            }
+        }
+    
+    }
+
+    return defaultXRCostume
 }
 }

+ 7 - 0
public/defaults/proxy/vwf.example.com/aframe/ascene.vwf.yaml

@@ -86,6 +86,13 @@ methods:
   deleteNode:
   deleteNode:
     parameters:
     parameters:
       - nodeName
       - nodeName
+  getChildByName:
+    parameters:
+      - name
+  getAllChildsByName:
+    parameters:
+      - name
+  getDefaultXRCostume:
   enterVR:
   enterVR:
   exitVR:
   exitVR:
 scripts:
 scripts:

+ 92 - 70
public/defaults/proxy/vwf.example.com/aframe/xrcontroller.js

@@ -1,50 +1,3 @@
-this.simpleDef = {
-    "extends": "http://vwf.example.com/aframe/abox.vwf",
-    children: {
-        "material": {
-            "extends": "http://vwf.example.com/aframe/aMaterialComponent.vwf",
-            "type": "component",
-            "properties":{
-                "color": "white"
-            }
-        }
-    },
-    "properties": {
-        "position": "0 0 0",
-        "height": 0.01,
-        "width": 0.01,
-        "depth": 1
-    },
-    children: {
-        "pointer": {
-            "extends": "http://vwf.example.com/aframe/abox.vwf",
-            "properties": {
-                "position": "0 0 -0.7",
-                "height": 0.1,
-                "width": 0.1,
-                "depth": 0.1
-            },
-            children: {
-                "material": {
-                    "extends": "http://vwf.example.com/aframe/aMaterialComponent.vwf",
-                    "type": "component",
-                    "properties":{
-                        "color": "green"
-                    }
-                }
-            }
-        }
-        // "interpolation":
-        //     {
-        //         "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
-        //         "type": "component",
-        //         "properties": {
-        //             "enabled": true
-        //         }
-        //     }
-    }
-}
-
 this.modelDef = {
 this.modelDef = {
     "extends": "http://vwf.example.com/aframe/agltfmodel.vwf",
     "extends": "http://vwf.example.com/aframe/agltfmodel.vwf",
     "properties": {
     "properties": {
@@ -66,26 +19,16 @@ this.modelDef = {
 
 
 this.createController = function (modelSrc) {
 this.createController = function (modelSrc) {
 
 
-    let controllerDef = this.simpleDef;
+    let self = this;
 
 
     var newNode = {
     var newNode = {
         "extends": "http://vwf.example.com/aframe/aentity.vwf",
         "extends": "http://vwf.example.com/aframe/aentity.vwf",
         "properties": {
         "properties": {
             "position": [0, 0, -0.4]
             "position": [0, 0, -0.4]
         },
         },
-        children: {
-            "controller": controllerDef
-        }
-    }
-
-    if (modelSrc) {
-
-        let controllerDef = this.modelDef;
-        controllerDef.properties.src = modelSrc;
-        newNode.children.controller = controllerDef;
+        children: {}
     }
     }
 
 
-
     let interpolation =  {
     let interpolation =  {
         "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
         "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
         "type": "component",
         "type": "component",
@@ -96,7 +39,13 @@ this.createController = function (modelSrc) {
 
 
 
 
     this.children.create( "interpolation", interpolation );
     this.children.create( "interpolation", interpolation );
-    this.children.create("handVRNode", newNode);
+    this.children.create("xrnode", newNode, function(child){
+        if(child) {
+            //find default costume
+            self.setControllerNode(modelSrc);
+        }
+
+    });
 
 
 }
 }
 
 
@@ -109,16 +58,16 @@ this.updateVRControl = function(position, rotation){
 }
 }
 
 
 
 
-this.createSimpleController = function(){
-       if (this.handVRNode.controller) {
-        this.handVRNode.children.delete(this.handVRNode.controller);
+// this.createSimpleController = function(){
+//        if (this.handVRNode.controller) {
+//         this.handVRNode.children.delete(this.handVRNode.controller);
 
 
-        let controllerDef = this.simpleDef;
+//         let controllerDef = this.simpleDef;
 
 
-        this.handVRNode.children.create("controller", controllerDef);
+//         this.handVRNode.children.create("controller", controllerDef);
 
 
-       }
-}
+//        }
+// }
 
 
 this.createAvatarFromGLTF = function(modelSrc){
 this.createAvatarFromGLTF = function(modelSrc){
 
 
@@ -138,9 +87,82 @@ this.initialize = function() {
 }
 }
 
 
 this.triggerdown = function() {
 this.triggerdown = function() {
-    this.handVRNode.controller.pointer.material.color = 'red'
+    let controller = this.xrnode.controller;
+    if(controller){
+        controller.triggerdown();
+    }
+    //this.xrnode.controller.pointer.material.color = 'red'
  }
  }
 
 
  this.triggerup = function() {
  this.triggerup = function() {
-    this.handVRNode.controller.pointer.material.color = 'green'
- }
+    let controller = this.xrnode.controller;
+    if(controller){
+        controller.triggerup();
+    }
+    //this.xrnode.controller.pointer.material.color = 'green'
+ }
+
+this.saveToScene = function(){
+
+    let scene = this.getScene();
+    let controller = this.xrnode.controller;
+    if(controller){
+        let defNode = this.checkDefaultXRCostume();
+
+        if(defNode){
+            scene.children.delete(defNode);
+        } 
+
+       let node = controller.nodeDef(); 
+       node.properties.visible = false;
+       node.properties.displayName = 'defaultXRCostume';
+        scene.children.create('defaultXRCostume', node, function( child ) {
+            console.log('Save default controller costume to scene: ', child);
+           });
+
+    }
+
+}
+
+ this.checkDefaultXRCostume = function(){
+    let scene = this.getScene();
+    let defaultNode = scene.getChildByName('defaultXRCostume');
+    return defaultNode ? defaultNode : undefined
+ }
+
+
+this.setControllerNode = function(modelSrc){
+
+    let scene = this.getScene();
+    let defaultNode = this.checkDefaultXRCostume();
+    let oldCostume = this.xrnode.controller;
+    if(oldCostume){
+        this.xrnode.children.delete(oldCostume);
+    }
+
+    if(defaultNode) {
+        let def = _app.helpers.getNodeDef(defaultNode.id);
+        def.properties.position = '0 0 0';
+        def.properties.rotation = '0 0 0';
+        def.properties.visible = true;
+        def.properties.displayName = 'controller';
+        this.xrnode.children.create('controller', def, function( child ) {
+            console.log('Restore controller costume: ', child)
+           });
+    } else {
+
+        let controllerDef = scene.getDefaultXRCostume();
+        controllerDef.properties.displayName = 'controller';
+
+        if (modelSrc) {
+            let controllerDef = this.modelDef;
+            controllerDef.properties.src = modelSrc;
+        }
+
+        this.xrnode.children.create('controller', controllerDef, function( child ) {
+            console.log('New controller costume: ', child)
+           });
+    
+    }
+
+}

+ 5 - 0
public/defaults/proxy/vwf.example.com/aframe/xrcontroller.vwf.yaml

@@ -20,5 +20,10 @@ methods:
             - rotation
             - rotation
     triggerdown:
     triggerdown:
     triggerup:
     triggerup:
+    checkDefaultXRCostume:
+    setControllerNode:
+        parameters:
+            - modelSrc
+    saveToScene:
 scripts:
 scripts:
 - source: "http://vwf.example.com/aframe/xrcontroller.js"
 - source: "http://vwf.example.com/aframe/xrcontroller.js"