2 |
3 |
4 |
5 | A-Frame L-System Component - 2D Koch Snow Flake
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/examples/animated hilbert curve/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | A-Frame L-System Component - Hilbert Curve
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/examples/animated tree/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | A-Frame L-System Component - Animated Tree
4 |
5 |
6 |
7 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/examples/forrest/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | A-Frame L-System Component - Forrest
4 |
5 |
6 |
7 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/examples/hilbertcurve/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | A-Frame L-System Component - Hilbert Curve
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/examples/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | A-Frame Example Component
4 |
5 |
22 |
23 |
24 | A-Frame L-System Component
25 | Hilbert Curve
26 | Animated Hilbert Curve
27 | This example shows how to use the L-System component to render a 4-iteration Hilbert Curve in A-Frame.
28 |
29 | 2D Koch Snowflake
30 |
31 | multiple mixins (geometry and color changes)
32 | Demonstrating how to use !
and '
to increment or decrement the mixin index. This makes it possible to use all kinds of materials and geometries for symbols. Make sure to also check the source code of the examples! :)
33 |
34 | Tree
35 | This example shows how to use the L-System component to render a tree in A-Frame.
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | Forrest
44 | This example shows how to use the L-System component to render a multiple trees in A-Frame.
45 |
46 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/examples/libs/aframe-animation-component.js:
--------------------------------------------------------------------------------
1 | !function(t){function n(r){if(e[r])return e[r].exports;var a=e[r]={exports:{},id:r,loaded:!1};return t[r].call(a.exports,a,a.exports,n),a.loaded=!0,a.exports}var e={};return n.m=t,n.c=e,n.p="",n(0)}([function(t,n,e){function r(t,n,e){var r=n.from||s(t,n.property);return AFRAME.utils.extend({},e,{targets:[{aframeProperty:r}],aframeProperty:n.to,update:function(){c(t,n.property,this.targets[0].aframeProperty)}})}function a(t,n,e){var r=s(t,n.property);n.from&&(r=AFRAME.utils.coordinates.parse(n.from));var a=AFRAME.utils.coordinates.parse(n.to);return AFRAME.utils.extend({},e,{targets:[r],update:function(){c(t,n.property,this.targets[0])}},a)}function i(t,n){var e=n.split("."),r=e[0],a=e[1],i=t.components[r]||AFRAME.components[r];return i?a?i.schema[a].type:i.schema.type:null}var o=e(1);if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");var u=AFRAME.utils,s=u.entity.getComponentProperty,c=u.entity.setComponentProperty;u.styleParser.parse;AFRAME.registerComponent("animation",{schema:{delay:{"default":0},dir:{"default":""},dur:{"default":1e3},easing:{"default":"easeInQuad"},elasticity:{"default":400},from:{"default":""},loop:{"default":!1},property:{"default":""},repeat:{"default":0},startEvents:{type:"array"},pauseEvents:{type:"array"},to:{"default":""}},multiple:!0,init:function(){this.animation=null,this.animationIsPlaying=!1,this.config=null,this.playAnimationBound=this.playAnimation.bind(this),this.pauseAnimationBound=this.pauseAnimation.bind(this),this.repeat=0},update:function(){var t=this.attrName,n=this.data,e=this.el,u=i(e,n.property),s=this;this.repeat=n.repeat;var c={autoplay:!1,begin:function(){e.emit("animation-begin"),e.emit(t+"-begin")},complete:function(){e.emit("animation-complete"),e.emit(t+"-complete"),--s.repeat>0&&s.animation.play()},direction:n.dir,duration:n.dur,easing:n.easing,elasticity:n.elasticity,loop:n.loop},f=r;"vec2"!==u&&"vec3"!==u&&"vec4"!==u||(f=a),this.pauseAnimation(),this.config=f(e,n,c),this.animation=o(this.config),this.data.startEvents.length||(this.animationIsPlaying=!0),this.removeEventListeners(),this.addEventListeners()},remove:function(){this.pauseAnimation(),this.removeEventListeners()},pause:function(){this.pauseAnimation(),this.removeEventListeners()},play:function(){this.animation&&this.animationIsPlaying&&(this.playAnimation(),this.addEventListeners())},addEventListeners:function(){var t=this,n=this.data,e=this.el;n.startEvents.map(function(n){e.addEventListener(n,t.playAnimationBound)}),n.pauseEvents.map(function(n){e.addEventListener(n,t.pauseAnimationBound)})},removeEventListeners:function(){var t=this,n=this.data,e=this.el;n.startEvents.map(function(n){e.removeEventListener(n,t.playAnimationBound)}),n.pauseEvents.map(function(n){e.removeEventListener(n,t.pauseAnimationBound)})},playAnimation:function(){this.animation&&(this.animation.restart(),this.animationIsPlaying=!0)},pauseAnimation:function(){this.animation&&(this.animation.pause(),this.animationIsPlaying=!1)}})},function(t,n,e){var r,a,i;!function(e,o){a=[],r=o,i="function"==typeof r?r.apply(n,a):r,!(void 0!==i&&(t.exports=i))}(this,function(){var t,n="1.1.0",e={duration:1e3,delay:0,loop:!1,autoplay:!0,direction:"normal",easing:"easeOutElastic",elasticity:400,round:!1,begin:void 0,update:void 0,complete:void 0},r=["translateX","translateY","translateZ","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skewX","skewY"],a="transform",i=function(){return{array:function(t){return Array.isArray(t)},object:function(t){return Object.prototype.toString.call(t).indexOf("Object")>-1},svg:function(t){return t instanceof SVGElement},dom:function(t){return t.nodeType||i.svg(t)},number:function(t){return!isNaN(parseInt(t))},string:function(t){return"string"==typeof t},func:function(t){return"function"==typeof t},undef:function(t){return"undefined"==typeof t},"null":function(t){return"null"==typeof t},hex:function(t){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t)},rgb:function(t){return/^rgb/.test(t)},rgba:function(t){return/^rgba/.test(t)},hsl:function(t){return/^hsl/.test(t)},color:function(t){return i.hex(t)||i.rgb(t)||i.rgba(t)||i.hsl(t)}}}(),o=function(){var t={},n=["Quad","Cubic","Quart","Quint","Expo"],e={Sine:function(t){return 1-Math.cos(t*Math.PI/2)},Circ:function(t){return 1-Math.sqrt(1-t*t)},Elastic:function(t,n){if(0===t||1===t)return t;var e=1-Math.min(n,998)/1e3,r=t/1,a=r-1,i=e/(2*Math.PI)*Math.asin(1);return-(Math.pow(2,10*a)*Math.sin((a-i)*(2*Math.PI)/e))},Back:function(t){return t*t*(3*t-2)},Bounce:function(t){for(var n,e=4;t<((n=Math.pow(2,--e))-1)/11;);return 1/Math.pow(4,3-e)-7.5625*Math.pow((3*n-2)/22-t,2)}};return n.forEach(function(t,n){e[t]=function(t){return Math.pow(t,n+2)}}),Object.keys(e).forEach(function(n){var r=e[n];t["easeIn"+n]=r,t["easeOut"+n]=function(t,n){return 1-r(1-t,n)},t["easeInOut"+n]=function(t,n){return t<.5?r(2*t,n)/2:1-r(t*-2+2,n)/2}}),t.linear=function(t){return t},t}(),u=function(t){return i.string(t)?t:t+""},s=function(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()},c=function(t){if(i.color(t))return!1;try{var n=document.querySelectorAll(t);return n}catch(e){return!1}},f=function(t,n){return Math.floor(Math.random()*(n-t+1))+t},l=function(t){return t.reduce(function(t,n){return t.concat(i.array(n)?l(n):n)},[])},p=function(t){return i.array(t)?t:(i.string(t)&&(t=c(t)||t),t instanceof NodeList||t instanceof HTMLCollection?[].slice.call(t):[t])},m=function(t,n){return t.some(function(t){return t===n})},d=function(t,n){var e={};return t.forEach(function(t){var r=JSON.stringify(n.map(function(n){return t[n]}));e[r]=e[r]||[],e[r].push(t)}),Object.keys(e).map(function(t){return e[t]})},h=function(t){return t.filter(function(t,n,e){return e.indexOf(t)===n})},v=function(t){var n={};for(var e in t)n[e]=t[e];return n},g=function(t,n){for(var e in n)t[e]=i.undef(t[e])?n[e]:t[e];return t},y=function(t){var n=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,t=t.replace(n,function(t,n,e,r){return n+n+e+e+r+r}),e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t),r=parseInt(e[1],16),a=parseInt(e[2],16),i=parseInt(e[3],16);return"rgb("+r+","+a+","+i+")"},b=function(t){var n,e,r,t=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),a=parseInt(t[1])/360,i=parseInt(t[2])/100,o=parseInt(t[3])/100,u=function(t,n,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?t+6*(n-t)*e:e<.5?n:e<2/3?t+(n-t)*(2/3-e)*6:t};if(0==i)n=e=r=o;else{var s=o<.5?o*(1+i):o+i-o*i,c=2*o-s;n=u(c,s,a+1/3),e=u(c,s,a),r=u(c,s,a-1/3)}return"rgb("+255*n+","+255*e+","+255*r+")"},A=function(t){return i.rgb(t)||i.rgba(t)?t:i.hex(t)?y(t):i.hsl(t)?b(t):void 0},E=function(t){return/([\+\-]?[0-9|auto\.]+)(%|px|pt|em|rem|in|cm|mm|ex|pc|vw|vh|deg)?/.exec(t)[2]},M=function(t,n,e){return E(n)?n:t.indexOf("translate")>-1?E(e)?n+E(e):n+"px":t.indexOf("rotate")>-1||t.indexOf("skew")>-1?n+"deg":n},x=function(t,n){if(n in t.style)return getComputedStyle(t).getPropertyValue(s(n))||"0"},w=function(t,n){var e=n.indexOf("scale")>-1?1:0,r=t.style.transform;if(!r)return e;for(var a=/(\w+)\((.+?)\)/g,i=[],o=[],u=[];i=a.exec(r);)o.push(i[1]),u.push(i[2]);var s=u.filter(function(t,e){return o[e]===n});return s.length?s[0]:e},I=function(t,n){return i.dom(t)&&m(r,n)?"transform":i.dom(t)&&"transform"!==n&&x(t,n)?"css":i.dom(t)&&(t.getAttribute(n)||i.svg(t)&&t[n])?"attribute":i["null"](t[n])||i.undef(t[n])?void 0:"object"},P=function(t,n){switch(I(t,n)){case"transform":return w(t,n);case"css":return x(t,n);case"attribute":return t.getAttribute(n)}return t[n]||0},L=function(t,n,e){if(i.color(n))return A(n);if(E(n))return n;var r=E(E(t.to)?t.to:t.from);return!r&&e&&(r=E(e)),r?n+r:n},O=function(t){var n=/-?\d*\.?\d+/g;return{original:t,numbers:u(t).match(n)?u(t).match(n).map(Number):[0],strings:u(t).split(n)}},k=function(t,n,e){return n.reduce(function(n,r,a){var r=r?r:e[a-1];return n+t[a-1]+r})},F=function(t){var t=t?l(i.array(t)?t.map(p):p(t)):[];return t.map(function(t,n){return{target:t,id:n}})},j=function(t,n){var r=[];for(var a in t)if(!e.hasOwnProperty(a)&&"targets"!==a){var o=i.object(t[a])?v(t[a]):{value:t[a]};o.name=a,r.push(g(o,n))}return r},C=function(t,n,e,r){var a=p(i.func(e)?e(t,r):e);return{from:a.length>1?a[0]:P(t,n),to:a.length>1?a[1]:a[0]}},R=function(t,n,e,r){var a={};if("transform"===e)a.from=t+"("+M(t,n.from,n.to)+")",a.to=t+"("+M(t,n.to)+")";else{var i="css"===e?x(r,t):void 0;a.from=L(n,n.from,i),a.to=L(n,n.to,i)}return{from:O(a.from),to:O(a.to)}},B=function(t,n){var e=[];return t.forEach(function(r,a){var o=r.target;return n.forEach(function(n){var u=I(o,n.name);if(u){var s=C(o,n.name,n.value,a),c=v(n);c.animatables=r,c.type=u,c.from=R(n.name,s,c.type,o).from,c.to=R(n.name,s,c.type,o).to,c.round=i.color(s.from)||c.round?1:0,c.delay=(i.func(c.delay)?c.delay(o,a,t.length):c.delay)/J.speed,c.duration=(i.func(c.duration)?c.duration(o,a,t.length):c.duration)/J.speed,e.push(c)}})}),e},N=function(t,n){var e=B(t,n),r=d(e,["name","from","to","delay","duration"]);return r.map(function(t){var n=v(t[0]);return n.animatables=t.map(function(t){return t.animatables}),n.totalDuration=n.delay+n.duration,n})},S=function(t,n){t.tweens.forEach(function(e){var r=e.to,a=e.from,i=t.duration-(e.delay+e.duration);e.from=r,e.to=a,n&&(e.delay=i)}),t.reversed=!t.reversed},T=function(t){if(t.length)return Math.max.apply(Math,t.map(function(t){return t.totalDuration}))},$=function(t){var n=[],e=[];return t.tweens.forEach(function(t){"css"!==t.type&&"transform"!==t.type||(n.push("css"===t.type?s(t.name):"transform"),t.animatables.forEach(function(t){e.push(t.target)}))}),{properties:h(n).join(", "),elements:h(e)}},V=function(t){var n=$(t);n.elements.forEach(function(t){t.style.willChange=n.properties})},X=function(t){var n=$(t);n.elements.forEach(function(t){t.style.removeProperty("will-change")})},Y=function(t){var n=i.string(t)?c(t)[0]:t;return{path:n,value:n.getTotalLength()}},Q=function(t,n){var e=t.path,r=t.value*n,a=function(a){var i=a||0,o=n>1?t.value+i:r+i;return e.getPointAtLength(o)},i=a(),o=a(-1),u=a(1);switch(t.name){case"translateX":return i.x;case"translateY":return i.y;case"rotate":return 180*Math.atan2(u.y-o.y,u.x-o.x)/Math.PI}},Z=function(t,n){var e=Math.min(Math.max(n-t.delay,0),t.duration),r=e/t.duration,a=t.to.numbers.map(function(n,e){var a=t.from.numbers[e],i=o[t.easing](r,t.elasticity),u=t.path?Q(t,i):a+i*(n-a);return u=t.round?Math.round(u*t.round)/t.round:u});return k(a,t.to.strings,t.from.strings)},q=function(n,e){var r;n.currentTime=e,n.progress=e/n.duration*100;for(var i=0;i=r.delay&&(r.begin(n),r.begin=void 0),e.current>=n.duration&&(r.loop?(e.start=t,"alternate"===r.direction&&S(n,!0),i.number(r.loop)&&r.loop--):(n.ended=!0,n.pause(),r.complete&&r.complete(n)),e.last=0)},n.seek=function(t){q(n,t/100*n.duration)},n.pause=function(){X(n);var t=z.indexOf(n);t>-1&&z.splice(t,1)},n.play=function(t){n.pause(),t&&(n=g(D(g(t,n.settings)),n)),e.start=0,e.last=n.ended?0:n.currentTime;var r=n.settings;"reverse"===r.direction&&S(n),"alternate"!==r.direction||r.loop||(r.loop=1),V(n),z.push(n),G||H()},n.restart=function(){n.reversed&&S(n),n.pause(),n.seek(0),n.play()},n.settings.autoplay&&n.play(),n},K=function(t){for(var n=l(i.array(t)?t.map(p):p(t)),e=z.length-1;e>=0;e--)for(var r=z[e],a=r.tweens,o=a.length-1;o>=0;o--)for(var u=a[o].animatables,s=u.length-1;s>=0;s--)m(n,u[s].target)&&(u.splice(s,1),u.length||a.splice(o,1),a.length||r.pause())};return J.version=n,J.speed=1,J.list=z,J.remove=K,J.easings=o,J.getValue=P,J.path=Y,J.random=f,J})}]);
2 |
--------------------------------------------------------------------------------
/examples/libs/aframe-lsystem-component.js:
--------------------------------------------------------------------------------
1 | !function(t){function e(i){if(s[i])return s[i].exports;var o=s[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var s={};e.m=t,e.c=s,e.d=function(t,s,i){e.o(t,s)||Object.defineProperty(t,s,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var s=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(s,"a",s),s},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,s){"use strict";function i(t){let e=t.split(/(\w)\s*:\s*/).filter(t=>0!==t.length),s=[];for(var i=0;ii(t).map(t=>{var e=l(t,2);return[e[0],e[1].replace(/\s/g,"")]})},segmentMixins:{type:"string",parse:function(t){var e,s,o,r,n,a;let c=new Map,h=i(t);e=!0,s=!1,o=void 0;try{for(r=h[Symbol.iterator]();!(e=(n=r.next()).done);e=!0){let t=n.value,e=(a=l(t,2))[0],s=a[1];s=s.replace(/[\[\]]/g,"").split(","),c.set(e,s)}}catch(t){s=!0,o=t}finally{try{!e&&r.return&&r.return()}finally{if(s)throw o}}return c}},iterations:{type:"int",default:1},angle:{default:90},translateAxis:{type:"string",default:"y",parse:function(t){if("x"===(t=t.toLowerCase()))return new THREE.Vector3(1,0,0);if("y"===t)return new THREE.Vector3(0,1,0);if("z"===t)return new THREE.Vector3(0,0,1);throw Error('translateAxis has to be a string: "x", "y" or "z"')}},scaleFactor:{default:1},dynamicSegmentLength:{default:!0},mergeGeometries:{type:"boolean",default:!0},functionsInProductions:{type:"boolean",default:!0}},init:function(){this.sceneEl=document.querySelector("a-scene");let t=this;this.initWorker(),this.X=new THREE.Vector3(1,0,0),this.Y=new THREE.Vector3(0,1,0),this.Z=new THREE.Vector3(0,0,1),this.xPosRotation=new THREE.Quaternion,this.xNegRotation=new THREE.Quaternion,this.yPosRotation=new THREE.Quaternion,this.yNegRotation=new THREE.Quaternion,this.zPosRotation=new THREE.Quaternion,this.zNegRotation=new THREE.Quaternion,this.yReverseRotation=new THREE.Quaternion,this.xPosRotation=new THREE.Quaternion,this.xNegRotation=new THREE.Quaternion,this.yPosRotation=new THREE.Quaternion,this.yNegRotation=new THREE.Quaternion,this.zPosRotation=new THREE.Quaternion,this.zNegRotation=new THREE.Quaternion,this.yReverseRotation=new THREE.Quaternion,this.segmentLengthFactor=1,this.transformationSegment=new THREE.Object3D,this.transformationSegmentTemplate=this.transformationSegment.clone();let e=t.data.scaleFactor;this.colorIndex=0,this.lineWidth=5e-4,this.lineLength=.125,this.LSystem=new o.a({axiom:"F",productions:{F:"F"},finals:{"+":()=>{t.transformationSegment.quaternion.multiply(t.yPosRotation)},"-":()=>{t.transformationSegment.quaternion.multiply(t.yNegRotation)},"&":()=>{t.transformationSegment.quaternion.multiply(t.zNegRotation)},"^":()=>{t.transformationSegment.quaternion.multiply(t.zPosRotation)},"\\":()=>{t.transformationSegment.quaternion.multiply(t.xNegRotation)},"<":()=>{t.transformationSegment.quaternion.multiply(t.xNegRotation)},"/":()=>{t.transformationSegment.quaternion.multiply(t.xPosRotation)},">":()=>{t.transformationSegment.quaternion.multiply(t.xPosRotation)},"|":()=>{t.transformationSegment.quaternion.multiply(t.yReverseRotation)},"!":()=>{t.segmentLengthFactor*=e,t.transformationSegment.scale.set(t.transformationSegment.scale.x*=e,t.transformationSegment.scale.y*=e,t.transformationSegment.scale.z*=e),t.colorIndex++},"'":()=>{t.segmentLengthFactor*=1/e,t.transformationSegment.scale.set(t.transformationSegment.scale.x*=1/e,t.transformationSegment.scale.y*=1/e,t.transformationSegment.scale.z*=1/e),t.colorIndex=Math.max(0,t.colorIndex-1)},"[":()=>{t.stack.push(t.transformationSegment.clone())},"]":()=>{t.transformationSegment=t.stack.pop()}}})},update:function(t){var e,s,i,o,r;if(!1===this.data.mergeGeometries&&void 0!==this.segmentElementGroupsMap){e=!0,s=!1,i=void 0;try{for(o=this.segmentElementGroupsMap.values()[Symbol.iterator]();!(e=(r=o.next()).done);e=!0){let t=r.value;t.removeObject3D("mesh"),t.innerHTML=""}}catch(t){s=!0,i=t}finally{try{!e&&o.return&&o.return()}finally{if(s)throw i}}}if(0===Object.keys(t).length)this.updateLSystem(),this.updateSegmentMixins(),this.updateTurtleGraphics();else{let e=!1;(t.axiom&&t.axiom!==this.data.axiom||t.iterations&&t.iterations!==this.data.iterations||t.productions&&JSON.stringify(t.productions)!==JSON.stringify(this.data.productions))&&(this.updateLSystem(),e=!0),void 0!==t.segmentMixins&&JSON.stringify(Array.from(t.segmentMixins.entries()))!==JSON.stringify(Array.from(this.data.segmentMixins.entries()))&&(this.updateSegmentMixins(),e=!0),(e||t.angle&&t.angle!==this.data.angle)&&this.updateTurtleGraphics()}},calculateSegmentLength:function(t,e){if(this.segmentLengthMap.has(t))return this.segmentLengthMap.get(t);let s;return e.computeBoundingBox(),this.data.translateAxis.equals(this.X)?s=Math.abs(e.boundingBox.min.x-e.boundingBox.max.x):this.data.translateAxis.equals(this.Y)?s=Math.abs(e.boundingBox.min.y-e.boundingBox.max.y):this.data.translateAxis.equals(this.Z)&&(s=Math.abs(e.boundingBox.min.z-e.boundingBox.max.z)),this.segmentLengthMap.set(t,s),s},initWorker:function(){this.worker=new n.a},pushSegment:function(t){let e=this,s=e.transformationSegment.quaternion,i=e.transformationSegment.position,o=e.transformationSegment.scale,r=Math.min(this.colorIndex,this.data.segmentMixins.get(t).length-1),n=this.mixinMap.get(t+r);if(!1===this.data.mergeGeometries){let a=document.createElement("a-entity");a.setAttribute("mixin",n),a.addEventListener("loaded",()=>{let t=e.segmentLengthMap.get(n);a.object3D.children[0].translateOnAxis(e.data.translateAxis,t*e.segmentLengthFactor/2),a.object3D.quaternion.copy(s),a.object3D.position.copy(i),a.object3D.scale.copy(o)},{once:!0}),this.segmentElementGroupsMap.get(t+r).appendChild(a)}else{let e=this.segmentObjects3DMap.get(t+r).clone();e.matrixAutoUpdate=!1,e.quaternion.copy(s),e.position.copy(i),e.scale.copy(o),e.updateMatrix(),this.mergeGroups.get(t+r).geometry.merge(e.geometry,e.matrix)}let a=this.segmentLengthMap.get(n);this.transformationSegment.translateOnAxis(this.data.translateAxis,a*this.segmentLengthFactor)},updateLSystem:function(){let t=this,e={axiom:this.data.axiom,productions:this.data.productions,iterations:this.data.iterations};return Date.now()-this.worker.startTime>1e3&&(this.worker.terminate(),this.initWorker()),this.worker.startTime=Date.now(),this.workerPromise=new Promise(e=>{this.worker.onmessage=(s=>{t.LSystem.setAxiom(s.data.result),e()})}),this.worker.postMessage(e),this.workerPromise},updateSegmentMixins:function(){var t,e,s,i,o,r,n,a,c,h,u,m;let f=this;this.el.innerHTML="",this.segmentElementGroupsMap=new Map,this.mixinMap=new Map,t=!0,e=!1,s=void 0;try{for(i=this.data.segmentMixins[Symbol.iterator]();!(t=(o=i.next()).done);t=!0){let t=o.value,e=(r=l(t,2))[0],s=r[1];for(let t=0;t{f.pushSegment.bind(f,e)()});for(let t=0;t{let s=document.createElement("a-entity");if(s.setAttribute("id",o+"-group-"+i+Math.floor(1e4*Math.random())),s.setAttribute("geometry","buffer",!1),s.setAttribute("mixin",o),s.addEventListener("loaded",function(){let r=s.getObject3D("mesh").clone();s.getObject3D("mesh").geometry.dispose(),r.geometry=r.geometry.clone();let n=f.calculateSegmentLength(o,r.geometry);if(!0===f.data.mergeGeometries){let t=f.data.translateAxis.clone().multiplyScalar(n*f.segmentLengthFactor/2);r.geometry.translate(t.x,t.y,t.z),f.segmentObjects3DMap.set(e+i,r)}s.removeObject3D("mesh"),t()},{once:!0}),this.segmentElementGroupsMap.has(e+i)){let t=this.segmentElementGroupsMap.get(e+i);this.segmentElementGroupsMap.delete(e+i),this.el.removeChild(t)}this.segmentElementGroupsMap.set(e+i,s),this.el.appendChild(s)}))}}}catch(t){a=!0,c=t}finally{try{!n&&h.return&&h.return()}finally{if(a)throw c}}}},updateTurtleGraphics:async function(){var t,e,s,i,o,r,n,a,c,h,u,m;if(await Promise.all([...this.mixinPromises,this.workerPromise]),this.transformationSegment.copy(this.transformationSegmentTemplate),!0===this.data.mergeGeometries){t=!0,e=!1,s=void 0;try{for(i=this.segmentObjects3DMap[Symbol.iterator]();!(t=(o=i.next()).done);t=!0){let t=o.value,e=(r=l(t,2))[0],s=r[1];this.mergeGroups.set(e,new THREE.Mesh(new THREE.Geometry,s.material))}}catch(t){e=!0,s=t}finally{try{!t&&i.return&&i.return()}finally{if(e)throw s}}}this.stack=[];let f=this.data.angle;if(this.xPosRotation.setFromAxisAngle(this.X,Math.PI/180*f),this.xNegRotation.setFromAxisAngle(this.X,Math.PI/180*-f),this.yPosRotation.setFromAxisAngle(this.Y,Math.PI/180*f),this.yNegRotation.setFromAxisAngle(this.Y,Math.PI/180*-f),this.yReverseRotation.setFromAxisAngle(this.Y,Math.PI/180*180),this.zPosRotation.setFromAxisAngle(this.Z,Math.PI/180*f),this.zNegRotation.setFromAxisAngle(this.Z,Math.PI/180*-f),this.LSystem.final(),!0===this.data.mergeGeometries){n=!0,a=!1,c=void 0;try{for(h=this.segmentElementGroupsMap[Symbol.iterator]();!(n=(u=h.next()).done);n=!0){let t=u.value,e=(m=l(t,2))[0],s=m[1];0===this.mergeGroups.get(e).geometry.vertices.length?this.el.removeChild(s):(s.setObject3D("mesh",this.mergeGroups.get(e)),s.setAttribute("mixin",this.mixinMap.get(e)))}}catch(t){a=!0,c=t}finally{try{!n&&h.return&&h.return()}finally{if(a)throw c}}}},remove:function(){},tick:function(){},pause:function(){},play:function(){}})},function(t,e){"use strict";function s(t){let e,s=t[0].match(/(.+)<(.)/),i=t[0].match(/(.)>(.+)/);if(null===s&&null===i)return t;let o=t[1].successor||t[1].successors?t[1]:{successor:t[1]};return null!==s&&(e=s[2],o.leftCtx=s[1]),null!==i&&(e=i[1],o.rightCtx=i[2]),[e,o]}function i(t){if("string"!=typeof t&&t instanceof String==!1)return t;let e=[];for(let s of t)e.push({symbol:s});return e}function o(t,e){return t[1]=function t(e,s){if(e.hasOwnProperty("successors"))for(var o=0;o{if(void 0===e.symbol)throw console.log("found:",e),Error("L-Systems that use only objects as symbols (eg: {symbol: 'F', params: []}), cant use string symbols (eg. 'F')! Check if you always return objects in your productions and no strings.");return t+e.symbol},""):JSON.stringify(this.axiom)}setProduction(t,e,i=!1){let r=[t,e];if(void 0===r)throw Error("no production specified.");if(e.successor&&e.successors)throw Error('You can not have both a "successor" and a "successors" field in your production!');if(!0===this.allowClassicSyntax&&(r=s(r)),(r=o(r,this.forceObjects))[1].isStochastic=void 0!==r[1].successors&&r[1].successors.every(t=>void 0!==t.weight),r[1].isStochastic)for(let t of(r[1].weightSum=0,r[1].successors))r[1].weightSum+=t.weight;let n=r[0];if(!0===i&&this.productions.has(n)){let t=this.productions.get(n),e=t.successor,s=t.successors;e&&!s&&(t={successors:[t]}),t.successors.push(r[1]),this.productions.set(n,t)}else this.productions.set(n,r[1])}setProductions(t){if(void 0===t)throw Error("no production specified.");for(let e of(this.clearProductions(),Object.entries(t))){let t=e[0],s=e[1];this.setProduction(t,s,!0)}}clearProductions(){this.productions=new Map}setFinal(t,e){let s=[t,e];if(void 0===s)throw Error("no final specified.");this.finals.set(s[0],s[1])}setFinals(t){if(void 0===t)throw Error("no finals specified.");for(let e in this.finals=new Map,t)t.hasOwnProperty(e)&&this.setFinal(e,t[e])}getProductionResult(t,e,s,i,o=!1){let r=void 0!==t.leftCtx||void 0!==t.rightCtx,n=!1,a=!0;if(void 0!==t.condition&&!1===t.condition({index:e,currentAxiom:this.axiom,part:s,params:i})?a=!1:r&&(void 0!==t.leftCtx&&void 0!==t.rightCtx?a=this.match({direction:"left",match:t.leftCtx,index:e,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result&&this.match({direction:"right",match:t.rightCtx,index:e,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result:void 0!==t.leftCtx?a=this.match({direction:"left",match:t.leftCtx,index:e,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result:void 0!==t.rightCtx&&(a=this.match({direction:"right",match:t.rightCtx,index:e,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result)),!1===a)n=!1;else if(t.successors){let o,r;for(let a of(t.isStochastic&&(r=Math.random()*t.weightSum,o=0),t.successors)){if(t.isStochastic&&r>(o+=a.weight))continue;let l=this.getProductionResult(a,e,s,i,!0);if(void 0!==l&&!1!==l){n=l;break}}}else n="function"==typeof t.successor?t.successor({index:e,currentAxiom:this.axiom,part:s,params:i}):t.successor;return n||(o?n:s)}applyProductions(){let t="string"==typeof this.axiom?"":[],e=0;for(let s of this.axiom){let i=s.symbol||s,o=s.params||[],r=s;if(this.productions.has(i)){let t=this.productions.get(i);r=this.getProductionResult(t,e,s,o)}"string"==typeof t?t+=r:r instanceof Array?t.push(...r):t.push(r),e++}return this.axiom=t,t}iterate(t=1){let e;this.iterations=t;for(let s=0;t>s;s++)e=this.applyProductions();return e}final(t){let e=0;for(let s of this.axiom){let i=s;if("object"==typeof s&&s.symbol&&(i=s.symbol),this.finals.has(i)){let o=this.finals.get(i),r=typeof o;if("function"!==r)throw Error("'"+i+"' has an object for a final function. But it is __not a function__ but a "+r+"!");o({index:e,part:s},t)}e++}}match({axiom_:t,match:e,ignoredSymbols:s,branchSymbols:i,index:o,direction:r}){var n,a;let l=0,c=0;t=t||this.axiom,void 0===i&&(i=void 0!==this.branchSymbols?this.branchSymbols:[]),void 0===s&&(s=void 0!==this.ignoredSymbols?this.ignoredSymbols:[]);let h,u,m,f,d,g,y,p=[];if("right"===r)f=g=1,m=o+1,d=0,y=e.length,i.length>0&&(h=(n=i)[0],u=n[1]);else{if("left"!==r)throw Error(r,"is not a valid direction for matching.");f=g=-1,m=o-1,d=e.length-1,y=-1,i.length>0&&(u=(a=i)[0],h=a[1])}for(;m=0;m+=f){let i=t[m].symbol||t[m],o=e[d];if(i===o){if((0===l||c>0)&&(i===h?(c++,l++,d+=g):i===u?(c=Math.max(0,c-1),l=Math.max(0,l-1),0===c&&(d+=g)):(p.push(m),d+=g)),d===y)return{result:!0,matchIndices:p}}else if(i===h)l++,c>0&&c++;else if(i===u)l=Math.max(0,l-1),c>0&&(c=Math.max(0,c-1));else if((0===l||c>0&&o!==u)&&!1===s.includes(i))return{result:!1,matchIndices:p}}return{result:!1,matchIndices:p}}}LSystem.getStringResult=LSystem.getString,LSystem.transformClassicStochasticProductions=function(t){return function(){let e=t,s=e.length,i=Math.random();for(let t=0;s>t;t++)if((t+1)/s>=i)return e[t];console.error("Should have returned a result of the list, something is wrong here with the random numbers?.")}},LSystem.transformClassicCSProduction=s,LSystem.transformClassicParametricAxiom=function(t){let e=t.replace(/\s+/g,"").split(/[\(\)]/),s=[];for(let t=0;t(.+)/);if(null===o&&null===i)return t;let e=t[1].successor||t[1].successors?t[1]:{successor:t[1]};return null!==o&&(s=o[2],e.leftCtx=o[1]),null!==i&&(s=i[1],e.rightCtx=i[2]),[s,e]}function i(t){if("string"!=typeof t&&t instanceof String==!1)return t;let s=[];for(let o of t)s.push({symbol:o});return s}function e(t,s){return t[1]=function t(s,o){if(s.hasOwnProperty("successors"))for(var e=0;e{if(void 0===s.symbol)throw console.log("found:",s),Error("L-Systems that use only objects as symbols (eg: {symbol: \'F\', params: []}), cant use string symbols (eg. \'F\')! Check if you always return objects in your productions and no strings.");return t+s.symbol},""):JSON.stringify(this.axiom)}setProduction(t,s,i=!1){let r=[t,s];if(void 0===r)throw Error("no production specified.");if(s.successor&&s.successors)throw Error(\'You can not have both a "successor" and a "successors" field in your production!\');if(!0===this.allowClassicSyntax&&(r=o(r)),(r=e(r,this.forceObjects))[1].isStochastic=void 0!==r[1].successors&&r[1].successors.every(t=>void 0!==t.weight),r[1].isStochastic)for(let t of(r[1].weightSum=0,r[1].successors))r[1].weightSum+=t.weight;let n=r[0];if(!0===i&&this.productions.has(n)){let t=this.productions.get(n),s=t.successor,o=t.successors;s&&!o&&(t={successors:[t]}),t.successors.push(r[1]),this.productions.set(n,t)}else this.productions.set(n,r[1])}setProductions(t){if(void 0===t)throw Error("no production specified.");for(let s of(this.clearProductions(),Object.entries(t))){let t=s[0],o=s[1];this.setProduction(t,o,!0)}}clearProductions(){this.productions=new Map}setFinal(t,s){let o=[t,s];if(void 0===o)throw Error("no final specified.");this.finals.set(o[0],o[1])}setFinals(t){if(void 0===t)throw Error("no finals specified.");for(let s in this.finals=new Map,t)t.hasOwnProperty(s)&&this.setFinal(s,t[s])}getProductionResult(t,s,o,i,e=!1){let r=void 0!==t.leftCtx||void 0!==t.rightCtx,n=!1,c=!0;if(void 0!==t.condition&&!1===t.condition({index:s,currentAxiom:this.axiom,part:o,params:i})?c=!1:r&&(void 0!==t.leftCtx&&void 0!==t.rightCtx?c=this.match({direction:"left",match:t.leftCtx,index:s,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result&&this.match({direction:"right",match:t.rightCtx,index:s,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result:void 0!==t.leftCtx?c=this.match({direction:"left",match:t.leftCtx,index:s,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result:void 0!==t.rightCtx&&(c=this.match({direction:"right",match:t.rightCtx,index:s,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result)),!1===c)n=!1;else if(t.successors){let e,r;for(let c of(t.isStochastic&&(r=Math.random()*t.weightSum,e=0),t.successors)){if(t.isStochastic&&r>(e+=c.weight))continue;let a=this.getProductionResult(c,s,o,i,!0);if(void 0!==a&&!1!==a){n=a;break}}}else n="function"==typeof t.successor?t.successor({index:s,currentAxiom:this.axiom,part:o,params:i}):t.successor;return n||(e?n:o)}applyProductions(){let t="string"==typeof this.axiom?"":[],s=0;for(let o of this.axiom){let i=o.symbol||o,e=o.params||[],r=o;if(this.productions.has(i)){let t=this.productions.get(i);r=this.getProductionResult(t,s,o,e)}"string"==typeof t?t+=r:r instanceof Array?t.push(...r):t.push(r),s++}return this.axiom=t,t}iterate(t=1){let s;this.iterations=t;for(let o=0;t>o;o++)s=this.applyProductions();return s}final(t){let s=0;for(let o of this.axiom){let i=o;if("object"==typeof o&&o.symbol&&(i=o.symbol),this.finals.has(i)){let e=this.finals.get(i),r=typeof e;if("function"!==r)throw Error("\'"+i+"\' has an object for a final function. But it is __not a function__ but a "+r+"!");e({index:s,part:o},t)}s++}}match({axiom_:t,match:s,ignoredSymbols:o,branchSymbols:i,index:e,direction:r}){var n,c;let a=0,l=0;t=t||this.axiom,void 0===i&&(i=void 0!==this.branchSymbols?this.branchSymbols:[]),void 0===o&&(o=void 0!==this.ignoredSymbols?this.ignoredSymbols:[]);let u,h,f,d,m,y,b,g=[];if("right"===r)d=y=1,f=e+1,m=0,b=s.length,i.length>0&&(u=(n=i)[0],h=n[1]);else{if("left"!==r)throw Error(r,"is not a valid direction for matching.");d=y=-1,f=e-1,m=s.length-1,b=-1,i.length>0&&(h=(c=i)[0],u=c[1])}for(;f=0;f+=d){let i=t[f].symbol||t[f],e=s[m];if(i===e){if((0===a||l>0)&&(i===u?(l++,a++,m+=y):i===h?(l=Math.max(0,l-1),a=Math.max(0,a-1),0===l&&(m+=y)):(g.push(f),m+=y)),m===b)return{result:!0,matchIndices:g}}else if(i===u)a++,l>0&&l++;else if(i===h)a=Math.max(0,a-1),l>0&&(l=Math.max(0,l-1));else if((0===a||l>0&&e!==h)&&!1===o.includes(i))return{result:!1,matchIndices:g}}return{result:!1,matchIndices:g}}}LSystem.getStringResult=LSystem.getString,LSystem.transformClassicStochasticProductions=function(t){return function(){let s=t,o=s.length,i=Math.random();for(let t=0;o>t;t++)if((t+1)/o>=i)return s[t];console.error("Should have returned a result of the list, something is wrong here with the random numbers?.")}},LSystem.transformClassicCSProduction=o,LSystem.transformClassicParametricAxiom=function(t){let s=t.replace(/\\s+/g,"").split(/[\\(\\)]/),o=[];for(let t=0;t
2 |
3 | Testing experimental things
4 |
5 |
6 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |