index.vwf.yaml 9.4 KB

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