// ThreeCanvas.js r47dev - http://github.com/mrdoob/three.js 'use strict';var THREE=THREE||{};if(!self.Int32Array)self.Int32Array=Array,self.Float32Array=Array;if(!self.requestAnimationFrame)self.requestAnimationFrame=function(){return self.webkitRequestAnimationFrame||self.mozRequestAnimationFrame||self.oRequestAnimationFrame||self.msRequestAnimationFrame||function(a){self.setTimeout(a,1E3/60)}}();THREE.Color=function(a){void 0!==a&&this.setHex(a);return this}; THREE.Color.prototype={constructor:THREE.Color,r:1,g:1,b:1,copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;return this},copyGammaToLinear:function(a){this.r=a.r*a.r;this.g=a.g*a.g;this.b=a.b*a.b;return this},copyLinearToGamma:function(a){this.r=Math.sqrt(a.r);this.g=Math.sqrt(a.g);this.b=Math.sqrt(a.b);return this},convertGammaToLinear:function(){var a=this.r,b=this.g,c=this.b;this.r=a*a;this.g=b*b;this.b=c*c;return this},convertLinearToGamma:function(){this.r=Math.sqrt(this.r);this.g=Math.sqrt(this.g); this.b=Math.sqrt(this.b);return this},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;return this},setHSV:function(a,b,c){var d,e,f;if(0===c)this.r=this.g=this.b=0;else switch(d=Math.floor(6*a),e=6*a-d,a=c*(1-b),f=c*(1-b*e),b=c*(1-b*(1-e)),d){case 1:this.r=f;this.g=c;this.b=a;break;case 2:this.r=a;this.g=c;this.b=b;break;case 3:this.r=a;this.g=f;this.b=c;break;case 4:this.r=b;this.g=a;this.b=c;break;case 5:this.r=c;this.g=a;this.b=f;break;case 6:case 0:this.r=c,this.g=b,this.b=a}return this},setHex:function(a){a= Math.floor(a);this.r=(a>>16&255)/255;this.g=(a>>8&255)/255;this.b=(a&255)/255;return this},getHex:function(){return Math.floor(255*this.r)<<16^Math.floor(255*this.g)<<8^Math.floor(255*this.b)},getContextStyle:function(){return"rgb("+Math.floor(255*this.r)+","+Math.floor(255*this.g)+","+Math.floor(255*this.b)+")"},clone:function(){return(new THREE.Color).setRGB(this.r,this.g,this.b)}}; THREE.Frustum=function(){this.planes=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4]}; THREE.Frustum.prototype.setFromMatrix=function(a){var b,c=this.planes;c[0].set(a.n41-a.n11,a.n42-a.n12,a.n43-a.n13,a.n44-a.n14);c[1].set(a.n41+a.n11,a.n42+a.n12,a.n43+a.n13,a.n44+a.n14);c[2].set(a.n41+a.n21,a.n42+a.n22,a.n43+a.n23,a.n44+a.n24);c[3].set(a.n41-a.n21,a.n42-a.n22,a.n43-a.n23,a.n44-a.n24);c[4].set(a.n41-a.n31,a.n42-a.n32,a.n43-a.n33,a.n44-a.n34);c[5].set(a.n41+a.n31,a.n42+a.n32,a.n43+a.n33,a.n44+a.n34);for(a=0;6>a;a++)b=c[a],b.divideScalar(Math.sqrt(b.x*b.x+b.y*b.y+b.z*b.z))}; THREE.Frustum.prototype.contains=function(a){for(var b=this.planes,c=a.matrixWorld,d=-a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)),e=0;6>e;e++)if(a=b[e].x*c.n14+b[e].y*c.n24+b[e].z*c.n34+b[e].w,a<=d)return!1;return!0};THREE.Vector2=function(a,b){this.x=a||0;this.y=b||0}; THREE.Vector2.prototype={constructor:THREE.Vector2,set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this}, divideScalar:function(a){a?(this.x/=a,this.y/=a):this.set(0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,a=this.y-a.y;return b*b+a*a},setLength:function(a){return this.normalize().multiplyScalar(a)}, equals:function(a){return a.x===this.x&&a.y===this.y}};THREE.Vector3=function(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0}; THREE.Vector3.prototype={constructor:THREE.Vector3,set:function(a,b,c){this.x=a;this.y=b;this.z=c;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setZ:function(a){this.z=a;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this}, addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideSelf:function(a){this.x/=a.x;this.y/=a.y;this.z/=a.z;return this}, divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a):this.z=this.y=this.x=0;return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return this.x+this.y+this.z},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)}, cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,c=this.y,d=this.z;this.x=c*a.z-d*a.y;this.y=d*a.x-b*a.z;this.z=b*a.y-c*a.x;return this},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){return(new THREE.Vector3).sub(this,a).lengthSq()},setPositionFromMatrix:function(a){this.x=a.n14;this.y=a.n24;this.z=a.n34},setRotationFromMatrix:function(a){var b=Math.cos(this.y); this.y=Math.asin(a.n13);1.0E-5this.lengthSq()}};THREE.Vector4=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=void 0!==d?d:1}; THREE.Vector4.prototype={constructor:THREE.Vector4,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=void 0!==a.w?a.w:1},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z- b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a,this.w/=a):(this.z=this.y=this.x=0,this.w=1);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())}, normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b;return this}}; THREE.Ray=function(a,b){function c(a,b,c){j.sub(c,a);q=j.dot(b);w=p.add(a,k.copy(b).multiplyScalar(q));return u=c.distanceTo(w)}function d(a,b,c,d){j.sub(d,b);p.sub(c,b);k.sub(a,b);I=j.dot(j);G=j.dot(p);v=j.dot(k);H=p.dot(p);z=p.dot(k);E=1/(I*H-G*G);r=(H*v-G*z)*E;s=(I*z-G*v)*E;return 0<=r&&0<=s&&1>r+s}this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3;this.intersectScene=function(a){return this.intersectObjects(a.children)};this.intersectObjects=function(a){var b,c,d=[];for(b=0, c=a.length;ba.scale.x)return[];b={distance:j,point:a.position,face:null,object:a};k.push(b)}else if(a instanceof THREE.Mesh){j=c(this.origin,this.direction,a.matrixWorld.getPosition());if(j>a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)))return k;var q,r=a.geometry,s=r.vertices,F;a.matrixRotationWorld.extractRotation(a.matrixWorld);for(j=0,p=r.faces.length;j=q)&&(e=F.multiplyVector3(e.copy(s[b.a].position)),f=F.multiplyVector3(f.copy(s[b.b].position)),g=F.multiplyVector3(g.copy(s[b.c].position)),b instanceof THREE.Face4&&(i=F.multiplyVector3(i.copy(s[b.d].position))),o=a.matrixRotationWorld.multiplyVector3(o.copy(b.normal)),q=h.dot(o),a.doubleSided||(a.flipSided?0q)))if(q=o.dot(l.sub(e,m))/q,n.add(m,h.multiplyScalar(q)),b instanceof THREE.Face3)d(n,e,f,g)&&(b={distance:m.distanceTo(n), point:n.clone(),face:b,object:a},k.push(b));else if(b instanceof THREE.Face4&&(d(n,e,f,i)||d(n,f,g,i)))b={distance:m.distanceTo(n),point:n.clone(),face:b,object:a},k.push(b)}return k};var j=new THREE.Vector3,p=new THREE.Vector3,k=new THREE.Vector3,q,w,u,I,G,v,H,z,E,r,s}; THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,i=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return f};this.getHeight=function(){return g};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,l,o){i=!1;b=f;c=g;d=l;e=o;a()};this.addPoint=function(f,g){i?(i=!1,b=f,c=g,d=f,e=g):(b=bf?d:f,e=e>g?e:g);a()};this.add3Points= function(f,g,l,o,n,j){i?(i=!1,b=fl?f>n?f:n:l>n?l:n,e=g>o?g>j?g:j:o>j?o:j):(b=fl?f>n?f>d?f:d:n>d?n:d:l>n?l>d?l:d:n>d?n:d,e=g>o?g>j?g>e?g:e:j>e?j:e:o>j?o>e?o:e:j>e?j:e);a()};this.addRectangle=function(f){i?(i=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=bf.getRight()?d:f.getRight(),e=e> f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=da.getRight()||ea.getBottom()?!1:!0};this.empty=function(){i=!0;e=d=c=b=0;a()};this.isEmpty=function(){return i}}; THREE.Math={clamp:function(a,b,c){return ac?c:a},clampBottom:function(a,b){return ae&&0>f||0>g&&0>i)return!1;0>e?c=Math.max(c,e/(e-f)):0>f&&(d=Math.min(d,e/(e-f)));0>g?c=Math.max(c,g/(g-i)):0>i&&(d=Math.min(d,g/(g-i)));if(dg&&i.positionScreen.z(M.positionScreen.x-x.positionScreen.x)*(O.positionScreen.y-x.positionScreen.y)-(M.positionScreen.y-x.positionScreen.y)*(O.positionScreen.x- x.positionScreen.x)))V=n[o]=n[o]||new THREE.RenderableFace3,o++,l=V,l.v1.copy(x),l.v2.copy(O),l.v3.copy(M);else continue;else if(D instanceof THREE.Face4)if(x=h[D.a],O=h[D.b],M=h[D.c],V=h[D.d],x.visible&&O.visible&&M.visible&&V.visible&&(K.doubleSided||K.flipSided!=(0>(V.positionScreen.x-x.positionScreen.x)*(O.positionScreen.y-x.positionScreen.y)-(V.positionScreen.y-x.positionScreen.y)*(O.positionScreen.x-x.positionScreen.x)||0>(O.positionScreen.x-M.positionScreen.x)*(V.positionScreen.y-M.positionScreen.y)- (O.positionScreen.y-M.positionScreen.y)*(V.positionScreen.x-M.positionScreen.x))))ea=p[j]=p[j]||new THREE.RenderableFace4,j++,l=ea,l.v1.copy(x),l.v2.copy(O),l.v3.copy(M),l.v4.copy(V);else continue;l.normalWorld.copy(D.normal);B.multiplyVector3(l.normalWorld);l.centroidWorld.copy(D.centroid);t.multiplyVector3(l.centroidWorld);l.centroidScreen.copy(l.centroidWorld);E.multiplyVector3(l.centroidScreen);M=D.vertexNormals;for(x=0,O=M.length;xz.z))g=G[I]=G[I]||new THREE.RenderableParticle,I++,u=g,u.x=z.x/z.w,u.y=z.y/z.w,u.z=z.z,u.rotation=K.rotation.z,u.scale.x= K.scale.x*Math.abs(u.x-(z.x+e.projectionMatrix.n11)/(z.w+e.projectionMatrix.n14)),u.scale.y=K.scale.y*Math.abs(u.y-(z.y+e.projectionMatrix.n22)/(z.w+e.projectionMatrix.n24)),u.material=K.material,v.elements.push(u);f&&v.elements.sort(c);return v}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,void 0!==d?d:1)}; THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=Math.PI/360,c=a.x*b,d=a.y*b,e=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-e),e=Math.sin(-e),f=Math.cos(c),c=Math.sin(c),g=a*b,i=d*e;this.w=g*f-i*c;this.x=g*c+i*f;this.y=d*b*f+a*e*c;this.z=a*e*f-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c); this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.n11+a.n22+a.n33))/2;this.x=Math.sqrt(Math.max(0,b+a.n11-a.n22-a.n33))/2;this.y=Math.sqrt(Math.max(0,b-a.n11+a.n22-a.n33))/2;this.z=Math.sqrt(Math.max(0,b-a.n11-a.n22+a.n33))/2;this.x=0>a.n32-a.n23?-Math.abs(this.x):Math.abs(this.x);this.y=0>a.n13-a.n31?-Math.abs(this.y):Math.abs(this.y);this.z=0>a.n21-a.n12?-Math.abs(this.z):Math.abs(this.z); this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);0===a?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},multiplySelf:function(a){var b= this.x,c=this.y,d=this.z,e=this.w,f=a.x,g=a.y,i=a.z,a=a.w;this.x=b*a+e*f+c*i-d*g;this.y=c*a+e*g+d*f-b*i;this.z=d*a+e*i+b*g-c*f;this.w=e*a-b*f-c*g-d*i;return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,i=this.z,m=this.w,h=m*c+g*e-i*d,l=m*d+i*c-f*e,o=m*e+f*d-g*c,c=-f* c-g*d-i*e;b.x=h*m+c*-f+l*-i-o*-g;b.y=l*m+c*-g+o*-f-h*-i;b.z=o*m+c*-i+h*-g-l*-f;return b}}; THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;0>e?(c.w=-b.w,c.x=-b.x,c.y=-b.y,c.z=-b.z,e=-e):c.copy(b);if(1<=Math.abs(e))return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var f=Math.acos(e),e=Math.sqrt(1-e*e);if(0.0010>Math.abs(e))return c.w=0.5*(a.w+b.w),c.x=0.5*(a.x+b.x),c.y=0.5*(a.y+b.y),c.z=0.5*(a.z+b.z),c;b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(a){this.position=a||new THREE.Vector3}; THREE.Face3=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materialIndex=f;this.centroid=new THREE.Vector3}; THREE.Face4=function(a,b,c,d,e,f,g){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=f instanceof THREE.Color?f:new THREE.Color;this.vertexColors=f instanceof Array?f:[];this.vertexTangents=[];this.materialIndex=g;this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.u=a||0;this.v=b||0}; THREE.UV.prototype={constructor:THREE.UV,set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.u=a.u;this.v=a.v;return this},clone:function(){return new THREE.UV(this.u,this.v)}}; THREE.Geometry=function(){this.id=THREE.GeometryCount++;this.vertices=[];this.colors=[];this.materials=[];this.faces=[];this.faceUvs=[[]];this.faceVertexUvs=[[]];this.morphTargets=[];this.morphColors=[];this.skinWeights=[];this.skinIndices=[];this.boundingSphere=this.boundingBox=null;this.dynamic=this.hasTangents=!1}; THREE.Geometry.prototype={constructor:THREE.Geometry,applyMatrix:function(a){var b=new THREE.Matrix4;b.extractRotation(a,new THREE.Vector3(1,1,1));for(var c=0,d=this.vertices.length;ce?-1:1,f.vertexTangents[d]=new THREE.Vector4(Z.x,Z.y,Z.z,e)}this.hasTangents=!0},computeBoundingBox:function(){if(0c.x)c.x=a.x;if(a.yc.y)c.y=a.y;if(a.zc.z)c.z=a.z}}},computeBoundingSphere:function(){for(var a,b=0,c=0,d=this.vertices.length;cb&&(b=a);this.boundingSphere={radius:b}},mergeVertices:function(){var a={},b=[],c=[],d,e=Math.pow(10,4),f,g;for(f=0,g=this.vertices.length;fw&&k.clearRect(Math.floor(Y.getX()),Math.floor(Y.getY()),Math.floor(Y.getWidth()),Math.floor(Y.getHeight())),0=k||(k*=g.intensity,d.r+=i.r*k,d.g+=i.g*k,d.b+=i.b*k)):g instanceof THREE.PointLight&&(l=g.matrixWorld.getPosition(),k=c.dot(R.sub(l,b).normalize()),0>=k||(k*=0==g.distance?1:1-Math.min(b.distanceTo(l)/g.distance,1),0!=k&&(k*=g.intensity,d.r+=i.r*k,d.g+=i.g*k,d.b+=i.b*k)))}function q(a,f,g){b(g.opacity);c(g.blending);var i,l,h,m,za,o;if(g instanceof THREE.ParticleBasicMaterial){if(g.map)m=g.map.image,za=m.width>>1,o=m.height>> 1,g=f.scale.x*j,h=f.scale.y*p,i=g*za,l=h*o,X.set(a.x-i,a.y-l,a.x+i,a.y+l),la.intersects(X)&&(k.save(),k.translate(a.x,a.y),k.rotate(-f.rotation),k.scale(g,-h),k.translate(-za,-o),k.drawImage(m,0,0),k.restore())}else g instanceof THREE.ParticleCanvasMaterial&&(i=f.scale.x*j,l=f.scale.y*p,X.set(a.x-i,a.y-l,a.x+i,a.y+l),la.intersects(X)&&(d(g.color.getContextStyle()),e(g.color.getContextStyle()),k.save(),k.translate(a.x,a.y),k.rotate(-f.rotation),k.scale(i,l),g.program(k),k.restore()))}function v(a, e,f,g){b(g.opacity);c(g.blending);k.beginPath();k.moveTo(a.positionScreen.x,a.positionScreen.y);k.lineTo(e.positionScreen.x,e.positionScreen.y);k.closePath();if(g instanceof THREE.LineBasicMaterial){a=g.linewidth;if(H!=a)k.lineWidth=H=a;a=g.linecap;if(z!=a)k.lineCap=z=a;a=g.linejoin;if(E!=a)k.lineJoin=E=a;d(g.color.getContextStyle());k.stroke();X.inflate(2*g.linewidth)}}function u(a,d,e,g,i,k,h,j){f.info.render.vertices+=3;f.info.render.faces++;b(j.opacity);c(j.blending);N=a.positionScreen.x;P=a.positionScreen.y; S=d.positionScreen.x;T=d.positionScreen.y;F=e.positionScreen.x;D=e.positionScreen.y;w(N,P,S,T,F,D);if(j instanceof THREE.MeshBasicMaterial)if(j.map)j.map.mapping instanceof THREE.UVMapping&&($=h.uvs[0],Aa(N,P,S,T,F,D,$[g].u,$[g].v,$[i].u,$[i].v,$[k].u,$[k].v,j.map));else if(j.envMap){if(j.envMap.mapping instanceof THREE.SphericalReflectionMapping)a=l.matrixWorldInverse,R.copy(h.vertexNormalsWorld[g]),Ba=0.5*(R.x*a.n11+R.y*a.n12+R.z*a.n13)+0.5,Ca=0.5*-(R.x*a.n21+R.y*a.n22+R.z*a.n23)+0.5,R.copy(h.vertexNormalsWorld[i]), Da=0.5*(R.x*a.n11+R.y*a.n12+R.z*a.n13)+0.5,Ea=0.5*-(R.x*a.n21+R.y*a.n22+R.z*a.n23)+0.5,R.copy(h.vertexNormalsWorld[k]),Fa=0.5*(R.x*a.n11+R.y*a.n12+R.z*a.n13)+0.5,Ga=0.5*-(R.x*a.n21+R.y*a.n22+R.z*a.n23)+0.5,Aa(N,P,S,T,F,D,Ba,Ca,Da,Ea,Fa,Ga,j.envMap)}else j.wireframe?ia(j.color,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(j.color);else if(j instanceof THREE.MeshLambertMaterial)j.map&&!j.wireframe&&(j.map.mapping instanceof THREE.UVMapping&&($=h.uvs[0],Aa(N,P,S,T,F,D,$[g].u,$[g].v, $[i].u,$[i].v,$[k].u,$[k].v,j.map)),c(THREE.SubtractiveBlending)),xa?!j.wireframe&&j.shading==THREE.SmoothShading&&3==h.vertexNormalsWorld.length?(B.r=y.r=A.r=W.r,B.g=y.g=A.g=W.g,B.b=y.b=A.b=W.b,n(m,h.v1.positionWorld,h.vertexNormalsWorld[0],B),n(m,h.v2.positionWorld,h.vertexNormalsWorld[1],y),n(m,h.v3.positionWorld,h.vertexNormalsWorld[2],A),B.r=Math.max(0,Math.min(j.color.r*B.r,1)),B.g=Math.max(0,Math.min(j.color.g*B.g,1)),B.b=Math.max(0,Math.min(j.color.b*B.b,1)),y.r=Math.max(0,Math.min(j.color.r* y.r,1)),y.g=Math.max(0,Math.min(j.color.g*y.g,1)),y.b=Math.max(0,Math.min(j.color.b*y.b,1)),A.r=Math.max(0,Math.min(j.color.r*A.r,1)),A.g=Math.max(0,Math.min(j.color.g*A.g,1)),A.b=Math.max(0,Math.min(j.color.b*A.b,1)),L.r=0.5*(y.r+A.r),L.g=0.5*(y.g+A.g),L.b=0.5*(y.b+A.b),da=va(B,y,A,L),pa(N,P,S,T,F,D,0,0,1,0,0,1,da)):(t.r=W.r,t.g=W.g,t.b=W.b,n(m,h.centroidWorld,h.normalWorld,t),t.r=Math.max(0,Math.min(j.color.r*t.r,1)),t.g=Math.max(0,Math.min(j.color.g*t.g,1)),t.b=Math.max(0,Math.min(j.color.b*t.b, 1)),j.wireframe?ia(t,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(t)):j.wireframe?ia(j.color,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(j.color);else if(j instanceof THREE.MeshDepthMaterial)fa=l.near,ga=l.far,B.r=B.g=B.b=1-oa(a.positionScreen.z,fa,ga),y.r=y.g=y.b=1-oa(d.positionScreen.z,fa,ga),A.r=A.g=A.b=1-oa(e.positionScreen.z,fa,ga),L.r=0.5*(y.r+A.r),L.g=0.5*(y.g+A.g),L.b=0.5*(y.b+A.b),da=va(B,y,A,L),pa(N,P,S,T,F,D,0,0,1,0,0,1,da);else if(j instanceof THREE.MeshNormalMaterial)t.r= qa(h.normalWorld.x),t.g=qa(h.normalWorld.y),t.b=qa(h.normalWorld.z),j.wireframe?ia(t,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):ha(t)}function I(a,d,e,g,i,j,k,h,o){f.info.render.vertices+=4;f.info.render.faces++;b(h.opacity);c(h.blending);if(h.map||h.envMap)u(a,d,g,0,1,3,k,h,o),u(i,e,j,1,2,3,k,h,o);else if(N=a.positionScreen.x,P=a.positionScreen.y,S=d.positionScreen.x,T=d.positionScreen.y,F=e.positionScreen.x,D=e.positionScreen.y,Q=g.positionScreen.x,x=g.positionScreen.y,O=i.positionScreen.x, M=i.positionScreen.y,V=j.positionScreen.x,K=j.positionScreen.y,h instanceof THREE.MeshBasicMaterial)G(N,P,S,T,F,D,Q,x),h.wireframe?ia(h.color,h.wireframeLinewidth,h.wireframeLinecap,h.wireframeLinejoin):ha(h.color);else if(h instanceof THREE.MeshLambertMaterial)xa?!h.wireframe&&h.shading==THREE.SmoothShading&&4==k.vertexNormalsWorld.length?(B.r=y.r=A.r=L.r=W.r,B.g=y.g=A.g=L.g=W.g,B.b=y.b=A.b=L.b=W.b,n(m,k.v1.positionWorld,k.vertexNormalsWorld[0],B),n(m,k.v2.positionWorld,k.vertexNormalsWorld[1],y), n(m,k.v4.positionWorld,k.vertexNormalsWorld[3],A),n(m,k.v3.positionWorld,k.vertexNormalsWorld[2],L),B.r=Math.max(0,Math.min(h.color.r*B.r,1)),B.g=Math.max(0,Math.min(h.color.g*B.g,1)),B.b=Math.max(0,Math.min(h.color.b*B.b,1)),y.r=Math.max(0,Math.min(h.color.r*y.r,1)),y.g=Math.max(0,Math.min(h.color.g*y.g,1)),y.b=Math.max(0,Math.min(h.color.b*y.b,1)),A.r=Math.max(0,Math.min(h.color.r*A.r,1)),A.g=Math.max(0,Math.min(h.color.g*A.g,1)),A.b=Math.max(0,Math.min(h.color.b*A.b,1)),L.r=Math.max(0,Math.min(h.color.r* L.r,1)),L.g=Math.max(0,Math.min(h.color.g*L.g,1)),L.b=Math.max(0,Math.min(h.color.b*L.b,1)),da=va(B,y,A,L),w(N,P,S,T,Q,x),pa(N,P,S,T,Q,x,0,0,1,0,0,1,da),w(O,M,F,D,V,K),pa(O,M,F,D,V,K,1,0,1,1,0,1,da)):(t.r=W.r,t.g=W.g,t.b=W.b,n(m,k.centroidWorld,k.normalWorld,t),t.r=Math.max(0,Math.min(h.color.r*t.r,1)),t.g=Math.max(0,Math.min(h.color.g*t.g,1)),t.b=Math.max(0,Math.min(h.color.b*t.b,1)),G(N,P,S,T,F,D,Q,x),h.wireframe?ia(t,h.wireframeLinewidth,h.wireframeLinecap,h.wireframeLinejoin):ha(t)):(G(N,P,S, T,F,D,Q,x),h.wireframe?ia(h.color,h.wireframeLinewidth,h.wireframeLinecap,h.wireframeLinejoin):ha(h.color));else if(h instanceof THREE.MeshNormalMaterial)t.r=qa(k.normalWorld.x),t.g=qa(k.normalWorld.y),t.b=qa(k.normalWorld.z),G(N,P,S,T,F,D,Q,x),h.wireframe?ia(t,h.wireframeLinewidth,h.wireframeLinecap,h.wireframeLinejoin):ha(t);else if(h instanceof THREE.MeshDepthMaterial)fa=l.near,ga=l.far,B.r=B.g=B.b=1-oa(a.positionScreen.z,fa,ga),y.r=y.g=y.b=1-oa(d.positionScreen.z,fa,ga),A.r=A.g=A.b=1-oa(g.positionScreen.z, fa,ga),L.r=L.g=L.b=1-oa(e.positionScreen.z,fa,ga),da=va(B,y,A,L),w(N,P,S,T,Q,x),pa(N,P,S,T,Q,x,0,0,1,0,0,1,da),w(O,M,F,D,V,K),pa(O,M,F,D,V,K,1,0,1,1,0,1,da)}function w(a,b,c,d,e,f){k.beginPath();k.moveTo(a,b);k.lineTo(c,d);k.lineTo(e,f);k.lineTo(a,b);k.closePath()}function G(a,b,c,d,e,f,g,h){k.beginPath();k.moveTo(a,b);k.lineTo(c,d);k.lineTo(e,f);k.lineTo(g,h);k.lineTo(a,b);k.closePath()}function ia(a,b,c,e){if(H!=b)k.lineWidth=H=b;if(z!=c)k.lineCap=z=c;if(E!=e)k.lineJoin=E=e;d(a.getContextStyle()); k.stroke();X.inflate(2*b)}function ha(a){e(a.getContextStyle());k.fill()}function Aa(a,b,c,d,f,g,h,i,j,l,m,o,n){if(0!=n.image.width){if(!0==n.needsUpdate||void 0==ka[n.id]){var p=n.wrapS==THREE.RepeatWrapping,q=n.wrapT==THREE.RepeatWrapping;ka[n.id]=k.createPattern(n.image,p&&q?"repeat":p&&!q?"repeat-x":!p&&q?"repeat-y":"no-repeat");n.needsUpdate=!1}e(ka[n.id]);var p=n.offset.x/n.repeat.x,q=n.offset.y/n.repeat.y,r=n.image.width*n.repeat.x,s=n.image.height*n.repeat.y,h=(h+p)*r,i=(i+q)*s,c=c-a,d=d- b,f=f-a,g=g-b,j=(j+p)*r-h,l=(l+q)*s-i,m=(m+p)*r-h,o=(o+q)*s-i,p=j*o-m*l;if(0==p){if(void 0===ea[n.id])b=document.createElement("canvas"),b.width=n.image.width,b.height=n.image.height,b=b.getContext("2d"),b.drawImage(n.image,0,0),ea[n.id]=b.getImageData(0,0,n.image.width,n.image.height).data;b=ea[n.id];h=4*(Math.floor(h)+Math.floor(i)*n.image.width);t.setRGB(b[h]/255,b[h+1]/255,b[h+2]/255);ha(t)}else p=1/p,n=(o*c-l*f)*p,l=(o*d-l*g)*p,c=(j*f-m*c)*p,d=(j*g-m*d)*p,a=a-n*h-c*i,h=b-l*h-d*i,k.save(),k.transform(n, l,c,d,a,h),k.fill(),k.restore()}}function pa(a,b,c,d,e,f,g,h,i,j,l,m,n){var o,p;o=n.width-1;p=n.height-1;g*=o;h*=p;c-=a;d-=b;e-=a;f-=b;i=i*o-g;j=j*p-h;l=l*o-g;m=m*p-h;p=1/(i*m-l*j);o=(m*c-j*e)*p;j=(m*d-j*f)*p;c=(i*e-l*c)*p;d=(i*f-l*d)*p;a=a-o*g-c*h;b=b-j*g-d*h;k.save();k.transform(o,j,c,d,a,b);k.clip();k.drawImage(n,0,0);k.restore()}function va(a,b,c,d){var e=~~(255*a.r),f=~~(255*a.g),a=~~(255*a.b),g=~~(255*b.r),h=~~(255*b.g),b=~~(255*b.b),i=~~(255*c.r),j=~~(255*c.g),c=~~(255*c.b),k=~~(255*d.r),l= ~~(255*d.g),d=~~(255*d.b);aa[0]=0>e?0:255f?0:255a?0:255g?0:255h?0:255b?0:255i?0:255j?0:255c?0:255k?0:255l?0:255d?0:255a?0:1o-1?e-1:o-1,j=(o+1)%e,p=0>l-1?d-1:l-1,k=(l+1)%d,q=[],w=[0,0,i[4*(o*d+l)]/255*b];q.push([-1,0,i[4*(o*d+p)]/255*b]);q.push([-1,-1,i[4*(n*d+p)]/255*b]);q.push([0,-1,i[4*(n*d+l)]/255*b]);q.push([1, -1,i[4*(n*d+k)]/255*b]);q.push([1,0,i[4*(o*d+k)]/255*b]);q.push([1,1,i[4*(j*d+k)]/255*b]);q.push([0,1,i[4*(j*d+l)]/255*b]);q.push([-1,1,i[4*(j*d+p)]/255*b]);n=[];p=q.length;for(j=0;j