// ThreeCanvas.js - http://github.com/mrdoob/three.js 'use strict';var THREE=THREE||{REVISION:"48dev"};if(!self.Int32Array)self.Int32Array=Array,self.Float32Array=Array; (function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c>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.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)}, lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;return this},equals:function(a){return a.x===this.x&&a.y===this.y},isZero:function(){return 1.0E-4>this.lengthSq()}};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 Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},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;return this},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()},getPositionFromMatrix:function(a){this.x= a.n14;this.y=a.n24;this.z=a.n34;return this},getRotationFromMatrix:function(a,b){var c=b?b.x:1,d=b?b.y:1,e=b?b.z:1,f=a.n11/c,g=a.n12/d,c=a.n21/c,d=a.n22/d,h=a.n23/e,l=a.n33/e;this.y=Math.asin(a.n13/e);e=Math.cos(this.y);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;return this},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.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=THREE.Frustum.__v1.set(c.getColumnX().length(),c.getColumnY().length(),c.getColumnZ().length()),d=-a.geometry.boundingSphere.radius*Math.max(d.x,Math.max(d.y,d.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.Frustum.__v1=new THREE.Vector3; THREE.Ray=function(a,b){function c(a,b,c){p.sub(c,a);D=p.dot(b);u=k.add(a,r.copy(b).multiplyScalar(D));return G=c.distanceTo(u)}function d(a,b,c,d){p.sub(d,b);k.sub(c,b);r.sub(a,b);I=p.dot(p);v=p.dot(k);H=p.dot(r);A=k.dot(k);F=k.dot(r);s=1/(I*A-v*v);w=(A*H-v*F)*s;z=(I*F-v*H)*s;return 0<=w&&0<=z&&1>w+z}this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3;this.intersectObjects=function(a){var b,c,d=[];for(b=0,c=a.length;ba.scale.x)return[];b={distance:p,point:a.position,face:null,object:a}; k.push(b)}else if(a instanceof THREE.Mesh){var p=c(this.origin,this.direction,a.matrixWorld.getPosition()),r=THREE.Frustum.__v1.set(a.matrixWorld.getColumnX().length(),a.matrixWorld.getColumnY().length(),a.matrixWorld.getColumnZ().length());if(p>a.geometry.boundingSphere.radius*Math.max(r.x,Math.max(r.y,r.z)))return k;var s,w,v=a.geometry,E=v.vertices,u;a.matrixRotationWorld.extractRotation(a.matrixWorld);for(p=0,r=v.faces.length;pw)&&(a.doubleSided||(a.flipSided?0s))))if(n.add(j,i.multiplyScalar(w)),b instanceof THREE.Face3)f=u.multiplyVector3(f.copy(E[b.a].position)),g=u.multiplyVector3(g.copy(E[b.b].position)),h=u.multiplyVector3(h.copy(E[b.c].position)),d(n,f,g,h)&&(b={distance:j.distanceTo(n),point:n.clone(),face:b,object:a},k.push(b));else if(b instanceof THREE.Face4&&(f=u.multiplyVector3(f.copy(E[b.a].position)),g=u.multiplyVector3(g.copy(E[b.b].position)),h=u.multiplyVector3(h.copy(E[b.c].position)),l=u.multiplyVector3(l.copy(E[b.d].position)),d(n,f,g,l)||d(n,g,h,l)))b={distance:j.distanceTo(n),point:n.clone(),face:b,object:a},k.push(b)}return k};var p=new THREE.Vector3,k=new THREE.Vector3,r=new THREE.Vector3,D,u,G,I,v,H,A,F,s,w,z}; THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,h=!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,i,o){h=!1;b=f;c=g;d=i;e=o;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=bf?d:f,e=e>g?e:g);a()};this.add3Points= function(f,g,i,o,m,n){h?(h=!1,b=fi?f>m?f:m:i>m?i:m,e=g>o?g>n?g:n:o>n?o:n):(b=fi?f>m?f>d?f:d:m>d?m:d:i>m?i>d?i:d:m>d?m:d,e=g>o?g>n?g>e?g:e:n>e?n:e:o>n?o>e?o:e:n>e?n:e);a()};this.addRectangle=function(f){h?(h=!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(){h=!0;e=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 ae&&0>f||0>g&&0>h)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-h)):0>h&&(d=Math.min(d,g/(g-h)));if(dg&&h.positionScreen.z(M.positionScreen.x-B.positionScreen.x)*(O.positionScreen.y-B.positionScreen.y)-(M.positionScreen.y-B.positionScreen.y)*(O.positionScreen.x-B.positionScreen.x),t.doubleSided|| Q!=t.flipSided)V=m[o]=m[o]||new THREE.RenderableFace3,o++,i=V,i.v1.copy(B),i.v2.copy(O),i.v3.copy(M);else continue;else continue;else if(J instanceof THREE.Face4)if(B=j[J.a],O=j[J.b],M=j[J.c],V=j[J.d],B.visible&&O.visible&&M.visible&&V.visible)if(Q=0>(V.positionScreen.x-B.positionScreen.x)*(O.positionScreen.y-B.positionScreen.y)-(V.positionScreen.y-B.positionScreen.y)*(O.positionScreen.x-B.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),t.doubleSided||Q!=t.flipSided)fa=p[n]=p[n]||new THREE.RenderableFace4,n++,i=fa,i.v1.copy(B),i.v2.copy(O),i.v3.copy(M),i.v4.copy(V);else continue;else continue;i.normalWorld.copy(J.normal);!Q&&(t.flipSided||t.doubleSided)&&i.normalWorld.negate();x.multiplyVector3(i.normalWorld);i.centroidWorld.copy(J.centroid);y.multiplyVector3(i.centroidWorld);i.centroidScreen.copy(i.centroidWorld);F.multiplyVector3(i.centroidScreen);M=J.vertexNormals;for(B= 0,O=M.length;BA.z))g=I[G]=I[G]||new THREE.RenderableParticle,G++,u=g,u.x=A.x/A.w,u.y=A.y/A.w,u.z=A.z,u.rotation=t.rotation.z,u.scale.x=t.scale.x*Math.abs(u.x-(A.x+e.projectionMatrix.n11)/(A.w+e.projectionMatrix.n14)),u.scale.y=t.scale.y*Math.abs(u.y-(A.y+e.projectionMatrix.n22)/(A.w+e.projectionMatrix.n24)),u.material=t.material,v.elements.push(u);f&&v.elements.sort(c);return v}}; THREE.Quaternion=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.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},clone:function(){return new THREE.Quaternion(this.x,this.y,this.z,this.w)},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,h=d*e;this.w=g*f-h*c;this.x=g*c+h*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,h=a.z,a=a.w;this.x=b*a+e*f+c*h-d*g;this.y=c*a+e*g+d*f-b*h;this.z=d*a+e*h+b*g-c*f;this.w=e*a-b*f-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,e=a.z,f=this.x,g=this.y,h=this.z,l=this.w,j=l*c+g*e-h*d,i=l*d+h*c-f*e,o=l*e+f*d-g*c,c=-f*c-g*d-h*e;b.x=j*l+c*-f+i*-h-o*-g;b.y=i*l+c*-g+o*-f-j*-h;b.z=o*l+c*-h+j*-g-i*-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.001>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.Vertex.prototype={constructor:THREE.Vertex,clone:function(){return new THREE.Vertex(this.position.clone())}};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.Face3.prototype={constructor:THREE.Face3,clone:function(){var a=new THREE.Face3(this.a,this.b,this.c);a.normal.copy(this.normal);a.color.copy(this.color);a.centroid.copy(this.centroid);a.materialIndex=this.materialIndex;var b,c;for(b=0,c=this.vertexNormals.length;be?-1:1,f.vertexTangents[d]=new THREE.Vector4($.x,$.y,$.z,e)}this.hasTangents=!0},computeBoundingBox:function(){if(!this.boundingBox)this.boundingBox={min:new THREE.Vector3,max:new THREE.Vector3};if(0c.x)c.x=a.x;if(a.yc.y)c.y=a.y;if(a.zc.z)c.z=a.z}}else this.boundingBox.min.set(0,0,0),this.boundingBox.max.set(0,0,0)},computeBoundingSphere:function(){if(!this.boundingSphere)this.boundingSphere={radius:0};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;fD&&k.clearRect(Math.floor(Z.getX()),Math.floor(Z.getY()),Math.floor(Z.getWidth()),Math.floor(Z.getHeight())),0=i||(i*=g.intensity,d.r+=h.r*i,d.g+=h.g*i,d.b+=h.b*i)):g instanceof THREE.PointLight&&(j=g.matrixWorld.getPosition(),i=c.dot(S.sub(j,b).normalize()),0>=i||(i*=0==g.distance?1:1-Math.min(b.distanceTo(j)/g.distance,1),0!=i&&(i*=g.intensity,d.r+=h.r*i,d.g+=h.g*i,d.b+=h.b*i)))}function r(a,f,g){b(g.opacity);c(g.blending);var h,i,j,l,q,o;if(g instanceof THREE.ParticleBasicMaterial){if(g.map)l=g.map.image,q=l.width>>1,o=l.height>> 1,g=f.scale.x*n,j=f.scale.y*p,h=g*q,i=j*o,Y.set(a.x-h,a.y-i,a.x+h,a.y+i),ma.intersects(Y)&&(k.save(),k.translate(a.x,a.y),k.rotate(-f.rotation),k.scale(g,-j),k.translate(-q,-o),k.drawImage(l,0,0),k.restore())}else g instanceof THREE.ParticleCanvasMaterial&&(h=f.scale.x*n,i=f.scale.y*p,Y.set(a.x-h,a.y-i,a.x+h,a.y+i),ma.intersects(Y)&&(d(g.color.getContextStyle()),e(g.color.getContextStyle()),k.save(),k.translate(a.x,a.y),k.rotate(-f.rotation),k.scale(h,i),g.program(k),k.restore()))}function u(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(A!=a)k.lineCap=A=a;a=g.linejoin;if(F!=a)k.lineJoin=F=a;d(g.color.getContextStyle());k.stroke();Y.inflate(2*g.linewidth)}}function v(a,d,e,g,h,j,k,q){f.info.render.vertices+=3;f.info.render.faces++;b(q.opacity);c(q.blending);N=a.positionScreen.x;P=a.positionScreen.y; T=d.positionScreen.x;Q=d.positionScreen.y;U=e.positionScreen.x;E=e.positionScreen.y;G(N,P,T,Q,U,E);if(q instanceof THREE.MeshBasicMaterial)if(q.map)q.map.mapping instanceof THREE.UVMapping&&(aa=k.uvs[0],Aa(N,P,T,Q,U,E,aa[g].u,aa[g].v,aa[h].u,aa[h].v,aa[j].u,aa[j].v,q.map));else if(q.envMap){if(q.envMap.mapping instanceof THREE.SphericalReflectionMapping)a=i.matrixWorldInverse,S.copy(k.vertexNormalsWorld[g]),Ba=0.5*(S.x*a.n11+S.y*a.n12+S.z*a.n13)+0.5,Ca=0.5*-(S.x*a.n21+S.y*a.n22+S.z*a.n23)+0.5,S.copy(k.vertexNormalsWorld[h]), Da=0.5*(S.x*a.n11+S.y*a.n12+S.z*a.n13)+0.5,Ea=0.5*-(S.x*a.n21+S.y*a.n22+S.z*a.n23)+0.5,S.copy(k.vertexNormalsWorld[j]),Fa=0.5*(S.x*a.n11+S.y*a.n12+S.z*a.n13)+0.5,Ga=0.5*-(S.x*a.n21+S.y*a.n22+S.z*a.n23)+0.5,Aa(N,P,T,Q,U,E,Ba,Ca,Da,Ea,Fa,Ga,q.envMap)}else q.wireframe?ja(q.color,q.wireframeLinewidth,q.wireframeLinecap,q.wireframeLinejoin):ia(q.color);else if(q instanceof THREE.MeshLambertMaterial)q.map&&!q.wireframe&&(q.map.mapping instanceof THREE.UVMapping&&(aa=k.uvs[0],Aa(N,P,T,Q,U,E,aa[g].u,aa[g].v, aa[h].u,aa[h].v,aa[j].u,aa[j].v,q.map)),c(THREE.SubtractiveBlending)),ya?!q.wireframe&&q.shading==THREE.SmoothShading&&3==k.vertexNormalsWorld.length?(y.r=x.r=C.r=X.r,y.g=x.g=C.g=X.g,y.b=x.b=C.b=X.b,m(l,k.v1.positionWorld,k.vertexNormalsWorld[0],y),m(l,k.v2.positionWorld,k.vertexNormalsWorld[1],x),m(l,k.v3.positionWorld,k.vertexNormalsWorld[2],C),y.r=Math.max(0,Math.min(q.color.r*y.r,1)),y.g=Math.max(0,Math.min(q.color.g*y.g,1)),y.b=Math.max(0,Math.min(q.color.b*y.b,1)),x.r=Math.max(0,Math.min(q.color.r* x.r,1)),x.g=Math.max(0,Math.min(q.color.g*x.g,1)),x.b=Math.max(0,Math.min(q.color.b*x.b,1)),C.r=Math.max(0,Math.min(q.color.r*C.r,1)),C.g=Math.max(0,Math.min(q.color.g*C.g,1)),C.b=Math.max(0,Math.min(q.color.b*C.b,1)),L.r=0.5*(x.r+C.r),L.g=0.5*(x.g+C.g),L.b=0.5*(x.b+C.b),ea=wa(y,x,C,L),qa(N,P,T,Q,U,E,0,0,1,0,0,1,ea)):(t.r=X.r,t.g=X.g,t.b=X.b,m(l,k.centroidWorld,k.normalWorld,t),t.r=Math.max(0,Math.min(q.color.r*t.r,1)),t.g=Math.max(0,Math.min(q.color.g*t.g,1)),t.b=Math.max(0,Math.min(q.color.b*t.b, 1)),q.wireframe?ja(t,q.wireframeLinewidth,q.wireframeLinecap,q.wireframeLinejoin):ia(t)):q.wireframe?ja(q.color,q.wireframeLinewidth,q.wireframeLinecap,q.wireframeLinejoin):ia(q.color);else if(q instanceof THREE.MeshDepthMaterial)ga=i.near,ha=i.far,y.r=y.g=y.b=1-pa(a.positionScreen.z,ga,ha),x.r=x.g=x.b=1-pa(d.positionScreen.z,ga,ha),C.r=C.g=C.b=1-pa(e.positionScreen.z,ga,ha),L.r=0.5*(x.r+C.r),L.g=0.5*(x.g+C.g),L.b=0.5*(x.b+C.b),ea=wa(y,x,C,L),qa(N,P,T,Q,U,E,0,0,1,0,0,1,ea);else if(q instanceof THREE.MeshNormalMaterial)t.r= ra(k.normalWorld.x),t.g=ra(k.normalWorld.y),t.b=ra(k.normalWorld.z),q.wireframe?ja(t,q.wireframeLinewidth,q.wireframeLinecap,q.wireframeLinejoin):ia(t)}function D(a,d,e,g,h,j,k,q,n){f.info.render.vertices+=4;f.info.render.faces++;b(q.opacity);c(q.blending);if(q.map||q.envMap)v(a,d,g,0,1,3,k,q,n),v(h,e,j,1,2,3,k,q,n);else if(N=a.positionScreen.x,P=a.positionScreen.y,T=d.positionScreen.x,Q=d.positionScreen.y,U=e.positionScreen.x,E=e.positionScreen.y,J=g.positionScreen.x,R=g.positionScreen.y,B=h.positionScreen.x, O=h.positionScreen.y,M=j.positionScreen.x,V=j.positionScreen.y,q instanceof THREE.MeshBasicMaterial)I(N,P,T,Q,U,E,J,R),q.wireframe?ja(q.color,q.wireframeLinewidth,q.wireframeLinecap,q.wireframeLinejoin):ia(q.color);else if(q instanceof THREE.MeshLambertMaterial)ya?!q.wireframe&&q.shading==THREE.SmoothShading&&4==k.vertexNormalsWorld.length?(y.r=x.r=C.r=L.r=X.r,y.g=x.g=C.g=L.g=X.g,y.b=x.b=C.b=L.b=X.b,m(l,k.v1.positionWorld,k.vertexNormalsWorld[0],y),m(l,k.v2.positionWorld,k.vertexNormalsWorld[1],x), m(l,k.v4.positionWorld,k.vertexNormalsWorld[3],C),m(l,k.v3.positionWorld,k.vertexNormalsWorld[2],L),y.r=Math.max(0,Math.min(q.color.r*y.r,1)),y.g=Math.max(0,Math.min(q.color.g*y.g,1)),y.b=Math.max(0,Math.min(q.color.b*y.b,1)),x.r=Math.max(0,Math.min(q.color.r*x.r,1)),x.g=Math.max(0,Math.min(q.color.g*x.g,1)),x.b=Math.max(0,Math.min(q.color.b*x.b,1)),C.r=Math.max(0,Math.min(q.color.r*C.r,1)),C.g=Math.max(0,Math.min(q.color.g*C.g,1)),C.b=Math.max(0,Math.min(q.color.b*C.b,1)),L.r=Math.max(0,Math.min(q.color.r* L.r,1)),L.g=Math.max(0,Math.min(q.color.g*L.g,1)),L.b=Math.max(0,Math.min(q.color.b*L.b,1)),ea=wa(y,x,C,L),G(N,P,T,Q,J,R),qa(N,P,T,Q,J,R,0,0,1,0,0,1,ea),G(B,O,U,E,M,V),qa(B,O,U,E,M,V,1,0,1,1,0,1,ea)):(t.r=X.r,t.g=X.g,t.b=X.b,m(l,k.centroidWorld,k.normalWorld,t),t.r=Math.max(0,Math.min(q.color.r*t.r,1)),t.g=Math.max(0,Math.min(q.color.g*t.g,1)),t.b=Math.max(0,Math.min(q.color.b*t.b,1)),I(N,P,T,Q,U,E,J,R),q.wireframe?ja(t,q.wireframeLinewidth,q.wireframeLinecap,q.wireframeLinejoin):ia(t)):(I(N,P,T, Q,U,E,J,R),q.wireframe?ja(q.color,q.wireframeLinewidth,q.wireframeLinecap,q.wireframeLinejoin):ia(q.color));else if(q instanceof THREE.MeshNormalMaterial)t.r=ra(k.normalWorld.x),t.g=ra(k.normalWorld.y),t.b=ra(k.normalWorld.z),I(N,P,T,Q,U,E,J,R),q.wireframe?ja(t,q.wireframeLinewidth,q.wireframeLinecap,q.wireframeLinejoin):ia(t);else if(q instanceof THREE.MeshDepthMaterial)ga=i.near,ha=i.far,y.r=y.g=y.b=1-pa(a.positionScreen.z,ga,ha),x.r=x.g=x.b=1-pa(d.positionScreen.z,ga,ha),C.r=C.g=C.b=1-pa(g.positionScreen.z, ga,ha),L.r=L.g=L.b=1-pa(e.positionScreen.z,ga,ha),ea=wa(y,x,C,L),G(N,P,T,Q,J,R),qa(N,P,T,Q,J,R,0,0,1,0,0,1,ea),G(B,O,U,E,M,V),qa(B,O,U,E,M,V,1,0,1,1,0,1,ea)}function G(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 I(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 ja(a,b,c,e){if(H!=b)k.lineWidth=H=b;if(A!=c)k.lineCap=A=c;if(F!=e)k.lineJoin=F=e;d(a.getContextStyle()); k.stroke();Y.inflate(2*b)}function ia(a){e(a.getContextStyle());k.fill()}function Aa(a,b,c,d,f,g,h,j,i,l,n,o,m){if(0!=m.image.width){if(!0==m.needsUpdate||void 0==la[m.id]){var p=m.wrapS==THREE.RepeatWrapping,r=m.wrapT==THREE.RepeatWrapping;la[m.id]=k.createPattern(m.image,p&&r?"repeat":p&&!r?"repeat-x":!p&&r?"repeat-y":"no-repeat");m.needsUpdate=!1}e(la[m.id]);var p=m.offset.x/m.repeat.x,r=m.offset.y/m.repeat.y,s=m.image.width*m.repeat.x,u=m.image.height*m.repeat.y,h=(h+p)*s,j=(j+r)*u,c=c-a,d=d- b,f=f-a,g=g-b,i=(i+p)*s-h,l=(l+r)*u-j,n=(n+p)*s-h,o=(o+r)*u-j,p=i*o-n*l;if(0==p){if(void 0===fa[m.id])b=document.createElement("canvas"),b.width=m.image.width,b.height=m.image.height,b=b.getContext("2d"),b.drawImage(m.image,0,0),fa[m.id]=b.getImageData(0,0,m.image.width,m.image.height).data;b=fa[m.id];h=4*(Math.floor(h)+Math.floor(j)*m.image.width);t.setRGB(b[h]/255,b[h+1]/255,b[h+2]/255);ia(t)}else p=1/p,m=(o*c-l*f)*p,l=(o*d-l*g)*p,c=(i*f-n*c)*p,d=(i*g-n*d)*p,a=a-m*h-c*j,h=b-l*h-d*j,k.save(),k.transform(m, l,c,d,a,h),k.fill(),k.restore()}}function qa(a,b,c,d,e,f,g,h,j,i,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;j=j*o-g;i=i*p-h;l=l*o-g;m=m*p-h;p=1/(j*m-l*i);o=(m*c-i*e)*p;i=(m*d-i*f)*p;c=(j*e-l*c)*p;d=(j*f-l*d)*p;a=a-o*g-c*h;b=b-i*g-d*h;k.save();k.transform(o,i,c,d,a,b);k.clip();k.drawImage(n,0,0);k.restore()}function wa(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);ba[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,n=(o+1)%e,p=0>i-1?d-1:i-1,k=(i+1)%d,r=[],D=[0,0,h[4*(o*d+i)]/255*b];r.push([-1,0,h[4*(o*d+p)]/255*b]);r.push([-1,-1,h[4*(m*d+p)]/255*b]);r.push([0,-1, h[4*(m*d+i)]/255*b]);r.push([1,-1,h[4*(m*d+k)]/255*b]);r.push([1,0,h[4*(o*d+k)]/255*b]);r.push([1,1,h[4*(n*d+k)]/255*b]);r.push([0,1,h[4*(n*d+i)]/255*b]);r.push([-1,1,h[4*(n*d+p)]/255*b]);m=[];p=r.length;for(n=0;n