Browse Source

windows mixed reality controllers support

Nikolay Suslov 7 years ago
parent
commit
dd874681a3

+ 30 - 2
support/client/lib/vwf/model/aframe/addon/aframe-components.js

@@ -375,7 +375,7 @@ AFRAME.registerComponent('gearvrcontrol', {
     
         init: function () {
             var self = this;
-            var controllerID = 'controlvr-' + vwf_view.kernel.moniker();
+            var controllerID = 'gearvr-' + vwf_view.kernel.moniker();
             //this.gearel = document.querySelector('#gearvrcontrol');
             this.el.addEventListener('triggerdown', function (event) {
               vwf_view.kernel.callMethod(controllerID, "triggerdown", []);
@@ -390,4 +390,32 @@ AFRAME.registerComponent('gearvrcontrol', {
     
         tick: function (t) {
         }
-    })
+    })
+
+
+    AFRAME.registerComponent('wmrvrcontrol', {
+        
+        schema: {
+            hand: { default: 'right' }
+        },
+    
+        update: function (old) {
+            this.hand = this.data.hand;
+        },
+
+            init: function () {
+                var self = this;
+                this.hand = this.data.hand;
+                var controllerID = 'wrmr-' + this.hand + '-' + vwf_view.kernel.moniker();
+                //this.gearel = document.querySelector('#gearvrcontrol');
+                this.el.addEventListener('triggerdown', function (event) {
+                  vwf_view.kernel.callMethod(controllerID, "triggerdown", []);
+                  });
+                  this.el.addEventListener('triggerup', function (event) {
+                   vwf_view.kernel.callMethod(controllerID, "triggerup", []);
+                  });
+            },
+        
+            tick: function (t) {
+            }
+        })

+ 0 - 51
support/client/lib/vwf/model/aframeComponent.js

@@ -656,48 +656,6 @@ define(["module", "vwf/model", "vwf/utility"], function (module, model, utility)
                 }
 
 
-                if (value === undefined && isGearVRControlsDefinition(node.prototypes)) {
-                    value = propertyValue;
-
-                    // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
-                    let parentNodeAF = aframeObject.el;
-
-                    switch (propertyName) {
-
-                        case "armModel":
-
-                            value = AFRAME.utils.coordinates.stringify(parentNodeAF.getAttribute(aframeObject.compName).armModel);
-                            break;
-
-                        case "buttonColor":
-                            value = AFRAME.utils.coordinates.stringify(parentNodeAF.getAttribute(aframeObject.compName).buttonColor);
-                            break;
-
-                        case "buttonTouchedColor":
-                            value = parentNodeAF.getAttribute(aframeObject.compName).buttonTouchedColor;
-                            break;
-
-                        case "buttonHighlightColor":
-                            value = parentNodeAF.getAttribute(aframeObject.compName).buttonHighlightColor;
-                            break;
-
-                        case "hand":
-                            value = parentNodeAF.getAttribute(aframeObject.compName).hand;
-                            break;
-
-                        case "model":
-                            value = parentNodeAF.getAttribute(aframeObject.compName).model;
-                            break;
-
-                        case "rotationOffset":
-                            value = parentNodeAF.getAttribute(aframeObject.compName).rotationOffset;
-                            break;
-
-                    }
-                }
-
-
-
             }
 
             if (value !== undefined) {
@@ -923,15 +881,6 @@ define(["module", "vwf/model", "vwf/utility"], function (module, model, utility)
  
          }
 
-        if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/gearvr-controlsComponent.vwf")) {
-
-
-            // aframeObj.el.setAttribute(node.type, {});
-            aframeObj.compName = "gearvr-controls";
-            aframeObj.el.setAttribute(aframeObj.compName, {});
-
-        }
-
         if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/app-raycaster-listener-component.vwf")) {
 
 

+ 50 - 74
support/client/lib/vwf/view/aframe.js

@@ -70,27 +70,30 @@ define(["module", "vwf/view"], function (module, view) {
 
                 if (this.gearvr == true) {
                     console.log("CREATE GEARVR HERE!!");
-
                     if (AFRAME.utils.device.isGearVR()) {
-                        let nodeName = 'controlvr-' + self.kernel.moniker();
+                        let nodeName = 'gearvr-' + self.kernel.moniker();
                         createGearVRControls();
                         createGearVRController.call(this, childID, nodeName);
                     }
                 }
-                // if (this.wmrright == true) {
-                //     console.log("CREATE WMR RIGHT HERE!!");
-                //     if (AFRAME.utils.device.checkHasPositionalTracking()) {
-                //         createWMRVRControls('right');
-                //         createControlVR.call(this, childID, 'wmrvr-right-');
-                //     }
-                // }
-                // if (this.wmrright == true) {
-                //     console.log("CREATE WMR LEFT HERE!!");
-                //     if (AFRAME.utils.device.checkHasPositionalTracking()) {
-                //         createWMRVRControls('left');
-                //         createControlVR.call(this, childID, 'wmrvr-left-');
-                //     }
-                // }
+
+                if (this.wmrright == true) {
+                    console.log("CREATE WMR RIGHT HERE!!");
+                    if (AFRAME.utils.device.checkHasPositionalTracking()) {
+                        let nodeName = 'wmrvr-right-' + self.kernel.moniker();
+                        createWMRVRControls('right');
+                        createWMRVR.call(this, childID, nodeName);
+                    }
+                }
+
+                if (this.wmrright == true) {
+                    console.log("CREATE WMR LEFT HERE!!");
+                    if (AFRAME.utils.device.checkHasPositionalTracking()) {
+                        let nodeName = 'wmrvr-left-' + self.kernel.moniker();
+                        createWMRVRControls('left');
+                        createWMRVR.call(this, childID, nodeName);
+                    }
+                }
 
             }
 
@@ -115,9 +118,6 @@ define(["module", "vwf/view"], function (module, view) {
                 return;
             }
 
-
-
-
         },
 
         createdProperty: function (nodeId, propertyName, propertyValue) {
@@ -197,9 +197,17 @@ define(["module", "vwf/view"], function (module, view) {
         ticked: function (vwfTime) {
 
             updateAvatarPosition();
-            updateHandControllerVR('controlvr-', '#gearvrcontrol');
-            // updateHandControllerVR('wmrvr-right-', '#wmrvrcontrolright');
-            // updateHandControllerVR('wmrvr-left-', '#wmrvrcontrolleft');
+
+            //update vr controllers
+            if (this.gearvr == true) {
+                updateHandControllerVR('gearvr-', '#gearvrcontrol');
+            }
+            if (this.wmrright == true) {
+                updateHandControllerVR('wmrvr-right-', '#wmrvrcontrolright');
+            }
+            if (this.wmrleft == true) {
+                updateHandControllerVR('wmrvr-left-', '#wmrvrcontrolleft');
+            }
 
 
             //lerpTick ()
@@ -259,17 +267,13 @@ define(["module", "vwf/view"], function (module, view) {
 
                     vwf_view.kernel.setProperty(avatarName, "rotation", AFRAME.utils.coordinates.stringify(rotation));
                     vwf_view.kernel.setProperty(avatarName, "position", AFRAME.utils.coordinates.stringify(position));
-
-
                 }
             }
 
         }
-
     }
 
 
-
     function createAvatarControl(aScene) {
 
         let avatarName = 'avatar-' + self.kernel.moniker();
@@ -317,6 +321,25 @@ define(["module", "vwf/view"], function (module, view) {
 
     }
 
+    function createWMRVR (nodeID, nodeName) { 
+
+        var newNode = {
+            "id": nodeName,
+            "uri": nodeName,
+            "extends": "http://vwf.example.com/aframe/wmrvrcontroller.vwf",
+            "properties": {
+            }
+        }
+
+        if (!self.state.nodes[nodeName]) {
+
+            vwf_view.kernel.createChild(nodeID, nodeName, newNode);
+            vwf_view.kernel.callMethod(nodeName, "createController", []);
+            //"/../assets/controller/wmrvr.gltf"
+        }
+    }
+
+
     function createGearVRController(nodeID, nodeName) {
 
             var newNode = {
@@ -376,57 +399,10 @@ define(["module", "vwf/view"], function (module, view) {
         wmrvr.setAttribute('id', 'wmrvrcontrol' + hand);
         wmrvr.setAttribute('windows-motion-controls', '');
         wmrvr.setAttribute('windows-motion-controls', 'hand', hand);
+        wmrvr.setAttribute('wmrvrcontrol', {'hand': hand});
         sceneEl.appendChild(wmrvr);
     }
 
 
 
-    function createControlVR(nodeID, name) {
-
-        let avatarID = self.kernel.moniker();
-        var nodeName = name + avatarID;
-
-        var newNode = {
-            "id": nodeName,
-            "uri": nodeName,
-            "extends": "http://vwf.example.com/aframe/abox.vwf",
-            "properties": {
-                "color": "white",
-                "position": "0 0 0",
-                "height": 0.01,
-                "width": 0.01,
-                "depth": 1,
-            },
-            children: {
-                "cur": {
-                    "extends": "http://vwf.example.com/aframe/abox.vwf",
-                    "properties": {
-                        "color": "green",
-                        "position": "0 0 -1",
-                        "height": 0.2,
-                        "width": 0.2,
-                        "depth": 0.2
-                    }
-                },
-                "gearvr":
-                    {
-                        "extends": "http://vwf.example.com/aframe/gearvrcontrol-component.vwf",
-                        "type": "component",
-                        "properties": {
-                        }
-                    },
-                "interpolation":
-                    {
-                        "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
-                        "type": "component",
-                        "properties": {
-                        }
-                    }
-            }
-        }
-
-        vwf_view.kernel.createChild(nodeID, nodeName, newNode);
-        // vwf_view.kernel.callMethod(nodeName, "createAvatarBody");
-    }
-
 });

+ 2 - 2
support/proxy/vwf.example.com/aframe/ascene.js

@@ -27,8 +27,8 @@ this.clientWatch = function () {
                     } else {
                         //console.log(node.id + " needed to delete!");
                         self.children.delete(self.children[node.id]);
-                        //'controlvr-'
-                        let controllerVR = self.children['controlvr-'+ node.id.slice(7)];
+                        //'gearvr-'
+                        let controllerVR = self.children['gearvr-'+ node.id.slice(7)];
                         if (controllerVR){
                             self.children.delete(controllerVR);
                         }

+ 0 - 12
support/proxy/vwf.example.com/aframe/gearvr-controlsComponent.vwf.yaml

@@ -1,12 +0,0 @@
-#https://aframe.io/docs/master/components/gearvr-controls.html
----
-extends: http://vwf.example.com/aframe/aentityComponent.vwf
-type: "component"
-properties:
-  armModel:
-  buttonColor:
-  buttonTouchedColor:
-  buttonHighlightColor:
-  hand:
-  model:
-  rotationOffset:

+ 9 - 9
support/proxy/vwf.example.com/aframe/gearvrcontroller.js

@@ -82,7 +82,7 @@ this.createController = function (modelSrc) {
 
 
     this.children.create( "interpolation", interpolation );
-    this.children.create("gearVRNode", newNode);
+    this.children.create("handVRNode", newNode);
 
 }
 
@@ -96,25 +96,25 @@ this.updateAvatarVRControl = function(position, rotation){
 
 
 this.createSimpleController = function(){
-       if (this.gearVRNode.controller) {
-        this.gearVRNode.children.delete(this.gearVRNode.controller);
+       if (this.handVRNode.controller) {
+        this.handVRNode.children.delete(this.handVRNode.controller);
 
         let controllerDef = this.simpleDef;
 
-        this.gearVRNode.children.create("controller", controllerDef);
+        this.handVRNode.children.create("controller", controllerDef);
 
        }
 }
 
 this.createAvatarFromGLTF = function(modelSrc){
 
-    if (this.gearVRNode.controller) {
-        this.gearVRNode.children.delete(this.gearVRNode.controller);
+    if (this.handVRNode.controller) {
+        this.handVRNode.children.delete(this.handVRNode.controller);
         
         let controllerDef = this.modelDef;
         controllerDef.properties.src = modelSrc;
 
-        this.gearVRNode.children.create("controller", controllerDef);
+        this.handVRNode.children.create("controller", controllerDef);
 
        }
 }
@@ -124,9 +124,9 @@ this.initialize = function() {
 }
 
 this.triggerdown = function() {
-    this.gearVRNode.controller.pointer.color = 'red'
+    this.handVRNode.controller.pointer.color = 'red'
  }
 
  this.triggerup = function() {
-    this.gearVRNode.controller.pointer.color = 'green'
+    this.handVRNode.controller.pointer.color = 'green'
  }

+ 132 - 0
support/proxy/vwf.example.com/aframe/wmrvrcontroller.js

@@ -0,0 +1,132 @@
+this.simpleDef = {
+    "extends": "http://vwf.example.com/aframe/abox.vwf",
+    "properties": {
+        "color": "white",
+        "position": "0 0 0",
+        "height": 0.01,
+        "width": 0.01,
+        "depth": 1,
+    },
+    children: {
+        "pointer": {
+            "extends": "http://vwf.example.com/aframe/abox.vwf",
+            "properties": {
+                "color": "green",
+                "position": "0 0 -0.8",
+                "height": 0.1,
+                "width": 0.1,
+                "depth": 0.1
+            }
+        },
+        "interpolation":
+            {
+                "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
+                "type": "component",
+                "properties": {
+                }
+            }
+    }
+}
+
+this.modelDef = {
+    "extends": "http://vwf.example.com/aframe/agltfmodel.vwf",
+    "properties": {
+        "src": "#wmrvr",
+        "position": "0 0 0",
+        "rotation": "0 180 0"
+    },
+    "children": {
+        "animation-mixer": {
+            "extends": "http://vwf.example.com/aframe/anim-mixer-component.vwf",
+            "properties": {
+                "clip": "*",
+                "duration": 1
+            }
+        }
+
+    }
+}
+
+this.createController = function (modelSrc) {
+
+    let controllerDef = this.simpleDef;
+
+    var newNode = {
+        "extends": "http://vwf.example.com/aframe/aentity.vwf",
+        "properties": {
+            "position": [0, 0, 0]
+        },
+        children: {
+            "controller": controllerDef
+        }
+    }
+
+    if (modelSrc) {
+
+        let controllerDef = this.modelDef;
+        controllerDef.properties.src = modelSrc;
+        newNode.children.controller = controllerDef;
+    }
+
+
+    let interpolation =  {
+        "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
+        "type": "component",
+        "properties": {
+            "enabled": true,
+            "duration": 50,
+            "deltaPos": 0,
+            "deltaRot": 0
+        }
+    }
+
+
+    this.children.create( "interpolation", interpolation );
+    this.children.create("handVRNode", newNode);
+
+}
+
+
+this.updateAvatarVRControl = function(position, rotation){
+
+    this.rotation = rotation;
+    this.position = position;
+
+}
+
+
+this.createSimpleController = function(){
+       if (this.handVRNode.controller) {
+        this.handVRNode.children.delete(this.handVRNode.controller);
+
+        let controllerDef = this.simpleDef;
+
+        this.handVRNode.children.create("controller", controllerDef);
+
+       }
+}
+
+this.createAvatarFromGLTF = function(modelSrc){
+
+    if (this.handVRNode.controller) {
+        this.handVRNode.children.delete(this.handVRNode.controller);
+        
+        let controllerDef = this.modelDef;
+        controllerDef.properties.src = modelSrc;
+
+        this.handVRNode.children.create("controller", controllerDef);
+
+       }
+}
+
+this.initialize = function() {
+   // this.future(0).update();
+}
+
+this.triggerdown = function() {
+    this.handVRNode.controller.pointer.color = 'red'
+ }
+
+ this.triggerup = function() {
+    this.handVRNode.controller.pointer.color = 'green'
+ }

+ 24 - 0
support/proxy/vwf.example.com/aframe/wmrvrcontroller.vwf.yaml

@@ -0,0 +1,24 @@
+# wmrvr controller
+# Copyright 2017 Krestianstvo.org project
+---
+extends: http://vwf.example.com/aframe/aentity.vwf
+type: "wmrvr"
+properties:
+methods:
+    initialize:
+    updateController:
+    createSimpleController:
+    createControllerFromGLTF:
+        parameters:
+            - modelSrc
+    createController:
+        parameters:
+            - modelSrc
+    updateVRControl:
+        parameters:
+            - position
+            - rotation
+    triggerdown:
+    triggerup:
+scripts:
+- source: "http://vwf.example.com/aframe/wmrvrcontroller.js"