index.vwf.yaml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. light1:
  15. extends: http://vwf.example.com/aframe/alight.vwf
  16. properties:
  17. type: "ambient"
  18. color: "#BBB"
  19. light2:
  20. extends: http://vwf.example.com/aframe/alight.vwf
  21. properties:
  22. type: "directional"
  23. color: "#FFF"
  24. intensity: 0.6
  25. position: "-0.5 1 1"
  26. groundPlane:
  27. extends: http://vwf.example.com/aframe/aplane.vwf
  28. properties:
  29. height: 50
  30. width: 50
  31. rotation: [-90, 0, 0]
  32. children:
  33. material:
  34. extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
  35. properties:
  36. wireframe: false
  37. src: "#bg2"
  38. repeat: "10 10"
  39. calcResult:
  40. extends: http://vwf.example.com/aframe/atext.vwf
  41. properties:
  42. value: "no result"
  43. color: "#1d7027"
  44. position: [1, 2.5, -2]
  45. scale: [3, 3, 3]
  46. side: "double"
  47. methods:
  48. calcMe:
  49. body: |
  50. let match = this.parent.calcText.calcLang.grammar.match(this.parent.calcText.value);
  51. if (match.succeeded()){
  52. if (typeof this.parent.calcText.calcLang.semantics === 'function'){
  53. this.value = this.parent.calcText.calcLang.semantics(match).interpret()}
  54. }
  55. this.future( 0.1 ).calcMe();
  56. calcText:
  57. extends: http://vwf.example.com/aframe/atext.vwf
  58. properties:
  59. value: "1 * pi"
  60. color: "#b74217"
  61. position: [-1, 2.5, -2]
  62. scale: [2, 2, 2]
  63. side: "double"
  64. children:
  65. calcLang:
  66. extends: http://vwf.example.com/ohm/node.vwf
  67. properties:
  68. grammar:
  69. semantics:
  70. ohmLang: |
  71. Arithmetic {
  72. Exp
  73. = AddExp
  74. AddExp
  75. = AddExp "+" MulExp -- plus
  76. | AddExp "-" MulExp -- minus
  77. | MulExp
  78. MulExp
  79. = MulExp "*" ExpExp -- times
  80. | MulExp "/" ExpExp -- divide
  81. | ExpExp
  82. ExpExp
  83. = PriExp "^" ExpExp -- power
  84. | PriExp
  85. PriExp
  86. = "(" Exp ")" -- paren
  87. | "+" PriExp -- pos
  88. | "-" PriExp -- neg
  89. | ident
  90. | number
  91. ident (an identifier)
  92. = letter alnum*
  93. number (a number)
  94. = digit* "." digit+ -- fract
  95. | digit+ -- whole
  96. }
  97. methods:
  98. initLang:
  99. body: |
  100. console.log("add operations to semantics")
  101. this.addOperationLang();
  102. addOperationLang:
  103. body: |
  104. var constants = {pi: Math.PI, e: Math.E};
  105. this.semantics.addOperation('interpret', {
  106. Exp: function(e) {
  107. return e.interpret();
  108. },
  109. AddExp: function(e) {
  110. return e.interpret();
  111. },
  112. AddExp_plus: function(x, _, y) {
  113. return x.interpret() + y.interpret();
  114. },
  115. AddExp_minus: function(x, _, y) {
  116. return x.interpret() - y.interpret();
  117. },
  118. MulExp: function(e) { return e.interpret(); },
  119. MulExp_times: function(x, _, y) { return x.interpret() * y.interpret(); },
  120. MulExp_divide: function(x, _, y) { return x.interpret() / y.interpret(); },
  121. ExpExp: function(e) { return e.interpret(); },
  122. ExpExp_power: function(x, _, y) { return Math.pow(x.interpret(), y.interpret()); },
  123. PriExp: function(e) { return e.interpret(); },
  124. PriExp_paren: function(_l, e, _r) { return e.interpret(); },
  125. PriExp_pos: function(_, e) { return e.interpret(); },
  126. PriExp_neg: function(_, e) { return -e.interpret(); },
  127. ident: function(_l, _ns) {
  128. // Look up the value of a named constant, e.g., 'pi'.
  129. return constants[this.sourceString] || 0;
  130. },
  131. number: function(_) {
  132. // Use `parseFloat` to convert (e.g.) the string '123' to the number 123.
  133. return parseFloat(this.sourceString);
  134. }
  135. })
  136. testLang:
  137. body: |
  138. var match = this.grammar.match('2+2');
  139. console.log(match);
  140. var res = this.semantics(match).interpret();
  141. console.log(res);
  142. sky:
  143. extends: http://vwf.example.com/aframe/asky.vwf
  144. properties:
  145. children:
  146. material:
  147. extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
  148. properties:
  149. color: "#ECECEC"
  150. side: "back"