Browse Source

redefined osc example

Nikolay Suslov 7 years ago
parent
commit
374e60e865

+ 88 - 78
public/osc-example/index.vwf.yaml

@@ -37,96 +37,106 @@ children:
       depth: 1
       height: 1
       width: 1
+    children:
+      sphere:
+        extends: http://vwf.example.com/aframe/asphere.vwf
+        properties:
+          position: "0 2 0"
+          rotation: "0 0 0"
+          color: "#3c7249"
+          radius: 0.4
+  newSky:
+    extends: http://vwf.example.com/aframe/aentity.vwf
+    children:
+      skyshader:
+        extends: http://vwf.example.com/aframe/app-skyshader-component.vwf
+  oscLang:
+    extends: http://vwf.example.com/ohm/node.vwf
+    properties:
       osc: true
+      grammar:
+      semantics:
+      ohmLang: |
+                parseOSC {
+                            all = address ":" props
+                            address = ("/" addr)*
+                            addr = ~("/") propSingle
+                            props 
+                                = propSingle row  -- single
+                                | "rgb" row       -- rgb
+                                | propSingle number -- prop
+                            row = "[" col rep "]"
+                            rep = ("," col)*
+                            col = colChar*
+                            colChar = ~("[" | "," | "]") number
+                            propSingle = ~("rgb") letter*
+                            number  (a number)
+                                = digit* "." digit+  -- fract
+                                | digit+             -- whole
+                            }
     methods:
+      initLang:
+        body: |
+              console.log("add operations to semantics")
+              this.addOperationLang();
+      addOperationLang:
+        body: |
+              var self = this;
+              this.semantics.addOperation('parse',
+              {
+                  all: function(e, _, k){ return {"address": e.parse(), "params": k.parse()} },
+                  address: function(_, e){ return e.parse()},
+                  addr: function(e) {return e.parse() },
+                  props: function(e) {return e.parse()},
+                  props_single: function( e, k){
+                          return {'propName': e.parse(), 'propValue': k.parse()};
+                  },
+                  props_rgb: function(_, e)
+                  {
+                      return {'propName': 'color', 'propValue': ['rgb('+ e.parse() + ')']};
+                  },
+                  props_prop: function(e, k){
+                          return {'propName': e.parse(), 'propValue': k.parse()};
+                  },
+                  row: function(_l, e, k, _e){
+                         let end = k.parse();
+                          if (end.length !== 0) {
+                           return e.parse() +','+ k.parse();
+                         }
+                         return e.parse()    
+                  },
+                  rep: function(_, e){ return e.parse()},
+                  col: function(e) {return e.parse()},
+                  colChar: function(e) {return e.parse()},
+                  number: function(_) {return parseFloat(this.sourceString)},
+                  propSingle: function(_){return this.sourceString}
+              });
       getOSC:
         parameters:
           - msg
         body: |
-              this.parseColorOSC(msg);
-              this.parseSingleOSC(msg);
-      parseColorOSC:
+              this.parseOSC(msg);
+      parseOSC:
         parameters:
           - msg
         body: |
                 let str = msg.address + JSON.stringify(msg.args);
-                var match = this.oscLang.grammar.match(str, "rgb");
+                var match = this.grammar.match(str, "all");
                 if (match.succeeded())
                 {
-                    let res = this.oscLang.semantics(match).parse();
-                   this.setColorFromOSC(res);
-                }
-      setSinglePropFromOSC:
-        parameters:
-          - val
-        body: |
-                if (this.properties[val.propName]){
-                  this[val.propName] = val.propValue
+                    let res = this.semantics(match).parse();
+                    this.setPropsFromOSC(res);
                 }
-      setColorFromOSC:
+      setPropsFromOSC:
         parameters:
-          - propValue
+          - res
         body: |
-              this.color = propValue;
-              //this.parent.myLight.color = propValue;
-      parseSingleOSC:
-        parameters:
-          - msg
-        body: |
-                let str = msg.address + JSON.stringify(msg.args[0]);
-                var match = this.oscLang.grammar.match(str, "prop");
-                if (match.succeeded())
-                {
-                    let res = this.oscLang.semantics(match).parse();
-                    this.setSinglePropFromOSC(res);
-                }
-    children:
-      oscLang:
-          extends: http://vwf.example.com/ohm/node.vwf
-          properties:
-            grammar:
-            semantics:
-            ohmLang: |
-                      parseOSC {
-                        rgb = "/rgb/" row
-                        row = "[" col rep "]"
-                        rep = ("," col)*
-                        col = colChar*
-                        colChar = ~("[" | "," | "]") number
-                        prop = "/" propSingle "/" number
-                        propSingle = letter*
-                        number  (a number)
-                          = digit* "." digit+  -- fract
-                          | digit+             -- whole
-                      }
-          methods:
-            initLang:
-              body: |
-                    console.log("add operations to semantics")
-                    this.addOperationLang();
-            addOperationLang:
-              body: |
-                    var self = this;
-                    this.semantics.addOperation('parse',
-                    {
-                        rgb: function(_, e)
-                        {
-                            return 'rgb('+ e.parse() + ')'
-                        },
-                         prop: function(_l, e, _r, k){
-                                return {'propName': e.parse(), 'propValue': k.parse()};
-                        },
-                        row: function(_l, e, k, _e){
-                                return e.parse() +','+ k.parse();
-                        },
-                        rep: function(_, e){ return e.parse()},
-                        col: function(e) {return e.parse()},
-                        colChar: function(e) {return e.parse()},
-                        number: function(_) {return parseFloat(this.sourceString)},
-                        propSingle: function(_){return this.sourceString}
-                    });     
-  newSky:
-    extends: http://vwf.example.com/aframe/aentity.vwf
-    children:
-      skyshader:
-        extends: http://vwf.example.com/aframe/app-skyshader-component.vwf
+              //console.log(res);
+              let address = '/'+res.address.join('/');
+              let nodeID = vwf.find("", address);
+              if (res.params.propValue.length == 1) {
+                  vwf_view.kernel.setProperty(nodeID, res.params.propName, [res.params.propValue[0]])
+              }
+              if (res.params.propValue.length >= 1) {
+                  vwf_view.kernel.setProperty(nodeID, res.params.propName, [res.params.propValue])
+              }

+ 0 - 5
public/osc-example2/appui.js

@@ -1,5 +0,0 @@
-//-----App ui-----
-
-// function createApp() {
-//     return {}
-// }

+ 0 - 6
public/osc-example2/assets.json

@@ -1,6 +0,0 @@
-{
-     "bg2":{
-        "tag": "img",
-        "src": "/../assets/checker.jpg"
-    }
-}

+ 0 - 8
public/osc-example2/index.vwf.config.yaml

@@ -1,8 +0,0 @@
----
-info:
-  title: "VWF & AFrame Example App"
-model:
-  vwf/model/aframe:
-view:
-  vwf/view/aframe:
-  vwf/view/editor-new:

+ 0 - 147
public/osc-example2/index.vwf.yaml

@@ -1,147 +0,0 @@
-# A-Frame & VWF & OSC simple scene
-# Copyright 2017 Krestianstvo.org project
----
-extends: http://vwf.example.com/aframe/ascene.vwf
-properties:
-  fog: "type: linear; color: #ECECEC; far: 20; near: 0"
-  assets: "assets.json"
-children:
-  oscLang:
-    extends: http://vwf.example.com/ohm/node.vwf
-    properties:
-      osc: true
-      grammar:
-      semantics:
-      ohmLang: |
-                parseOSC {
-                            all = address ":" props
-                            address = ("/" addr)*
-                            addr = ~("/") propSingle
-                            props 
-                                = single
-                                | rgb
-                                | prop
-                            single = propSingle row
-                            prop = propSingle number
-                            rgb = "rgb" row
-                            row = "[" col rep "]"
-                            rep = ("," col)*
-                            col = colChar*
-                            colChar = ~("[" | "," | "]") number
-                            propSingle = ~("rgb") letter*
-                            number  (a number)
-                                = digit* "." digit+  -- fract
-                                | digit+             -- whole
-                            }
-    methods:
-      initLang:
-        body: |
-              console.log("add operations to semantics")
-              this.addOperationLang();
-      addOperationLang:
-        body: |
-              var self = this;
-              this.semantics.addOperation('parse',
-              {
-                  all: function(e, _, k){ return {"address": e.parse(), "params": k.parse()} },
-                  address: function(_, e){ return e.parse()},
-                  addr: function(e) {return e.parse() },
-                  props: function(e) {return e.parse()},
-                  single: function( e, k){
-                          return {'propName': e.parse(), 'propValue': k.parse()};
-                  },
-                  rgb: function(_, e)
-                  {
-                      return {'propName': 'color', 'propValue': ['rgb('+ e.parse() + ')']};
-                  },
-                  prop: function(e, k){
-                          return {'propName': e.parse(), 'propValue': k.parse()};
-                  },
-                  row: function(_l, e, k, _e){
-                         let end = k.parse();
-                          if (end.length !== 0) {
-                           return e.parse() +','+ k.parse();
-                         }
-                         return e.parse()
-                          
-                  },
-                  rep: function(_, e){ return e.parse()},
-                  col: function(e) {return e.parse()},
-                  colChar: function(e) {return e.parse()},
-                  number: function(_) {return parseFloat(this.sourceString)},
-                  propSingle: function(_){return this.sourceString}
-              });
-      getOSC:
-        parameters:
-          - msg
-        body: |
-              this.parseOSC(msg);
-      parseOSC:
-        parameters:
-          - msg
-        body: |
-                let str = msg.address + JSON.stringify(msg.args);
-                console.log(str);
-                var match = this.grammar.match(str, "all");
-                if (match.succeeded())
-                {
-                    let res = this.semantics(match).parse();
-                    this.setPropsFromOSC(res);
-                }
-      setPropsFromOSC:
-        parameters:
-          - res
-        body: |
-              console.log(res);
-              let address = '/'+res.address.join('/');
-              let nodeID = vwf.find("", address);
-              if (res.params.propValue.length == 1) {
-                  vwf_view.kernel.setProperty(nodeID, res.params.propName, [res.params.propValue[0]])
-              }
-              if (res.params.propValue.length >= 1) {
-                  vwf_view.kernel.setProperty(nodeID, res.params.propName, [res.params.propValue])
-              }      
-  myLight:
-    extends: http://vwf.example.com/aframe/alight.vwf
-    properties:
-      type: "point"
-      color: "white"
-      position: "0 10 5"
-      rotation: "0 0 0"
-  groundPlane:
-    extends: http://vwf.example.com/aframe/aplane.vwf
-    properties:
-        height: 50
-        width: 50
-        repeat: "10 10"
-        rotation: [-90, 0, 0]
-        wireframe: false
-        src: "#bg2"
-  spaceText:
-    extends: http://vwf.example.com/aframe/atext.vwf
-    properties:
-      value: "Virtual World Framework & A-Frame & OSC"
-      color: "#2b5d83"
-      position: [-2, 2.5, -3]
-  cube:
-    extends: http://vwf.example.com/aframe/abox.vwf
-    properties:
-      position: "0 1 -3"
-      rotation: "0 0 0"
-      color: "#3c7249"
-      depth: 1
-      height: 1
-      width: 1
-    children:
-      sphere:
-        extends: http://vwf.example.com/aframe/asphere.vwf
-        properties:
-          position: "0 2 0"
-          rotation: "0 0 0"
-          color: "#3c7249"
-          radius: 0.4
-  newSky:
-    extends: http://vwf.example.com/aframe/aentity.vwf
-    children:
-      skyshader:
-        extends: http://vwf.example.com/aframe/app-skyshader-component.vwf

BIN
public/osc-example2/webimg.jpg