// 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.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);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){function c(a,b,c){h=h.copy(c).subSelf(a);l=h.dot(b);if(l<=0)return null;q=j.copy(a).addSelf(n.copy(b).multiplyScalar(l));return k=c.distanceTo(q)}function d(a,b,c,d){h.copy(d).subSelf(b);j.copy(c).subSelf(b);n.copy(a).subSelf(b);s=h.dot(h);Q=h.dot(j);D=h.dot(n);I=j.dot(j);N=j.dot(n);w=1/(s*I-Q*Q);F=(I*D-Q*N)*w;z=(s*N-Q*D)*w;return F>=0&&z>=0&&F+z<1}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=[];b=0;for(c=a.length;bh.scale.x)return[];k={distance:l,point:h.position,face:null,object:h};j.push(k)}else if(h instanceof THREE.Mesh){l=c(this.origin,this.direction,h.matrixWorld.getPosition());if(l===null||l>h.geometry.boundingSphere.radius*Math.max(h.scale.x,Math.max(h.scale.y,h.scale.z)))return j;var S,q=h.geometry,E=q.vertices,G,H=new THREE.Vector3;h.matrixRotationWorld.extractRotation(h.matrixWorld);l=0;for(n= q.faces.length;l0:S<0)))if(S=o.dot(m.sub(f, a))/S,H.add(a,b.multiplyScalar(S)),k instanceof THREE.Face3)d(H,f,e,g)&&(k={distance:a.distanceTo(H),point:H.clone(),face:k,object:h},j.push(k));else if(k instanceof THREE.Face4&&(d(H,f,e,i)||d(H,e,g,i)))k={distance:a.distanceTo(H),point:H.clone(),face:k,object:h},j.push(k)}return j};var h=new THREE.Vector3,j=new THREE.Vector3,n=new THREE.Vector3,l,q,k,s,Q,D,I,N,w,F,z}; THREE.Rectangle=function(){function a(){e=d-b;g=f-c}var b,c,d,f,e,g,i=!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,h,j){i=!1;b=e;c=g;d=h;f=j;a()};this.addPoint=function(e,g){i?(i=!1,b=e,c=g,d=e,f=g):(b=be?d:e,f=f>g?f:g);a()};this.add3Points= function(e,g,h,j,n,l){i?(i=!1,b=eh?e>n?e:n:h>n?h:n,f=g>j?g>l?g:l:j>l?j:l):(b=eh?e>n?e>d?e:d:n>d?n:d:h>n?h>d?h:d:n>d?n:d,f=g>j?g>l?g>f?g:f:l>f?l:f:j>l?j>f?j:f:l>f?l:f);a()};this.addRectangle=function(e){i?(i=!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(){i=!0;f=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 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&&i.positionScreen.z0&&z.z<1))g=N[I]=N[I]||new THREE.RenderableParticle,I++,D=g,D.x=z.x/z.w,D.y=z.y/z.w,D.z=z.z,D.rotation=K.rotation.z,D.scale.x=K.scale.x*Math.abs(D.x-(z.x+e.projectionMatrix.n11)/(z.w+e.projectionMatrix.n14)),D.scale.y=K.scale.y*Math.abs(D.y-(z.y+e.projectionMatrix.n22)/(z.w+e.projectionMatrix.n24)),D.material=K.material,w.elements.push(D); f&&w.elements.sort(c);return w}};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,i=d*f;this.w=g*e-i*c;this.x=g*c+i*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,i=a.z,a=a.w;this.x=b*a+f*e+c*i-d*g;this.y=c*a+f*g+d*e-b*i;this.z=d*a+f*i+b*g-c*e;this.w=f*a-b*e-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,f=a.z,e=this.x,g=this.y,i=this.z,m=this.w,o=m*c+g*f-i*d,h=m*d+i*c-e*f,j=m*f+e*d-g*c,c=-e* c-g*d-i*f;b.x=o*m+c*-e+h*-i-j*-g;b.y=h*m+c*-g+j*-e-o*-i;b.z=j*m+c*-i+o*-g-h*-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.0010)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)+","+Q+")"),k.fillRect(Math.floor(Z.getX()), Math.floor(Z.getY()),Math.floor(Z.getWidth()),Math.floor(Z.getHeight()))),Z.empty())};this.render=function(a,h){function j(a){var b,c,d,e;$.setRGB(0,0,0);sa.setRGB(0,0,0);ta.setRGB(0,0,0);b=0;for(c=a.length;b>1,o=j.height>> 1,g=e.scale.x*l,m=e.scale.y*q,h=g*p,i=m*o,X.set(a.x-h,a.y-i,a.x+h,a.y+i),la.intersects(X)&&(k.save(),k.translate(a.x,a.y),k.rotate(-e.rotation),k.scale(g,-m),k.translate(-p,-o),k.drawImage(j,0,0),k.restore())}else g instanceof THREE.ParticleCanvasMaterial&&(h=e.scale.x*l,i=e.scale.y*q,X.set(a.x-h,a.y-i,a.x+h,a.y+i),la.intersects(X)&&(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 w(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(F!=a)k.lineWidth=F=a;a=g.linecap;if(z!=a)k.lineCap=z=a;a=g.linejoin;if(J!=a)k.lineJoin=J=a;d(g.color.getContextStyle());k.stroke();X.inflate(g.linewidth*2)}}function D(a,d,f,g,i,k,j,p){e.info.render.vertices+=3;e.info.render.faces++;b(p.opacity);c(p.blending);E=a.positionScreen.x;G=a.positionScreen.y; H=d.positionScreen.x;Y=d.positionScreen.y;L=f.positionScreen.x;B=f.positionScreen.y;I(E,G,H,Y,L,B);if(p instanceof THREE.MeshBasicMaterial)if(p.map)p.map.mapping instanceof THREE.UVMapping&&(ba=j.uvs[0],za(E,G,H,Y,L,B,ba[g].u,ba[g].v,ba[i].u,ba[i].v,ba[k].u,ba[k].v,p.map));else if(p.envMap){if(p.envMap.mapping instanceof THREE.SphericalReflectionMapping)a=h.matrixWorldInverse,U.copy(j.vertexNormalsWorld[g]),Aa=(U.x*a.n11+U.y*a.n12+U.z*a.n13)*0.5+0.5,Ba=-(U.x*a.n21+U.y*a.n22+U.z*a.n23)*0.5+0.5,U.copy(j.vertexNormalsWorld[i]), Ca=(U.x*a.n11+U.y*a.n12+U.z*a.n13)*0.5+0.5,Da=-(U.x*a.n21+U.y*a.n22+U.z*a.n23)*0.5+0.5,U.copy(j.vertexNormalsWorld[k]),Ea=(U.x*a.n11+U.y*a.n12+U.z*a.n13)*0.5+0.5,Fa=-(U.x*a.n21+U.y*a.n22+U.z*a.n23)*0.5+0.5,za(E,G,H,Y,L,B,Aa,Ba,Ca,Da,Ea,Fa,p.envMap)}else p.wireframe?ha(p.color,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ia(p.color);else if(p instanceof THREE.MeshLambertMaterial)p.map&&!p.wireframe&&(p.map.mapping instanceof THREE.UVMapping&&(ba=j.uvs[0],za(E,G,H,Y,L,B,ba[g].u,ba[g].v, ba[i].u,ba[i].v,ba[k].u,ba[k].v,p.map)),c(THREE.SubtractiveBlending)),xa?!p.wireframe&&p.shading==THREE.SmoothShading&&j.vertexNormalsWorld.length==3?(A.r=x.r=y.r=$.r,A.g=x.g=y.g=$.g,A.b=x.b=y.b=$.b,n(m,j.v1.positionWorld,j.vertexNormalsWorld[0],A),n(m,j.v2.positionWorld,j.vertexNormalsWorld[1],x),n(m,j.v3.positionWorld,j.vertexNormalsWorld[2],y),A.r=Math.max(0,Math.min(p.color.r*A.r,1)),A.g=Math.max(0,Math.min(p.color.g*A.g,1)),A.b=Math.max(0,Math.min(p.color.b*A.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)),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)),M.r=(x.r+y.r)*0.5,M.g=(x.g+y.g)*0.5,M.b=(x.b+y.b)*0.5,fa=va(A,x,y,M),na(E,G,H,Y,L,B,0,0,1,0,0,1,fa)):(t.r=$.r,t.g=$.g,t.b=$.b,n(m,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?ha(t,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ia(t)):p.wireframe?ha(p.color,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ia(p.color);else if(p instanceof THREE.MeshDepthMaterial)aa=h.near,ga=h.far,A.r=A.g=A.b=1-ma(a.positionScreen.z,aa,ga),x.r=x.g=x.b=1-ma(d.positionScreen.z,aa,ga),y.r=y.g=y.b=1-ma(f.positionScreen.z,aa,ga),M.r=(x.r+y.r)*0.5,M.g=(x.g+y.g)*0.5,M.b=(x.b+y.b)*0.5,fa=va(A,x,y,M),na(E,G,H,Y,L,B,0,0,1,0,0,1,fa);else if(p instanceof THREE.MeshNormalMaterial)t.r= oa(j.normalWorld.x),t.g=oa(j.normalWorld.y),t.b=oa(j.normalWorld.z),p.wireframe?ha(t,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ia(t)}function Q(a,d,f,g,i,k,j,p,l){e.info.render.vertices+=4;e.info.render.faces++;b(p.opacity);c(p.blending);if(p.map||p.envMap)D(a,d,g,0,1,3,j,p,l),D(i,f,k,1,2,3,j,p,l);else if(E=a.positionScreen.x,G=a.positionScreen.y,H=d.positionScreen.x,Y=d.positionScreen.y,L=f.positionScreen.x,B=f.positionScreen.y,T=g.positionScreen.x,v=g.positionScreen.y,R=i.positionScreen.x, P=i.positionScreen.y,W=k.positionScreen.x,K=k.positionScreen.y,p instanceof THREE.MeshBasicMaterial)N(E,G,H,Y,L,B,T,v),p.wireframe?ha(p.color,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ia(p.color);else if(p instanceof THREE.MeshLambertMaterial)xa?!p.wireframe&&p.shading==THREE.SmoothShading&&j.vertexNormalsWorld.length==4?(A.r=x.r=y.r=M.r=$.r,A.g=x.g=y.g=M.g=$.g,A.b=x.b=y.b=M.b=$.b,n(m,j.v1.positionWorld,j.vertexNormalsWorld[0],A),n(m,j.v2.positionWorld,j.vertexNormalsWorld[1],x), n(m,j.v4.positionWorld,j.vertexNormalsWorld[3],y),n(m,j.v3.positionWorld,j.vertexNormalsWorld[2],M),A.r=Math.max(0,Math.min(p.color.r*A.r,1)),A.g=Math.max(0,Math.min(p.color.g*A.g,1)),A.b=Math.max(0,Math.min(p.color.b*A.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)),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)),M.r=Math.max(0,Math.min(p.color.r* M.r,1)),M.g=Math.max(0,Math.min(p.color.g*M.g,1)),M.b=Math.max(0,Math.min(p.color.b*M.b,1)),fa=va(A,x,y,M),I(E,G,H,Y,T,v),na(E,G,H,Y,T,v,0,0,1,0,0,1,fa),I(R,P,L,B,W,K),na(R,P,L,B,W,K,1,0,1,1,0,1,fa)):(t.r=$.r,t.g=$.g,t.b=$.b,n(m,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)),N(E,G,H,Y,L,B,T,v),p.wireframe?ha(t,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ia(t)):(N(E,G,H, Y,L,B,T,v),p.wireframe?ha(p.color,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ia(p.color));else if(p instanceof THREE.MeshNormalMaterial)t.r=oa(j.normalWorld.x),t.g=oa(j.normalWorld.y),t.b=oa(j.normalWorld.z),N(E,G,H,Y,L,B,T,v),p.wireframe?ha(t,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):ia(t);else if(p instanceof THREE.MeshDepthMaterial)aa=h.near,ga=h.far,A.r=A.g=A.b=1-ma(a.positionScreen.z,aa,ga),x.r=x.g=x.b=1-ma(d.positionScreen.z,aa,ga),y.r=y.g=y.b=1-ma(g.positionScreen.z, aa,ga),M.r=M.g=M.b=1-ma(f.positionScreen.z,aa,ga),fa=va(A,x,y,M),I(E,G,H,Y,T,v),na(E,G,H,Y,T,v,0,0,1,0,0,1,fa),I(R,P,L,B,W,K),na(R,P,L,B,W,K,1,0,1,1,0,1,fa)}function I(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 N(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 ha(a,b,c,e){if(F!=b)k.lineWidth=F=b;if(z!=c)k.lineCap=z=c;if(J!=e)k.lineJoin=J=e;d(a.getContextStyle()); k.stroke();X.inflate(b*2)}function ia(a){f(a.getContextStyle());k.fill()}function za(a,b,c,d,e,g,h,i,j,l,m,o,n){if(n.image.width!=0){if(n.needsUpdate==!0||ka[n.id]==void 0){var q=n.wrapS==THREE.RepeatWrapping,r=n.wrapT==THREE.RepeatWrapping;ka[n.id]=k.createPattern(n.image,q&&r?"repeat":q&&!r?"repeat-x":!q&&r?"repeat-y":"no-repeat");n.needsUpdate=!1}f(ka[n.id]);var q=n.offset.x/n.repeat.x,r=n.offset.y/n.repeat.y,s=(n.image.width-1)*n.repeat.x,n=(n.image.height-1)*n.repeat.y,h=(h+q)*s,i=(i+r)*n,j= (j+q)*s,l=(l+r)*n,m=(m+q)*s,o=(o+r)*n;c-=a;d-=b;e-=a;g-=b;j-=h;l-=i;m-=h;o-=i;q=1/(j*o-m*l);n=(o*c-l*e)*q;l=(o*d-l*g)*q;c=(j*e-m*c)*q;d=(j*g-m*d)*q;a=a-n*h-c*i;b=b-l*h-d*i;k.save();k.transform(n,l,c,d,a,b);k.fill();k.restore()}}function na(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);ca[0]=e<0?0:e>255?255:e;ca[1]=f<0?0:f>255?255:f;ca[2]=a<0?0:a>255?255:a;ca[4]=g<0?0:g>255?255:g;ca[5]=h<0?0:h>255?255:h;ca[6]=b<0?0:b>255?255:b;ca[8]=i<0?0:i>255?255:i;ca[9]=j<0?0:j>255?255:j;ca[10]=c<0?0:c>255?255:c;ca[12]=k<0?0:k>255?255:k;ca[13]=l<0?0:l>255?255:l;ca[14]=d<0? 0:d>255?255:d;qa.putImageData(ya,0,0);ua.drawImage(pa,0,0);return ra}function ma(a,b,c){a=(a-b)/(c-b);return a*a*(3-2*a)}function oa(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function ja(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,da;this.autoClear?this.clear():k.setTransform(1,0,0,-1,l,q);e.info.render.vertices=0;e.info.render.faces=0;g=o.projectScene(a,h,this.sortElements);i=g.elements;m=g.lights;(xa=m.length>0)&&j(m);wa=0;for(Ga=i.length;wa< Ga;wa++)if(V=i[wa],da=V.material,da=da instanceof THREE.MeshFaceMaterial?V.faceMaterial:da,!(da==null||da.opacity==0)){X.empty();if(V instanceof THREE.RenderableParticle)u=V,u.x*=l,u.y*=q,s(u,V,da,a);else if(V instanceof THREE.RenderableLine)u=V.v1,r=V.v2,u.positionScreen.x*=l,u.positionScreen.y*=q,r.positionScreen.x*=l,r.positionScreen.y*=q,X.addPoint(u.positionScreen.x,u.positionScreen.y),X.addPoint(r.positionScreen.x,r.positionScreen.y),la.intersects(X)&&w(u,r,V,da,a);else if(V instanceof THREE.RenderableFace3)u= V.v1,r=V.v2,C=V.v3,u.positionScreen.x*=l,u.positionScreen.y*=q,r.positionScreen.x*=l,r.positionScreen.y*=q,C.positionScreen.x*=l,C.positionScreen.y*=q,da.overdraw&&(ja(u.positionScreen,r.positionScreen),ja(r.positionScreen,C.positionScreen),ja(C.positionScreen,u.positionScreen)),X.add3Points(u.positionScreen.x,u.positionScreen.y,r.positionScreen.x,r.positionScreen.y,C.positionScreen.x,C.positionScreen.y),la.intersects(X)&&D(u,r,C,0,1,2,V,da,a);else if(V instanceof THREE.RenderableFace4)u=V.v1,r=V.v2, C=V.v3,O=V.v4,u.positionScreen.x*=l,u.positionScreen.y*=q,r.positionScreen.x*=l,r.positionScreen.y*=q,C.positionScreen.x*=l,C.positionScreen.y*=q,O.positionScreen.x*=l,O.positionScreen.y*=q,S.positionScreen.copy(r.positionScreen),ea.positionScreen.copy(O.positionScreen),da.overdraw&&(ja(u.positionScreen,r.positionScreen),ja(r.positionScreen,O.positionScreen),ja(O.positionScreen,u.positionScreen),ja(C.positionScreen,S.positionScreen),ja(C.positionScreen,ea.positionScreen)),X.addPoint(u.positionScreen.x, u.positionScreen.y),X.addPoint(r.positionScreen.x,r.positionScreen.y),X.addPoint(C.positionScreen.x,C.positionScreen.y),X.addPoint(O.positionScreen.x,O.positionScreen.y),la.intersects(X)&&Q(u,r,C,O,S,ea,V,da,a);Z.addRectangle(X)}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};