// ThreeCanvas.js r47dev - 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,e,f;if(c===0)this.r=this.g=this.b=0;else switch(d=Math.floor(a*6),e=a*6-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(this.r*255)<<16^Math.floor(this.g*255)<<8^Math.floor(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.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;a<6;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;e<6;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);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.sub(c,a);p=h.dot(b);if(p<=0)return null;i=m.add(a,o.copy(b).multiplyScalar(p));return q=c.distanceTo(i)}function d(a,b,c,d){h.sub(d,b);m.sub(c,b);o.sub(a,b);F=h.dot(h);x=h.dot(m);I=h.dot(o);G=m.dot(m);r=m.dot(o);C=1/(F*G-x*x);y=(G*I-x*r)*C;D=(F*r-x*I)*C;return y>=0&&D>=0&&y+D<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;bi.scale.x)return[];h={distance:m,point:i.position,face:null,object:i};o.push(h)}else if(i instanceof THREE.Mesh){m=c(this.origin,this.direction,i.matrixWorld.getPosition());if(m===null||m>i.geometry.boundingSphere.radius*Math.max(i.scale.x,Math.max(i.scale.y,i.scale.z)))return o;var U,J=i.geometry,K=J.vertices,H;i.matrixRotationWorld.extractRotation(i.matrixWorld);m=0;for(p=J.faces.length;m0:U<0)))if(U=k.dot(n.sub(e,a))/U,l.add(a,b.multiplyScalar(U)),h instanceof THREE.Face3)d(l, e,f,g)&&(h={distance:a.distanceTo(l),point:l.clone(),face:h,object:i},o.push(h));else if(h instanceof THREE.Face4&&(d(l,e,f,j)||d(l,f,g,j)))h={distance:a.distanceTo(l),point:l.clone(),face:h,object:i},o.push(h)}return o};var h=new THREE.Vector3,m=new THREE.Vector3,o=new THREE.Vector3,p,i,q,F,x,I,G,r,C,y,D}; THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,j=!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,h){j=!1;b=f;c=g;d=l;e=h;a()};this.addPoint=function(f,g){j?(j=!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,h,m,o){j?(j=!1,b=fl?f>m?f:m:l>m?l:m,e=g>h?g>o?g:o:h>o?h:o):(b=fl?f>m?f>d?f:d:m>d?m:d:l>m?l>d?l:d:m>d?m:d,e=g>h?g>o?g>e?g:e:o>e?o:e:h>o?h>e?h:e:o>e?o:e);a()};this.addRectangle=function(f){j?(j=!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())return!1;if(ea.getBottom())return!1;return!0};this.empty=function(){j=!0;e=d=c=b=0;a()};this.isEmpty=function(){return j}}; THREE.Math={clamp:function(a,b,c){return ac?c:a},clampBottom:function(a,b){return a=0&&f>=0&&g>=0&&j>=0?!0:e<0&&f<0||g<0&&j<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-j)):j<0&&(d=Math.min(d,g/(g-j))),dg&&j.positionScreen.z0&&y.z<1))g=G[I]=G[I]||new THREE.RenderableParticle,I++,x=g,x.x=y.x/y.w,x.y=y.y/y.w,x.z=y.z,x.rotation= L.rotation.z,x.scale.x=L.scale.x*Math.abs(x.x-(y.x+e.projectionMatrix.n11)/(y.w+e.projectionMatrix.n14)),x.scale.y=L.scale.y*Math.abs(x.y-(y.y+e.projectionMatrix.n22)/(y.w+e.projectionMatrix.n24)),x.material=L.material,r.elements.push(x);f&&r.elements.sort(c);return r}};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,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,j=d*e;this.w=g*f-j*c;this.x=g*c+j*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=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,e=this.w,f=a.x,g=a.y,j=a.z,a=a.w;this.x=b*a+e*f+c*j-d*g;this.y=c*a+e*g+d*f-b*j;this.z=d*a+e*j+b*g-c*f;this.w=e*a-b*f-c*g-d*j;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,j=this.z,n=this.w,k=n*c+g*e-j*d,l=n*d+j*c-f*e,h=n*e+f*d-g*c,c=-f* c-g*d-j*e;b.x=k*n+c*-f+l*-j-h*-g;b.y=l*n+c*-g+h*-f-k*-j;b.z=h*n+c*-j+k*-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;e<0?(c.w=-b.w,c.x=-b.x,c.y=-b.y,c.z=-b.z,e=-e):c.copy(b);if(Math.abs(e)>=1)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(Math.abs(e)<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)*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;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),e("rgba("+Math.floor(q.r*255)+","+Math.floor(q.g*255)+","+Math.floor(q.b*255)+","+F+")"),i.fillRect(Math.floor(Y.getX()), Math.floor(Y.getY()),Math.floor(Y.getWidth()),Math.floor(Y.getHeight()))),Y.empty())};this.render=function(a,l){function h(a){var b,c,d,e;Z.setRGB(0,0,0);sa.setRGB(0,0,0);ta.setRGB(0,0,0);b=0;for(c=a.length;b>1,n=h.height>> 1,g=f.scale.x*o,k=f.scale.y*p,j=g*za,l=k*n,W.set(a.x-j,a.y-l,a.x+j,a.y+l),la.intersects(W)&&(i.save(),i.translate(a.x,a.y),i.rotate(-f.rotation),i.scale(g,-k),i.translate(-za,-n),i.drawImage(h,0,0),i.restore())}else g instanceof THREE.ParticleCanvasMaterial&&(j=f.scale.x*o,l=f.scale.y*p,W.set(a.x-j,a.y-l,a.x+j,a.y+l),la.intersects(W)&&(d(g.color.getContextStyle()),e(g.color.getContextStyle()),i.save(),i.translate(a.x,a.y),i.rotate(-f.rotation),i.scale(j,l),g.program(i),i.restore()))}function r(a, e,f,g){b(g.opacity);c(g.blending);i.beginPath();i.moveTo(a.positionScreen.x,a.positionScreen.y);i.lineTo(e.positionScreen.x,e.positionScreen.y);i.closePath();if(g instanceof THREE.LineBasicMaterial){a=g.linewidth;if(C!=a)i.lineWidth=C=a;a=g.linecap;if(y!=a)i.lineCap=y=a;a=g.linejoin;if(D!=a)i.lineJoin=D=a;d(g.color.getContextStyle());i.stroke();W.inflate(g.linewidth*2)}}function x(a,d,e,g,j,i,k,h){f.info.render.vertices+=3;f.info.render.faces++;b(h.opacity);c(h.blending);J=a.positionScreen.x;K=a.positionScreen.y; H=d.positionScreen.x;X=d.positionScreen.y;M=e.positionScreen.x;B=e.positionScreen.y;F(J,K,H,X,M,B);if(h instanceof THREE.MeshBasicMaterial)if(h.map)h.map.mapping instanceof THREE.UVMapping&&(aa=k.uvs[0],Aa(J,K,H,X,M,B,aa[g].u,aa[g].v,aa[j].u,aa[j].v,aa[i].u,aa[i].v,h.map));else if(h.envMap){if(h.envMap.mapping instanceof THREE.SphericalReflectionMapping)a=l.matrixWorldInverse,S.copy(k.vertexNormalsWorld[g]),Ba=(S.x*a.n11+S.y*a.n12+S.z*a.n13)*0.5+0.5,Ca=-(S.x*a.n21+S.y*a.n22+S.z*a.n23)*0.5+0.5,S.copy(k.vertexNormalsWorld[j]), Da=(S.x*a.n11+S.y*a.n12+S.z*a.n13)*0.5+0.5,Ea=-(S.x*a.n21+S.y*a.n22+S.z*a.n23)*0.5+0.5,S.copy(k.vertexNormalsWorld[i]),Fa=(S.x*a.n11+S.y*a.n12+S.z*a.n13)*0.5+0.5,Ga=-(S.x*a.n21+S.y*a.n22+S.z*a.n23)*0.5+0.5,Aa(J,K,H,X,M,B,Ba,Ca,Da,Ea,Fa,Ga,h.envMap)}else h.wireframe?ia(h.color,h.wireframeLinewidth,h.wireframeLinecap,h.wireframeLinejoin):ha(h.color);else if(h instanceof THREE.MeshLambertMaterial)h.map&&!h.wireframe&&(h.map.mapping instanceof THREE.UVMapping&&(aa=k.uvs[0],Aa(J,K,H,X,M,B,aa[g].u,aa[g].v, aa[j].u,aa[j].v,aa[i].u,aa[i].v,h.map)),c(THREE.SubtractiveBlending)),xa?!h.wireframe&&h.shading==THREE.SmoothShading&&k.vertexNormalsWorld.length==3?(z.r=v.r=w.r=Z.r,z.g=v.g=w.g=Z.g,z.b=v.b=w.b=Z.b,m(n,k.v1.positionWorld,k.vertexNormalsWorld[0],z),m(n,k.v2.positionWorld,k.vertexNormalsWorld[1],v),m(n,k.v3.positionWorld,k.vertexNormalsWorld[2],w),z.r=Math.max(0,Math.min(h.color.r*z.r,1)),z.g=Math.max(0,Math.min(h.color.g*z.g,1)),z.b=Math.max(0,Math.min(h.color.b*z.b,1)),v.r=Math.max(0,Math.min(h.color.r* v.r,1)),v.g=Math.max(0,Math.min(h.color.g*v.g,1)),v.b=Math.max(0,Math.min(h.color.b*v.b,1)),w.r=Math.max(0,Math.min(h.color.r*w.r,1)),w.g=Math.max(0,Math.min(h.color.g*w.g,1)),w.b=Math.max(0,Math.min(h.color.b*w.b,1)),N.r=(v.r+w.r)*0.5,N.g=(v.g+w.g)*0.5,N.b=(v.b+w.b)*0.5,da=va(z,v,w,N),na(J,K,H,X,M,B,0,0,1,0,0,1,da)):(s.r=Z.r,s.g=Z.g,s.b=Z.b,m(n,k.centroidWorld,k.normalWorld,s),s.r=Math.max(0,Math.min(h.color.r*s.r,1)),s.g=Math.max(0,Math.min(h.color.g*s.g,1)),s.b=Math.max(0,Math.min(h.color.b*s.b, 1)),h.wireframe?ia(s,h.wireframeLinewidth,h.wireframeLinecap,h.wireframeLinejoin):ha(s)):h.wireframe?ia(h.color,h.wireframeLinewidth,h.wireframeLinecap,h.wireframeLinejoin):ha(h.color);else if(h instanceof THREE.MeshDepthMaterial)fa=l.near,ga=l.far,z.r=z.g=z.b=1-ma(a.positionScreen.z,fa,ga),v.r=v.g=v.b=1-ma(d.positionScreen.z,fa,ga),w.r=w.g=w.b=1-ma(e.positionScreen.z,fa,ga),N.r=(v.r+w.r)*0.5,N.g=(v.g+w.g)*0.5,N.b=(v.b+w.b)*0.5,da=va(z,v,w,N),na(J,K,H,X,M,B,0,0,1,0,0,1,da);else if(h instanceof THREE.MeshNormalMaterial)s.r= oa(k.normalWorld.x),s.g=oa(k.normalWorld.y),s.b=oa(k.normalWorld.z),h.wireframe?ia(s,h.wireframeLinewidth,h.wireframeLinecap,h.wireframeLinejoin):ha(s)}function I(a,d,e,g,h,j,k,i,o){f.info.render.vertices+=4;f.info.render.faces++;b(i.opacity);c(i.blending);if(i.map||i.envMap)x(a,d,g,0,1,3,k,i,o),x(h,e,j,1,2,3,k,i,o);else if(J=a.positionScreen.x,K=a.positionScreen.y,H=d.positionScreen.x,X=d.positionScreen.y,M=e.positionScreen.x,B=e.positionScreen.y,R=g.positionScreen.x,u=g.positionScreen.y,Q=h.positionScreen.x, P=h.positionScreen.y,V=j.positionScreen.x,L=j.positionScreen.y,i instanceof THREE.MeshBasicMaterial)G(J,K,H,X,M,B,R,u),i.wireframe?ia(i.color,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(i.color);else if(i instanceof THREE.MeshLambertMaterial)xa?!i.wireframe&&i.shading==THREE.SmoothShading&&k.vertexNormalsWorld.length==4?(z.r=v.r=w.r=N.r=Z.r,z.g=v.g=w.g=N.g=Z.g,z.b=v.b=w.b=N.b=Z.b,m(n,k.v1.positionWorld,k.vertexNormalsWorld[0],z),m(n,k.v2.positionWorld,k.vertexNormalsWorld[1],v), m(n,k.v4.positionWorld,k.vertexNormalsWorld[3],w),m(n,k.v3.positionWorld,k.vertexNormalsWorld[2],N),z.r=Math.max(0,Math.min(i.color.r*z.r,1)),z.g=Math.max(0,Math.min(i.color.g*z.g,1)),z.b=Math.max(0,Math.min(i.color.b*z.b,1)),v.r=Math.max(0,Math.min(i.color.r*v.r,1)),v.g=Math.max(0,Math.min(i.color.g*v.g,1)),v.b=Math.max(0,Math.min(i.color.b*v.b,1)),w.r=Math.max(0,Math.min(i.color.r*w.r,1)),w.g=Math.max(0,Math.min(i.color.g*w.g,1)),w.b=Math.max(0,Math.min(i.color.b*w.b,1)),N.r=Math.max(0,Math.min(i.color.r* N.r,1)),N.g=Math.max(0,Math.min(i.color.g*N.g,1)),N.b=Math.max(0,Math.min(i.color.b*N.b,1)),da=va(z,v,w,N),F(J,K,H,X,R,u),na(J,K,H,X,R,u,0,0,1,0,0,1,da),F(Q,P,M,B,V,L),na(Q,P,M,B,V,L,1,0,1,1,0,1,da)):(s.r=Z.r,s.g=Z.g,s.b=Z.b,m(n,k.centroidWorld,k.normalWorld,s),s.r=Math.max(0,Math.min(i.color.r*s.r,1)),s.g=Math.max(0,Math.min(i.color.g*s.g,1)),s.b=Math.max(0,Math.min(i.color.b*s.b,1)),G(J,K,H,X,M,B,R,u),i.wireframe?ia(s,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(s)):(G(J,K,H, X,M,B,R,u),i.wireframe?ia(i.color,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(i.color));else if(i instanceof THREE.MeshNormalMaterial)s.r=oa(k.normalWorld.x),s.g=oa(k.normalWorld.y),s.b=oa(k.normalWorld.z),G(J,K,H,X,M,B,R,u),i.wireframe?ia(s,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(s);else if(i instanceof THREE.MeshDepthMaterial)fa=l.near,ga=l.far,z.r=z.g=z.b=1-ma(a.positionScreen.z,fa,ga),v.r=v.g=v.b=1-ma(d.positionScreen.z,fa,ga),w.r=w.g=w.b=1-ma(g.positionScreen.z, fa,ga),N.r=N.g=N.b=1-ma(e.positionScreen.z,fa,ga),da=va(z,v,w,N),F(J,K,H,X,R,u),na(J,K,H,X,R,u,0,0,1,0,0,1,da),F(Q,P,M,B,V,L),na(Q,P,M,B,V,L,1,0,1,1,0,1,da)}function F(a,b,c,d,e,f){i.beginPath();i.moveTo(a,b);i.lineTo(c,d);i.lineTo(e,f);i.lineTo(a,b);i.closePath()}function G(a,b,c,d,e,f,g,h){i.beginPath();i.moveTo(a,b);i.lineTo(c,d);i.lineTo(e,f);i.lineTo(g,h);i.lineTo(a,b);i.closePath()}function ia(a,b,c,e){if(C!=b)i.lineWidth=C=b;if(y!=c)i.lineCap=y=c;if(D!=e)i.lineJoin=D=e;d(a.getContextStyle()); i.stroke();W.inflate(b*2)}function ha(a){e(a.getContextStyle());i.fill()}function Aa(a,b,c,d,f,g,h,j,k,l,n,o,m){if(m.image.width!=0){if(m.needsUpdate==!0||ka[m.id]==void 0){var p=m.wrapS==THREE.RepeatWrapping,q=m.wrapT==THREE.RepeatWrapping;ka[m.id]=i.createPattern(m.image,p&&q?"repeat":p&&!q?"repeat-x":!p&&q?"repeat-y":"no-repeat");m.needsUpdate=!1}e(ka[m.id]);var p=m.offset.x/m.repeat.x,q=m.offset.y/m.repeat.y,r=m.image.width*m.repeat.x,t=m.image.height*m.repeat.y,h=(h+p)*r,j=(j+q)*t,k=(k+p)*r, l=(l+q)*t,n=(n+p)*r,o=(o+q)*t;c-=a;d-=b;f-=a;g-=b;k-=h;l-=j;n-=h;o-=j;p=k*o-n*l;if(p==0){if(ea[m.id]==void 0)b=document.createElement("canvas"),b.width=m.image.width,b.height=m.image.height,a=b.getContext("2d"),a.drawImage(m.image,0,0),ea[m.id]=a.getImageData(0,0,m.image.width,m.image.height).data,delete b;b=ea[m.id];h=(Math.floor(h)+Math.floor(j)*m.image.width)*4;s.setRGB(b[h]/255,b[h+1]/255,b[h+2]/255);ha(s)}else p=1/p,m=(o*c-l*f)*p,l=(o*d-l*g)*p,c=(k*f-n*c)*p,d=(k*g-n*d)*p,a=a-m*h-c*j,h=b-l*h- d*j,i.save(),i.transform(m,l,c,d,a,h),i.fill(),i.restore()}}function na(a,b,c,d,e,f,g,h,j,k,l,m,n){var o,p;o=n.width-1;p=n.height-1;g*=o;h*=p;j*=o;k*=p;l*=o;m*=p;c-=a;d-=b;e-=a;f-=b;j-=g;k-=h;l-=g;m-=h;p=1/(j*m-l*k);o=(m*c-k*e)*p;k=(m*d-k*f)*p;c=(j*e-l*c)*p;d=(j*f-l*d)*p;a=a-o*g-c*h;b=b-k*g-d*h;i.save();i.transform(o,k,c,d,a,b);i.clip();i.drawImage(n,0,0);i.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 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,Ha,T,ca;this.autoClear?this.clear():i.setTransform(1,0,0,-1,o,p);f.info.render.vertices=0;f.info.render.faces=0;g=k.projectScene(a,l,this.sortElements);j=g.elements;n=g.lights;(xa=n.length>0)&&h(n);wa=0;for(Ha=j.length;wa