// ThreeCanvas.js r46dev - http://github.com/mrdoob/three.js var THREE=THREE||{};if(!self.Int32Array)self.Int32Array=Array,self.Float32Array=Array;THREE.Color=function(a){a!==void 0&&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},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;return this},setHSV:function(a,b,c){var d,f,e;if(c===0)this.r=this.g=this.b=0;else switch(d=Math.floor(a*6),f=a*6-d,a=c*(1-b),e=c*(1- b*f),b=c*(1-b*(1-f)),d){case 1:this.r=e;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=e;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=e;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~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},getContextStyle:function(){return"rgb("+ Math.floor(this.r*255)+","+Math.floor(this.g*255)+","+Math.floor(this.b*255)+")"},clone:function(){return(new THREE.Color).setRGB(this.r,this.g,this.b)}};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.set(0,0,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){return this.set(this.y*a.z-this.z*a.y,this.z*a.x-this.x*a.z,this.x*a.y-this.y*a.x)},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); Math.abs(b)>1.0E-5?(this.x=Math.atan2(-a.n23/b,a.n33/b),this.z=Math.atan2(-a.n12/b,a.n11/b)):(this.x=0,this.z=Math.atan2(a.n21,a.n22))},isZero:function(){return this.lengthSq()<1.0E-4}};THREE.Vector4=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=d!==void 0?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=a.w!==void 0?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){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3}; THREE.Ray.prototype={constructor:THREE.Ray,intersectScene:function(a){return this.intersectObjects(a.children)},intersectObjects:function(a){var b,c,d=[];b=0;for(c=a.length;b0&&a>0&&e+a<1}for(var d,f=[],e=0,g=a.children.length;ea.scale.x)return[];d={distance:e,point:a.position,face:null,object:a};f.push(d)}else if(a instanceof THREE.Mesh){e= b(this.origin,this.direction,a.matrixWorld.getPosition());if(e===null||e>a.geometry.boundingSphere.radius*Math.max(a.scale.x,Math.max(a.scale.y,a.scale.z)))return f;var h,l,o,i,n,m,j,q,k=a.geometry,s=k.vertices;a.matrixRotationWorld.extractRotation(a.matrixWorld);e=0;for(g=k.faces.length;e0:m<0)))if(m=n.dot((new THREE.Vector3).sub(h,j))/m,j=j.addSelf(q.multiplyScalar(m)),d instanceof THREE.Face3)c(j,h,l,o)&&(d={distance:this.origin.distanceTo(j),point:j,face:d,object:a},f.push(d));else if(d instanceof THREE.Face4&&(c(j,h,l,i)||c(j,l,o,i)))d={distance:this.origin.distanceTo(j), point:j,face:d,object:a},f.push(d)}return f}}; THREE.Rectangle=function(){function a(){e=d-b;g=f-c}var b,c,d,f,e,g,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return e};this.getHeight=function(){return g};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return f};this.set=function(e,g,i,n){h=!1;b=e;c=g;d=i;f=n;a()};this.addPoint=function(e,g){h?(h=!1,b=e,c=g,d=e,f=g):(b=be?d:e,f=f>g?f:g);a()};this.add3Points= function(e,g,i,n,m,j){h?(h=!1,b=ei?e>m?e:m:i>m?i:m,f=g>n?g>j?g:j:n>j?n:j):(b=ei?e>m?e>d?e:d:m>d?m:d:i>m?i>d?i:d:m>d?m:d,f=g>n?g>j?g>f?g:f:j>f?j:f:n>j?n>f?n:f:j>f?j:f);a()};this.addRectangle=function(e){h?(h=!1,b=e.getLeft(),c=e.getTop(),d=e.getRight(),f=e.getBottom()):(b=be.getRight()?d:e.getRight(),f=f> e.getBottom()?f:e.getBottom());a()};this.inflate=function(e){b-=e;c-=e;d+=e;f+=e;a()};this.minSelf=function(e){b=b>e.getLeft()?b:e.getLeft();c=c>e.getTop()?c:e.getTop();d=d=0&&Math.min(f,a.getBottom())-Math.max(c,a.getTop())>=0};this.empty=function(){h=!0;f=d=c=b=0;a()};this.isEmpty=function(){return h}}; THREE.Math={clamp:function(a,b,c){return ac?c:a},clampBottom:function(a,b){return a=0&&f>=0&&g>=0&&h>=0?!0:e<0&&f<0||g<0&&h<0?!1:(e<0?c=Math.max(c,e/(e-f)):f<0&&(d=Math.min(d,e/(e-f))),g<0?c=Math.max(c,g/(g-h)):h<0&&(d=Math.min(d,g/(g-h))),dg&&h.positionScreen.z0&&C.z<1))g=P[S]=P[S]||new THREE.RenderableParticle,S++,F=g,F.x=C.x/C.w,F.y=C.y/C.w,F.z=C.z,F.rotation=G.rotation.z,F.scale.x=G.scale.x*Math.abs(F.x-(C.x+e.projectionMatrix.n11)/(C.w+e.projectionMatrix.n14)),F.scale.y=G.scale.y*Math.abs(F.y-(C.y+e.projectionMatrix.n22)/(C.w+e.projectionMatrix.n24)),F.material=G.material,z.elements.push(F);f&&z.elements.sort(c);return z}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?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,f=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-f),f=Math.sin(-f),e=Math.cos(c),c=Math.sin(c),g=a*b,h=d*f;this.w=g*e-h*c;this.x=g*c+h*e;this.y=d*b*e+a*f*c;this.z=a*f*e-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=a.n32-a.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=a.n13-a.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.n21-a.n12<0?-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);a===0?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,f=this.w,e=a.x,g=a.y,h=a.z,a=a.w;this.x=b*a+f*e+c*h-d*g;this.y=c*a+f*g+d*e-b*h;this.z=d*a+f*h+b*g-c*e;this.w=f*a-b*e-c*g-d*h;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,f=a.z,e=this.x,g=this.y,h=this.z,l=this.w,o=l*c+g*f-h*d,i=l*d+h*c-e*f,n=l*f+e*d-g*c,c=-e* c-g*d-h*f;b.x=o*l+c*-e+i*-h-n*-g;b.y=i*l+c*-g+n*-e-o*-h;b.z=n*l+c*-h+o*-g-i*-e;return b}}; THREE.Quaternion.slerp=function(a,b,c,d){var f=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;f<0?(c.w=-b.w,c.x=-b.x,c.y=-b.y,c.z=-b.z,f=-f):c.copy(b);if(Math.abs(f)>=1)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var e=Math.acos(f),f=Math.sqrt(1-f*f);if(Math.abs(f)<0.001)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)*e)/f;d=Math.sin(d*e)/f;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,f,e){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=f instanceof THREE.Color?f:new THREE.Color;this.vertexColors=f instanceof Array?f:[];this.vertexTangents=[];this.materialIndex=e;this.centroid=new THREE.Vector3}; THREE.Face4=function(a,b,c,d,f,e,g){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];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;c0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y, this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,c=this.vertices.length;bthis.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.ythis.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.zthis.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=0,b=0,c=this.vertices.length;b0&&(c(THREE.NormalBlending),b(1),f("rgba("+Math.floor(s.r*255)+","+Math.floor(s.g*255)+","+Math.floor(s.b*255)+","+N+")"),k.fillRect(Math.floor(X.getX()), Math.floor(X.getY()),Math.floor(X.getWidth()),Math.floor(X.getHeight()))),X.empty())};this.render=function(a,i){function n(a){var b,c,d,e;Y.setRGB(0,0,0);sa.setRGB(0,0,0);ta.setRGB(0,0,0);b=0;for(c=a.length;b>1,o=n.height>> 1,g=e.scale.x*j,l=e.scale.y*q,h=g*p,i=l*o,W.set(a.x-h,a.y-i,a.x+h,a.y+i),ka.intersects(W)&&(k.save(),k.translate(a.x,a.y),k.rotate(-e.rotation),k.scale(g,-l),k.translate(-p,-o),k.drawImage(n,0,0),k.restore())}else g instanceof THREE.ParticleCanvasMaterial&&(h=e.scale.x*j,i=e.scale.y*q,W.set(a.x-h,a.y-i,a.x+h,a.y+i),ka.intersects(W)&&(d(g.color.getContextStyle()),f(g.color.getContextStyle()),k.save(),k.translate(a.x,a.y),k.rotate(-e.rotation),k.scale(h,i),g.program(k),k.restore()))}function z(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(A!=a)k.lineWidth=A=a;a=g.linecap;if(C!=a)k.lineCap=C=a;a=g.linejoin;if(E!=a)k.lineJoin=E=a;d(g.color.getContextStyle());k.stroke();W.inflate(g.linewidth*2)}}function F(a,d,f,g,h,k,j,p){e.info.render.vertices+=3;e.info.render.faces++;b(p.opacity);c(p.blending);L=a.positionScreen.x;O=a.positionScreen.y; T=d.positionScreen.x;U=d.positionScreen.y;H=f.positionScreen.x;B=f.positionScreen.y;N(L,O,T,U,H,B);if(p instanceof THREE.MeshBasicMaterial)if(p.map)p.map.mapping instanceof THREE.UVMapping&&(aa=j.uvs[0],za(L,O,T,U,H,B,aa[g].u,aa[g].v,aa[h].u,aa[h].v,aa[k].u,aa[k].v,p.map));else if(p.envMap){if(p.envMap.mapping instanceof THREE.SphericalReflectionMapping)a=i.matrixWorldInverse,R.copy(j.vertexNormalsWorld[g]),Aa=(R.x*a.n11+R.y*a.n12+R.z*a.n13)*0.5+0.5,Ba=-(R.x*a.n21+R.y*a.n22+R.z*a.n23)*0.5+0.5,R.copy(j.vertexNormalsWorld[h]), Ca=(R.x*a.n11+R.y*a.n12+R.z*a.n13)*0.5+0.5,Da=-(R.x*a.n21+R.y*a.n22+R.z*a.n23)*0.5+0.5,R.copy(j.vertexNormalsWorld[k]),Ea=(R.x*a.n11+R.y*a.n12+R.z*a.n13)*0.5+0.5,Fa=-(R.x*a.n21+R.y*a.n22+R.z*a.n23)*0.5+0.5,za(L,O,T,U,H,B,Aa,Ba,Ca,Da,Ea,Fa,p.envMap)}else p.wireframe?ga(p.color,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ha(p.color);else if(p instanceof THREE.MeshLambertMaterial)p.map&&!p.wireframe&&(p.map.mapping instanceof THREE.UVMapping&&(aa=j.uvs[0],za(L,O,T,U,H,B,aa[g].u,aa[g].v, aa[h].u,aa[h].v,aa[k].u,aa[k].v,p.map)),c(THREE.SubtractiveBlending)),xa?!p.wireframe&&p.shading==THREE.SmoothShading&&j.vertexNormalsWorld.length==3?(y.r=w.r=x.r=Y.r,y.g=w.g=x.g=Y.g,y.b=w.b=x.b=Y.b,m(l,j.v1.positionWorld,j.vertexNormalsWorld[0],y),m(l,j.v2.positionWorld,j.vertexNormalsWorld[1],w),m(l,j.v3.positionWorld,j.vertexNormalsWorld[2],x),y.r=Math.max(0,Math.min(p.color.r*y.r,1)),y.g=Math.max(0,Math.min(p.color.g*y.g,1)),y.b=Math.max(0,Math.min(p.color.b*y.b,1)),w.r=Math.max(0,Math.min(p.color.r* w.r,1)),w.g=Math.max(0,Math.min(p.color.g*w.g,1)),w.b=Math.max(0,Math.min(p.color.b*w.b,1)),x.r=Math.max(0,Math.min(p.color.r*x.r,1)),x.g=Math.max(0,Math.min(p.color.g*x.g,1)),x.b=Math.max(0,Math.min(p.color.b*x.b,1)),I.r=(w.r+x.r)*0.5,I.g=(w.g+x.g)*0.5,I.b=(w.b+x.b)*0.5,ea=va(y,w,x,I),ma(L,O,T,U,H,B,0,0,1,0,0,1,ea)):(t.r=Y.r,t.g=Y.g,t.b=Y.b,m(l,j.centroidWorld,j.normalWorld,t),t.r=Math.max(0,Math.min(p.color.r*t.r,1)),t.g=Math.max(0,Math.min(p.color.g*t.g,1)),t.b=Math.max(0,Math.min(p.color.b*t.b, 1)),p.wireframe?ga(t,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ha(t)):p.wireframe?ga(p.color,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ha(p.color);else if(p instanceof THREE.MeshDepthMaterial)Z=i.near,fa=i.far,y.r=y.g=y.b=1-la(a.positionScreen.z,Z,fa),w.r=w.g=w.b=1-la(d.positionScreen.z,Z,fa),x.r=x.g=x.b=1-la(f.positionScreen.z,Z,fa),I.r=(w.r+x.r)*0.5,I.g=(w.g+x.g)*0.5,I.b=(w.b+x.b)*0.5,ea=va(y,w,x,I),ma(L,O,T,U,H,B,0,0,1,0,0,1,ea);else if(p instanceof THREE.MeshNormalMaterial)t.r= na(j.normalWorld.x),t.g=na(j.normalWorld.y),t.b=na(j.normalWorld.z),p.wireframe?ga(t,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ha(t)}function S(a,d,f,g,h,k,j,p,n){e.info.render.vertices+=4;e.info.render.faces++;b(p.opacity);c(p.blending);if(p.map||p.envMap)F(a,d,g,0,1,3,j,p,n),F(h,f,k,1,2,3,j,p,n);else if(L=a.positionScreen.x,O=a.positionScreen.y,T=d.positionScreen.x,U=d.positionScreen.y,H=f.positionScreen.x,B=f.positionScreen.y,Q=g.positionScreen.x,v=g.positionScreen.y,M=h.positionScreen.x, K=h.positionScreen.y,oa=k.positionScreen.x,G=k.positionScreen.y,p instanceof THREE.MeshBasicMaterial)P(L,O,T,U,H,B,Q,v),p.wireframe?ga(p.color,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ha(p.color);else if(p instanceof THREE.MeshLambertMaterial)xa?!p.wireframe&&p.shading==THREE.SmoothShading&&j.vertexNormalsWorld.length==4?(y.r=w.r=x.r=I.r=Y.r,y.g=w.g=x.g=I.g=Y.g,y.b=w.b=x.b=I.b=Y.b,m(l,j.v1.positionWorld,j.vertexNormalsWorld[0],y),m(l,j.v2.positionWorld,j.vertexNormalsWorld[1], w),m(l,j.v4.positionWorld,j.vertexNormalsWorld[3],x),m(l,j.v3.positionWorld,j.vertexNormalsWorld[2],I),y.r=Math.max(0,Math.min(p.color.r*y.r,1)),y.g=Math.max(0,Math.min(p.color.g*y.g,1)),y.b=Math.max(0,Math.min(p.color.b*y.b,1)),w.r=Math.max(0,Math.min(p.color.r*w.r,1)),w.g=Math.max(0,Math.min(p.color.g*w.g,1)),w.b=Math.max(0,Math.min(p.color.b*w.b,1)),x.r=Math.max(0,Math.min(p.color.r*x.r,1)),x.g=Math.max(0,Math.min(p.color.g*x.g,1)),x.b=Math.max(0,Math.min(p.color.b*x.b,1)),I.r=Math.max(0,Math.min(p.color.r* I.r,1)),I.g=Math.max(0,Math.min(p.color.g*I.g,1)),I.b=Math.max(0,Math.min(p.color.b*I.b,1)),ea=va(y,w,x,I),N(L,O,T,U,Q,v),ma(L,O,T,U,Q,v,0,0,1,0,0,1,ea),N(M,K,H,B,oa,G),ma(M,K,H,B,oa,G,1,0,1,1,0,1,ea)):(t.r=Y.r,t.g=Y.g,t.b=Y.b,m(l,j.centroidWorld,j.normalWorld,t),t.r=Math.max(0,Math.min(p.color.r*t.r,1)),t.g=Math.max(0,Math.min(p.color.g*t.g,1)),t.b=Math.max(0,Math.min(p.color.b*t.b,1)),P(L,O,T,U,H,B,Q,v),p.wireframe?ga(t,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ha(t)):(P(L,O, T,U,H,B,Q,v),p.wireframe?ga(p.color,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ha(p.color));else if(p instanceof THREE.MeshNormalMaterial)t.r=na(j.normalWorld.x),t.g=na(j.normalWorld.y),t.b=na(j.normalWorld.z),P(L,O,T,U,H,B,Q,v),p.wireframe?ga(t,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ha(t);else if(p instanceof THREE.MeshDepthMaterial)Z=i.near,fa=i.far,y.r=y.g=y.b=1-la(a.positionScreen.z,Z,fa),w.r=w.g=w.b=1-la(d.positionScreen.z,Z,fa),x.r=x.g=x.b=1-la(g.positionScreen.z, Z,fa),I.r=I.g=I.b=1-la(f.positionScreen.z,Z,fa),ea=va(y,w,x,I),N(L,O,T,U,Q,v),ma(L,O,T,U,Q,v,0,0,1,0,0,1,ea),N(M,K,H,B,oa,G),ma(M,K,H,B,oa,G,1,0,1,1,0,1,ea)}function N(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 P(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 ga(a,b,c,e){if(A!=b)k.lineWidth=A=b;if(C!=c)k.lineCap=C=c;if(E!=e)k.lineJoin=E=e;d(a.getContextStyle()); k.stroke();W.inflate(b*2)}function ha(a){f(a.getContextStyle());k.fill()}function za(a,b,c,d,e,g,h,i,j,l,n,o,m){if(m.image.width!=0){if(m.needsUpdate==!0||ja[m.id]==void 0){var q=m.wrapS==THREE.RepeatWrapping,r=m.wrapT==THREE.RepeatWrapping;ja[m.id]=k.createPattern(m.image,q&&r?"repeat":q&&!r?"repeat-x":!q&&r?"repeat-y":"no-repeat");m.needsUpdate=!1}f(ja[m.id]);var q=m.offset.x/m.repeat.x,r=m.offset.y/m.repeat.y,s=(m.image.width-1)*m.repeat.x,m=(m.image.height-1)*m.repeat.y,h=(h+q)*s,i=(i+r)*m,j= (j+q)*s,l=(l+r)*m,n=(n+q)*s,o=(o+r)*m;c-=a;d-=b;e-=a;g-=b;j-=h;l-=i;n-=h;o-=i;q=1/(j*o-n*l);m=(o*c-l*e)*q;l=(o*d-l*g)*q;c=(j*e-n*c)*q;d=(j*g-n*d)*q;a=a-m*h-c*i;b=b-l*h-d*i;k.save();k.transform(m,l,c,d,a,b);k.fill();k.restore()}}function ma(a,b,c,d,e,f,g,h,i,j,l,m,n){var o,q;o=n.width-1;q=n.height-1;g*=o;h*=q;i*=o;j*=q;l*=o;m*=q;c-=a;d-=b;e-=a;f-=b;i-=g;j-=h;l-=g;m-=h;q=1/(i*m-l*j);o=(m*c-j*e)*q;j=(m*d-j*f)*q;c=(i*e-l*c)*q;d=(i*f-l*d)*q;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=~~(a.r*255),f=~~(a.g*255),a=~~(a.b*255),g=~~(b.r*255),h=~~(b.g*255),b=~~(b.b*255),i=~~(c.r*255),j=~~(c.g*255),c=~~(c.b*255),k=~~(d.r*255),l=~~(d.g*255),d=~~(d.b*255);ba[0]=e<0?0:e>255?255:e;ba[1]=f<0?0:f>255?255:f;ba[2]=a<0?0:a>255?255:a;ba[4]=g<0?0:g>255?255:g;ba[5]=h<0?0:h>255?255:h;ba[6]=b<0?0:b>255?255:b;ba[8]=i<0?0:i>255?255:i;ba[9]=j<0?0:j>255?255:j;ba[10]=c<0?0:c>255?255:c;ba[12]=k<0?0:k>255?255:k;ba[13]=l<0?0:l>255?255:l;ba[14]=d<0? 0:d>255?255:d;qa.putImageData(ya,0,0);ua.drawImage(pa,0,0);return ra}function la(a,b,c){a=(a-b)/(c-b);return a*a*(3-2*a)}function na(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function ia(a,b){var c=b.x-a.x,d=b.y-a.y,e=c*c+d*d;e!=0&&(e=1/Math.sqrt(e),c*=e,d*=e,b.x+=c,b.y+=d,a.x-=c,a.y-=d)}var wa,Ga,V,ca;this.autoClear?this.clear():k.setTransform(1,0,0,-1,j,q);e.info.render.vertices=0;e.info.render.faces=0;g=o.projectScene(a,i,this.sortElements);h=g.elements;l=g.lights;(xa=l.length>0)&&n(l);wa=0;for(Ga=h.length;wa< Ga;wa++)if(V=h[wa],ca=V.material,ca=ca instanceof THREE.MeshFaceMaterial?V.faceMaterial:ca,!(ca==null||ca.opacity==0)){W.empty();if(V instanceof THREE.RenderableParticle)u=V,u.x*=j,u.y*=q,s(u,V,ca,a);else if(V instanceof THREE.RenderableLine)u=V.v1,r=V.v2,u.positionScreen.x*=j,u.positionScreen.y*=q,r.positionScreen.x*=j,r.positionScreen.y*=q,W.addPoint(u.positionScreen.x,u.positionScreen.y),W.addPoint(r.positionScreen.x,r.positionScreen.y),ka.intersects(W)&&z(u,r,V,ca,a);else if(V instanceof THREE.RenderableFace3)u= V.v1,r=V.v2,D=V.v3,u.positionScreen.x*=j,u.positionScreen.y*=q,r.positionScreen.x*=j,r.positionScreen.y*=q,D.positionScreen.x*=j,D.positionScreen.y*=q,ca.overdraw&&(ia(u.positionScreen,r.positionScreen),ia(r.positionScreen,D.positionScreen),ia(D.positionScreen,u.positionScreen)),W.add3Points(u.positionScreen.x,u.positionScreen.y,r.positionScreen.x,r.positionScreen.y,D.positionScreen.x,D.positionScreen.y),ka.intersects(W)&&F(u,r,D,0,1,2,V,ca,a);else if(V instanceof THREE.RenderableFace4)u=V.v1,r=V.v2, D=V.v3,J=V.v4,u.positionScreen.x*=j,u.positionScreen.y*=q,r.positionScreen.x*=j,r.positionScreen.y*=q,D.positionScreen.x*=j,D.positionScreen.y*=q,J.positionScreen.x*=j,J.positionScreen.y*=q,$.positionScreen.copy(r.positionScreen),da.positionScreen.copy(J.positionScreen),ca.overdraw&&(ia(u.positionScreen,r.positionScreen),ia(r.positionScreen,J.positionScreen),ia(J.positionScreen,u.positionScreen),ia(D.positionScreen,$.positionScreen),ia(D.positionScreen,da.positionScreen)),W.addPoint(u.positionScreen.x, u.positionScreen.y),W.addPoint(r.positionScreen.x,r.positionScreen.y),W.addPoint(D.positionScreen.x,D.positionScreen.y),W.addPoint(J.positionScreen.x,J.positionScreen.y),ka.intersects(W)&&S(u,r,D,J,$,da,V,ca,a);X.addRectangle(W)}k.setTransform(1,0,0,1,0,0)}};THREE.RenderableVertex=function(){this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.visible=!0};THREE.RenderableVertex.prototype.copy=function(a){this.positionWorld.copy(a.positionWorld);this.positionScreen.copy(a.positionScreen)}; THREE.RenderableFace3=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterial=this.material=null;this.uvs=[[]];this.z=null}; THREE.RenderableFace4=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.v4=new THREE.RenderableVertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterial=this.material=null;this.uvs=[[]];this.z=null};THREE.RenderableObject=function(){this.z=this.object=null}; THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.material=null};