// 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)}, 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)}, 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;return this},setRotationFromMatrix:function(a){this.y=Math.asin(a.n13); var b=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){k.sub(c,a);q=k.dot(b);x=p.add(a,i.copy(b).multiplyScalar(q));return v=c.distanceTo(x)}function d(a,b,c,d){k.sub(d,b);p.sub(c,b);i.sub(a,b);H=k.dot(k);E=k.dot(p);t=k.dot(i);G=p.dot(p);z=p.dot(i);F=1/(H*G-E*E);s=(G*t-E*z)*F;u=(H*z-E*t)*F;return 0<=s&&0<=u&&1>s+u}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:k,point:a.position,face:null,object:a};i.push(b)}else if(a instanceof THREE.Mesh){var k= c(this.origin,this.direction,a.matrixWorld.getPosition()),p=THREE.Frustum.__v1.set(a.matrixWorld.getColumnX().length(),a.matrixWorld.getColumnY().length(),a.matrixWorld.getColumnZ().length());if(k>a.geometry.boundingSphere.radius*Math.max(p.x,Math.max(p.y,p.z)))return i;var q,s,u=a.geometry,t=u.vertices,D;a.matrixRotationWorld.extractRotation(a.matrixWorld);for(k=0,p=u.faces.length;kMath.abs(q))&&(s=o.dot(l)/q,!(0>s)&&(a.doubleSided||(a.flipSided?0q))))if(n.add(m,j.multiplyScalar(s)),b instanceof THREE.Face3)e=D.multiplyVector3(e.copy(t[b.a].position)),f=D.multiplyVector3(f.copy(t[b.b].position)),g=D.multiplyVector3(g.copy(t[b.c].position)),d(n,e,f,g)&&(b={distance:m.distanceTo(n),point:n.clone(),face:b,object:a},i.push(b));else if(b instanceof THREE.Face4&&(e=D.multiplyVector3(e.copy(t[b.a].position)), f=D.multiplyVector3(f.copy(t[b.b].position)),g=D.multiplyVector3(g.copy(t[b.c].position)),h=D.multiplyVector3(h.copy(t[b.d].position)),d(n,e,f,h)||d(n,f,g,h)))b={distance:m.distanceTo(n),point:n.clone(),face:b,object:a},i.push(b)}return i};var k=new THREE.Vector3,p=new THREE.Vector3,i=new THREE.Vector3,q,x,v,H,E,t,G,z,F,s,u}; 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,l,o){h=!1;b=f;c=g;d=l;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,l,o,n,k){h?(h=!1,b=fl?f>n?f:n:l>n?l:n,e=g>o?g>k?g:k:o>k?o:k):(b=fl?f>n?f>d?f:d:n>d?n:d:l>n?l>d?l:d:n>d?n:d,e=g>o?g>k?g>e?g:e:k>e?k:e:o>k?o>e?o:e:k>e?k: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(L.positionScreen.x-A.positionScreen.x)*(N.positionScreen.y-A.positionScreen.y)-(L.positionScreen.y-A.positionScreen.y)*(N.positionScreen.x-A.positionScreen.x),r.doubleSided|| P!=r.flipSided)U=n[o]=n[o]||new THREE.RenderableFace3,o++,l=U,l.v1.copy(A),l.v2.copy(N),l.v3.copy(L);else continue;else continue;else if(I instanceof THREE.Face4)if(A=j[I.a],N=j[I.b],L=j[I.c],U=j[I.d],A.visible&&N.visible&&L.visible&&U.visible)if(P=0>(U.positionScreen.x-A.positionScreen.x)*(N.positionScreen.y-A.positionScreen.y)-(U.positionScreen.y-A.positionScreen.y)*(N.positionScreen.x-A.positionScreen.x)||0>(N.positionScreen.x-L.positionScreen.x)*(U.positionScreen.y-L.positionScreen.y)-(N.positionScreen.y- L.positionScreen.y)*(U.positionScreen.x-L.positionScreen.x),r.doubleSided||P!=r.flipSided)ea=p[k]=p[k]||new THREE.RenderableFace4,k++,l=ea,l.v1.copy(A),l.v2.copy(N),l.v3.copy(L),l.v4.copy(U);else continue;else continue;l.normalWorld.copy(I.normal);!P&&(r.flipSided||r.doubleSided)&&l.normalWorld.negate();w.multiplyVector3(l.normalWorld);l.centroidWorld.copy(I.centroid);y.multiplyVector3(l.centroidWorld);l.centroidScreen.copy(l.centroidWorld);F.multiplyVector3(l.centroidScreen);L=I.vertexNormals;for(A= 0,N=L.length;Az.z))g=E[H]=E[H]||new THREE.RenderableParticle,H++,v=g,v.x=z.x/z.w,v.y=z.y/z.w,v.z=z.z,v.rotation=r.rotation.z,v.scale.x=r.scale.x*Math.abs(v.x-(z.x+e.projectionMatrix.n11)/(z.w+e.projectionMatrix.n14)),v.scale.y=r.scale.y*Math.abs(v.y-(z.y+e.projectionMatrix.n22)/(z.w+e.projectionMatrix.n24)),v.material=r.material,t.elements.push(v);f&&t.elements.sort(c);return t}}; 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,m=this.w,j=m*c+g*e-h*d,l=m*d+h*c-f*e,o=m*e+f*d-g*c,c=-f*c-g*d-h*e;b.x=j*m+c*-f+l*-h-o*-g;b.y=l*m+c*-g+o*-f-j*-h;b.z=o*m+c*-h+j*-g-l*-f;return b}}; THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;0>e?(c.w=-b.w,c.x=-b.x,c.y=-b.y,c.z=-b.z,e=-e):c.copy(b);if(1<=Math.abs(e))return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var f=Math.acos(e),e=Math.sqrt(1-e*e);if(0.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.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.morphNormals=[];this.skinWeights=[];this.skinIndices=[];this.boundingSphere=this.boundingBox=null;this.dynamic=this.hasTangents=!1}; THREE.Geometry.prototype={constructor:THREE.Geometry,applyMatrix:function(a){var b=new THREE.Matrix4;b.extractRotation(a,new THREE.Vector3(1,1,1));for(var c=0,d=this.vertices.length;ce?-1:1,f.vertexTangents[d]=new THREE.Vector4(Z.x,Z.y,Z.z,e)}this.hasTangents=!0},computeBoundingBox:function(){if(!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;fx&&i.clearRect(Math.floor(Y.getX()),Math.floor(Y.getY()),Math.floor(Y.getWidth()),Math.floor(Y.getHeight())),0=l||(l*=g.intensity,d.r+=h.r*l,d.g+=h.g*l,d.b+=h.b*l)):g instanceof THREE.PointLight&&(j=g.matrixWorld.getPosition(),l=c.dot(R.sub(j,b).normalize()),0>=l||(l*=0==g.distance?1:1-Math.min(b.distanceTo(j)/g.distance,1),0!=l&&(l*=g.intensity,d.r+=h.r*l,d.g+=h.g*l,d.b+=h.b*l)))}function q(a,f,g){b(g.opacity);c(g.blending);var h,l,j,m,za,o;if(g instanceof THREE.ParticleBasicMaterial){if(g.map)m=g.map.image,za=m.width>>1,o=m.height>> 1,g=f.scale.x*k,j=f.scale.y*p,h=g*za,l=j*o,X.set(a.x-h,a.y-l,a.x+h,a.y+l),la.intersects(X)&&(i.save(),i.translate(a.x,a.y),i.rotate(-f.rotation),i.scale(g,-j),i.translate(-za,-o),i.drawImage(m,0,0),i.restore())}else g instanceof THREE.ParticleCanvasMaterial&&(h=f.scale.x*k,l=f.scale.y*p,X.set(a.x-h,a.y-l,a.x+h,a.y+l),la.intersects(X)&&(d(g.color.getContextStyle()),e(g.color.getContextStyle()),i.save(),i.translate(a.x,a.y),i.rotate(-f.rotation),i.scale(h,l),g.program(i),i.restore()))}function t(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(G!=a)i.lineWidth=G=a;a=g.linecap;if(z!=a)i.lineCap=z=a;a=g.linejoin;if(F!=a)i.lineJoin=F=a;d(g.color.getContextStyle());i.stroke();X.inflate(2*g.linewidth)}}function v(a,d,e,g,h,j,i,k){f.info.render.vertices+=3;f.info.render.faces++;b(k.opacity);c(k.blending);M=a.positionScreen.x;O=a.positionScreen.y; S=d.positionScreen.x;P=d.positionScreen.y;T=e.positionScreen.x;D=e.positionScreen.y;x(M,O,S,P,T,D);if(k instanceof THREE.MeshBasicMaterial)if(k.map)k.map.mapping instanceof THREE.UVMapping&&($=i.uvs[0],Aa(M,O,S,P,T,D,$[g].u,$[g].v,$[h].u,$[h].v,$[j].u,$[j].v,k.map));else if(k.envMap){if(k.envMap.mapping instanceof THREE.SphericalReflectionMapping)a=l.matrixWorldInverse,R.copy(i.vertexNormalsWorld[g]),Ba=0.5*(R.x*a.n11+R.y*a.n12+R.z*a.n13)+0.5,Ca=0.5*-(R.x*a.n21+R.y*a.n22+R.z*a.n23)+0.5,R.copy(i.vertexNormalsWorld[h]), Da=0.5*(R.x*a.n11+R.y*a.n12+R.z*a.n13)+0.5,Ea=0.5*-(R.x*a.n21+R.y*a.n22+R.z*a.n23)+0.5,R.copy(i.vertexNormalsWorld[j]),Fa=0.5*(R.x*a.n11+R.y*a.n12+R.z*a.n13)+0.5,Ga=0.5*-(R.x*a.n21+R.y*a.n22+R.z*a.n23)+0.5,Aa(M,O,S,P,T,D,Ba,Ca,Da,Ea,Fa,Ga,k.envMap)}else k.wireframe?ia(k.color,k.wireframeLinewidth,k.wireframeLinecap,k.wireframeLinejoin):ha(k.color);else if(k instanceof THREE.MeshLambertMaterial)k.map&&!k.wireframe&&(k.map.mapping instanceof THREE.UVMapping&&($=i.uvs[0],Aa(M,O,S,P,T,D,$[g].u,$[g].v, $[h].u,$[h].v,$[j].u,$[j].v,k.map)),c(THREE.SubtractiveBlending)),xa?!k.wireframe&&k.shading==THREE.SmoothShading&&3==i.vertexNormalsWorld.length?(y.r=w.r=B.r=W.r,y.g=w.g=B.g=W.g,y.b=w.b=B.b=W.b,n(m,i.v1.positionWorld,i.vertexNormalsWorld[0],y),n(m,i.v2.positionWorld,i.vertexNormalsWorld[1],w),n(m,i.v3.positionWorld,i.vertexNormalsWorld[2],B),y.r=Math.max(0,Math.min(k.color.r*y.r,1)),y.g=Math.max(0,Math.min(k.color.g*y.g,1)),y.b=Math.max(0,Math.min(k.color.b*y.b,1)),w.r=Math.max(0,Math.min(k.color.r* w.r,1)),w.g=Math.max(0,Math.min(k.color.g*w.g,1)),w.b=Math.max(0,Math.min(k.color.b*w.b,1)),B.r=Math.max(0,Math.min(k.color.r*B.r,1)),B.g=Math.max(0,Math.min(k.color.g*B.g,1)),B.b=Math.max(0,Math.min(k.color.b*B.b,1)),K.r=0.5*(w.r+B.r),K.g=0.5*(w.g+B.g),K.b=0.5*(w.b+B.b),da=va(y,w,B,K),pa(M,O,S,P,T,D,0,0,1,0,0,1,da)):(r.r=W.r,r.g=W.g,r.b=W.b,n(m,i.centroidWorld,i.normalWorld,r),r.r=Math.max(0,Math.min(k.color.r*r.r,1)),r.g=Math.max(0,Math.min(k.color.g*r.g,1)),r.b=Math.max(0,Math.min(k.color.b*r.b, 1)),k.wireframe?ia(r,k.wireframeLinewidth,k.wireframeLinecap,k.wireframeLinejoin):ha(r)):k.wireframe?ia(k.color,k.wireframeLinewidth,k.wireframeLinecap,k.wireframeLinejoin):ha(k.color);else if(k instanceof THREE.MeshDepthMaterial)fa=l.near,ga=l.far,y.r=y.g=y.b=1-oa(a.positionScreen.z,fa,ga),w.r=w.g=w.b=1-oa(d.positionScreen.z,fa,ga),B.r=B.g=B.b=1-oa(e.positionScreen.z,fa,ga),K.r=0.5*(w.r+B.r),K.g=0.5*(w.g+B.g),K.b=0.5*(w.b+B.b),da=va(y,w,B,K),pa(M,O,S,P,T,D,0,0,1,0,0,1,da);else if(k instanceof THREE.MeshNormalMaterial)r.r= qa(i.normalWorld.x),r.g=qa(i.normalWorld.y),r.b=qa(i.normalWorld.z),k.wireframe?ia(r,k.wireframeLinewidth,k.wireframeLinecap,k.wireframeLinejoin):ha(r)}function H(a,d,e,g,h,k,j,i,o){f.info.render.vertices+=4;f.info.render.faces++;b(i.opacity);c(i.blending);if(i.map||i.envMap)v(a,d,g,0,1,3,j,i,o),v(h,e,k,1,2,3,j,i,o);else if(M=a.positionScreen.x,O=a.positionScreen.y,S=d.positionScreen.x,P=d.positionScreen.y,T=e.positionScreen.x,D=e.positionScreen.y,I=g.positionScreen.x,Q=g.positionScreen.y,A=h.positionScreen.x, N=h.positionScreen.y,L=k.positionScreen.x,U=k.positionScreen.y,i instanceof THREE.MeshBasicMaterial)E(M,O,S,P,T,D,I,Q),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&&4==j.vertexNormalsWorld.length?(y.r=w.r=B.r=K.r=W.r,y.g=w.g=B.g=K.g=W.g,y.b=w.b=B.b=K.b=W.b,n(m,j.v1.positionWorld,j.vertexNormalsWorld[0],y),n(m,j.v2.positionWorld,j.vertexNormalsWorld[1],w), n(m,j.v4.positionWorld,j.vertexNormalsWorld[3],B),n(m,j.v3.positionWorld,j.vertexNormalsWorld[2],K),y.r=Math.max(0,Math.min(i.color.r*y.r,1)),y.g=Math.max(0,Math.min(i.color.g*y.g,1)),y.b=Math.max(0,Math.min(i.color.b*y.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)),B.r=Math.max(0,Math.min(i.color.r*B.r,1)),B.g=Math.max(0,Math.min(i.color.g*B.g,1)),B.b=Math.max(0,Math.min(i.color.b*B.b,1)),K.r=Math.max(0,Math.min(i.color.r* K.r,1)),K.g=Math.max(0,Math.min(i.color.g*K.g,1)),K.b=Math.max(0,Math.min(i.color.b*K.b,1)),da=va(y,w,B,K),x(M,O,S,P,I,Q),pa(M,O,S,P,I,Q,0,0,1,0,0,1,da),x(A,N,T,D,L,U),pa(A,N,T,D,L,U,1,0,1,1,0,1,da)):(r.r=W.r,r.g=W.g,r.b=W.b,n(m,j.centroidWorld,j.normalWorld,r),r.r=Math.max(0,Math.min(i.color.r*r.r,1)),r.g=Math.max(0,Math.min(i.color.g*r.g,1)),r.b=Math.max(0,Math.min(i.color.b*r.b,1)),E(M,O,S,P,T,D,I,Q),i.wireframe?ia(r,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(r)):(E(M,O,S, P,T,D,I,Q),i.wireframe?ia(i.color,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(i.color));else if(i instanceof THREE.MeshNormalMaterial)r.r=qa(j.normalWorld.x),r.g=qa(j.normalWorld.y),r.b=qa(j.normalWorld.z),E(M,O,S,P,T,D,I,Q),i.wireframe?ia(r,i.wireframeLinewidth,i.wireframeLinecap,i.wireframeLinejoin):ha(r);else if(i instanceof THREE.MeshDepthMaterial)fa=l.near,ga=l.far,y.r=y.g=y.b=1-oa(a.positionScreen.z,fa,ga),w.r=w.g=w.b=1-oa(d.positionScreen.z,fa,ga),B.r=B.g=B.b=1-oa(g.positionScreen.z, fa,ga),K.r=K.g=K.b=1-oa(e.positionScreen.z,fa,ga),da=va(y,w,B,K),x(M,O,S,P,I,Q),pa(M,O,S,P,I,Q,0,0,1,0,0,1,da),x(A,N,T,D,L,U),pa(A,N,T,D,L,U,1,0,1,1,0,1,da)}function x(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 E(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(G!=b)i.lineWidth=G=b;if(z!=c)i.lineCap=z=c;if(F!=e)i.lineJoin=F=e;d(a.getContextStyle()); i.stroke();X.inflate(2*b)}function ha(a){e(a.getContextStyle());i.fill()}function Aa(a,b,c,d,f,g,h,k,j,l,m,o,n){if(0!=n.image.width){if(!0==n.needsUpdate||void 0==ka[n.id]){var p=n.wrapS==THREE.RepeatWrapping,q=n.wrapT==THREE.RepeatWrapping;ka[n.id]=i.createPattern(n.image,p&&q?"repeat":p&&!q?"repeat-x":!p&&q?"repeat-y":"no-repeat");n.needsUpdate=!1}e(ka[n.id]);var p=n.offset.x/n.repeat.x,q=n.offset.y/n.repeat.y,s=n.image.width*n.repeat.x,t=n.image.height*n.repeat.y,h=(h+p)*s,k=(k+q)*t,c=c-a,d=d- b,f=f-a,g=g-b,j=(j+p)*s-h,l=(l+q)*t-k,m=(m+p)*s-h,o=(o+q)*t-k,p=j*o-m*l;if(0==p){if(void 0===ea[n.id])b=document.createElement("canvas"),b.width=n.image.width,b.height=n.image.height,b=b.getContext("2d"),b.drawImage(n.image,0,0),ea[n.id]=b.getImageData(0,0,n.image.width,n.image.height).data;b=ea[n.id];h=4*(Math.floor(h)+Math.floor(k)*n.image.width);r.setRGB(b[h]/255,b[h+1]/255,b[h+2]/255);ha(r)}else p=1/p,n=(o*c-l*f)*p,l=(o*d-l*g)*p,c=(j*f-m*c)*p,d=(j*g-m*d)*p,a=a-n*h-c*k,h=b-l*h-d*k,i.save(),i.transform(n, l,c,d,a,h),i.fill(),i.restore()}}function pa(a,b,c,d,e,f,g,h,k,j,l,m,n){var o,p;o=n.width-1;p=n.height-1;g*=o;h*=p;c-=a;d-=b;e-=a;f-=b;k=k*o-g;j=j*p-h;l=l*o-g;m=m*p-h;p=1/(k*m-l*j);o=(m*c-j*e)*p;j=(m*d-j*f)*p;c=(k*e-l*c)*p;d=(k*f-l*d)*p;a=a-o*g-c*h;b=b-j*g-d*h;i.save();i.transform(o,j,c,d,a,b);i.clip();i.drawImage(n,0,0);i.restore()}function va(a,b,c,d){var e=~~(255*a.r),f=~~(255*a.g),a=~~(255*a.b),g=~~(255*b.r),h=~~(255*b.g),b=~~(255*b.b),i=~~(255*c.r),j=~~(255*c.g),c=~~(255*c.b),k=~~(255*d.r),l= ~~(255*d.g),d=~~(255*d.b);aa[0]=0>e?0:255f?0:255a?0:255g?0:255h?0:255b?0:255i?0:255j?0:255c?0:255k?0:255l?0:255d?0:255a?0:1o-1?e-1:o-1,k=(o+1)%e,p=0>l-1?d-1:l-1,i=(l+1)%d,q=[],x=[0,0,h[4*(o*d+l)]/255*b];q.push([-1,0,h[4*(o*d+p)]/255*b]);q.push([-1,-1,h[4*(n*d+p)]/255*b]);q.push([0,-1, h[4*(n*d+l)]/255*b]);q.push([1,-1,h[4*(n*d+i)]/255*b]);q.push([1,0,h[4*(o*d+i)]/255*b]);q.push([1,1,h[4*(k*d+i)]/255*b]);q.push([0,1,h[4*(k*d+l)]/255*b]);q.push([-1,1,h[4*(k*d+p)]/255*b]);n=[];p=q.length;for(k=0;k