// osg-0.0.5.js commit ba7e80947d5baa1841b1bc62c26c2820e2ac1fba - http://github.com/cedricpinson/osgjs
var osg={};osg.version="0.0.5";osg.copyright="Cedric Pinson - cedric.pinson@plopbyte.com";osg.instance=0;osg.version=0;osg.log=function(a){window.console!==undefined&&window.console.log(a)};osg.reportErrorGL=!1;osg.init=function(){};
osg.checkError=function(a){if(a!==0)if(a===1280)osg.log("detected error INVALID_ENUM");else if(a===1281)osg.log("detected error INVALID_VALUE");else if(a===1282)osg.log("detected error INVALID_OPERATION");else if(a===1285)osg.log("detected error OUT_OF_MEMORY");else a===1286?osg.log("detected error INVALID_FRAMEBUFFER_OPERATION"):osg.log("detected error UNKNOWN")};
osg.extend=function(){var a=Object.prototype.toString,c=Object.prototype.hasOwnProperty,e=function(q){return a.call(q)==="[object Array]"},f=function(q){if(!q||a.call(q)!=="[object Object]"||q.nodeType||q.setInterval)return!1;if(q.constructor&&!c.call(q,"constructor")&&!c.call(q.constructor.prototype,"isPrototypeOf"))return!1;for(var s in q);return s===undefined||c.call(q,s)},g=arguments[0]||{},h=1,i=arguments.length,j=!1,k,m,n,o;if(typeof g==="boolean"){j=g;g=arguments[1]||{};h=2}typeof g!=="object"&&
a.call(g)!=="[object Function]"&&(g={});if(i===h){g=this;--h}for(;h<i;h++)if((k=arguments[h])!=null)for(m in k){n=g[m];o=k[m];if(g!==o)if(j&&o&&(f(o)||e(o))){n=n&&(f(n)||e(n))?n:e(o)?[]:{};g[m]=osg.extend(j,n,o)}else o!==undefined&&(g[m]=o)}return g};osg.objectInehrit=function(a,c){function e(){}e.prototype=a;var f=new e;c&&osg.objectMix(f,c,!1);return f};osg.objectMix=function(a,c,e){for(var f in c)if(!e||!a[f])a[f]=c[f];return a};osg.objectType={};osg.objectType.type=0;
osg.objectType.generate=function(a){var c=osg.objectType.type;osg.objectType[c]=a;osg.objectType[a]=c;osg.objectType.type+=1;return c};osg.Float32Array=Float32Array;osg.Int32Array=Int32Array;osg.Uint16Array=Uint16Array;
osg.Vec2={copy:function(a,c){c[0]=a[0];c[1]=a[1];return c},valid:function(a){if(isNaN(a[0]))return!1;if(isNaN(a[1]))return!1;return!0},mult:function(a,c,e){e[0]=a[0]*c;e[1]=a[1]*c;return e},length2:function(a){return a[0]*a[0]+a[1]*a[1]},length:function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1])},normalize:function(a,c){var e=this.length2(a);if(e>0){e=1/Math.sqrt(e);c[0]=a[0]*e;c[1]=a[1]*e}else{c[0]=a[0];c[1]=a[1]}return c},dot:function(a,c){return a[0]*c[0]+a[1]*c[1]},sub:function(a,c,e){e[0]=a[0]-
c[0];e[1]=a[1]-c[1];return e},add:function(a,c,e){e[0]=a[0]+c[0];e[1]=a[1]+c[1];return e},neg:function(a,c){c[0]=-a[0];c[1]=-a[1];return c},lerp:function(a,c,e,f){var g=1-a;f[0]=c[0]*g+a*e[0];f[1]=c[1]*g+a*e[1];return f}};
osg.Vec3={copy:function(a,c){c[0]=a[0];c[1]=a[1];c[2]=a[2];return c},cross:function(a,c,e){e[0]=a[1]*c[2]-a[2]*c[1];e[1]=a[2]*c[0]-a[0]*c[2];e[2]=a[0]*c[1]-a[1]*c[0];return e},valid:function(a){if(isNaN(a[0]))return!1;if(isNaN(a[1]))return!1;if(isNaN(a[2]))return!1;return!0},mult:function(a,c,e){e[0]=a[0]*c;e[1]=a[1]*c;e[2]=a[2]*c;return e},length2:function(a){return a[0]*a[0]+a[1]*a[1]+a[2]*a[2]},length:function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2])},normalize:function(a,c){var e=this.length2(a);
if(e>0){e=1/Math.sqrt(e);c[0]=a[0]*e;c[1]=a[1]*e;c[2]=a[2]*e}else{c[0]=a[0];c[1]=a[1];c[2]=a[2]}return c},dot:function(a,c){return a[0]*c[0]+a[1]*c[1]+a[2]*c[2]},sub:function(a,c,e){e[0]=a[0]-c[0];e[1]=a[1]-c[1];e[2]=a[2]-c[2];return e},add:function(a,c,e){e[0]=a[0]+c[0];e[1]=a[1]+c[1];e[2]=a[2]+c[2];return e},neg:function(a,c){c[0]=-a[0];c[1]=-a[1];c[2]=-a[2];return c},lerp:function(a,c,e,f){var g=1-a;f[0]=c[0]*g+a*e[0];f[1]=c[1]*g+a*e[1];f[2]=c[2]*g+a*e[2];return f}};
osg.Vec4={dot:function(a,c){return a[0]*c[0]+a[1]*c[1]+a[2]*c[2]+a[3]*c[3]},copy:function(a,c){c[0]=a[0];c[1]=a[1];c[2]=a[2];c[3]=a[3];return c},sub:function(a,c,e){e[0]=a[0]-c[0];e[1]=a[1]-c[1];e[2]=a[2]-c[2];e[3]=a[3]-c[3];return e},mult:function(a,c){r[0]=a[0]*c;r[1]=a[1]*c;r[2]=a[2]*c;r[3]=a[3]*c;return r},add:function(a,c,e){e[0]=a[0]+c[0];e[1]=a[1]+c[1];e[2]=a[2]+c[2];e[3]=a[3]+c[3];return e},neg:function(a,c){c[0]=-a[0];c[1]=-a[1];c[2]=-a[2];c[3]=-a[3];return c},lerp:function(a,c,e,f){var g=
1-a;f[0]=c[0]*g+a*e[0];f[1]=c[1]*g+a*e[1];f[2]=c[2]*g+a*e[2];f[3]=c[3]*g+a*e[3];return f}};
osg.Matrix={setRow:function(a,c,e,f,g,h){c*=4;a[c+0]=e;a[c+1]=f;a[c+2]=g;a[c+3]=h},innerProduct:function(a,c,e,f){e*=4;return a[e+0]*c[0+f]+a[e+1]*c[4+f]+a[e+2]*c[8+f]+a[e+3]*c[12+f]},set:function(a,c,e,f){return a[c*4+e]=f},get:function(a,c,e){return a[c*4+e]},makeIdentity:function(a){a===undefined&&(a=[]);osg.Matrix.setRow(a,0,1,0,0,0);osg.Matrix.setRow(a,1,0,1,0,0);osg.Matrix.setRow(a,2,0,0,1,0);osg.Matrix.setRow(a,3,0,0,0,1);return a},makeTranslate:function(a,c,e,f){f===undefined&&(f=[]);osg.Matrix.setRow(f,
0,1,0,0,0);osg.Matrix.setRow(f,1,0,1,0,0);osg.Matrix.setRow(f,2,0,0,1,0);osg.Matrix.setRow(f,3,a,c,e,1);return f},setTrans:function(a,c,e,f){a[12]=c;a[13]=e;a[14]=f;return a},getTrans:function(a,c){c===undefined&&(c=[]);c[0]=a[12];c[1]=a[13];c[2]=a[14];return c},preMult:function(a,c){var e,f,g,h;e=c[0]*a[0]+c[1]*a[4]+c[2]*a[8]+c[3]*a[12];f=c[4]*a[0]+c[5]*a[4]+c[6]*a[8]+c[7]*a[12];g=c[8]*a[0]+c[9]*a[4]+c[10]*a[8]+c[11]*a[12];h=c[12]*a[0]+c[13]*a[4]+c[14]*a[8]+c[15]*a[12];a[0]=e;a[4]=f;a[8]=g;a[12]=
h;e=c[0]*a[1]+c[1]*a[5]+c[2]*a[9]+c[3]*a[13];f=c[4]*a[1]+c[5]*a[5]+c[6]*a[9]+c[7]*a[13];g=c[8]*a[1]+c[9]*a[5]+c[10]*a[9]+c[11]*a[13];h=c[12]*a[1]+c[13]*a[5]+c[14]*a[9]+c[15]*a[13];a[1]=e;a[5]=f;a[9]=g;a[13]=h;e=c[0]*a[2]+c[1]*a[6]+c[2]*a[10]+c[3]*a[14];f=c[4]*a[2]+c[5]*a[6]+c[6]*a[10]+c[7]*a[14];g=c[8]*a[2]+c[9]*a[6]+c[10]*a[10]+c[11]*a[14];h=c[12]*a[2]+c[13]*a[6]+c[14]*a[10]+c[15]*a[14];a[2]=e;a[6]=f;a[10]=g;a[14]=h;e=c[0]*a[3]+c[1]*a[7]+c[2]*a[11]+c[3]*a[15];f=c[4]*a[3]+c[5]*a[7]+c[6]*a[11]+c[7]*
a[15];g=c[8]*a[3]+c[9]*a[7]+c[10]*a[11]+c[11]*a[15];h=c[12]*a[3]+c[13]*a[7]+c[14]*a[11]+c[15]*a[15];a[3]=e;a[7]=f;a[11]=g;a[15]=h;return a},postMult:function(a,c){btmp0=c[0]*a[0]+c[1]*a[4]+c[2]*a[8]+c[3]*a[12];btmp1=c[0]*a[1]+c[1]*a[5]+c[2]*a[9]+c[3]*a[13];btmp2=c[0]*a[2]+c[1]*a[6]+c[2]*a[10]+c[3]*a[14];btmp3=c[0]*a[3]+c[1]*a[7]+c[2]*a[11]+c[3]*a[15];c[0]=btmp0;c[1]=btmp1;c[2]=btmp2;c[3]=btmp3;btmp0=c[4]*a[0]+c[5]*a[4]+c[6]*a[8]+c[7]*a[12];btmp1=c[4]*a[1]+c[5]*a[5]+c[6]*a[9]+c[7]*a[13];btmp2=c[4]*
a[2]+c[5]*a[6]+c[6]*a[10]+c[7]*a[14];btmp3=c[4]*a[3]+c[5]*a[7]+c[6]*a[11]+c[7]*a[15];c[4]=btmp0;c[5]=btmp1;c[6]=btmp2;c[7]=btmp3;btmp0=c[8]*a[0]+c[9]*a[4]+c[10]*a[8]+c[11]*a[12];btmp1=c[8]*a[1]+c[9]*a[5]+c[10]*a[9]+c[11]*a[13];btmp2=c[8]*a[2]+c[9]*a[6]+c[10]*a[10]+c[11]*a[14];btmp3=c[8]*a[3]+c[9]*a[7]+c[10]*a[11]+c[11]*a[15];c[8]=btmp0;c[9]=btmp1;c[10]=btmp2;c[11]=btmp3;btmp0=c[12]*a[0]+c[13]*a[4]+c[14]*a[8]+c[15]*a[12];btmp1=c[12]*a[1]+c[13]*a[5]+c[14]*a[9]+c[15]*a[13];btmp2=c[12]*a[2]+c[13]*a[6]+
c[14]*a[10]+c[15]*a[14];btmp3=c[12]*a[3]+c[13]*a[7]+c[14]*a[11]+c[15]*a[15];c[12]=btmp0;c[13]=btmp1;c[14]=btmp2;c[15]=btmp3;return c},multa:function(a,c,e){if(e===a)return this.preMult(a,c);else if(e===c)return this.postMult(a,c);else{e===undefined&&(e=[]);e[0]=c[0]*a[0]+c[1]*a[4]+c[2]*a[8]+c[3]*a[12];e[1]=c[0]*a[1]+c[1]*a[5]+c[2]*a[9]+c[3]*a[13];e[2]=c[0]*a[2]+c[1]*a[6]+c[2]*a[10]+c[3]*a[14];e[3]=c[0]*a[3]+c[1]*a[7]+c[2]*a[11]+c[3]*a[15];e[4]=c[4]*a[0]+c[5]*a[4]+c[6]*a[8]+c[7]*a[12];e[5]=c[4]*a[1]+
c[5]*a[5]+c[6]*a[9]+c[7]*a[13];e[6]=c[4]*a[2]+c[5]*a[6]+c[6]*a[10]+c[7]*a[14];e[7]=c[4]*a[3]+c[5]*a[7]+c[6]*a[11]+c[7]*a[15];e[8]=c[8]*a[0]+c[9]*a[4]+c[10]*a[8]+c[11]*a[12];e[9]=c[8]*a[1]+c[9]*a[5]+c[10]*a[9]+c[11]*a[13];e[10]=c[8]*a[2]+c[9]*a[6]+c[10]*a[10]+c[11]*a[14];e[11]=c[8]*a[3]+c[9]*a[7]+c[10]*a[11]+c[11]*a[15];e[12]=c[12]*a[0]+c[13]*a[4]+c[14]*a[8]+c[15]*a[12];e[13]=c[12]*a[1]+c[13]*a[5]+c[14]*a[9]+c[15]*a[13];e[14]=c[12]*a[2]+c[13]*a[6]+c[14]*a[10]+c[15]*a[14];e[15]=c[12]*a[3]+c[13]*a[7]+
c[14]*a[11]+c[15]*a[15];return e}},mult:function(a,c,e){var f=c[0],g=c[1],h=c[2],i=c[3],j=c[4],k=c[5],m=c[6],n=c[7],o=c[8],q=c[9],s=c[10],p=c[11],t=c[12],v=c[13],w=c[14];c=c[15];var x=a[0],y=a[1],z=a[2],A=a[3],B=a[4],C=a[5],D=a[6],E=a[7],F=a[8],G=a[9],H=a[10],I=a[11],u=a[12],J=a[13],K=a[14];a=a[15];e[0]=f*x+g*B+h*F+i*u;e[1]=f*y+g*C+h*G+i*J;e[2]=f*z+g*D+h*H+i*K;e[3]=f*A+g*E+h*I+i*a;e[4]=j*x+k*B+m*F+n*u;e[5]=j*y+k*C+m*G+n*J;e[6]=j*z+k*D+m*H+n*K;e[7]=j*A+k*E+m*I+n*a;e[8]=o*x+q*B+s*F+p*u;e[9]=o*y+q*C+
s*G+p*J;e[10]=o*z+q*D+s*H+p*K;e[11]=o*A+q*E+s*I+p*a;e[12]=t*x+v*B+w*F+c*u;e[13]=t*y+v*C+w*G+c*J;e[14]=t*z+v*D+w*H+c*K;e[15]=t*A+v*E+w*I+c*a;return e},multOrig:function(a,c,e){if(e===a){e=[];for(var f=0;f<4;f++){e[0]=osg.Matrix.innerProduct(c,a,0,f);e[1]=osg.Matrix.innerProduct(c,a,1,f);e[2]=osg.Matrix.innerProduct(c,a,2,f);e[3]=osg.Matrix.innerProduct(c,a,3,f);a[0+f]=e[0];a[4+f]=e[1];a[8+f]=e[2];a[12+f]=e[3]}return a}else if(e===c){e=[];for(f=0;f<4;f++){e[0]=osg.Matrix.innerProduct(c,a,f,0);e[1]=
osg.Matrix.innerProduct(c,a,f,1);e[2]=osg.Matrix.innerProduct(c,a,f,2);e[3]=osg.Matrix.innerProduct(c,a,f,3);this.setRow(c,f,e[0],e[1],e[2],e[3])}return c}e===undefined&&(e=[]);f=c[0];var g=c[1],h=c[2],i=c[3],j=c[4],k=c[5],m=c[6],n=c[7],o=c[8],q=c[9],s=c[10],p=c[11],t=c[12],v=c[13],w=c[14];c=c[15];var x=a[0],y=a[1],z=a[2],A=a[3],B=a[4],C=a[5],D=a[6],E=a[7],F=a[8],G=a[9],H=a[10],I=a[11],u=a[12],J=a[13],K=a[14];a=a[15];e[0]=f*x+g*B+h*F+i*u;e[1]=f*y+g*C+h*G+i*J;e[2]=f*z+g*D+h*H+i*K;e[3]=f*A+g*E+h*I+
i*a;e[4]=j*x+k*B+m*F+n*u;e[5]=j*y+k*C+m*G+n*J;e[6]=j*z+k*D+m*H+n*K;e[7]=j*A+k*E+m*I+n*a;e[8]=o*x+q*B+s*F+p*u;e[9]=o*y+q*C+s*G+p*J;e[10]=o*z+q*D+s*H+p*K;e[11]=o*A+q*E+s*I+p*a;e[12]=t*x+v*B+w*F+c*u;e[13]=t*y+v*C+w*G+c*J;e[14]=t*z+v*D+w*H+c*K;e[15]=t*A+v*E+w*I+c*a;return e},makeLookAt:function(a,c,e,f){f===undefined&&(f=[]);c=osg.Vec3.sub(c,a,[]);osg.Vec3.normalize(c,c);e=osg.Vec3.cross(c,e,[]);osg.Vec3.normalize(e,e);var g=osg.Vec3.cross(e,c,[]);osg.Vec3.normalize(g,g);f[0]=e[0];f[1]=g[0];f[2]=-c[0];
f[3]=0;f[4]=e[1];f[5]=g[1];f[6]=-c[1];f[7]=0;f[8]=e[2];f[9]=g[2];f[10]=-c[2];f[11]=0;f[12]=0;f[13]=0;f[14]=0;f[15]=1;osg.Matrix.multTranslate(f,osg.Vec3.neg(a,[]),f);return f},makeOrtho:function(a,c,e,f,g,h,i){i===undefined&&(i=[]);var j=-(c+a)/(c-a),k=-(f+e)/(f-e),m=-(h+g)/(h-g),n=osg.Matrix.setRow;n(i,0,2/(c-a),0,0,0);n(i,1,0,2/(f-e),0,0);n(i,2,0,0,-2/(h-g),0);n(i,3,j,k,m,1);return i},getLookAt:function(a,c,e,f,g){g===undefined&&(g=1);var h=[];osg.Matrix.inverse(a,h)||osg.Matrix.makeIdentity(h);
osg.Matrix.transformVec3(h,[0,0,0],c);osg.Matrix.transform3x3(a,[0,1,0],f);osg.Matrix.transform3x3(a,[0,0,-1],e);osg.Vec3.normalize(e,e);osg.Vec3.add(osg.Vec3.mult(e,g,[]),c,e)},getRotate:function(a,c){c===undefined&&(c=[]);var e;e=[];var f,g;f=a[0];g=a[5];var h=a[10];e[0]=1+f+g+h;e[1]=1+f-g-h;e[2]=1-f+g-h;e[3]=1-f-g+h;g=0;for(f=1;f<4;f++)e[f]>e[g]&&(g=f);if(g===0){c[3]=e[0];c[0]=a[6]-a[9];c[1]=a[8]-a[2];c[2]=a[1]-a[4]}else if(g==1){c[3]=a[6]-a[9];c[0]=e[1];c[1]=a[1]+a[4];c[2]=a[8]+a[2]}else if(g==
2){c[3]=a[8]-a[2];c[0]=a[1]+a[4];c[1]=e[2];c[2]=a[6]+a[9]}else{c[3]=a[1]-a[4];c[0]=a[8]+a[2];c[1]=a[6]+a[9];c[2]=e[3]}e=Math.sqrt(0.25/e[g]);c[3]*=e;c[0]*=e;c[1]*=e;c[2]*=e;return c},multTranslate:function(a,c,e){e===undefined&&(e=[]);e!==a&&osg.Matrix.copy(a,e);var f;if(c[0]!==0){f=c[0];e[12]+=f*a[0];e[13]+=f*a[1];e[14]+=f*a[2];e[15]+=f*a[3]}if(c[1]!==0){f=c[1];e[12]+=f*a[4];e[13]+=f*a[5];e[14]+=f*a[6];e[15]+=f*a[7]}if(c[2]!==0){f=c[2];e[12]+=f*a[8];e[13]+=f*a[9];e[14]+=f*a[10];e[15]+=f*a[11]}return e},
makeRotate:function(a,c,e,f,g){g===undefined&&(g=[]);var h=Math.sqrt(c*c+e*e+f*f),i=Math.sin(a);a=Math.cos(a);if(h>0){var j,k,m,n,o;h=1/h;c*=h;e*=h;f*=h;h=c*e;j=e*f;k=f*c;m=c*i;n=e*i;i*=f;o=1-a;g[0]=o*c*c+a;g[1]=o*h-i;g[2]=o*k+n;g[3]=0;g[4]=o*h+i;g[5]=o*e*e+a;g[6]=o*j-m;g[7]=0;g[8]=o*k-n;g[9]=o*j+m;g[10]=o*f*f+a;g[11]=0;g[12]=0;g[13]=0;g[14]=0;g[15]=1}return g},transform3x3:function(a,c,e){e===undefined&&(e=[]);e[0]=a[0]*c[0]+a[1]*c[1]+a[2]*c[2];e[1]=a[4]*c[0]+a[5]*c[1]+a[6]*c[2];e[2]=a[8]*c[0]+a[9]*
c[1]+a[10]*c[2];return e},transformVec3:function(a,c,e){var f=1/(a[3]*c[0]+a[7]*c[1]+a[11]*c[2]+a[15]);e===undefined&&(e=[]);var g;g=e===c?[]:e;g[0]=(a[0]*c[0]+a[4]*c[1]+a[8]*c[2]+a[12])*f;g[1]=(a[1]*c[0]+a[5]*c[1]+a[9]*c[2]+a[13])*f;g[2]=(a[2]*c[0]+a[6]*c[1]+a[10]*c[2]+a[14])*f;e===c&&osg.Vec3.copy(g,e);return e},transformVec4:function(a,c,e){e===undefined&&(e=[]);var f;f=e===c?[]:e;f[0]=a[0]*c[0]+a[1]*c[1]+a[2]*c[2]+a[3]*c[3];f[1]=a[4]*c[0]+a[5]*c[1]+a[6]*c[2]+a[7]*c[3];f[2]=a[8]*c[0]+a[9]*c[1]+
a[10]*c[2]+a[11]*c[3];f[3]=a[12]*c[0]+a[13]*c[1]+a[14]*c[2]+a[15]*c[3];e===c&&osg.Vec4.copy(f,e);return e},copy:function(a,c){c===undefined&&(c=[]);c[0]=a[0];c[1]=a[1];c[2]=a[2];c[3]=a[3];c[4]=a[4];c[5]=a[5];c[6]=a[6];c[7]=a[7];c[8]=a[8];c[9]=a[9];c[10]=a[10];c[11]=a[11];c[12]=a[12];c[13]=a[13];c[14]=a[14];c[15]=a[15];return c},inverse:function(a,c){return this.inverse4x4(a,c)},inverse4x4:function(a,c){result=c===undefined?[]:c;var e=a[10]*a[15],f=a[14]*a[11],g=a[6]*a[15],h=a[14]*a[7],i=a[6]*a[11],
j=a[10]*a[7],k=a[2]*a[15],m=a[14]*a[3],n=a[2]*a[11],o=a[10]*a[3],q=a[2]*a[7],s=a[6]*a[3],p=a[8]*a[13],t=a[12]*a[9],v=a[4]*a[13],w=a[12]*a[5],x=a[4]*a[9],y=a[8]*a[5],z=a[0]*a[13],A=a[12]*a[1],B=a[0]*a[9],C=a[8]*a[1],D=a[0]*a[5],E=a[4]*a[1],F=e*a[5]+h*a[9]+i*a[13]-(f*a[5]+g*a[9]+j*a[13]),G=f*a[1]+k*a[9]+o*a[13]-(e*a[1]+m*a[9]+n*a[13]),H=g*a[1]+m*a[5]+q*a[13]-(h*a[1]+k*a[5]+s*a[13]),I=j*a[1]+n*a[5]+s*a[9]-(i*a[1]+o*a[5]+q*a[9]),u=a[0]*F+a[4]*G+a[8]*H+a[12]*I;if(Math.abs(u)<1.0E-5){osg.log("Warning can't inverse matrix "+
a);if(c!==undefined)return!1;else osg.Matrix.makeIdentity(result)}u=1/u;var J=u*(f*a[4]+g*a[8]+j*a[12]-(e*a[4]+h*a[8]+i*a[12]));e=u*(e*a[0]+m*a[8]+n*a[12]-(f*a[0]+k*a[8]+o*a[12]));g=u*(h*a[0]+k*a[4]+s*a[12]-(g*a[0]+m*a[4]+q*a[12]));i=u*(i*a[0]+o*a[4]+q*a[8]-(j*a[0]+n*a[4]+s*a[8]));j=u*(p*a[7]+w*a[11]+x*a[15]-(t*a[7]+v*a[11]+y*a[15]));n=u*(t*a[3]+z*a[11]+C*a[15]-(p*a[3]+A*a[11]+B*a[15]));o=u*(v*a[3]+A*a[7]+D*a[15]-(w*a[3]+z*a[7]+E*a[15]));q=u*(y*a[3]+B*a[7]+E*a[11]-(x*a[3]+C*a[7]+D*a[11]));s=u*(v*
a[10]+y*a[14]+t*a[6]-(x*a[14]+p*a[6]+w*a[10]));p=u*(B*a[14]+p*a[2]+A*a[10]-(z*a[10]+C*a[14]+t*a[2]));v=u*(z*a[6]+E*a[14]+w*a[2]-(D*a[14]+v*a[2]+A*a[6]));x=u*(D*a[10]+x*a[2]+C*a[6]-(B*a[6]+E*a[10]+y*a[2]));result[0]=u*F;result[1]=u*G;result[2]=u*H;result[3]=u*I;result[4]=J;result[5]=e;result[6]=g;result[7]=i;result[8]=j;result[9]=n;result[10]=o;result[11]=q;result[12]=s;result[13]=p;result[14]=v;result[15]=x;if(c!==undefined)return!0;return result},inverse4x3:function(a,c){result=c===undefined?[]:
c;result[0]=a[5]*a[10]-a[6]*a[9];result[1]=a[2]*a[9]-a[1]*a[10];result[2]=a[1]*a[6]-a[2]*a[5];var e=a[0],f=a[4],g=a[8],h=1/(e*result[0]+f*result[1]+g*result[2]);e*=h;f*=h;g*=h;result[0]*=h;result[1]*=h;result[2]*=h;result[3]=0;result[4]=a[6]*g-f*a[10];result[5]=e*a[10]-a[2]*g;result[6]=a[2]*f-e*a[6];result[7]=0;result[8]=f*a[9]-a[5]*g;result[9]=a[1]*g-e*a[9];result[10]=e*a[5]-a[1]*f;result[11]=0;result[15]=1;e=a[15];f=e-1;var i,j,k;if(f*f>1.0E-6){f=[];result[12]=result[13]=result[15]=0;i=a[3];j=a[7];
k=a[11];g=result[0]*i+result[1]*j+result[2]*k;h=result[4]*i+result[5]*j+result[6]*k;var m=result[8]*i+result[9]*j+result[10]*k;i=a[12];j=a[13];k=a[14];e=1/(e-(i*g+j*h+k*m));i*=e;j*=e;k*=e;f[0]=i*g+1;f[1]=j*g;f[2]=k*g;f[3]=-g*e;f[4]=i*h;f[5]=j*h+1;f[6]=k*h;f[7]=-h*e;f[8]=i*m;f[9]=j*m;f[10]=k*m+1;f[11]=-m*e;f[12]=-i;f[13]=-j;f[14]=-k;f[15]=e;this.mult(result,f,result)}else{i=a[12];j=a[13];k=a[14];result[12]=-(i*result[0]+j*result[4]+k*result[8]);result[13]=-(i*result[1]+j*result[5]+k*result[9]);result[14]=
-(i*result[2]+j*result[6]+k*result[10])}if(c!==undefined)return!0;return result},transpose:function(a,c){if(a===c){var e=a[1],f=a[2],g=a[3],h=a[6],i=a[7],j=a[11];a[1]=a[4];a[2]=a[8];a[3]=a[12];a[4]=e;a[6]=a[9];a[7]=a[13];a[8]=f;a[9]=h;a[11]=a[14];a[12]=g;a[13]=i;a[14]=j;return a}else{c[0]=a[0];c[1]=a[4];c[2]=a[8];c[3]=a[12];c[4]=a[1];c[5]=a[5];c[6]=a[9];c[7]=a[13];c[8]=a[2];c[9]=a[6];c[10]=a[10];c[11]=a[14];c[12]=a[3];c[13]=a[7];c[14]=a[11];c[15]=a[15];return c}},makePerspective:function(a,c,e,f,
g){g===undefined&&(g=[]);a=e*Math.tan(a*Math.PI/360);var h=-a;return osg.Matrix.makeFrustum(h*c,a*c,h,a,e,f,g)},makeScale:function(a,c,e,f){f===undefined&&(f=[]);this.setRow(f,0,a,0,0,0);this.setRow(f,1,0,c,0,0);this.setRow(f,2,0,0,e,0);this.setRow(f,3,0,0,0,1);return f},makeFrustum:function(a,c,e,f,g,h,i){i===undefined&&(i=[]);var j=2*g/(f-e),k=(c+a)/(c-a);e=(f+e)/(f-e);f=-(h+g)/(h-g);h=-2*h*g/(h-g);this.setRow(i,0,2*g/(c-a),0,0,0);this.setRow(i,1,0,j,0,0);this.setRow(i,2,k,e,f,-1);this.setRow(i,
3,0,0,h,0);return i},makeRotateFromQuat:function(a,c){c===undefined&&(c=[]);this.makeIdentity(c);return this.setRotateFromQuat(c,a)},setRotateFromQuat:function(a,c){var e=osg.Quat.length2(c);if(Math.abs(e)<=Number.MIN_VALUE){a[0]=0;a[1]=0;a[2]=0;a[4]=0;a[5]=0;a[6]=0;a[8]=0;a[9]=0;a[10]=0}else{e=e!==1?2/e:2;var f,g,h,i,j,k,m,n;f=e*c[0];g=e*c[1];h=e*c[2];e=c[0]*f;k=c[0]*g;m=c[0]*h;i=c[1]*g;j=c[1]*h;n=c[2]*h;f*=c[3];g*=c[3];h*=c[3];a[0]=1-(i+n);a[4]=k-h;a[8]=m+g;a[1]=k+h;a[5]=1-(e+n);a[9]=j-f;a[2]=m-
g;a[6]=j+f;a[10]=1-(e+i)}return a}};osg.ShaderGeneratorType={VertexInit:0,VertexFunction:1,VertexMain:2,FragmentInit:3,FragmentMain:5};osg.Shader=function(a,c){this.type=a;this.text=c};
osg.Shader.prototype={compile:function(){this.shader=gl.createShader(this.type);gl.shaderSource(this.shader,this.text);gl.compileShader(this.shader);if(!gl.getShaderParameter(this.shader,gl.COMPILE_STATUS)){osg.log("can't compile shader:\n"+this.text+"\n");for(var a=("\n"+this.text).split("\n"),c="\n",e=0,f=a.length;e<f;++e)c+=e+" "+a[e]+"\n";osg.log(c);osg.log(gl.getShaderInfoLog(this.shader))}}};
osg.Shader.create=function(a,c){osg.log("osg.Shader.create is deprecated, use new osg.Shader with the same arguments instead");return new osg.Shader(a,c)};osg.StateAttribute=function(){this._dirty=!0};osg.StateAttribute.prototype={isDirty:function(){return this._dirty},dirty:function(){this._dirty=!0},setDirty:function(a){this._dirty=a}};osg.StateAttribute.OFF=0;osg.StateAttribute.ON=1;osg.StateAttribute.OVERRIDE=2;osg.StateAttribute.PROTECTED=4;osg.StateAttribute.INHERIT=8;
osg.Uniform=function(){this.transpose=!1;this._dirty=!0};
osg.Uniform.prototype={get:function(){return this.data},set:function(a){this.data=a;this.dirty()},dirty:function(){this._dirty=!0},apply:function(a){if(this._dirty){this.update.call(this.glData,this.data);this._dirty=!1}this.glCall(a,this.glData)},applyMatrix:function(a){if(this._dirty){this.update.call(this.glData,this.data);this._dirty=!1}this.glCall(a,this.transpose,this.glData)},update:function(a){for(var c=0,e=a.length;c<e;++c)this[c]=a[c]},_updateFloat1:function(a){this[0]=a[0]},_updateFloat2:function(a){this[0]=
a[0];this[1]=a[1]},_updateFloat3:function(a){this[0]=a[0];this[1]=a[1];this[2]=a[2]},_updateFloat4:function(a){this[0]=a[0];this[1]=a[1];this[2]=a[2];this[3]=a[3]},_updateFloat9:function(a){this[0]=a[0];this[1]=a[1];this[2]=a[2];this[3]=a[3];this[4]=a[4];this[5]=a[5];this[6]=a[6];this[7]=a[7];this[8]=a[8]},_updateFloat16:function(a){this[0]=a[0];this[1]=a[1];this[2]=a[2];this[3]=a[3];this[4]=a[4];this[5]=a[5];this[6]=a[6];this[7]=a[7];this[8]=a[8];this[9]=a[9];this[10]=a[10];this[11]=a[11];this[12]=
a[12];this[13]=a[13];this[14]=a[14];this[15]=a[15]}};osg.Uniform.createFloat1=function(a,c){var e=new osg.Uniform;e.data=[a];e.glCall=function(f,g){gl.uniform1fv(f,g)};e.glData=new osg.Float32Array(e.data);e.update=osg.Uniform.prototype._updateFloat1;e.name=c;return e};osg.Uniform.createFloat2=function(a,c){var e=new osg.Uniform;e.data=a;e.glCall=function(f,g){gl.uniform2fv(f,g)};e.glData=new osg.Float32Array(e.data);e.update=osg.Uniform.prototype._updateFloat2;e.name=c;return e};
osg.Uniform.createFloat3=function(a,c){var e=new osg.Uniform;e.data=a;e.glCall=function(f,g){gl.uniform3fv(f,g)};e.glData=new osg.Float32Array(e.data);e.update=osg.Uniform.prototype._updateFloat3;e.name=c;return e};osg.Uniform.createFloat4=function(a,c){var e=new osg.Uniform;e.data=a;e.glCall=function(f,g){gl.uniform4fv(f,g)};e.glData=new osg.Float32Array(e.data);e.update=osg.Uniform.prototype._updateFloat4;e.name=c;return e};
osg.Uniform.createInt1=function(a,c){var e=new osg.Uniform;e.data=[a];e.glCall=function(f,g){gl.uniform1iv(f,g)};e.glData=new osg.Int32Array(e.data);e.name=c;return e};osg.Uniform.createInt2=function(a,c){var e=new osg.Uniform;e.data=a;e.glCall=function(f,g){gl.uniform2iv(f,g)};e.glData=new osg.Int32Array(e.data);e.name=c;return e};osg.Uniform.createInt3=function(a,c){var e=new osg.Uniform;e.data=a;e.glCall=function(f,g){gl.uniform3iv(f,g)};e.glData=new osg.Int32Array(e.data);e.name=c;return e};
osg.Uniform.createInt4=function(a,c){var e=new osg.Uniform;e.data=a;e.glCall=function(f,g){gl.uniform4iv(f,g)};e.glData=new osg.Int32Array(e.data);e.name=c;return e};osg.Uniform.createMatrix2=function(a,c){var e=new osg.Uniform;e.data=a;e.glCall=function(f,g,h){gl.uniformMatrix2fv(f,g,h)};e.apply=e.applyMatrix;e.transpose=!1;e.glData=new osg.Float32Array(e.data);e.update=osg.Uniform.prototype._updateFloat4;e.name=c;return e};
osg.Uniform.createMatrix3=function(a,c){var e=new osg.Uniform;e.data=a;e.glCall=function(f,g,h){gl.uniformMatrix3fv(f,g,h)};e.apply=e.applyMatrix;e.transpose=!1;e.glData=new osg.Float32Array(e.data);e.update=osg.Uniform.prototype._updateFloat9;e.name=c;return e};
osg.Uniform.createMatrix4=function(a,c){var e=new osg.Uniform;e.data=a;e.glCall=function(f,g,h){gl.uniformMatrix4fv(f,g,h)};e.apply=e.applyMatrix;e.transpose=!1;e.glData=new osg.Float32Array(e.data);e.update=osg.Uniform.prototype._updateFloat16;e.name=c;return e};osg.Node=function(){this.children=[];this.parents=[];this.nodeMask=-1;this.boundingSphere=new osg.BoundingSphere;this.boundingSphereComputed=!1};
osg.Node.prototype={getOrCreateStateSet:function(){if(this.stateset===undefined)this.stateset=new osg.StateSet;return this.stateset},getStateSet:function(){return this.stateset},accept:function(a){if(a.validNodeMask(this)){a.pushOntoNodePath(this);a.apply(this);a.popFromNodePath()}},dirtyBound:function(){if(this.boundingSphereComputed===!0){this.boundingSphereComputed=!1;for(var a=0,c=this.parents.length;a<c;a++)this.parents[a].dirtyBound()}},setNodeMask:function(a){this.nodeMask=a},getNodeMask:function(){return this.nodeMask},
setStateSet:function(a){this.stateset=a},setUpdateCallback:function(a){this.updateCallback=a},getUpdateCallback:function(){return this.updateCallback},setName:function(a){this.name=a},getName:function(){return this.name},hasChild:function(a){for(var c=0,e=this.children.length;c<e;c++)if(this.children[c]===a)return!0;return!1},addChild:function(a){var c=this.children.push(a);a.addParent(this);this.dirtyBound();return c},getChildren:function(){return this.children},addParent:function(a){this.parents.push(a)},
removeParent:function(a){for(var c=0,e=this.parents.length,f=this.parents;c<e;c++)if(f[c]===a){f.splice(c,1);break}},removeChildren:function(){var a=this.children;if(a.length!==0){for(var c=0,e=a.length;c<e;c++)a[c].removeParent(this);this.children.length=0;this.dirtyBound()}},removeChild:function(a){for(var c=0,e=this.children.length;c<e;c++)if(this.children[c]===a){a.removeParent(this);this.children.splice(c,1);this.dirtyBound()}},traverse:function(a){for(var c=0,e=this.children.length;c<e;c++)this.children[c].accept(a)},
ascend:function(a){for(var c=0,e=this.parents.length;c<e;c++)this.parents[c].accept(a)},getBound:function(){if(!this.boundingSphereComputed){this.computeBound(this.boundingSphere);this.boundingSphereComputed=!0}return this.boundingSphere},computeBound:function(a){var c=new osg.BoundingBox;c.init();a.init();for(var e=0,f=this.children.length;e<f;e++){var g=this.children[e];(g.referenceFrame===undefined||g.referenceFrame===osg.Transform.RELATIVE_RF)&&c.expandBySphere(g.getBound())}if(!c.valid())return a;
a._center=c.center();c=a._radius=0;for(e=this.children.length;c<e;c++){f=this.children[c];(f.referenceFrame===undefined||f.referenceFrame===osg.Transform.RELATIVE_RF)&&a.expandRadiusBySphere(f.getBound())}return a},getWorldMatrices:function(a){var c=function(h){this.nodePaths=[];this.halt=h;osg.NodeVisitor.call(this,osg.NodeVisitor.TRAVERSE_PARENTS)};c.prototype=osg.objectInehrit(osg.NodeVisitor.prototype,{apply:function(h){h.parents.length===0||h===this.halt?this.nodePaths.push(this.nodePath.slice(0)):
this.traverse(h)}});a=new c(a);this.accept(a);c=[];for(var e=0,f=a.nodePaths.length;e<f;e++){var g=a.nodePaths[e];g.length===0?c.push(osg.Matrix.makeIdentity()):c.push(osg.computeLocalToWorld(g))}return c}};osg.Node.prototype.objectType=osg.objectType.generate("Node");osg.NodeVisitor=function(a){this.traversalMask=-1;this.nodeMaskOverride=0;this.traversalMode=a;if(a===undefined)this.traversalMode=osg.NodeVisitor.TRAVERSE_ALL_CHILDREN;this.nodePath=[]};osg.NodeVisitor.TRAVERSE_PARENTS=1;
osg.NodeVisitor.TRAVERSE_ALL_CHILDREN=2;osg.NodeVisitor._traversalFunctions={};osg.NodeVisitor._traversalFunctions[osg.NodeVisitor.TRAVERSE_PARENTS]=function(a){a.ascend(this)};osg.NodeVisitor._traversalFunctions[osg.NodeVisitor.TRAVERSE_ALL_CHILDREN]=function(a){a.traverse(this)};osg.NodeVisitor._pushOntoNodePath={};osg.NodeVisitor._pushOntoNodePath[osg.NodeVisitor.TRAVERSE_PARENTS]=function(a){this.nodePath.unshift(a)};osg.NodeVisitor._pushOntoNodePath[osg.NodeVisitor.TRAVERSE_ALL_CHILDREN]=function(a){this.nodePath.push(a)};
osg.NodeVisitor._popFromNodePath={};osg.NodeVisitor._popFromNodePath[osg.NodeVisitor.TRAVERSE_PARENTS]=function(){return this.nodePath.shift()};osg.NodeVisitor._popFromNodePath[osg.NodeVisitor.TRAVERSE_ALL_CHILDREN]=function(){this.nodePath.pop()};
osg.NodeVisitor.prototype={setTraversalMask:function(a){this.traversalMask=a},getTraversalMask:function(){return this.traversalMask},pushOntoNodePath:function(a){osg.NodeVisitor._pushOntoNodePath[this.traversalMode].call(this,a)},popFromNodePath:function(){osg.NodeVisitor._popFromNodePath[this.traversalMode].call(this)},validNodeMask:function(a){return(this.traversalMask&(this.nodeMaskOverride|a.getNodeMask()))!==0},apply:function(a){this.traverse(a)},traverse:function(a){osg.NodeVisitor._traversalFunctions[this.traversalMode].call(this,
a)}};osg.Transform=function(){osg.Node.call(this);this.referenceFrame=osg.Transform.RELATIVE_RF};osg.Transform.RELATIVE_RF=0;osg.Transform.ABSOLUTE_RF=1;
osg.Transform.prototype=osg.objectInehrit(osg.Node.prototype,{setReferenceFrame:function(a){this.referenceFrame=a},getReferenceFrame:function(){return this.referenceFrame},computeBound:function(a){osg.Node.prototype.computeBound.call(this,a);if(!a.valid())return a;var c=osg.Matrix.makeIdentity();this.computeLocalToWorldMatrix(c);var e=osg.Vec3.copy(a._center,[]);e[0]+=a._radius;osg.Matrix.transformVec3(c,e,e);var f=osg.Vec3.copy(a._center,[]);f[1]+=a._radius;osg.Matrix.transformVec3(c,f,f);var g=
osg.Vec3.copy(a._center,[]);g[2]+=a._radius;osg.Matrix.transformVec3(c,g,g);osg.Matrix.transformVec3(c,a._center,a._center);osg.Vec3.sub(e,a._center,e);c=osg.Vec3.length(e);osg.Vec3.sub(f,a._center,f);f=osg.Vec3.length(f);osg.Vec3.sub(g,a._center,g);g=osg.Vec3.length(g);a._radius=c;if(a._radius<f)a._radius=f;if(a._radius<g)a._radius=g;return a}});
osg.computeLocalToWorld=function(a,c){var e=c;e===undefined&&(e=!0);var f=osg.Matrix.makeIdentity(),g=0;if(e)for(g=a.length-1;g>0;g--){e=a[g];if(e.objectType===osg.Camera.prototype.objectType&&(e.getReferenceFrame!==osg.Transform.RELATIVE_RF||e.getParents().length===0))break}for(e=a.length;g<e;g++){var h=a[g];h.computeLocalToWorldMatrix&&h.computeLocalToWorldMatrix(f)}return f};
osg.BlendFunc=function(a,c){osg.StateAttribute.call(this);this.sourceFactor="ONE";this.destinationFactor="ZERO";if(a!==undefined)this.sourceFactor=a;if(c!==undefined)this.destinationFactor=c};osg.BlendFunc.prototype=osg.objectInehrit(osg.StateAttribute.prototype,{attributeType:"BlendFunc",cloneType:function(){return new osg.BlendFunc},getType:function(){return this.attributeType},getTypeMember:function(){return this.attributeType},apply:function(){gl.blendFunc(gl[this.sourceFactor],gl[this.destinationFactor])}});
osg.BoundingBox=function(){this._min=[1,1,1];this._max=[0,0,0]};
osg.BoundingBox.prototype={init:function(){this._min=[1,1,1];this._max=[0,0,0]},valid:function(){return this._max[0]>=this._min[0]&&this._max[1]>=this._min[1]&&this._max[2]>=this._min[2]},expandBySphere:function(a){if(a.valid()){a._center[0]-a._radius<this._min[0]&&(this._min[0]=a._center[0]-a._radius);a._center[0]+a._radius>this._max[0]&&(this._max[0]=a._center[0]+a._radius);a._center[1]-a._radius<this._min[1]&&(this._min[1]=a._center[1]-a._radius);a._center[1]+a._radius>this._max[1]&&(this._max[1]=
a._center[1]+a._radius);a._center[2]-a._radius<this._min[2]&&(this._min[2]=a._center[2]-a._radius);a._center[2]+a._radius>this._max[2]&&(this._max[2]=a._center[2]+a._radius)}},expandByVec3:function(a){if(this.valid()){this._min[0]>a[0]&&(this._min[0]=a[0]);this._min[1]>a[1]&&(this._min[1]=a[1]);this._min[2]>a[2]&&(this._min[2]=a[2]);this._max[0]<a[0]&&(this._max[0]=a[0]);this._max[1]<a[1]&&(this._max[1]=a[1]);this._max[2]<a[2]&&(this._max[2]=a[2])}else{this._min[0]=a[0];this._min[1]=a[1];this._min[2]=
a[2];this._max[0]=a[0];this._max[1]=a[1];this._max[2]=a[2]}},center:function(){return osg.Vec3.mult(osg.Vec3.add(this._min,this._max,[]),0.5,[])},radius:function(){return Math.sqrt(this.radius2())},radius2:function(){return 0.25*osg.Vec3.length2(osg.Vec3.sub(this._max,this._min,[]))},corner:function(a){ret=[0,0,0];ret[0]=a&1?this._max[0]:this._min[0];ret[1]=a&2?this._max[1]:this._min[1];ret[2]=a&4?this._max[2]:this._min[2];return ret}};
osg.BoundingSphere=function(){this._center=[0,0,0];this._radius=-1};
osg.BoundingSphere.prototype={init:function(){this._center=[0,0,0];this._radius=-1},valid:function(){return this._radius>=0},set:function(a,c){this._center=a;this._radius=c},center:function(){return this._center},radius:function(){return this._radius},radius2:function(){return this._radius*this._radius},expandByBox:function(a){if(a.valid()){var c;if(this.valid()){var e=new osg.BoundingBox;e._min[0]=a._min[0];e._min[1]=a._min[1];e._min[2]=a._min[2];e._max[0]=a._max[0];e._max[1]=a._max[1];e._max[2]=
a._max[2];for(var f=0;f<8;f++){var g=osg.Vec3.sub(a.corner(c),this._center,[]);osg.Vec3.normalize(g,g);nv[0]*=-this._radius;nv[1]*=-this._radius;nv[2]*=-this._radius;nv[0]+=this._center[0];nv[1]+=this._center[1];nv[2]+=this._center[2];e.expandBy(nv)}c=e.center();this._center[0]=c[0];this._center[1]=c[1];this._center[2]=c[2];this._radius=e.radius()}else{c=a.center();this._center[0]=c[0];this._center[1]=c[1];this._center[2]=c[2];this._radius=a.radius()}}},expandByVec3:function(a){if(this.valid()){a=
osg.Vec3.sub(a,this.center(),[]);r=osg.Vec3.length(a);if(r>this.radius()){dr=(r-this.radius())*0.5;this._center[0]+=a[0]*(dr/r);this._center[1]+=a[1]*(dr/r);this._center[2]+=a[2]*(dr/r);this._radius+=dr}}else{this._center[0]=a[0];this._center[1]=a[1];this._center[2]=a[2];this._radius=0}},expandRadiusBySphere:function(a){if(a.valid())if(this.valid()){var c=osg.Vec3.sub,e=osg.Vec3.length;a=e(c(a._center,this._center,[]))+a._radius;if(a>this._radius)this._radius=a}else{this._center=osg.Vec3.copy(a._center,
[]);this._radius=a._radius}},expandBy:function(a){if(a.valid())if(this.valid()){var c=osg.Vec3.sub(this.center(),a.center(),[]);d=osg.Vec3.length(c);if(!(d+a.radius()<=this.radius()))if(d+this.radius()<=a.radius()){this._center[0]=a._center[0];this._center[1]=a._center[1];this._center[2]=a._center[2];this._radius=a._radius}else{new_radius=(this.radius()+d+a.radius())*0.5;ratio=(new_radius-this.radius())/d;this._center[0]+=(a._center[0]-this._center[0])*ratio;this._center[1]+=(a._center[1]-this._center[1])*
ratio;this._center[2]+=(a._center[2]-this._center[2])*ratio;this._radius=new_radius}}else{this._center[0]=a._center[0];this._center[1]=a._center[1];this._center[2]=a._center[2];this._radius=a.radius()}},contains:function(a){a=osg.Vec3.sub(a,this.center(),[]);return valid()&&osg.Vec3.length2(a)<=radius2()},intersects:function(a){var c=osg.Vec3.length2(osg.Vec3.sub(this.center(),a.center(),[]));return valid()&&a.valid()&&c<=(this.radius()+a.radius())*(this.radius()+a.radius())}};
osg.BufferArray=function(a,c,e){if(osg.BufferArray.instanceID===undefined)osg.BufferArray.instanceID=0;this.instanceID=osg.BufferArray.instanceID;osg.BufferArray.instanceID+=1;this.dirty();this.itemSize=e;this.type=a;this.elements=this.type===gl.ELEMENT_ARRAY_BUFFER?new osg.Uint16Array(c):new osg.Float32Array(c)};
osg.BufferArray.prototype={init:function(){if(!this.buffer&&this.elements.length>0){this.buffer=gl.createBuffer();this.buffer.itemSize=this.itemSize;this.buffer.numItems=this.elements.length/this.itemSize}},dirty:function(){this._dirty=!0},isDirty:function(){return this._dirty},compile:function(){if(this._dirty){gl.bufferData(this.type,this.elements,gl.STATIC_DRAW);this._dirty=!1}},getElements:function(){return this.elements}};
osg.BufferArray.create=function(a,c,e){osg.log("osg.BufferArray.create is deprecated, use new osg.BufferArray with same arguments instead");return new osg.BufferArray(a,c,e)};osg.CullFace=function(a){osg.StateAttribute.call(this);this.mode="BACK";if(a!==undefined)this.mode=a};
osg.CullFace.prototype=osg.objectInehrit(osg.StateAttribute.prototype,{attributeType:"CullFace",cloneType:function(){return new osg.CullFace},getType:function(){return this.attributeType},getTypeMember:function(){return this.attributeType},apply:function(){if(this.mode==="DISABLE")gl.disable(gl.CULL_FACE);else{gl.enable(gl.CULL_FACE);gl.cullFace(gl[this.mode])}this._dirty=!1}});
osg.CullSettings=function(){this.computeNearFar=!0;this.nearFarRatio=5.0E-4;var a=[0,0,-1];this.bbCornerFar=(a[0]>=0?1:0)|(a[1]>=0?2:0)|(a[2]>=0?4:0);this.bbCornerNear=~this.bbCornerFar&7};osg.CullSettings.prototype={setCullSettings:function(a){this.computeNearFar=a.computeNearFar;this.nearFarRatio=a.nearFarRatio},setNearFarRatio:function(a){this.nearFarRatio=a},getNearFarRatio:function(){return this.nearFarRatio},setComputeNearFar:function(a){this.computeNearFar=a},getComputeNearFar:function(){return this.computeNearFar}};
osg.Camera=function(){osg.Transform.call(this);osg.CullSettings.call(this);this.viewport=undefined;this.setClearColor([0,0,0,1]);this.setClearDepth(1);this.setClearMask(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);this.setViewMatrix(osg.Matrix.makeIdentity());this.setProjectionMatrix(osg.Matrix.makeIdentity());this.renderOrder=osg.Camera.NESTED_RENDER;this.renderOrderNum=0};osg.Camera.PRE_RENDER=0;osg.Camera.NESTED_RENDER=1;osg.Camera.POST_RENDER=2;
osg.Camera.prototype=osg.objectInehrit(osg.CullSettings.prototype,osg.objectInehrit(osg.Transform.prototype,{setClearDepth:function(a){this.clearDepth=a},getClearDepth:function(){return this.clearDepth},setClearMask:function(a){this.clearMask=a},getClearMask:function(){return this.clearMask},setClearColor:function(a){this.clearColor=a},getClearColor:function(){return this.clearColor},setViewport:function(a){this.viewport=a;this.getOrCreateStateSet().setAttributeAndMode(a)},getViewport:function(){return this.viewport},
setViewMatrix:function(a){this.modelviewMatrix=a},setProjectionMatrix:function(a){this.projectionMatrix=a},setProjectionMatrixAsOrtho:function(a,c,e,f,g,h){osg.Matrix.makeOrtho(a,c,e,f,g,h,this.getProjectionMatrix())},getViewMatrix:function(){return this.modelviewMatrix},getProjectionMatrix:function(){return this.projectionMatrix},getRenderOrder:function(){return this.renderOrder},setRenderOrder:function(a,c){this.renderOrder=a;this.renderOrderNum=c},attachTexture:function(a,c,e){this.frameBufferObject&&
this.frameBufferObject.dirty();e===undefined&&(e=0);if(this.attachments===undefined)this.attachments={};this.attachments[a]={texture:c,level:e}},attachRenderBuffer:function(a,c){this.frameBufferObject&&this.frameBufferObject.dirty();if(this.attachments===undefined)this.attachments={};this.attachments[a]={format:c}},computeLocalToWorldMatrix:function(a){this.referenceFrame===osg.Transform.RELATIVE_RF&&osg.Matrix.preMult(a,this.modelviewMatrix);return!0},computeWorldToLocalMatrix:function(a){var c=
osg.Matrix.inverse(this.modelviewMatrix);this.referenceFrame===osg.Transform.RELATIVE_RF&&osg.Matrix.postMult(c,a);return!0}}));osg.Camera.prototype.objectType=osg.objectType.generate("Camera");osg.Depth=function(a,c,e,f){osg.StateAttribute.call(this);this.func="LESS";this.near=0;this.far=1;this.writeMask=!0;if(a!==undefined)this.func=a;if(c!==undefined)this.near=c;if(e!==undefined)this.far=e;if(f!==undefined)this.writeMask=e};
osg.Depth.prototype=osg.objectInehrit(osg.StateAttribute.prototype,{attributeType:"Depth",cloneType:function(){return new osg.Depth},getType:function(){return this.attributeType},getTypeMember:function(){return this.attributeType},setRange:function(a,c){this.near=a;this.far=c},setWriteMask:function(a){this.mask=a},apply:function(){if(this.func==="DISABLE")gl.disable(gl.DEPTH_TEST);else{gl.enable(gl.DEPTH_TEST);gl.depthFunc(gl[this.func]);gl.depthMask(this.writeMask);gl.depthRange(this.near,this.far)}}});
osg.WGS_84_RADIUS_EQUATOR=6378137;osg.WGS_84_RADIUS_POLAR=6356752.3142;osg.EllipsoidModel=function(){this._radiusEquator=osg.WGS_84_RADIUS_EQUATOR;this._radiusPolar=osg.WGS_84_RADIUS_POLAR;this.computeCoefficients()};
osg.EllipsoidModel.prototype={setRadiusEquator:function(){this._radiusEquator=radius;this.computeCoefficients()},getRadiusEquator:function(){return this._radiusEquator},setRadiusPolar:function(a){this._radiusPolar=a;this.computeCoefficients()},getRadiusPolar:function(){return this._radiusPolar},convertLatLongHeightToXYZ:function(a,c,e){var f=Math.sin(a);a=Math.cos(a);var g=this._radiusEquator/Math.sqrt(1-this._eccentricitySquared*f*f);return[(g+e)*a*Math.cos(c),(g+e)*a*Math.sin(c),(g*(1-this._eccentricitySquared)+
e)*f]},convertXYZToLatLongHeight:function(a,c,e){var f=Math.sqrt(a*a+c*c),g=Math.atan2(e*this._radiusEquator,f*this._radiusPolar),h=Math.sin(g);g=Math.cos(g);latitude=Math.atan((e+(this._radiusEquator*this._radiusEquator-this._radiusPolar*this._radiusPolar)/(this._radiusPolar*this._radiusPolar)*this._radiusPolar*h*h*h)/(f-this._eccentricitySquared*this._radiusEquator*g*g*g));longitude=Math.atan2(c,a);a=Math.sin(latitude);height=f/Math.cos(latitude)-this._radiusEquator/Math.sqrt(1-this._eccentricitySquared*
a*a);return[latitude,longitude,height]},computeLocalUpVector:function(a,c,e){var f,g;a=this.convertXYZToLatLongHeight(a,c,e,f,g,void 0);f=a[0];g=a[1];return[Math.cos(g)*Math.cos(f),Math.sin(g)*Math.cos(f),Math.sin(f)]},isWGS84:function(){return this._radiusEquator==osg.WGS_84_RADIUS_EQUATOR&&this._radiusPolar==osg.WGS_84_RADIUS_POLAR},computeCoefficients:function(){var a=(this._radiusEquator-this._radiusPolar)/this._radiusEquator;this._eccentricitySquared=2*a-a*a},computeLocalToWorldTransformFromLatLongHeight:function(a,
c,e){e=this.convertLatLongHeightToXYZ(a,c,e);e=osg.Matrix.makeTranslate(e[0],e[1],e[2]);this.computeCoordinateFrame(a,c,e);return e},computeLocalToWorldTransformFromXYZ:function(a,c,e){var f=this.convertXYZToLatLongHeight(a,c,e);a=osg.Matrix.makeTranslate(a,c,e);this.computeCoordinateFrame(f[0],f[1],a);return a},computeCoordinateFrame:function(a,c,e){a=[Math.cos(c)*Math.cos(a),Math.sin(c)*Math.cos(a),Math.sin(a)];c=[-Math.sin(c),Math.cos(c),0];var f=osg.Vec3.cross(a,c);osg.Matrix.set(e,0,0,c[0]);
osg.Matrix.set(e,0,1,c[1]);osg.Matrix.set(e,0,2,c[2]);osg.Matrix.set(e,1,0,f[0]);osg.Matrix.set(e,1,1,f[1]);osg.Matrix.set(e,1,2,f[2]);osg.Matrix.set(e,2,0,a[0]);osg.Matrix.set(e,2,1,a[1]);osg.Matrix.set(e,2,2,a[2])}};osg.FrameBufferObject=function(){osg.StateAttribute.call(this);this.fbo=undefined;this.attachments=[];this.dirty()};
osg.FrameBufferObject.prototype=osg.objectInehrit(osg.StateAttribute.prototype,{attributeType:"FrameBufferObject",cloneType:function(){return new osg.FrameBufferObject},getType:function(){return this.attributeType},getTypeMember:function(){return this.attributeType},setAttachment:function(a){this.attachments.push(a)},apply:function(a){if(this.attachments.length>0)if(this.isDirty()){if(!this.fbo)this.fbo=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,this.fbo);for(var c=!1,e=0,f=this.attachments.length;e<
f;++e)if(this.attachments[e].texture===undefined){c=gl.createRenderbuffer();gl.bindRenderbuffer(gl.RENDERBUFFER,c);gl.renderbufferStorage(gl.RENDERBUFFER,this.attachments[e].format,this.attachments[e].width,this.attachments[e].height);gl.framebufferRenderbuffer(gl.FRAMEBUFFER,this.attachments[e].attachment,gl.RENDERBUFFER,c);c=!0}else{var g=this.attachments[e].texture;a.applyTextureAttribute(0,g);gl.framebufferTexture2D(gl.FRAMEBUFFER,this.attachments[e].attachment,gl[g.target],g.textureObject,this.attachments[e].level)}a=
gl.checkFramebufferStatus(gl.FRAMEBUFFER);a!==36053&&osg.log("framebuffer error check "+a);c&&gl.bindRenderbuffer(null);this.setDirty(!1)}else{gl.bindFramebuffer(gl.FRAMEBUFFER,this.fbo);if(osg.reportErrorGL===!0){a=gl.checkFramebufferStatus(gl.FRAMEBUFFER);a!==36053&&osg.log("framebuffer error check "+a)}}else gl.bindFramebuffer(gl.FRAMEBUFFER,null)}});
osg.FrameStamp=function(){var a=0,c=0,e=0;this.setReferenceTime=function(f){c=f};this.setSimulationTime=function(f){e=f};this.getReferenceTime=function(){return c};this.getSimulationTime=function(){return e};this.setFrameNumber=function(f){a=f};this.getFrameNumber=function(){return a}};osg.Geometry=function(){osg.Node.call(this);this.primitives=[];this.attributes={};this.boundingBox=new osg.BoundingBox;this.boundingBoxComputed=!1;this.cacheAttributeList={}};
osg.Geometry.prototype=osg.objectInehrit(osg.Node.prototype,{dirtyBound:function(){if(this.boundingBoxComputed===!0)this.boundingBoxComputed=!1;osg.Node.dirtyBound.call(this)},dirty:function(){this.cacheAttributeList={}},getPrimitives:function(){return this.primitives},getAttributes:function(){return this.attributes},drawImplementation:function(a){var c=a.getLastProgramApplied(),e=c.instanceID;if(this.cacheAttributeList[e]===undefined){var f,g=c.attributesCache,h=[];c="//generated by Geometry::implementation\nfunction(state) {\n";
c+="state.lazyDisablingOfVertexAttributes();\n";for(var i=0,j=g.attributeKeys.length;i<j;i++){var k=g.attributeKeys[i];f=g[k];if(this.attributes[k]!==undefined){h.push(f);c+="state.setVertexAttribArray("+f+', this.attributes["'+k+'"], false);\n'}}c+="state.applyDisablingOfVertexAttributes();\n";g=this.primitives;c+="var primitives = this.primitives;\n";f=0;for(g=g.length;f<g;++f)c+="primitives["+f+"].draw(state);\n";c+="}";f=this.cacheAttributeList;eval("var drawImplementationAutogenerated = "+c+
";");f[e]=drawImplementationAutogenerated}this.cacheAttributeList[e].call(this,a)},drawImplementationDummy:function(a){a.getLastProgramApplied();a=0;for(var c=this.primitives.length;a<c;++a);},getBoundingBox:function(){if(!this.boundingBoxComputed){this.computeBoundingBox(this.boundingBox);this.boundingBoxComputed=!0}return this.boundingBox},computeBoundingBox:function(a){var c=this.getAttributes();if(c.Vertex.itemSize==3){vertexes=c.Vertex.getElements();c=0;for(var e=vertexes.length;c<e;c+=3)a.expandByVec3([vertexes[c],
vertexes[c+1],vertexes[c+2]])}return a},computeBound:function(a){a.init();var c=this.getBoundingBox();a.expandByBox(c);return a}});osg.Geometry.prototype.objectType=osg.objectType.generate("Geometry");
osg.Light=function(){osg.StateAttribute.call(this);this.ambient=[0.2,0.2,0.2,1];this.diffuse=[0.8,0.8,0.8,1];this.specular=[0,0,0,1];this.direction=[0,0,1];this.quadratic_attenuation=this.linear_attenuation=this.constant_attenuation=1;this.enabled=this.light_unit=0;this.ambient=[1,1,1,1];this.diffuse=[1,1,1,1];this.specular=[1,1,1,1];this._dirty=!0};
osg.Light.prototype=osg.objectInehrit(osg.StateAttribute.prototype,{attributeType:"Light",cloneType:function(){return new osg.Light},getType:function(){return this.attributeType},getTypeMember:function(){return this.attributeType+this.light_unit},getOrCreateUniforms:function(){if(osg.Light.uniforms===undefined)osg.Light.uniforms={};if(osg.Light.uniforms[this.getTypeMember()]===undefined){osg.Light.uniforms[this.getTypeMember()]={ambient:osg.Uniform.createFloat4([0.2,0.2,0.2,1],this.getParameterName("ambient")),
diffuse:osg.Uniform.createFloat4([0.8,0.8,0.8,1],this.getParameterName("diffuse")),specular:osg.Uniform.createFloat4([0.2,0.2,0.2,1],this.getParameterName("specular")),direction:osg.Uniform.createFloat3([0,0,1],this.getParameterName("direction")),constant_attenuation:osg.Uniform.createFloat1(0,this.getParameterName("constant_attenuation")),linear_attenuation:osg.Uniform.createFloat1(0,this.getParameterName("linear_attenuation")),quadratic_attenuation:osg.Uniform.createFloat1(0,this.getParameterName("quadratic_attenuation")),
enable:osg.Uniform.createInt1(0,this.getParameterName("enable")),matrix:osg.Uniform.createMatrix4(osg.Matrix.makeIdentity(),this.getParameterName("matrix"))};var a=[],c;for(c in osg.Light.uniforms[this.getTypeMember()])a.push(c);osg.Light.uniforms[this.getTypeMember()].uniformKeys=a}return osg.Light.uniforms[this.getTypeMember()]},getPrefix:function(){return this.getType()+this.light_unit},getParameterName:function(a){return this.getPrefix()+"_"+a},applyPositionedUniform:function(a){this.getOrCreateUniforms().matrix.set(a)},
apply:function(){var a=this.getOrCreateUniforms();a.ambient.set(this.ambient);a.diffuse.set(this.diffuse);a.specular.set(this.specular);a.direction.set(this.direction);a.constant_attenuation.set([this.constant_attenuation]);a.linear_attenuation.set([this.linear_attenuation]);a.quadratic_attenuation.set([this.quadratic_attenuation]);a.enable.set([this.enable]);this._dirty=!1},writeShaderInstance:function(a){var c="";switch(a){case osg.ShaderGeneratorType.VertexInit:c="\nvarying vec4 LightColor;\nvec3 EyeVector;\nvec3 NormalComputed;\n\n";
break;case osg.ShaderGeneratorType.VertexFunction:c="\nvec3 computeNormal() {\n   return vec3(NormalMatrix * vec4(Normal, 0.0));\n}\n\nvec3 computeEyeDirection() {\n   return vec3(ModelViewMatrix * vec4(Vertex,1.0));\n}\n\nvoid directionalLight(in vec3 lightDirection, in vec3 lightHalfVector, in float constantAttenuation, in float linearAttenuation, in float quadraticAttenuation, in vec4 ambient, in vec4 diffuse,in vec4 specular, in vec3 normal)\n{\n   float nDotVP;         // normal . light direction\n   float nDotHV;         // normal . light half vector\n   float pf;             // power factor\n\n   nDotVP = max(0.0, dot(normal, normalize(lightDirection)));\n   nDotHV = max(0.0, dot(normal, lightHalfVector));\n\n   if (nDotHV == 0.0)\n   {\n       pf = 0.0;\n   }\n   else\n   {\n       pf = pow(nDotHV, MaterialShininess);\n   }\n   Ambient  += ambient;\n   Diffuse  += diffuse * nDotVP;\n   Specular += specular * pf;\n}\n\nvoid flight(in vec3 lightDirection, in float constantAttenuation, in float linearAttenuation, in float quadraticAttenuation, in vec4 ambient, in vec4 diffuse, in vec4 specular, in vec3 normal)\n{\n    vec4 localColor;\n    vec3 lightHalfVector = normalize(EyeVector-lightDirection);\n    // Clear the light intensity accumulators\n    Ambient  = vec4 (0.0);\n    Diffuse  = vec4 (0.0);\n    Specular = vec4 (0.0);\n\n    directionalLight(lightDirection, lightHalfVector, constantAttenuation, linearAttenuation, quadraticAttenuation, ambient, diffuse, specular, normal);\n\n    vec4 sceneColor = vec4(0,0,0,0);\n    localColor = sceneColor +\n      MaterialEmission +\n      Ambient  * MaterialAmbient +\n      Diffuse  * MaterialDiffuse;\n      //Specular * MaterialSpecular;\n    localColor = clamp( localColor, 0.0, 1.0 );\n    LightColor += localColor;\n\n}";
break;case osg.ShaderGeneratorType.VertexMain:c="\nEyeVector = computeEyeDirection();\nNormalComputed = computeNormal();\nLightColor = vec4(0,0,0,0);\n";break;case osg.ShaderGeneratorType.FragmentInit:c="varying vec4 LightColor;\n";break;case osg.ShaderGeneratorType.FragmentMain:c="\nfragColor *= LightColor;"}return c},writeToShader:function(a){var c="";switch(a){case osg.ShaderGeneratorType.VertexInit:c=["","uniform bool "+this.getParameterName("enabled")+";","uniform vec4 "+this.getParameterName("ambient")+
";","uniform vec4 "+this.getParameterName("diffuse")+";","uniform vec4 "+this.getParameterName("specular")+";","uniform vec3 "+this.getParameterName("direction")+";","uniform float "+this.getParameterName("constantAttenuation")+";","uniform float "+this.getParameterName("linearAttenuation")+";","uniform float "+this.getParameterName("quadraticAttenuation")+";","\n"].join("\n");break;case osg.ShaderGeneratorType.VertexMain:a=this.getParameterName("direction");c=this.getParameterName("directionNormalized");
var e=this.getParameterName("NdotL");c=["","//if ("+this.getParameterName("enabled")+") {","if (true) {","  vec3 "+c+" = normalize("+a+");","  float "+e+" = max(dot(Normal, "+c+"), 0.0);","  flight("+c+", "+this.getParameterName("constantAttenuation")+", "+this.getParameterName("linearAttenuation")+", "+this.getParameterName("quadraticAttenuation")+", "+this.getParameterName("ambient")+", "+this.getParameterName("diffuse")+", "+this.getParameterName("specular")+", NormalComputed );","}\n"].join("\n")}return c}});
osg.LineWidth=function(a){osg.StateAttribute.call(this);this.lineWidth=1;if(a!==undefined)this.lineWidth=a};osg.LineWidth.prototype=osg.objectInehrit(osg.StateAttribute.prototype,{attributeType:"LineWidth",cloneType:function(){return new osg.LineWidth},getType:function(){return this.attributeType},getTypeMember:function(){return this.attributeType},apply:function(){gl.lineWidth(this.lineWidth)}});
osg.Material=function(){osg.StateAttribute.call(this);this.ambient=[0.2,0.2,0.2,1];this.diffuse=[0.8,0.8,0.8,1];this.specular=[0,0,0,1];this.emission=[0,0,0,1];this.shininess=[0];this._dirty=!0};
osg.Material.prototype=osg.objectInehrit(osg.StateAttribute.prototype,{setAmbient:function(a){this.ambient=a;this._dirty=!0},setSpecular:function(a){this.specular=a;this._dirty=!0},setDiffuse:function(a){this.diffuse=a;this._dirty=!0},attributeType:"Material",cloneType:function(){return new osg.Material},getType:function(){return this.attributeType},getTypeMember:function(){return this.attributeType},getOrCreateUniforms:function(){if(osg.Material.uniforms===undefined){osg.Material.uniforms={ambient:osg.Uniform.createFloat4([0,
0,0,0],"MaterialAmbient"),diffuse:osg.Uniform.createFloat4([0,0,0,0],"MaterialDiffuse"),specular:osg.Uniform.createFloat4([0,0,0,0],"MaterialSpecular"),emission:osg.Uniform.createFloat4([0,0,0,0],"MaterialEmission"),shininess:osg.Uniform.createFloat1([0],"MaterialShininess")};var a=[],c;for(c in osg.Material.uniforms)a.push(c);osg.Material.uniforms.uniformKeys=a}return osg.Material.uniforms},apply:function(){var a=this.getOrCreateUniforms();a.ambient.set(this.ambient);a.diffuse.set(this.diffuse);
a.specular.set(this.specular);a.emission.set(this.emission);a.shininess.set(this.shininess);this._dirty=!1},writeToShader:function(a){var c="";switch(a){case osg.ShaderGeneratorType.VertexInit:c="uniform vec4 MaterialAmbient;\nuniform vec4 MaterialDiffuse;\nuniform vec4 MaterialSpecular;\nuniform vec4 MaterialEmission;\nuniform float MaterialShininess;\nvec4 Ambient;\nvec4 Diffuse;\nvec4 Specular;\n"}return c}});osg.MatrixTransform=function(){osg.Transform.call(this);this.matrix=osg.Matrix.makeIdentity()};
osg.MatrixTransform.prototype=osg.objectInehrit(osg.Transform.prototype,{getMatrix:function(){return this.matrix},setMatrix:function(a){this.matrix=a},computeLocalToWorldMatrix:function(a){this.referenceFrame===osg.Transform.RELATIVE_RF&&osg.Matrix.preMult(a,this.matrix);return!0},computeWorldToLocalMatrix:function(a){var c=osg.Matrix.inverse(this.matrix);this.referenceFrame===osg.Transform.RELATIVE_RF&&osg.Matrix.postMult(c,a);return!0}});osg.MatrixTransform.prototype.objectType=osg.objectType.generate("MatrixTransform");
osg.DrawArrays=function(a,c,e){this.mode=a;this.first=c;this.count=e};osg.DrawArrays.prototype={draw:function(){gl.drawArrays(this.mode,this.first,this.count)},getMode:function(){return this.mode},getCount:function(){return this.count},getFirst:function(){return this.first}};osg.DrawArrays.create=function(a,c,e){osg.log("osg.DrawArrays.create is deprecated, use new osg.DrawArrays with same arguments");return new osg.DrawArray(a,c,e)};
osg.DrawElements=function(a,c){this.mode=gl.POINTS;if(a!==undefined)this.mode=a;this.offset=this.count=0;this.indices=c;if(c!==undefined)this.count=c.elements.length};
osg.DrawElements.prototype={getMode:function(){return this.mode},draw:function(a){a.setIndexArray(this.indices);gl.drawElements(this.mode,this.count,gl.UNSIGNED_SHORT,this.offset)},getIndices:function(){return this.indices},setFirst:function(a){this.offset=a},getFirst:function(){return this.offset},setCount:function(a){this.count=a},getCount:function(){return this.count}};
osg.DrawElements.create=function(a,c){osg.log("osg.DrawElements.create is deprecated, use new osg.DrawElements with same arguments");return new osg.DrawElements(a,c)};osg.Program=function(a,c){if(osg.Program.instanceID===undefined)osg.Program.instanceID=0;this.instanceID=osg.Program.instanceID;this._dirty=!0;osg.Program.instanceID+=1;this.program=null;this.vertex=a;this.fragment=c;this.dirty=!0};
osg.Program.prototype={isDirty:function(){return this._dirty},attributeType:"Program",cloneType:function(){var a=new osg.Program;a.default_program=!0;return a},getType:function(){return this.attributeType},getTypeMember:function(){return this.attributeType},setVertexShader:function(a){program.vertex=a},setFragmentShader:function(a){program.fragment=a},apply:function(){if(!this.program||this._dirty){if(this.default_program===!0)return;this.vertex.shader||this.vertex.compile();this.fragment.shader||
this.fragment.compile();this.program=gl.createProgram();gl.attachShader(this.program,this.vertex.shader);gl.attachShader(this.program,this.fragment.shader);gl.linkProgram(this.program);gl.validateProgram(this.program);if(!gl.getProgramParameter(this.program,gl.LINK_STATUS)){osg.log("can't link program\nvertex shader:\n"+this.vertex.text+"\n fragment shader:\n"+this.fragment.text);osg.log(gl.getProgramInfoLog(this.program));debugger;return null}this.uniformsCache={};this.uniformsCache.uniformKeys=
[];this.attributesCache={};this.attributesCache.attributeKeys=[];this.cacheUniformList(this.vertex.text);this.cacheUniformList(this.fragment.text);this.cacheAttributeList(this.vertex.text);this._dirty=!1}gl.useProgram(this.program)},cacheUniformList:function(a){a=a.match(/uniform\s+\w+\s+\w+/g);if(a!==null)for(var c in a){var e=a[c].match(/uniform\s+\w+\s+(\w+)/)[1],f=gl.getUniformLocation(this.program,e);if(f!==undefined&&f!==null&&this.uniformsCache[e]===undefined){this.uniformsCache[e]=f;this.uniformsCache.uniformKeys.push(e)}}},
cacheAttributeList:function(a){a=a.match(/attribute\s+\w+\s+\w+/g);if(a!==null)for(var c in a){var e=a[c].match(/attribute\s+\w+\s+(\w+)/)[1],f=gl.getAttribLocation(this.program,e);if(f!==-1&&f!==undefined&&this.attributesCache[e]===undefined){this.attributesCache[e]=f;this.attributesCache.attributeKeys.push(e)}}}};osg.Program.create=function(a,c){console.log("osg.Program.create is deprecated use new osg.Program(vertex, fragment) instead");return new osg.Program(a,c)};
osg.Projection=function(){osg.Node.call(this);this.projection=osg.Matrix.makeIdentity()};osg.Projection.prototype=osg.objectInehrit(osg.Node.prototype,{getProjectionMatrix:function(){return this.projection},setProjectionMatrix:function(a){this.projection=a}});osg.Projection.prototype.objectType=osg.objectType.generate("Projection");
osg.Quat={makeIdentity:function(a){return osg.Quat.init(a)},init:function(a){a===undefined&&(a=[]);a[0]=0;a[1]=0;a[2]=0;a[3]=1;return a},sub:function(a,c,e){e===undefined&&(e=[]);e[0]=a[0]-c[0];e[1]=a[1]-c[1];e[2]=a[2]-c[2];e[3]=a[3]-c[3];return e},add:function(a,c,e){e===undefined&&(e=[]);e[0]=a[0]+c[0];e[1]=a[1]+c[1];e[2]=a[2]+c[2];e[3]=a[3]+c[3];return e},dot:function(a,c){return a[0]*c[0]+a[1]*c[1]+a[2]*c[2]+a[3]*c[3]},length2:function(a){return a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3]},neg:function(a,
c){c===undefined&&(c=[]);c[0]=-a[0];c[1]=-a[1];c[2]=-a[2];c[3]=-a[3];return c},makeRotate:function(a,c,e,f,g){var h=Math.sqrt(c*c+e*e+f*f);if(h<1.0E-7)return this.init();h=1/h;var i=Math.cos(0.5*a);a=Math.sin(0.5*a);g===undefined&&(g=[]);g[0]=c*a*h;g[1]=e*a*h;g[2]=f*a*h;g[3]=i;return g},lerp:function(a,c,e,f){f===undefined&&(f=[]);e=1-a;f[0]=c[0]*e+quatTo[0]*a;f[1]=c[1]*e+quatTo[1]*a;f[2]=c[2]*e+quatTo[2]*a;f[3]=c[3]*e+quatTo[3]*a;return f},slerp:function(a,c,e,f){var g=e,h=this.dot(c,g);if(h<0){h=
-h;g=this.neg(e)}var i;if(1-h>1.0E-5){h=Math.acos(h);i=Math.sin(h);e=Math.sin((1-a)*h)/i;a=Math.sin(a*h)/i}else e=1-a;f===undefined&&(f=[]);f[0]=c[0]*e+g[0]*a;f[1]=c[1]*e+g[1]*a;f[2]=c[2]*e+g[2]*a;f[3]=c[3]*e+g[3]*a;return f},conj:function(a,c){c===undefined&&(c=[]);c[0]=-a[0];c[1]=-a[1];c[2]=-a[2];c[3]=a[3];return c},inverse:function(a,c){c===undefined&&(c=[]);var e=1/this.length2(a);this.conj(a,c);c[0]*=e;c[1]*=e;c[2]*=e;c[3]*=e;return c},mult:function(a,c,e){e===undefined&&(e=[]);e[0]=a[0]*c[3]+
a[1]*c[2]-a[2]*c[1]+a[3]*c[0];e[1]=-a[0]*c[2]+a[1]*c[3]+a[2]*c[0]+a[3]*c[1];e[2]=a[0]*c[1]-a[1]*c[0]+a[2]*c[3]+a[3]*c[2];e[3]=-a[0]*c[0]-a[1]*c[1]-a[2]*c[2]+a[3]*c[3];return e},div:function(a,c,e){e===undefined&&(e=[]);c=1/c;e[0]=a[0]*c;e[1]=a[1]*c;e[2]=a[2]*c;e[3]=a[3]*c;return e},exp:function(a,c){var e=Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]),f=Math.exp(a[3]),g=0;e>1.0E-5&&(g=f*Math.sin(e)/e);c===undefined&&(c=[]);c[0]=g*a[0];c[1]=g*a[1];c[2]=g*a[2];c[3]=f*Math.cos(e);return c},ln:function(a,c){var e=
a[0]*a[0]+a[1]*a[1]+a[2]*a[2],f=Math.sqrt(e),g=0;f>1.0E-5&&(g=Math.atan2(f,a[3])/f);c===undefined&&(c=[]);e+=a[3]*a[3];c[0]=g*a[0];c[1]=g*a[1];c[2]=g*a[2];c[3]=0.5*Math.log(e);return c},squad:function(a,c,e,f,g,h){c=this.slerp(a,c,g);e=this.slerp(a,e,f);return this.slerp(2*a*(1-a),c,e,h)},computeTangent:function(a,c,e,f){f===undefined&&(f=[]);c=this.inv(c);this.mult(e,c,void 0);this.ln(void 0,void 0);this.mult(a,c,void 0);this.ln(void 0,void 0);this.add(void 0,void 0,void 0);this.div(void 0,-4,void 0);
this.exp(void 0,void 0);return this.mult(void 0,q1,f)},createKey:function(a,c){if(c===undefined)c=this.init();else if(a!==c){c[0]=a[0];c[1]=a[1];c[2]=a[2];c[3]=a[3]}c.time=0;c.tangent=[];return c}};osg.RenderBin=function(a){this.leafs=[];this.stateGraph=a;this.positionedAttribute=[];this.renderStage=undefined;this.renderBin={};this.stateGraphList=[]};
osg.RenderBin.prototype={getStage:function(){return this.renderStage},addStateGraph:function(a){this.stateGraphList.push(a)},reset:function(){this.stateGraph=undefined;this.stateGraphList.length=0;this.renderBin={};this.positionedAttribute.length=0;this.leafs.length=0},applyPositionedAttribute:function(a,c){for(var e=0,f=c.length;e<f;e++){var g=c[e],h=g[1];g=g[0];a.setGlobalDefaultValue(h);h.applyPositionedUniform(g,a)}},drawImplementation:function(a,c){var e=c,f;for(f in this.renderBin)f<0&&(e=this.renderBin[f].drawImplementation(a,
e));e=this.drawLeafs(a,e);for(f in this.renderBin)f>=0&&(e=this.renderBin[f].drawImplementation(a,e));return e},drawLeafs:function(a,c){var e=this.stateGraphList,f,g,h,i=c,j=[],k=osg.Matrix;c&&osg.StateGraph.prototype.moveToRootStateGraph(a,c.parent);this.positionedAttribute&&this.applyPositionedAttribute(a,this.positionedAttribute);for(var m=0,n=e.length;m<n;m++)for(var o=e[m],q=0,s=o.leafs.length;q<s;q++){var p=o.leafs[q],t=!1;if(i!==undefined){i=i.parent;var v=i.parent,w=p.parent;if(v!==w.parent){w.moveStateGraph(a,
v,w.parent);a.pushStateSet(w.stateset);t=!0}else if(w!==i){a.pushStateSet(w.stateset);t=!0}}else{p.parent.moveStateGraph(a,undefined,p.parent.parent);a.pushStateSet(p.parent.stateset);t=!0}if(t===!0){a.apply();f=a.getLastProgramApplied();g=f.uniformsCache[a.modelViewMatrix.name];h=f.uniformsCache[a.projectionMatrix.name];f=f.uniformsCache[a.normalMatrix.name]}if(g!==undefined){a.modelViewMatrix.set(p.modelview);a.modelViewMatrix.apply(g)}if(h!==undefined){a.projectionMatrix.set(p.projection);a.projectionMatrix.apply(h)}if(f!==
undefined){k.copy(p.modelview,j);j[12]=0;j[13]=0;j[14]=0;k.inverse(j,j);k.transpose(j,j);a.normalMatrix.set(j);a.normalMatrix.apply(f)}p.geometry.drawImplementation(a);if(t===!0){a.popGeneratedProgram();a.popStateSet()}i=p}return i}};
osg.RenderStage=function(){osg.RenderBin.call(this);this.positionedAttribute=[];this.clearDepth=1;this.clearColor=[0,0,0,1];this.clearMask=gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT;this.viewport=this.camera=undefined;this.preRenderList=[];this.postRenderList=[];this.renderStage=this};
osg.RenderStage.prototype=osg.objectInehrit(osg.RenderBin.prototype,{reset:function(){osg.RenderBin.prototype.reset.call(this);this.preRenderList.length=0;this.postRenderList.length=0},setClearDepth:function(a){this.clearDepth=a},getClearDepth:function(){return this.clearDepth},setClearColor:function(a){this.clearColor=a},getClearColor:function(){return this.clearColor},setClearMask:function(a){this.clearMask=a},getClearMask:function(){return this.clearMask},setViewport:function(a){this.viewport=
a},getViewport:function(){return this.viewport},setCamera:function(a){this.camera=a},addPreRenderStage:function(a,c){for(var e=0,f=this.preRenderList.length;e<f;e++)if(c<this.preRenderList[e].order)break;if(e<this.preRenderList.length)this.preRenderList=this.preRenderList.splice(e,0,{order:c,renderStage:a});else this.preRenderList.push({order:c,renderStage:a})},addPostRenderStage:function(a,c){for(var e=0,f=this.postRenderList.length;e<f;e++)if(c<this.postRenderList[e].order)break;if(e<this.postRenderList.length)this.postRenderList=
this.postRenderList.splice(e,0,{order:c,renderStage:a});else this.postRenderList.push({order:c,renderStage:a})},drawPreRenderStages:function(a,c){for(var e=c,f=0,g=this.preRenderList.length;f<g;++f)e=this.preRenderList[f].renderStage.draw(a,e);return e},draw:function(a,c){var e=this.drawPreRenderStages(a,c);e=this.drawImplementation(a,e);return e=this.drawPostRenderStages(a,e)},drawPostRenderStages:function(a,c){for(var e=c,f=0,g=this.postRenderList.length;f<g;++f)e=this.postRenderList[f].renderStage.draw(a,
e);return e},applyCamera:function(a){if(this.camera===undefined)gl.bindFramebuffer(gl.FRAMEBUFFER,null);else{var c=this.camera.getViewport(),e=this.camera.frameBufferObject;if(!e){e=new osg.FrameBufferObject;this.camera.frameBufferObject=e}if(e.isDirty()&&this.camera.attachments!==undefined)for(var f in this.camera.attachments){var g=this.camera.attachments[f],h=undefined;if(g.texture===undefined)h={attachment:f,format:g.format,width:c.width(),height:c.height()};else if(g.texture!==undefined){h={attachment:f,
texture:g.texture,level:g.level};if(g.format)h.format=g.format}e.setAttachment(h)}e.apply(a)}},drawImplementation:function(a,c){var e;if(osg.reportErrorGL===!0){e=gl.getError();osg.checkError(e)}this.applyCamera(a);this.viewport===undefined&&osg.log("RenderStage does not have a valid viewport");a.applyAttribute(this.viewport);this.clearMask&gl.COLOR_BUFFER_BIT&&gl.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]);this.clearMask&gl.DEPTH_BUFFER_BIT&&gl.clearDepth(this.clearDepth);
gl.clear(this.clearMask);this.positionedAttribute&&this.applyPositionedAttribute(a,this.positionedAttribute);var f=osg.RenderBin.prototype.drawImplementation.call(this,a,c);if(osg.reportErrorGL===!0){e=gl.getError();osg.checkError(e)}return f}});osg.ShaderGenerator=function(){this.cache=[]};
osg.ShaderGenerator.prototype={getActiveTypeMember:function(a){for(var c=[],e=0,f=a.attributeMap.attributeKeys.length;e<f;e++){var g=a.attributeMap.attributeKeys[e],h=a.attributeMap[g];h.length===0&&h.globalDefault.applyPositionedUniform===undefined||(h.globalDefault.getOrCreateUniforms!==undefined||h.globalDefault.writeToShader!==undefined)&&c.push(g)}e=0;for(f=a.textureAttributeMapList.length;e<f;e++){g=a.textureAttributeMapList[e];if(g!==undefined){h=0;for(var i=g.attributeKeys.length;h<i;h++){var j=
g.attributeKeys[h],k=g[j];k.length!==0&&(k.globalDefault.getOrCreateUniforms!==undefined||k.globalDefault.writeToShader!==undefined)&&c.push(j+e)}}}return c},getActiveAttributeMapKeys:function(a){for(var c=[],e=0,f=a.attributeMap.attributeKeys.length;e<f;e++){var g=a.attributeMap.attributeKeys[e],h=a.attributeMap[g];h.length===0&&h.globalDefault.applyPositionedUniform===undefined||(h.globalDefault.getOrCreateUniforms!==undefined||h.globalDefault.writeToShader!==undefined)&&c.push(g)}return c},getActiveTextureAttributeMapKeys:function(a){for(var c=
[],e=0,f=a.textureAttributeMapList.length;e<f;e++){var g=a.textureAttributeMapList[e];if(g!==undefined){c[e]=[];for(var h=0,i=g.attributeKeys.length;h<i;h++){var j=g.attributeKeys[h],k=g[j];k.length!==0&&(k.globalDefault.getOrCreateUniforms!==undefined||k.globalDefault.writeToShader!==undefined)&&c[e].push(j)}}}return c},getActiveUniforms:function(a,c,e){for(var f={},g=0,h=c.length;g<h;g++){var i=c[g];if(a.attributeMap[i].globalDefault.getOrCreateUniforms!==undefined){i=a.attributeMap[i].globalDefault.getOrCreateUniforms();
for(var j=0,k=i.uniformKeys.length;j<k;j++){var m=i[i.uniformKeys[j]];f[m.name]=m}}}c=0;for(g=e.length;c<g;c++){h=e[c];if(h!==undefined){i=0;for(j=h.length;i<j;i++){k=a.textureAttributeMapList[c][h[i]].globalDefault;if(k.getOrCreateUniforms!==undefined){k=k.getOrCreateUniforms(c);m=0;for(var n=k.uniformKeys.length;m<n;m++){var o=k[k.uniformKeys[m]];f[o.name]=o}}}}}a=[];for(var q in f)a.push(q);f.uniformKeys=a;return f},getOrCreateProgram:function(a){for(var c=this.getActiveTypeMember(a),e=0,f=this.cache.length;e<
f;++e)if(this.compareAttributeMap(c,this.cache[e].flattenKeys)===0)return this.cache[e];e=this.getActiveAttributeMapKeys(a);f=this.getActiveTextureAttributeMapKeys(a);var g=this.getOrCreateVertexShader(a,e,f),h=this.getOrCreateFragmentShader(a,e,f);g=new osg.Program(new osg.Shader(gl.VERTEX_SHADER,g),new osg.Shader(gl.FRAGMENT_SHADER,h));g.flattenKeys=c;g.activeAttributeKeys=e;g.activeTextureAttributeKeys=f;g.activeUniforms=this.getActiveUniforms(a,e,f);g.generated=!0;osg.log(g.vertex.text);osg.log(g.fragment.text);
this.cache.push(g);return g},compareAttributeMap:function(a,c){for(var e,f=0,g=a.length;f<g;f++){e=a[f];if(c.indexOf(e)===-1)return 1}if(c.length!==a.length)return-1;return 0},fillTextureShader:function(a,c,e){for(var f="",g={},h=0,i=c.length;h<i;h++){var j=c[h];if(j!==undefined)for(var k=a[h],m=0,n=j.length;m<n;m++){var o=j[m],q=k[o].globalDefault;if(q.writeShaderInstance!==undefined&&g[o]===undefined){f+=q.writeShaderInstance(h,e);g[o]=!0}q.writeToShader&&(f+=q.writeToShader(h,e))}}return f},fillShader:function(a,
c,e){for(var f="",g={},h=0,i=c.length;h<i;h++){var j=c[h],k=a[j].globalDefault;if(k.writeShaderInstance!==undefined&&g[j]===undefined){f+=k.writeShaderInstance(e);g[j]=!0}k.writeToShader&&(f+=k.writeToShader(e))}return f},getOrCreateVertexShader:function(a,c,e){var f=osg.ShaderGeneratorType.VertexInit,g="\n#ifdef GL_ES\nprecision highp float;\n#endif\nattribute vec3 Vertex;\nattribute vec4 Color;\nattribute vec3 Normal;\nuniform int ArrayColorEnabled;\nuniform mat4 ModelViewMatrix;\nuniform mat4 ProjectionMatrix;\nuniform mat4 NormalMatrix;\nvarying vec4 VertexColor;\n";
g+=this.fillTextureShader(a.textureAttributeMapList,e,f);g+=this.fillShader(a.attributeMap,c,f);f=osg.ShaderGeneratorType.VertexFunction;g+="\nvec4 ftransform() {\nreturn ProjectionMatrix * ModelViewMatrix * vec4(Vertex, 1.0);\n}";g+=this.fillTextureShader(a.textureAttributeMapList,e,f);g+=this.fillShader(a.attributeMap,c,f);g+="\nvoid main(void) {\ngl_Position = ftransform();\nif (ArrayColorEnabled == 1)\n  VertexColor = Color;\nelse\n  VertexColor = vec4(1.0,1.0,1.0,1.0);\n";f=osg.ShaderGeneratorType.VertexMain;
g+=this.fillTextureShader(a.textureAttributeMapList,e,f);g+=this.fillShader(a.attributeMap,c,f);g+="}\n";return g},getOrCreateFragmentShader:function(a,c,e){var f="\n#ifdef GL_ES\nprecision highp float;\n#endif\nvarying vec4 VertexColor;\nuniform int ArrayColorEnabled;\nvec4 fragColor;\n",g=osg.ShaderGeneratorType.FragmentInit;f+=this.fillTextureShader(a.textureAttributeMapList,e,g);f+=this.fillShader(a.attributeMap,c,g);f+="void main(void) {\nfragColor = VertexColor;\n";g=osg.ShaderGeneratorType.FragmentMain;
if(e.length>0){e=this.fillTextureShader(a.textureAttributeMapList,e,g);f+=e}f+=this.fillShader(a.attributeMap,c,g);f+="\ngl_FragColor = fragColor;\n}";return f}};
osg.createTexturedBox=function(a,c,e,f,g,h){var i=new osg.Geometry,j;f/=2;g/=2;j=h/2;h=[];var k=[],m=[];h[0]=a-f;h[1]=c-g;h[2]=e+j;m[0]=0;m[1]=-1;m[2]=0;k[0]=0;k[1]=1;h[3]=a-f;h[4]=c-g;h[5]=e-j;m[3]=0;m[4]=-1;m[5]=0;k[2]=0;k[3]=0;h[6]=a+f;h[7]=c-g;h[8]=e-j;m[6]=0;m[7]=-1;m[8]=0;k[4]=1;k[5]=0;h[9]=a+f;h[10]=c-g;h[11]=e+j;m[9]=0;m[10]=-1;m[11]=0;k[6]=1;k[7]=1;h[12]=a+f;h[13]=c+g;h[14]=e+j;m[12]=0;m[13]=1;m[14]=0;k[8]=0;k[9]=1;h[15]=a+f;h[16]=c+g;h[17]=e-j;m[15]=0;m[16]=1;m[17]=0;k[10]=0;k[11]=0;h[18]=
a-f;h[19]=c+g;h[20]=e-j;m[18]=0;m[19]=1;m[20]=0;k[12]=1;k[13]=0;h[21]=a-f;h[22]=c+g;h[23]=e+j;m[21]=0;m[22]=1;m[23]=0;k[14]=1;k[15]=1;h[24]=a+f;h[25]=c-g;h[26]=e+j;m[24]=1;m[25]=0;m[26]=0;k[16]=0;k[17]=1;h[27]=a+f;h[28]=c-g;h[29]=e-j;m[27]=1;m[28]=0;m[29]=0;k[18]=0;k[19]=0;h[30]=a+f;h[31]=c+g;h[32]=e-j;m[30]=1;m[31]=0;m[32]=0;k[20]=1;k[21]=0;h[33]=a+f;h[34]=c+g;h[35]=e+j;m[33]=1;m[34]=0;m[35]=0;k[22]=1;k[23]=1;h[36]=a-f;h[37]=c+g;h[38]=e+j;m[36]=-1;m[37]=0;m[38]=0;k[24]=0;k[25]=1;h[39]=a-f;h[40]=
c+g;h[41]=e-j;m[39]=-1;m[40]=0;m[41]=0;k[26]=0;k[27]=0;h[42]=a-f;h[43]=c-g;h[44]=e-j;m[42]=-1;m[43]=0;m[44]=0;k[28]=1;k[29]=0;h[45]=a-f;h[46]=c-g;h[47]=e+j;m[45]=-1;m[46]=0;m[47]=0;k[30]=1;k[31]=1;h[48]=a-f;h[49]=c+g;h[50]=e+j;m[48]=0;m[49]=0;m[50]=1;k[32]=0;k[33]=1;h[51]=a-f;h[52]=c-g;h[53]=e+j;m[51]=0;m[52]=0;m[53]=1;k[34]=0;k[35]=0;h[54]=a+f;h[55]=c-g;h[56]=e+j;m[54]=0;m[55]=0;m[56]=1;k[36]=1;k[37]=0;h[57]=a+f;h[58]=c+g;h[59]=e+j;m[57]=0;m[58]=0;m[59]=1;k[38]=1;k[39]=1;h[60]=a+f;h[61]=c+g;h[62]=
e-j;m[60]=0;m[61]=0;m[62]=-1;k[40]=0;k[41]=1;h[63]=a+f;h[64]=c-g;h[65]=e-j;m[63]=0;m[64]=0;m[65]=-1;k[42]=0;k[43]=0;h[66]=a-f;h[67]=c-g;h[68]=e-j;m[66]=0;m[67]=0;m[68]=-1;k[44]=1;k[45]=0;h[69]=a-f;h[70]=c+g;h[71]=e-j;m[69]=0;m[70]=0;m[71]=-1;k[46]=1;k[47]=1;a=[];a[0]=0;a[1]=1;a[2]=2;a[3]=0;a[4]=2;a[5]=3;a[6]=4;a[7]=5;a[8]=6;a[9]=4;a[10]=6;a[11]=7;a[12]=8;a[13]=9;a[14]=10;a[15]=8;a[16]=10;a[17]=11;a[18]=12;a[19]=13;a[20]=14;a[21]=12;a[22]=14;a[23]=15;a[24]=16;a[25]=17;a[26]=18;a[27]=16;a[28]=18;a[29]=
19;a[30]=20;a[31]=21;a[32]=22;a[33]=20;a[34]=22;a[35]=23;i.getAttributes().Vertex=new osg.BufferArray(gl.ARRAY_BUFFER,h,3);i.getAttributes().Normal=new osg.BufferArray(gl.ARRAY_BUFFER,m,3);i.getAttributes().TexCoord0=new osg.BufferArray(gl.ARRAY_BUFFER,k,2);a=new osg.DrawElements(gl.TRIANGLES,new osg.BufferArray(gl.ELEMENT_ARRAY_BUFFER,a,1));i.getPrimitives().push(a);return i};
osg.createTexturedQuad=function(a,c,e,f,g,h,i,j,k,m,n,o,q){if(o===undefined&&q===undefined){o=m;q=n;n=m=0}var s=new osg.Geometry,p=[];p[0]=a+i;p[1]=c+j;p[2]=e+k;p[3]=a;p[4]=c;p[5]=e;p[6]=a+f;p[7]=c+g;p[8]=e+h;p[9]=a+f+i;p[10]=c+g+j;p[11]=e+h+k;o===undefined&&(o=1);q===undefined&&(q=1);a=[];a[0]=m;a[1]=q;a[2]=m;a[3]=n;a[4]=o;a[5]=n;a[6]=o;a[7]=q;g=osg.Vec3.cross([f,g,h],[i,j,k],[]);f=[];f[0]=g[0];f[1]=g[1];f[2]=g[2];f[3]=g[0];f[4]=g[1];f[5]=g[2];f[6]=g[0];f[7]=g[1];f[8]=g[2];f[9]=g[0];f[10]=g[1];f[11]=
g[2];g=[];g[0]=0;g[1]=1;g[2]=2;g[3]=0;g[4]=2;g[5]=3;s.getAttributes().Vertex=new osg.BufferArray(gl.ARRAY_BUFFER,p,3);s.getAttributes().Normal=new osg.BufferArray(gl.ARRAY_BUFFER,f,3);s.getAttributes().TexCoord0=new osg.BufferArray(gl.ARRAY_BUFFER,a,2);p=new osg.DrawElements(gl.TRIANGLES,new osg.BufferArray(gl.ELEMENT_ARRAY_BUFFER,g,1));s.getPrimitives().push(p);return s};osg.Stack=function(){};
osg.Stack.create=function(){var a=[];a.globalDefault=undefined;a.lastApplied=undefined;a.back=function(){return this[this.length-1]};return a};osg.StateGraph=function(){this.depth=0;this.children={};this.children.keys=[];this.leafs=[];this.parent=this.stateset=undefined};
osg.StateGraph.prototype={clean:function(){for(var a=this.leafs.length=0,c=this.children.keys.length;a<c;a++)this.children[this.children.keys[a]].clean()},findOrInsert:function(a){var c;if(this.children[a.id])c=this.children[a.id];else{c=new osg.StateGraph;c.parent=this;c.depth=this.depth+1;c.stateset=a;this.children[a.id]=c;this.children.keys.push(a.id)}return c},moveToRootStateGraph:function(a,c){for(;c;){c.stateSet&&a.popStateSet();c=c._parent}},moveStateGraph:function(a,c,e){var f;if(!(e===c||
e===undefined))if(c===undefined){f=[];do{e.stateset!==undefined&&f.push(e.stateset);e=e.parent}while(e);f.reverse();c=0;for(l=f.length;c<l;++c)a.pushStateSet(f[c])}else if(c.parent===e.parent){c.stateset!==undefined&&a.popStateSet();e.stateset!==undefined&&a.pushStateSet(e.stateset)}else{for(;c.depth>e.depth;){c.stateset!==undefined&&a.popStateSet();c=c.parent}for(f=[];e.depth>c.depth;){e.stateset!==undefined&&f.push(e.stateset);e=e.parent}for(;c!==e;){c.stateset!==undefined&&a.popStateSet();c=c.parent;
e.stateset!==undefined&&f.push(e.stateset);e=e.parent}f.reverse();stackLength=f.length;for(c=0;c<stackLength;++c)a.pushStateSet(f[c])}}};
osg.State=function(){this.currentVBO=null;this.vertexAttribList=[];this.programs=osg.Stack.create();this.stateSets=osg.Stack.create();this.uniforms={};this.uniforms.uniformKeys=[];this.textureAttributeMapList=[];this.attributeMap={};this.attributeMap.attributeKeys=[];this.modeMap={};this.shaderGenerator=new osg.ShaderGenerator;this.modelViewMatrix=osg.Uniform.createMatrix4(osg.Matrix.makeIdentity(),"ModelViewMatrix");this.projectionMatrix=osg.Uniform.createMatrix4(osg.Matrix.makeIdentity(),"ProjectionMatrix");
this.normalMatrix=osg.Uniform.createMatrix4(osg.Matrix.makeIdentity(),"NormalMatrix");this.uniformArrayState={};this.uniformArrayState.uniformKeys=[];this.uniformArrayState.Color=osg.Uniform.createInt1(0,"ArrayColorEnabled");this.uniformArrayState.uniformKeys.push("Color");this.vertexAttribMap={};this.vertexAttribMap._disable=[];this.vertexAttribMap._keys=[]};
osg.State.prototype={pushStateSet:function(a){this.stateSets.push(a);a.attributeMap&&this.pushAttributeMap(this.attributeMap,a.attributeMap);if(a.textureAttributeMapList)for(var c=a.textureAttributeMapList,e=0,f=c.length;e<f;e++)if(c[e]!==undefined){if(!this.textureAttributeMapList[e]){this.textureAttributeMapList[e]={};this.textureAttributeMapList[e].attributeKeys=[]}this.pushAttributeMap(this.textureAttributeMapList[e],c[e])}a.uniforms&&this.pushUniformsList(this.uniforms,a.uniforms)},applyStateSet:function(a){this.pushStateSet(a);
this.apply();this.popStateSet()},popAllStateSets:function(){for(;this.stateSets.length;)this.popStateSet()},popStateSet:function(){var a=this.stateSets.pop();a.program&&this.programs.pop();a.attributeMap&&this.popAttributeMap(this.attributeMap,a.attributeMap);if(a.textureAttributeMapList)for(var c=a.textureAttributeMapList,e=0,f=c.length;e<f;e++)c[e]!==undefined&&this.popAttributeMap(this.textureAttributeMapList[e],c[e]);a.uniforms&&this.popUniformsList(this.uniforms,a.uniforms)},applyAttribute:function(a){var c=
a.getTypeMember(),e=this.attributeMap[c];if(e===undefined){e=osg.Stack.create();this.attributeMap[c]=e;this.attributeMap[c].globalDefault=a.cloneType();this.attributeMap.attributeKeys.push(c)}if(e.lastApplied!==a||a.isDirty()){a.apply&&a.apply(this);e.lastApplied=a;e.asChanged=!0}},applyTextureAttribute:function(a,c){gl.activeTexture(gl.TEXTURE0+a);var e=c.getTypeMember();if(!this.textureAttributeMapList[a]){this.textureAttributeMapList[a]={};this.textureAttributeMapList[a].attributeKeys=[]}var f=
this.textureAttributeMapList[a][e];if(f===undefined){f=osg.Stack.create();this.textureAttributeMapList[a][e]=f;f.globalDefault=c.cloneType();this.textureAttributeMapList[a].attributeKeys.push(e)}if(f.lastApplied!==c||c.isDirty()){c.apply&&c.apply(this);f.lastApplied=c;f.asChanged=!0}},getLastProgramApplied:function(){return this.programs.lastApplied},pushGeneratedProgram:function(){var a;if(this.attributeMap.Program!==undefined&&this.attributeMap.Program.length!==0){a=this.attributeMap.Program.back().object;
value=this.attributeMap.Program.back().value;if(a!==undefined&&value!==osg.StateAttribute.OFF){this.programs.push(this.getObjectPair(a,value));return a}}a=this.shaderGenerator.getOrCreateProgram({textureAttributeMapList:this.textureAttributeMapList,attributeMap:this.attributeMap});this.programs.push(this.getObjectPair(a,osg.StateAttribute.ON));return a},popGeneratedProgram:function(){this.programs.pop()},applyWithoutProgram:function(){this.applyAttributeMap(this.attributeMap);this.applyTextureAttributeMapList(this.textureAttributeMapList)},
apply:function(){this.applyAttributeMap(this.attributeMap);this.applyTextureAttributeMapList(this.textureAttributeMapList);this.pushGeneratedProgram();var a=this.programs.back().object;if(this.programs.lastApplied!==a){a.apply(this);this.programs.lastApplied=a}var c,e,f,g;if(a.generated!==undefined&&a.generated===!0){c=a.uniformsCache;e=a.activeUniforms;a=!1;f=0;for(l=e.uniformKeys.length;f<l;f++){var h=e.uniformKeys[f],i=c[h];if(i!==undefined)e[h].apply(i);else{a=!0;delete e[h]}}if(a){c=[];for(g in e)g!==
"uniformKeys"&&c.push(g);e.uniformKeys=c}}else{i=a.program;c=a.uniformsCache;h=this.uniforms;e=[];f=a.trackUniforms;var j;if(a.trackAttributes!==undefined&&f===undefined){var k=a.trackAttributes.attributeKeys;f=0;for(l=k.length;f<l;f++){g=k[f];attributeStack=this.attributeMap[g];if(attributeStack!==undefined){g=attributeStack.globalDefault;if(g.getOrCreateUniforms!==undefined){g=g.getOrCreateUniforms();j=0;for(b=g.uniformKeys.length;j<b;j++)e.push(g[g.uniformKeys[j]])}}}k=a.trackAttributes.textureAttributeKeys;
if(k!==undefined){f=0;for(l=k.length;f<l;f++){var m=k[f];if(m!==undefined)for(var n=0,o=m.length;n<o;n++){g=m[n];j=this.textureAttributeMapList[f];if(j!==undefined){attributeStack=j[g];if(attributeStack!==undefined){g=attributeStack.globalDefault;if(g.getOrCreateUniforms!==undefined){g=g.getOrCreateUniforms(f);j=0;for(b=g.uniformKeys.length;j<b;j++)e.push(g[g.uniformKeys[j]])}}}}}}g={};f=0;for(l=e.length;f<l;f++){k=e[f];m=gl.getUniformLocation(i,k.name);m!==undefined&&m!==null&&(g[k.name]=e[f])}a.trackUniforms=
g}f=0;for(l=c.uniformKeys.length;f<l;f++){g=c.uniformKeys[f];e=c[g];i=h[g];if(i===undefined){if(a.trackUniforms!==undefined){i=a.trackUniforms[g];i!==undefined&&i.apply(e)}}else{i=i.length===0?i.globalDefault:i.back().object;i.apply(e)}}}},applyUniformList:function(a,c){for(var e,f,g=this.getLastProgramApplied().uniformsCache,h=0,i=g.uniformKeys.length;h<i;h++){var j=g.uniformKeys[h];e=g[j];f=c[j];if(f===undefined){f=a[j];if(f===undefined)continue;f=f.length===0?f.globalDefault:f.back().object}f.apply(e)}},
applyAttributeMap:function(a){for(var c,e=0,f=a.attributeKeys.length;e<f;e++){c=a[a.attributeKeys[e]];if(c!==undefined){var g;g=c.length===0?c.globalDefault:c.back().object;if(c.lastApplied!==g||g.isDirty()){g.apply&&g.apply(this);c.lastApplied=g;c.asChanged=!0}}}},getObjectPair:function(a,c){return{object:a,value:c}},pushUniformsList:function(a,c){for(var e,f,g=0,h=c.uniformKeys.length;g<h;g++){uniformPair=c[c.uniformKeys[g]];f=uniformPair.object;e=f.name;if(a[e]===undefined){a[e]=osg.Stack.create();
a[e].globalDefault=f;a.uniformKeys.push(e)}e=a[e];if(e.length===0)e.push(this.getObjectPair(f,uniformPair.value));else e[e.length-1].value&osg.StateAttribute.OVERRIDE&&!(uniformPair.value&osg.StateAttribute.PROTECTED)?e.push(e[e.length-1]):e.push(this.getObjectPair(f,uniformPair.value))}},popUniformsList:function(a,c){for(var e=0,f=c.uniformKeys.length;e<f;e++)a[c.uniformKeys[e]].pop()},applyTextureAttributeMapList:function(a){for(var c,e=0,f=a.length;e<f;e++){c=a[e];if(c!==undefined)for(var g=0,
h=c.attributeKeys.length;g<h;g++){var i=c[c.attributeKeys[g]];if(i!==undefined){var j;j=i.length===0?i.globalDefault:i.back().object;if(i.lastApplied!==j||j.isDirty()){gl.activeTexture(gl.TEXTURE0+e);j.apply(this.state);i.lastApplied=j}}}}},setGlobalDefaultValue:function(a){var c=a.getTypeMember();if(this.attributeMap[c])this.attributeMap[c].globalDefault=a;else{this.attributeMap[c]=osg.Stack.create();this.attributeMap[c].globalDefault=a;this.attributeMap.attributeKeys.push(c)}},pushAttributeMap:function(a,
c){for(var e,f=0,g=c.attributeKeys.length;f<g;f++){e=c.attributeKeys[f];var h=c[e],i=h.object;if(a[e]===undefined){a[e]=osg.Stack.create();a[e].globalDefault=i.cloneType();a.attributeKeys.push(e)}e=a[e];if(e.length===0)e.push(this.getObjectPair(i,h.value));else e[e.length-1].value&osg.StateAttribute.OVERRIDE&&!(h.value&osg.StateAttribute.PROTECTED)?e.push(e[e.length-1]):e.push(this.getObjectPair(i,h.value));e.asChanged=!0}},popAttributeMap:function(a,c){for(var e,f=0,g=c.attributeKeys.length;f<g;f++){type=
c.attributeKeys[f];e=a[type];e.pop();e.asChanged=!0}},setIndexArray:function(a){if(this.currentIndexVBO!==a){a.buffer||a.init();gl.bindBuffer(a.type,a.buffer);this.currentIndexVBO=a}a.isDirty()&&a.compile()},lazyDisablingOfVertexAttributes:function(){for(var a=this.vertexAttribMap._keys,c=0,e=a.length;c<e;c++){var f=a[c];this.vertexAttribMap[f]&&(this.vertexAttribMap._disable[f]=!0)}},applyDisablingOfVertexAttributes:function(){for(var a=this.vertexAttribMap._keys,c=0,e=a.length;c<e;c++)if(this.vertexAttribMap._disable[a[c]]===
!0){var f=a[c];gl.disableVertexAttribArray(f);this.vertexAttribMap._disable[f]=!1;this.vertexAttribMap[f]=!1}a=this.programs.lastApplied;if(a.generated===!0){c=!1;if(this.previousAppliedProgram!==this.programs.lastApplied){c=!0;this.previousAppliedProgram=this.programs.lastApplied}else{e=a.attributesCache.Color;this.vertexAttribMap[e]!==this.previousColorAttrib&&(c=!0)}if(c){e=a.attributesCache.Color;if(e!==undefined){this.vertexAttribMap[e]?this.uniformArrayState.Color.set([1]):this.uniformArrayState.Color.set([0]);
this.previousColorAttrib=this.vertexAttribMap[e];this.uniformArrayState.Color.apply(a.uniformsCache.ArrayColorEnabled)}}}},setVertexAttribArray:function(a,c,e){this.vertexAttribMap._disable[a]=!1;c.buffer||c.init();if(c.isDirty()){gl.bindBuffer(c.type,c.buffer);c.compile()}if(this.vertexAttribMap[a]!==c){gl.bindBuffer(c.type,c.buffer);if(!this.vertexAttribMap[a]){gl.enableVertexAttribArray(a);this.vertexAttribMap[a]===undefined&&this.vertexAttribMap._keys.push(a)}this.vertexAttribMap[a]=c;gl.vertexAttribPointer(a,
c.itemSize,gl.FLOAT,e,0,0)}}};osg.State.create=function(){var a=new osg.State;gl.hint(gl.NICEST,gl.GENERATE_MIPMAP_HINT);return a};osg.StateSet=function(){this.id=osg.instance++};
osg.StateSet.prototype={getObjectPair:function(a,c){return{object:a,value:c}},addUniform:function(a,c){if(c===undefined)c=osg.StateAttribute.ON;if(!this.uniforms){this.uniforms={};this.uniforms.uniformKeys=[]}var e=a.name;this.uniforms[e]=this.getObjectPair(a,c);this.uniforms.uniformKeys.indexOf(e)===-1&&this.uniforms.uniformKeys.push(e)},getUniform:function(a){if(this.uniforms[a])return this.uniforms[a].object},setTextureAttributeAndMode:function(a,c,e){if(e===undefined)e=osg.StateAttribute.ON;this._setTextureAttribute(a,
this.getObjectPair(c,e))},getTextureAttribute:function(a,c){if(!(this.textureAttributeMapList[a]===undefined||this.textureAttributeMapList[a][c]===undefined))return this.textureAttributeMapList[a][c].object},setAttributeAndMode:function(a,c){if(c===undefined)c=osg.StateAttribute.ON;this._setAttribute(this.getObjectPair(a,c))},_getUniformMap:function(){return this.uniforms},_setTextureAttribute:function(a,c){if(!this.textureAttributeMapList)this.textureAttributeMapList=[];if(this.textureAttributeMapList[a]===
undefined){this.textureAttributeMapList[a]={};this.textureAttributeMapList[a].attributeKeys=[]}var e=c.object.getTypeMember();this.textureAttributeMapList[a][e]=c;this.textureAttributeMapList[a].attributeKeys.indexOf(e)===-1&&this.textureAttributeMapList[a].attributeKeys.push(e)},_setAttribute:function(a){if(!this.attributeMap){this.attributeMap={};this.attributeMap.attributeKeys=[]}var c=a.object.getTypeMember();this.attributeMap[c]=a;this.attributeMap.attributeKeys.indexOf(c)===-1&&this.attributeMap.attributeKeys.push(c)},
getAttributeMap:function(){return this.attributeMap}};osg.Texture=function(){osg.StateAttribute.call(this);this.setDefaultParameters()};
osg.Texture.prototype=osg.objectInehrit(osg.StateAttribute.prototype,{attributeType:"Texture",cloneType:function(){var a=new osg.Texture;a.default_type=!0;return a},getType:function(){return this.attributeType},getTypeMember:function(){return this.attributeType},getOrCreateUniforms:function(a){if(osg.Texture.uniforms===undefined)osg.Texture.uniforms=[];if(osg.Texture.uniforms[a]===undefined){var c=this.getType()+a,e={};e[c]=osg.Uniform.createInt1(a,c);e.uniformKeys=[c];osg.Texture.uniforms[a]=e}return osg.Texture.uniforms[a]},
setDefaultParameters:function(){this.min_filter=this.mag_filter="LINEAR";this.wrap_t=this.wrap_s="CLAMP_TO_EDGE";this.textureHeight=this.textureWidth=0;this.target="TEXTURE_2D"},setTextureSize:function(a,c){this.textureWidth=a;this.textureHeight=c},init:function(){if(!this.textureObject){this.textureObject=gl.createTexture();this._dirty=!0}},getWidth:function(){return this.textureWidth},getHeight:function(){return this.textureHeight},setWrapS:function(a){this.wrap_s=a},setWrapT:function(a){this.wrap_t=
a},setMinFilter:function(a){this.min_filter=a},setMagFilter:function(a){this.mag_filter=a},setImage:function(a){this.image=a;this._dirty=!0},setFromCanvas:function(a){this.init();gl.bindTexture(gl.TEXTURE_2D,this.textureObject);gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.UNSIGNED_BYTE,a);this.setTextureSize(a.width,a.height);this.applyFilterParameter();this._dirty=!1},isImageReady:function(){var a=this.image;if(a&&a.complete){if(typeof a.naturalWidth!=="undefined"&&a.naturalWidth===0)return!1;
return!0}return!1},applyFilterParameter:function(){gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl[this.mag_filter]);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl[this.min_filter]);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl[this.wrap_s]);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl[this.wrap_t]);(this.min_filter==="NEAREST_MIPMAP_NEAREST"||this.min_filter==="LINEAR_MIPMAP_NEAREST"||this.min_filter==="NEAREST_MIPMAP_LINEAR"||this.min_filter==="LINEAR_MIPMAP_LINEAR")&&
gl.generateMipmap(gl.TEXTURE_2D)},apply:function(){if(this.image!==undefined)if(this.textureObject)gl.bindTexture(gl.TEXTURE_2D,this.textureObject);else if(this.isImageReady()){if(!this.textureObject){this.init();this.setTextureSize(this.image.naturalWidth,this.image.naturalHeight);this._dirty=!1}gl.bindTexture(gl.TEXTURE_2D,this.textureObject);gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.UNSIGNED_BYTE,this.image);this.applyFilterParameter()}else gl.bindTexture(gl.TEXTURE_2D,null);else if(this.textureHeight!==
0&&this.textureWidth!==0)if(this.textureObject)gl.bindTexture(gl.TEXTURE_2D,this.textureObject);else{this.init();gl.bindTexture(gl.TEXTURE_2D,this.textureObject);gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,this.textureWidth,this.textureHeight,0,gl.RGBA,gl.UNSIGNED_BYTE,null);this.applyFilterParameter()}else this.textureObject!==undefined?gl.bindTexture(gl.TEXTURE_2D,this.textureObject):gl.bindTexture(gl.TEXTURE_2D,null)},setShaderGeneratorFunction:function(a,c){this[c]=a},writeToShader:function(a,c){if(this[c])return this[c].call(this,
a);return""}});osg.Texture.prototype[osg.ShaderGeneratorType.VertexInit]=function(a){var c="attribute vec2 TexCoord"+a+";\n";c+="varying vec2 FragTexCoord"+a+";\n";return c};osg.Texture.prototype[osg.ShaderGeneratorType.VertexMain]=function(a){return"FragTexCoord"+a+" = TexCoord"+a+";\n"};osg.Texture.prototype[osg.ShaderGeneratorType.FragmentInit]=function(a){var c="varying vec2 FragTexCoord"+a+";\n";c+="uniform sampler2D Texture"+a+";\n";c+="vec4 texColor"+a+";\n";return c};
osg.Texture.prototype[osg.ShaderGeneratorType.FragmentMain]=function(a){var c="texColor"+a+" = texture2D( Texture"+a+", FragTexCoord"+a+".xy );\n";c+="fragColor = fragColor * texColor"+a+";\n";return c};osg.Texture.createFromURL=function(a){var c=new osg.Texture;if(a!==undefined){var e=new Image;e.src=a;c.setImage(e)}return c};osg.Texture.createFromImg=function(a){var c=new osg.Texture;c.setImage(a);return c};osg.Texture.createFromCanvas=function(a){var c=new osg.Texture;c.setFromCanvas(a);return c};
osg.Texture.create=function(a){osg.log("osg.Texture.create is deprecated, use osg.Texture.createFromURL instead");return osg.Texture.createFromURL(a)};osg.UpdateVisitor=function(){osg.NodeVisitor.call(this);var a=new osg.FrameStamp;this.getFrameStamp=function(){return a};this.setFrameStamp=function(c){a=c}};
osg.UpdateVisitor.prototype=osg.objectInehrit(osg.NodeVisitor.prototype,{apply:function(a){if(a.getUpdateCallback!==undefined){var c=a.getUpdateCallback();if(c!==undefined){c.update(a,this);return}}a.traverse&&this.traverse(a)}});osg.View=function(){osg.Camera.call(this)};osg.View.prototype=osg.objectInehrit(osg.Camera.prototype,{computeIntersections:function(a,c,e){e===undefined&&(e=-1);var f=new osgUtil.IntersectVisitor;f.setTraversalMask(e);f.addLineSegment([a,c,0],[a,c,1]);f.apply(this);return f.hits}});
osg.Viewport=function(a,c,e,f){osg.StateAttribute.call(this);a===undefined&&(a=0);c===undefined&&(c=0);e===undefined&&(e=800);f===undefined&&(f=600);var g=a,h=c,i=e,j=f;this.x=function(){return g};this.y=function(){return h};this.width=function(){return i};this.height=function(){return j};this.computeWindowMatrix=function(){var k=osg.Matrix.makeTranslate(1,1,1),m=osg.Matrix.makeScale(0.5*i,0.5*j,0.5),n=osg.Matrix.makeTranslate(g,h,0);return osg.Matrix.preMult(n,osg.Matrix.preMult(m,k))};this._dirty=
!0};osg.Viewport.prototype=osg.objectInehrit(osg.StateAttribute.prototype,{attributeType:"Viewport",cloneType:function(){return new osg.Viewport},getType:function(){return this.attributeType},getTypeMember:function(){return this.attributeType},apply:function(){gl.viewport(this.x(),this.y(),this.width(),this.height());this._dirty=!1}});osg.CullStack=function(){this.modelviewMatrixStack=[osg.Matrix.makeIdentity()];this.projectionMatrixStack=[osg.Matrix.makeIdentity()];this.viewportStack=[]};
osg.CullStack.prototype={getViewport:function(){if(this.viewportStack.length!==0)return this.viewportStack[this.viewportStack.length-1]},getLookVectorLocal:function(){var a=this.modelviewMatrixStack[this.modelviewMatrixStack.length-1];return[-a[2],-a[6],-a[10]]},pushViewport:function(a){this.viewportStack.push(a)},popViewport:function(){this.viewportStack.pop()},pushModelviewMatrix:function(a){this.modelviewMatrixStack.push(a);a=this.getLookVectorLocal();this.bbCornerFar=(a[0]>=0?1:0)|(a[1]>=0?2:
0)|(a[2]>=0?4:0);this.bbCornerNear=~this.bbCornerFar&7},popModelviewMatrix:function(){this.modelviewMatrixStack.pop();var a;a=this.modelviewMatrixStack.length!==0?this.getLookVectorLocal():[0,0,-1];this.bbCornerFar=(a[0]>=0?1:0)|(a[1]>=0?2:0)|(a[2]>=0?4:0);this.bbCornerNear=~this.bbCornerFar&7},pushProjectionMatrix:function(a){this.projectionMatrixStack.push(a)},popProjectionMatrix:function(){this.projectionMatrixStack.pop()}};
osg.CullVisitor=function(){osg.NodeVisitor.call(this);osg.CullSettings.call(this);osg.CullStack.call(this);this.rootRenderStage=this.currentRenderStage=this.currentRenderBin=this.currentStateGraph=this.rootStateGraph=undefined;this.computeNearFar=!0;this.computedNear=Number.POSITIVE_INFINITY;this.computedFar=Number.NEGATIVE_INFINITY;var a=[0,0,-1];this.bbCornerFar=(a[0]>=0?1:0)|(a[1]>=0?2:0)|(a[2]>=0?4:0);this.bbCornerNear=~this.bbCornerFar&7;this.reserveMatrixStack=[[]];this.reserveMatrixStack.current=
0;this.reserveLeafStack=[{}];this.reserveLeafStack.current=0};
osg.CullVisitor.prototype=osg.objectInehrit(osg.CullStack.prototype,osg.objectInehrit(osg.CullSettings.prototype,osg.objectInehrit(osg.NodeVisitor.prototype,{distance:function(a,c){return-(a[0]*c[2]+a[1]*c[6]+a[2]*c[10]+c[14])},updateCalculatedNearFar:function(a,c){var e=c.getBoundingBox(),f;f=this.distance(e.corner(this.bbCornerNear),a);e=this.distance(e.corner(this.bbCornerFar),a);if(f>e){var g=f;f=e;e=g}if(e<0)return!1;if(f<this.computedNear)this.computedNear=f;if(e>this.computedFar)this.computedFar=
e;return!0},clampProjectionMatrix:function(a,c,e,f,g){if(e<c-1.0E-6){osg.log("clampProjectionMatrix not applied, invalid depth range, znear = "+c+"  zfar = "+e);return!1}var h,i;if(e<c+1.0E-6){e=(c+e)*0.5;c=e-1.0E-6;e+=1.0E-6}if(Math.abs(osg.Matrix.get(a,0,3))<1.0E-6&&Math.abs(osg.Matrix.get(a,1,3))<1.0E-6&&Math.abs(osg.Matrix.get(a,2,3))<1.0E-6){i=(e-c)*0.02;i<1&&(i=1);h=c-i;i=e+i;c=h;e=i;osg.Matrix.set(a,2,2,-2/(i-h));osg.Matrix.set(a,3,2,-(i+h)/(i-h))}else{h=c*0.98;i=e*1.02;c=e*f;h<c&&(h=c);c=
h;e=i;f=osg.Matrix.get(a,2,2);var j=osg.Matrix.get(a,3,2),k=osg.Matrix.get(a,2,3),m=osg.Matrix.get(a,3,3);h=(-h*f+j)/(-h*k+m);i=(-i*f+j)/(-i*k+m);f=Math.abs(2/(h-i));osg.Matrix.postMult([1,0,0,0,0,1,0,0,0,0,f,0,0,0,-(h+i)/2*f,1],a)}if(g!==undefined){g[0]=c;g[1]=e}return!0},setStateGraph:function(a){this.currentStateGraph=this.rootStateGraph=a},setRenderStage:function(a){this.currentRenderBin=this.rootRenderStage=a},reset:function(){this.modelviewMatrixStack.length=1;this.projectionMatrixStack.length=
1;this.reserveMatrixStack.current=0;this.reserveLeafStack.current=0},getCurrentRenderBin:function(){return this.currentRenderBin},setCurrentRenderBin:function(a){this.currentRenderBin=a},addPositionedAttribute:function(a){var c=this.modelviewMatrixStack[this.modelviewMatrixStack.length-1];this.currentRenderBin.getStage().positionedAttribute.push([c,a])},pushStateSet:function(a){this.currentStateGraph=this.currentStateGraph.findOrInsert(a)},popStateSet:function(){this.currentStateGraph=this.currentStateGraph.parent},
popProjectionMatrix:function(){this.computeNearFar===!0&&this.computedFar>=this.computedNear&&this.clampProjectionMatrix(this.projectionMatrixStack[this.projectionMatrixStack.length-1],this.computedNear,this.computedFar,this.nearFarRatio);osg.CullStack.prototype.popProjectionMatrix.call(this)},apply:function(a){this[a.objectType].call(this,a)},getReservedMatrix:function(){var a=this.reserveMatrixStack[this.reserveMatrixStack.current++];this.reserveMatrixStack.current===this.reserveMatrixStack.length&&
this.reserveMatrixStack.push(osg.Matrix.makeIdentity());return a},getReservedLeaf:function(){var a=this.reserveLeafStack[this.reserveLeafStack.current++];this.reserveLeafStack.current===this.reserveLeafStack.length&&this.reserveLeafStack.push({});return a}})));
osg.CullVisitor.prototype[osg.Camera.prototype.objectType]=function(a){var c=a.getStateSet();c&&this.pushStateSet(c);a.light&&this.addPositionedAttribute(a.light);var e=this.getReservedMatrix(),f=this.getReservedMatrix();if(a.getReferenceFrame()===osg.Transform.RELATIVE_RF){osg.Matrix.mult(this.projectionMatrixStack[this.projectionMatrixStack.length-1],a.getProjectionMatrix(),f);osg.Matrix.mult(this.modelviewMatrixStack[this.modelviewMatrixStack.length-1],a.getViewMatrix(),e)}else{osg.Matrix.copy(a.getViewMatrix(),
e);osg.Matrix.copy(a.getProjectionMatrix(),f)}this.pushProjectionMatrix(f);this.pushModelviewMatrix(e);a.getViewport()&&this.pushViewport(a.getViewport());e=this.computedNear;f=this.computedFar;var g=new osg.CullSettings;g.setCullSettings(this);this.computedNear=Number.POSITIVE_INFINITY;this.computedFar=Number.NEGATIVE_INFINITY;this.setCullSettings(a);if(a.getRenderOrder()===osg.Camera.NESTED_RENDER)a.traverse&&this.traverse(a);else{var h=this.getCurrentRenderBin().getStage(),i=new osg.RenderStage;
i.setCamera(a);i.setClearDepth(a.getClearDepth());i.setClearColor(a.getClearColor());i.setClearMask(a.getClearMask());h=a.getViewport()===undefined?h.getViewport():a.getViewport();i.setViewport(h);h=this.getCurrentRenderBin();this.setCurrentRenderBin(i);a.traverse&&a.traverse(this);this.setCurrentRenderBin(h);a.getRenderOrder()===osg.Camera.PRE_RENDER?this.getCurrentRenderBin().getStage().addPreRenderStage(i,a.renderOrderNum):this.getCurrentRenderBin().getStage().addPostRenderStage(i,a.renderOrderNum)}this.popModelviewMatrix();
this.popProjectionMatrix();a.getViewport()&&this.popViewport();this.setCullSettings(g);this.computedNear=e;this.computedFar=f;c&&this.popStateSet()};
osg.CullVisitor.prototype[osg.MatrixTransform.prototype.objectType]=function(a){var c=this.modelviewMatrixStack[this.modelviewMatrixStack.length-1],e=this.getReservedMatrix();osg.Matrix.mult(c,a.getMatrix(),e);this.pushModelviewMatrix(e);(c=a.getStateSet())&&this.pushStateSet(c);a.light&&this.addPositionedAttribute(a.light);a.traverse&&this.traverse(a);c&&this.popStateSet();this.popModelviewMatrix()};
osg.CullVisitor.prototype[osg.Projection.prototype.objectType]=function(a){lastMatrixStack=this.projectionMatrixStack[this.projectionMatrixStack.length-1];var c=this.getReservedMatrix();osg.Matrix.mult(lastMatrixStack,a.getProjectionMatrix(),c);this.pushProjectionMatrix(c);(c=a.getStateSet())&&this.pushStateSet(c);a.traverse&&this.traverse(a);c&&this.popStateSet();this.popProjectionMatrix()};
osg.CullVisitor.prototype[osg.Node.prototype.objectType]=function(a){var c=a.getStateSet();c&&this.pushStateSet(c);a.light&&this.addPositionedAttribute(a.light);a.traverse&&this.traverse(a);c&&this.popStateSet()};
osg.CullVisitor.prototype[osg.Geometry.prototype.objectType]=function(a){matrix=this.modelviewMatrixStack[this.modelviewMatrixStack.length-1];var c=a.getBoundingBox();if(!this.computeNearFar||!c.valid()||this.updateCalculatedNearFar(matrix,a)){(c=a.getStateSet())&&this.pushStateSet(c);var e=this.currentStateGraph.leafs;e.length===0&&this.currentRenderBin.addStateGraph(this.currentStateGraph);var f=this.getReservedLeaf();f.parent=this.currentStateGraph;f.modelview=this.modelviewMatrixStack[this.modelviewMatrixStack.length-
1];f.projection=this.projectionMatrixStack[this.projectionMatrixStack.length-1];f.geometry=a;e.push(f);c&&this.popStateSet()}};var osgAnimation={};osgAnimation.EaseOutQuad=function(a){return-(a*(a-2))};osgAnimation.EaseInQuad=function(a){return a*a};osgAnimation.EaseOutCubic=function(a){a-=1;return a*a*a+1};osgAnimation.EaseInCubic=function(a){return a*a*a};osgAnimation.EaseOutQuart=function(a){a-=1;return-(a*a*a*a-1)};osgAnimation.EaseInQuart=function(a){return a*a*a*a};
osgAnimation.EaseOutElastic=function(a){return Math.pow(2,-10*a)*Math.sin((a-0.075)*2*Math.PI/0.3)+1};var osgUtil={};osgUtil.TriangleHit=function(a,c,e,f,g,h,i,j){this.index=a;this.normal=c;this.r1=e;this.v1=f;this.r2=g;this.v2=h;this.r3=i;this.v3=j};osgUtil.TriangleIntersect=function(){this.hits=[];this.nodePath=[]};
osgUtil.TriangleIntersect.prototype={setNodePath:function(a){this.nodePath=a},set:function(a,c){this.start=a;this.end=c;this.dir=osg.Vec3.sub(c,a,[]);this.length=osg.Vec3.length(this.dir);osg.Vec3.mult(this.dir,1/this.length,this.dir)},apply:function(a){var c,e,f,g,h,i,j;j=this.index=0;for(l=a.primitives.length;j<l;j++){c=a.primitives[j];if(c.getIndices!==undefined){e=a.getAttributes().Vertex.getElements();var k=c.indices.getElements();switch(c.getMode()){case gl.TRIANGLES:f=c.getCount();for(c=c.getFirst();c<
f;c+=3){g=[];h=[];i=[];g[0]=e[k[c]*3];g[1]=e[k[c]*3+1];g[2]=e[k[c]*3+2];h[0]=e[k[c+1]*3];h[1]=e[k[c+1]*3+1];h[2]=e[k[c+1]*3+2];i[0]=e[k[c+2]*3];i[1]=e[k[c+2]*3+1];i[2]=e[k[c+2]*3+2];this.intersect(g,h,i)}break;case gl.TRIANGLE_STRIP:console&&console.log("TriangleIntersect does not support TRIANGLE_STRIP");break;case gl.TRIANGLE_FAN:console&&console.log("TriangleIntersect does not support TRIANGLE_FAN")}}else{e=a.getAttributes().Vertex.getElements();switch(c.getMode()){case gl.TRIANGLES:f=c.getCount();
for(c=c.getFirst();c<f;){g=[];h=[];i=[];g[0]=e[c++];g[1]=e[c++];g[2]=e[c++];h[0]=e[c++];h[1]=e[c++];h[2]=e[c++];i[0]=e[c++];i[1]=e[c++];i[2]=e[c++];this.intersect(g,h,i)}break;case gl.TRIANGLE_STRIP:console&&console.log("TriangleIntersect does not support TRIANGLE_STRIP");break;case gl.TRIANGLE_FAN:console&&console.log("TriangleIntersect does not support TRIANGLE_FAN")}}}},intersect:function(a,c,e){this.index++;if(!(a==c||c==e||a==e)){var f=osg.Vec3.sub(c,a,[]),g=osg.Vec3.cross(f,this.dir,[]),h=osg.Vec3.dot(osg.Vec3.sub(this.start,
a,[]),g),i=osg.Vec3.dot(osg.Vec3.sub(e,a,[]),g);if(i>=0){if(h<0)return;if(h>i)return}else{if(h>0)return;if(h<i)return}g=osg.Vec3.sub(e,c,[]);var j=osg.Vec3.cross(g,this.dir,[]),k=osg.Vec3.dot(osg.Vec3.sub(this.start,c,[]),j);j=osg.Vec3.dot(osg.Vec3.sub(a,c,[]),j);if(j>=0){if(k<0)return;if(k>j)return}else{if(k>0)return;if(k<j)return}var m=osg.Vec3.sub(a,e,[]),n=osg.Vec3.cross(m,this.dir,[]);m=osg.Vec3.dot(osg.Vec3.sub(this.start,e,[]),n);n=osg.Vec3.dot(osg.Vec3.sub(c,e,[]),n);if(n>=0){if(m<0)return;
if(m>n)return}else{if(m>0)return;if(m<n)return}if(h===0)h=0;else if(i!==0)h/=i;else return;if(k===0)k=0;else if(j!==0)k/=j;else return;if(m===0)i=0;else if(n!==0)i=m/n;else return;j=k+i+h;if(j!==1){if(j===0)return;j=1/j;k*=j;i*=j;h*=j}j=[];osg.Vec3.add(osg.Vec3.mult(a,k,[]),osg.Vec3.mult(c,i,[]),j);osg.Vec3.add(osg.Vec3.mult(e,h,[]),j,j);if(osg.Vec3.valid(j)){j=osg.Vec3.dot(osg.Vec3.sub(j,this.start,[]),this.dir);if(!(j<0)&&!(j>this.length)){f=osg.Vec3.cross(f,g,[]);osg.Vec3.normalize(f,f);this.hits.push({ratio:j/
this.length,nodepath:this.nodePath.slice(0),triangleHit:new osgUtil.TriangleHit(this.index-1,f,k,a,i,c,h,e)});this.hit=!0}}else{osg.log("Warning: TriangleIntersect ");osg.log("hit:     "+j);osg.log("         "+a);osg.log("         "+c);osg.log("         "+e)}}}};osgUtil.IntersectVisitor=function(){osg.NodeVisitor.call(this);this.matrix=[];this.hits=[];this.nodePath=[]};
osgUtil.IntersectVisitor.prototype=osg.objectInehrit(osg.NodeVisitor.prototype,{addLineSegment:function(a,c){this.start=a;this.end=c},intersectSegmentWithSphere:function(a,c,e){var f=osg.Vec3.sub(a,e.center);e=osg.Vec3.length2(f)-e.radius*e.radius;if(e<0)return!0;c=osg.Vec3.sub(c,a);a=osg.Vec3.length2(c);f=osg.Vec3.dot(f,c)*2;e=f*f-4*a*e;if(e<0)return!1;e=Math.sqrt(e);c=0.5*a;a=(-f-e)*c;f=(-f+e)*c;if(a<=0&&f<=0)return!1;if(a>=1&&f>=1)return!1;return!0},pushModelMatrix:function(a){if(this.matrix.length>
0){var c=osg.Matrix.copy(this.matrix[this.matrix.length-1]);osg.Matrix.preMult(c,a);this.matrix.push(c)}else this.matrix.push(a)},getModelMatrix:function(){if(this.matrix.length===0)return osg.Matrix.makeIdentity();return this.matrix[this.matrix.length-1]},popModelMatrix:function(){return this.matrix.pop()},getWindowMatrix:function(){return this.windowMatrix},getProjectionMatrix:function(){return this.projectionMatrix},getViewMatrix:function(){return this.viewMatrix},intersectSegmentWithGeometry:function(a,
c,e){ti=new osgUtil.TriangleIntersect;ti.setNodePath(this.nodePath);ti.set(a,c);ti.apply(e);a=ti.hits.length;if(a>0){for(c=0;c<a;c++)this.hits.push(ti.hits[c]);return!0}return!1},applyCamera:function(a){this.projectionMatrix=a.getProjectionMatrix();this.viewMatrix=a.getViewMatrix();var c=a.getViewport();if(c!==undefined)this.windowMatrix=c.computeWindowMatrix();this.traverse(a)},applyNode:function(a){a.getMatrix&&this.pushModelMatrix(a.getMatrix());if(a.primitives){var c=[];osg.Matrix.copy(this.getWindowMatrix(),
c);osg.Matrix.preMult(c,this.getProjectionMatrix());osg.Matrix.preMult(c,this.getViewMatrix());osg.Matrix.preMult(c,this.getModelMatrix());var e=[];if(!osg.Matrix.inverse(c,e))return;c=osg.Matrix.transformVec3(e,this.start);e=osg.Matrix.transformVec3(e,this.end);this.intersectSegmentWithGeometry(c,e,a)}a.traverse&&this.traverse(a);a.getMatrix&&this.popModelMatrix()},apply:function(a){if(this.enterNode(a)!==!1){this.nodePath.push(a);a.getViewMatrix?this.applyCamera(a):this.applyNode(a);this.nodePath.pop()}},
enterNode:function(a){if(a.boundingSphere!==undefined&&!this.intersectSegmentWithSphere)return!1;return!0}});var osgDB={};
osgDB.parseSceneGraph=function(a){var c,e=a.children;if(a.primitives||a.attributes){c=new osg.Geometry;osg.extend(c,a);a=c;for(var f in a.primitives){c=a.primitives[f].mode;if(a.primitives[f].indices){var g=a.primitives[f].indices;g=new osg.BufferArray(gl[g.type],g.elements,g.itemSize);c=c?gl[c]:gl.TRIANGLES;a.primitives[f]=new osg.DrawElements(c,g)}else{c=gl[c];a.primitives[f]=new osg.DrawArrays(c,a.primitives[f].first,a.primitives[f].count)}}for(var h in a.attributes)if(a.attributes.hasOwnProperty(h)){f=
a.attributes[h];a.attributes[h]=new osg.BufferArray(gl[f.type],f.elements,f.itemSize)}}if(a.stateset){h=new osg.StateSet;if(a.stateset.textures){f=a.stateset.textures;c=0;for(g=f.length;c<g;c++)if(f[c].file){var i=new osg.Texture;osg.extend(i,f[c]);var j=new Image;j.src=f[c].file;i.setImage(j);h.setTextureAttributeAndMode(c,i);h.addUniform(osg.Uniform.createInt1(c,"Texture"+c))}else osg.log("no texture on unit "+c+" skip it")}if(a.stateset.material){f=a.stateset.material;c=new osg.Material;osg.extend(c,
f);h.setAttributeAndMode(c)}a.stateset=h}if(a.matrix){c=new osg.MatrixTransform;osg.extend(c,a);c.setMatrix(osg.Matrix.copy(a.matrix));a=c}if(a.projection){c=new osg.Projection;osg.extend(c,a);c.setProjectionMatrix(osg.Matrix.copy(a.projection));a=c}if(a.objectType===undefined){c=new osg.Node;osg.extend(c,a);a=c}if(e){a.children=[];h=0;for(f=e.length;h<f;h++)a.addChild(osgDB.parseSceneGraph(e[h]))}return a};var osgViewer={};
WebGLUtils=function(){var a='This page requires a browser that supports WebGL.<br/><a href="http://get.webgl.org">Click here to upgrade your browser.</a>',c='It doesn\'t appear your computer can support WebGL.<br/><a href="http://get.webgl.org">Click here for more information.</a>',e=function(f,g){for(var h=["webgl","experimental-webgl","webkit-3d","moz-webgl"],i=null,j=0;j<h.length;++j){try{i=f.getContext(h[j],g)}catch(k){}if(i)break}return i};return{create3DContext:e,setupWebGL:function(f,g,h){function i(j){var k=
document.getElementsByTagName("body")[0];if(k){var m=window.WebGLRenderingContext?c:a;j&&(m+="<br/><br/>Status: "+j);k.innerHTML='<div style="margin: auto; width:500px;z-index:10000;margin-top:20em;text-align:center;">'+m+"</div>"}}h=h||i;f.addEventListener&&f.addEventListener("webglcontextcreationerror",function(j){h(j.statusMessage)},!1);(f=e(f,g))||h("");return f}}}();
if(!window.requestAnimationFrame)window.requestAnimationFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)}}();var Stats={};Stats.Stats=function(a){this.layers=[];this.last_update=undefined;this.canvas=a};
Stats.Stats.prototype={addLayer:function(a,c){a===undefined&&(a="rgb(255,255,255)");this.layers.push({previous:0,color:a,getValue:c})},update:function(){var a=(new Date).getTime();if(this.last_update===undefined)this.last_update=a;var c=(a-this.last_update)*120/1E3;if(!(c<1)){var e=this.canvas,f=e.width,g=e.height,h=e.getContext("2d");h.save();h.globalCompositeOperation="copy";h.mozImageSmoothingEnabled=!1;h.translate(-c,0);h.drawImage(e,0,0,f,g);h.restore();h.clearRect(f-c,0,c,g);for(var i=0,j=this.layers.length;i<
j;i++){var k=this.layers[i];e=this.canvas;var m=k.getValue(a);f=e.width;g=e.height;h.lineWidth=1;h.strokeStyle=k.color;h.beginPath();h.moveTo(f-c,g-k.previous);h.lineTo(f,g-m);h.stroke();k.previous=m}this.last_update=a}}};
osgViewer.Viewer=function(a,c,e){c===undefined&&(c={antialias:!0});if(gl=WebGLUtils.setupWebGL(a,c,e)){this.gl=gl;osg.init();this.canvas=a;this.frameRate=60;osgUtil.UpdateVisitor=osg.UpdateVisitor;osgUtil.CullVisitor=osg.CullVisitor;this.urlOptions=!0;this.mouseWheelEventNode=a;this.eventNode=document;if(c&&c.mouseWheelEventNode)this.mouseWheelEventNode=c.mouseWheelEventNode}else throw"No WebGL implementation found";};
osgViewer.Viewer.prototype={getScene:function(){return this.scene},setScene:function(a){this.root.removeChildren();this.root.addChild(a);this.scene=a},init:function(){this._done=!1;this.root=new osg.Node;this.state=new osg.State;this.view=new osg.View;this.view.addChild(this.root);var a=this.canvas.width/this.canvas.height;this.view.setViewport(new osg.Viewport(0,0,this.canvas.width,this.canvas.height));this.view.setViewMatrix(osg.Matrix.makeLookAt([0,0,-10],[0,0,0],[0,1,0]));this.view.setProjectionMatrix(osg.Matrix.makePerspective(60,
a,1,1E3));this.view.light=new osg.Light;this.view.getOrCreateStateSet().setAttributeAndMode(new osg.Material);gl.enable(gl.DEPTH_TEST);gl.enable(gl.BLEND);gl.enable(gl.CULL_FACE);gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL,!0);this.updateVisitor=new osgUtil.UpdateVisitor;this.cullVisitor=new osgUtil.CullVisitor;this.renderStage=new osg.RenderStage;this.stateGraph=new osg.StateGraph;this.renderStage.setViewport(this.view.getViewport());this.urlOptions&&this.parseOptions()},parseOptions:function(){var a=
function(){for(var c=[],e,f=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),g=0;g<f.length;g++){e=f[g].split("=");c.push(e[0]);c[e[0]]=e[1]}return c}();(a.stats==="1"||a.STATS==="1"||a.Stats==="1")&&this.initStats(a);a.DEPTH_TEST==="0"&&gl.disable(gl.DEPTH_TEST);a.BLEND==="0"&&gl.disable(gl.BLEND);a.CULL_FACE==="0"&&gl.disable(gl.CULL_FACE);a.LIGHT==="0"&&delete this.view.light},initStats:function(a){var c=50,e=10;a.statsMaxMS!==undefined&&(c=parseInt(a.statsMaxMS));a.statsStepMS!==
undefined&&(e=parseInt(a.statsStepMS));a=function(i){i=i===undefined?document.body:document.getElementById(i);var j=document.createElement("div");j.innerHTML="<div id='StatsDiv' style='float: left; position: relative; width: 300px; height: 150px; z-index: 10;'>\n<div id='StatsLegends' style='position: absolute; left: 0px; font-size: 14px;color: #ffffff;'>\n<div id='frameRate' style='color: #00ff00;' > frameRate </div>\n<div id='frameTime' style='color: #ffff00;' > frameTime </div>\n<div id='updateTime' style='color: #d07b1f;'> updateTime </div>\n<div id='cullTime' style='color: #73e0ff;'> cullTime </div>\n<div id='drawTime' style='color: #ff0000;'> drawTime </div>\n<div id='fps'> </div>\n</div>\n<div id='StatsCanvasDiv' style='position: relative;'>\n<canvas id='StatsCanvasGrid' width='300' height='150' style='z-index:-1; position: absolute; background: rgba(14,14,14,0.8); ' ></canvas>\n<canvas id='StatsCanvas' width='300' height='150' style='z-index:8; position: absolute;' ></canvas>\n<canvas id='StatsCanvasFps' width='30' height='15' style='z-index:9; position: absolute; top: 130px' ></canvas>\n</div>\n</div>";
i.appendChild(j);i=document.getElementById("StatsCanvasGrid");j=i.getContext("2d");j.clearRect(0,0,i.width,i.height);var k=Math.floor(c/e).toFixed(0),m=i.height/k;j.strokeStyle="rgb(70,70,70)";for(var n=0;n<k;n++){j.beginPath();j.moveTo(0,n*m);j.lineTo(i.width,n*m);j.stroke()}j=document.getElementById("StatsCanvasFps").getContext("2d");j.font="14px Sans";return document.getElementById("StatsCanvas")};if(this.canvasStats===undefined||this.canvasStats===null)this.canvasStats=a();this.stats=new Stats.Stats(this.canvasStats);
var f=this;this.frameRate=1;this.drawTime=this.cullTime=this.updateTime=this.frameTime=0;var g=this.canvasStats.height,h=g/c;g-=2;a=function(i,j){var k=document.getElementById(i);if(k.style)return k.style.getPropertyValue(j);return null};this.stats.addLayer(a("frameRate","color"),function(){var i=g/60*(1E3/f.frameRate);if(i>g)return g;return i});this.stats.addLayer(a("frameTime","color"),function(){var i=f.frameTime*h;if(i>g)return g;return i});this.stats.addLayer(a("updateTime","color"),function(){var i=
f.updateTime*h;if(i>g)return g;return i});this.stats.addLayer(a("cullTime","color"),function(){var i=f.cullTime*h;if(i>g)return g;return i});this.stats.addLayer(a("drawTime","color"),function(){var i=f.drawTime*h;if(i>g)return g;return i})},update:function(){this.view.accept(this.updateVisitor)},cull:function(){this.stateGraph.clean();this.renderStage.reset();this.cullVisitor.reset();this.cullVisitor.setStateGraph(this.stateGraph);this.cullVisitor.setRenderStage(this.renderStage);this.renderStage.setClearDepth(this.view.getClearDepth());
this.renderStage.setClearColor(this.view.getClearColor());this.renderStage.setClearMask(this.view.getClearMask());this.view.accept(this.cullVisitor)},draw:function(){this.renderStage.draw(this.state);this.state.popAllStateSets()},frame:function(){var a;a=(new Date).getTime();if(this.lastFrameTime===undefined)this.lastFrameTime=0;this.frameRate=a-this.lastFrameTime;this.lastFrameTime=a;if(this.updateVisitor.getFrameStamp().getFrameNumber()===0){this.updateVisitor.getFrameStamp().setReferenceTime(a/
1E3);this.numberFrame=0}this.updateVisitor.getFrameStamp().setSimulationTime(a/1E3-this.updateVisitor.getFrameStamp().getReferenceTime());this.manipulator&&this.view.setViewMatrix(this.manipulator.getInverseMatrix());var c=(new Date).getTime();this.update();var e=(new Date).getTime();this.updateTime=e-c;this.cull();c=(new Date).getTime();this.cullTime=c-e;this.draw();this.drawTime=c=(new Date).getTime()-c;e=this.updateVisitor.getFrameStamp().getFrameNumber()+1;this.updateVisitor.getFrameStamp().setFrameNumber(e);
this.numberFrame++;e=(new Date).getTime();this.frameTime=(new Date).getTime()-a;if(this.stats!==undefined){this.stats.update();if(this.numberFrame%60===0){a=(this.numberFrame*1E3/(e-this.statsStartTime)).toFixed(1);this.statsStartTime=e;this.numberFrame=0;e=document.getElementById("StatsCanvasFps");c=e.getContext("2d");c.clearRect(0,0,e.width,e.height);c.fillStyle="rgb(255,255,255)";c.fillText(a,0,e.height)}}},setDone:function(){this._done=!0},done:function(){return this._done},run:function(){var a=
this,c=function(){if(!a.done()){window.requestAnimationFrame(c,a.canvas);a.frame()}};c()},getManipulator:function(){return this.manipulator},setupManipulator:function(a,c){a===undefined&&(a=new osgGA.OrbitManipulator);if(a.setNode!==undefined)a.setNode(this.root);else a.view=this.view;this.manipulator=a;var e=this,f=this;this.manipulator.convertEventToCanvas=function(n){var o=e.canvas,q,s;if(n.pageX||n.pageY){q=n.pageX;s=n.pageY}else if(n.clientX||n.clientY){q=n.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;
s=n.clientY+document.body.scrollTop+document.documentElement.scrollTop}n=function(p){var t=0,v=0;t=p.offsetLeft;v=p.offsetTop;for(var w=document.getElementsByTagName("body")[0];p.offsetParent&&p!=w;){t+=p.offsetParent.offsetLeft;v+=p.offsetParent.offsetTop;p=p.offsetParent}return[t,v]}(o);q-=n[0];s=o.height-(s-n[1]);return[q,s]};if(c===undefined||c===!1){var g=!1;this.canvas.addEventListener("MozTouchDown",function(n){g=!0;return f.getManipulator().touchDown(n)},!1);this.canvas.addEventListener("MozTouchUp",
function(n){g=!0;return f.getManipulator().touchUp(n)},!1);this.canvas.addEventListener("MozTouchMove",function(n){g=!0;return f.getManipulator().touchMove(n)},!1);var h=function(n){if(g===!1)return f.getManipulator().mousedown(n)},i=function(n){if(g===!1)return f.getManipulator().mouseup(n)},j=function(n){if(g===!1)return f.getManipulator().mousemove(n)},k=function(n){if(g===!1)return f.getManipulator().dblclick(n)},m=function(n){if(g===!1){var o=n||window.event,q=[].slice.call(arguments,1),s=0,
p=0,t=0;n.type="mousewheel";n.wheelDelta&&(s=n.wheelDelta/120);n.detail&&(s=-n.detail/3);t=s;if(o.axis!==undefined&&o.axis===o.HORIZONTAL_AXIS){t=0;p=-1*s}o.wheelDeltaY!==undefined&&(t=o.wheelDeltaY/120);o.wheelDeltaX!==undefined&&(p=-1*o.wheelDeltaX/120);q.unshift(n,s,p,t);o=f.getManipulator();return o.mousewheel.apply(o,q)}};f.getManipulator().mousedown&&this.eventNode.addEventListener("mousedown",h,!1);f.getManipulator().mouseup&&this.eventNode.addEventListener("mouseup",i,!1);f.getManipulator().mousemove&&
this.eventNode.addEventListener("mousemove",j,!1);f.getManipulator().dblclick&&this.eventNode.addEventListener("dblclick",k,!1);if(f.getManipulator().mousewheel){this.canvas.addEventListener("DOMMouseScroll",m,!1);this.canvas.addEventListener("mousewheel",m,!1)}h=function(n){return f.getManipulator().keydown(n)};i=function(n){return f.getManipulator().keyup(n)};f.getManipulator().keydown&&this.eventNode.addEventListener("keydown",h,!1);f.getManipulator().keyup&&this.eventNode.addEventListener("keyup",
i,!1)}}};osgGA={};osgGA.OrbitManipulatorMode={Rotate:0,Pan:1,Zoom:2};osgGA.OrbitManipulator=function(){this.init()};
osgGA.OrbitManipulator.prototype={init:function(){this.distance=25;this.target=[0,0,0];this.eye=[0,this.distance,0];this.rotation=osg.Matrix.mult(osg.Matrix.makeRotate(Math.PI,0,0,1),osg.Matrix.makeRotate(-Math.PI/10,1,0,0),[]);this.up=[0,0,1];this.dy=this.dx=this.time=0;this.buttonup=!0;this.scale=1;this.targetDistance=this.distance;this.currentMode=osgGA.OrbitManipulatorMode.Rotate;this.minDistance=this.maxDistance=0},reset:function(){this.init()},setNode:function(a){this.node=a},computeHomePosition:function(){if(this.node!==
undefined){var a=this.node.getBound();this.setDistance(a.radius()*1.5);this.target=a.center()}},keydown:function(a){if(a.keyCode===32)this.computeHomePosition();else if(a.keyCode===33){this.distanceIncrease();return!1}else if(a.keyCode===34){this.distanceDecrease();return!1}},keyup:function(){},mouseup:function(a){this.dragging=!1;this.panning=!1;this.releaseButton(a)},mousedown:function(a){this.panning=!0;this.dragging=!0;var c=this.convertEventToCanvas(a);this.clientX=c[0];this.clientY=c[1];this.pushButton(a);
a.preventDefault()},mousemove:function(a){if(this.buttonup!==!0){var c,e,f;c=this.convertEventToCanvas(a);a=c[0];c=c[1];e=(this.clientX-a)/10;f=(this.clientY-c)/10;this.clientX=a;this.clientY=c;this.update(e,f);return!1}},dblclick:function(){},touchDown:function(){},touchUp:function(){},touchMove:function(){},setMaxDistance:function(a){this.maxDistance=a},setMinDistance:function(a){this.minDistance=a},setDistance:function(a){this.targetDistance=this.distance=a},panModel:function(a,c){var e=osg.Matrix.inverse(this.rotation),
f=[osg.Matrix.get(e,0,0),osg.Matrix.get(e,0,1),0];osg.Vec3.normalize(f,f);e=[osg.Matrix.get(e,1,0),osg.Matrix.get(e,1,1),0];osg.Vec3.normalize(e,e);osg.Vec3.add(this.target,osg.Vec3.mult(f,-a),this.target);osg.Vec3.add(this.target,osg.Vec3.mult(e,-c),this.target)},zoomModel:function(a,c){this.distance+=c},computeRotation:function(a,c){var e=osg.Matrix.makeRotate(a/10,0,0,1),f=osg.Matrix.mult(this.rotation,e,[]);e=osg.Matrix.makeRotate(c/10,1,0,0);e=osg.Matrix.mult(e,f,[]);var g=osg.Matrix.transformVec3(osg.Matrix.inverse(e),
[0,this.distance,0]);g=osg.Vec3.neg(g,[]);osg.Vec3.normalize(g,g);g=osg.Vec3.dot(g,[0,0,1]);this.rotation=Math.abs(g)>0.95?f:e},update:function(a,c){this.dx=a;this.dy=c;if(Math.abs(a)+Math.abs(c)>0)this.time=(new Date).getTime()},updateWithDelay:function(){var a=1,c,e=this.dx,f=this.dy;if(this.buttonup){a=0;c=((new Date).getTime()-this.time)/1E3;c<2&&(a=1-osgAnimation.EaseOutQuad(c/2));e*=a;f*=a}else this.dy=this.dx=0;if(Math.abs(e)+Math.abs(f)>0)if(this.currentMode===osgGA.OrbitManipulatorMode.Pan)this.panModel(e/
this.scale,f/this.scale);else if(this.currentMode===osgGA.OrbitManipulatorMode.Rotate)this.computeRotation(e,f);else this.currentMode===osgGA.OrbitManipulatorMode.Zoom&&this.zoomModel(e,f)},releaseButton:function(){this.buttonup=!0},changeScale:function(a){var c=this.scale/a;this.scale=a;this.distance=this.targetDistance;this.targetDistance=this.distance*c;this.timeMotion=(new Date).getTime()},mousewheel:function(a,c){if(c>0)this.distanceDecrease&&this.distanceDecrease();else c<0&&this.distanceIncrease&&
this.distanceIncrease()},distanceIncrease:function(){var a=this.targetDistance,c=a+this.distance/10;if(this.maxDistance>0&&c>this.maxDistance)c=this.maxDistance;this.distance=a;this.targetDistance=c;this.timeMotion=(new Date).getTime()},distanceDecrease:function(){var a=this.targetDistance,c=a-this.distance/10;if(this.minDistance>0&&c<this.minDistance)c=this.minDistance;this.distance=a;this.targetDistance=c;this.timeMotion=(new Date).getTime()},pushButton:function(){this.dx=this.dy=0;this.buttonup=
!1},getInverseMatrix:function(){this.updateWithDelay();var a=this.target,c=this.distance;if(this.timeMotion!==undefined){var e=((new Date).getTime()-this.timeMotion)/1E3;if(e<1){e=osgAnimation.EaseOutQuad(e/1);this.targetMotion&&(a=osg.Vec3.add(this.target,osg.Vec3.mult(osg.Vec3.sub(this.targetMotion,this.target),e)));this.targetDistance&&(c=this.distance+(this.targetDistance-this.distance)*e)}else{if(this.targetMotion)a=this.target=this.targetMotion;if(this.targetDistance)c=this.distance=this.targetDistance;
this.timeMotion=undefined}}e=[];var f=[];osg.Matrix.inverse(this.rotation,e);osg.Matrix.transformVec3(e,[0,c,0],f);osg.Matrix.makeLookAt(osg.Vec3.add(a,f,f),a,[0,0,1],e);return e}};osgGA.FirstPersonManipulator=function(){this.init()};
osgGA.FirstPersonManipulator.prototype={setNode:function(a){this.node=a},computeHomePosition:function(){if(this.node)this.eye=[0,-this.node.getBound().radius()*1.5,0]},init:function(){this.direction=[0,1,0];this.angleHorizontal=this.angleVertical=0;this.eye=[0,25,10];this.up=[0,0,1];this.time=0;this.buttonup=!0},reset:function(){this.init()},mouseup:function(a){this.dragging=!1;this.releaseButton(a)},mousedown:function(a){this.dragging=!0;var c=this.convertEventToCanvas(a);this.clientX=c[0];this.clientY=
c[1];this.pushButton(a)},mousemove:function(a){if(this.buttonup!==!0){var c,e,f;c=this.convertEventToCanvas(a);a=c[0];c=c[1];e=this.clientX-a;f=this.clientY-c;this.clientX=a;this.clientY=c;this.update(e,f);this.computeRotation(this.dx,this.dy)}},dblclick:function(){},touchdown:function(){},touchup:function(){},touchmove:function(){},pushButton:function(){this.dx=this.dy=0;this.buttonup=!1},computeRotation:function(a,c){this.angleVertical+=c*0.01;this.angleHorizontal-=a*0.01;var e=osg.Matrix.makeRotate(this.angleVertical,
1,0,0),f=osg.Matrix.makeRotate(this.angleHorizontal,0,0,1);e=osg.Matrix.mult(f,e,[]);this.direction=osg.Matrix.transformVec3(e,[0,1,0],[]);this.up=osg.Matrix.transformVec3(e,[0,0,1],[])},update:function(a,c){this.dx=a;this.dy=c;if(Math.abs(a)+Math.abs(c)>0)this.time=(new Date).getTime()},releaseButton:function(){this.buttonup=!0},getInverseMatrix:function(){var a=osg.Vec3.add(this.eye,this.direction);return osg.Matrix.makeLookAt(this.eye,a,this.up)},moveForward:function(a){a=osg.Vec3.mult(osg.Vec3.normalize(this.direction),
a);this.eye=osg.Vec3.add(this.eye,a)},strafe:function(a){var c=osg.Vec3.cross(this.direction,this.up);a=osg.Vec3.mult(osg.Vec3.normalize(c),a);this.eye=osg.Vec3.add(this.eye,a)},keydown:function(a){if(a.keyCode===32)this.computeHomePosition();else if(a.keyCode==87){this.moveForward(5);return!1}else if(a.keyCode==83){this.moveForward(-5);return!1}else if(a.keyCode==68){this.strafe(5);return!1}else if(a.keyCode==65){this.strafe(-5);return!1}}};
