try{window||(self.window=self,self.document={},self.fakeWindow=!0,self.console={log:function(){}})}catch(e$$8){self.window=self,self.document={},self.fakeWindow=!0,self.console={log:function(){}}} (function(m,w,t,h,o){function r(a,e){if("object"!==typeof a)return q("enumerator validation failed, invalid type base object."),o;if(e===o)return o;if("number"===typeof e)return e;if("string"===typeof e){var f=parseInt(e,10);if(""!==e&&isFinite(f))return f;f=e.toUpperCase();f=a[f];if(f!==o)return f;q("enumerator validation failed, unknown enum value: "+e);var f="",b;for(b in a)a.hasOwnProperty(b)&&(""!==f&&(f+=", "),f+=b.toLowerCase());q("possible enum values are: "+f)}return o}var d="";try{for(var g= w.querySelectorAll("script"),c=0,a=g.length;cf){b=f;e=f*c.GLCore.fixed_aspect}f=b}if(a.getContext!==o){a.width=e;a.height=f;if(!c.GLCore.fixed_size){a.style.left=(m.innerWidth/2-e/2|0)+"px";a.style.top=(m.innerHeight/2-f/2|0)+"px";a.style.position="absolute"}n.viewport(0,0,e,f)}else a.resize(e,f)},setDepthAlpha:function(a,e,f){B.depth_alpha=a;B.depth_alpha_near=e;B.depth_alpha_far=f},setDefaultFilter:function(a){B.default_filter=r(c.enums.texture.filter, a)},setSoftShadows:function(a){B.soft_shadow=a},setFog:function(a){B.fog_enabled=a},setFogExp:function(a,e){B.fog_enabled=true;B.fogLinear=false;B.fogExp=true;B.fogColor=a;B.fogDensity=e},setNoise:function(a){B.fogNoise=a},setFogLinear:function(a,e,f){B.fog_enabled=true;B.fogExp=false;B.fogLinear=true;B.fogColor=a;B.fogNear=e;B.fogFar=f},setCanvasSizeFactor:function(a){B.canvasSizeFactor=a},setQuality:function(a){a=r(s.quality,a);if(a===s.quality.HIGH)c.features=G;else if(a===s.quality.MEDIUM)c.features= C;else if(a===s.quality.LOW)c.features=u;c.quality=a;return c.features},getQuality:function(){return c.features}},I=function(a,e,f){for(var n,b=w.getElementsByTagName("script"),q=0;qe?a=g.add(a,n):qMath.abs(b))return!1;a=-(q+a[0]*f[0]+a[1]*f[1]+a[2]*f[2])/b;return[f[0]+a*(e[0]-f[0]),f[1]+a*(e[1]-f[1]),f[2]+a*(e[2]-f[2])]}},c={lookat:function(a,b,f,e,q,n,c,d,x){var u=[],h=[],o=[],h=[];u[0]=e-a;u[1]=q-b;u[2]=n-f;o[0]=c;o[1]=d;o[2]=x;u=g.normalize(u);h=g.cross(u,o);h=g.normalize(h);o=g.cross(h,u);h=[h[0],o[0],-u[0],0,h[1],o[1],-u[1],0,h[2],o[2],-u[2],0,0,0,0,1];e=new m.Transform(h);e.translate([-a,-b,-f]);return e.getResult()},multiply:function(a,b,f){f=== h&&(f=[]);f[0]=a[0]*b[0]+a[4]*b[1]+a[8]*b[2]+a[12]*b[3];f[1]=a[1]*b[0]+a[5]*b[1]+a[9]*b[2]+a[13]*b[3];f[2]=a[2]*b[0]+a[6]*b[1]+a[10]*b[2]+a[14]*b[3];f[3]=a[3]*b[0]+a[7]*b[1]+a[11]*b[2]+a[15]*b[3];f[4]=a[0]*b[4]+a[4]*b[5]+a[8]*b[6]+a[12]*b[7];f[5]=a[1]*b[4]+a[5]*b[5]+a[9]*b[6]+a[13]*b[7];f[6]=a[2]*b[4]+a[6]*b[5]+a[10]*b[6]+a[14]*b[7];f[7]=a[3]*b[4]+a[7]*b[5]+a[11]*b[6]+a[15]*b[7];f[8]=a[0]*b[8]+a[4]*b[9]+a[8]*b[10]+a[12]*b[11];f[9]=a[1]*b[8]+a[5]*b[9]+a[9]*b[10]+a[13]*b[11];f[10]=a[2]*b[8]+a[6]*b[9]+ a[10]*b[10]+a[14]*b[11];f[11]=a[3]*b[8]+a[7]*b[9]+a[11]*b[10]+a[15]*b[11];f[12]=a[0]*b[12]+a[4]*b[13]+a[8]*b[14]+a[12]*b[15];f[13]=a[1]*b[12]+a[5]*b[13]+a[9]*b[14]+a[13]*b[15];f[14]=a[2]*b[12]+a[6]*b[13]+a[10]*b[14]+a[14]*b[15];f[15]=a[3]*b[12]+a[7]*b[13]+a[11]*b[14]+a[15]*b[15];return f},vec4_multiply:function(a,b,f){f===h&&(f=[]);f[0]=b[0]*a[0]+b[4]*a[1]+b[8]*a[2]+b[12]*a[3];f[1]=b[1]*a[0]+b[5]*a[1]+b[9]*a[2]+b[13]*a[3];f[2]=b[2]*a[0]+b[6]*a[1]+b[10]*a[2]+b[14]*a[3];f[3]=b[3]*a[0]+b[7]*a[1]+b[11]* a[2]+b[15]*a[3];return f},vec3_multiply:function(a,b,f){f===h&&(f=[]);f[0]=b[0]*a[0]+b[4]*a[1]+b[8]*a[2]+b[12];f[1]=b[1]*a[0]+b[5]*a[1]+b[9]*a[2]+b[13];f[2]=b[2]*a[0]+b[6]*a[1]+b[10]*a[2]+b[14];return f},perspective:function(a,b,f,e){a=Math.tan(a*Math.PI/360);return[1/(a*b),0,0,0,0,1/a,0,0,0,0,-(e+f)/(e-f),-1,0,0,-(2*e*f)/(e-f),0]},ortho:function(a,b,f,e,q,n){return[2/(b-a),0,0,0,0,2/(e-f),0,0,0,0,-2/(n-q),0,-(a+b)/(b-a),-(e+f)/(e-f),-(n+q)/(n-q),1]},determinant:function(a){return(a[0]*a[5]-a[1]* a[4])*(a[10]*a[15]-a[11]*a[14])-(a[0]*a[6]-a[2]*a[4])*(a[9]*a[15]-a[11]*a[13])+(a[0]*a[7]-a[3]*a[4])*(a[9]*a[14]-a[10]*a[13])+(a[1]*a[6]-a[2]*a[5])*(a[8]*a[15]-a[11]*a[12])-(a[1]*a[7]-a[3]*a[5])*(a[8]*a[14]-a[10]*a[12])+(a[2]*a[7]-a[3]*a[6])*(a[8]*a[13]-a[9]*a[12])},coFactor:function(){},transpose:function(a){return[a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15]]},inverse_mat3:function(a){var b=[],f=a[0],e=a[1],q=a[2],n=a[4],c=a[5],g=a[6],d=a[8],u=a[9],a=a[10], h=a*c-g*u,o=-a*n+g*d,m=u*n-c*d,r=f*h+e*o+q*m;if(!r)return null;r=1/r;b[0]=h*r;b[1]=(-a*e+q*u)*r;b[2]=(g*e-q*c)*r;b[3]=o*r;b[4]=(a*f-q*d)*r;b[5]=(-g*f+q*n)*r;b[6]=m*r;b[7]=(-u*f+e*d)*r;b[8]=(c*f-e*n)*r;return b},inverse:function(a,b){var f=a[0]*a[5]-a[1]*a[4],e=a[0]*a[6]-a[2]*a[4],q=a[0]*a[7]-a[3]*a[4],n=a[1]*a[6]-a[2]*a[5],c=a[1]*a[7]-a[3]*a[5],g=a[2]*a[7]-a[3]*a[6],d=a[8]*a[13]-a[9]*a[12],u=a[8]*a[14]-a[10]*a[12],o=a[8]*a[15]-a[11]*a[12],m=a[9]*a[14]-a[10]*a[13],r=a[9]*a[15]-a[11]*a[13],t=a[10]* a[15]-a[11]*a[14],v=f*t-e*r+q*m+n*o-c*u+g*d;return 0!==v?(b===h&&(b=[]),b[0]=0+a[5]*t-a[6]*r+a[7]*m,b[4]=0-a[4]*t+a[6]*o-a[7]*u,b[8]=0+a[4]*r-a[5]*o+a[7]*d,b[12]=0-a[4]*m+a[5]*u-a[6]*d,b[1]=0-a[1]*t+a[2]*r-a[3]*m,b[5]=0+a[0]*t-a[2]*o+a[3]*u,b[9]=0-a[0]*r+a[1]*o-a[3]*d,b[13]=0+a[0]*m-a[1]*u+a[2]*d,b[2]=0+a[13]*g-a[14]*c+a[15]*n,b[6]=0-a[12]*g+a[14]*q-a[15]*e,b[10]=0+a[12]*c-a[13]*q+a[15]*f,b[14]=0-a[12]*n+a[13]*e-a[14]*f,b[3]=0-a[9]*g+a[10]*c-a[11]*n,b[7]=0+a[8]*g-a[10]*q+a[11]*e,b[11]=0-a[8]*c+a[9]* q-a[11]*f,b[15]=0+a[8]*n-a[9]*e+a[10]*f,f=1/v,b[0]*=f,b[1]*=f,b[2]*=f,b[3]*=f,b[4]*=f,b[5]*=f,b[6]*=f,b[7]*=f,b[8]*=f,b[9]*=f,b[10]*=f,b[11]*=f,b[12]*=f,b[13]*=f,b[14]*=f,b[15]*=f,b):null},identity:function(a){if(a==h)return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=0;a[5]=1;a[6]=0;a[7]=0;a[8]=0;a[9]=0;a[10]=1;a[11]=0;a[12]=0;a[13]=0;a[14]=0;a[15]=1},translate:function(a,b,f,e){a=[1,0,0,0,0,1,0,0,0,0,1,0,a,b,f,1];if(e===h)return a;c.multiply(e.slice(0),a,e)},rotateAxis:function(a, b,f,e,q){var n=Math.sin(a*(Math.PI/180)),a=Math.cos(a*(Math.PI/180)),b=[a+b*b*(1-a),b*f*(1-a)-e*n,b*e*(1-a)+f*n,0,f*b*(1-a)+e*n,a+f*f*(1-a),f*e*(1-a)-b*n,0,e*b*(1-a)-f*n,e*f*(1-a)+b*n,a+e*e*(1-a),0,0,0,0,1];if(q===h)return b;c.multiply(q.slice(0),b,q)},rotate:function(a,b,f,e){var q;e===h&&(e=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);0!==f&&(q=Math.sin(f*(Math.PI/180)),f=Math.cos(f*(Math.PI/180)),c.multiply(e.slice(0),[f,q,0,0,-q,f,0,0,0,0,1,0,0,0,0,1],e));0!==b&&(q=Math.sin(b*(Math.PI/180)),f=Math.cos(b* (Math.PI/180)),c.multiply(e.slice(0),[f,0,-q,0,0,1,0,0,q,0,f,0,0,0,0,1],e));0!==a&&(q=Math.sin(a*(Math.PI/180)),f=Math.cos(a*(Math.PI/180)),c.multiply(e.slice(0),[1,0,0,0,0,f,q,0,0,-q,f,0,0,0,0,1],e));return e},scale:function(a,b,f,e){if(e===h)return[a,0,0,0,0,b,0,0,0,0,f,0,0,0,0,1];c.multiply(e.slice(0),[a,0,0,0,0,b,0,0,0,0,f,0,0,0,0,1],e)},transform:function(a,b,f){var e=c.identity();a&&c.translate(a[0],a[1],a[2],e);b&&(0===b[0]&&0===b[1]&&0===b[2]||c.rotate(b[0],b[1],b[2],e));f&&(1===f[0]&&1=== f[1]&&1===f[2]||c.scale(f[0],f[1],f[2],e));return e}};w.prototype={setIdentity:function(){this.m_stack[this.c_stack]=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];this.valid===this.c_stack&&this.c_stack&&this.valid--;return this},getIdentity:function(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]},invalidate:function(){this.valid=0;this.result=null;return this},getResult:function(){var a=m.mat4;if(!this.c_stack)return this.m_stack[0];var b=o;this.valid>this.c_stack-1&&(this.valid=this.c_stack-1);for(var f=this.valid;f< this.c_stack+1;f++)b=a.multiply(b,this.m_stack[f]),this.m_cache[f]=b;this.valid=this.c_stack-1;return this.result=this.m_cache[this.c_stack]},pushMatrix:function(a){this.c_stack++;this.m_stack[this.c_stack]=a?a:o;return this},popMatrix:function(){if(0!==this.c_stack)return this.c_stack--,this},clearStack:function(a){this.m_stack=[];this.m_cache=[];this.valid=this.c_stack=0;this.result=null;a!==h?this.m_stack[0]=a:this.setIdentity();return this},translate:function(a,b,f){var e=m.mat4;if("object"=== typeof a)return this.translate(a[0],a[1],a[2]);var q=this.getIdentity();q[12]=a;q[13]=b;q[14]=f;this.m_stack[this.c_stack]=e.multiply(this.m_stack[this.c_stack],q);this.valid===this.c_stack&&this.c_stack&&this.valid--;return this},scale:function(a,b,f){var e=m.mat4;if("object"===typeof a)return this.scale(a[0],a[1],a[2]);var q=this.getIdentity();q[0]=a;q[5]=b;q[10]=f;this.m_stack[this.c_stack]=e.multiply(this.m_stack[this.c_stack],q);this.valid===this.c_stack&&this.c_stack&&this.valid--;return this}, rotate:function(a,b,f,e){var q=m.mat4;if("object"===typeof a)return this.rotate(a[0],1,0,0),this.rotate(a[1],0,1,0),this.rotate(a[2],0,0,1),this;var n,c;if(b||f||e)n=Math.sin(-a*(Math.PI/180)),c=Math.cos(-a*(Math.PI/180));b&&(a=this.getIdentity(),a[5]=c*b,a[9]=n*b,a[6]=-n*b,a[10]=c*b,this.m_stack[this.c_stack]=q.multiply(a,this.m_stack[this.c_stack]));f&&(b=this.getIdentity(),b[0]=c*f,b[8]=-n*f,b[2]=n*f,b[10]=c*f,this.m_stack[this.c_stack]=q.multiply(b,this.m_stack[this.c_stack]));e&&(f=this.getIdentity(), f[0]=c*e,f[4]=n*e,f[1]=-n*e,f[5]=c*e,this.m_stack[this.c_stack]=q.multiply(f,this.m_stack[this.c_stack]));this.valid===this.c_stack&&this.c_stack&&this.valid--;return this}};t.prototype={length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.length());this.x/=a;this.y/=a;this.z/=a;this.w/=a},fromMatrix:function(a){var b=1+a[0]+a[5]+a[10],f,e,q;1.0E-8a[5]&&a[0]>a[10]?(f=2*Math.sqrt(1+a[0]-a[5]-a[10]),b=0.25*f,e=(a[4]+a[1])/f,q=(a[2]+a[8])/f,a=(a[9]-a[6])/f):a[5]>a[10]?(f=2*Math.sqrt(1+a[5]-a[0]-a[10]),b=(a[4]+a[1])/f,e=0.25*f,q=(a[9]+a[6])/f,a=(a[2]-a[8])/f):(f=2*Math.sqrt(1+a[10]-a[0]-a[5]),b=(a[2]+a[8])/f,e=(a[9]+a[6])/f,q=0.25*f,a=(a[4]-a[1])/f);this.x=b;this.y=e;this.z=q;this.w=a},fromEuler:function(a,b,f){var e=Math.cos(Math.PI/180*b/2),b=Math.sin(Math.PI/180*b/2),q=Math.cos(Math.PI/180*f/2),f=Math.sin(Math.PI/180*f/2),n=Math.cos(Math.PI/ 180*a/2),a=Math.sin(Math.PI/180*a/2),c=e*q,g=b*f;this.w=c*n-g*a;this.x=c*a+g*n;this.y=b*q*n+e*f*a;this.z=e*f*n-b*q*a},toEuler:function(){var a=this.w*this.w,b=this.x*this.x,f=this.y*this.y,e=this.z*this.z,q=180/Math.PI*Math.atan2(2*(this.y*this.z+this.x*this.w),-b-f+e+a),n=180/Math.PI*Math.asin(-2*(this.x*this.z-this.y*this.w)),a=180/Math.PI*Math.atan2(2*(this.x*this.y+this.z*this.w),b-f-e+a);return[q,n,a]},multiply:function(a,b){b===h&&(b=a,a=this);return new t(a.x*b.w+a.w*b.x+a.y*b.z-a.z*b.y,a.y* b.w+a.w*b.y+a.z*b.x-a.x*b.z,a.z*b.w+a.w*b.z+a.x*b.y-a.y*b.x,a.w*b.w-a.x*b.x-a.y*b.y-a.z*b.z)}};return{vec2:{equal:function(a,b,f){f===h&&(f=1.0E-8);return a===h&&b===h?!0:a===h||b===h?!1:Math.abs(a[0]-b[0])b[0]?a[0]:b[0],n=a[1]>b[1]?a[1]:b[1];return(a[0]b[0]&&(a[0][0]=b[0]);a[0][1]>b[1]&&(a[0][1]=b[1]);a[0][2]>b[2]&&(a[0][2]=b[2]);a[1][0]b[1][0]||a[1][0]b[1][1]||a[1][1]b[1][2]||a[1][2]=b[0][0]&&a[1][0]<=b[1][0]&&a[0][1]>=b[0][1]&&a[1][1]<=b[1][1]&&a[0][2]>=b[0][2]&&a[1][2]<=b[1][2]?d.aabb.A_INSIDE_B:b[0][0]>=a[0][0]&&b[1][0]<=a[1][0]&&b[0][1]>=a[0][1]&&b[1][1]<=a[1][1]&&b[0][2]>=a[0][2]&&b[1][2]<=a[1][2]?d.aabb.B_INSIDE_A: d.aabb.INTERSECT}},plane:{classifyPoint:function(a,b){var f=a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3];return 0>f?-1:0/gm, "").replace(/\n/g," ").split(/(<[^>]*>)([^<]*)/gm),g=/^\s+$/gm,c,a=[],b=[],f={},e=f,q=0,n=d.length;q]*>/.test(s))if(/<.*?>/.test(s)){c=s.split(/<([^>]*?)(.*)?>/g)[2];if("/"!==c[0]&&(s=c.split(" "),c=s[0],s=s.slice(1).join(" "),a.push(c),b.push(f),f[c]&&!(f[c]instanceof Array)?f[c]=[f[c]]:(f[c]||(f[c]={}),f=f[c]),f instanceof Array&&(f.push({}),f=f[f.length-1]),"/"===c.substr(c.length-1)||"/"===s.substr(s.length-1)))c="/"+c;if("/"===c[0]){c= c.substr(1);if(a.length&&a[a.length-1]!==c)return console.log("Unmatched tag, aborting: "+c),!1;a.pop();f=b.length?b[b.length-1]:null;b.pop()}}else{var F=b[b.length-1][c];F instanceof Array?(F.pop(),F.push(r.parseNumeric(s))):b[b.length-1][c]=r.parseNumeric(s)}}return e},xmlstring2badgerfish:function(d){for(var d=d.replace(/<\!--.*?--\>/gm,"").replace(/\n/g," ").split(/(<[^>]*>)([^<]*)/gm),g=/^\s+$/gm,c,a=[],b=[],f={},e=f,q=0,n=d.length;q]*>/.test(c))if(/<.*?>/.test(c)){c= c.split(/<([^>]*?)(.*)?>/g)[2];if("/"!==c[0]){var s=c.split(" ");c=s[0];s=s.slice(1).join(" ");a.push(c);b.push(f);f[c]&&!(f[c]instanceof Array)?f[c]=[f[c]]:f[c]||(f[c]={});f=f[c];f instanceof Array&&(f.push({}),f=f[f.length-1]);if("/"===c.substr(c.length-1)||"/"===s.substr(s.length-1))c="/"+c;for(var s=r.multiSplit(s,"= "),F="",x=0;x=h?w.push(h):(2047>=h?w.push(h>>6|192):(65535>=h?w.push(h>>12|224):(w.push(h>>18|240),w.push(h>>12&63|128)),w.push(h>>6&63|128)),w.push(h&63|128));return w}; Iuppiter.Base64={CA:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",CAS:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",IA:Array(256),IAS:Array(256),init:function(){var m;for(m=0;256>m;m++)Iuppiter.Base64.IA[m]=-1,Iuppiter.Base64.IAS[m]=-1;m=0;for(iS=Iuppiter.Base64.CA.length;m>18&63),h[a++]=t.charAt(b>>12&63),h[a++]=t.charAt(b>>6&63),h[a++]=t.charAt(b&63);c=r-d;0>12),h[g-3]=t.charAt(b>>6&63),h[g-2]=2==c?t.charAt(b&63):"=",h[g-1]="=");return h.join("")},decode:function(m, w){var t,h,o,r,d,g,c,a,b,f,e,q;t=w?Iuppiter.Base64.IAS:Iuppiter.Base64.IA;m.constructor==Array?(o=m,d=!0):(o=Iuppiter.toByteArray(m),d=!1);r=o.length;g=0;for(c=r-1;gt[o[g]];)g++;for(;0t[o[c]];)c--;a="="==o[c]?"="==o[c-1]?2:1:0;h=c-g+1;b=76>3)-a;h=Array(r);e=f=0;for(eLen=3*(r/3);f>16&255,h[f++]=q>>8&255,h[f++]=q&255,0>t&255}if(d)return h;for(q=0;qt;t++)b[t]=3435973836;m=m.constructor==Array?m:Iuppiter.toByteArray(m);for(t=m.length;h=t-1-16){c=t;for(o=h=0;c;c--)w[o++]=m[h++];break}g=1;d=o;w[o++]=0}if(h>t-66)w[o++]=m[h++];else if(r=(m[h]+13^m[h+1]-13^m[h+2])&255,a=h-b[r]&1023,b[r]=h,r=h-a,0<=r&&r!=h&&m[h]==m[r]&&m[h+1]==m[r+1]&&m[h+2]==m[r+2]){w[d]|=g;for(c=3;66>c&&m[h+c]==m[r+c];c++);w[o++]=c-3<<2|a>>8;w[o++]=a;h+= c}else w[o++]=m[h++]}return w};Iuppiter.decompress=function(m,w){var t,h=[],o,r=0,d=0,g,c,a=128,b;t=m.constructor==Array?m:Iuppiter.toByteArray(m);for(o=t.length;r>2)+3,g=(t[r]<<8|t[r+1])&1023,r+=2,0<=(g=d-g))for(;0<=--b;)h[d++]=h[g++];else break;else h[d++]=t[r++]}if(!("undefined"==typeof w?0:w)){for(t=0;t "+e[d-1]);console.log(b+d+", :"+g)}}},bindSelf:function(a){var e,b,n;-1!==a.indexOf(".")?-1!==a.indexOf("[")?(e=a.split("["),n=e[0],e=e[1].split("]"),b=e[0],e=e[1].split("."),e=e[1],this[n]===h&&(this[n]=[]),this[n][b]===h&&(this[n][b]={}),this[n][b][e]=this.uniforms[a]):(e=a.split("."),n=e[0],e=e[1],this[n]===h&&(this[n]={}),this[n][e]=this.uniforms[a]):-1!==a.indexOf("[")?(e=a.split("["),n=e[0], e=e[1].split("]"),b=e[0],this[n]===h&&(this[n]=[]),this[n][b]=this.uniforms[a]):this[a]=this.uniforms[a]},addMatrix:function(a,e){this.use();this.uniforms[a]=o.gl.getUniformLocation(this.shader,a);this.uniform_type[a]=r.shader.uniform.MATRIX;this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]);e!==h&&this.setMatrix(a,e);this.bindSelf(a);return this.uniforms[a]},addVector:function(a,e){this.use();this.uniforms[a]=o.gl.getUniformLocation(this.shader,a);this.uniform_type[a]=r.shader.uniform.VECTOR; this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]);e!==h&&this.setVector(a,e);this.bindSelf(a);return this.uniforms[a]},addFloat:function(a,e){this.use();this.uniforms[a]=o.gl.getUniformLocation(this.shader,a);this.uniform_type[a]=r.shader.uniform.FLOAT;this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]);e!==h&&this.setFloat(a,e);this.bindSelf(a);return this.uniforms[a]},addVertexArray:function(a){this.use();this.uniforms[a]=o.gl.getAttribLocation(this.shader,a);this.uniform_type[a]= r.shader.uniform.ARRAY_VERTEX;this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]);this.bindSelf(a);return this.uniforms[a]},addUVArray:function(a){this.use();this.uniforms[a]=o.gl.getAttribLocation(this.shader,a);this.uniform_type[a]=r.shader.uniform.ARRAY_UV;this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]);this.bindSelf(a);return this.uniforms[a]},addFloatArray:function(a){this.use();this.uniforms[a]=o.gl.getAttribLocation(this.shader,a);this.uniform_type[a]=r.shader.uniform.ARRAY_FLOAT; this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]);this.bindSelf(a);return this.uniforms[a]},addInt:function(a,e){this.use();this.uniforms[a]=o.gl.getUniformLocation(this.shader,a);this.uniform_type[a]=r.shader.uniform.INT;this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]);e!==h&&this.setInt(a,e);this.bindSelf(a);return this.uniforms[a]},use:function(){o.gl.useProgram(this.shader)},setMatrix:function(a,e){var b=this.uniforms[a];if(null!==b){var n=e.length;16===n? o.gl.uniformMatrix4fv(b,!1,e):9===n?o.gl.uniformMatrix3fv(b,!1,e):4===n&&o.gl.uniformMatrix2fv(b,!1,e)}},setInt:function(a,e){var b=this.uniforms[a];null!==b&&o.gl.uniform1i(b,e)},setFloat:function(a,e){var b=this.uniforms[a];null!==b&&o.gl.uniform1f(b,e)},setVector:function(a,e){var b=this.uniforms[a];if(null!==b){var n=e.length;4==n?o.gl.uniform4fv(b,e):3==n?o.gl.uniform3fv(b,e):2==n?o.gl.uniform2fv(b,e):o.gl.uniform4fv(b,e)}},clearArray:function(a){var e=o.gl,a=this.uniforms[a];null!==a&&e.disableVertexAttribArray(a)}, bindArray:function(a,e){var b=o.gl,n=this.uniforms[a];if(null!==n){var c=this.uniform_type[a];c===r.shader.uniform.ARRAY_VERTEX?(b.bindBuffer(b.ARRAY_BUFFER,e),b.vertexAttribPointer(n,3,b.FLOAT,!1,0,0),b.enableVertexAttribArray(n)):c===r.shader.uniform.ARRAY_UV?(b.bindBuffer(b.ARRAY_BUFFER,e),b.vertexAttribPointer(n,2,b.FLOAT,!1,0,0)):c===r.shader.uniform.ARRAY_FLOAT&&(b.bindBuffer(b.ARRAY_BUFFER,e),b.vertexAttribPointer(n,1,b.FLOAT,!1,0,0))}}};var b={tidyScript:function(a){return a.replace(/\t+/g, " ").replace(/\/\/.*$/gm,"").replace(/\/\*(.|\n)*\*\//g,"").replace(/ +/g," ").replace(/ *\[ */g,"[").replace(/ *\] */g,"]").replace(/ *; */g,";").replace(/ *$/gm,"").replace(/^ */gm,"")},getDefines:function(a){var e={},a=g.multiSplit(a,"\n;");i=0;for(iMax=a.length;i=x.length||("struct"==x[0]?(A=x[1],u[A]={}):A&&(u[A][x[1]]=x[0]))}r.struct=u;c=0;for(n=o.length;cb&&(e=b);this.camera.position=f.add(this.camera.target,f.multiply(f.normalize(f.subtract(this.camera.position,this.camera.target)),e))},bindEvent:function(c,a){this.mEvents[c]=a===r?this.eventDefaults[c]:a},unbindEvent:function(c){this.bindEvent(c,null)},bind:function(){this.canvas.addEventListener("mousemove",this.onMouseMove,!1);this.canvas.addEventListener("mousedown", this.onMouseDown,!1);this.canvas.addEventListener("mouseup",this.onMouseUp,!1);this.canvas.addEventListener("mousewheel",this.onMouseWheel,!1);this.canvas.addEventListener("DOMMouseScroll",this.onMouseWheel,!1);window.addEventListener("keydown",this.onKeyDown,!1);window.addEventListener("keyup",this.onKeyUp,!1)},unbind:function(){this.canvas.removeEventListener("mousemove",this.onMouseMove,!1);this.canvas.removeEventListener("mousedown",this.onMouseDown,!1);this.canvas.removeEventListener("mouseup", this.onMouseUp,!1);this.canvas.removeEventListener("mousewheel",this.onMouseWheel,!1);this.canvas.removeEventListener("DOMMouseScroll",this.onMouseWheel,!1);window.removeEventListener("keydown",this.onKeyDown,!1);window.removeEventListener("keyup",this.onKeyUp,!1)},setCamera:function(c){this.camera=c},getMousePosition:function(){return this.mpos}};return{Timer:w,MainLoop:h,MouseViewController:o,setMainLoop:function(c){m.GLCore.mainloop=c},keyboard:d.keyboard}}); CubicVR.RegisterModule("Texture",function(m){function w(a,e){if(1===a||1===e)return!1;if(1!==a)for(;0===a%2;)a/=2;if(1!==e)for(;0===e%2;)e/=2;return 1B&&(B=I)}r.width=h||B;r.height=o||w*C;c&&(A.fillStyle=c,A.fillRect(0,0,r.width,r.height));A.fillStyle=f;A.font=d;A.textAlign=g;A.textBaseline="top";if(1===C)f=e&&e.x||"center"===g?r.width/2:"right"===g?r.width:0,A.fillText(a,f,q);else for(m=0;mq||q>=f||0>F||F>=e)){s=F-m;var x;0===c&&(x=(1-Math.sqrt(n*n+s*s)/g)/2);s=4*(F*f+q);0===d?0>x&&(x=0):1===d?0>x&&(x=0):2===d&&(x=-x,0u&&(u=0);255H&&(H=0);255z&&(z=0);255t&&(t=0);b[s]=u;b[s+1]=H;b[s+2]=z;b[s+3]=t}},update:function(){var h= w.gl;this.flush();h.bindTexture(h.TEXTURE_2D,m.Textures[this.tex_id]);h.texImage2D(h.TEXTURE_2D,0,h.RGBA,this.width,this.height,0,h.RGBA,h.UNSIGNED_BYTE,this.imageBuffer);h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MAG_FILTER,h.LINEAR);h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MIN_FILTER,h.LINEAR)}}),DrawBufferBrush:h}}); CubicVR.RegisterModule("Material",function(m){function w(a){this.blendEnabled=this.dirtyFlag=this.initialized=!1;this.textures=[];this.shader=[];this.customShader=(a=m.get(a)||{},a.shader||null);null===r&&(r=new m.CustomShader({vertex:"precision lowp float; \nattribute vec3 vertexPosition; uniform mat4 matrixModelView; uniform mat4 matrixProjection; uniform mat4 matrixObject;\nvoid main(void) { gl_Position = matrixProjection * matrixModelView * matrixObject * vec4(vertexPosition,1.0); }",fragment:"precision lowp float; \nvoid main(void) { gl_FragColor = vec4(1.0,0.0,1.0,1.0); }\n"}), r._init_shader(r._vertex,r._fragment,!1));this.customShader&&(!this.customShader._init_shader&&"object"===typeof this.customShader)&&(this.customShader=new m.CustomShader(this.customShader));this.diffuse=a.diffuse||[1,1,1];this.specular=a.specular||[0.1,0.1,0.1];this.color=a.color||[1,1,1];this.ambient=a.ambient||[0,0,0];this.name=a.name||null;this.visible=a.visible!==t?a.visible:!0;this.friction=a.friction!==t?a.friction:0.3;this.collision=a.visible!==t?a.collision:!0;this.opacity=a.opacity===t? 1:a.opacity;this.shininess=a.shininess===t?1:a.shininess;this.max_smooth=a.max_smooth===t?60:a.max_smooth;this.env_amount=a.env_amount===t?0.75:a.env_amount;this.morph=a.morph===t?!1:a.morph;this.color_map=a.colorMap===t?!1:a.colorMap;this.uvOffset=a.uvOffset===t?[0,0]:a.uvOffset;this.noFog=a.noFog===t?!1:a.noFog;this.pointSprite=a.pointSprite||!1;this.pointSize=a.pointSize||0;this.pointCircle=a.pointCircle||0;if(a.textures)for(var b in a.textures)this.setTexture(a.textures[b],b)}var t=m.undef,h= m.GLCore,o=m.enums,r=null,d=[o.texture.map.REFLECT,o.texture.map.SPECULAR,o.texture.map.NORMAL,o.texture.map.BUMP],g=[],c="textureColor textureEnvSphere textureNormal textureBump textureReflect textureSpecular textureAmbient textureAlpha matrixModelView matrixProjection matrixObject matrixNormal vertexPosition vertexNormal vertexColor vertexTexCoord materialTexOffset vertexMorphPosition vertexMorphNormal materialMorphWeight lightDiffuse lightSpecular lightIntensity lightDistance lightPosition lightDirection lightCutOffAngle lightShadowMap lightProjectionMap lightDepthClip lightShadowMatrix lightAmbient materialDiffuse materialColor materialAmbient materialSpecular materialShininess materialEnvironment materialAlpha postDepthInfo".split(" "); w.prototype={clone:function(){var a=new m.Material({diffuse:this.diffuse,specular:this.specular,color:this.color,ambient:this.ambient,opacity:this.opacity,shininess:this.shininess,max_smooth:this.max_smooth,env_amount:this.env_amount,morph:this.morph,colorMap:this.color_map,visible:this.visible,friction:this.friction,collision:this.collision,pointSprite:this.pointSprite,pointSize:this.pointSize,pointCircle:this.pointCircle,name:this.name}),b;for(b in this.textures)this.textures.hasOwnProperty(b)&& a.setTexture(this.textures[b],b);return a},setVisibility:function(a){this.visible=a},getVisibility:function(){return this.visible},setCollision:function(a){this.collision=a},getCollision:function(){return this.collision},setFriction:function(a){this.friction=a},getFriction:function(){return this.friction},setTexture:function(a,b){if(a&&(b=m.parseEnum(o.texture.map,b)||0,m.features.texturePerPixel||-1===d.indexOf(b)))!a.use&&"string"===typeof a&&(a=m.Textures_ref[a]!==t?m.Textures_obj[m.Textures_ref[a]]: new m.Texture(a)),this.textures[b]=a},calcShaderMask:function(){var a;a=0+("object"===typeof this.textures[o.texture.map.COLOR]?o.shader.map.COLOR:0);a+="object"===typeof this.textures[o.texture.map.SPECULAR]?o.shader.map.SPECULAR:0;a+="object"===typeof this.textures[o.texture.map.NORMAL]?o.shader.map.NORMAL:0;a+="object"===typeof this.textures[o.texture.map.BUMP]?o.shader.map.BUMP:0;a+="object"===typeof this.textures[o.texture.map.REFLECT]?o.shader.map.REFLECT:0;a+="object"===typeof this.textures[o.texture.map.ENVSPHERE]? o.shader.map.ENVSPHERE:0;a+="object"===typeof this.textures[o.texture.map.AMBIENT]?o.shader.map.AMBIENT:0;a+="object"===typeof this.textures[o.texture.map.ALPHA]?o.shader.map.ALPHA:0;a+=this.pointSprite?o.shader.mode.POINT_SPRITE:0;a+=this.pointSize?o.shader.mode.POINT_SIZE:0;a+=this.pointCircle?o.shader.mode.POINT_CIRCLE:0;a+=1!==this.opacity?o.shader.map.ALPHA:0;a+=this.color_map?o.shader.map.COLORMAP:0;1!==this.opacity&&(this.blendEnabled=!0);return a},getShaderHeader:function(a,b){return(b!== t?"#define LIGHT_COUNT "+b+"\n":"")+"#define TEXTURE_COLOR "+("object"===typeof this.textures[o.texture.map.COLOR]?1:0)+"\n#define TEXTURE_SPECULAR "+("object"===typeof this.textures[o.texture.map.SPECULAR]?1:0)+"\n#define TEXTURE_NORMAL "+("object"===typeof this.textures[o.texture.map.NORMAL]?1:0)+"\n#define TEXTURE_BUMP "+("object"===typeof this.textures[o.texture.map.BUMP]?1:0)+"\n#define TEXTURE_REFLECT "+("object"===typeof this.textures[o.texture.map.REFLECT]?1:0)+"\n#define TEXTURE_ENVSPHERE "+ ("object"===typeof this.textures[o.texture.map.ENVSPHERE]?1:0)+"\n#define TEXTURE_AMBIENT "+("object"===typeof this.textures[o.texture.map.AMBIENT]?1:0)+"\n#define TEXTURE_ALPHA "+("object"===typeof this.textures[o.texture.map.ALPHA]?1:0)+"\n#define MATERIAL_ALPHA "+(1!==this.opacity?1:0)+"\n#define LIGHT_IS_POINT "+(a===o.light.type.POINT?1:0)+"\n#define LIGHT_IS_DIRECTIONAL "+(a===o.light.type.DIRECTIONAL?1:0)+"\n#define LIGHT_IS_SPOT "+(a===o.light.type.SPOT||a===o.light.type.SPOT_SHADOW||a=== o.light.type.SPOT_SHADOW_PROJECTOR?1:0)+"\n#define LIGHT_SHADOWED "+(a===o.light.type.SPOT_SHADOW||a===o.light.type.SPOT_SHADOW_PROJECTOR||a===o.light.type.AREA?1:0)+"\n#define LIGHT_IS_PROJECTOR "+(a===o.light.type.SPOT_SHADOW_PROJECTOR?1:0)+"\n#define LIGHT_SHADOWED_SOFT "+(h.soft_shadow?1:0)+"\n#define LIGHT_IS_AREA "+(a===o.light.type.AREA?1:0)+"\n#define LIGHT_DEPTH_PASS "+(a===o.light.type.DEPTH_PACK?1:0)+"\n#define FX_DEPTH_ALPHA "+(h.depth_alpha?1:0)+"\n#define VERTEX_MORPH "+(this.morph? 1:0)+"\n#define VERTEX_COLOR "+(this.color_map?1:0)+"\n#define FOG_ENABLED "+(h.fog_enabled&&!this.noFog?1:0)+"\n#define USE_FOG_EXP "+(h.fogExp?1:0)+"\n#define USE_FOG_LINEAR "+(h.fogLinear?1:0)+"\n#define LIGHT_PERPIXEL "+(m.features.lightPerPixel?1:0)+"\n#define POINT_SPRITE "+(this.pointSprite?1:0)+"\n#define POINT_SIZE "+(this.pointSize?1:0)+"\n#define POINT_CIRCLE "+(this.pointCircle?1:0)+"\n\n"},bindObject:function(a,b){var f=h.gl,e=b.vertexPosition,c=b.vertexTexCoord,n=b.vertexNormal,d=b.vertexColor; f.bindBuffer(f.ARRAY_BUFFER,a.compiled.gl_points);f.vertexAttribPointer(e,3,f.FLOAT,!1,0,0);f.enableVertexAttribArray(e);c!==t&&(null!==a.compiled.gl_uvs&&-1!==c)&&(f.bindBuffer(f.ARRAY_BUFFER,a.compiled.gl_uvs),f.vertexAttribPointer(c,2,f.FLOAT,!1,0,0),f.enableVertexAttribArray(c));g.uv=c;n!==t&&(null!==a.compiled.gl_normals&&-1!==n)&&(f.bindBuffer(f.ARRAY_BUFFER,a.compiled.gl_normals),f.vertexAttribPointer(n,3,f.FLOAT,!1,0,0),f.enableVertexAttribArray(n));g.un=n;d!==t&&(null!==a.compiled.gl_colors&& -1!==d)&&(f.bindBuffer(f.ARRAY_BUFFER,a.compiled.gl_colors),f.vertexAttribPointer(d,3,f.FLOAT,!1,0,0),f.enableVertexAttribArray(d));g.uc=d;a.morphTarget&&(e=b.vertexMorphPosition,n=b.vertexMorphNormal,f.bindBuffer(f.ARRAY_BUFFER,a.morphTarget.gl_points),f.vertexAttribPointer(e,3,f.FLOAT,!1,0,0),f.enableVertexAttribArray(e),n!==t&&(null!==a.morphTarget.gl_normals&&-1!==n)&&(f.bindBuffer(f.ARRAY_BUFFER,a.morphTarget.gl_normals),f.vertexAttribPointer(n,3,f.FLOAT,!1,0,0),f.enableVertexAttribArray(n)), f.uniform1f(b.materialMorphWeight,a.morphWeight));a.compiled.unrolled?f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,null):f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,a.compiled.gl_elements)},bindLines:function(a,b){var f=h.gl,e=b.vertexPosition,c=b.vertexTexCoord,n=b.vertexNormal,d=b.vertexColor;a.compiled.unrolled?(f.bindBuffer(f.ARRAY_BUFFER,a.compiled.gl_lines),f.vertexAttribPointer(e,3,f.FLOAT,!1,0,0),f.enableVertexAttribArray(e),g.up=e,c!==t&&(null!==a.compiled.gl_line_uvs&&-1!==c)&&(f.bindBuffer(f.ARRAY_BUFFER, a.compiled.gl_line_uvs),f.vertexAttribPointer(c,2,f.FLOAT,!1,0,0),f.enableVertexAttribArray(c)),g.uv=c,n!==t&&(null!==a.compiled.gl_line_normals&&-1!==n)&&(f.bindBuffer(f.ARRAY_BUFFER,a.compiled.gl_line_normals),f.vertexAttribPointer(n,3,f.FLOAT,!1,0,0),f.enableVertexAttribArray(n)),g.un=n,d!==t&&(null!==a.compiled.gl_line_colors&&-1!==d)&&(f.bindBuffer(f.ARRAY_BUFFER,a.compiled.gl_line_colors),f.vertexAttribPointer(d,3,f.FLOAT,!1,0,0),f.enableVertexAttribArray(d)),g.uc=d):f.bindBuffer(f.ELEMENT_ARRAY_BUFFER, a.compiled.gl_line_elements);a.morphTarget&&(e=b.vertexMorphPosition,n=b.vertexMorphNormal,f.bindBuffer(f.ARRAY_BUFFER,a.morphTarget.gl_lines),f.vertexAttribPointer(e,3,f.FLOAT,!1,0,0),f.enableVertexAttribArray(e),n!==t&&(null!==a.morphTarget.gl_line_normals&&-1!==n)&&(f.bindBuffer(f.ARRAY_BUFFER,a.morphTarget.gl_line_normals),f.vertexAttribPointer(n,3,f.FLOAT,!1,0,0),f.enableVertexAttribArray(n)),f.uniform1f(b.materialMorphWeight,a.morphWeight))},clearObject:function(a,b){var f=h.gl;g.uv!==t&&-1!== g.uv&&f.disableVertexAttribArray(g.uv);g.un!==t&&-1!==g.un&&f.disableVertexAttribArray(g.un);g.uc!==t&&-1!==g.uc&&f.disableVertexAttribArray(g.uc);a.morphTarget&&b&&(up=b.vertexMorphPosition,f.disableVertexAttribArray(up),un=b.vertexMorphNormal,null!==un&&(null!==a.compiled.gl_normals&&-1!==un)&&f.disableVertexAttribArray(un))},use:function(a,b){var f,e=h.gl,d=this.textures,n=!0,b=b||0,a=a||0;this.shader[a]||(this.shader[a]=[]);var g=this.shader[a][b],F=this.customShader&&a===o.light.type.DEPTH_PACK&& !this.customShader.hasDepthPack();g&&(1!==this.opacity&&!0!==this.blendEnabled)&&(this.dirtyFlag=!0);!0===this.dirtyFlag&&(g=null,this.dirtyFlag=!1);if(g)n=g!==r,g.use();else{f=this.calcShaderMask(a);if(!this.customShader||F)m.ShaderPool[a][f]||(m.ShaderPool[a][f]=[]),g=m.ShaderPool[a][f][b];if(!g){var x=this.getShaderHeader(a,b),u=x+h.CoreShader_vs,x=x+h.CoreShader_fs;this.customShader&&!F?this.customShader._initialized||(this.customShader._init_shader(u,x,c),g=this.customShader.getShader(),g.isCompiled()|| (n=!1,g=r.getShader())):(g=new m.Shader(u,x),g.isCompiled()||(n=!1,g=r.getShader()),m.ShaderPool[a][f][b]=g);f=0;if(a!==o.light.type.DEPTH_PACK){if(a===o.light.type.SPOT_SHADOW||a===o.light.type.SPOT_SHADOW_PROJECTOR||a===o.light.type.AREA)f+=b,a===o.light.type.SPOT_SHADOW_PROJECTOR&&(f+=b);"object"===typeof d[o.texture.map.COLOR]&&g.addInt("textureColor",f++);"object"===typeof d[o.texture.map.ENVSPHERE]&&g.addInt("textureEnvSphere",f++);"object"===typeof d[o.texture.map.NORMAL]&&g.addInt("textureNormal", f++);"object"===typeof d[o.texture.map.BUMP]&&g.addInt("textureBump",f++);"object"===typeof d[o.texture.map.REFLECT]&&g.addInt("textureReflect",f++);"object"===typeof d[o.texture.map.SPECULAR]&&g.addInt("textureSpecular",f++);"object"===typeof d[o.texture.map.AMBIENT]&&g.addInt("textureAmbient",f++)}"object"===typeof d[o.texture.map.ALPHA]&&g.addInt("textureAlpha",f++);g.addMatrix("matrixModelView");g.addMatrix("matrixProjection");g.addMatrix("matrixObject");g.addMatrix("matrixNormal");g.addVertexArray("vertexPosition", 0);g.addVertexArray("vertexNormal");this.color_map&&g.addVertexArray("vertexColor");this.morph&&(g.addVertexArray("vertexMorphPosition"),g.addVertexArray("vertexMorphNormal"),g.addFloat("materialMorphWeight",0));for(f=0;fthis.opacity&&e.uniform1f(g.materialAlpha,this.opacity),(h.depth_alpha||a===o.light.type.SPOT_SHADOW||a===o.light.type.SPOT_SHADOW_PROJECTOR||a===o.light.type.AREA)&&e.uniform3fv(g.postDepthInfo, [h.depth_alpha_near,h.depth_alpha_far,0])):e.uniform3fv(g.postDepthInfo,[h.shadow_near,h.shadow_far,0]);g.materialTexOffset&&e.uniform2fv(g.materialTexOffset,this.uvOffset);if(this.pointSprite||this.pointSize)e.uniform1f(g.pointSize,this.pointSize),this.pointSprite||e.uniform3fv(g.viewPort,[h.viewportWidth,h.viewportHeight,0]);this.customShader&&(a!==o.light.type.DEPTH_PACK||a===o.light.type.DEPTH_PACK&&!F)&&this.customShader._doUpdate({material:this,textureIndex:f});return n}};return{Material:w}}); CubicVR.RegisterModule("Mesh",function(m){function w(){this.points=[];this.point_normals=[];this.point_colors=[];this.uvs=[];this.normal=[0,0,0];this.segment=this.material=0}function t(d){this.compiled=null;this.materials=[];this.edges=this.instanceMaterials=this.bb=null;this.faces=[];this.points=[];this.currentFace=-1;this.currentSegment=this.currentMaterial=0;this.morphTarget=this.morphTargets=null;this.morphWeight=0;this.morphTargetIndex=this.morphSourceIndex=-1;this.originBuffer=null;this.genNormals= !0;d=m.get(d)||{};if(d instanceof m.Mesh)this.booleanAdd(d),d._clones=d._clones||1,d._clones++,this.name=d.name?d.name+"_copy"+d._clones:null;else{this.name=d.name||null;this.dynamic=d.dynamic||!1;if(d.material){var g=d.material;g.length?this.materials=g:"object"===typeof g&&(g.use?this.setFaceMaterial(g):this.setFaceMaterial(new m.Material(g)))}(d.point||d.points)&&this.build(d);d.part?this.build(d.part):d.parts&&this.build(d.parts);if((this.primitives=d.primitives||d.primitive||null)&&!this.primitives.length|| "string"===typeof this.primitives)this.primitives=[this.primitives];if(this.primitives&&this.primitives.length)for(var g=0,c=this.primitives.length;gn.length?[0,0,0]:c.normalize(a.normal(q[n[0]],q[n[1]],q[n[2]]));return this},getMaterial:function(d){if(!isNaN(parseInt(d,10)))return this.materials[g];for(var g=0,c=this.materials.length;gf;f++)if(c=a[b][f],d.faceCount[3*b+f]=c?c.length:0,d.faceNormIdx[b]=g,c){e=0;for(c= c.length;ej;j++){s=o.point_normals[j];e=t[0];q=t[1]; n=t[2];x=d.faceCount[3*c+j];b=0;for(iMax=x;bj;j++){s=o.point_normals[j];e=t[0];q=t[1];n=t[2];x=d.faceCount[m++];b=0;for(iMax=x;b"+f.fpb+"], holes not yet supported; perhaps use Mesh.removeDoubles()?");return}f.edge_point||(e=c.multiply(c.add(this.points[f.a],this.points[f.b]),0.5),g?(v=c.multiply(c.add(this.points[H[f.face]],this.points[H[q.face]]),0.5),f.edge_point=c.multiply(c.add(e,v),0.5)):f.edge_point=e,q.edge_point=f.edge_point,f.edge_avg=e,q.edge_avg=e,f.ep_idx=this.addPoint(f.edge_point),q.ep_idx=f.ep_idx);o[f.a]=o[f.a]|| [];o[f.a].push(f.edge_avg);e=this.faces[f.face].uvs;e.length&&(q=e[f.fpa],e=e[f.fpb],f.uv=[(q[0]+e[0])/2,(q[1]+e[1])/2]);q=this.faces[f.face].point_colors;q.length&&(f.color=c.multiply(c.add(q[f.fpa],q[f.fpb]),0.5));q=this.faces[f.face].point_normals;q.length&&(f.normal=c.normalize(c.multiply(c.add(q[f.fpa],q[f.fpb]),0.5)))}if(g){q=[];a=0;for(f=x;an;n++){var A=this.faces[y].points[n],C=-1;if(r[A]!==h){s=0;for(u=r[A].length;sa.bounds[1][0]&&(a.bounds[1][0]=this.points[A][0]),this.points[A][1]>a.bounds[1][1]&&(a.bounds[1][1]=this.points[A][1]),this.points[A][2]>a.bounds[1][2]&&(a.bounds[1][2]=this.points[A][2])),D&&(a.normals===h&&(a.normals=[]),a.normals.push([y,n])),v&&(a.colors===h&&(a.colors=[]),a.colors.push([y,n])),t&&(a.uvs===h&&(a.uvs=[]),a.uvs.push([y,n])),a.elements===h&&(a.elements=[]),a.elements[f]===h&& (a.elements[f]=[]),a.elements[f][e]===h&&(a.elements[f][e]=[]),a.elements[f][e].push(z),r[A]===h&&(r[A]=[]),r[A].push([y,n,z]),z++)}}}if(this.edges){a.line_elements=[];f=0;for(o=this.edges.length;fc?r:-r:0>b?-Math.atan(c/b)+Math.PI:-Math.atan(c/b)},g=function(c,a,b){var f;0===c&&0===b?(f=0,c=0!==a?0>a?-r:r:0):(f=0===b?0>c?r:-r:0>b?-Math.atan(c/b)+Math.PI:-Math.atan(c/b),c=Math.sqrt(c*c+b*b),c=0===c?0>a?-r:r:Math.atan(a/c));return[f,c]};w.prototype={setRotation:function(c){this.rotation=c},setScale:function(c){this.scale= c},setCenter:function(c){this.center=c},setProjectionAxis:function(c){this.projection_axis=c},setProjectionMode:function(c){this.projection_mode=c},setWrapW:function(c){this.wrap_w_count=c},setWrapH:function(c){this.wrap_h_count=c},apply:function(c,a,b,f,e){var q=m.mat4,n,s,F,x,u,H=new m.Transform,z=!1,E=null;if(this.center[0]||this.center[1]||this.center[2])H.translate(-this.center[0],-this.center[1],-this.center[2]),z=!0;if(this.rotation[0]||this.rotation[1]||this.rotation[2])this.rotation[0]&& H.rotate(this.rotation[2],0,0,1),this.rotation[1]&&H.rotate(this.rotation[1],0,1,0),this.rotation[2]&&H.rotate(this.rotation[0],1,0,0),z=!0;z&&(E=H.getResult());"object"===typeof a&&(a=c.materials.indexOf(a));var H=0,D=c.faces.length;f&&(H=f);for(e&&(D=e+1);H=y&&v>=A&&(F=n[2]/this.scale[2]+this.scale[2]/2,x=-n[1]/this.scale[1]+this.scale[1]/2,0>c.faces[H].normal[0]?(F=(s[2][2]-s[2][0])*(1-F),x=1-(s[2][3]-s[2][1])*x,F+=s[2][0],x+=s[2][1]):(F*=s[3][2]-s[3][0],x=1-(s[3][3]-s[3][1])* x,F+=s[3][0],x+=s[3][1])),y>=v&&y>=A&&(F=n[0]/this.scale[0]+this.scale[0]/2,x=-n[2]/this.scale[2]+this.scale[2]/2,0>c.faces[H].normal[1]?(F*=s[1][2]-s[1][0],x=1-(s[1][3]-s[1][1])*x,F+=s[1][0],x-=s[1][1]):(F*=s[0][2]-s[0][0],x=1-(s[0][3]-s[0][1])*x,F+=s[0][0],x-=s[0][1])),A>=v&&A>=y&&(F=n[0]/this.scale[0]+this.scale[0]/2,x=n[1]/this.scale[1]+this.scale[1]/2,0>c.faces[H].normal[2]?(F*=s[4][2]-s[4][0],x=1-(s[4][3]-s[4][1])*(1-x),F+=s[4][0],x-=s[4][1]):(F=(s[5][2]-s[5][0])*(1-F),x=1-(s[5][3]-s[5][1])* (1-x),F+=s[5][0],x+=s[5][1])),c.faces[H].setUV([F,x],e);else if(K===h.uv.projection.CUBIC)v>=y&&v>=A&&(F=n[2]/this.scale[2]+0.5,x=n[1]/this.scale[1]+0.5),y>=v&&y>=A&&(F=-n[0]/this.scale[0]+0.5,x=n[2]/this.scale[2]+0.5),A>=v&&A>=y&&(F=-n[0]/this.scale[0]+0.5,x=n[1]/this.scale[1]+0.5),0c.faces[H].normal[1]&&(F=-F),0r&&Math.abs(M[0]- N[0])>r&&(M[0]=M[0]>L[0]&&M[0]>N[0]?M[0]-o:M[0]+o);Math.abs(M[1]-L[1])>r&&Math.abs(M[1]-N[1])>r&&(M[1]=M[1]>L[1]&&M[1]>N[1]?M[1]-o:M[1]+o);u=1-M[0]/o;s=0.5-M[1]/Math.PI;1!==this.wrap_w_count&&(u*=this.wrap_w_count);1!==this.wrap_h_count&&(s*=this.wrap_h_count);n=u}else s=n=0;c.faces[H].setUV([n,s],e)}}}return this}};return{UVMapper:w}}); CubicVR.RegisterModule("Renderer",function(m){var w=m.undef;return{renderObject:function(t,h,o,r,d,g,c,a){var b=!1,d=d||!1,g=g||!1;if(null!==t.compiled){var f=0,e=m.GLCore.gl,q,n=r===w?0:r.length,s,F=0,x,u=null,H=t.instanceMaterials||t.materials,c=(t.wireframe||c)&&t.compiled.line_elements_ref,a=(t.pointMode||a)&&t.compiled.line_elements_ref,z=e.TRIANGLES;c?z=e.LINES:a&&(z=e.POINTS);var E=c||a?t.compiled.line_elements_ref:t.compiled.elements_ref,D=!1,v,y,A;e.depthFunc(e.LEQUAL);o===w&&(o=cubicvr_identity); for(var C=0,G=E.length;Cu.opacity&&d)b=!0;else if(!(g&&1<=u.opacity)){1!==u.opacity?(e.enable(e.BLEND),e.depthMask(0),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA)):(e.depthMask(1),e.disable(e.BLEND),e.blendFunc(e.ONE,e.ONE));for(var I=0,J=E[C].length;Iq){f+=2*q;B-=q;if(n){y=!1;for(v=0;vm.MAX_LIGHTS&&(q=m.MAX_LIGHTS);0m.MAX_LIGHTS&&(q=m.MAX_LIGHTS);0this.areaFloor&&(g=g[1][1]-this.areaFloor,d+=g/Math.abs(this.direction[1]));this.dummyCam.nearclip=0.01;this.dummyCam.farclip=d;this.dummyCam.setOrtho(-this.distance/2,this.distance/2,-this.distance/2,this.distance/2)},orthoBounds:function(d,g,c,a,b,f){var a=m.vec3,e=a.normalize([b[0],b[4],b[8]]),q=a.normalize([b[1],b[5],b[9]]),b=a.normalize(a.cross(q,e)),n;n=c/2;c=[];g=a.multiply(e,g/2);e=a.multiply(q,n);f=a.multiply(b,f);c[0]=a.add(a.subtract(d, g),a.add(e,f));c[1]=a.add(a.add(d,g),a.add(e,f));c[2]=a.subtract(a.subtract(d,g),a.add(e,f));c[3]=a.subtract(a.add(d,g),a.add(e,f));aabb1=c[0];aabb2=c[0];for(d=1;4>d;d++)aabb1[0]>c[d][0]&&(aabb1[0]=c[d][0]),aabb1[1]>c[d][1]&&(aabb1[1]=c[d][1]),aabb1[2]>c[d][2]&&(aabb1[2]=c[d][2]),aabb2[0]this.bounds[0][0]&&c[1]>this.bounds[0][1]&&c[2]>this.bounds[0][2]&&c[0]1.0) {\nuv.x -= 1.0;\n}\nvec2 cen = vec2(0.5,0.5) - uv.xy;\nif (length(cen)>0.5) discard;\nvec2 mcen = -0.02*tan(length(cen)*3.14)*(cen);\nuv += mcen;\nif (uv.x>1.0||uv.x<0.0||uv.y>1.0||uv.y<0.0) discard;\nuv.x /= 2.0;\nif (vTex.x > 0.5) {\nuv.x+=0.5;\n}\ngl_FragColor = texture2D(srcTex, uv);\n}",outputMode:"replace",enabled:!1});this.shaderTwoColor= new m.PostProcessShader({shader_vertex:"attribute vec3 aVertex;\nattribute vec2 aTex;\nvarying vec2 vTex;\nvoid main(void)\n{\nvTex = aTex;\nvec4 vPos = vec4(aVertex.xyz,1.0);\ngl_Position = vPos;\n}",shader_fragment:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform sampler2D srcTex;\nuniform sampler2D rightTex;\nvarying vec2 vTex;\nuniform vec3 leftColor;\nuniform vec3 rightColor;\nvoid main()\n{\nvec3 leftSample = texture2D(srcTex, vTex).rgb;\nvec3 rightSample = texture2D(rightTex, vTex).rgb;\nleftSample.rgb = vec3((leftSample.r+leftSample.g+leftSample.b)/3.0);\nrightSample.rgb = vec3((rightSample.r+rightSample.g+rightSample.b)/3.0);\ngl_FragColor = vec4(leftSample.rgb*leftColor+rightSample.rgb*rightColor,1.0);\n}", outputMode:"replace",enabled:!1,init:function(h){h.addInt("rightTex",2);h.addVector("leftColor",this.leftColor);h.addVector("rightColor",this.rightColor)}});this.shaderInterlace=new m.PostProcessShader({shader_vertex:"attribute vec3 aVertex;\nattribute vec2 aTex;\nvarying vec2 vTex;\nvoid main(void)\n{\nvTex = aTex;\nvec4 vPos = vec4(aVertex.xyz,1.0);\ngl_Position = vPos;\n}",shader_fragment:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform sampler2D srcTex;\nvarying vec2 vTex;\nuniform vec3 texel;\nvoid main()\n{\nvec2 uv = vTex;\nuv.y *= 0.5;\nif (mod(floor(vTex.y/texel.y),2.0)==0.0) {\nuv.y+=0.5;\n}\ngl_FragColor = texture2D(srcTex, uv);\n}", outputMode:"replace",enabled:!1});this.fxChain.addShader(this.shaderEyeWarp);this.fxChain.addShader(this.shaderTwoColor);this.fxChain.addShader(this.shaderInterlace);this.aspect=h.aspect;this.aspect||(this.aspect=this.mode==w.stereo.mode.STEREO?o.width/2/o.height:o.width/o.height);this.setMode({mode:this.mode})};t.prototype={setMode:function(h){h=h||{mode:1};this.mode=m.parseEnum(w.stereo.mode,h.mode);fov=h.fov||this.fov;aspect=h.aspect||this.aspect;this.leftColor=h.leftColor||this.leftColor;this.rightColor= h.rightColor||this.rightColor;switch(this.mode){case w.stereo.mode.STEREO:this.setDoubleBuffer(!1);this.setEyeWarp(!1);this.setInterlace(!1);this.setTwoColor(!1);break;case w.stereo.mode.RIFT:aspect=110/90;fov=110;this.setDoubleBuffer(!1);this.setEyeWarp(!0);this.setInterlace(!1);this.setTwoColor(!1);break;case w.stereo.mode.TWOCOLOR:this.setDoubleBuffer(!0);this.setEyeWarp(!1);this.setInterlace(!1);this.setTwoColor(!0);this.shaderTwoColor.shader.use();this.shaderTwoColor.shader.setVector("leftColor", this.leftColor);this.shaderTwoColor.shader.setVector("rightColor",this.rightColor);break;case w.stereo.mode.INTERLACE:this.setDoubleBuffer(!1),this.setEyeWarp(!1),this.setInterlace(!0),this.setTwoColor(!1)}this.camLeft.setAspect(aspect);this.camLeft.setFOV(fov);this.camLeft.setTargeted(this.camera.targeted);this.camRight.setAspect(aspect);this.camRight.setFOV(fov);this.camRight.setTargeted(this.camera.targeted)},getMode:function(){return this.mode},setupCameras:function(){var h=this.camera;this.camLeft.rot= h.rot;this.camRight.rot=h.rot;h.unProject(h.farclip);this.camLeft.pos=h.pos;this.camRight.pos=h.pos;this.camera.targeted?(this.camLeft.position=m.vec3.moveViewRelative(this.camera.position,this.camera.target,-this.eyeSpacing/2,0),this.camRight.position=m.vec3.moveViewRelative(this.camera.position,this.camera.target,this.eyeSpacing/2,0),this.camLeft.target=m.vec3.moveViewRelative(this.camera.position,this.camera.target,-this.eyeSpacing/2,0,this.camera.target),this.camRight.target=m.vec3.moveViewRelative(this.camera.position, this.camera.target,this.eyeSpacing/2,0,this.camera.target)):(this.camLeft.position[0]-=this.eyeSpacing/2,this.camRight.position[0]+=this.eyeSpacing/2);!this.camera.parent&&!this.camera.targeted&&(h=m.mat4.transform(m.vec3.subtract([0,0,0],this.camera.position),this.camera.rotation),this.camLeft.parent={tMatrix:h},this.camRight.parent={tMatrix:h})},renderScene:function(h){this.setupCameras();var o=m.getCanvas(),r=this.fxChain,d=this.fxChainB,g=m.GLCore.gl,c=o.width/2,a=o.height/2,b=o.height,o=o.width; this.shaderEyeWarp.enabled=this.eyeWarpEnabled;this.shaderTwoColor.enabled=this.twoColorEnabled;this.shaderInterlace.enabled=this.interlaceEnabled;this.twoColorEnabled&&d?(r.begin(),g.viewport(0,0,o,b),g.clear(g.DEPTH_BUFFER_BIT|g.COLOR_BUFFER_BIT),h.render({camera:this.swapEyes?this.camRight:this.camLeft}),r.end(),d.begin(),g.viewport(0,0,o,b),g.clear(g.DEPTH_BUFFER_BIT|g.COLOR_BUFFER_BIT),h.render({camera:this.swapEyes?this.camLeft:this.camRight}),d.end(),g.viewport(0,0,o,b),d.captureBuffer.texture.use(g.TEXTURE2)): (r.begin(),g.viewport(0,0,o,b),g.clear(g.DEPTH_BUFFER_BIT|g.COLOR_BUFFER_BIT),this.interlaceEnabled?g.viewport(0,0,o,a):g.viewport(0,0,c,b),h.render({camera:this.swapEyes?this.camRight:this.camLeft}),this.interlaceEnabled?g.viewport(0,a,o,a):g.viewport(c,0,c,b),h.render({camera:this.swapEyes?this.camLeft:this.camRight}),r.end(),g.viewport(0,0,o,b));r.render()},setEyeWarp:function(h){this.eyeWarpEnabled=h},getEyeWarp:function(){return this.eyeWarpEnabled},setSwapEyes:function(h){this.swapEyes=h},getSwapEyes:function(){return this.swapEyes}, setDoubleBuffer:function(h){if(!this.fxChainB){var o=m.getCanvas();this.fxChainB=new m.PostProcessChain(o.width,o.height,!1);m.addResizeable(this.fxChainB)}this.doubleBuffer=h},getDoubleBuffer:function(){return this.doubleBuffer},setTwoColor:function(h){this.twoColorEnabled=h},getTwoColor:function(){return this.twoColorEnabled},setInterlace:function(h){this.interlaceEnabled=h},getInterlace:function(){return this.interlaceEnabled},addUI:function(){var h=document.createElement("div");h.style.position= "absolute";h.style.top="10px";h.style.left="10px";h.style.color="white";h.style.zIndex=1E3;h.appendChild(document.createTextNode("Mode:"));var o=document.createElement("select");o.options[0]=new Option("Oculus Rift Untested","rift");o.options[1]=new Option("Split Stereo","stereo");o.options[2]=new Option("Red/Blue Stereo","redblue");o.options[3]=new Option("Red/Green Stereo","redgreen");o.options[4]=new Option("Interlaced","interlace");o.selectedIndex=0;h.appendChild(o);h.appendChild(document.createTextNode(" Swap Eyes:")); var r=document.createElement("input");r.type="checkbox";r.value="1";h.appendChild(r);document.body.appendChild(h);o.selectedIndex=0;var d=this;r.addEventListener("change",function(){d.setSwapEyes(this.checked)},!0);o.addEventListener("change",function(){var g=this.options[this.selectedIndex].value,c=m.getCanvas();switch(g){case "rift":d.setMode({mode:"rift"});break;case "stereo":d.setMode({mode:"stereo",fov:60,aspect:c.width/2/c.height});break;case "redblue":d.setMode({mode:"twocolor",leftColor:[0, 0,1],rightColor:[1,0,0],fov:60,aspect:c.width/c.height});break;case "redgreen":d.setMode({mode:"twocolor",leftColor:[0,1,0],rightColor:[1,0,0],fov:60,aspect:c.width/c.height});break;case "interlace":d.setMode({mode:"interlace",leftColor:[0,1,0],rightColor:[1,0,0],fov:60,aspect:c.width/c.height})}},!0)}};return{StereoCameraRig:t}}); CubicVR.RegisterModule("Motion",function(m){function w(){this.time=this.value=0;this.shape=r.envelope.shape.TCB;this.bias=this.continuity=this.tension=0;this.next=this.prev=null;this.param=[0,0,0,0]}function t(a){this.nKeys=0;this.lastKey=this.firstKey=this.keys=null;a?(this.in_behavior=CubicVR.parseEnum(r.envelope.behavior,a.in_behavior||a.inBehavior||a.behavior)||r.envelope.behavior.CONSTANT,this.out_behavior=CubicVR.parseEnum(r.envelope.behavior,a.out_behavior||a.outBehavior||a.behavior)||r.envelope.behavior.CONSTANT): this.out_behavior=this.in_behavior=r.envelope.behavior.CONSTANT}function h(a,e){this.controllers=[];this.yzflip=!1;if("object"===typeof a){var b=CubicVR.get(a);this.env_init=CubicVR.get(b.envelope);this.key_init=CubicVR.get(b.key);for(var c in b)if(b.hasOwnProperty(c)&&!("envelope"===c||"key"===c)){var g=b[c],d=CubicVR.get(g.envelope),h;for(h in g)if(g.hasOwnProperty(h)&&!("envelope"===h||"key"===h)){var u=g[h];if("object"===typeof u)for(var o in u)this.setKey(c,o,h,u[o]),d&&this.setBehavior(c,o, d)}}}else this.env_init=a,this.key_init=e}var o=m.undef,r=CubicVR.enums;r.motion={POS:0,ROT:1,SCL:2,POSITION:0,ROTATION:1,SCALE:2,FOV:3,LENS:4,NEARCLIP:5,FARCLIP:6,INTENSITY:7,X:0,Y:1,Z:2,V:3};r.envelope={shape:{TCB:0,HERM:1,BEZI:2,LINE:3,STEP:4,BEZ2:5},behavior:{RESET:0,CONSTANT:1,REPEAT:2,OSCILLATE:3,OFFSET:4,LINEAR:5}};var d=function(a,e,b){var c=0,c=b-e;if(0===c)return[e,0];e=a-c*Math.floor((a-e)/c);c=-parseInt((e-a)/c+(e>a?0.5:-0.5),10);return[e,c]},g=function(a,e,b,c,g){var d,h;h=g*g;d=3*(e- a);e=3*(b-e)-d;return(c-a-d-e)*h*g+e*h+d*g+a},c=function(a,e,b,n,d,h,o){var u,m;m=h+0.5*(o-h);u=g(a,e,b,n,m);return 1.0E-4d?o=m:h=m,c(a,e,b,n,d,h,o)):m},a=function(a,e){var b,c,g,d;a.shape===r.envelope.shape.TCB?(b=(1-a.tension)*(1+a.continuity)*(1+a.bias),c=(1-a.tension)*(1-a.continuity)*(1-a.bias),g=e.value-a.value,a.prev?(d=(e.time-a.time)/(e.time-a.prev.time),b=d*(b*(a.value-a.prev.value)+c*g)):b=c*g):a.shape===r.envelope.shape.LINE?(g=e.value-a.value,a.prev?(d=(e.time-a.time)/ (e.time-a.prev.time),b=d*(a.value-a.prev.value+g)):b=g):a.shape===r.envelope.shape.BEZI||a.shape===r.envelope.shape.HERM?(b=a.param[1],a.prev&&(b*=(e.time-a.time)/(e.time-a.prev.time))):a.shape===r.envelope.shape.BEZ2?(b=a.param[3]*(e.time-a.time),b=1.0E-5a?this.firstKey=e:this.lastKey.timee.time)return e.prev=b.prev,e.prev&&(e.prev.next=e),e.next=b,e.next.prev=e,this.nKeys++,e;if(!b.next)return e.prev=b,b.next=e,this.nKeys++,e;b=b.next}return null},evaluate:function(f){var e,q,n,s,h,o=0;if(0===this.nKeys)return 0;if(1=== this.nKeys)return this.keys.value;q=this.firstKey;e=this.lastKey;if(fe.time){s=this.out_behavior;if(s===r.envelope.behavior.RESET)return 0;if(s===r.envelope.behavior.CONSTANT)return e.value;if(s===r.envelope.behavior.REPEAT)s=d(f,q.time,e.time),f=s[0];else if(s===r.envelope.behavior.OCILLATE)s=d(f,q.time,e.time),f=s[0],s=s[1],s%2&&(f=e.time-q.time-f);else if(s===r.envelope.behavior.OFFSET)s=d(f,q.time,e.time),f=s[0],s=s[1],o=s*(e.value-q.value);else if(s===r.envelope.behavior.LINEAR)return s=b(e.prev,e)/(e.time- e.prev.time),s*(f-e.time)+e.value}if(this.lastKey0)if(f>this.lastKey0.time)e=this.lastKey0;else if(fe.next.time;)e=e.next;q=e.next;this.lastKey0=e;if(f===e.time)return e.value+o;if(f===q.time)return q.value+o;n=(f-e.time)/(q.time-e.time);s=q.shape;if(s===r.envelope.shape.TCB||s===r.envelope.shape.BEZI||s===r.envelope.shape.HERM){h=a(e,q);s=b(e,q);var u,m;m=n*n;u=n*m;f=3*m-u-u;u-=m;f=[1-f,f,u- m+n,u];return f[0]*e.value+f[1]*q.value+f[2]*h+f[3]*s+o}return s===r.envelope.shape.BEZ2?(f=c(e.time,e.shape===r.envelope.shape.BEZ2?e.time+e.param[2]:e.time+(q.time-e.time)/3,q.time+q.param[0],q.time,f,0,1),g(e.value,e.shape===r.envelope.shape.BEZ2?e.value+e.param[3]:e.value+e.param[1]/3,q.param[1]+q.value,q.value,f)+o):s===r.envelope.shape.LINE?e.value+n*(q.value-e.value)+o:s===r.envelope.shape.STEP?e.value+o:o}};h.prototype={clone:function(){var a=new m.Motion(this.env_init,this.key_init),e;for(e in this.controllers)if(this.controllers.hasOwnProperty(e)){a.controllers[e]=== o&&(a.controllers[e]=[]);for(var b in this.controllers[e])if(this.controllers[e].hasOwnProperty(b)){var c=this.controllers[e][b],g=a.controllers[e][b]=new t({in_behavior:c.in_behavior,out_behavior:c.out_behavior});g.nKeys=c.nKeys;g.keys=c.keys;g.firstKey=c.firstKey;g.lastKey=c.lastKey}}return a},envelope:function(a,e){e=CubicVR.parseEnum(r.motion,e)||0;a=CubicVR.parseEnum(r.motion,a)||0;this.controllers[a]===o&&(this.controllers[a]=[]);this.controllers[a][e]===o&&(this.controllers[a][e]=new t(this.env_init)); return this.controllers[a][e]},evaluate:function(a){var e=[],b;for(b in this.controllers)if(this.controllers.hasOwnProperty(b)){e[b]=[];for(var c in this.controllers[b])this.controllers[b].hasOwnProperty(c)&&(e[b][c]=this.controllers[b][c].evaluate(a))}return e},apply:function(a,e){for(var b in this.controllers)if(this.controllers.hasOwnProperty(b)){var c=parseInt(b,10);if(this.yzflip&&c===r.motion.ROT){this.q||(this.q=new CubicVR.Quaternion);var g=this.q,d=this.controllers[b][0].evaluate(a),h=this.controllers[b][1].evaluate(a), u=this.controllers[b][2].evaluate(a);g.fromEuler(d,u,-h);g=g.toEuler();e.control(c,0,g[0]);e.control(c,1,g[1]);e.control(c,2,g[2])}else for(var o in this.controllers[b])this.controllers[b].hasOwnProperty(o)&&e.control(c,parseInt(o,10),this.controllers[b][o].evaluate(a))}},setKey:function(a,e,b,c,g){e=CubicVR.parseEnum(r.motion,e)||0;a=CubicVR.parseEnum(r.motion,a)||0;return this.envelope(a,e).addKey(b,c,g?g:this.key_init)},setArray:function(a,e,b,c){var g=[],a=CubicVR.parseEnum(r.motion,a)||0,d;for(d in b)if(b.hasOwnProperty(d)){var h= this.envelope(a,CubicVR.parseEnum(r.motion,d));g[d]=h.addKey(e,b[d],c?c:this.key_init)}return g},setBehavior:function(a,e,b,c){var g=this.envelope(a,e);"object"===typeof b&&(c=b,b=c.in_behavior||c.inBehavior||c.behavior,c=c.out_behavior||c.outBehavior||c.behavior);CubicVR.parseEnum(r.motion,e);CubicVR.parseEnum(r.motion,a);g.setBehavior(b,c)},setBehaviorArray:function(a,e,b){var a=CubicVR.parseEnum(r.motion,a)||0,c=this.controllers[a],g;for(g in c)c.hasOwnProperty(g)&&this.envelope(a,CubicVR.parseEnum(r.motion, g)||0).setBehavior(e,b)}};return{Motion:h,Envelope:t,EnvelopeKey:w}}); CubicVR.RegisterModule("EventHandler",function(m){function w(g){g=CubicVR.parseEnum(r.event,g);return g===o?(d("For custom events use CubicVR.registerEvent('event_name'); and use the resulting CubicVR.enums.event.EVENT_NAME for type checks and 'event_name' for construction."),!1):!isNaN(parseInt(g,10))&&(g>=r.event.EVENT_MAX||0>g)?(d("Unknown event ID passed: "+g),!1):g}function t(g){g=g||{};this.name=g.name;g.id=w(g.id)||r.event.TICK;this.id=g.id;this.interval=g.interval||0;this.enabled=g.enabled|| !0;this.action=g.action||null;this.properties=g.properties||{};this.event_properties=g.event_properties||{};this.buffered=g.buffered||!1;this.weight=g.weight===o?-1:g.weight;this.subject=null;this.n_updates=this.t_resting=this.t_rest=this.t_last=this.t_update=this.t_updatecall=this.t_active=this.t_sleep=0;this.break_chain=!1}function h(){this.events=[];this.eventProperties=[];this.eventPropertyCount=[];this.eventHandled=[];this.listeners=[];this.listenerNames=[];this.eventParameters=[]}var o=m.undef, r=CubicVR.enums,d=m.log;r.event={TICK:0,MOVE:1,MATRIX_UPDATE:2,OCTREE_ADJUST:3,COLLIDE:4,CONTACT:5,CONTACT_ADD:6,CONTACT_REMOVE:7,CONTACT_GHOST:8,RIGID_REST:9,RIGID_AWAKE:10,ENUM_MAX:11};t.prototype={getName:function(){return this.name},setName:function(g){this.name=g},getSubject:function(){return this.subject},setSubject:function(g){this.subject=g},getId:function(){return this.id},setId:function(g){this.id=g},isEnabled:function(){return this.enabled},disable:function(){this.setEnabled(!1)},enable:function(){this.setEnabled(!0)}, setEnabled:function(g){g&&!this.enabled&&(this.n_updates=this.t_resting=this.t_rest=this.t_last=this.t_update=this.t_updatecall=this.t_active=this.t_sleep=0,this.break_chain=!1);this.enabled=g},isBuffered:function(){return this.buffered},setBuffered:function(g){this.buffered=g},setInterval:function(g){this.interval=g},getInterval:function(){return this.interval},setAction:function(g){this.action=g},getAction:function(){return this.action},getProperties:function(){return this.properties},setProperties:function(g){this.properties= g},getProperty:function(g){return this.properties[g]},setProperty:function(g,c){this.properties[g]=c},setEventProperties:function(g){this.event_properties=g},getEventProperties:function(){return this.event_properties},getEventProperty:function(g){return this.event_properties[g]},setEventProperty:function(g,c){this.properties[g]=c},getTimeSleeping:function(){return this.t_sleep},getTimeActive:function(){return this.t_active},getTimeUpdated:function(){return this.t_update},getSeconds:function(){return this.getTimeUpdated()}, getRestInterval:function(){return this.t_rest},getLastUpdateSeconds:function(){return this.t_last},setRestInterval:function(g){this.t_rest=g},getUpdateCount:function(){return this.n_updates},breakChain:function(){this.break_chain=!0},isChainBroken:function(){return this.break_chain},rest:function(g){this.setRestInterval(g||0)},awake:function(){this.t_rest=0},update:function(g,c){if(!this.enabled)return!1;var a=0,b=!0;0===this.n_updates?(this.t_updatecall=this.t_update=g,a=1/60):g!==this.t_update? (this.t_rest||(this.t_last=g-this.t_update,this.t_update=g),a=g-this.t_updatecall,this.t_updatecall=g):b=!1;if(0this.t_rest&&(this.t_rest=0));else return b&&(this.t_active+=this.t_last,!this.t_rest&&this.interval&&(this.t_rest=this.interval),this.n_updates++),this.callEvent(c),!0;b&&this.n_updates++;return!1},callEvent:function(g){return!this.action?!1:this.action(this,g)}};h.prototype={addEvent:function(g){g.callEvent||(g=new t(g));var c=g.getId(); this.eventProperties[c]||(this.eventProperties[c]={});this.listeners[c]=this.listeners[c]||0;this.listeners[c]++;this.events.push(g);-1===this.listenerNames.indexOf(c)&&this.listenerNames.push(c);return g},removeEvent:function(g){if(this.lockState)this.lockRemovals||(this.lockRemovals=[]),-1==this.lockRemovals.indexOf(g)&&this.lockRemovals.push(g);else{var c=this.events.indexOf(g);-1!==c&&(g=g.getId(),this.events.splice(c,1),this.listeners[g]--,this.listeners[g]||(this.eventHandled[g]=!0,this.eventParameters[g]= {},this.eventProperties[g]=[],this.eventPropertyCount[g]=0,c=this.listenerNames.indexOf(g),0<=c&&this.listenerNames.splice(c,1)))}},getProperties:function(g){this.eventParameters[g]=this.eventParameters[g]||{};return this.eventParameters[g]},setProperties:function(g,c){this.eventParameters[g]=c},getProperty:function(g,c){return this.getProperties(g)[c]},setProperty:function(g,c,a){this.getProperties(g)[c]=a},hasEvent:function(g){return!!this.listeners[g]},triggerEvent:function(g,c){if(!this.listeners[g])return null; this.eventProperties[g]==o&&(this.eventProperties[g]=[]);var a=this.eventProperties[g];this.eventPropertyCount[g]===o&&(this.eventPropertyCount[g]=0);var b=this.eventPropertyCount[g];20 20: "+b);a[b]=c&&a?c:a[b]||{};this.eventPropertyCount[g]++;this.eventHandled[g]=!1;return a[b]},update:function(g){var c,a,b,f,e,d;if(this.hasEvent(r.event.TICK)&&0===this.eventPropertyCount[r.event.TICK]&&(c=this.triggerEvent(r.event.TICK)))c.time=g,c.handler=this;this.lockState= !0;c=0;for(a=this.events.length;cv||u>y||o>b)){for(f=0;fb;++b)d=a.vec3_multiply(c[b],this.tMatrix),f[0]>d[0]&&(f[0]=d[0]),f[1]>d[1]&&(f[1]=d[1]),f[2]>d[2]&&(f[2]=d[2]),g[0]d.id&&(d.id=b,++b), this.sceneObjectsById[d.id]=d,c.reset(d.octree_aabb,d.position),this.octree.insert(d),(void 0===d.octree_common_root||null===d.octree_common_root)&&log("!!",d.name,"octree_common_root is null"))}}},setSkyBox:function(a){this.skybox=a},getSceneObject:function(a){return this.sceneObjectsByName[a]},bindSceneObject:function(a,f,g){if(-1==this.sceneObjects.indexOf(a)){this.sceneObjects.push(a);f!==r&&f&&this.pickables.push(a);null!==a.name&&(this.sceneObjectsByName[a.name]=a);if(this.octree!==r&&(g=== r||"true"===g))0>a.id&&(a.id=b,++b),this.sceneObjectsById[a.id]=a,c.reset(a.octree_aabb,a.position),this.octree.insert(a);if(a.children)for(var d=0,h=a.children.length;da.scale[0]&&(o=!o);0>a.scale[1]&&(o=!o);0>a.scale[2]&&(o=!o);o&&z.cullFace(z.FRONT);var t=a.obj;null!==t.morphTargets&&(-1!==a.morphSource&&t.setMorphSource(a.morphSource),-1!==a.morphTarget&&t.setMorphTarget(a.morphTarget),null!==a.morphWeight&&(t.morphWeight=a.morphWeight));a.instanceMaterials&&t.bindInstanceMaterials(a.instanceMaterials);m.renderObject(t,b,a.tMatrix,c,d,h,this.isWireframe()|| a.isWireframe(),this.isPointMode()||a.isPointMode())&&u&&u.push(a);a.instanceMaterials&&t.bindInstanceMaterials(null);o&&z.cullFace(z.BACK)}a=a.children;if(f&&a){f=0;for(o=a.length;fr[0]-o[0]&&(o[0]-=0.1,r[0]+=0.1);0.2>r[1]-o[1]&&(o[1]-=0.1,r[1]+=0.1);0.2>r[2]-o[2]&&(o[2]-=0.1,r[2]+=0.1);var t=g.multiply(g.add(o,r),0.5),D=g.getClosestTo(a,b,t),t=g.length(g.subtract(D,t));(D[0]>=o[0]&&D[0]<= r[0]?1:0)+(D[1]>=o[1]&&D[1]<=r[1]?1:0)+(D[2]>=o[2]&&D[2]<=r[2]?1:0)>=c&&d.push({dist:t,obj:f})}d.length&&d.sort(function(a,b){return a.dist==b.dist?0:a.distC&&(I.method=h.light.method.DYNAMIC);mCount=0;for(n=r.data.length;mCountf){n=0;for(z=F.length;nthis.strokes[c][d][0]&&(o[0]=this.strokes[c][d][0]),o[1]>this.strokes[c][d][1]&& (o[1]=this.strokes[c][d][1]),o[2]>this.strokes[c][d][2]&&(o[2]=this.strokes[c][d][2]),m[0]d?1:d;return r[(d>c?c:d)-1]};this.getPageTexture= function(d,c,a){var d=this.getPage(d),b=d.getViewport(1),c=c||b.width,a=a||b.height;return new CubicVR.PdfTexture(d,{width:c,height:a,viewport:b})};m({url:t,progress:function(){},error:function(){console.log("PDF Error: error loading pdf `"+t+"`")}},function(g){PDFJS.getDocument({data:g}).then(function(c){function a(){b++>=c.numPages?h():c.getPage(b).then(function(b){r.push(b);d.push(b);a()})}o=c;var b=0;a()},function(c,a){console.warn(c,a);h()})})}}}); CubicVR.RegisterModule("Particles",function(m){function w(h,m,d,g,c,a,b){h&&(this.last_particle=this.particles=null,this.pTex=d!==t?d:null,this.vWidth=g,this.vHeight=c,this.alpha=a!==t?a:!1,this.alphaCut=b!==t?b:0,this.pfunc=function(a,b){var c=b-a.start_time;if(0>c)return 0;if(c>a.life_time&&a.life_time)return-1;a.pos[0]=a.startpos[0]+c*a.velocity[0]+c*c*a.accel[0];a.pos[1]=a.startpos[1]+c*a.velocity[1]+c*c*a.accel[1];a.pos[2]=a.startpos[2]+c*a.velocity[2]+c*c*a.accel[2];null!==this.pgov&&this.pgov(a, b);return 1},this.pgov=null,this.hasColor=m===t?!1:m,d=null!==this.pTex,this.vs=["#ifdef GL_ES\nprecision highp float;\n#endif\nattribute vec3 aVertexPosition;",this.hasColor?"attribute vec3 aColor;":"","uniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\nvarying vec4 color;\nvarying vec2 screenPos;",d?"varying float pSize;":"","void main(void) {\nvec4 position = uPMatrix * uMVMatrix * vec4(aVertexPosition,1.0);",d?"screenPos=vec2(position.x/position.w,position.y/position.w);":"","gl_Position = position;", this.hasColor?"color = vec4(aColor.r,aColor.g,aColor.b,1.0);":"color = vec4(1.0,1.0,1.0,1.0);",d?"pSize=200.0/position.z;":"float pSize=200.0/position.z;","gl_PointSize = pSize;\n}"].join("\n"),this.fs=["#ifdef GL_ES\nprecision highp float;\n#endif",d?"uniform sampler2D pMap;":"","varying vec4 color;",d?"varying vec2 screenPos;":"",d?"uniform vec3 screenDim;":"",d?"varying float pSize;":"","void main(void) {\nvec4 c = color;",d?"vec2 screen=vec2((gl_FragCoord.x/screenDim.x-0.5)*2.0,(gl_FragCoord.y/screenDim.y-0.5)*2.0);": "",d?"vec2 pointCoord=vec2( ((screen.x-screenPos.x)/(pSize/screenDim.x))/2.0+0.5,((screen.y-screenPos.y)/(pSize/screenDim.y))/2.0+0.5);":"",d?"vec4 tc = texture2D(pMap,pointCoord); gl_FragColor = vec4(c.rgb*tc.rgb,1.0);":"gl_FragColor = c;","}"].join("\n"),this.maxPoints=h,this.numParticles=0,this.arPoints=new Float32Array(3*h),this.glPoints=null,m&&(this.arColor=new Float32Array(3*h),this.glColor=null),this.shader_particle=new CubicVR.Shader(this.vs,this.fs),this.shader_particle.use(),this.shader_particle.addVertexArray("aVertexPosition", 0),this.hasColor&&this.shader_particle.addVertexArray("aColor"),this.shader_particle.addMatrix("uMVMatrix"),this.shader_particle.addMatrix("uPMatrix"),null!==this.pTex&&(this.shader_particle.addInt("pMap",0),this.shader_particle.addVector("screenDim"),this.shader_particle.setVector("screenDim",[g,c,0])),this.genBuffer())}var t=m.undef,h=m.GLCore;w.prototype={resizeView:function(h,m){this.vWidth=h;this.vHeight=m;null!==this.pTex&&(this.shader_particle.addVector("screenDim"),this.shader_particle.setVector("screenDim", [h,m,0]))},addParticle:function(h){null===this.last_particle?this.particles=h:this.last_particle.nextParticle=h;this.last_particle=h},genBuffer:function(){var o=h.gl;this.glPoints=o.createBuffer();o.bindBuffer(o.ARRAY_BUFFER,this.glPoints);o.bufferData(o.ARRAY_BUFFER,this.arPoints,o.DYNAMIC_DRAW);this.hasColor&&(this.glColor=o.createBuffer(),o.bindBuffer(o.ARRAY_BUFFER,this.glColor),o.bufferData(o.ARRAY_BUFFER,this.arColor,o.DYNAMIC_DRAW))},updatePoints:function(){var o=h.gl;o.bindBuffer(o.ARRAY_BUFFER, this.glPoints);o.bufferData(o.ARRAY_BUFFER,this.arPoints,o.DYNAMIC_DRAW)},updateColors:function(){var o=h.gl;this.hasColor&&(o.bindBuffer(o.ARRAY_BUFFER,this.glColor),o.bufferData(o.ARRAY_BUFFER,this.arColor,o.DYNAMIC_DRAW))},draw:function(o,m,d){var g=h.gl;this.shader_particle.use();null!==this.pTex&&this.pTex.use(g.TEXTURE0);this.shader_particle.setMatrix("uMVMatrix",o);this.shader_particle.setMatrix("uPMatrix",m);g.bindBuffer(g.ELEMENT_ARRAY_BUFFER,null);g.bindBuffer(g.ARRAY_BUFFER,this.glPoints); g.vertexAttribPointer(this.shader_particle.uniforms.aVertexPosition,3,g.FLOAT,!1,0,0);g.enableVertexAttribArray(this.shader_particle.uniforms.aVertexPosition);this.hasColor&&(g.bindBuffer(g.ARRAY_BUFFER,this.glColor),g.vertexAttribPointer(this.shader_particle.uniforms.aColor,3,g.FLOAT,!1,0,0),g.enableVertexAttribArray(this.shader_particle.uniforms.aColor));if(d!==t){this.numParticles=0;if(null===this.particles){g.disable(g.BLEND);return}for(var o=this.particles,m=null,c=0;null!==o;){var a=3*this.numParticles, b=this.pfunc(o,d);if(1===b){if(this.arPoints[a]=o.pos[0],this.arPoints[a+1]=o.pos[1],this.arPoints[a+2]=o.pos[2],null!==o.color&&this.arColor!==t&&(this.arColor[a]=o.color[0],this.arColor[a+1]=o.color[1],this.arColor[a+2]=o.color[2]),this.numParticles++,c++,this.numParticles===this.maxPoints)break}else-1===b?null!==m&&(m.nextParticle=o.nextParticle):0===b&&c++;m=o;o=o.nextParticle}c||(this.last_particle=this.particles=null);this.updatePoints();this.hasColor&&this.updateColors()}this.alpha&&(g.enable(g.BLEND), g.enable(g.DEPTH_TEST),g.depthMask(0),g.blendFunc(g.ONE,g.ONE_MINUS_SRC_COLOR));g.drawArrays(g.POINTS,0,this.numParticles);this.alpha&&(g.disable(g.BLEND),g.depthMask(1),g.blendFunc(g.ONE,g.ONE));this.hasColor&&g.disableVertexAttribArray(this.shader_particle.uniforms.aColor)}};return{ParticleSystem:w,Particle:function(h,m,d,g,c){this.startpos=new Float32Array(h);this.pos=new Float32Array(h);this.velocity=new Float32Array(g!==t?g:[0,0,0]);this.accel=new Float32Array(c!==t?c:[0,0,0]);this.start_time= m!==t?m:0;this.life_time=d!==t?d:0;this.nextParticle=this.color=null}}}); CubicVR.RegisterModule("Lines",function(m){function w(h){h=h||{};this.color=h.color||[1,1,1];this.maxPoints=h.maxPoints||1024;this.vs="#ifdef GL_ES\nprecision highp float;\n#endif\nattribute vec3 aVertexPosition;\nuniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\nvoid main(void) {\nvec4 position = uPMatrix * uMVMatrix * vec4(aVertexPosition,1.0);\ngl_Position = position;\n}";this.fs="#ifdef GL_ES\nprecision highp float;\n#endif\nuniform vec3 color;\nvoid main(void) {\nvec4 c = vec4(color,1.0);\ngl_FragColor = c;\n}";this.arLines= new Float32Array(6*this.maxPoints);this.glLines=null;this.lineLength=0;this.shader_line=new CubicVR.Shader(this.vs,this.fs);this.shader_line.use();this.shader_line.addVertexArray("aVertexPosition",0);this.shader_line.addVector("color",this.color);this.shader_line.addMatrix("uMVMatrix");this.shader_line.addMatrix("uPMatrix");this.genBuffer();this.newSegment=!1}var t=m.GLCore;w.prototype={genBuffer:function(){var h=t.gl;this.glLines=h.createBuffer();h.bindBuffer(h.ARRAY_BUFFER,this.glLines);h.bufferData(h.ARRAY_BUFFER, this.arLines,h.DYNAMIC_DRAW)},update:function(){var h=t.gl;h.bindBuffer(h.ARRAY_BUFFER,this.glLines);h.bufferData(h.ARRAY_BUFFER,this.arLines,h.DYNAMIC_DRAW)},addPoint:function(h){var m=this.lineLength;1this.divZ?(this.sizeX=c,this.sizeZ=c/this.divX*this.divZ):(this.sizeX=this.divZ>this.divX? c/this.divZ*this.divX:c,this.sizeZ=c);this.drawBuffer=[];this.cellSize=this.sizeX/this.divX;this.startX=-(this.sizeX/2)+this.ofsX;this.startZ=-(this.sizeZ/2)+this.ofsZ},setBrush:function(d){this.brush=d},getBrush:function(){return this.brush},draw:function(d,g,c){var a=this.brush||c,c=a.getOperation(),b=a.getSize(),f=a.getBrushType(),a=a.getStrength();if(this.areaBuffered){var e=d-b,q=g-b,n=d+b,h=g+b;ethis.drawArea.endX&&(this.drawArea.endX=n);n>this.drawArea.endX&&(this.drawArea.endZ=h)}else this.drawArea={startX:d-b,startZ:g-b,endX:d+b,endZ:g+b},this.areaBuffered=!0;this.drawBuffer.push([d,g,c,b,f,a])},getDrawArea:function(){return!this.areaBuffered?!1:this.drawArea},clearDrawArea:function(){this.areaBuffered=!1},flush:function(){if(!this.drawBuffer.length)return!1;for(;this.drawBuffer.length;){var d=this.drawBuffer.pop();this.drawFunc(d[0],d[1],d[2],d[3],d[4],d[5])}return!0},needsFlush:function(){return 0!== this.drawBuffer.length},drawFunc:function(d,g,c,a,b,f){for(var c=this.hfFloatBuffer,b=this.divX,e=this.divZ,a=a/this.cellSize,d=(d-this.startX)/this.cellSize,g=(g-this.startZ)/this.cellSize,q=parseInt(Math.floor(d-a),10),n=parseInt(Math.ceil(d+a),10);qq||q>=b||0>m||m>=e)){var u=m-g,u=f*((1-Math.sqrt(h*h+u*u)/a)/2);0>u&&0<=f&&(u=0);0=f&&(u=0);c[m*b+q]+=u}},getUint8Buffer:function(){return this.hfUInt8Buffer}, getFloat32Buffer:function(){return this.hfFloatBuffer},getDivX:function(){return this.divX},getDivZ:function(){return this.divZ},getSizeX:function(){return this.sizeX},getSizeZ:function(){return this.sizeZ},getStartX:function(){return this.startX},getStartZ:function(){return this.startZ},getCellSize:function(){return this.cellSize},getSize:function(){return this.size},setRect:function(d){var d=d||{},g=d.value||0,c=d.src||d.func||null,a=d.startX||0,b=d.startZ||0,f=d.walkX,e=d.walkZ,d=this.hfFloatBuffer, q,n=this.startX,h=this.startZ;if(a!==w&&b!==w&&f!==w&&e!==w){if(!(a>=this.divX)&&!(b>=this.divZ)&&(a+f>=this.divX&&(f=this.divX-1-a),b+e>=this.divZ&&(e=this.divZ-1-b),!(0>=f||0>=e))){q=a;for(a+=f;qb||b>=this.divX-1||0>f||f>=this.divZ-1)return-1;if(1<=Math.abs(g-((f+1)*this.cellSize+a))/Math.abs(d-(b*this.cellSize+c)))return c=[b+(f+1)*this.divX,b+1+f*this.divX,b+f*this.divX],[b,f,c,0];c=[b+(f+1)*this.divX,b+1+(f+1)*this.divX,b+1+f*this.divX];return[b,f,c,1]},getHeightValue:function(d,g){var c=m.triangle;if("object"===typeof d)return this.getHeightValue(d[0], d[2]);var a=this.getIndicesAt(d,g);if(-1===a)return 0;var b=a[2],f=a[0]*this.cellSize+this.startX,e=a[1]*this.cellSize+this.startZ,q;q=0===a[3]?c.normal([f,this.hfFloatBuffer[b[0]],e+this.cellSize],[f+this.cellSize,this.hfFloatBuffer[b[1]],e],[f,this.hfFloatBuffer[b[2]],e]):c.normal([f,this.hfFloatBuffer[b[0]],e+this.cellSize],[f+this.cellSize,this.hfFloatBuffer[b[1]],e+this.cellSize],[f+this.cellSize,this.hfFloatBuffer[b[2]],e]);c=q[0];a=q[1];q=q[2];b=[f,this.hfFloatBuffer[b[0]],e+this.cellSize]; return(c*d+q*g+(-(c*b[0])-a*b[1]-q*b[2]))/-a},rayIntersect:function(d,g){var c=d.slice(0),a=this.startX,b=this.startZ,f=this.startX+this.sizeX,e=this.startZ+this.sizeZ,q=this.cellSize,n=m.vec2,h=m.vec3,o=h.normalize(g),r=[o[0],o[2]],u=[c[0],c[2]];if(c[0]f||c[2]e){var t=[[a,b],[f,b],[a,e],[f,e]],z=[];c[0]>=f&&z.push([t[1],t[3]]);c[0]<=a&&z.push([t[0],t[2]]);c[2]>=e&&z.push([t[2],t[3]]);c[2]<=b&&z.push([t[0],t[1]]);if(0!==z.length){c=[];f=0;for(e=z.length;f=q)for(;e>=q;)e-=q;if(t>=q)for(;t>=q;)t-=q;v=n.length(u,[z,f])/n.length(r);D=n.length(u,[z-D,f-C])/n.length(r);v=c[1]+o[1]*v;D=c[1]+o[1]*D;if(y>this.divX||0>y||A>this.divZ||0>A)return!1;var C=w[A*this.divX+y],G=w[A*this.divX+ y+1],B=w[(A+1)*this.divX+y],I=w[(A+1)*this.divX+y+1];if(0>=v-C||0>=v-G||0>=v-B||0>=v-I||0>=D-C||0>=D-G||0>=D-B||0>=D-I){G=[y+(A+1)*this.divX,y+1+A*this.divX,y+A*this.divX];C=[y+(A+1)*this.divX,y+1+(A+1)*this.divX,y+1+A*this.divX];v=a+q*y;D=b+q*A;tmpNormA=m.triangle.normal([v,w[G[0]],D+q],[v+q,w[G[1]],D],[v,w[G[2]],D]);tmpNormB=m.triangle.normal([v,w[C[0]],D+q],[v+q,w[C[1]],D+q],[v+q,w[C[2]],D]);G=h.linePlaneIntersect(tmpNormA,[v,w[G[0]],D+q],c,h.add(c,o));y=Math.abs(b+(A+1)*q-G[0])/Math.abs(a+y*q- G[2]);if(1<=y&&G[0]>=v-1.0E-8&&G[0]<=v+q+1.0E-8&&G[2]>=D-1.0E-8&&G[2]<=D+1.0E-8+q)return G;A=h.linePlaneIntersect(tmpNormB,[v,w[C[0]],D+q],c,h.add(c,o));if(1>y&&A[0]>=v-1.0E-8&&A[0]<=v+q+1.0E-8&&A[2]>=D-1.0E-8&&A[2]<=D+q+1.0E-8)return A}}}};var r=m.extendClassGeneral(m.Mesh,function(d){d=d||{};d.dynamic=!0;d.buildWireframe=!0;this.material=d.material;this._update=m.Mesh.prototype.update;m.Mesh.apply(this,[d]);this.hField=d.hField||null;this.divX=d.divX||null;this.divZ=d.divZ||null;this.viewX=d.viewX|| 0;this.viewZ=d.viewZ||0;this.ofsX=d.ofsX||0;this.ofsZ=d.ofsZ||0;this.edgeX=d.edgeX||0;this.edgeZ=d.edgeZ||0;this.normalBuffer=[];this.genHeightfieldMesh()},{setIndexedHeight:function(d,g,c){this.points[d+g*this.divX][1]=c},genHeightfieldMesh:function(){var d,g,c=this.divX+this.edgeX,a=this.divZ+this.edgeZ,b=this.hField.getCellSize(),f=b*this.divX;d=b*this.divZ;0!==this.points.length&&this.clean();var e=-(d/2);for(g=0;gthis.divZ?(this.sizeX=this.size,this.sizeZ=this.size/this.divX*this.divZ):(this.sizeX=this.divZ>this.divX?this.size/this.divZ* this.divX:this.size,this.sizeZ=this.size);this.cellSize=this.sizeX/this.divX;this.tileSize=this.cellSize*this.tileX;this.spatResolution=h.spatResolution||256;this.spats=h.spats||[];this.sourceSpats=h.spats.slice(0);m.SceneObject.apply(this,[{mesh:null,shadowCast:!1}]);for(var o=0,r=0,d=0;d=1.0-spatTexel/2.0) {\n spatSourceCoord.s=1.0-spatTexel/2.0;\n}\nif (spatSourceCoord.t<=spatTexel/2.0) {\n spatSourceCoord.t=spatTexel/2.0;\n}\nif (spatSourceCoord.t>=1.0-spatTexel/2.0) {\n spatSourceCoord.t=1.0-spatTexel/2.0;\n}\nvec4 spatSource = texture2D(spatImage,spatSourceCoord);\ncolor = mix(color,texture2D(spat1,spatTexCoord),spatSource.r);\ncolor = mix(color,texture2D(spat2,spatTexCoord),spatSource.g);\ncolor = mix(color,texture2D(spat3,spatTexCoord),spatSource.b);\ncolor = mix(color,texture2D(spat4,spatTexCoord),spatSource.a);\nvec3 normal = cubicvr_normal(texCoord);\ncolor = cubicvr_environment(color,normal,texCoord);\ncolor = cubicvr_lighting(color,normal,texCoord);\ngl_FragColor = clamp(color,0.0,1.0);\n}", init:function(){},update:function(d){return function(c,a){var b=a.textureIndex;c.spatImage.set(b++,d.sourceTex);c.spatOffset.set(d.spatOffset);c.spatTexel.set(d.spatTexel);o[0]&&c.spat0.set(b++,o[0]);o[1]&&c.spat1.set(b++,o[1]);o[2]&&c.spat2.set(b++,o[2]);o[3]&&c.spat3.set(b++,o[3]);o[4]&&c.spat4.set(b++,o[4])}}(this)});h.shader=this.spatShader;m.Material.apply(this,[h])},{setSpats:function(h){this.spats=h},getSpats:function(){return this.spats},setSource:function(h){this.sourceTexture=h}})}}); CubicVR.RegisterModule("Octree",function(m){function w(a,b,c,e,d){var g=this._children=[];this._dirty=!1;g[0]=null;g[1]=null;g[2]=null;g[3]=null;g[4]=null;g[5]=null;g[6]=null;g[7]=null;this._child_index=d||-1;this._root=c||null;this._max_depth=b||0;a=this._size=a||0;e=this._position=e||[0,0,0];this._nodes=[];this._lights=[];this._static_lights=[];this._sphere=[e[0],e[1],e[2],Math.sqrt(3*(this._size/2*this._size/2))];b=this._bbox=[[0,0,0],[0,0,0]];c=m.aabb;c.reset(b,e);a/=2;c.engulf(b,[e[0]+a,e[1]+ a,e[2]+a]);c.engulf(b,[e[0]-a,e[1]-a,e[2]-a]);this._debug_visible=!1}function t(){this.position=[0,0,0];this.visible=!1;this._object=null}function h(){this.last_in=[];this._planes=[];this.sphere=null;for(var a=0;6>a;++a)this._planes[a]=[0,0,0,0]}var o=m.undef,r=m.plane,d=m.sphere,g=m.enums;g.frustum={plane:{LEFT:0,RIGHT:1,TOP:2,BOTTOM:3,NEAR:4,FAR:5}};g.octree={TOP_NW:0,TOP_NE:1,TOP_SE:2,TOP_SW:3,BOTTOM_NW:4,BOTTOM_NE:5,BOTTOM_SE:6,BOTTOM_SW:7};var c=function(a,b,c){c=a.slice((c||b)+1||a.length); a.length=0>b?a.length+b:b;return a.push.apply(a,c)};w.prototype.destroy=function(){var a,b,c;a=0;for(b=this._static_lights.length;ab;++b)null!==this._children[b]&&this._children[b].propagate_static_light(a)};w.prototype.collect_static_lights=function(a){var b,c;b=0;for(c=this._static_lights.length;bb;++b)null!==this._children[b]&&this._children[b].collect_static_lights(a)};w.prototype.insert=function(a,b){function c(a,b,e,d){var f,n;if(e)if(b.method===g.light.method.STATIC){-1=== a._static_lights.indexOf(b)&&a._static_lights.push(b);e=0;for(f=a._nodes.length;ee[0]&&t[1]e[1]&&t[2]e[0]&&z[1]>e[1]&&t[2]e[2];r=z[0]>e[0]&&t[1]e[2];t=t[0]e[1]&&z[2]>e[2];e=z[0]>e[0]&&z[1]>e[1]&&z[2]>e[2];if(d&&n&&x&&u&&h&&r&&t&&e)c(this,a,b,this),b?a.method==g.light.method.STATIC&&this.propagate_static_light(a):this.collect_static_lights(a);else{for(var z=0,E=this._static_lights.length;z=this._position[0]-this._size/2&&a[1]>= this._position[1]-this._size/2&&a[2]>=this._position[2]-this._size/2};w.prototype.get_frustum_hits=function(a,b){var c={objects:[],lights:[]};if((b===o||!0===b)&&!this.contains_point(a.position)){if(!1===d.intersects(a.frustum.sphere,this._sphere))return c;var e=a.frustum.contains_sphere(this._sphere);if(-1===e)return this._debug_visible=!1,c;if(1===e)this._debug_visible=2,b=!1;else if(0===e){this._debug_visible=!0;e=a.frustum.contains_box(this._bbox);if(-1===e)return this._debug_visible=!1,c;1=== e&&(this._debug_visible=3,b=!1)}}var g,n,e=0;for(g=this._nodes.length;ee;++e)if(null!==this._children[e]){g=this._children[e].get_frustum_hits(a,b);var h;n=0;for(h=g.objects.length;nm.indexOf(this._lights[r])&&m.push(this._lights[r])}n=0;for(h=g.lights.length;nc.lights.indexOf(g.lights[n])&&c.lights.push(g.lights[n])}return c};w.prototype.reset_node_visibility=function(){this._debug_visible=!1;var a,b;a=0;for(b=this._nodes.length;an;++n)r.normalize(b[n]);n=-b[g.frustum.plane.NEAR][3];b=b[g.frustum.plane.FAR][3]-n;c=b*(1/c[5]);c=d.subtract([0, 0,n+0.5*b],[c,c,n+b]);c=d.length(c);e=[e[3],e[9],e[10]];n=d.length(e);e=d.multiply(e,1/n);a=[a.position[0],a.position[1],a.position[2]];a=d.add(a,d.multiply(e,0.5*b));a=d.add(a,d.multiply(e,1));this.sphere=[a[0],a[1],a[2],c]}};h.prototype.contains_sphere=function(a){for(var b=m.vec3,c=this._planes,e=0;6>e;++e){var d=c[e],d=b.dot([d[0],d[1],d[2]],[a[0],a[1],a[2]])+d.d;this.last_in[e]=1;if(d<-a[3])return-1;if(Math.abs(d)e;++e){for(var d=8,g=1,h=0;8>h;++h)-1===r.classifyPoint(a[e],c[h])&&(g=0,--d);this.last_in[e]=g;if(0===d)return-1;b+=g}return 6===b?1:0};return{Frustum:h,Octree:w}}); CubicVR.RegisterModule("CVRXML",function(m){function w(b,c,e,d){var g=CubicVR.util,h=null,m=null;d.triangles&&(m=g.intDelimArray(a.getTextNode(d,"triangles")," "));if(m&&(d.segments&&(h=g.intDelimArray(a.getTextNode(d,"segments")," ")),null===h&&(h=[0,parseInt(m.length/3,10)]),d=0,b.setFaceMaterial(c),m.length)){p=0;for(pMax=h.length;pc)return null;var d=[],g;g=a.length;for(var h=0,m=g-1,o=0;o=o--)return null;var r=g;c<=r&&(r=0);g=r+1;c<=g&&(g=0);m=g+1;c<=m&&(m=0);var t;a:{t=a;var w=r,v=g,y=m,A=c,C=d,G=void 0,B=void 0,I=void 0,J=void 0,K=void 0,M=void 0,L=void 0,N=void 0,Y=void 0,B=t[C[w]][0],I=t[C[w]][1], J=t[C[v]][0],K=t[C[v]][1],M=t[C[y]][0],L=t[C[y]][1];if(f>(J-B)*(L-I)-(K-I)*(M-B))t=!1;else{for(G=0;Gb[0]});for(c=0;5>c;c++)for(d=0;dMath.abs(g[c][1]-g[d][1])&&4>Math.abs(g[c][2]-g[d][2])&&o.push([c,d]);o.sort(function(a,b){return g[a[0]][0]+g[a[1]][0]>g[b[0]][0]+g[b[1]][0]});10h&&(e.contacts.length=h);for(c=0;cthis.maxEngineForce&&(this.gEngineForce=this.maxEngineForce);this.gEngineForce<-this.maxEngineForce&&(this.gEngineForce=-this.maxEngineForce)}, getEngineForce:function(){return this.gEngineForce},incEngine:function(d){this.setEngineForce(this.getEngineForce()+d)},decEngine:function(d){this.setEngineForce(this.getEngineForce()-d)},setSteering:function(d){this.gVehicleSteering=d},getSteering:function(){return this.gVehicleSteering},incSteering:function(d){this.gVehicleSteering+=d;this.gVehicleSteering>this.steeringClamp&&(this.gVehicleSteering=this.steeringClamp);this.gVehicleSteering<-this.steeringClamp&&(this.gVehicleSteering=-this.steeringClamp)}, setBrake:function(d){this.gBreakingForce=d},getWheelGroundPosition:function(d){return this.wheels[d].wheelObj.getWorldPosition()-[0,wheels[d].getWheelRadius(),0]},getWheelSkid:function(d){return this.m_vehicle.getWheelInfo(d).get_m_skidInfo()},getRigidGround:function(d){this.m_vehicle.getWheelInfo(d)},addWheel:function(d,c){c===w&&(c=this.wheels.length);this.wheels[c]=d},getWheel:function(d){return this.wheels[d]},bindToScene:function(d){for(var c=this.wheels.length,a=0;a