index.vwf.yaml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. children:
  8. skySun:
  9. extends: http://vwf.example.com/aframe/aentity.vwf
  10. children:
  11. sun:
  12. extends: http://vwf.example.com/aframe/app-sun-component.vwf
  13. newSky:
  14. extends: http://vwf.example.com/aframe/aentity.vwf
  15. children:
  16. skyshader:
  17. extends: http://vwf.example.com/aframe/app-skyshader-component.vwf
  18. groundPlane:
  19. extends: http://vwf.example.com/aframe/aplane.vwf
  20. properties:
  21. height: 50
  22. width: 50
  23. rotation: [-90, 0, 0]
  24. children:
  25. material:
  26. extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
  27. properties:
  28. wireframe: false
  29. src: "#bg2"
  30. repeat: "10 10"
  31. turtle:
  32. extends: http://vwf.example.com/aframe/asphere.vwf
  33. properties:
  34. position: [1, 1.25, -4]
  35. radius: 0.2
  36. angleInRadians: 0
  37. iteration: 3
  38. angle: 60
  39. stepLength: 0.5
  40. rule: 'F++F++F'
  41. axiomF: 'F-F++F-F'
  42. axiomG: ''
  43. lsys: ''
  44. readyForDraw: true
  45. children:
  46. interpolation:
  47. extends: http://vwf.example.com/aframe/interpolation-component.vwf
  48. properties:
  49. enabled: true
  50. material:
  51. extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
  52. properties:
  53. wireframe: true
  54. color: "#e0e014"
  55. drawNode:
  56. extends: http://vwf.example.com/aframe/aentity.vwf
  57. children:
  58. linepath:
  59. extends: http://vwf.example.com/aframe/linepath.vwf
  60. properties:
  61. color: "#445447"
  62. path: []
  63. width: 0.02
  64. lsysLang:
  65. extends: http://vwf.example.com/ohm/node.vwf
  66. properties:
  67. grammar:
  68. semantics:
  69. ohmLang: |
  70. LSys { Gen<x>
  71. = ReadRule+
  72. ReadRule
  73. = letters | symbols
  74. letters = "F" | "G"
  75. symbols = "-" | "+" }
  76. methods:
  77. initLang:
  78. body: |
  79. console.log("add operations to semantics")
  80. this.addOperationLang();
  81. addOperationLang:
  82. body: |
  83. this.semantics.addOperation('gen(x)', {
  84. Gen: function(e)
  85. {
  86. return e.gen(this.args.x);
  87. },
  88. ReadRule: function(e)
  89. {
  90. return e.gen(this.args.x);
  91. },
  92. letters: function(_)
  93. {
  94. for (var propName in this.args.x)
  95. {
  96. if (propName == this.sourceString)
  97. return this.args.x[propName]
  98. }
  99. return this.sourceString
  100. },
  101. symbols: function(_)
  102. {
  103. return this.sourceString;
  104. }
  105. });
  106. turtleLang:
  107. extends: http://vwf.example.com/ohm/node.vwf
  108. properties:
  109. grammar:
  110. semantics:
  111. ohmLang: |
  112. Turtle {
  113. Draw<x, y>
  114. = (drawLetter | turn)+
  115. drawLetter
  116. = letter
  117. turn
  118. = "+" | "-" }
  119. methods:
  120. initLang:
  121. body: |
  122. console.log("add operations to semantics")
  123. this.addOperationLang();
  124. addOperationLang:
  125. body: |
  126. var turtleID = this.parent.id;
  127. var self = this;
  128. this.semantics.addOperation('draw(x,y)', {
  129. Draw: function(e)
  130. {
  131. e.draw(this.args.x, this.args.y);
  132. },
  133. drawLetter: function(e)
  134. {
  135. //vwf_view.kernel.callMethod(turtleID, 'goForward', [this.args.x]);
  136. self.parent.goForward(this.args.x);
  137. },
  138. turn: function(e)
  139. {
  140. if (this.sourceString == "+")
  141. //vwf_view.kernel.callMethod(turtleID, 'turn', [this.args.y]);
  142. self.parent.turn(this.args.y);
  143. if (this.sourceString == "-")
  144. //vwf_view.kernel.callMethod(turtleID, 'turn', [-1 * this.args.y]);
  145. self.parent.turn(-1*this.args.y);
  146. }
  147. });
  148. methods:
  149. parseLSys: |
  150. var str = this.rule;
  151. var axioms = {"F": this.axiomF, "G": this.axiomG};
  152. for (var i = 1; i < this.iteration; i++)
  153. {
  154. var match = this.lsysLang.grammar.match(str, 'Gen<"y">');
  155. if (match.succeeded()){
  156. var res = this.lsysLang.semantics(match).gen(axioms);
  157. str = res.join("");
  158. }
  159. }
  160. console.log(str);
  161. this.lsys = str;
  162. makeLSys: |
  163. if (this.readyForDraw){
  164. this.drawNode.position = [0, 0, 0]
  165. this.angleInRadians = 0;
  166. this.drawNode.linepath.path = [];
  167. this.parseLSys();
  168. this.drawLSys();
  169. this.drawNode.position = [0, 0, 0]
  170. }
  171. drawLSys: |
  172. var match = this.turtleLang.grammar.match(this.lsys, 'Draw<"1","1">');
  173. if (match.succeeded()){
  174. var res = this.turtleLang.semantics(match).draw(this.stepLength, this.angle);
  175. }
  176. turn:
  177. parameters:
  178. - angle
  179. body: |
  180. var angle0 = this.angleInRadians;
  181. var targetAngle = angle * Math.PI / 180.0;
  182. this.angleInRadians = angle0 + targetAngle;
  183. goForward:
  184. parameters:
  185. - step
  186. body: |
  187. let pos = this.drawNode.position;
  188. var x0 = pos[0];
  189. var y0 = pos[1];
  190. var xx = Math.sin(this.angleInRadians);
  191. var yy = Math.cos(this.angleInRadians);
  192. let startPosition = {x: pos[0], y: pos[1], z:pos[2]};
  193. let endPosition = {x: x0 + step * xx, y: y0 + step * yy, z: pos[2]};
  194. var drawPath = this.drawNode.linepath.path;
  195. drawPath.push(startPosition);
  196. drawPath.push(endPosition);
  197. vwf_view.kernel.setProperty(this.drawNode.linepath.id, 'path', drawPath);
  198. this.drawNode.position = [endPosition.x, endPosition.y, endPosition.z];
  199. setTurtleParams:
  200. parameters:
  201. - val
  202. body: |
  203. this.readyForDraw = false;
  204. val.forEach(el => {
  205. this[el[0]] = el[1]
  206. })
  207. this.readyForDraw = true;
  208. this.makeLSys();
  209. initialize:
  210. body: |
  211. //this.redrawEvent = function(){this.makeLSys()}
  212. vwf_view.kernel.callMethod(this.id, "makeLSys");
  213. console.log("initialising turtle");
  214. methods:
  215. initialize:
  216. body: |
  217. console.log("initialising scene");
  218. drawLSys1: |
  219. this.turtle.makeLSys()
  220. testTurtle: |
  221. this.turtle.goForward(1);
  222. this.turtle.goForward(1);
  223. this.turtle.turn(45);
  224. this.turtle.goForward(1);
  225. this.turtle.goForward(1);
  226. this.turtle.turn(45);
  227. this.turtle.goForward(1);