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],g=0;16>g;g++)d[g]/=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,g){c=Math.tan(c*Math.PI/360)*a;b*=c;return Matrix.frustum(-b,b,-c,c,a,d,g)};Matrix.frustum=function(c,b,a,d,g,f,e){e=e||new Matrix;var h=e.m;h[0]=2*g/(b-c);h[1]=0;h[2]=(b+c)/(b-c);h[3]=0;h[4]=0;h[5]=2*g/(d-a);h[6]=(d+a)/(d-a);h[7]=0;h[8]=0;h[9]=0;h[10]=-(f+g)/(f-g);h[11]=-2*f*g/(f-g);h[12]=0;h[13]=0;h[14]=-1;h[15]=0;return e};
Matrix.ortho=function(c,b,a,d,g,f,e){e=e||new Matrix;var h=e.m;h[0]=2/(b-c);h[1]=0;h[2]=0;h[3]=-(b+c)/(b-c);h[4]=0;h[5]=2/(d-a);h[6]=0;h[7]=-(d+a)/(d-a);h[8]=0;h[9]=0;h[10]=-2/(f-g);h[11]=-(f+g)/(f-g);h[12]=0;h[13]=0;h[14]=0;h[15]=1;return e};Matrix.scale=function(c,b,a,d){d=d||new Matrix;var g=d.m;g[0]=c;g[1]=0;g[2]=0;g[3]=0;g[4]=0;g[5]=b;g[6]=0;g[7]=0;g[8]=0;g[9]=0;g[10]=a;g[11]=0;g[12]=0;g[13]=0;g[14]=0;g[15]=1;return d};
Matrix.translate=function(c,b,a,d){d=d||new Matrix;var g=d.m;g[0]=1;g[1]=0;g[2]=0;g[3]=c;g[4]=0;g[5]=1;g[6]=0;g[7]=b;g[8]=0;g[9]=0;g[10]=1;g[11]=a;g[12]=0;g[13]=0;g[14]=0;g[15]=1;return d};
Matrix.rotate=function(c,b,a,d,g){if(!c||!b&&!a&&!d)return Matrix.identity(g);g=g||new Matrix;var f=g.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 h=1-e;f[0]=b*b*h+e;f[1]=b*a*h-d*c;f[2]=b*d*h+a*c;f[3]=0;f[4]=a*b*h+d*c;f[5]=a*a*h+e;f[6]=a*d*h-b*c;f[7]=0;f[8]=d*b*h-a*c;f[9]=d*a*h+b*c;f[10]=d*d*h+e;f[11]=0;f[12]=0;f[13]=0;f[14]=0;f[15]=1;return g};
Matrix.lookAt=function(c,b,a,d,g,f,e,h,k,l){l=l||new Matrix;var m=l.m;c=new Vector(c,b,a);d=new Vector(d,g,f);h=new Vector(e,h,k);e=c.subtract(d).unit();h=h.cross(e).unit();k=e.cross(h).unit();m[0]=h.x;m[1]=h.y;m[2]=h.z;m[3]=-h.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)],g=c[b],f=c[Math.min(b+1,c.length-1)];c=c[Math.min(b+2,c.length-1)];var e=Math.pow(a,3),h=Math.pow(a,2);b=-.5*e+h-.5*a;var k=1.5*e-2.5*h+1;a=-1.5*e+2*h+.5*a;e=.5*e-.5*h;return{x:d.x*b+g.x*k+f.x*a+c.x*e,y:d.y*b+g.y*k+f.y*a+c.y*e,z:d.z*b+g.z*k+f.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 g=this.interpolate(c,a,d/(b-1));this.outputPath.push(g)}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.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 g="\tstack: "+a,g=g+(", function: "+d.function.name),g=g+(", line: "+d.lineNumber),g=g+(", info: "+Duktape.enc("jx",d));c[++b]=g}}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 g=0;g<d.length;g++){var f=d[g];this.setTimeVariables(f,c,a,b);c=f.end;b=f.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);if(void 0===b.ptr){var a=shaderLoad(c,c);1==a.ok&&(b=shaderProgramLoad(c),shaderProgramAddShaderByName(b.name,a.name),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,g,f=c.shader.variable.length,e=0;e<f;e++){var h=c.shader.variable[e],k=b(h.name);g=d;"int"===h.type&&(g=a);for(var l=[],m=h.value.length,n=0;n<m;n++)l.push(Utils.evaluateVariable(c,h.value[n]));switch(m){case 1:g(k,l[0]);break;case 2:g(k,l[0],l[1]);break;case 3:g(k,l[0],l[1],l[2]);break;case 4:g(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,g=0;g<c.length;g++){var f=c[g];Utils.setTimeVariables(f,b,a,d);b=f.start;a=f.end;d=a-b;"rocket"===f.type&&(f.ref=syncEditorGetTrack(f.name));void 0===f.pattern&&(f.pattern=[{}],void 0===f.ref&&(f.pattern=[{start:b,duration:d}]));Utils.preprocessTimeAnimation(b,d,a,f.pattern);for(var e=0;e<f.pattern.length;e++){var h=f.pattern[e];h.started=!1;h.counter=0}Sync.syncDefinitions[f.name]=f}};
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 g=a.pattern.length,f=0;f<g;f++){var e=a.pattern[f];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 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));void 0!==Settings.demoScript.window&&void 0!==Settings.demoScript.window.title&&windowSetTitle(Settings.demoScript.window.title);void 0!==Settings.demoScript.clearColor&&setClearColor(Settings.demoScript.clearColor.r,Settings.demoScript.clearColor.g,Settings.demoScript.clearColor.b,Settings.demoScript.clearColor.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(var 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].default&&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){perspective2dBegin(800,600);var b=300+200*c,a=1;.95<c&&(a=1-(c-.95)/(1-.95));1<a?a=1:0>a&&(a=0);glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);glEnable(GL_BLEND);glColor4d(.6,.6,.6,a);glBegin(GL_LINE_STRIP);glVertex3f(295,293,0);glVertex3f(505,293,0);glVertex3f(505,307,0);glVertex3f(295,307,0);glVertex3f(295,293,0);glEnd();glColor4d(.3,.3,.3,a);glBegin(GL_QUADS);glVertex3f(300,298,0);glVertex3f(b,298,0);glVertex3f(b,302,0);glVertex3f(300,302,0);glEnd();glDisable(GL_BLEND);
glColor4d(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,g){if(void 0!==d)for(a=b=c=0,void 0!==g&&(c=g.x,b=g.y,a=g.z),g=0;g<d.length;g++){var f=d[g];void 0===f.x&&(f.x=c);void 0===f.y&&(f.y=b);void 0===f.z&&(f.z=a);c=f.x;b=f.y;a=f.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,g){this.setSyncDefaults(d,"color");var f=d=255,e=255,h=255;void 0===g&&(g=[{}]);Utils.preprocessTimeAnimation(c,b,a,g);for(c=0;c<g.length;c++)b=g[c],void 0===b.r&&(b.r=d),void 0===b.g&&(b.g=f),void 0===b.b&&(b.b=e),void 0===b.a&&(b.a=h),d=b.r,f=b.g,e=b.b,h=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 g=a=b=c=0;g<d.angle.length;g++){var f=d.angle[g];void 0===f.degreesX&&(f.degreesX=c);void 0===f.degreesY&&(f.degreesY=b);void 0===f.degreesZ&&(f.degreesZ=a);void 0!==f.pivot&&debugErrorPrint("angle.pivot is deprecated. move pivot under animation. incorrectJson: "+JSON.stringify(f,
null,2));c=f.degreesX;b=f.degreesY;a=f.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 g=1E3,f=0;f<d.perspective.length;f++){var e=d.perspective[f];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=g);c=e.fov;b=e.aspect;a=e.near;g=e.far}};
Loader.prototype.preprocessScaleAnimation=function(c,b,a,d){this.setSyncDefaults(d,"scale");void 0===d.scale&&(d.scale=[{}]);for(var g=0;g<d.scale.length;g++){var f=d.scale[g];void 0!==f.uniform3d?(f.x=f.uniform3d,f.y=f.uniform3d,f.z=f.uniform3d):void 0!==f.uniform2d&&(f.x=f.uniform2d,f.y=f.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,g){void 0!==d.position&&(this.setSyncDefaults(d,"position"),Utils.preprocessTimeAnimation(c,b,a,d.position),this.preprocess3dCoordinateAnimation(c,b,a,d.position,g))};
Loader.prototype.preprocessPivotAnimation=function(c,b,a,d,g){void 0!==d.pivot&&(this.setSyncDefaults(d,"pivot"),Utils.preprocessTimeAnimation(c,b,a,d.pivot),this.preprocess3dCoordinateAnimation(c,b,a,d.pivot,g))};
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]=[]);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.shader&&this.addNotifyResource(d.shader.name);void 0!==d.initFunction&&this.addNotifyResource(d.initFunction);
this.animationLayers[b].push(d)}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 g=this.animationLayers[d].length,f=0;f<g;f++){var e=this.animationLayers[d][f];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.name),this.validateResourceLoaded(e,e.shader.ref,"Could not load "+
e.shader.name),this.notifyResourceLoaded(e.shader.name));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 h=1;void 0!==e.shape.radius&&(h=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,h,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);h=30;void 0!==e.shape.slices&&(h=e.shape.slices);var n=30;void 0!==e.shape.stacks&&(n=e.shape.stacks);e.ref=setObjectCylinderData(e.object,k,l,m,h,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),h=30,void 0!==e.shape.slices&&(h=e.shape.slices),m=30,void 0!==e.shape.loops&&(m=e.shape.loops),e.ref=setObjectDiskData(e.object,k,l,h,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);this.validateResourceLoaded(e,e.ref,"Could not load "+e.object)&&(!1===e.objectLighting&&useObjectLighting(e.ref.ptr,0),!1===e.objectCamera&&useObjectCamera(e.ref.ptr,0));!0===Settings.demoScript.kanttuCompatibility&&void 0===e.objectLighting&&(e.objectLighting=!1)}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;h=c;k=b;l=k-h;this.preprocessAnimationDefinitions(h,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(k=0;k<e.image.length;k++)!0===Utils.isString(e.image[k])&&(e.image[k]={name:e.image[k]});e.ref=imageLoadImage(e.image[0].name);e.multiTexRef=[e.ref];for(k=1;k<e.image.length;k++)e.multiTexRef.push(imageLoadImage(e.image[k].name));for(k=0;k<e.image.length;k++)Utils.isVideo(e.image[k].name)&&
(h=e.multiTexRef[k],h.video={},void 0!==e.image[k].video&&(h.video=e.image[k].video),h.video.ref=videoLoad(e.image[k].name),0==k&&(e.ref.video=h.video));void 0===e.perspective&&(e.perspective="2d");void 0===e.align&&void 0===e.position&&(e.align=1);h=c;k=b;l=k-h;this.preprocessAnimationDefinitions(h,l,k,e);c="Could not load "+e.image[0].name;this.validateResourceLoaded(e,e.ref,c);for(k=0;k<e.multiTexRef.length;k++)h=e.multiTexRef[k],this.validateResourceLoaded(e,h,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.align&&void 0===e.position&&(e.align=1),h=c,k=b,l=k-h,this.preprocessAnimationDefinitions(h,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=h=c,l=k-h,this.preprocessDimensionAnimation(h,l,k,e),this.notifyResourceLoaded(e.fbo.name)):void 0!==e.light?(e.type="light",k=h=c,l=k-h,this.preprocessPositionAnimation(h,l,k,e,{x:0,y:0,z:1}),void 0!==e.ambientColor&&(k=h=c,l=k-h,this.preprocessColorAnimation(h,l,k,e,e.ambientColor)),void 0!==e.diffuseColor&&(k=h=c,l=k-h,this.preprocessColorAnimation(h,l,k,e,
e.diffuseColor)),void 0!==e.specularColor&&(k=h=c,l=k-h,this.preprocessColorAnimation(h,l,k,e,e.specularColor))):void 0!==e.camera&&(e.type="camera",k=h=c,l=k-h,this.preprocessPerspectiveAnimation(h,l,k,e),k=h=c,l=k-h,this.preprocessPositionAnimation(h,l,k,e,{x:0,y:0,z:2}),k=h=c,l=k-h,void 0!==e.sync&&void 0===e.sync.target&&(e.sync.target=!0===e.sync.all?!0:!1),Utils.preprocessTimeAnimation(h,l,k,e.target),this.preprocess3dCoordinateAnimation(h,l,k,e.target,{x:0,y:0,z:0}),k=h=c,l=k-h,void 0!==e.sync&&
void 0===e.sync.up&&(e.sync.up=!0===e.sync.all?!0:!1),Utils.preprocessTimeAnimation(h,l,k,e.up),this.preprocess3dCoordinateAnimation(h,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 g=b.length,f=0;f<g;f++){var e=b[f];if(c>=e.start){var h=(c-e.start)/e.duration;d.x=
a(h,d.x,Utils.evaluateVariable(b,e.x));d.y=a(h,d.y,Utils.evaluateVariable(b,e.y));d.z=a(h,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 g=
interpolate,f=b.perspective.length,e=0;e<f;e++){var h=b.perspective[e];if(d>=h.start){var k=(d-h.start)/h.duration;a.fov=g(k,a.fov,Utils.evaluateVariable(b,h.fov));a.aspect=g(k,a.aspect,Utils.evaluateVariable(b,h.aspect));a.near=g(k,a.near,Utils.evaluateVariable(b,h.near));a.far=g(k,a.far,Utils.evaluateVariable(b,h.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 g=interpolate,f=0;f<a.length;f++){var e=a[f];if(c>=e.start){var h=(c-e.start)/e.duration;d.r=g(h,d.r,Utils.evaluateVariable(b,e.r));d.g=
g(h,d.g,Utils.evaluateVariable(b,e.g));d.b=g(h,d.b,Utils.evaluateVariable(b,e.b));d.a=g(h,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 g=interpolate,f=b.angle.length,e=0;e<f;e++){var h=b.angle[e];if(d>=h.start){var k=(d-h.start)/h.duration;a.degreesX=g(k,a.degreesX,Utils.evaluateVariable(b,h.degreesX));a.degreesY=g(k,a.degreesY,Utils.evaluateVariable(b,h.degreesY));a.degreesZ=g(k,a.degreesZ,Utils.evaluateVariable(b,h.degreesZ));a.x=g(k,a.x,Utils.evaluateVariable(b,h.x));a.y=g(k,a.y,Utils.evaluateVariable(b,h.y));a.z=g(k,a.z,Utils.evaluateVariable(b,h.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,g=a.y,f=a.z;Settings.demoScript.kanttuCompatibility&&(g=getScreenHeight()-a.y);setTexturePosition(b.ref.ptr,d,g,f)}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){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 d=f.x,g=f.y;Settings.demoScript.kanttuCompatibility&&(d=-(getTextStringWidth()*a.x)/2,a=-(getTextStringHeight()*
a.y)/2,d+=f.x,g=getScreenHeight()-(f.y-a));setTextPosition(d,g,0)}void 0!==b.align&&alignTextCenter(b.align)}else if(void 0!==b.position){var f=this.calculatePositionAnimation(c,b);setTextPosition(f.x,f.y,f.z)}f=this.calculateColorAnimation(c,b,b.color);glColor4ub(f.r,f.g,f.b,f.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,g=(c-b.start)*b.fps;void 0!==b.frame&&(g=b.frame);var f=b.clearDepthBuffer;void 0!==b.shape&&"CUSTOM"===b.shape.type&&(a=!0);a&&glPushMatrix();f&&glClear(GL_DEPTH_BUFFER_BIT);drawObject(b.ref.ptr,d,g,f)}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,g=0;g<d;g++){glPushAttrib(GL_CURRENT_BIT);var f=c[a][g];void 0===f.error&&(b>=f.start&&b<f.end&&(Sync.calculateAnimationSync(b,f),void 0!==f.shader&&Shader.enableShader(f),"image"===f.type?this.drawImageAnimation(b,f):"text"===f.type?this.drawTextAnimation(b,f):"object"===f.type?this.drawObjectAnimation(b,f):"fbo"===f.type?this.drawFboAnimation(b,f):"light"===
f.type?this.drawLightAnimation(b,f):"camera"===f.type&&this.drawCameraAnimation(b,f),void 0!==f.runFunction&&Utils.evaluateVariable(f,f.runFunction),void 0!==f.shader&&Shader.disableShader(f)),glPopAttrib())}glPopMatrix()}};
