var hasFloat32Array="undefined"!=typeof Float32Array;function Matrix(){var c=Array.prototype.concat.apply([],arguments);c.length||(c=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);this.m=hasFloat32Array?new Float32Array(c):c}
Matrix.prototype={inverse:function(){return Matrix.inverse(this,new Matrix)},transpose:function(){return Matrix.transpose(this,new Matrix)},multiply:function(c){return Matrix.multiply(this,c,new Matrix)},transformPoint:function(c){var b=this.m;return(new Vector(b[0]*c.x+b[1]*c.y+b[2]*c.z+b[3],b[4]*c.x+b[5]*c.y+b[6]*c.z+b[7],b[8]*c.x+b[9]*c.y+b[10]*c.z+b[11])).divide(b[12]*c.x+b[13]*c.y+b[14]*c.z+b[15])},transformVector:function(c){var b=this.m;return new Vector(b[0]*c.x+b[1]*c.y+b[2]*c.z,b[4]*c.x+
b[5]*c.y+b[6]*c.z,b[8]*c.x+b[9]*c.y+b[10]*c.z)}};
Matrix.inverse=function(c,b){b=b||new Matrix;var a=c.m,d=b.m;d[0]=a[5]*a[10]*a[15]-a[5]*a[14]*a[11]-a[6]*a[9]*a[15]+a[6]*a[13]*a[11]+a[7]*a[9]*a[14]-a[7]*a[13]*a[10];d[1]=-a[1]*a[10]*a[15]+a[1]*a[14]*a[11]+a[2]*a[9]*a[15]-a[2]*a[13]*a[11]-a[3]*a[9]*a[14]+a[3]*a[13]*a[10];d[2]=a[1]*a[6]*a[15]-a[1]*a[14]*a[7]-a[2]*a[5]*a[15]+a[2]*a[13]*a[7]+a[3]*a[5]*a[14]-a[3]*a[13]*a[6];d[3]=-a[1]*a[6]*a[11]+a[1]*a[10]*a[7]+a[2]*a[5]*a[11]-a[2]*a[9]*a[7]-a[3]*a[5]*a[10]+a[3]*a[9]*a[6];d[4]=-a[4]*a[10]*a[15]+a[4]*
a[14]*a[11]+a[6]*a[8]*a[15]-a[6]*a[12]*a[11]-a[7]*a[8]*a[14]+a[7]*a[12]*a[10];d[5]=a[0]*a[10]*a[15]-a[0]*a[14]*a[11]-a[2]*a[8]*a[15]+a[2]*a[12]*a[11]+a[3]*a[8]*a[14]-a[3]*a[12]*a[10];d[6]=-a[0]*a[6]*a[15]+a[0]*a[14]*a[7]+a[2]*a[4]*a[15]-a[2]*a[12]*a[7]-a[3]*a[4]*a[14]+a[3]*a[12]*a[6];d[7]=a[0]*a[6]*a[11]-a[0]*a[10]*a[7]-a[2]*a[4]*a[11]+a[2]*a[8]*a[7]+a[3]*a[4]*a[10]-a[3]*a[8]*a[6];d[8]=a[4]*a[9]*a[15]-a[4]*a[13]*a[11]-a[5]*a[8]*a[15]+a[5]*a[12]*a[11]+a[7]*a[8]*a[13]-a[7]*a[12]*a[9];d[9]=-a[0]*a[9]*
a[15]+a[0]*a[13]*a[11]+a[1]*a[8]*a[15]-a[1]*a[12]*a[11]-a[3]*a[8]*a[13]+a[3]*a[12]*a[9];d[10]=a[0]*a[5]*a[15]-a[0]*a[13]*a[7]-a[1]*a[4]*a[15]+a[1]*a[12]*a[7]+a[3]*a[4]*a[13]-a[3]*a[12]*a[5];d[11]=-a[0]*a[5]*a[11]+a[0]*a[9]*a[7]+a[1]*a[4]*a[11]-a[1]*a[8]*a[7]-a[3]*a[4]*a[9]+a[3]*a[8]*a[5];d[12]=-a[4]*a[9]*a[14]+a[4]*a[13]*a[10]+a[5]*a[8]*a[14]-a[5]*a[12]*a[10]-a[6]*a[8]*a[13]+a[6]*a[12]*a[9];d[13]=a[0]*a[9]*a[14]-a[0]*a[13]*a[10]-a[1]*a[8]*a[14]+a[1]*a[12]*a[10]+a[2]*a[8]*a[13]-a[2]*a[12]*a[9];d[14]=
-a[0]*a[5]*a[14]+a[0]*a[13]*a[6]+a[1]*a[4]*a[14]-a[1]*a[12]*a[6]-a[2]*a[4]*a[13]+a[2]*a[12]*a[5];d[15]=a[0]*a[5]*a[10]-a[0]*a[9]*a[6]-a[1]*a[4]*a[10]+a[1]*a[8]*a[6]+a[2]*a[4]*a[9]-a[2]*a[8]*a[5];for(var a=a[0]*d[0]+a[1]*d[4]+a[2]*d[8]+a[3]*d[12],f=0;16>f;f++)d[f]/=a;return b};
Matrix.transpose=function(c,b){b=b||new Matrix;var a=c.m,d=b.m;d[0]=a[0];d[1]=a[4];d[2]=a[8];d[3]=a[12];d[4]=a[1];d[5]=a[5];d[6]=a[9];d[7]=a[13];d[8]=a[2];d[9]=a[6];d[10]=a[10];d[11]=a[14];d[12]=a[3];d[13]=a[7];d[14]=a[11];d[15]=a[15];return b};
Matrix.multiply=function(c,b,a){a=a||new Matrix;c=c.m;b=b.m;var d=a.m;d[0]=c[0]*b[0]+c[1]*b[4]+c[2]*b[8]+c[3]*b[12];d[1]=c[0]*b[1]+c[1]*b[5]+c[2]*b[9]+c[3]*b[13];d[2]=c[0]*b[2]+c[1]*b[6]+c[2]*b[10]+c[3]*b[14];d[3]=c[0]*b[3]+c[1]*b[7]+c[2]*b[11]+c[3]*b[15];d[4]=c[4]*b[0]+c[5]*b[4]+c[6]*b[8]+c[7]*b[12];d[5]=c[4]*b[1]+c[5]*b[5]+c[6]*b[9]+c[7]*b[13];d[6]=c[4]*b[2]+c[5]*b[6]+c[6]*b[10]+c[7]*b[14];d[7]=c[4]*b[3]+c[5]*b[7]+c[6]*b[11]+c[7]*b[15];d[8]=c[8]*b[0]+c[9]*b[4]+c[10]*b[8]+c[11]*b[12];d[9]=c[8]*b[1]+
c[9]*b[5]+c[10]*b[9]+c[11]*b[13];d[10]=c[8]*b[2]+c[9]*b[6]+c[10]*b[10]+c[11]*b[14];d[11]=c[8]*b[3]+c[9]*b[7]+c[10]*b[11]+c[11]*b[15];d[12]=c[12]*b[0]+c[13]*b[4]+c[14]*b[8]+c[15]*b[12];d[13]=c[12]*b[1]+c[13]*b[5]+c[14]*b[9]+c[15]*b[13];d[14]=c[12]*b[2]+c[13]*b[6]+c[14]*b[10]+c[15]*b[14];d[15]=c[12]*b[3]+c[13]*b[7]+c[14]*b[11]+c[15]*b[15];return a};Matrix.identity=function(c){c=c||new Matrix;var b=c.m;b[0]=b[5]=b[10]=b[15]=1;b[1]=b[2]=b[3]=b[4]=b[6]=b[7]=b[8]=b[9]=b[11]=b[12]=b[13]=b[14]=0;return c};
Matrix.perspective=function(c,b,a,d,f){c=Math.tan(c*Math.PI/360)*a;b*=c;return Matrix.frustum(-b,b,-c,c,a,d,f)};Matrix.frustum=function(c,b,a,d,f,h,e){e=e||new Matrix;var g=e.m;g[0]=2*f/(b-c);g[1]=0;g[2]=(b+c)/(b-c);g[3]=0;g[4]=0;g[5]=2*f/(d-a);g[6]=(d+a)/(d-a);g[7]=0;g[8]=0;g[9]=0;g[10]=-(h+f)/(h-f);g[11]=-2*h*f/(h-f);g[12]=0;g[13]=0;g[14]=-1;g[15]=0;return e};
Matrix.ortho=function(c,b,a,d,f,h,e){e=e||new Matrix;var g=e.m;g[0]=2/(b-c);g[1]=0;g[2]=0;g[3]=-(b+c)/(b-c);g[4]=0;g[5]=2/(d-a);g[6]=0;g[7]=-(d+a)/(d-a);g[8]=0;g[9]=0;g[10]=-2/(h-f);g[11]=-(h+f)/(h-f);g[12]=0;g[13]=0;g[14]=0;g[15]=1;return e};Matrix.scale=function(c,b,a,d){d=d||new Matrix;var f=d.m;f[0]=c;f[1]=0;f[2]=0;f[3]=0;f[4]=0;f[5]=b;f[6]=0;f[7]=0;f[8]=0;f[9]=0;f[10]=a;f[11]=0;f[12]=0;f[13]=0;f[14]=0;f[15]=1;return d};
Matrix.translate=function(c,b,a,d){d=d||new Matrix;var f=d.m;f[0]=1;f[1]=0;f[2]=0;f[3]=c;f[4]=0;f[5]=1;f[6]=0;f[7]=b;f[8]=0;f[9]=0;f[10]=1;f[11]=a;f[12]=0;f[13]=0;f[14]=0;f[15]=1;return d};
Matrix.rotate=function(c,b,a,d,f){if(!c||!b&&!a&&!d)return Matrix.identity(f);f=f||new Matrix;var h=f.m,e=Math.sqrt(b*b+a*a+d*d);c*=Math.PI/180;b/=e;a/=e;d/=e;e=Math.cos(c);c=Math.sin(c);var g=1-e;h[0]=b*b*g+e;h[1]=b*a*g-d*c;h[2]=b*d*g+a*c;h[3]=0;h[4]=a*b*g+d*c;h[5]=a*a*g+e;h[6]=a*d*g-b*c;h[7]=0;h[8]=d*b*g-a*c;h[9]=d*a*g+b*c;h[10]=d*d*g+e;h[11]=0;h[12]=0;h[13]=0;h[14]=0;h[15]=1;return f};
Matrix.lookAt=function(c,b,a,d,f,h,e,g,k,l){l=l||new Matrix;var m=l.m;c=new Vector(c,b,a);d=new Vector(d,f,h);g=new Vector(e,g,k);e=c.subtract(d).unit();g=g.cross(e).unit();k=e.cross(g).unit();m[0]=g.x;m[1]=g.y;m[2]=g.z;m[3]=-g.dot(c);m[4]=k.x;m[5]=k.y;m[6]=k.z;m[7]=-k.dot(c);m[8]=e.x;m[9]=e.y;m[10]=e.z;m[11]=-e.dot(c);m[12]=0;m[13]=0;m[14]=0;m[15]=1;return l};function Vector(c,b,a){this.x=c||0;this.y=b||0;this.z=a||0}
Vector.prototype={negative:function(){return new Vector(-this.x,-this.y,-this.z)},add:function(c){return c instanceof Vector?new Vector(this.x+c.x,this.y+c.y,this.z+c.z):new Vector(this.x+c,this.y+c,this.z+c)},subtract:function(c){return c instanceof Vector?new Vector(this.x-c.x,this.y-c.y,this.z-c.z):new Vector(this.x-c,this.y-c,this.z-c)},multiply:function(c){return c instanceof Vector?new Vector(this.x*c.x,this.y*c.y,this.z*c.z):new Vector(this.x*c,this.y*c,this.z*c)},divide:function(c){return c instanceof
Vector?new Vector(this.x/c.x,this.y/c.y,this.z/c.z):new Vector(this.x/c,this.y/c,this.z/c)},equals:function(c){return this.x==c.x&&this.y==c.y&&this.z==c.z},dot:function(c){return this.x*c.x+this.y*c.y+this.z*c.z},cross:function(c){return new Vector(this.y*c.z-this.z*c.y,this.z*c.x-this.x*c.z,this.x*c.y-this.y*c.x)},length:function(){return Math.sqrt(this.dot(this))},unit:function(){return this.divide(this.length())},min:function(){return Math.min(Math.min(this.x,this.y),this.z)},max:function(){return Math.max(Math.max(this.x,
this.y),this.z)},toAngles:function(){return{theta:Math.atan2(this.z,this.x),phi:Math.asin(this.y/this.length())}},angleTo:function(c){return Math.acos(this.dot(c)/(this.length()*c.length()))},toArray:function(c){return[this.x,this.y,this.z].slice(0,c||3)},clone:function(){return new Vector(this.x,this.y,this.z)},init:function(c,b,a){this.x=c;this.y=b;this.z=a;return this}};Vector.negative=function(c,b){b.x=-c.x;b.y=-c.y;b.z=-c.z;return b};
Vector.add=function(c,b,a){b instanceof Vector?(a.x=c.x+b.x,a.y=c.y+b.y,a.z=c.z+b.z):(a.x=c.x+b,a.y=c.y+b,a.z=c.z+b);return a};Vector.subtract=function(c,b,a){b instanceof Vector?(a.x=c.x-b.x,a.y=c.y-b.y,a.z=c.z-b.z):(a.x=c.x-b,a.y=c.y-b,a.z=c.z-b);return a};Vector.multiply=function(c,b,a){b instanceof Vector?(a.x=c.x*b.x,a.y=c.y*b.y,a.z=c.z*b.z):(a.x=c.x*b,a.y=c.y*b,a.z=c.z*b);return a};
Vector.divide=function(c,b,a){b instanceof Vector?(a.x=c.x/b.x,a.y=c.y/b.y,a.z=c.z/b.z):(a.x=c.x/b,a.y=c.y/b,a.z=c.z/b);return a};Vector.cross=function(c,b,a){a.x=c.y*b.z-c.z*b.y;a.y=c.z*b.x-c.x*b.z;a.z=c.x*b.y-c.y*b.x;return a};Vector.unit=function(c,b){var a=c.length();b.x=c.x/a;b.y=c.y/a;b.z=c.z/a;return b};Vector.fromAngles=function(c,b){return new Vector(Math.cos(c)*Math.cos(b),Math.sin(b),Math.sin(c)*Math.cos(b))};
Vector.randomDirection=function(){return Vector.fromAngles(Math.random()*Math.PI*2,Math.asin(2*Math.random()-1))};Vector.min=function(c,b){return new Vector(Math.min(c.x,b.x),Math.min(c.y,b.y),Math.min(c.z,b.z))};Vector.max=function(c,b){return new Vector(Math.max(c.x,b.x),Math.max(c.y,b.y),Math.max(c.z,b.z))};Vector.lerp=function(c,b,a){return b.subtract(c).multiply(a).add(c)};Vector.fromArray=function(c){return new Vector(c[0],c[1],c[2])};Vector.angleBetween=function(c,b){return c.angleTo(b)};var CatmullRomSpline=function(){this.outputPath=null};CatmullRomSpline.prototype.interpolate=function(c,b,a){var d=c[Math.max(0,b-1)],f=c[b],h=c[Math.min(b+1,c.length-1)];c=c[Math.min(b+2,c.length-1)];var e=Math.pow(a,3),g=Math.pow(a,2);b=-.5*e+g-.5*a;var k=1.5*e-2.5*g+1;a=-1.5*e+2*g+.5*a;e=.5*e-.5*g;return{x:d.x*b+f.x*k+h.x*a+c.x*e,y:d.y*b+f.y*k+h.y*a+c.y*e,z:d.z*b+f.z*k+h.z*a+c.z*e}};
CatmullRomSpline.prototype.calculateSpline=function(c,b){if(void 0===c||!(c instanceof Array)||3>c.length)return debugErrorPrint("Spline path must be an array that contains vector data"),[];this.outputPath=[];for(var a=0;a<c.length-1;a++)for(var d=0;d<b;d++){var f=this.interpolate(c,a,d/(b-1));this.outputPath.push(f)}return this.outputPath};CatmullRomSpline.prototype.getSpline=function(c){return this.outputPath};var Input=function(){};Input.events=[];Input.eventClearTime=1;Input.mouse={x:-1,y:-1};Input.addEvent=function(c){void 0!==c.mouse&&(Input.mouse.x=c.mouse.x,Input.mouse.y=c.mouse.y);Input.events.push(c)};Input.hasEvents=function(){return 0<Input.events.length?!0:!1};Input.pollEvent=function(){return 0==Input.events.length?null:Input.events.pop()};
Input.type={NOEVENT:0,ACTIVEEVENT:1,KEYDOWN:2,KEYUP:3,MOUSEMOTION:4,MOUSEBUTTONDOWN:5,MOUSEBUTTONUP:6,JOYAXISMOTION:7,JOYBALLMOTION:8,JOYHATMOTION:9,JOYBUTTONDOWN:10,JOYBUTTONUP:11,QUIT:12,SYSWMEVENT:13,EVENT_RESERVEDA:14,EVENT_RESERVEDB:15,VIDEORESIZE:16,VIDEOEXPOSE:17,USEREVENT:24};
Input.Keyboard={state:{RELEASED:0,PRESSED:1},symbol:{KEY_UNKNOWN:0,KEY_FIRST:0,KEY_BACKSPACE:8,KEY_TAB:9,KEY_CLEAR:12,KEY_RETURN:13,KEY_PAUSE:19,KEY_ESCAPE:27,KEY_SPACE:32,KEY_EXCLAIM:33,KEY_QUOTEDBL:34,KEY_HASH:35,KEY_DOLLAR:36,KEY_AMPERSAND:38,KEY_QUOTE:39,KEY_LEFTPAREN:40,KEY_RIGHTPAREN:41,KEY_ASTERISK:42,KEY_PLUS:43,KEY_COMMA:44,KEY_MINUS:45,KEY_PERIOD:46,KEY_SLASH:47,KEY_0:48,KEY_1:49,KEY_2:50,KEY_3:51,KEY_4:52,KEY_5:53,KEY_6:54,KEY_7:55,KEY_8:56,KEY_9:57,KEY_COLON:58,KEY_SEMICOLON:59,KEY_LESS:60,
KEY_EQUALS:61,KEY_GREATER:62,KEY_QUESTION:63,KEY_AT:64,KEY_LEFTBRACKET:91,KEY_BACKSLASH:92,KEY_RIGHTBRACKET:93,KEY_CARET:94,KEY_UNDERSCORE:95,KEY_BACKQUOTE:96,KEY_a:97,KEY_b:98,KEY_c:99,KEY_d:100,KEY_e:101,KEY_f:102,KEY_g:103,KEY_h:104,KEY_i:105,KEY_j:106,KEY_k:107,KEY_l:108,KEY_m:109,KEY_n:110,KEY_o:111,KEY_p:112,KEY_q:113,KEY_r:114,KEY_s:115,KEY_t:116,KEY_u:117,KEY_v:118,KEY_w:119,KEY_x:120,KEY_y:121,KEY_z:122,KEY_DELETE:127,KEY_WORLD_0:160,KEY_WORLD_1:161,KEY_WORLD_2:162,KEY_WORLD_3:163,KEY_WORLD_4:164,
KEY_WORLD_5:165,KEY_WORLD_6:166,KEY_WORLD_7:167,KEY_WORLD_8:168,KEY_WORLD_9:169,KEY_WORLD_10:170,KEY_WORLD_11:171,KEY_WORLD_12:172,KEY_WORLD_13:173,KEY_WORLD_14:174,KEY_WORLD_15:175,KEY_WORLD_16:176,KEY_WORLD_17:177,KEY_WORLD_18:178,KEY_WORLD_19:179,KEY_WORLD_20:180,KEY_WORLD_21:181,KEY_WORLD_22:182,KEY_WORLD_23:183,KEY_WORLD_24:184,KEY_WORLD_25:185,KEY_WORLD_26:186,KEY_WORLD_27:187,KEY_WORLD_28:188,KEY_WORLD_29:189,KEY_WORLD_30:190,KEY_WORLD_31:191,KEY_WORLD_32:192,KEY_WORLD_33:193,KEY_WORLD_34:194,
KEY_WORLD_35:195,KEY_WORLD_36:196,KEY_WORLD_37:197,KEY_WORLD_38:198,KEY_WORLD_39:199,KEY_WORLD_40:200,KEY_WORLD_41:201,KEY_WORLD_42:202,KEY_WORLD_43:203,KEY_WORLD_44:204,KEY_WORLD_45:205,KEY_WORLD_46:206,KEY_WORLD_47:207,KEY_WORLD_48:208,KEY_WORLD_49:209,KEY_WORLD_50:210,KEY_WORLD_51:211,KEY_WORLD_52:212,KEY_WORLD_53:213,KEY_WORLD_54:214,KEY_WORLD_55:215,KEY_WORLD_56:216,KEY_WORLD_57:217,KEY_WORLD_58:218,KEY_WORLD_59:219,KEY_WORLD_60:220,KEY_WORLD_61:221,KEY_WORLD_62:222,KEY_WORLD_63:223,KEY_WORLD_64:224,
KEY_WORLD_65:225,KEY_WORLD_66:226,KEY_WORLD_67:227,KEY_WORLD_68:228,KEY_WORLD_69:229,KEY_WORLD_70:230,KEY_WORLD_71:231,KEY_WORLD_72:232,KEY_WORLD_73:233,KEY_WORLD_74:234,KEY_WORLD_75:235,KEY_WORLD_76:236,KEY_WORLD_77:237,KEY_WORLD_78:238,KEY_WORLD_79:239,KEY_WORLD_80:240,KEY_WORLD_81:241,KEY_WORLD_82:242,KEY_WORLD_83:243,KEY_WORLD_84:244,KEY_WORLD_85:245,KEY_WORLD_86:246,KEY_WORLD_87:247,KEY_WORLD_88:248,KEY_WORLD_89:249,KEY_WORLD_90:250,KEY_WORLD_91:251,KEY_WORLD_92:252,KEY_WORLD_93:253,KEY_WORLD_94:254,
KEY_WORLD_95:255,KEY_KP0:256,KEY_KP1:257,KEY_KP2:258,KEY_KP3:259,KEY_KP4:260,KEY_KP5:261,KEY_KP6:262,KEY_KP7:263,KEY_KP8:264,KEY_KP9:265,KEY_KP_PERIOD:266,KEY_KP_DIVIDE:267,KEY_KP_MULTIPLY:268,KEY_KP_MINUS:269,KEY_KP_PLUS:270,KEY_KP_ENTER:271,KEY_KP_EQUALS:272,KEY_UP:273,KEY_DOWN:274,KEY_RIGHT:275,KEY_LEFT:276,KEY_INSERT:277,KEY_HOME:278,KEY_END:279,KEY_PAGEUP:280,KEY_PAGEDOWN:281,KEY_F1:282,KEY_F2:283,KEY_F3:284,KEY_F4:285,KEY_F5:286,KEY_F6:287,KEY_F7:288,KEY_F8:289,KEY_F9:290,KEY_F10:291,KEY_F11:292,
KEY_F12:293,KEY_F13:294,KEY_F14:295,KEY_F15:296,KEY_NUMLOCK:300,KEY_CAPSLOCK:301,KEY_SCROLLOCK:302,KEY_RSHIFT:303,KEY_LSHIFT:304,KEY_RCTRL:305,KEY_LCTRL:306,KEY_RALT:307,KEY_LALT:308,KEY_RMETA:309,KEY_LMETA:310,KEY_LSUPER:311,KEY_RSUPER:312,KEY_MODE:313,KEY_COMPOSE:314,KEY_HELP:315,KEY_PRINT:316,KEY_SYSREQ:317,KEY_BREAK:318,KEY_MENU:319,KEY_POWER:320,KEY_EURO:321,KEY_UNDO:322}};String.prototype.endsWith=function(c){return-1!==this.indexOf(c,this.length-c.length)};var Utils=function(){};Utils.clamp=function(c){return Utils.clampRange(c,0,1)};Utils.clampRange=function(c,b,a){return Math.min(Math.max(c,b),a)};Utils.calculateProgress=function(c,b,a){c=(getSceneTimeFromStart()-c)/b;!0!==a&&(c=Utils.clamp(c));return c};
Utils.debugPrintStackTrace=function(){for(var c=["stack trace:"],b=0,a=-3;;a--){var d=Duktape.act(a);if(!d)break;if(""!=d.function.name){var f="\tstack: "+a,f=f+(", function: "+d.function.name),f=f+(", line: "+d.lineNumber),f=f+(", info: "+Duktape.enc("jx",d));c[++b]=f}}1<c.length&&debugPrint(c.join("\n"))};Utils.isString=function(c){return"string"===typeof c||c instanceof String?!0:!1};Utils.isNumeric=function(c){return!isNaN(parseFloat(c))&&isFinite(c)?!0:!1};
Utils.isVideo=function(c){return c.endsWith(".ogv")||c.endsWith(".ogg")?!0:!1};Utils.evaluateVariable=function(c,b){return Utils.isString(b)&&"{"===b.charAt(0)?(new Function("animation",b))(c):b};Utils.deepCopyJson=function(c){var b=JSON.parse(JSON.stringify(c));void 0!==c.ptr&&(b.ptr=c.ptr);void 0!==c.ref&&void 0!==c.ref.ptr&&(b.ref.ptr=c.ref.ptr);return b};Utils.getRandomArrayIndex=function(c){if(void 0!==c.length)return Math.floor(random()*c.length)};
Utils.setTimeVariables=function(c,b,a,d){Utils.isString(c.start)&&(c.start=convertTimeToSeconds(c.start));Utils.isString(c.duration)&&(c.duration=convertTimeToSeconds(c.duration));Utils.isString(c.end)&&(c.end=convertTimeToSeconds(c.end));void 0===c.start&&(c.start=b);void 0===c.duration&&(void 0!==c.end?c.duration=c.end-c.start:(c.duration=d,c.end=c.start+c.duration));void 0===c.end&&(c.end=c.start+c.duration)};
Utils.preprocessTimeAnimation=function(c,b,a,d){if(void 0!==d)for(var f=0;f<d.length;f++){var h=d[f];Utils.setTimeVariables(h,c,a,b);c=h.end;b=h.duration;a=c+b}};var Shader=function(c){};Shader.increaseLoaderResourceCountWithShaders=function(){void 0!==Settings.demoScript.shaders&&setResourceCount(Settings.demoScript.shaders.length);void 0!==Settings.demoScript.shaderPrograms&&setResourceCount(Settings.demoScript.shaderPrograms.length)};
Shader.compileAndLinkShaders=function(){Shader.increaseLoaderResourceCountWithShaders();if(void 0!==Settings.demoScript.shaders)for(var c=0;c<Settings.demoScript.shaders.length;c++){if(isUserExit())return;var b=Settings.demoScript.shaders[c];!0!==b.skip&&(b.ref=shaderLoad(b.name,b.filename),notifyResourceLoaded())}if(void 0!==Settings.demoScript.shaderPrograms)for(var a=0;a<Settings.demoScript.shaderPrograms.length&&!isUserExit();a++){var d=Settings.demoScript.shaderPrograms[a];if(!0!==d.skip){d.ref=
shaderProgramLoad(d.name);for(c=0;c<d.shaders.length;c++)b=d.shaders[c],shaderProgramAddShaderByName(d.name,b.name);shaderProgramAttachAndLink(d.ref.ptr);notifyResourceLoaded()}}};Shader.load=function(c){var b=getShaderProgramFromMemory(c.programName);if(void 0===b.ptr){for(var b=shaderProgramLoad(c.programName),a=0;a<c.name.length;a++){var d=c.name[a];1==shaderLoad(d,d).ok&&shaderProgramAddShaderByName(c.programName,d)}shaderProgramAttachAndLink(b.ptr)}return b};
Shader.enableShader=function(c){if(void 0!==c.shader&&(shaderProgramUse(c.shader.ref.ptr),void 0!==c.shader.variable))for(var b=getUniformLocation,a=glUniformi,d=glUniformf,f,h=c.shader.variable.length,e=0;e<h;e++){var g=c.shader.variable[e],k=b(g.name);f=d;"int"===g.type&&(f=a);var l=[];if(!0===Utils.isString(g.value))l=Utils.evaluateVariable(c,g.value);else for(var m=g.value.length,n=0;n<m;n++)l.push(Utils.evaluateVariable(c,g.value[n]));m=l.length;switch(m){case 1:f(k,l[0]);break;case 2:f(k,l[0],
l[1]);break;case 3:f(k,l[0],l[1],l[2]);break;case 4:f(k,l[0],l[1],l[2],l[3])}}};Shader.disableShader=function(c){void 0!==c.shader&&disableShaderProgram()};var Sync=function(){};Sync.syncDefinitions={};Sync.addSync=function(c){for(var b=0,a=0,d=0,f=0;f<c.length;f++){var h=c[f];Utils.setTimeVariables(h,b,a,d);b=h.start;a=h.end;d=a-b;"rocket"===h.type&&(h.ref=syncEditorGetTrack(h.name));void 0===h.pattern&&(h.pattern=[{}],void 0===h.ref&&(h.pattern=[{start:b,duration:d}]));Utils.preprocessTimeAnimation(b,d,a,h.pattern);for(var e=0;e<h.pattern.length;e++){var g=h.pattern[e];g.started=!1;g.counter=0}Sync.syncDefinitions[h.name]=h}};
Sync.getSyncValue=function(c){c=Sync.syncDefinitions[c];return void 0!==c&&void 0!==c.ref?syncEditorGetTrackCurrentValue(c.ref.ptr):0};
Sync.calculateAnimationSync=function(c,b){if(void 0!==b.sync){var a=Sync.syncDefinitions[b.sync.name];if(void 0!==a){var d=c%a.end;b.sync.progress=0;if(void 0!==a.ref)b.sync.progress=syncEditorGetTrackCurrentValue(a.ref.ptr),void 0!==a.syncStartFunction&&void 0===a.started&&(a.started=!0,Utils.evaluateVariable(b,a.syncStartFunction)),void 0!==a.syncRunFunction&&Utils.evaluateVariable(b,a.syncRunFunction);else for(var f=a.pattern.length,h=0;h<f;h++){var e=a.pattern[h];d>=e.start&&d<e.end&&(b.sync.progress=
(d-e.start)/e.duration,1<b.sync.progress&&(b.sync.progress=1),e.started||(e.started=!0,e.startTime=c,void 0!==e.syncStartFunction?Utils.evaluateVariable(b,e.syncStartFunction):void 0!==a.syncStartFunction&&Utils.evaluateVariable(b,a.syncStartFunction)),void 0!==e.syncRunFunction?Utils.evaluateVariable(b,e.syncRunFunction):void 0!==a.syncRunFunction&&Utils.evaluateVariable(b,a.syncRunFunction));e.started&&(c>=e.startTime+e.duration||e.startTime>c)&&(e.started=!1,b.sync.progress=0,void 0!==e.syncEndFunction?
Utils.evaluateVariable(b,e.syncEndFunction):void 0!==a.syncEndFunction&&Utils.evaluateVariable(b,a.syncEndFunction))}}}};var Constants=function(){};Constants.Align={NONE:0,CENTER:1,HORIZONTAL:2,VERTICAL:3,LEFT:4,RIGHT:5};var Settings=function(){};Settings.sceneVariables={};Settings.processVariables=function(c){if(c.hasOwnProperty("variables")){Settings.sceneVariables[c.name]=c.variables;for(var b in c.variables){var a=c.variables[b];addTwVariable(c.name,b,a.type,a.definition)}}};
Settings.processDemoScript=function(){evalFile("data/js/script.js");Settings.sceneVariables={};setPlaylistMusic(Settings.demoScript.music);setPlaylistLength(Settings.demoScript.totalTime);jsSetUseInput(!0===Settings.demoScript.useInput?1:0);void 0!==Settings.demoScript.screen&&(setScreenDimensions(Settings.demoScript.screen.width,Settings.demoScript.screen.height),void 0!==Settings.demoScript.screen.aspectRatio?setWindowScreenAreaAspectRatio(Settings.demoScript.screen.aspectRatio.width,Settings.demoScript.screen.aspectRatio.height):
setWindowScreenAreaAspectRatio(Settings.demoScript.screen.width,Settings.demoScript.screen.height));!0===Settings.demoScript.jumalauta&&windowSetTitle("Jumalauta!");void 0!==Settings.demoScript.fps&&timerSetTargetFps(Settings.demoScript.fps);void 0!==Settings.demoScript.window&&void 0!==Settings.demoScript.window.title&&windowSetTitle(Settings.demoScript.window.title);if(void 0!==Settings.demoScript.clearColor){var c=Settings.demoScript.clearColor;setClearColor(c.r,c.g,c.b,c.a)}void 0!==Settings.demoScript.beatsPerMinute&&
timerSetBeatsPerMinute(Settings.demoScript.beatsPerMinute);void 0!==Settings.demoScript.rowsPerBeat&&syncEditorSetRowsPerBeat(Settings.demoScript.rowsPerBeat);if(void 0!==Settings.demoScript.resolutions)for(c=0;c<Settings.demoScript.resolutions.length;c++)setMenuResolution(c,Settings.demoScript.resolutions[c].width+"x"+Settings.demoScript.resolutions[c].height),!0===Settings.demoScript.resolutions[c].selected&&setMenuComponentSelected(c)};
Settings.processPlayer=function(){void 0===Settings.demoScript.effects&&(Settings.demoScript.effects=[{name:"Demo",reference:"data/js/Demo.js"}]);for(var c=0;c<Settings.demoScript.effects.length;c++){var b=Settings.demoScript.effects[c];!0!==b.skip&&addPlayerEffect(b.name,b.reference)}void 0===Settings.demoScript.scenes&&(Settings.demoScript.scenes=[{name:"Demo",effect:"Demo"}]);for(c=0;c<Settings.demoScript.scenes.length;c++)if(b=Settings.demoScript.scenes[c],!0!==b.skip&&(void 0===b.startTime&&
(b.startTime="0:00"),void 0===b.durationTime&&(b.durationTime=Settings.demoScript.totalTime),addPlayerScene("",b.name,b.effect,b.startTime,b.durationTime),Settings.processVariables(b),!b.hasOwnProperty("effect")))for(var a=0;a<b.scenes.length;a++){var d=b.scenes[a];!0!==d.skip&&(addPlayerScene(b.name,d.name,d.effect,d.startTime,d.durationTime),Settings.processVariables(d))}};var Effect=function(){};Effect.effects=[];Effect.init=function(c){var b=eval("new "+c);void 0===b.loader&&(b.loader=new Loader);void 0===b.player&&(b.player=new Player);Effect.effects[c]=b;void 0!==b.init&&b.init();void 0!==b.postInit?b.postInit():b.loader.processAnimation()};Effect.run=function(c){c=Effect.effects[c];void 0!==c.run?c.run():c.player.drawAnimation(c.loader.animationLayers)};Effect.deinit=function(c){var b=Effect.effects[c];void 0!==b.deinit&&b.deinit();delete Effect.effects[c]};var Loader=function(){this.resourceCount=0;this.resourceUniqueList=[];this.animationLayers={}};
Loader.drawLoadingBar=function(c){var b=getScreenWidth(),a=getScreenHeight();perspective2dBegin(b,a);var d=.6*b,f=.2*a,h=d*c,e=.01*b,g=.01*a*getWindowScreenAreaAspectRatio(),k=b/2-d/2,b=b/2+d/2,l=a/2-f/2,a=a/2+f/2,h=k+h,d=k+.2*d,m=a+3*g,n=m+f,q=l-3*g,f=q-f,p=1;.85<c&&(p=Utils.clamp(1-(c-.85)/(1-.85)));glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);glEnable(GL_BLEND);glColor4f(.2,.2,.2,p);glBegin(GL_QUADS);glVertex2i(k-e,l-g);glVertex2i(b+e,l-g);glVertex2i(b+e,a+g);glVertex2i(k-e,a+g);glVertex2i(k-
e,l-g);glEnd();glColor4f(.4,.4,.4,p);glBegin(GL_QUADS);glVertex2i(k,l);glVertex2i(h,l);glVertex2i(h,a);glVertex2i(k,a);glEnd();!0===Settings.demoScript.jumalauta&&(glColor4f(.2,.2,.2,p),glBegin(GL_QUADS),glVertex2i(k-e,f-g),glVertex2i(d+e,f-g),glVertex2i(d+e,q+g),glVertex2i(k-e,q+g),glVertex2i(k-e,f-g),glEnd(),glBegin(GL_QUADS),glVertex2i(k-e,m-g),glVertex2i(d+e,m-g),glVertex2i(d+e,n+g),glVertex2i(k-e,n+g),glVertex2i(k-e,m-g),glEnd());glDisable(GL_BLEND);glColor4f(1,1,1,1);perspective2dEnd()};
Loader.prototype.validateResourceLoaded=function(c,b,a){return void 0===c||void 0===b||void 0===b.ptr?(this.setAnimationError(c,"RESOURCE",a),!1):!0};Loader.prototype.setAnimationError=function(c,b,a){windowSetTitle(b+" ERROR");c.error=a;debugErrorPrint(a+" - JSON: "+JSON.stringify(c,null,2))};
Loader.prototype.preprocess3dCoordinateAnimation=function(c,b,a,d,f){if(void 0!==d)for(a=b=c=0,void 0!==f&&(c=f.x,b=f.y,a=f.z),f=0;f<d.length;f++){var h=d[f];void 0===h.x&&(h.x=c);void 0===h.y&&(h.y=b);void 0===h.z&&(h.z=a);c=h.x;b=h.y;a=h.z}};Loader.prototype.setSyncDefaults=function(c,b){void 0!==c.sync&&void 0===c.sync[b]&&(c.sync[b]=!0===c.sync.all?!0:!1)};
Loader.prototype.preprocessColorAnimation=function(c,b,a,d,f){this.setSyncDefaults(d,"color");var h=d=255,e=255,g=255;void 0===f&&(f=[{}]);Utils.preprocessTimeAnimation(c,b,a,f);for(c=0;c<f.length;c++)b=f[c],void 0===b.r&&(b.r=d),void 0===b.g&&(b.g=h),void 0===b.b&&(b.b=e),void 0===b.a&&(b.a=g),d=b.r,h=b.g,e=b.b,g=b.a};
Loader.prototype.preprocessAngleAnimation=function(c,b,a,d){if(void 0!==d.angle){this.setSyncDefaults(d,"angle");Utils.preprocessTimeAnimation(c,b,a,d.angle);this.preprocess3dCoordinateAnimation(c,b,a,d.angle,{x:1,y:1,z:1});for(var f=a=b=c=0;f<d.angle.length;f++){var h=d.angle[f];void 0===h.degreesX&&(h.degreesX=c);void 0===h.degreesY&&(h.degreesY=b);void 0===h.degreesZ&&(h.degreesZ=a);void 0!==h.pivot&&this.setAnimationError(d,"PARSE","angle.pivot is deprecated. move pivot under animation.");c=h.degreesX;
b=h.degreesY;a=h.degreesZ}}};Loader.prototype.preprocessPerspectiveAnimation=function(c,b,a,d){this.setSyncDefaults(d,"perspective");void 0===d.perspective&&(d.perspective=[{}]);Utils.preprocessTimeAnimation(c,b,a,d.perspective);c=45;b=getWindowScreenAreaAspectRatio();a=1;for(var f=1E3,h=0;h<d.perspective.length;h++){var e=d.perspective[h];void 0===e.fov&&(e.fov=c);void 0===e.aspect&&(e.aspect=b);void 0===e.near&&(e.near=a);void 0===e.far&&(e.far=f);c=e.fov;b=e.aspect;a=e.near;f=e.far}};
Loader.prototype.preprocessScaleAnimation=function(c,b,a,d){this.setSyncDefaults(d,"scale");void 0===d.scale&&(d.scale=[{}]);for(var f=0;f<d.scale.length;f++){var h=d.scale[f];void 0!==h.uniform3d?(h.x=h.uniform3d,h.y=h.uniform3d,h.z=h.uniform3d):void 0!==h.uniform2d&&(h.x=h.uniform2d,h.y=h.uniform2d)}Utils.preprocessTimeAnimation(c,b,a,d.scale);this.preprocess3dCoordinateAnimation(c,b,a,d.scale,{x:1,y:1,z:1})};
Loader.prototype.preprocessDimensionAnimation=function(c,b,a,d){this.setSyncDefaults(d,"dimension");void 0===d.dimension&&(d.dimension=[{}]);Utils.preprocessTimeAnimation(c,b,a,d.dimension);this.preprocess3dCoordinateAnimation(c,b,a,d.dimension,{x:1,y:1,z:1})};Loader.prototype.preprocessPositionAnimation=function(c,b,a,d,f){void 0!==d.position&&(this.setSyncDefaults(d,"position"),Utils.preprocessTimeAnimation(c,b,a,d.position),this.preprocess3dCoordinateAnimation(c,b,a,d.position,f))};
Loader.prototype.preprocessPivotAnimation=function(c,b,a,d,f){void 0!==d.pivot&&(this.setSyncDefaults(d,"pivot"),Utils.preprocessTimeAnimation(c,b,a,d.pivot),this.preprocess3dCoordinateAnimation(c,b,a,d.pivot,f))};
Loader.prototype.preprocessAnimationDefinitions=function(c,b,a,d){a=c=b=c;this.preprocessColorAnimation(c,a-c,a,d,d.color);a=c=b;this.preprocessAngleAnimation(c,a-c,a,d);a=c=b;this.preprocessScaleAnimation(c,a-c,a,d);a=c=b;this.preprocessPositionAnimation(c,a-c,a,d,{x:0,y:0,z:0});a=c=b;this.preprocessPivotAnimation(c,a-c,a,d,{x:0,y:0,z:0})};
Loader.prototype.addNotifyResource=function(c){return void 0!==c&&void 0===this.resourceUniqueList[c]?(this.resourceCount++,this.resourceUniqueList[c]=!1,setResourceCount(1),!0):!1};Loader.prototype.notifyResourceLoaded=function(c){return void 0!==c&&!1===this.resourceUniqueList[c]?(this.resourceUniqueList[c]=!0,notifyResourceLoaded(),!0):!1};Loader.prototype.sortArray=function(c){return Object.keys(c).sort().reduce(function(b,a){b[a]=c[a];return b},{})};
Loader.prototype.getLayerString=function(c){if(Utils.isString(c))return c;if(Utils.isNumeric(c))return c="00000"+c,c.substring(c.length-5)};
Loader.prototype.addAnimation=function(c){for(var b="00001",a=0;a<c.length;a++){var d=c[a];void 0!==d.layer&&(b=this.getLayerString(d.layer));d.layer=b;void 0===this.animationLayers[b]&&(this.animationLayers[b]=[]);if(void 0!==d.shader){if(d.shader.constructor===Array){if(void 0===d.passToFbo){this.setAnimationError(d,"PARSE","passToFbo must be declared when declaring animation shaders as an Array.");continue}for(var f=void 0,h=0;h<d.shader.length;h++){var e=Utils.deepCopyJson(d);e.shader=Utils.deepCopyJson(d.shader[h]);
if(0<h&&void 0!==f)if(void 0!==e.fbo)void 0!==e.fbo.name&&(e.fbo.name=f);else if(void 0!==e.image){var g=e.image;0<=g.indexOf(".color.fbo")?g=f+".color.fbo":0<=g.indexOf(".depth.fbo")&&(g=f+".depth.fbo");e.image=g}h<d.shader.length-1?(e.passToFbo.name+=".pass."+h,this.addAnimation([e])):(d.shader=e.shader,void 0!==d.fbo&&(d.fbo.name=e.fbo.name),void 0!==d.image&&(d.image=e.image));f=e.passToFbo.name}}d.shader.name.constructor!==Array&&(d.shader.name=[d.shader.name]);f=d.shader.name[d.shader.name.length-
1];void 0===d.shader.programName&&(d.shader.programName=f);this.addNotifyResource(d.shader.programName)}void 0!==d.passToFbo&&(f={fbo:{}},void 0!==d.start&&(f.start=d.start),void 0!==d.end&&(f.end=d.end),void 0!==d.duration&&(f.duration=d.duration),f.layer=d.layer,void 0!==d.passToFbo.beginLayer&&(f.layer=d.passToFbo.beginLayer),f.fbo.name=d.passToFbo.name,f.fbo.action="begin",void 0!==d.passToFbo.beginAction&&(f.fbo.action=d.passToFbo.beginAction),this.addAnimation([f]));void 0!==d.object?this.addNotifyResource(d.object):
void 0!==d.image?this.addNotifyResource(d.image)&&imageLoadImageAsync(d.image):void 0!==d.fbo&&this.addNotifyResource(d.fbo.name);void 0!==d.initFunction&&this.addNotifyResource(d.initFunction);this.animationLayers[b].push(d);void 0!==d.passToFbo&&(f={fbo:{}},void 0!==d.start&&(f.start=d.start),void 0!==d.end&&(f.end=d.end),void 0!==d.duration&&(f.duration=d.duration),f.layer=d.layer,void 0!==d.passToFbo.endLayer&&(f.layer=d.passToFbo.endLayer),f.fbo.name=d.passToFbo.name,f.fbo.action="unbind",void 0!==
d.passToFbo.endAction&&(f.fbo.action=d.passToFbo.endAction),this.addAnimation([f]))}this.animationLayers=this.sortArray(this.animationLayers)};
Loader.prototype.processAnimation=function(){threadWaitAsyncCalls();var c=getSceneStartTime(),b=getSceneEndTime(),a=0,d;for(d in this.animationLayers)if(this.animationLayers.hasOwnProperty(d))for(var f=this.animationLayers[d].length,h=0;h<f;h++){var e=this.animationLayers[d][h];Utils.setTimeVariables(e,c,b,a);c=e.start;b=e.end;a=b-c;void 0!==e.sync&&void 0===e.sync.all&&(e.sync.all=!0);void 0!==e.shader&&(e.shader.ref=Shader.load(e.shader),this.validateResourceLoaded(e,e.shader.ref,"Could not load shader program "+
e.shader.programName),this.notifyResourceLoaded(e.shader.programName));if(void 0!==e.object||void 0!==e.objectFunction){e.type="object";if(void 0!==e.object){if(void 0!==e.shape)if("SPHERE"===e.shape.type){var g=1;void 0!==e.shape.radius&&(g=e.shape.radius);var k=30;void 0!==e.shape.lats&&(k=e.shape.lats);var l=30;void 0!==e.shape.longs&&(l=e.shape.longs);e.ref=setObjectSphereData(e.object,g,k,l)}else if("CYLINDER"===e.shape.type){k=1;void 0!==e.shape.base&&(k=e.shape.base);l=1;void 0!==e.shape.top&&
(l=e.shape.top);var m=1;void 0!==e.shape.height&&(m=e.shape.height);g=30;void 0!==e.shape.slices&&(g=e.shape.slices);var n=30;void 0!==e.shape.stacks&&(n=e.shape.stacks);e.ref=setObjectCylinderData(e.object,k,l,m,g,n)}else if("DISK"===e.shape.type)k=0,void 0!==e.shape.inner&&(k=e.shape.inner),l=1,void 0!==e.shape.outer&&(l=e.shape.outer),g=30,void 0!==e.shape.slices&&(g=e.shape.slices),m=30,void 0!==e.shape.loops&&(m=e.shape.loops),e.ref=setObjectDiskData(e.object,k,l,g,m);else if("CUBE"===e.shape.type)e.ref=
setObjectCubeData(e.object);else{if("MATRIX"===e.shape.type||"CUSTOM"===e.shape.type)e.ref=loadObjectBasicShape(e.object,e.shape.type)}else e.ref=loadObject(e.object);!0===Settings.demoScript.kanttuCompatibility&&(void 0===e.objectLighting&&(e.objectLighting=!1),void 0===e.simpleColors&&(e.simpleColors=!0));this.validateResourceLoaded(e,e.ref,"Could not load "+e.object)&&(!1===e.objectLighting&&useObjectLighting(e.ref.ptr,0),!0===e.simpleColors&&useSimpleColors(e.ref.ptr,1),!1===e.objectCamera&&useObjectCamera(e.ref.ptr,
0))}void 0===e.fps&&(e.fps=0);void 0===e.camera&&(e.camera="Camera01");e.clearDepthBuffer=void 0===e.clearDepthBuffer?0:!0===e.clearDepthBuffer?1:0;g=c;k=b;l=k-g;this.preprocessAnimationDefinitions(g,l,k,e);this.notifyResourceLoaded(e.object)}else if(void 0!==e.image){e.type="image";e.image.constructor!==Array&&(e.image=[e.image]);for(g=0;g<e.image.length;g++)!0===Utils.isString(e.image[g])&&(e.image[g]={name:e.image[g]});e.ref=imageLoadImage(e.image[0].name);void 0!==e.image[0].video&&(k=Utils.deepCopyJson(e.image[0].video),
k.ref=videoLoad(e.image[0].name),e.ref.video=k);e.multiTexRef=[e.ref];for(g=1;g<e.image.length;g++)e.multiTexRef.push(imageLoadImage(e.image[g].name)),void 0!==e.image[g].video&&(k=Utils.deepCopyJson(e.image[g].video),k.ref=videoLoad(e.image[g].name),e.multiTexRef[g].video=k);void 0===e.perspective&&(e.perspective="2d");void 0===e.align&&void 0===e.position&&(e.align=Constants.Align.CENTER);g=c;k=b;l=k-g;this.preprocessAnimationDefinitions(g,l,k,e);c="Could not load "+e.image[0].name;this.validateResourceLoaded(e,
e.ref,c);for(g=0;g<e.multiTexRef.length;g++)this.validateResourceLoaded(e,e.multiTexRef[g],c);this.notifyResourceLoaded(e.image[0].name)}else void 0!==e.text?(e.type="text",void 0===e.text.perspective?e.text.perspective="2d":"3d"===e.text.perspective&&(e.clearDepthBuffer=void 0===e.clearDepthBuffer?0:!0===e.clearDepthBuffer?1:0),void 0!==e.text.name&&setTextFont(e.text.name),void 0===e.align&&void 0===e.position&&(e.align=Constants.Align.CENTER),g=c,k=b,l=k-g,this.preprocessAnimationDefinitions(g,
l,k,e)):void 0!==e.fbo?(e.type="fbo",void 0===e.fbo.name&&(e.fbo.name="fbo"),e.ref=fboInit(e.fbo.name),this.validateResourceLoaded(e,e.ref,"Could not load "+e.fbo.name)&&0===e.ref.id&&(fboStoreDepth(e.ref.ptr,!0===e.fbo.storeDepth?1:0),void 0!==e.fbo.width&&void 0!==e.fbo.height&&fboSetDimensions(e.ref.ptr,e.fbo.width,e.fbo.height),fboGenerateFramebuffer(e.ref.ptr)),k=g=c,l=k-g,this.preprocessDimensionAnimation(g,l,k,e),this.notifyResourceLoaded(e.fbo.name)):void 0!==e.light?(e.type="light",k=g=c,
l=k-g,this.preprocessPositionAnimation(g,l,k,e,{x:0,y:0,z:1}),void 0!==e.ambientColor&&(k=g=c,l=k-g,this.preprocessColorAnimation(g,l,k,e,e.ambientColor)),void 0!==e.diffuseColor&&(k=g=c,l=k-g,this.preprocessColorAnimation(g,l,k,e,e.diffuseColor)),void 0!==e.specularColor&&(k=g=c,l=k-g,this.preprocessColorAnimation(g,l,k,e,e.specularColor))):void 0!==e.camera&&(e.type="camera",k=g=c,l=k-g,this.preprocessPerspectiveAnimation(g,l,k,e),k=g=c,l=k-g,this.preprocessPositionAnimation(g,l,k,e,{x:0,y:0,z:2}),
k=g=c,l=k-g,void 0!==e.sync&&void 0===e.sync.target&&(e.sync.target=!0===e.sync.all?!0:!1),Utils.preprocessTimeAnimation(g,l,k,e.target),this.preprocess3dCoordinateAnimation(g,l,k,e.target,{x:0,y:0,z:0}),k=g=c,l=k-g,void 0!==e.sync&&void 0===e.sync.up&&(e.sync.up=!0===e.sync.all?!0:!1),Utils.preprocessTimeAnimation(g,l,k,e.up),this.preprocess3dCoordinateAnimation(g,l,k,e.up,{x:0,y:1,z:0}));void 0!==e.initFunction&&(Utils.evaluateVariable(e,e.initFunction),notifyResourceLoaded(e.initFunction));c=b;
b=c+a}};var Player=function(){};
Player.prototype.calculate3dCoordinateAnimation=function(c,b,a){var d={x:0,y:0,z:0};void 0!==a&&(d.x=a.x,d.y=a.y,d.z=a.z,void 0===a.sync&&void 0!==b.sync&&(a.sync=b.sync));if(void 0!==b){d.x=Utils.evaluateVariable(b,b[0].x);d.y=Utils.evaluateVariable(b,b[0].y);d.z=Utils.evaluateVariable(b,b[0].z);if(void 0!==b.sync&&!0===a.sync&&(c=b.start+b.duration*b.sync.progress,0==b.sync.progress))return d;a=interpolate;for(var f=b.length,h=0;h<f;h++){var e=b[h];if(c>=e.start){var g=(c-e.start)/e.duration;d.x=
a(g,d.x,Utils.evaluateVariable(b,e.x));d.y=a(g,d.y,Utils.evaluateVariable(b,e.y));d.z=a(g,d.z,Utils.evaluateVariable(b,e.z))}}}return d};Player.prototype.calculateScaleAnimation=function(c,b){return this.calculate3dCoordinateAnimation(c,b.scale,{x:1,y:1,z:1})};Player.prototype.calculatePositionAnimation=function(c,b){return this.calculate3dCoordinateAnimation(c,b.position,{x:0,y:0,z:0})};
Player.prototype.calculatePivotAnimation=function(c,b){return this.calculate3dCoordinateAnimation(c,b.pivot,{x:0,y:0,z:0})};
Player.prototype.calculatePerspectiveAnimation=function(c,b){var a={fov:45,aspect:getWindowScreenAreaAspectRatio(),near:1,far:1E3};if(void 0!==b.perspective){a.fov=Utils.evaluateVariable(b,b.perspective[0].fov);a.aspect=Utils.evaluateVariable(b,b.perspective[0].aspect);a.near=Utils.evaluateVariable(b,b.perspective[0].near);a.far=Utils.evaluateVariable(b,b.perspective[0].far);var d=c;if(void 0!==b.sync&&!0===b.sync.perspective&&(d=b.start+b.duration*b.sync.progress,0==b.sync.progress))return a;for(var f=
interpolate,h=b.perspective.length,e=0;e<h;e++){var g=b.perspective[e];if(d>=g.start){var k=(d-g.start)/g.duration;a.fov=f(k,a.fov,Utils.evaluateVariable(b,g.fov));a.aspect=f(k,a.aspect,Utils.evaluateVariable(b,g.aspect));a.near=f(k,a.near,Utils.evaluateVariable(b,g.near));a.far=f(k,a.far,Utils.evaluateVariable(b,g.far))}}}return a};
Player.prototype.calculateColorAnimation=function(c,b,a){var d={r:255,g:255,b:255,a:255};if(void 0!==a){d.r=Utils.evaluateVariable(a,a[0].r);d.g=Utils.evaluateVariable(a,a[0].g);d.b=Utils.evaluateVariable(a,a[0].b);d.a=Utils.evaluateVariable(a,a[0].a);if(void 0!==b.sync&&!0===b.sync.color&&(c=b.start+b.duration*b.sync.progress,0==b.sync.progress))return d;for(var f=interpolate,h=0;h<a.length;h++){var e=a[h];if(c>=e.start){var g=(c-e.start)/e.duration;d.r=f(g,d.r,Utils.evaluateVariable(b,e.r));d.g=
f(g,d.g,Utils.evaluateVariable(b,e.g));d.b=f(g,d.b,Utils.evaluateVariable(b,e.b));d.a=f(g,d.a,Utils.evaluateVariable(b,e.a))}}}return d};
Player.prototype.calculateAngleAnimation=function(c,b){var a={degreesX:0,degreesY:0,degreesZ:0,x:1,y:1,z:1};if(void 0!==b.angle){a.degreesX=Utils.evaluateVariable(b,b.angle[0].degreesX);a.degreesY=Utils.evaluateVariable(b,b.angle[0].degreesY);a.degreesZ=Utils.evaluateVariable(b,b.angle[0].degreesZ);a.x=Utils.evaluateVariable(b,b.angle[0].x);a.y=Utils.evaluateVariable(b,b.angle[0].y);a.z=Utils.evaluateVariable(b,b.angle[0].z);var d=c;if(void 0!==b.sync&&!0===b.sync.angle&&(d=b.start+b.duration*b.sync.progress,
0==b.sync.progress))return a;for(var f=interpolate,h=b.angle.length,e=0;e<h;e++){var g=b.angle[e];if(d>=g.start){var k=(d-g.start)/g.duration;a.degreesX=f(k,a.degreesX,Utils.evaluateVariable(b,g.degreesX));a.degreesY=f(k,a.degreesY,Utils.evaluateVariable(b,g.degreesY));a.degreesZ=f(k,a.degreesZ,Utils.evaluateVariable(b,g.degreesZ));a.x=f(k,a.x,Utils.evaluateVariable(b,g.x));a.y=f(k,a.y,Utils.evaluateVariable(b,g.y));a.z=f(k,a.z,Utils.evaluateVariable(b,g.z))}}}return a};
Player.prototype.drawImageAnimation=function(c,b){!0===b.additive&&setTextureBlendFunc(b.ref.ptr,GL_SRC_ALPHA,GL_ONE);var a=0;"3d"===b.perspective&&(a=1);setTexturePerspective3d(b.ref.ptr,a);void 0!==b.canvasWidth&&void 0!==b.canvasHeight&&setTextureCanvasDimensions(b.ref.ptr,Utils.evaluateVariable(b,b.canvasWidth),Utils.evaluateVariable(b,b.canvasHeight));void 0!==b.uv&&setTextureUvDimensions(b.ref.ptr,Utils.evaluateVariable(b,b.uv.uMin),Utils.evaluateVariable(b,b.uv.vMin),Utils.evaluateVariable(b,
b.uv.uMax),Utils.evaluateVariable(b,b.uv.vMax));for(a=1;a<b.multiTexRef.length;a++)setTextureUnitTexture(b.ref.ptr,a,b.multiTexRef[a].ptr);void 0!==b.pivot&&(a=this.calculatePivotAnimation(c,b),setTexturePivot(b.ref.ptr,a.x,a.y,a.z));void 0!==b.angle&&(a=this.calculateAngleAnimation(c,b),setTextureRotation(b.ref.ptr,a.degreesX,a.degreesY,a.degreesZ,a.x,a.y,a.z));a=this.calculateScaleAnimation(c,b);setTextureScale(b.ref.ptr,a.x,a.y);if(void 0!==b.position){var a=this.calculatePositionAnimation(c,b),
d=a.x,f=a.y,h=a.z;Settings.demoScript.kanttuCompatibility&&(f=getScreenHeight()-a.y);setTexturePosition(b.ref.ptr,d,f,h)}void 0!==b.align&&setTextureCenterAlignment(b.ref.ptr,b.align);a=this.calculateColorAnimation(c,b,b.color);glColor4ub(a.r,a.g,a.b,a.a);for(a=0;a<b.multiTexRef.length;a++)d=b.multiTexRef[a],void 0!==d.video&&(videoSetStartTime(d.video.ref.ptr,b.start),void 0!==d.video.speed&&videoSetSpeed(d.video.ref.ptr,Utils.evaluateVariable(b,d.video.speed)),void 0!==d.video.fps&&videoSetFps(d.video.ref.ptr,
Utils.evaluateVariable(b,d.video.fps)),void 0!==d.video.loop&&videoSetLoop(d.video.ref.ptr,Utils.evaluateVariable(b,d.video.loop)),void 0===d.video.playing&&(videoPlay(d.video.ref.ptr),d.video.playing=!0));drawTexture(b.ref.ptr);setTextureDefaults(b.ref.ptr)};
Player.prototype.drawTextAnimation=function(c,b){setTextDefaults();setDrawTextString(b.text.string);if(void 0!==b.pivot){var a=this.calculatePivotAnimation(c,b);setTextPivot(a.x,a.y,a.z)}void 0!==b.angle&&(a=this.calculateAngleAnimation(c,b),setTextRotation(a.degreesX,a.degreesY,a.degreesZ));a=this.calculateScaleAnimation(c,b);setTextSize(a.x,a.y);if("2d"===b.text.perspective){if(void 0!==b.position){var a=this.calculatePositionAnimation(c,b),d=a.x,f=a.y;Settings.demoScript.kanttuCompatibility&&(f=
getScreenHeight()-(a.y-yFixed));setTextPosition(d,f,0)}void 0!==b.align&&setTextCenterAlignment(b.align)}else void 0!==b.position&&(a=this.calculatePositionAnimation(c,b),setTextPosition(a.x,a.y,a.z));void 0!==b.text.name&&setTextFont(b.text.name);a=this.calculateColorAnimation(c,b,b.color);glColor4ub(a.r,a.g,a.b,a.a);"2d"===b.text.perspective?drawText2d():(b.clearDepthBuffer&&glClear(GL_DEPTH_BUFFER_BIT),drawText3d());setTextDefaults()};
Player.prototype.drawObjectAnimation=function(c,b){var a=!1;if(void 0!==b.ref){if(void 0!==b.position){var d=this.calculatePositionAnimation(c,b);setObjectPosition(b.ref.ptr,d.x,d.y,d.z)}void 0!==b.pivot&&(d=this.calculatePivotAnimation(c,b),setObjectPivot(b.ref.ptr,d.x,d.y,d.z));void 0!==b.angle&&(d=this.calculateAngleAnimation(c,b),setObjectRotation(b.ref.ptr,d.degreesX,d.degreesY,d.degreesZ,d.x,d.y,d.z));void 0!==b.scale&&(d=this.calculateScaleAnimation(c,b),setObjectScale(b.ref.ptr,d.x,d.y,d.z));
void 0!==b.color&&(d=this.calculateColorAnimation(c,b,b.color),setObjectColor(b.ref.ptr,d.r/255,d.g/255,d.b/255,d.a/255));var d=b.camera,f=(c-b.start)*b.fps;void 0!==b.frame&&(f=b.frame);var h=b.clearDepthBuffer;void 0!==b.shape&&"CUSTOM"===b.shape.type&&(a=!0);a&&glPushMatrix();h&&glClear(GL_DEPTH_BUFFER_BIT);drawObject(b.ref.ptr,d,f,h)}void 0!==b.objectFunction&&Utils.evaluateVariable(b,b.objectFunction);a&&glPopMatrix()};
Player.prototype.drawFboAnimation=function(c,b){if(void 0!==b.fbo.dimension){var a=this.calculate3dCoordinateAnimation(c,b.fbo.dimension,{x:1,y:1,z:1});fboSetRenderDimensions(b.ref.ptr,a.x,a.y)}"begin"===b.fbo.action?(fboBind(b.ref.ptr),fboUpdateViewport(b.ref.ptr)):"end"===b.fbo.action?(fboBind(),fboUpdateViewport(),fboBindTextures(b.ref.ptr),glColor4f(1,1,1,1),void 0!==b.ref.color&&setTextureSizeToScreenSize(b.ref.color.ptr),void 0!==b.ref.depth&&setTextureSizeToScreenSize(b.ref.depth.ptr),drawTexture(b.ref.color.ptr),
fboBindTextures()):"unbind"===b.fbo.action?(fboBind(),fboUpdateViewport()):"draw"===b.fbo.action&&(fboBindTextures(b.ref.ptr),glColor4f(1,1,1,1),void 0!==b.ref.color&&setTextureSizeToScreenSize(b.ref.color.ptr),void 0!==b.ref.depth&&setTextureSizeToScreenSize(b.ref.depth.ptr),drawTexture(b.ref.color.ptr),fboBindTextures())};
Player.prototype.drawLightAnimation=function(c,b){if(void 0!==b.ambientColor){var a=this.calculateColorAnimation(c,b,b.ambientColor);lightSetAmbientColor(b.light.index,a.r/255,a.g/255,a.b/255,a.a/255)}void 0!==b.diffuseColor&&(a=this.calculateColorAnimation(c,b,b.diffuseColor),lightSetDiffuseColor(b.light.index,a.r/255,a.g/255,a.b/255,a.a/255));void 0!==b.specularColor&&(a=this.calculateColorAnimation(c,b,b.specularColor),lightSetSpecularColor(b.light.index,a.r/255,a.g/255,a.b/255,a.a/255));void 0!==
b.position&&(a=this.calculate3dCoordinateAnimation(c,b.position,{x:0,y:0,z:1}),lightSetPosition(b.light.index,a.x,a.y,a.z));lightSetPositionObject(b.light.index);void 0!==b.positionObject?lightSetPositionObject(b.light.index,b.positionObject.ptr):void 0!==b.lightRelativePosition&&(b.positionObject=getObjectFromMemory(b.lightRelativePosition));"begin"===b.light.action?lightSetOn(b.light.index):"end"===b.light.action&&lightSetOff(b.light.index)};
Player.prototype.drawCameraAnimation=function(c,b){if(void 0!==b.perspective){var a=this.calculatePerspectiveAnimation(c,b);setCameraPerspective(a.fov,a.aspect,a.near,a.far)}void 0!==b.position&&(a=this.calculate3dCoordinateAnimation(c,b.position,{x:0,y:0,z:2}),setCameraPosition(a.x,a.y,a.z));void 0!==b.target&&(a=this.calculate3dCoordinateAnimation(c,b.target,{x:0,y:0,z:0}),setCameraLookAt(a.x,a.y,a.z));void 0!==b.up&&(a=this.calculate3dCoordinateAnimation(c,b.up,{x:0,y:1,z:0}),setCameraUpVector(a.x,
a.y,a.z));setCameraPositionObject();void 0!==b.positionObject?setCameraPositionObject(b.positionObject.ptr):void 0!==b.cameraRelativePosition&&(b.positionObject=getObjectFromMemory(b.cameraRelativePosition));setCameraTargetObject();void 0!==b.targetObject?setCameraTargetObject(b.targetObject.ptr):void 0!==b.cameraRelativeTarget&&(b.targetObject=getObjectFromMemory(b.cameraRelativeTarget));viewReset()};
Player.prototype.drawAnimation=function(c){var b=getSceneTimeFromStart(),a;for(a in c){glPushMatrix();if(c.hasOwnProperty(a))for(var d=c[a].length,f=0;f<d;f++){glPushAttrib(GL_CURRENT_BIT);var h=c[a][f];void 0===h.error&&(b>=h.start&&b<h.end&&(Sync.calculateAnimationSync(b,h),void 0!==h.shader&&Shader.enableShader(h),"image"===h.type?this.drawImageAnimation(b,h):"text"===h.type?this.drawTextAnimation(b,h):"object"===h.type?this.drawObjectAnimation(b,h):"fbo"===h.type?this.drawFboAnimation(b,h):"light"===
h.type?this.drawLightAnimation(b,h):"camera"===h.type&&this.drawCameraAnimation(b,h),void 0!==h.runFunction&&Utils.evaluateVariable(h,h.runFunction),void 0!==h.shader&&Shader.disableShader(h)),glPopAttrib())}glPopMatrix()}};
