index.vwf.yaml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # A-Frame & VWF simple scene
  2. # Copyright 2017 Krestianstvo.org project
  3. ---
  4. extends: http://vwf.example.com/aframe/ascene.vwf
  5. properties:
  6. assets: "assets.json"
  7. methods:
  8. initialize:
  9. body: |
  10. var calc = vwf_view.kernel.find("", "/calcResult")[0];
  11. console.log(calc);
  12. vwf_view.kernel.callMethod(calc, "calcMe");
  13. children:
  14. groundPlane:
  15. extends: http://vwf.example.com/aframe/aplane.vwf
  16. properties:
  17. height: 50
  18. width: 50
  19. repeat: "10 10"
  20. rotation: [-90, 0, 0]
  21. wireframe: false
  22. src: "#bg2"
  23. calcResult:
  24. extends: http://vwf.example.com/aframe/atext.vwf
  25. properties:
  26. value: "no result"
  27. color: "#1d7027"
  28. position: [1, 2.5, -2]
  29. scale: [3, 3, 3]
  30. methods:
  31. calcMe:
  32. body: |
  33. let match = this.parent.calcText.calcLang.grammar.match(this.parent.calcText.value);
  34. if (match.succeeded()){
  35. this.value = this.parent.calcText.calcLang.semantics(match).interpret()}
  36. this.future( 0.1 ).calcMe();
  37. calcText:
  38. extends: http://vwf.example.com/aframe/atext.vwf
  39. properties:
  40. value: "1 * pi"
  41. color: "#b74217"
  42. position: [-1, 2.5, -2]
  43. scale: [2, 2, 2]
  44. children:
  45. calcLang:
  46. extends: http://vwf.example.com/ohm/node.vwf
  47. properties:
  48. grammar:
  49. semantics:
  50. ohmLang: |
  51. Arithmetic {
  52. Exp
  53. = AddExp
  54. AddExp
  55. = AddExp "+" MulExp -- plus
  56. | AddExp "-" MulExp -- minus
  57. | MulExp
  58. MulExp
  59. = MulExp "*" ExpExp -- times
  60. | MulExp "/" ExpExp -- divide
  61. | ExpExp
  62. ExpExp
  63. = PriExp "^" ExpExp -- power
  64. | PriExp
  65. PriExp
  66. = "(" Exp ")" -- paren
  67. | "+" PriExp -- pos
  68. | "-" PriExp -- neg
  69. | ident
  70. | number
  71. ident (an identifier)
  72. = letter alnum*
  73. number (a number)
  74. = digit* "." digit+ -- fract
  75. | digit+ -- whole
  76. }
  77. methods:
  78. initLang:
  79. body: |
  80. console.log("add operations to semantics")
  81. this.addOperationLang();
  82. addOperationLang:
  83. body: |
  84. var constants = {pi: Math.PI, e: Math.E};
  85. this.semantics.addOperation('interpret', {
  86. Exp: function(e) {
  87. return e.interpret();
  88. },
  89. AddExp: function(e) {
  90. return e.interpret();
  91. },
  92. AddExp_plus: function(x, _, y) {
  93. return x.interpret() + y.interpret();
  94. },
  95. AddExp_minus: function(x, _, y) {
  96. return x.interpret() - y.interpret();
  97. },
  98. MulExp: function(e) { return e.interpret(); },
  99. MulExp_times: function(x, _, y) { return x.interpret() * y.interpret(); },
  100. MulExp_divide: function(x, _, y) { return x.interpret() / y.interpret(); },
  101. ExpExp: function(e) { return e.interpret(); },
  102. ExpExp_power: function(x, _, y) { return Math.pow(x.interpret(), y.interpret()); },
  103. PriExp: function(e) { return e.interpret(); },
  104. PriExp_paren: function(_l, e, _r) { return e.interpret(); },
  105. PriExp_pos: function(_, e) { return e.interpret(); },
  106. PriExp_neg: function(_, e) { return -e.interpret(); },
  107. ident: function(_l, _ns) {
  108. // Look up the value of a named constant, e.g., 'pi'.
  109. return constants[this.sourceString] || 0;
  110. },
  111. number: function(_) {
  112. // Use `parseFloat` to convert (e.g.) the string '123' to the number 123.
  113. return parseFloat(this.sourceString);
  114. }
  115. })
  116. testLang:
  117. body: |
  118. var match = this.grammar.match('2+2');
  119. console.log(match);
  120. var res = this.semantics(match).interpret();
  121. console.log(res);
  122. sky:
  123. extends: http://vwf.example.com/aframe/asky.vwf
  124. properties:
  125. color: "#ECECEC"
  126. camentity:
  127. extends: http://vwf.example.com/aframe/aentity.vwf
  128. properties:
  129. position: [0, 0, 0]
  130. children:
  131. camera:
  132. extends: http://vwf.example.com/aframe/acamera.vwf
  133. properties:
  134. look-controls-enabled: true
  135. forAvatar: true
  136. children:
  137. cursor:
  138. extends: http://vwf.example.com/aframe/acursor.vwf