Browse Source

Added crappy grass WebGL example.
Added `sortElements` boolean (true by default) to `CanvasRenderer` and `SVGRenderer`. Also added `sortObjects` boolean but not being used yet.

Mr.doob 14 years ago
parent
commit
c13377d736

+ 24 - 24
build/Three.js

@@ -101,36 +101,36 @@ q.positionScreen.copy(q.position);O.multiplyVector4(q.positionScreen);C=y[w-1];E
 v.x=J.x/J.w;v.y=J.y/J.w;v.z=J.z;v.rotation=s.rotation.z;v.scale.x=s.scale.x*Math.abs(v.x-(J.x+p.projectionMatrix.n11)/(J.w+p.projectionMatrix.n14));v.scale.y=s.scale.y*Math.abs(v.y-(J.y+p.projectionMatrix.n22)/(J.w+p.projectionMatrix.n24));v.material=s.material;h.push(v);u++}}}}k&&h.sort(b);return h};this.unprojectVector=function(e,p){var k=new THREE.Matrix4;k.multiply(THREE.Matrix4.makeInvert(p.matrix),THREE.Matrix4.makeInvert(p.projectionMatrix));k.multiplyVector3(e);return e}};
 v.x=J.x/J.w;v.y=J.y/J.w;v.z=J.z;v.rotation=s.rotation.z;v.scale.x=s.scale.x*Math.abs(v.x-(J.x+p.projectionMatrix.n11)/(J.w+p.projectionMatrix.n14));v.scale.y=s.scale.y*Math.abs(v.y-(J.y+p.projectionMatrix.n22)/(J.w+p.projectionMatrix.n24));v.material=s.material;h.push(v);u++}}}}k&&h.sort(b);return h};this.unprojectVector=function(e,p){var k=new THREE.Matrix4;k.multiply(THREE.Matrix4.makeInvert(p.matrix),THREE.Matrix4.makeInvert(p.projectionMatrix));k.multiplyVector3(e);return e}};
 THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,g,d,i,j;this.domElement=document.createElement("div");this.setSize=function(o,l){g=o;d=l;i=g/2;j=d/2};this.render=function(o,l){var n,c,B,A,v,u,G,L;a=b.projectScene(o,l);n=0;for(c=a.length;n<c;n++){v=a[n];if(v instanceof THREE.RenderableParticle){G=v.x*i+i;L=v.y*j+j;B=0;for(A=v.material.length;B<A;B++){u=v.material[B];if(u instanceof THREE.ParticleDOMMaterial){u=u.domElement;u.style.left=G+"px";u.style.top=L+"px"}}}}}};
 THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,g,d,i,j;this.domElement=document.createElement("div");this.setSize=function(o,l){g=o;d=l;i=g/2;j=d/2};this.render=function(o,l){var n,c,B,A,v,u,G,L;a=b.projectScene(o,l);n=0;for(c=a.length;n<c;n++){v=a[n];if(v instanceof THREE.RenderableParticle){G=v.x*i+i;L=v.y*j+j;B=0;for(A=v.material.length;B<A;B++){u=v.material[B];if(u instanceof THREE.ParticleDOMMaterial){u=u.domElement;u.style.left=G+"px";u.style.top=L+"px"}}}}}};
 THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,g=document.createElement("canvas"),d,i,j,o,l=g.getContext("2d"),n=1,c=0,B=null,A=null,v=1,u,G,L,J,I,O,E,f,m,e=new THREE.Color,p=new THREE.Color,k=new THREE.Color,h=new THREE.Color,t=new THREE.Color,w,D,q,C,Q,s,U,P,X,V,H=new THREE.Rectangle,y=new THREE.Rectangle,r=new THREE.Rectangle,N=false,S=new THREE.Color,M=new THREE.Color,T=new THREE.Color,aa=new THREE.Color,Ja=Math.PI*2,Y=new THREE.Vector3,na,oa,Aa,da,pa,ta,la=16;na=document.createElement("canvas");
 THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,g=document.createElement("canvas"),d,i,j,o,l=g.getContext("2d"),n=1,c=0,B=null,A=null,v=1,u,G,L,J,I,O,E,f,m,e=new THREE.Color,p=new THREE.Color,k=new THREE.Color,h=new THREE.Color,t=new THREE.Color,w,D,q,C,Q,s,U,P,X,V,H=new THREE.Rectangle,y=new THREE.Rectangle,r=new THREE.Rectangle,N=false,S=new THREE.Color,M=new THREE.Color,T=new THREE.Color,aa=new THREE.Color,Ja=Math.PI*2,Y=new THREE.Vector3,na,oa,Aa,da,pa,ta,la=16;na=document.createElement("canvas");
-na.width=na.height=2;oa=na.getContext("2d");oa.fillStyle="rgba(0,0,0,1)";oa.fillRect(0,0,2,2);Aa=oa.getImageData(0,0,2,2);da=Aa.data;pa=document.createElement("canvas");pa.width=pa.height=la;ta=pa.getContext("2d");ta.translate(-la/2,-la/2);ta.scale(la,la);la--;this.domElement=g;this.autoClear=true;this.setSize=function(ga,ua){d=ga;i=ua;j=d/2;o=i/2;g.width=d;g.height=i;H.set(-j,-o,j,o)};this.clear=function(){if(!y.isEmpty()){y.inflate(1);y.minSelf(H);l.clearRect(y.getX(),y.getY(),y.getWidth(),y.getHeight());
-y.empty()}};this.render=function(ga,ua){function Ka(x){var R,K,z,F=x.lights;M.setRGB(0,0,0);T.setRGB(0,0,0);aa.setRGB(0,0,0);x=0;for(R=F.length;x<R;x++){K=F[x];z=K.color;if(K instanceof THREE.AmbientLight){M.r+=z.r;M.g+=z.g;M.b+=z.b}else if(K instanceof THREE.DirectionalLight){T.r+=z.r;T.g+=z.g;T.b+=z.b}else if(K instanceof THREE.PointLight){aa.r+=z.r;aa.g+=z.g;aa.b+=z.b}}}function va(x,R,K,z){var F,W,$,ba,ca=x.lights;x=0;for(F=ca.length;x<F;x++){W=ca[x];$=W.color;ba=W.intensity;if(W instanceof THREE.DirectionalLight){W=
-K.dot(W.position)*ba;if(W>0){z.r+=$.r*W;z.g+=$.g*W;z.b+=$.b*W}}else if(W instanceof THREE.PointLight){Y.sub(W.position,R);Y.normalize();W=K.dot(Y)*ba;if(W>0){z.r+=$.r*W;z.g+=$.g*W;z.b+=$.b*W}}}}function La(x,R,K){if(K.opacity!=0){Ba(K.opacity);wa(K.blending);var z,F,W,$,ba,ca;if(K instanceof THREE.ParticleBasicMaterial){if(K.map){$=K.map;ba=$.width>>1;ca=$.height>>1;F=R.scale.x*j;W=R.scale.y*o;K=F*ba;z=W*ca;r.set(x.x-K,x.y-z,x.x+K,x.y+z);if(H.instersects(r)){l.save();l.translate(x.x,x.y);l.rotate(-R.rotation);
-l.scale(F,-W);l.translate(-ba,-ca);l.drawImage($,0,0);l.restore()}}}else if(K instanceof THREE.ParticleCircleMaterial){if(N){S.r=M.r+T.r+aa.r;S.g=M.g+T.g+aa.g;S.b=M.b+T.b+aa.b;e.r=K.color.r*S.r;e.g=K.color.g*S.g;e.b=K.color.b*S.b;e.updateStyleString()}else e.__styleString=K.color.__styleString;K=R.scale.x*j;z=R.scale.y*o;r.set(x.x-K,x.y-z,x.x+K,x.y+z);if(H.instersects(r)){F=e.__styleString;if(A!=F)l.fillStyle=A=F;l.save();l.translate(x.x,x.y);l.rotate(-R.rotation);l.scale(K,z);l.beginPath();l.arc(0,
-0,1,0,Ja,true);l.closePath();l.fill();l.restore()}}}}function Ma(x,R,K,z){if(z.opacity!=0){Ba(z.opacity);wa(z.blending);l.beginPath();l.moveTo(x.positionScreen.x,x.positionScreen.y);l.lineTo(R.positionScreen.x,R.positionScreen.y);l.closePath();if(z instanceof THREE.LineBasicMaterial){e.__styleString=z.color.__styleString;x=z.linewidth;if(v!=x)l.lineWidth=v=x;x=e.__styleString;if(B!=x)l.strokeStyle=B=x;l.stroke();r.inflate(z.linewidth*2)}}}function Fa(x,R,K,z,F,W){if(F.opacity!=0){Ba(F.opacity);wa(F.blending);
-J=x.positionScreen.x;I=x.positionScreen.y;O=R.positionScreen.x;E=R.positionScreen.y;f=K.positionScreen.x;m=K.positionScreen.y;l.beginPath();l.moveTo(J,I);l.lineTo(O,E);l.lineTo(f,m);l.lineTo(J,I);l.closePath();if(F instanceof THREE.MeshBasicMaterial)if(F.map)F.map.image.loaded&&F.map.mapping instanceof THREE.UVMapping&&qa(J,I,O,E,f,m,F.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);else if(F.env_map){if(F.env_map.image.loaded)if(F.env_map.mapping instanceof THREE.SphericalReflectionMapping){x=
-ua.matrix;Y.copy(z.vertexNormalsWorld[0]);Q=(Y.x*x.n11+Y.y*x.n12+Y.z*x.n13)*0.5+0.5;s=-(Y.x*x.n21+Y.y*x.n22+Y.z*x.n23)*0.5+0.5;Y.copy(z.vertexNormalsWorld[1]);U=(Y.x*x.n11+Y.y*x.n12+Y.z*x.n13)*0.5+0.5;P=-(Y.x*x.n21+Y.y*x.n22+Y.z*x.n23)*0.5+0.5;Y.copy(z.vertexNormalsWorld[2]);X=(Y.x*x.n11+Y.y*x.n12+Y.z*x.n13)*0.5+0.5;V=-(Y.x*x.n21+Y.y*x.n22+Y.z*x.n23)*0.5+0.5;qa(J,I,O,E,f,m,F.env_map.image,Q,s,U,P,X,V)}}else F.wireframe?xa(F.color.__styleString,F.wireframe_linewidth):ya(F.color.__styleString);else if(F instanceof
-THREE.MeshLambertMaterial){if(F.map&&!F.wireframe){F.map.mapping instanceof THREE.UVMapping&&qa(J,I,O,E,f,m,F.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);wa(THREE.SubtractiveBlending)}if(N)if(!F.wireframe&&F.shading==THREE.SmoothShading&&z.vertexNormalsWorld.length==3){p.r=k.r=h.r=M.r;p.g=k.g=h.g=M.g;p.b=k.b=h.b=M.b;va(W,z.v1.positionWorld,z.vertexNormalsWorld[0],p);va(W,z.v2.positionWorld,z.vertexNormalsWorld[1],k);va(W,z.v3.positionWorld,z.vertexNormalsWorld[2],
-h);t.r=(k.r+h.r)*0.5;t.g=(k.g+h.g)*0.5;t.b=(k.b+h.b)*0.5;C=Ga(p,k,h,t);qa(J,I,O,E,f,m,C,0,0,1,0,0,1)}else{S.r=M.r;S.g=M.g;S.b=M.b;va(W,z.centroidWorld,z.normalWorld,S);e.r=F.color.r*S.r;e.g=F.color.g*S.g;e.b=F.color.b*S.b;e.updateStyleString();F.wireframe?xa(e.__styleString,F.wireframe_linewidth):ya(e.__styleString)}else F.wireframe?xa(F.color.__styleString,F.wireframe_linewidth):ya(F.color.__styleString)}else if(F instanceof THREE.MeshDepthMaterial){w=F.__2near;D=F.__farPlusNear;q=F.__farMinusNear;
-p.r=p.g=p.b=1-w/(D-x.positionScreen.z*q);k.r=k.g=k.b=1-w/(D-R.positionScreen.z*q);h.r=h.g=h.b=1-w/(D-K.positionScreen.z*q);t.r=(k.r+h.r)*0.5;t.g=(k.g+h.g)*0.5;t.b=(k.b+h.b)*0.5;C=Ga(p,k,h,t);qa(J,I,O,E,f,m,C,0,0,1,0,0,1)}else if(F instanceof THREE.MeshNormalMaterial){e.r=Ca(z.normalWorld.x);e.g=Ca(z.normalWorld.y);e.b=Ca(z.normalWorld.z);e.updateStyleString();F.wireframe?xa(e.__styleString,F.wireframe_linewidth):ya(e.__styleString)}}}function xa(x,R){if(B!=x)l.strokeStyle=B=x;if(v!=R)l.lineWidth=
-v=R;l.stroke();r.inflate(R*2)}function ya(x){if(A!=x)l.fillStyle=A=x;l.fill()}function qa(x,R,K,z,F,W,$,ba,ca,ha,ea,ia,ra){var ka,ja;ka=$.width-1;ja=$.height-1;ba*=ka;ca*=ja;ha*=ka;ea*=ja;ia*=ka;ra*=ja;K-=x;z-=R;F-=x;W-=R;ha-=ba;ea-=ca;ia-=ba;ra-=ca;ja=1/(ha*ra-ia*ea);ka=(ra*K-ea*F)*ja;ea=(ra*z-ea*W)*ja;K=(ha*F-ia*K)*ja;z=(ha*W-ia*z)*ja;x=x-ka*ba-K*ca;R=R-ea*ba-z*ca;l.save();l.transform(ka,ea,K,z,x,R);l.clip();l.drawImage($,0,0);l.restore()}function Ba(x){if(n!=x)l.globalAlpha=n=x}function wa(x){if(c!=
-x){switch(x){case THREE.NormalBlending:l.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:l.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:l.globalCompositeOperation="darker"}c=x}}function Ga(x,R,K,z){var F=~~(x.r*255),W=~~(x.g*255);x=~~(x.b*255);var $=~~(R.r*255),ba=~~(R.g*255);R=~~(R.b*255);var ca=~~(K.r*255),ha=~~(K.g*255);K=~~(K.b*255);var ea=~~(z.r*255),ia=~~(z.g*255);z=~~(z.b*255);da[0]=F<0?0:F>255?255:F;da[1]=W<0?0:W>255?255:W;da[2]=x<0?0:x>
-255?255:x;da[4]=$<0?0:$>255?255:$;da[5]=ba<0?0:ba>255?255:ba;da[6]=R<0?0:R>255?255:R;da[8]=ca<0?0:ca>255?255:ca;da[9]=ha<0?0:ha>255?255:ha;da[10]=K<0?0:K>255?255:K;da[12]=ea<0?0:ea>255?255:ea;da[13]=ia<0?0:ia>255?255:ia;da[14]=z<0?0:z>255?255:z;oa.putImageData(Aa,0,0);ta.drawImage(na,0,0);return pa}function Ca(x){x=(x+1)*0.5;return x<0?0:x>1?1:x}function Da(x,R){var K=R.x-x.x,z=R.y-x.y,F=1/Math.sqrt(K*K+z*z);K*=F;z*=F;R.x+=K;R.y+=z;x.x-=K;x.y-=z}var za,Ha,Z,fa,ma,Ea,Ia,sa;l.setTransform(1,0,0,-1,
-j,o);this.autoClear&&this.clear();a=b.projectScene(ga,ua,true);(N=ga.lights.length>0)&&Ka(ga);za=0;for(Ha=a.length;za<Ha;za++){Z=a[za];r.empty();if(Z instanceof THREE.RenderableParticle){u=Z;u.x*=j;u.y*=o;fa=0;for(ma=Z.material.length;fa<ma;fa++)La(u,Z,Z.material[fa],ga)}else if(Z instanceof THREE.RenderableLine){u=Z.v1;G=Z.v2;u.positionScreen.x*=j;u.positionScreen.y*=o;G.positionScreen.x*=j;G.positionScreen.y*=o;r.addPoint(u.positionScreen.x,u.positionScreen.y);r.addPoint(G.positionScreen.x,G.positionScreen.y);
-if(H.instersects(r)){fa=0;for(ma=Z.material.length;fa<ma;)Ma(u,G,Z,Z.material[fa++],ga)}}else if(Z instanceof THREE.RenderableFace3){u=Z.v1;G=Z.v2;L=Z.v3;u.positionScreen.x*=j;u.positionScreen.y*=o;G.positionScreen.x*=j;G.positionScreen.y*=o;L.positionScreen.x*=j;L.positionScreen.y*=o;if(Z.overdraw){Da(u.positionScreen,G.positionScreen);Da(G.positionScreen,L.positionScreen);Da(L.positionScreen,u.positionScreen)}r.add3Points(u.positionScreen.x,u.positionScreen.y,G.positionScreen.x,G.positionScreen.y,
-L.positionScreen.x,L.positionScreen.y);if(H.instersects(r)){fa=0;for(ma=Z.meshMaterial.length;fa<ma;){sa=Z.meshMaterial[fa++];if(sa instanceof THREE.MeshFaceMaterial){Ea=0;for(Ia=Z.faceMaterial.length;Ea<Ia;)(sa=Z.faceMaterial[Ea++])&&Fa(u,G,L,Z,sa,ga)}else Fa(u,G,L,Z,sa,ga)}}}y.addRectangle(r)}l.setTransform(1,0,0,1,0,0)}};
+na.width=na.height=2;oa=na.getContext("2d");oa.fillStyle="rgba(0,0,0,1)";oa.fillRect(0,0,2,2);Aa=oa.getImageData(0,0,2,2);da=Aa.data;pa=document.createElement("canvas");pa.width=pa.height=la;ta=pa.getContext("2d");ta.translate(-la/2,-la/2);ta.scale(la,la);la--;this.domElement=g;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ga,ua){d=ga;i=ua;j=d/2;o=i/2;g.width=d;g.height=i;H.set(-j,-o,j,o)};this.clear=function(){if(!y.isEmpty()){y.inflate(1);y.minSelf(H);l.clearRect(y.getX(),
+y.getY(),y.getWidth(),y.getHeight());y.empty()}};this.render=function(ga,ua){function Ka(x){var R,K,z,F=x.lights;M.setRGB(0,0,0);T.setRGB(0,0,0);aa.setRGB(0,0,0);x=0;for(R=F.length;x<R;x++){K=F[x];z=K.color;if(K instanceof THREE.AmbientLight){M.r+=z.r;M.g+=z.g;M.b+=z.b}else if(K instanceof THREE.DirectionalLight){T.r+=z.r;T.g+=z.g;T.b+=z.b}else if(K instanceof THREE.PointLight){aa.r+=z.r;aa.g+=z.g;aa.b+=z.b}}}function va(x,R,K,z){var F,W,$,ba,ca=x.lights;x=0;for(F=ca.length;x<F;x++){W=ca[x];$=W.color;
+ba=W.intensity;if(W instanceof THREE.DirectionalLight){W=K.dot(W.position)*ba;if(W>0){z.r+=$.r*W;z.g+=$.g*W;z.b+=$.b*W}}else if(W instanceof THREE.PointLight){Y.sub(W.position,R);Y.normalize();W=K.dot(Y)*ba;if(W>0){z.r+=$.r*W;z.g+=$.g*W;z.b+=$.b*W}}}}function La(x,R,K){if(K.opacity!=0){Ba(K.opacity);wa(K.blending);var z,F,W,$,ba,ca;if(K instanceof THREE.ParticleBasicMaterial){if(K.map){$=K.map;ba=$.width>>1;ca=$.height>>1;F=R.scale.x*j;W=R.scale.y*o;K=F*ba;z=W*ca;r.set(x.x-K,x.y-z,x.x+K,x.y+z);if(H.instersects(r)){l.save();
+l.translate(x.x,x.y);l.rotate(-R.rotation);l.scale(F,-W);l.translate(-ba,-ca);l.drawImage($,0,0);l.restore()}}}else if(K instanceof THREE.ParticleCircleMaterial){if(N){S.r=M.r+T.r+aa.r;S.g=M.g+T.g+aa.g;S.b=M.b+T.b+aa.b;e.r=K.color.r*S.r;e.g=K.color.g*S.g;e.b=K.color.b*S.b;e.updateStyleString()}else e.__styleString=K.color.__styleString;K=R.scale.x*j;z=R.scale.y*o;r.set(x.x-K,x.y-z,x.x+K,x.y+z);if(H.instersects(r)){F=e.__styleString;if(A!=F)l.fillStyle=A=F;l.save();l.translate(x.x,x.y);l.rotate(-R.rotation);
+l.scale(K,z);l.beginPath();l.arc(0,0,1,0,Ja,true);l.closePath();l.fill();l.restore()}}}}function Ma(x,R,K,z){if(z.opacity!=0){Ba(z.opacity);wa(z.blending);l.beginPath();l.moveTo(x.positionScreen.x,x.positionScreen.y);l.lineTo(R.positionScreen.x,R.positionScreen.y);l.closePath();if(z instanceof THREE.LineBasicMaterial){e.__styleString=z.color.__styleString;x=z.linewidth;if(v!=x)l.lineWidth=v=x;x=e.__styleString;if(B!=x)l.strokeStyle=B=x;l.stroke();r.inflate(z.linewidth*2)}}}function Fa(x,R,K,z,F,W){if(F.opacity!=
+0){Ba(F.opacity);wa(F.blending);J=x.positionScreen.x;I=x.positionScreen.y;O=R.positionScreen.x;E=R.positionScreen.y;f=K.positionScreen.x;m=K.positionScreen.y;l.beginPath();l.moveTo(J,I);l.lineTo(O,E);l.lineTo(f,m);l.lineTo(J,I);l.closePath();if(F instanceof THREE.MeshBasicMaterial)if(F.map)F.map.image.loaded&&F.map.mapping instanceof THREE.UVMapping&&qa(J,I,O,E,f,m,F.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);else if(F.env_map){if(F.env_map.image.loaded)if(F.env_map.mapping instanceof
+THREE.SphericalReflectionMapping){x=ua.matrix;Y.copy(z.vertexNormalsWorld[0]);Q=(Y.x*x.n11+Y.y*x.n12+Y.z*x.n13)*0.5+0.5;s=-(Y.x*x.n21+Y.y*x.n22+Y.z*x.n23)*0.5+0.5;Y.copy(z.vertexNormalsWorld[1]);U=(Y.x*x.n11+Y.y*x.n12+Y.z*x.n13)*0.5+0.5;P=-(Y.x*x.n21+Y.y*x.n22+Y.z*x.n23)*0.5+0.5;Y.copy(z.vertexNormalsWorld[2]);X=(Y.x*x.n11+Y.y*x.n12+Y.z*x.n13)*0.5+0.5;V=-(Y.x*x.n21+Y.y*x.n22+Y.z*x.n23)*0.5+0.5;qa(J,I,O,E,f,m,F.env_map.image,Q,s,U,P,X,V)}}else F.wireframe?xa(F.color.__styleString,F.wireframe_linewidth):
+ya(F.color.__styleString);else if(F instanceof THREE.MeshLambertMaterial){if(F.map&&!F.wireframe){F.map.mapping instanceof THREE.UVMapping&&qa(J,I,O,E,f,m,F.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);wa(THREE.SubtractiveBlending)}if(N)if(!F.wireframe&&F.shading==THREE.SmoothShading&&z.vertexNormalsWorld.length==3){p.r=k.r=h.r=M.r;p.g=k.g=h.g=M.g;p.b=k.b=h.b=M.b;va(W,z.v1.positionWorld,z.vertexNormalsWorld[0],p);va(W,z.v2.positionWorld,z.vertexNormalsWorld[1],k);va(W,
+z.v3.positionWorld,z.vertexNormalsWorld[2],h);t.r=(k.r+h.r)*0.5;t.g=(k.g+h.g)*0.5;t.b=(k.b+h.b)*0.5;C=Ga(p,k,h,t);qa(J,I,O,E,f,m,C,0,0,1,0,0,1)}else{S.r=M.r;S.g=M.g;S.b=M.b;va(W,z.centroidWorld,z.normalWorld,S);e.r=F.color.r*S.r;e.g=F.color.g*S.g;e.b=F.color.b*S.b;e.updateStyleString();F.wireframe?xa(e.__styleString,F.wireframe_linewidth):ya(e.__styleString)}else F.wireframe?xa(F.color.__styleString,F.wireframe_linewidth):ya(F.color.__styleString)}else if(F instanceof THREE.MeshDepthMaterial){w=F.__2near;
+D=F.__farPlusNear;q=F.__farMinusNear;p.r=p.g=p.b=1-w/(D-x.positionScreen.z*q);k.r=k.g=k.b=1-w/(D-R.positionScreen.z*q);h.r=h.g=h.b=1-w/(D-K.positionScreen.z*q);t.r=(k.r+h.r)*0.5;t.g=(k.g+h.g)*0.5;t.b=(k.b+h.b)*0.5;C=Ga(p,k,h,t);qa(J,I,O,E,f,m,C,0,0,1,0,0,1)}else if(F instanceof THREE.MeshNormalMaterial){e.r=Ca(z.normalWorld.x);e.g=Ca(z.normalWorld.y);e.b=Ca(z.normalWorld.z);e.updateStyleString();F.wireframe?xa(e.__styleString,F.wireframe_linewidth):ya(e.__styleString)}}}function xa(x,R){if(B!=x)l.strokeStyle=
+B=x;if(v!=R)l.lineWidth=v=R;l.stroke();r.inflate(R*2)}function ya(x){if(A!=x)l.fillStyle=A=x;l.fill()}function qa(x,R,K,z,F,W,$,ba,ca,ha,ea,ia,ra){var ka,ja;ka=$.width-1;ja=$.height-1;ba*=ka;ca*=ja;ha*=ka;ea*=ja;ia*=ka;ra*=ja;K-=x;z-=R;F-=x;W-=R;ha-=ba;ea-=ca;ia-=ba;ra-=ca;ja=1/(ha*ra-ia*ea);ka=(ra*K-ea*F)*ja;ea=(ra*z-ea*W)*ja;K=(ha*F-ia*K)*ja;z=(ha*W-ia*z)*ja;x=x-ka*ba-K*ca;R=R-ea*ba-z*ca;l.save();l.transform(ka,ea,K,z,x,R);l.clip();l.drawImage($,0,0);l.restore()}function Ba(x){if(n!=x)l.globalAlpha=
+n=x}function wa(x){if(c!=x){switch(x){case THREE.NormalBlending:l.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:l.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:l.globalCompositeOperation="darker"}c=x}}function Ga(x,R,K,z){var F=~~(x.r*255),W=~~(x.g*255);x=~~(x.b*255);var $=~~(R.r*255),ba=~~(R.g*255);R=~~(R.b*255);var ca=~~(K.r*255),ha=~~(K.g*255);K=~~(K.b*255);var ea=~~(z.r*255),ia=~~(z.g*255);z=~~(z.b*255);da[0]=F<0?0:F>255?255:F;da[1]=W<0?0:W>
+255?255:W;da[2]=x<0?0:x>255?255:x;da[4]=$<0?0:$>255?255:$;da[5]=ba<0?0:ba>255?255:ba;da[6]=R<0?0:R>255?255:R;da[8]=ca<0?0:ca>255?255:ca;da[9]=ha<0?0:ha>255?255:ha;da[10]=K<0?0:K>255?255:K;da[12]=ea<0?0:ea>255?255:ea;da[13]=ia<0?0:ia>255?255:ia;da[14]=z<0?0:z>255?255:z;oa.putImageData(Aa,0,0);ta.drawImage(na,0,0);return pa}function Ca(x){x=(x+1)*0.5;return x<0?0:x>1?1:x}function Da(x,R){var K=R.x-x.x,z=R.y-x.y,F=1/Math.sqrt(K*K+z*z);K*=F;z*=F;R.x+=K;R.y+=z;x.x-=K;x.y-=z}var za,Ha,Z,fa,ma,Ea,Ia,sa;
+l.setTransform(1,0,0,-1,j,o);this.autoClear&&this.clear();a=b.projectScene(ga,ua,this.sortElements);(N=ga.lights.length>0)&&Ka(ga);za=0;for(Ha=a.length;za<Ha;za++){Z=a[za];r.empty();if(Z instanceof THREE.RenderableParticle){u=Z;u.x*=j;u.y*=o;fa=0;for(ma=Z.material.length;fa<ma;fa++)La(u,Z,Z.material[fa],ga)}else if(Z instanceof THREE.RenderableLine){u=Z.v1;G=Z.v2;u.positionScreen.x*=j;u.positionScreen.y*=o;G.positionScreen.x*=j;G.positionScreen.y*=o;r.addPoint(u.positionScreen.x,u.positionScreen.y);
+r.addPoint(G.positionScreen.x,G.positionScreen.y);if(H.instersects(r)){fa=0;for(ma=Z.material.length;fa<ma;)Ma(u,G,Z,Z.material[fa++],ga)}}else if(Z instanceof THREE.RenderableFace3){u=Z.v1;G=Z.v2;L=Z.v3;u.positionScreen.x*=j;u.positionScreen.y*=o;G.positionScreen.x*=j;G.positionScreen.y*=o;L.positionScreen.x*=j;L.positionScreen.y*=o;if(Z.overdraw){Da(u.positionScreen,G.positionScreen);Da(G.positionScreen,L.positionScreen);Da(L.positionScreen,u.positionScreen)}r.add3Points(u.positionScreen.x,u.positionScreen.y,
+G.positionScreen.x,G.positionScreen.y,L.positionScreen.x,L.positionScreen.y);if(H.instersects(r)){fa=0;for(ma=Z.meshMaterial.length;fa<ma;){sa=Z.meshMaterial[fa++];if(sa instanceof THREE.MeshFaceMaterial){Ea=0;for(Ia=Z.faceMaterial.length;Ea<Ia;)(sa=Z.faceMaterial[Ea++])&&Fa(u,G,L,Z,sa,ga)}else Fa(u,G,L,Z,sa,ga)}}}y.addRectangle(r)}l.setTransform(1,0,0,1,0,0)}};
 THREE.SVGRenderer=function(){function a(P,X,V){var H,y,r,N;H=0;for(y=P.lights.length;H<y;H++){r=P.lights[H];if(r instanceof THREE.DirectionalLight){N=X.normalWorld.dot(r.position)*r.intensity;if(N>0){V.r+=r.color.r*N;V.g+=r.color.g*N;V.b+=r.color.b*N}}else if(r instanceof THREE.PointLight){h.sub(r.position,X.centroidWorld);h.normalize();N=X.normalWorld.dot(h)*r.intensity;if(N>0){V.r+=r.color.r*N;V.g+=r.color.g*N;V.b+=r.color.b*N}}}}function b(P,X,V,H,y,r){q=d(C++);q.setAttribute("d","M "+P.positionScreen.x+
 THREE.SVGRenderer=function(){function a(P,X,V){var H,y,r,N;H=0;for(y=P.lights.length;H<y;H++){r=P.lights[H];if(r instanceof THREE.DirectionalLight){N=X.normalWorld.dot(r.position)*r.intensity;if(N>0){V.r+=r.color.r*N;V.g+=r.color.g*N;V.b+=r.color.b*N}}else if(r instanceof THREE.PointLight){h.sub(r.position,X.centroidWorld);h.normalize();N=X.normalWorld.dot(h)*r.intensity;if(N>0){V.r+=r.color.r*N;V.g+=r.color.g*N;V.b+=r.color.b*N}}}}function b(P,X,V,H,y,r){q=d(C++);q.setAttribute("d","M "+P.positionScreen.x+
 " "+P.positionScreen.y+" L "+X.positionScreen.x+" "+X.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+"z");if(y instanceof THREE.MeshBasicMaterial)E.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshLambertMaterial)if(O){f.r=m.r;f.g=m.g;f.b=m.b;a(r,H,f);E.r=y.color.r*f.r;E.g=y.color.g*f.g;E.b=y.color.b*f.b;E.updateStyleString()}else E.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshDepthMaterial){k=1-y.__2near/(y.__farPlusNear-H.z*y.__farMinusNear);
 " "+P.positionScreen.y+" L "+X.positionScreen.x+" "+X.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+"z");if(y instanceof THREE.MeshBasicMaterial)E.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshLambertMaterial)if(O){f.r=m.r;f.g=m.g;f.b=m.b;a(r,H,f);E.r=y.color.r*f.r;E.g=y.color.g*f.g;E.b=y.color.b*f.b;E.updateStyleString()}else E.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshDepthMaterial){k=1-y.__2near/(y.__farPlusNear-H.z*y.__farMinusNear);
 E.setRGB(k,k,k)}else y instanceof THREE.MeshNormalMaterial&&E.setRGB(i(H.normalWorld.x),i(H.normalWorld.y),i(H.normalWorld.z));y.wireframe?q.setAttribute("style","fill: none; stroke: "+E.__styleString+"; stroke-width: "+y.wireframe_linewidth+"; stroke-opacity: "+y.opacity+"; stroke-linecap: "+y.wireframe_linecap+"; stroke-linejoin: "+y.wireframe_linejoin):q.setAttribute("style","fill: "+E.__styleString+"; fill-opacity: "+y.opacity);l.appendChild(q)}function g(P,X,V,H,y,r,N){q=d(C++);q.setAttribute("d",
 E.setRGB(k,k,k)}else y instanceof THREE.MeshNormalMaterial&&E.setRGB(i(H.normalWorld.x),i(H.normalWorld.y),i(H.normalWorld.z));y.wireframe?q.setAttribute("style","fill: none; stroke: "+E.__styleString+"; stroke-width: "+y.wireframe_linewidth+"; stroke-opacity: "+y.opacity+"; stroke-linecap: "+y.wireframe_linecap+"; stroke-linejoin: "+y.wireframe_linejoin):q.setAttribute("style","fill: "+E.__styleString+"; fill-opacity: "+y.opacity);l.appendChild(q)}function g(P,X,V,H,y,r,N){q=d(C++);q.setAttribute("d",
 "M "+P.positionScreen.x+" "+P.positionScreen.y+" L "+X.positionScreen.x+" "+X.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+" L "+H.positionScreen.x+","+H.positionScreen.y+"z");if(r instanceof THREE.MeshBasicMaterial)E.__styleString=r.color.__styleString;else if(r instanceof THREE.MeshLambertMaterial)if(O){f.r=m.r;f.g=m.g;f.b=m.b;a(N,y,f);E.r=r.color.r*f.r;E.g=r.color.g*f.g;E.b=r.color.b*f.b;E.updateStyleString()}else E.__styleString=r.color.__styleString;else if(r instanceof THREE.MeshDepthMaterial){k=
 "M "+P.positionScreen.x+" "+P.positionScreen.y+" L "+X.positionScreen.x+" "+X.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+" L "+H.positionScreen.x+","+H.positionScreen.y+"z");if(r instanceof THREE.MeshBasicMaterial)E.__styleString=r.color.__styleString;else if(r instanceof THREE.MeshLambertMaterial)if(O){f.r=m.r;f.g=m.g;f.b=m.b;a(N,y,f);E.r=r.color.r*f.r;E.g=r.color.g*f.g;E.b=r.color.b*f.b;E.updateStyleString()}else E.__styleString=r.color.__styleString;else if(r instanceof THREE.MeshDepthMaterial){k=
 1-r.__2near/(r.__farPlusNear-y.z*r.__farMinusNear);E.setRGB(k,k,k)}else r instanceof THREE.MeshNormalMaterial&&E.setRGB(i(y.normalWorld.x),i(y.normalWorld.y),i(y.normalWorld.z));r.wireframe?q.setAttribute("style","fill: none; stroke: "+E.__styleString+"; stroke-width: "+r.wireframe_linewidth+"; stroke-opacity: "+r.opacity+"; stroke-linecap: "+r.wireframe_linecap+"; stroke-linejoin: "+r.wireframe_linejoin):q.setAttribute("style","fill: "+E.__styleString+"; fill-opacity: "+r.opacity);l.appendChild(q)}
 1-r.__2near/(r.__farPlusNear-y.z*r.__farMinusNear);E.setRGB(k,k,k)}else r instanceof THREE.MeshNormalMaterial&&E.setRGB(i(y.normalWorld.x),i(y.normalWorld.y),i(y.normalWorld.z));r.wireframe?q.setAttribute("style","fill: none; stroke: "+E.__styleString+"; stroke-width: "+r.wireframe_linewidth+"; stroke-opacity: "+r.opacity+"; stroke-linecap: "+r.wireframe_linecap+"; stroke-linejoin: "+r.wireframe_linejoin):q.setAttribute("style","fill: "+E.__styleString+"; fill-opacity: "+r.opacity);l.appendChild(q)}
 function d(P){if(t[P]==null){t[P]=document.createElementNS("http://www.w3.org/2000/svg","path");U==0&&t[P].setAttribute("shape-rendering","crispEdges");return t[P]}return t[P]}function i(P){return P<0?Math.min((1+P)*0.5,0.5):0.5+Math.min(P*0.5,0.5)}var j=null,o=new THREE.Projector,l=document.createElementNS("http://www.w3.org/2000/svg","svg"),n,c,B,A,v,u,G,L,J=new THREE.Rectangle,I=new THREE.Rectangle,O=false,E=new THREE.Color(16777215),f=new THREE.Color(16777215),m=new THREE.Color(0),e=new THREE.Color(0),
 function d(P){if(t[P]==null){t[P]=document.createElementNS("http://www.w3.org/2000/svg","path");U==0&&t[P].setAttribute("shape-rendering","crispEdges");return t[P]}return t[P]}function i(P){return P<0?Math.min((1+P)*0.5,0.5):0.5+Math.min(P*0.5,0.5)}var j=null,o=new THREE.Projector,l=document.createElementNS("http://www.w3.org/2000/svg","svg"),n,c,B,A,v,u,G,L,J=new THREE.Rectangle,I=new THREE.Rectangle,O=false,E=new THREE.Color(16777215),f=new THREE.Color(16777215),m=new THREE.Color(0),e=new THREE.Color(0),
-p=new THREE.Color(0),k,h=new THREE.Vector3,t=[],w=[],D=[],q,C,Q,s,U=1;this.domElement=l;this.autoClear=true;this.setQuality=function(P){switch(P){case "high":U=1;break;case "low":U=0}};this.setSize=function(P,X){n=P;c=X;B=n/2;A=c/2;l.setAttribute("viewBox",-B+" "+-A+" "+n+" "+c);l.setAttribute("width",n);l.setAttribute("height",c);J.set(-B,-A,B,A)};this.clear=function(){for(;l.childNodes.length>0;)l.removeChild(l.childNodes[0])};this.render=function(P,X){var V,H,y,r,N,S,M,T;this.autoClear&&this.clear();
-j=o.projectScene(P,X,true);s=Q=C=0;if(O=P.lights.length>0){M=P.lights;m.setRGB(0,0,0);e.setRGB(0,0,0);p.setRGB(0,0,0);V=0;for(H=M.length;V<H;V++){y=M[V];r=y.color;if(y instanceof THREE.AmbientLight){m.r+=r.r;m.g+=r.g;m.b+=r.b}else if(y instanceof THREE.DirectionalLight){e.r+=r.r;e.g+=r.g;e.b+=r.b}else if(y instanceof THREE.PointLight){p.r+=r.r;p.g+=r.g;p.b+=r.b}}}V=0;for(H=j.length;V<H;V++){M=j[V];I.empty();if(M instanceof THREE.RenderableParticle){v=M;v.x*=B;v.y*=-A;y=0;for(r=M.material.length;y<
-r;y++)if(T=M.material[y]){N=v;S=M;T=T;var aa=Q++;if(w[aa]==null){w[aa]=document.createElementNS("http://www.w3.org/2000/svg","circle");U==0&&w[aa].setAttribute("shape-rendering","crispEdges")}q=w[aa];q.setAttribute("cx",N.x);q.setAttribute("cy",N.y);q.setAttribute("r",S.scale.x*B);if(T instanceof THREE.ParticleCircleMaterial){if(O){f.r=m.r+e.r+p.r;f.g=m.g+e.g+p.g;f.b=m.b+e.b+p.b;E.r=T.color.r*f.r;E.g=T.color.g*f.g;E.b=T.color.b*f.b;E.updateStyleString()}else E=T.color;q.setAttribute("style","fill: "+
-E.__styleString)}l.appendChild(q)}}else if(M instanceof THREE.RenderableLine){v=M.v1;u=M.v2;v.positionScreen.x*=B;v.positionScreen.y*=-A;u.positionScreen.x*=B;u.positionScreen.y*=-A;I.addPoint(v.positionScreen.x,v.positionScreen.y);I.addPoint(u.positionScreen.x,u.positionScreen.y);if(J.instersects(I)){y=0;for(r=M.material.length;y<r;)if(T=M.material[y++]){N=v;S=u;T=T;aa=s++;if(D[aa]==null){D[aa]=document.createElementNS("http://www.w3.org/2000/svg","line");U==0&&D[aa].setAttribute("shape-rendering",
-"crispEdges")}q=D[aa];q.setAttribute("x1",N.positionScreen.x);q.setAttribute("y1",N.positionScreen.y);q.setAttribute("x2",S.positionScreen.x);q.setAttribute("y2",S.positionScreen.y);if(T instanceof THREE.LineBasicMaterial){E.__styleString=T.color.__styleString;q.setAttribute("style","fill: none; stroke: "+E.__styleString+"; stroke-width: "+T.linewidth+"; stroke-opacity: "+T.opacity+"; stroke-linecap: "+T.linecap+"; stroke-linejoin: "+T.linejoin);l.appendChild(q)}}}}else if(M instanceof THREE.RenderableFace3){v=
-M.v1;u=M.v2;G=M.v3;v.positionScreen.x*=B;v.positionScreen.y*=-A;u.positionScreen.x*=B;u.positionScreen.y*=-A;G.positionScreen.x*=B;G.positionScreen.y*=-A;I.addPoint(v.positionScreen.x,v.positionScreen.y);I.addPoint(u.positionScreen.x,u.positionScreen.y);I.addPoint(G.positionScreen.x,G.positionScreen.y);if(J.instersects(I)){y=0;for(r=M.meshMaterial.length;y<r;){T=M.meshMaterial[y++];if(T instanceof THREE.MeshFaceMaterial){N=0;for(S=M.faceMaterial.length;N<S;)(T=M.faceMaterial[N++])&&b(v,u,G,M,T,P)}else T&&
-b(v,u,G,M,T,P)}}}else if(M instanceof THREE.RenderableFace4){v=M.v1;u=M.v2;G=M.v3;L=M.v4;v.positionScreen.x*=B;v.positionScreen.y*=-A;u.positionScreen.x*=B;u.positionScreen.y*=-A;G.positionScreen.x*=B;G.positionScreen.y*=-A;L.positionScreen.x*=B;L.positionScreen.y*=-A;I.addPoint(v.positionScreen.x,v.positionScreen.y);I.addPoint(u.positionScreen.x,u.positionScreen.y);I.addPoint(G.positionScreen.x,G.positionScreen.y);I.addPoint(L.positionScreen.x,L.positionScreen.y);if(J.instersects(I)){y=0;for(r=M.meshMaterial.length;y<
-r;){T=M.meshMaterial[y++];if(T instanceof THREE.MeshFaceMaterial){N=0;for(S=M.faceMaterial.length;N<S;)(T=M.faceMaterial[N++])&&g(v,u,G,L,M,T,P)}else T&&g(v,u,G,L,M,T,P)}}}}}};
+p=new THREE.Color(0),k,h=new THREE.Vector3,t=[],w=[],D=[],q,C,Q,s,U=1;this.domElement=l;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(P){switch(P){case "high":U=1;break;case "low":U=0}};this.setSize=function(P,X){n=P;c=X;B=n/2;A=c/2;l.setAttribute("viewBox",-B+" "+-A+" "+n+" "+c);l.setAttribute("width",n);l.setAttribute("height",c);J.set(-B,-A,B,A)};this.clear=function(){for(;l.childNodes.length>0;)l.removeChild(l.childNodes[0])};this.render=function(P,X){var V,H,
+y,r,N,S,M,T;this.autoClear&&this.clear();j=o.projectScene(P,X,this.sortElements);s=Q=C=0;if(O=P.lights.length>0){M=P.lights;m.setRGB(0,0,0);e.setRGB(0,0,0);p.setRGB(0,0,0);V=0;for(H=M.length;V<H;V++){y=M[V];r=y.color;if(y instanceof THREE.AmbientLight){m.r+=r.r;m.g+=r.g;m.b+=r.b}else if(y instanceof THREE.DirectionalLight){e.r+=r.r;e.g+=r.g;e.b+=r.b}else if(y instanceof THREE.PointLight){p.r+=r.r;p.g+=r.g;p.b+=r.b}}}V=0;for(H=j.length;V<H;V++){M=j[V];I.empty();if(M instanceof THREE.RenderableParticle){v=
+M;v.x*=B;v.y*=-A;y=0;for(r=M.material.length;y<r;y++)if(T=M.material[y]){N=v;S=M;T=T;var aa=Q++;if(w[aa]==null){w[aa]=document.createElementNS("http://www.w3.org/2000/svg","circle");U==0&&w[aa].setAttribute("shape-rendering","crispEdges")}q=w[aa];q.setAttribute("cx",N.x);q.setAttribute("cy",N.y);q.setAttribute("r",S.scale.x*B);if(T instanceof THREE.ParticleCircleMaterial){if(O){f.r=m.r+e.r+p.r;f.g=m.g+e.g+p.g;f.b=m.b+e.b+p.b;E.r=T.color.r*f.r;E.g=T.color.g*f.g;E.b=T.color.b*f.b;E.updateStyleString()}else E=
+T.color;q.setAttribute("style","fill: "+E.__styleString)}l.appendChild(q)}}else if(M instanceof THREE.RenderableLine){v=M.v1;u=M.v2;v.positionScreen.x*=B;v.positionScreen.y*=-A;u.positionScreen.x*=B;u.positionScreen.y*=-A;I.addPoint(v.positionScreen.x,v.positionScreen.y);I.addPoint(u.positionScreen.x,u.positionScreen.y);if(J.instersects(I)){y=0;for(r=M.material.length;y<r;)if(T=M.material[y++]){N=v;S=u;T=T;aa=s++;if(D[aa]==null){D[aa]=document.createElementNS("http://www.w3.org/2000/svg","line");
+U==0&&D[aa].setAttribute("shape-rendering","crispEdges")}q=D[aa];q.setAttribute("x1",N.positionScreen.x);q.setAttribute("y1",N.positionScreen.y);q.setAttribute("x2",S.positionScreen.x);q.setAttribute("y2",S.positionScreen.y);if(T instanceof THREE.LineBasicMaterial){E.__styleString=T.color.__styleString;q.setAttribute("style","fill: none; stroke: "+E.__styleString+"; stroke-width: "+T.linewidth+"; stroke-opacity: "+T.opacity+"; stroke-linecap: "+T.linecap+"; stroke-linejoin: "+T.linejoin);l.appendChild(q)}}}}else if(M instanceof
+THREE.RenderableFace3){v=M.v1;u=M.v2;G=M.v3;v.positionScreen.x*=B;v.positionScreen.y*=-A;u.positionScreen.x*=B;u.positionScreen.y*=-A;G.positionScreen.x*=B;G.positionScreen.y*=-A;I.addPoint(v.positionScreen.x,v.positionScreen.y);I.addPoint(u.positionScreen.x,u.positionScreen.y);I.addPoint(G.positionScreen.x,G.positionScreen.y);if(J.instersects(I)){y=0;for(r=M.meshMaterial.length;y<r;){T=M.meshMaterial[y++];if(T instanceof THREE.MeshFaceMaterial){N=0;for(S=M.faceMaterial.length;N<S;)(T=M.faceMaterial[N++])&&
+b(v,u,G,M,T,P)}else T&&b(v,u,G,M,T,P)}}}else if(M instanceof THREE.RenderableFace4){v=M.v1;u=M.v2;G=M.v3;L=M.v4;v.positionScreen.x*=B;v.positionScreen.y*=-A;u.positionScreen.x*=B;u.positionScreen.y*=-A;G.positionScreen.x*=B;G.positionScreen.y*=-A;L.positionScreen.x*=B;L.positionScreen.y*=-A;I.addPoint(v.positionScreen.x,v.positionScreen.y);I.addPoint(u.positionScreen.x,u.positionScreen.y);I.addPoint(G.positionScreen.x,G.positionScreen.y);I.addPoint(L.positionScreen.x,L.positionScreen.y);if(J.instersects(I)){y=
+0;for(r=M.meshMaterial.length;y<r;){T=M.meshMaterial[y++];if(T instanceof THREE.MeshFaceMaterial){N=0;for(S=M.faceMaterial.length;N<S;)(T=M.faceMaterial[N++])&&g(v,u,G,L,M,T,P)}else T&&g(v,u,G,L,M,T,P)}}}}}};
 THREE.WebGLRenderer=function(a){function b(f,m){var e=c.createProgram(),p=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(e,o("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"+
 THREE.WebGLRenderer=function(a){function b(f,m){var e=c.createProgram(),p=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(e,o("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"+
 f));c.attachShader(e,o("vertex",p+m));c.linkProgram(e);c.getProgramParameter(e,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(e,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");e.uniforms={};e.attributes={};return e}function g(f,m){if(f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,
 f));c.attachShader(e,o("vertex",p+m));c.linkProgram(e);c.getProgramParameter(e,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(e,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");e.uniforms={};e.attributes={};return e}function g(f,m){if(f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,
 c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var e=0;e<6;++e)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,f.image[e]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+m);c.bindTexture(c.TEXTURE_CUBE_MAP,
 c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var e=0;e<6;++e)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,f.image[e]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+m);c.bindTexture(c.TEXTURE_CUBE_MAP,

+ 25 - 25
build/ThreeDebug.js

@@ -101,37 +101,37 @@ q.positionScreen.copy(q.position);O.multiplyVector4(q.positionScreen);C=w[y-1];E
 x.x=J.x/J.w;x.y=J.y/J.w;x.z=J.z;x.rotation=t.rotation.z;x.scale.x=t.scale.x*Math.abs(x.x-(J.x+p.projectionMatrix.n11)/(J.w+p.projectionMatrix.n14));x.scale.y=t.scale.y*Math.abs(x.y-(J.y+p.projectionMatrix.n22)/(J.w+p.projectionMatrix.n24));x.material=t.material;h.push(x);v++}}}}l&&h.sort(b);return h};this.unprojectVector=function(e,p){var l=new THREE.Matrix4;l.multiply(THREE.Matrix4.makeInvert(p.matrix),THREE.Matrix4.makeInvert(p.projectionMatrix));l.multiplyVector3(e);return e}};
 x.x=J.x/J.w;x.y=J.y/J.w;x.z=J.z;x.rotation=t.rotation.z;x.scale.x=t.scale.x*Math.abs(x.x-(J.x+p.projectionMatrix.n11)/(J.w+p.projectionMatrix.n14));x.scale.y=t.scale.y*Math.abs(x.y-(J.y+p.projectionMatrix.n22)/(J.w+p.projectionMatrix.n24));x.material=t.material;h.push(x);v++}}}}l&&h.sort(b);return h};this.unprojectVector=function(e,p){var l=new THREE.Matrix4;l.multiply(THREE.Matrix4.makeInvert(p.matrix),THREE.Matrix4.makeInvert(p.projectionMatrix));l.multiplyVector3(e);return e}};
 THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,g,d,i,k;this.domElement=document.createElement("div");this.setSize=function(o,j){g=o;d=j;i=g/2;k=d/2};this.render=function(o,j){var n,c,B,A,x,v,H,L;a=b.projectScene(o,j);n=0;for(c=a.length;n<c;n++){x=a[n];if(x instanceof THREE.RenderableParticle){H=x.x*i+i;L=x.y*k+k;B=0;for(A=x.material.length;B<A;B++){v=x.material[B];if(v instanceof THREE.ParticleDOMMaterial){v=v.domElement;v.style.left=H+"px";v.style.top=L+"px"}}}}}};
 THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,g,d,i,k;this.domElement=document.createElement("div");this.setSize=function(o,j){g=o;d=j;i=g/2;k=d/2};this.render=function(o,j){var n,c,B,A,x,v,H,L;a=b.projectScene(o,j);n=0;for(c=a.length;n<c;n++){x=a[n];if(x instanceof THREE.RenderableParticle){H=x.x*i+i;L=x.y*k+k;B=0;for(A=x.material.length;B<A;B++){v=x.material[B];if(v instanceof THREE.ParticleDOMMaterial){v=v.domElement;v.style.left=H+"px";v.style.top=L+"px"}}}}}};
 THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,g=document.createElement("canvas"),d,i,k,o,j=g.getContext("2d"),n=1,c=0,B=null,A=null,x=1,v,H,L,J,I,O,E,f,m,e=new THREE.Color,p=new THREE.Color,l=new THREE.Color,h=new THREE.Color,u=new THREE.Color,y,D,q,C,Q,t,U,P,X,V,F=new THREE.Rectangle,w=new THREE.Rectangle,r=new THREE.Rectangle,N=false,S=new THREE.Color,M=new THREE.Color,T=new THREE.Color,aa=new THREE.Color,Ja=Math.PI*2,Y=new THREE.Vector3,na,oa,Aa,da,pa,ta,la=16;na=document.createElement("canvas");
 THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,g=document.createElement("canvas"),d,i,k,o,j=g.getContext("2d"),n=1,c=0,B=null,A=null,x=1,v,H,L,J,I,O,E,f,m,e=new THREE.Color,p=new THREE.Color,l=new THREE.Color,h=new THREE.Color,u=new THREE.Color,y,D,q,C,Q,t,U,P,X,V,F=new THREE.Rectangle,w=new THREE.Rectangle,r=new THREE.Rectangle,N=false,S=new THREE.Color,M=new THREE.Color,T=new THREE.Color,aa=new THREE.Color,Ja=Math.PI*2,Y=new THREE.Vector3,na,oa,Aa,da,pa,ta,la=16;na=document.createElement("canvas");
-na.width=na.height=2;oa=na.getContext("2d");oa.fillStyle="rgba(0,0,0,1)";oa.fillRect(0,0,2,2);Aa=oa.getImageData(0,0,2,2);da=Aa.data;pa=document.createElement("canvas");pa.width=pa.height=la;ta=pa.getContext("2d");ta.translate(-la/2,-la/2);ta.scale(la,la);la--;this.domElement=g;this.autoClear=true;this.setSize=function(ga,ua){d=ga;i=ua;k=d/2;o=i/2;g.width=d;g.height=i;F.set(-k,-o,k,o)};this.clear=function(){if(!w.isEmpty()){w.inflate(1);w.minSelf(F);j.clearRect(w.getX(),w.getY(),w.getWidth(),w.getHeight());
-w.empty()}};this.render=function(ga,ua){function Ka(s){var R,K,z,G=s.lights;M.setRGB(0,0,0);T.setRGB(0,0,0);aa.setRGB(0,0,0);s=0;for(R=G.length;s<R;s++){K=G[s];z=K.color;if(K instanceof THREE.AmbientLight){M.r+=z.r;M.g+=z.g;M.b+=z.b}else if(K instanceof THREE.DirectionalLight){T.r+=z.r;T.g+=z.g;T.b+=z.b}else if(K instanceof THREE.PointLight){aa.r+=z.r;aa.g+=z.g;aa.b+=z.b}}}function va(s,R,K,z){var G,W,$,ba,ca=s.lights;s=0;for(G=ca.length;s<G;s++){W=ca[s];$=W.color;ba=W.intensity;if(W instanceof THREE.DirectionalLight){W=
-K.dot(W.position)*ba;if(W>0){z.r+=$.r*W;z.g+=$.g*W;z.b+=$.b*W}}else if(W instanceof THREE.PointLight){Y.sub(W.position,R);Y.normalize();W=K.dot(Y)*ba;if(W>0){z.r+=$.r*W;z.g+=$.g*W;z.b+=$.b*W}}}}function La(s,R,K){if(K.opacity!=0){Ba(K.opacity);wa(K.blending);var z,G,W,$,ba,ca;if(K instanceof THREE.ParticleBasicMaterial){if(K.map){$=K.map;ba=$.width>>1;ca=$.height>>1;G=R.scale.x*k;W=R.scale.y*o;K=G*ba;z=W*ca;r.set(s.x-K,s.y-z,s.x+K,s.y+z);if(!F.instersects(r))return;j.save();j.translate(s.x,s.y);j.rotate(-R.rotation);
-j.scale(G,-W);j.translate(-ba,-ca);j.drawImage($,0,0);j.restore()}j.beginPath();j.moveTo(s.x-10,s.y);j.lineTo(s.x+10,s.y);j.moveTo(s.x,s.y-10);j.lineTo(s.x,s.y+10);j.closePath();j.strokeStyle="rgb(255,255,0)";j.stroke()}else if(K instanceof THREE.ParticleCircleMaterial){if(N){S.r=M.r+T.r+aa.r;S.g=M.g+T.g+aa.g;S.b=M.b+T.b+aa.b;e.r=K.color.r*S.r;e.g=K.color.g*S.g;e.b=K.color.b*S.b;e.updateStyleString()}else e.__styleString=K.color.__styleString;K=R.scale.x*k;z=R.scale.y*o;r.set(s.x-K,s.y-z,s.x+K,s.y+
-z);if(F.instersects(r)){G=e.__styleString;if(A!=G)j.fillStyle=A=G;j.save();j.translate(s.x,s.y);j.rotate(-R.rotation);j.scale(K,z);j.beginPath();j.arc(0,0,1,0,Ja,true);j.closePath();j.fill();j.restore()}}}}function Ma(s,R,K,z){if(z.opacity!=0){Ba(z.opacity);wa(z.blending);j.beginPath();j.moveTo(s.positionScreen.x,s.positionScreen.y);j.lineTo(R.positionScreen.x,R.positionScreen.y);j.closePath();if(z instanceof THREE.LineBasicMaterial){e.__styleString=z.color.__styleString;s=z.linewidth;if(x!=s)j.lineWidth=
-x=s;s=e.__styleString;if(B!=s)j.strokeStyle=B=s;j.stroke();r.inflate(z.linewidth*2)}}}function Fa(s,R,K,z,G,W){if(G.opacity!=0){Ba(G.opacity);wa(G.blending);J=s.positionScreen.x;I=s.positionScreen.y;O=R.positionScreen.x;E=R.positionScreen.y;f=K.positionScreen.x;m=K.positionScreen.y;j.beginPath();j.moveTo(J,I);j.lineTo(O,E);j.lineTo(f,m);j.lineTo(J,I);j.closePath();if(G instanceof THREE.MeshBasicMaterial)if(G.map)G.map.image.loaded&&G.map.mapping instanceof THREE.UVMapping&&qa(J,I,O,E,f,m,G.map.image,
-z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);else if(G.env_map){if(G.env_map.image.loaded)if(G.env_map.mapping instanceof THREE.SphericalReflectionMapping){s=ua.matrix;Y.copy(z.vertexNormalsWorld[0]);Q=(Y.x*s.n11+Y.y*s.n12+Y.z*s.n13)*0.5+0.5;t=-(Y.x*s.n21+Y.y*s.n22+Y.z*s.n23)*0.5+0.5;Y.copy(z.vertexNormalsWorld[1]);U=(Y.x*s.n11+Y.y*s.n12+Y.z*s.n13)*0.5+0.5;P=-(Y.x*s.n21+Y.y*s.n22+Y.z*s.n23)*0.5+0.5;Y.copy(z.vertexNormalsWorld[2]);X=(Y.x*s.n11+Y.y*s.n12+Y.z*s.n13)*0.5+0.5;V=-(Y.x*
-s.n21+Y.y*s.n22+Y.z*s.n23)*0.5+0.5;qa(J,I,O,E,f,m,G.env_map.image,Q,t,U,P,X,V)}}else G.wireframe?xa(G.color.__styleString,G.wireframe_linewidth):ya(G.color.__styleString);else if(G instanceof THREE.MeshLambertMaterial){if(G.map&&!G.wireframe){G.map.mapping instanceof THREE.UVMapping&&qa(J,I,O,E,f,m,G.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);wa(THREE.SubtractiveBlending)}if(N)if(!G.wireframe&&G.shading==THREE.SmoothShading&&z.vertexNormalsWorld.length==3){p.r=l.r=
-h.r=M.r;p.g=l.g=h.g=M.g;p.b=l.b=h.b=M.b;va(W,z.v1.positionWorld,z.vertexNormalsWorld[0],p);va(W,z.v2.positionWorld,z.vertexNormalsWorld[1],l);va(W,z.v3.positionWorld,z.vertexNormalsWorld[2],h);u.r=(l.r+h.r)*0.5;u.g=(l.g+h.g)*0.5;u.b=(l.b+h.b)*0.5;C=Ga(p,l,h,u);qa(J,I,O,E,f,m,C,0,0,1,0,0,1)}else{S.r=M.r;S.g=M.g;S.b=M.b;va(W,z.centroidWorld,z.normalWorld,S);e.r=G.color.r*S.r;e.g=G.color.g*S.g;e.b=G.color.b*S.b;e.updateStyleString();G.wireframe?xa(e.__styleString,G.wireframe_linewidth):ya(e.__styleString)}else G.wireframe?
-xa(G.color.__styleString,G.wireframe_linewidth):ya(G.color.__styleString)}else if(G instanceof THREE.MeshDepthMaterial){y=G.__2near;D=G.__farPlusNear;q=G.__farMinusNear;p.r=p.g=p.b=1-y/(D-s.positionScreen.z*q);l.r=l.g=l.b=1-y/(D-R.positionScreen.z*q);h.r=h.g=h.b=1-y/(D-K.positionScreen.z*q);u.r=(l.r+h.r)*0.5;u.g=(l.g+h.g)*0.5;u.b=(l.b+h.b)*0.5;C=Ga(p,l,h,u);qa(J,I,O,E,f,m,C,0,0,1,0,0,1)}else if(G instanceof THREE.MeshNormalMaterial){e.r=Ca(z.normalWorld.x);e.g=Ca(z.normalWorld.y);e.b=Ca(z.normalWorld.z);
-e.updateStyleString();G.wireframe?xa(e.__styleString,G.wireframe_linewidth):ya(e.__styleString)}}}function xa(s,R){if(B!=s)j.strokeStyle=B=s;if(x!=R)j.lineWidth=x=R;j.stroke();r.inflate(R*2)}function ya(s){if(A!=s)j.fillStyle=A=s;j.fill()}function qa(s,R,K,z,G,W,$,ba,ca,ha,ea,ia,ra){var ka,ja;ka=$.width-1;ja=$.height-1;ba*=ka;ca*=ja;ha*=ka;ea*=ja;ia*=ka;ra*=ja;K-=s;z-=R;G-=s;W-=R;ha-=ba;ea-=ca;ia-=ba;ra-=ca;ja=1/(ha*ra-ia*ea);ka=(ra*K-ea*G)*ja;ea=(ra*z-ea*W)*ja;K=(ha*G-ia*K)*ja;z=(ha*W-ia*z)*ja;s=
-s-ka*ba-K*ca;R=R-ea*ba-z*ca;j.save();j.transform(ka,ea,K,z,s,R);j.clip();j.drawImage($,0,0);j.restore()}function Ba(s){if(n!=s)j.globalAlpha=n=s}function wa(s){if(c!=s){switch(s){case THREE.NormalBlending:j.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:j.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:j.globalCompositeOperation="darker"}c=s}}function Ga(s,R,K,z){var G=~~(s.r*255),W=~~(s.g*255);s=~~(s.b*255);var $=~~(R.r*255),ba=~~(R.g*255);R=~~(R.b*
-255);var ca=~~(K.r*255),ha=~~(K.g*255);K=~~(K.b*255);var ea=~~(z.r*255),ia=~~(z.g*255);z=~~(z.b*255);da[0]=G<0?0:G>255?255:G;da[1]=W<0?0:W>255?255:W;da[2]=s<0?0:s>255?255:s;da[4]=$<0?0:$>255?255:$;da[5]=ba<0?0:ba>255?255:ba;da[6]=R<0?0:R>255?255:R;da[8]=ca<0?0:ca>255?255:ca;da[9]=ha<0?0:ha>255?255:ha;da[10]=K<0?0:K>255?255:K;da[12]=ea<0?0:ea>255?255:ea;da[13]=ia<0?0:ia>255?255:ia;da[14]=z<0?0:z>255?255:z;oa.putImageData(Aa,0,0);ta.drawImage(na,0,0);return pa}function Ca(s){s=(s+1)*0.5;return s<0?
-0:s>1?1:s}function Da(s,R){var K=R.x-s.x,z=R.y-s.y,G=1/Math.sqrt(K*K+z*z);K*=G;z*=G;R.x+=K;R.y+=z;s.x-=K;s.y-=z}var za,Ha,Z,fa,ma,Ea,Ia,sa;j.setTransform(1,0,0,-1,k,o);this.autoClear&&this.clear();a=b.projectScene(ga,ua,true);j.fillStyle="rgba(0, 255, 255, 0.5)";j.fillRect(F.getX(),F.getY(),F.getWidth(),F.getHeight());(N=ga.lights.length>0)&&Ka(ga);za=0;for(Ha=a.length;za<Ha;za++){Z=a[za];r.empty();if(Z instanceof THREE.RenderableParticle){v=Z;v.x*=k;v.y*=o;fa=0;for(ma=Z.material.length;fa<ma;fa++)La(v,
-Z,Z.material[fa],ga)}else if(Z instanceof THREE.RenderableLine){v=Z.v1;H=Z.v2;v.positionScreen.x*=k;v.positionScreen.y*=o;H.positionScreen.x*=k;H.positionScreen.y*=o;r.addPoint(v.positionScreen.x,v.positionScreen.y);r.addPoint(H.positionScreen.x,H.positionScreen.y);if(F.instersects(r)){fa=0;for(ma=Z.material.length;fa<ma;)Ma(v,H,Z,Z.material[fa++],ga)}}else if(Z instanceof THREE.RenderableFace3){v=Z.v1;H=Z.v2;L=Z.v3;v.positionScreen.x*=k;v.positionScreen.y*=o;H.positionScreen.x*=k;H.positionScreen.y*=
-o;L.positionScreen.x*=k;L.positionScreen.y*=o;if(Z.overdraw){Da(v.positionScreen,H.positionScreen);Da(H.positionScreen,L.positionScreen);Da(L.positionScreen,v.positionScreen)}r.add3Points(v.positionScreen.x,v.positionScreen.y,H.positionScreen.x,H.positionScreen.y,L.positionScreen.x,L.positionScreen.y);if(F.instersects(r)){fa=0;for(ma=Z.meshMaterial.length;fa<ma;){sa=Z.meshMaterial[fa++];if(sa instanceof THREE.MeshFaceMaterial){Ea=0;for(Ia=Z.faceMaterial.length;Ea<Ia;)(sa=Z.faceMaterial[Ea++])&&Fa(v,
-H,L,Z,sa,ga)}else Fa(v,H,L,Z,sa,ga)}}}w.addRectangle(r)}j.lineWidth=1;j.strokeStyle="rgba( 255, 0, 0, 0.5 )";j.strokeRect(w.getX(),w.getY(),w.getWidth(),w.getHeight());j.setTransform(1,0,0,1,0,0)}};
+na.width=na.height=2;oa=na.getContext("2d");oa.fillStyle="rgba(0,0,0,1)";oa.fillRect(0,0,2,2);Aa=oa.getImageData(0,0,2,2);da=Aa.data;pa=document.createElement("canvas");pa.width=pa.height=la;ta=pa.getContext("2d");ta.translate(-la/2,-la/2);ta.scale(la,la);la--;this.domElement=g;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ga,ua){d=ga;i=ua;k=d/2;o=i/2;g.width=d;g.height=i;F.set(-k,-o,k,o)};this.clear=function(){if(!w.isEmpty()){w.inflate(1);w.minSelf(F);j.clearRect(w.getX(),
+w.getY(),w.getWidth(),w.getHeight());w.empty()}};this.render=function(ga,ua){function Ka(s){var R,K,z,G=s.lights;M.setRGB(0,0,0);T.setRGB(0,0,0);aa.setRGB(0,0,0);s=0;for(R=G.length;s<R;s++){K=G[s];z=K.color;if(K instanceof THREE.AmbientLight){M.r+=z.r;M.g+=z.g;M.b+=z.b}else if(K instanceof THREE.DirectionalLight){T.r+=z.r;T.g+=z.g;T.b+=z.b}else if(K instanceof THREE.PointLight){aa.r+=z.r;aa.g+=z.g;aa.b+=z.b}}}function va(s,R,K,z){var G,W,$,ba,ca=s.lights;s=0;for(G=ca.length;s<G;s++){W=ca[s];$=W.color;
+ba=W.intensity;if(W instanceof THREE.DirectionalLight){W=K.dot(W.position)*ba;if(W>0){z.r+=$.r*W;z.g+=$.g*W;z.b+=$.b*W}}else if(W instanceof THREE.PointLight){Y.sub(W.position,R);Y.normalize();W=K.dot(Y)*ba;if(W>0){z.r+=$.r*W;z.g+=$.g*W;z.b+=$.b*W}}}}function La(s,R,K){if(K.opacity!=0){Ba(K.opacity);wa(K.blending);var z,G,W,$,ba,ca;if(K instanceof THREE.ParticleBasicMaterial){if(K.map){$=K.map;ba=$.width>>1;ca=$.height>>1;G=R.scale.x*k;W=R.scale.y*o;K=G*ba;z=W*ca;r.set(s.x-K,s.y-z,s.x+K,s.y+z);if(!F.instersects(r))return;
+j.save();j.translate(s.x,s.y);j.rotate(-R.rotation);j.scale(G,-W);j.translate(-ba,-ca);j.drawImage($,0,0);j.restore()}j.beginPath();j.moveTo(s.x-10,s.y);j.lineTo(s.x+10,s.y);j.moveTo(s.x,s.y-10);j.lineTo(s.x,s.y+10);j.closePath();j.strokeStyle="rgb(255,255,0)";j.stroke()}else if(K instanceof THREE.ParticleCircleMaterial){if(N){S.r=M.r+T.r+aa.r;S.g=M.g+T.g+aa.g;S.b=M.b+T.b+aa.b;e.r=K.color.r*S.r;e.g=K.color.g*S.g;e.b=K.color.b*S.b;e.updateStyleString()}else e.__styleString=K.color.__styleString;K=
+R.scale.x*k;z=R.scale.y*o;r.set(s.x-K,s.y-z,s.x+K,s.y+z);if(F.instersects(r)){G=e.__styleString;if(A!=G)j.fillStyle=A=G;j.save();j.translate(s.x,s.y);j.rotate(-R.rotation);j.scale(K,z);j.beginPath();j.arc(0,0,1,0,Ja,true);j.closePath();j.fill();j.restore()}}}}function Ma(s,R,K,z){if(z.opacity!=0){Ba(z.opacity);wa(z.blending);j.beginPath();j.moveTo(s.positionScreen.x,s.positionScreen.y);j.lineTo(R.positionScreen.x,R.positionScreen.y);j.closePath();if(z instanceof THREE.LineBasicMaterial){e.__styleString=
+z.color.__styleString;s=z.linewidth;if(x!=s)j.lineWidth=x=s;s=e.__styleString;if(B!=s)j.strokeStyle=B=s;j.stroke();r.inflate(z.linewidth*2)}}}function Fa(s,R,K,z,G,W){if(G.opacity!=0){Ba(G.opacity);wa(G.blending);J=s.positionScreen.x;I=s.positionScreen.y;O=R.positionScreen.x;E=R.positionScreen.y;f=K.positionScreen.x;m=K.positionScreen.y;j.beginPath();j.moveTo(J,I);j.lineTo(O,E);j.lineTo(f,m);j.lineTo(J,I);j.closePath();if(G instanceof THREE.MeshBasicMaterial)if(G.map)G.map.image.loaded&&G.map.mapping instanceof
+THREE.UVMapping&&qa(J,I,O,E,f,m,G.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);else if(G.env_map){if(G.env_map.image.loaded)if(G.env_map.mapping instanceof THREE.SphericalReflectionMapping){s=ua.matrix;Y.copy(z.vertexNormalsWorld[0]);Q=(Y.x*s.n11+Y.y*s.n12+Y.z*s.n13)*0.5+0.5;t=-(Y.x*s.n21+Y.y*s.n22+Y.z*s.n23)*0.5+0.5;Y.copy(z.vertexNormalsWorld[1]);U=(Y.x*s.n11+Y.y*s.n12+Y.z*s.n13)*0.5+0.5;P=-(Y.x*s.n21+Y.y*s.n22+Y.z*s.n23)*0.5+0.5;Y.copy(z.vertexNormalsWorld[2]);X=
+(Y.x*s.n11+Y.y*s.n12+Y.z*s.n13)*0.5+0.5;V=-(Y.x*s.n21+Y.y*s.n22+Y.z*s.n23)*0.5+0.5;qa(J,I,O,E,f,m,G.env_map.image,Q,t,U,P,X,V)}}else G.wireframe?xa(G.color.__styleString,G.wireframe_linewidth):ya(G.color.__styleString);else if(G instanceof THREE.MeshLambertMaterial){if(G.map&&!G.wireframe){G.map.mapping instanceof THREE.UVMapping&&qa(J,I,O,E,f,m,G.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);wa(THREE.SubtractiveBlending)}if(N)if(!G.wireframe&&G.shading==THREE.SmoothShading&&
+z.vertexNormalsWorld.length==3){p.r=l.r=h.r=M.r;p.g=l.g=h.g=M.g;p.b=l.b=h.b=M.b;va(W,z.v1.positionWorld,z.vertexNormalsWorld[0],p);va(W,z.v2.positionWorld,z.vertexNormalsWorld[1],l);va(W,z.v3.positionWorld,z.vertexNormalsWorld[2],h);u.r=(l.r+h.r)*0.5;u.g=(l.g+h.g)*0.5;u.b=(l.b+h.b)*0.5;C=Ga(p,l,h,u);qa(J,I,O,E,f,m,C,0,0,1,0,0,1)}else{S.r=M.r;S.g=M.g;S.b=M.b;va(W,z.centroidWorld,z.normalWorld,S);e.r=G.color.r*S.r;e.g=G.color.g*S.g;e.b=G.color.b*S.b;e.updateStyleString();G.wireframe?xa(e.__styleString,
+G.wireframe_linewidth):ya(e.__styleString)}else G.wireframe?xa(G.color.__styleString,G.wireframe_linewidth):ya(G.color.__styleString)}else if(G instanceof THREE.MeshDepthMaterial){y=G.__2near;D=G.__farPlusNear;q=G.__farMinusNear;p.r=p.g=p.b=1-y/(D-s.positionScreen.z*q);l.r=l.g=l.b=1-y/(D-R.positionScreen.z*q);h.r=h.g=h.b=1-y/(D-K.positionScreen.z*q);u.r=(l.r+h.r)*0.5;u.g=(l.g+h.g)*0.5;u.b=(l.b+h.b)*0.5;C=Ga(p,l,h,u);qa(J,I,O,E,f,m,C,0,0,1,0,0,1)}else if(G instanceof THREE.MeshNormalMaterial){e.r=
+Ca(z.normalWorld.x);e.g=Ca(z.normalWorld.y);e.b=Ca(z.normalWorld.z);e.updateStyleString();G.wireframe?xa(e.__styleString,G.wireframe_linewidth):ya(e.__styleString)}}}function xa(s,R){if(B!=s)j.strokeStyle=B=s;if(x!=R)j.lineWidth=x=R;j.stroke();r.inflate(R*2)}function ya(s){if(A!=s)j.fillStyle=A=s;j.fill()}function qa(s,R,K,z,G,W,$,ba,ca,ha,ea,ia,ra){var ka,ja;ka=$.width-1;ja=$.height-1;ba*=ka;ca*=ja;ha*=ka;ea*=ja;ia*=ka;ra*=ja;K-=s;z-=R;G-=s;W-=R;ha-=ba;ea-=ca;ia-=ba;ra-=ca;ja=1/(ha*ra-ia*ea);ka=
+(ra*K-ea*G)*ja;ea=(ra*z-ea*W)*ja;K=(ha*G-ia*K)*ja;z=(ha*W-ia*z)*ja;s=s-ka*ba-K*ca;R=R-ea*ba-z*ca;j.save();j.transform(ka,ea,K,z,s,R);j.clip();j.drawImage($,0,0);j.restore()}function Ba(s){if(n!=s)j.globalAlpha=n=s}function wa(s){if(c!=s){switch(s){case THREE.NormalBlending:j.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:j.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:j.globalCompositeOperation="darker"}c=s}}function Ga(s,R,K,z){var G=~~(s.r*255),
+W=~~(s.g*255);s=~~(s.b*255);var $=~~(R.r*255),ba=~~(R.g*255);R=~~(R.b*255);var ca=~~(K.r*255),ha=~~(K.g*255);K=~~(K.b*255);var ea=~~(z.r*255),ia=~~(z.g*255);z=~~(z.b*255);da[0]=G<0?0:G>255?255:G;da[1]=W<0?0:W>255?255:W;da[2]=s<0?0:s>255?255:s;da[4]=$<0?0:$>255?255:$;da[5]=ba<0?0:ba>255?255:ba;da[6]=R<0?0:R>255?255:R;da[8]=ca<0?0:ca>255?255:ca;da[9]=ha<0?0:ha>255?255:ha;da[10]=K<0?0:K>255?255:K;da[12]=ea<0?0:ea>255?255:ea;da[13]=ia<0?0:ia>255?255:ia;da[14]=z<0?0:z>255?255:z;oa.putImageData(Aa,0,0);
+ta.drawImage(na,0,0);return pa}function Ca(s){s=(s+1)*0.5;return s<0?0:s>1?1:s}function Da(s,R){var K=R.x-s.x,z=R.y-s.y,G=1/Math.sqrt(K*K+z*z);K*=G;z*=G;R.x+=K;R.y+=z;s.x-=K;s.y-=z}var za,Ha,Z,fa,ma,Ea,Ia,sa;j.setTransform(1,0,0,-1,k,o);this.autoClear&&this.clear();a=b.projectScene(ga,ua,this.sortElements);j.fillStyle="rgba(0, 255, 255, 0.5)";j.fillRect(F.getX(),F.getY(),F.getWidth(),F.getHeight());(N=ga.lights.length>0)&&Ka(ga);za=0;for(Ha=a.length;za<Ha;za++){Z=a[za];r.empty();if(Z instanceof THREE.RenderableParticle){v=
+Z;v.x*=k;v.y*=o;fa=0;for(ma=Z.material.length;fa<ma;fa++)La(v,Z,Z.material[fa],ga)}else if(Z instanceof THREE.RenderableLine){v=Z.v1;H=Z.v2;v.positionScreen.x*=k;v.positionScreen.y*=o;H.positionScreen.x*=k;H.positionScreen.y*=o;r.addPoint(v.positionScreen.x,v.positionScreen.y);r.addPoint(H.positionScreen.x,H.positionScreen.y);if(F.instersects(r)){fa=0;for(ma=Z.material.length;fa<ma;)Ma(v,H,Z,Z.material[fa++],ga)}}else if(Z instanceof THREE.RenderableFace3){v=Z.v1;H=Z.v2;L=Z.v3;v.positionScreen.x*=
+k;v.positionScreen.y*=o;H.positionScreen.x*=k;H.positionScreen.y*=o;L.positionScreen.x*=k;L.positionScreen.y*=o;if(Z.overdraw){Da(v.positionScreen,H.positionScreen);Da(H.positionScreen,L.positionScreen);Da(L.positionScreen,v.positionScreen)}r.add3Points(v.positionScreen.x,v.positionScreen.y,H.positionScreen.x,H.positionScreen.y,L.positionScreen.x,L.positionScreen.y);if(F.instersects(r)){fa=0;for(ma=Z.meshMaterial.length;fa<ma;){sa=Z.meshMaterial[fa++];if(sa instanceof THREE.MeshFaceMaterial){Ea=0;
+for(Ia=Z.faceMaterial.length;Ea<Ia;)(sa=Z.faceMaterial[Ea++])&&Fa(v,H,L,Z,sa,ga)}else Fa(v,H,L,Z,sa,ga)}}}w.addRectangle(r)}j.lineWidth=1;j.strokeStyle="rgba( 255, 0, 0, 0.5 )";j.strokeRect(w.getX(),w.getY(),w.getWidth(),w.getHeight());j.setTransform(1,0,0,1,0,0)}};
 THREE.SVGRenderer=function(){function a(P,X,V){var F,w,r,N;F=0;for(w=P.lights.length;F<w;F++){r=P.lights[F];if(r instanceof THREE.DirectionalLight){N=X.normalWorld.dot(r.position)*r.intensity;if(N>0){V.r+=r.color.r*N;V.g+=r.color.g*N;V.b+=r.color.b*N}}else if(r instanceof THREE.PointLight){h.sub(r.position,X.centroidWorld);h.normalize();N=X.normalWorld.dot(h)*r.intensity;if(N>0){V.r+=r.color.r*N;V.g+=r.color.g*N;V.b+=r.color.b*N}}}}function b(P,X,V,F,w,r){q=d(C++);q.setAttribute("d","M "+P.positionScreen.x+
 THREE.SVGRenderer=function(){function a(P,X,V){var F,w,r,N;F=0;for(w=P.lights.length;F<w;F++){r=P.lights[F];if(r instanceof THREE.DirectionalLight){N=X.normalWorld.dot(r.position)*r.intensity;if(N>0){V.r+=r.color.r*N;V.g+=r.color.g*N;V.b+=r.color.b*N}}else if(r instanceof THREE.PointLight){h.sub(r.position,X.centroidWorld);h.normalize();N=X.normalWorld.dot(h)*r.intensity;if(N>0){V.r+=r.color.r*N;V.g+=r.color.g*N;V.b+=r.color.b*N}}}}function b(P,X,V,F,w,r){q=d(C++);q.setAttribute("d","M "+P.positionScreen.x+
 " "+P.positionScreen.y+" L "+X.positionScreen.x+" "+X.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+"z");if(w instanceof THREE.MeshBasicMaterial)E.__styleString=w.color.__styleString;else if(w instanceof THREE.MeshLambertMaterial)if(O){f.r=m.r;f.g=m.g;f.b=m.b;a(r,F,f);E.r=w.color.r*f.r;E.g=w.color.g*f.g;E.b=w.color.b*f.b;E.updateStyleString()}else E.__styleString=w.color.__styleString;else if(w instanceof THREE.MeshDepthMaterial){l=1-w.__2near/(w.__farPlusNear-F.z*w.__farMinusNear);
 " "+P.positionScreen.y+" L "+X.positionScreen.x+" "+X.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+"z");if(w instanceof THREE.MeshBasicMaterial)E.__styleString=w.color.__styleString;else if(w instanceof THREE.MeshLambertMaterial)if(O){f.r=m.r;f.g=m.g;f.b=m.b;a(r,F,f);E.r=w.color.r*f.r;E.g=w.color.g*f.g;E.b=w.color.b*f.b;E.updateStyleString()}else E.__styleString=w.color.__styleString;else if(w instanceof THREE.MeshDepthMaterial){l=1-w.__2near/(w.__farPlusNear-F.z*w.__farMinusNear);
 E.setRGB(l,l,l)}else w instanceof THREE.MeshNormalMaterial&&E.setRGB(i(F.normalWorld.x),i(F.normalWorld.y),i(F.normalWorld.z));w.wireframe?q.setAttribute("style","fill: none; stroke: "+E.__styleString+"; stroke-width: "+w.wireframe_linewidth+"; stroke-opacity: "+w.opacity+"; stroke-linecap: "+w.wireframe_linecap+"; stroke-linejoin: "+w.wireframe_linejoin):q.setAttribute("style","fill: "+E.__styleString+"; fill-opacity: "+w.opacity);j.appendChild(q)}function g(P,X,V,F,w,r,N){q=d(C++);q.setAttribute("d",
 E.setRGB(l,l,l)}else w instanceof THREE.MeshNormalMaterial&&E.setRGB(i(F.normalWorld.x),i(F.normalWorld.y),i(F.normalWorld.z));w.wireframe?q.setAttribute("style","fill: none; stroke: "+E.__styleString+"; stroke-width: "+w.wireframe_linewidth+"; stroke-opacity: "+w.opacity+"; stroke-linecap: "+w.wireframe_linecap+"; stroke-linejoin: "+w.wireframe_linejoin):q.setAttribute("style","fill: "+E.__styleString+"; fill-opacity: "+w.opacity);j.appendChild(q)}function g(P,X,V,F,w,r,N){q=d(C++);q.setAttribute("d",
 "M "+P.positionScreen.x+" "+P.positionScreen.y+" L "+X.positionScreen.x+" "+X.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+" L "+F.positionScreen.x+","+F.positionScreen.y+"z");if(r instanceof THREE.MeshBasicMaterial)E.__styleString=r.color.__styleString;else if(r instanceof THREE.MeshLambertMaterial)if(O){f.r=m.r;f.g=m.g;f.b=m.b;a(N,w,f);E.r=r.color.r*f.r;E.g=r.color.g*f.g;E.b=r.color.b*f.b;E.updateStyleString()}else E.__styleString=r.color.__styleString;else if(r instanceof THREE.MeshDepthMaterial){l=
 "M "+P.positionScreen.x+" "+P.positionScreen.y+" L "+X.positionScreen.x+" "+X.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+" L "+F.positionScreen.x+","+F.positionScreen.y+"z");if(r instanceof THREE.MeshBasicMaterial)E.__styleString=r.color.__styleString;else if(r instanceof THREE.MeshLambertMaterial)if(O){f.r=m.r;f.g=m.g;f.b=m.b;a(N,w,f);E.r=r.color.r*f.r;E.g=r.color.g*f.g;E.b=r.color.b*f.b;E.updateStyleString()}else E.__styleString=r.color.__styleString;else if(r instanceof THREE.MeshDepthMaterial){l=
 1-r.__2near/(r.__farPlusNear-w.z*r.__farMinusNear);E.setRGB(l,l,l)}else r instanceof THREE.MeshNormalMaterial&&E.setRGB(i(w.normalWorld.x),i(w.normalWorld.y),i(w.normalWorld.z));r.wireframe?q.setAttribute("style","fill: none; stroke: "+E.__styleString+"; stroke-width: "+r.wireframe_linewidth+"; stroke-opacity: "+r.opacity+"; stroke-linecap: "+r.wireframe_linecap+"; stroke-linejoin: "+r.wireframe_linejoin):q.setAttribute("style","fill: "+E.__styleString+"; fill-opacity: "+r.opacity);j.appendChild(q)}
 1-r.__2near/(r.__farPlusNear-w.z*r.__farMinusNear);E.setRGB(l,l,l)}else r instanceof THREE.MeshNormalMaterial&&E.setRGB(i(w.normalWorld.x),i(w.normalWorld.y),i(w.normalWorld.z));r.wireframe?q.setAttribute("style","fill: none; stroke: "+E.__styleString+"; stroke-width: "+r.wireframe_linewidth+"; stroke-opacity: "+r.opacity+"; stroke-linecap: "+r.wireframe_linecap+"; stroke-linejoin: "+r.wireframe_linejoin):q.setAttribute("style","fill: "+E.__styleString+"; fill-opacity: "+r.opacity);j.appendChild(q)}
 function d(P){if(u[P]==null){u[P]=document.createElementNS("http://www.w3.org/2000/svg","path");U==0&&u[P].setAttribute("shape-rendering","crispEdges");return u[P]}return u[P]}function i(P){return P<0?Math.min((1+P)*0.5,0.5):0.5+Math.min(P*0.5,0.5)}var k=null,o=new THREE.Projector,j=document.createElementNS("http://www.w3.org/2000/svg","svg"),n,c,B,A,x,v,H,L,J=new THREE.Rectangle,I=new THREE.Rectangle,O=false,E=new THREE.Color(16777215),f=new THREE.Color(16777215),m=new THREE.Color(0),e=new THREE.Color(0),
 function d(P){if(u[P]==null){u[P]=document.createElementNS("http://www.w3.org/2000/svg","path");U==0&&u[P].setAttribute("shape-rendering","crispEdges");return u[P]}return u[P]}function i(P){return P<0?Math.min((1+P)*0.5,0.5):0.5+Math.min(P*0.5,0.5)}var k=null,o=new THREE.Projector,j=document.createElementNS("http://www.w3.org/2000/svg","svg"),n,c,B,A,x,v,H,L,J=new THREE.Rectangle,I=new THREE.Rectangle,O=false,E=new THREE.Color(16777215),f=new THREE.Color(16777215),m=new THREE.Color(0),e=new THREE.Color(0),
-p=new THREE.Color(0),l,h=new THREE.Vector3,u=[],y=[],D=[],q,C,Q,t,U=1;this.domElement=j;this.autoClear=true;this.setQuality=function(P){switch(P){case "high":U=1;break;case "low":U=0}};this.setSize=function(P,X){n=P;c=X;B=n/2;A=c/2;j.setAttribute("viewBox",-B+" "+-A+" "+n+" "+c);j.setAttribute("width",n);j.setAttribute("height",c);J.set(-B,-A,B,A)};this.clear=function(){for(;j.childNodes.length>0;)j.removeChild(j.childNodes[0])};this.render=function(P,X){var V,F,w,r,N,S,M,T;this.autoClear&&this.clear();
-k=o.projectScene(P,X,true);t=Q=C=0;if(O=P.lights.length>0){M=P.lights;m.setRGB(0,0,0);e.setRGB(0,0,0);p.setRGB(0,0,0);V=0;for(F=M.length;V<F;V++){w=M[V];r=w.color;if(w instanceof THREE.AmbientLight){m.r+=r.r;m.g+=r.g;m.b+=r.b}else if(w instanceof THREE.DirectionalLight){e.r+=r.r;e.g+=r.g;e.b+=r.b}else if(w instanceof THREE.PointLight){p.r+=r.r;p.g+=r.g;p.b+=r.b}}}V=0;for(F=k.length;V<F;V++){M=k[V];I.empty();if(M instanceof THREE.RenderableParticle){x=M;x.x*=B;x.y*=-A;w=0;for(r=M.material.length;w<
-r;w++)if(T=M.material[w]){N=x;S=M;T=T;var aa=Q++;if(y[aa]==null){y[aa]=document.createElementNS("http://www.w3.org/2000/svg","circle");U==0&&y[aa].setAttribute("shape-rendering","crispEdges")}q=y[aa];q.setAttribute("cx",N.x);q.setAttribute("cy",N.y);q.setAttribute("r",S.scale.x*B);if(T instanceof THREE.ParticleCircleMaterial){if(O){f.r=m.r+e.r+p.r;f.g=m.g+e.g+p.g;f.b=m.b+e.b+p.b;E.r=T.color.r*f.r;E.g=T.color.g*f.g;E.b=T.color.b*f.b;E.updateStyleString()}else E=T.color;q.setAttribute("style","fill: "+
-E.__styleString)}j.appendChild(q)}}else if(M instanceof THREE.RenderableLine){x=M.v1;v=M.v2;x.positionScreen.x*=B;x.positionScreen.y*=-A;v.positionScreen.x*=B;v.positionScreen.y*=-A;I.addPoint(x.positionScreen.x,x.positionScreen.y);I.addPoint(v.positionScreen.x,v.positionScreen.y);if(J.instersects(I)){w=0;for(r=M.material.length;w<r;)if(T=M.material[w++]){N=x;S=v;T=T;aa=t++;if(D[aa]==null){D[aa]=document.createElementNS("http://www.w3.org/2000/svg","line");U==0&&D[aa].setAttribute("shape-rendering",
-"crispEdges")}q=D[aa];q.setAttribute("x1",N.positionScreen.x);q.setAttribute("y1",N.positionScreen.y);q.setAttribute("x2",S.positionScreen.x);q.setAttribute("y2",S.positionScreen.y);if(T instanceof THREE.LineBasicMaterial){E.__styleString=T.color.__styleString;q.setAttribute("style","fill: none; stroke: "+E.__styleString+"; stroke-width: "+T.linewidth+"; stroke-opacity: "+T.opacity+"; stroke-linecap: "+T.linecap+"; stroke-linejoin: "+T.linejoin);j.appendChild(q)}}}}else if(M instanceof THREE.RenderableFace3){x=
-M.v1;v=M.v2;H=M.v3;x.positionScreen.x*=B;x.positionScreen.y*=-A;v.positionScreen.x*=B;v.positionScreen.y*=-A;H.positionScreen.x*=B;H.positionScreen.y*=-A;I.addPoint(x.positionScreen.x,x.positionScreen.y);I.addPoint(v.positionScreen.x,v.positionScreen.y);I.addPoint(H.positionScreen.x,H.positionScreen.y);if(J.instersects(I)){w=0;for(r=M.meshMaterial.length;w<r;){T=M.meshMaterial[w++];if(T instanceof THREE.MeshFaceMaterial){N=0;for(S=M.faceMaterial.length;N<S;)(T=M.faceMaterial[N++])&&b(x,v,H,M,T,P)}else T&&
-b(x,v,H,M,T,P)}}}else if(M instanceof THREE.RenderableFace4){x=M.v1;v=M.v2;H=M.v3;L=M.v4;x.positionScreen.x*=B;x.positionScreen.y*=-A;v.positionScreen.x*=B;v.positionScreen.y*=-A;H.positionScreen.x*=B;H.positionScreen.y*=-A;L.positionScreen.x*=B;L.positionScreen.y*=-A;I.addPoint(x.positionScreen.x,x.positionScreen.y);I.addPoint(v.positionScreen.x,v.positionScreen.y);I.addPoint(H.positionScreen.x,H.positionScreen.y);I.addPoint(L.positionScreen.x,L.positionScreen.y);if(J.instersects(I)){w=0;for(r=M.meshMaterial.length;w<
-r;){T=M.meshMaterial[w++];if(T instanceof THREE.MeshFaceMaterial){N=0;for(S=M.faceMaterial.length;N<S;)(T=M.faceMaterial[N++])&&g(x,v,H,L,M,T,P)}else T&&g(x,v,H,L,M,T,P)}}}}}};
+p=new THREE.Color(0),l,h=new THREE.Vector3,u=[],y=[],D=[],q,C,Q,t,U=1;this.domElement=j;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(P){switch(P){case "high":U=1;break;case "low":U=0}};this.setSize=function(P,X){n=P;c=X;B=n/2;A=c/2;j.setAttribute("viewBox",-B+" "+-A+" "+n+" "+c);j.setAttribute("width",n);j.setAttribute("height",c);J.set(-B,-A,B,A)};this.clear=function(){for(;j.childNodes.length>0;)j.removeChild(j.childNodes[0])};this.render=function(P,X){var V,F,
+w,r,N,S,M,T;this.autoClear&&this.clear();k=o.projectScene(P,X,this.sortElements);t=Q=C=0;if(O=P.lights.length>0){M=P.lights;m.setRGB(0,0,0);e.setRGB(0,0,0);p.setRGB(0,0,0);V=0;for(F=M.length;V<F;V++){w=M[V];r=w.color;if(w instanceof THREE.AmbientLight){m.r+=r.r;m.g+=r.g;m.b+=r.b}else if(w instanceof THREE.DirectionalLight){e.r+=r.r;e.g+=r.g;e.b+=r.b}else if(w instanceof THREE.PointLight){p.r+=r.r;p.g+=r.g;p.b+=r.b}}}V=0;for(F=k.length;V<F;V++){M=k[V];I.empty();if(M instanceof THREE.RenderableParticle){x=
+M;x.x*=B;x.y*=-A;w=0;for(r=M.material.length;w<r;w++)if(T=M.material[w]){N=x;S=M;T=T;var aa=Q++;if(y[aa]==null){y[aa]=document.createElementNS("http://www.w3.org/2000/svg","circle");U==0&&y[aa].setAttribute("shape-rendering","crispEdges")}q=y[aa];q.setAttribute("cx",N.x);q.setAttribute("cy",N.y);q.setAttribute("r",S.scale.x*B);if(T instanceof THREE.ParticleCircleMaterial){if(O){f.r=m.r+e.r+p.r;f.g=m.g+e.g+p.g;f.b=m.b+e.b+p.b;E.r=T.color.r*f.r;E.g=T.color.g*f.g;E.b=T.color.b*f.b;E.updateStyleString()}else E=
+T.color;q.setAttribute("style","fill: "+E.__styleString)}j.appendChild(q)}}else if(M instanceof THREE.RenderableLine){x=M.v1;v=M.v2;x.positionScreen.x*=B;x.positionScreen.y*=-A;v.positionScreen.x*=B;v.positionScreen.y*=-A;I.addPoint(x.positionScreen.x,x.positionScreen.y);I.addPoint(v.positionScreen.x,v.positionScreen.y);if(J.instersects(I)){w=0;for(r=M.material.length;w<r;)if(T=M.material[w++]){N=x;S=v;T=T;aa=t++;if(D[aa]==null){D[aa]=document.createElementNS("http://www.w3.org/2000/svg","line");
+U==0&&D[aa].setAttribute("shape-rendering","crispEdges")}q=D[aa];q.setAttribute("x1",N.positionScreen.x);q.setAttribute("y1",N.positionScreen.y);q.setAttribute("x2",S.positionScreen.x);q.setAttribute("y2",S.positionScreen.y);if(T instanceof THREE.LineBasicMaterial){E.__styleString=T.color.__styleString;q.setAttribute("style","fill: none; stroke: "+E.__styleString+"; stroke-width: "+T.linewidth+"; stroke-opacity: "+T.opacity+"; stroke-linecap: "+T.linecap+"; stroke-linejoin: "+T.linejoin);j.appendChild(q)}}}}else if(M instanceof
+THREE.RenderableFace3){x=M.v1;v=M.v2;H=M.v3;x.positionScreen.x*=B;x.positionScreen.y*=-A;v.positionScreen.x*=B;v.positionScreen.y*=-A;H.positionScreen.x*=B;H.positionScreen.y*=-A;I.addPoint(x.positionScreen.x,x.positionScreen.y);I.addPoint(v.positionScreen.x,v.positionScreen.y);I.addPoint(H.positionScreen.x,H.positionScreen.y);if(J.instersects(I)){w=0;for(r=M.meshMaterial.length;w<r;){T=M.meshMaterial[w++];if(T instanceof THREE.MeshFaceMaterial){N=0;for(S=M.faceMaterial.length;N<S;)(T=M.faceMaterial[N++])&&
+b(x,v,H,M,T,P)}else T&&b(x,v,H,M,T,P)}}}else if(M instanceof THREE.RenderableFace4){x=M.v1;v=M.v2;H=M.v3;L=M.v4;x.positionScreen.x*=B;x.positionScreen.y*=-A;v.positionScreen.x*=B;v.positionScreen.y*=-A;H.positionScreen.x*=B;H.positionScreen.y*=-A;L.positionScreen.x*=B;L.positionScreen.y*=-A;I.addPoint(x.positionScreen.x,x.positionScreen.y);I.addPoint(v.positionScreen.x,v.positionScreen.y);I.addPoint(H.positionScreen.x,H.positionScreen.y);I.addPoint(L.positionScreen.x,L.positionScreen.y);if(J.instersects(I)){w=
+0;for(r=M.meshMaterial.length;w<r;){T=M.meshMaterial[w++];if(T instanceof THREE.MeshFaceMaterial){N=0;for(S=M.faceMaterial.length;N<S;)(T=M.faceMaterial[N++])&&g(x,v,H,L,M,T,P)}else T&&g(x,v,H,L,M,T,P)}}}}}};
 THREE.WebGLRenderer=function(a){function b(f,m){var e=c.createProgram(),p=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(e,o("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"+
 THREE.WebGLRenderer=function(a){function b(f,m){var e=c.createProgram(),p=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(e,o("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"+
 f));c.attachShader(e,o("vertex",p+m));c.linkProgram(e);c.getProgramParameter(e,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(e,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");e.uniforms={};e.attributes={};return e}function g(f,m){if(f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,
 f));c.attachShader(e,o("vertex",p+m));c.linkProgram(e);c.getProgramParameter(e,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(e,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");e.uniforms={};e.attributes={};return e}function g(f,m){if(f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,
 c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var e=0;e<6;++e)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,f.image[e]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+m);c.bindTexture(c.TEXTURE_CUBE_MAP,
 c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var e=0;e<6;++e)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,f.image[e]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+m);c.bindTexture(c.TEXTURE_CUBE_MAP,

+ 15 - 15
build/ThreeExtras.js

@@ -101,12 +101,12 @@ x.positionScreen.copy(x.position);D.multiplyVector4(x.positionScreen);J=G[F-1];n
 r.x=K.x/K.w;r.y=K.y/K.w;r.z=K.z;r.rotation=C.rotation.z;r.scale.x=C.scale.x*Math.abs(r.x-(K.x+v.projectionMatrix.n11)/(K.w+v.projectionMatrix.n14));r.scale.y=C.scale.y*Math.abs(r.y-(K.y+v.projectionMatrix.n22)/(K.w+v.projectionMatrix.n24));r.material=C.material;m.push(r);s++}}}}q&&m.sort(b);return m};this.unprojectVector=function(j,v){var q=new THREE.Matrix4;q.multiply(THREE.Matrix4.makeInvert(v.matrix),THREE.Matrix4.makeInvert(v.projectionMatrix));q.multiplyVector3(j);return j}};
 r.x=K.x/K.w;r.y=K.y/K.w;r.z=K.z;r.rotation=C.rotation.z;r.scale.x=C.scale.x*Math.abs(r.x-(K.x+v.projectionMatrix.n11)/(K.w+v.projectionMatrix.n14));r.scale.y=C.scale.y*Math.abs(r.y-(K.y+v.projectionMatrix.n22)/(K.w+v.projectionMatrix.n24));r.material=C.material;m.push(r);s++}}}}q&&m.sort(b);return m};this.unprojectVector=function(j,v){var q=new THREE.Matrix4;q.multiply(THREE.Matrix4.makeInvert(v.matrix),THREE.Matrix4.makeInvert(v.projectionMatrix));q.multiplyVector3(j);return j}};
 THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,e,d,f,g;this.domElement=document.createElement("div");this.setSize=function(l,h){e=l;d=h;f=e/2;g=d/2};this.render=function(l,h){var k,c,u,y,r,s,w,z;a=b.projectScene(l,h);k=0;for(c=a.length;k<c;k++){r=a[k];if(r instanceof THREE.RenderableParticle){w=r.x*f+f;z=r.y*g+g;u=0;for(y=r.material.length;u<y;u++){s=r.material[u];if(s instanceof THREE.ParticleDOMMaterial){s=s.domElement;s.style.left=w+"px";s.style.top=z+"px"}}}}}};
 THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,e,d,f,g;this.domElement=document.createElement("div");this.setSize=function(l,h){e=l;d=h;f=e/2;g=d/2};this.render=function(l,h){var k,c,u,y,r,s,w,z;a=b.projectScene(l,h);k=0;for(c=a.length;k<c;k++){r=a[k];if(r instanceof THREE.RenderableParticle){w=r.x*f+f;z=r.y*g+g;u=0;for(y=r.material.length;u<y;u++){s=r.material[u];if(s instanceof THREE.ParticleDOMMaterial){s=s.domElement;s.style.left=w+"px";s.style.top=z+"px"}}}}}};
 THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,e=document.createElement("canvas"),d,f,g,l,h=e.getContext("2d"),k=1,c=0,u=null,y=null,r=1,s,w,z,K,I,D,n,i,o,j=new THREE.Color,v=new THREE.Color,q=new THREE.Color,m=new THREE.Color,A=new THREE.Color,F,M,x,J,R,C,V,T,$,W,O=new THREE.Rectangle,G=new THREE.Rectangle,B=new THREE.Rectangle,S=false,p=new THREE.Color,t=new THREE.Color,E=new THREE.Color,N=new THREE.Color,X=Math.PI*2,Y=new THREE.Vector3,ea,ma,oa,fa,ra,va,pa=16;ea=document.createElement("canvas");
 THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,e=document.createElement("canvas"),d,f,g,l,h=e.getContext("2d"),k=1,c=0,u=null,y=null,r=1,s,w,z,K,I,D,n,i,o,j=new THREE.Color,v=new THREE.Color,q=new THREE.Color,m=new THREE.Color,A=new THREE.Color,F,M,x,J,R,C,V,T,$,W,O=new THREE.Rectangle,G=new THREE.Rectangle,B=new THREE.Rectangle,S=false,p=new THREE.Color,t=new THREE.Color,E=new THREE.Color,N=new THREE.Color,X=Math.PI*2,Y=new THREE.Vector3,ea,ma,oa,fa,ra,va,pa=16;ea=document.createElement("canvas");
-ea.width=ea.height=2;ma=ea.getContext("2d");ma.fillStyle="rgba(0,0,0,1)";ma.fillRect(0,0,2,2);oa=ma.getImageData(0,0,2,2);fa=oa.data;ra=document.createElement("canvas");ra.width=ra.height=pa;va=ra.getContext("2d");va.translate(-pa/2,-pa/2);va.scale(pa,pa);pa--;this.domElement=e;this.autoClear=true;this.setSize=function(ia,wa){d=ia;f=wa;g=d/2;l=f/2;e.width=d;e.height=f;O.set(-g,-l,g,l)};this.clear=function(){if(!G.isEmpty()){G.inflate(1);G.minSelf(O);h.clearRect(G.getX(),G.getY(),G.getWidth(),G.getHeight());
-G.empty()}};this.render=function(ia,wa){function Ka(H){var U,Q,L,P=H.lights;t.setRGB(0,0,0);E.setRGB(0,0,0);N.setRGB(0,0,0);H=0;for(U=P.length;H<U;H++){Q=P[H];L=Q.color;if(Q instanceof THREE.AmbientLight){t.r+=L.r;t.g+=L.g;t.b+=L.b}else if(Q instanceof THREE.DirectionalLight){E.r+=L.r;E.g+=L.g;E.b+=L.b}else if(Q instanceof THREE.PointLight){N.r+=L.r;N.g+=L.g;N.b+=L.b}}}function xa(H,U,Q,L){var P,Z,ba,ca,da=H.lights;H=0;for(P=da.length;H<P;H++){Z=da[H];ba=Z.color;ca=Z.intensity;if(Z instanceof THREE.DirectionalLight){Z=
-Q.dot(Z.position)*ca;if(Z>0){L.r+=ba.r*Z;L.g+=ba.g*Z;L.b+=ba.b*Z}}else if(Z instanceof THREE.PointLight){Y.sub(Z.position,U);Y.normalize();Z=Q.dot(Y)*ca;if(Z>0){L.r+=ba.r*Z;L.g+=ba.g*Z;L.b+=ba.b*Z}}}}function La(H,U,Q){if(Q.opacity!=0){Ca(Q.opacity);ya(Q.blending);var L,P,Z,ba,ca,da;if(Q instanceof THREE.ParticleBasicMaterial){if(Q.map){ba=Q.map;ca=ba.width>>1;da=ba.height>>1;P=U.scale.x*g;Z=U.scale.y*l;Q=P*ca;L=Z*da;B.set(H.x-Q,H.y-L,H.x+Q,H.y+L);if(O.instersects(B)){h.save();h.translate(H.x,H.y);
-h.rotate(-U.rotation);h.scale(P,-Z);h.translate(-ca,-da);h.drawImage(ba,0,0);h.restore()}}}else if(Q instanceof THREE.ParticleCircleMaterial){if(S){p.r=t.r+E.r+N.r;p.g=t.g+E.g+N.g;p.b=t.b+E.b+N.b;j.r=Q.color.r*p.r;j.g=Q.color.g*p.g;j.b=Q.color.b*p.b;j.updateStyleString()}else j.__styleString=Q.color.__styleString;Q=U.scale.x*g;L=U.scale.y*l;B.set(H.x-Q,H.y-L,H.x+Q,H.y+L);if(O.instersects(B)){P=j.__styleString;if(y!=P)h.fillStyle=y=P;h.save();h.translate(H.x,H.y);h.rotate(-U.rotation);h.scale(Q,L);
-h.beginPath();h.arc(0,0,1,0,X,true);h.closePath();h.fill();h.restore()}}}}function Ma(H,U,Q,L){if(L.opacity!=0){Ca(L.opacity);ya(L.blending);h.beginPath();h.moveTo(H.positionScreen.x,H.positionScreen.y);h.lineTo(U.positionScreen.x,U.positionScreen.y);h.closePath();if(L instanceof THREE.LineBasicMaterial){j.__styleString=L.color.__styleString;H=L.linewidth;if(r!=H)h.lineWidth=r=H;H=j.__styleString;if(u!=H)h.strokeStyle=u=H;h.stroke();B.inflate(L.linewidth*2)}}}function Ga(H,U,Q,L,P,Z){if(P.opacity!=
-0){Ca(P.opacity);ya(P.blending);K=H.positionScreen.x;I=H.positionScreen.y;D=U.positionScreen.x;n=U.positionScreen.y;i=Q.positionScreen.x;o=Q.positionScreen.y;h.beginPath();h.moveTo(K,I);h.lineTo(D,n);h.lineTo(i,o);h.lineTo(K,I);h.closePath();if(P instanceof THREE.MeshBasicMaterial)if(P.map)P.map.image.loaded&&P.map.mapping instanceof THREE.UVMapping&&sa(K,I,D,n,i,o,P.map.image,L.uvs[0].u,L.uvs[0].v,L.uvs[1].u,L.uvs[1].v,L.uvs[2].u,L.uvs[2].v);else if(P.env_map){if(P.env_map.image.loaded)if(P.env_map.mapping instanceof
+ea.width=ea.height=2;ma=ea.getContext("2d");ma.fillStyle="rgba(0,0,0,1)";ma.fillRect(0,0,2,2);oa=ma.getImageData(0,0,2,2);fa=oa.data;ra=document.createElement("canvas");ra.width=ra.height=pa;va=ra.getContext("2d");va.translate(-pa/2,-pa/2);va.scale(pa,pa);pa--;this.domElement=e;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ia,wa){d=ia;f=wa;g=d/2;l=f/2;e.width=d;e.height=f;O.set(-g,-l,g,l)};this.clear=function(){if(!G.isEmpty()){G.inflate(1);G.minSelf(O);h.clearRect(G.getX(),
+G.getY(),G.getWidth(),G.getHeight());G.empty()}};this.render=function(ia,wa){function Ka(H){var U,Q,L,P=H.lights;t.setRGB(0,0,0);E.setRGB(0,0,0);N.setRGB(0,0,0);H=0;for(U=P.length;H<U;H++){Q=P[H];L=Q.color;if(Q instanceof THREE.AmbientLight){t.r+=L.r;t.g+=L.g;t.b+=L.b}else if(Q instanceof THREE.DirectionalLight){E.r+=L.r;E.g+=L.g;E.b+=L.b}else if(Q instanceof THREE.PointLight){N.r+=L.r;N.g+=L.g;N.b+=L.b}}}function xa(H,U,Q,L){var P,Z,ba,ca,da=H.lights;H=0;for(P=da.length;H<P;H++){Z=da[H];ba=Z.color;
+ca=Z.intensity;if(Z instanceof THREE.DirectionalLight){Z=Q.dot(Z.position)*ca;if(Z>0){L.r+=ba.r*Z;L.g+=ba.g*Z;L.b+=ba.b*Z}}else if(Z instanceof THREE.PointLight){Y.sub(Z.position,U);Y.normalize();Z=Q.dot(Y)*ca;if(Z>0){L.r+=ba.r*Z;L.g+=ba.g*Z;L.b+=ba.b*Z}}}}function La(H,U,Q){if(Q.opacity!=0){Ca(Q.opacity);ya(Q.blending);var L,P,Z,ba,ca,da;if(Q instanceof THREE.ParticleBasicMaterial){if(Q.map){ba=Q.map;ca=ba.width>>1;da=ba.height>>1;P=U.scale.x*g;Z=U.scale.y*l;Q=P*ca;L=Z*da;B.set(H.x-Q,H.y-L,H.x+Q,
+H.y+L);if(O.instersects(B)){h.save();h.translate(H.x,H.y);h.rotate(-U.rotation);h.scale(P,-Z);h.translate(-ca,-da);h.drawImage(ba,0,0);h.restore()}}}else if(Q instanceof THREE.ParticleCircleMaterial){if(S){p.r=t.r+E.r+N.r;p.g=t.g+E.g+N.g;p.b=t.b+E.b+N.b;j.r=Q.color.r*p.r;j.g=Q.color.g*p.g;j.b=Q.color.b*p.b;j.updateStyleString()}else j.__styleString=Q.color.__styleString;Q=U.scale.x*g;L=U.scale.y*l;B.set(H.x-Q,H.y-L,H.x+Q,H.y+L);if(O.instersects(B)){P=j.__styleString;if(y!=P)h.fillStyle=y=P;h.save();
+h.translate(H.x,H.y);h.rotate(-U.rotation);h.scale(Q,L);h.beginPath();h.arc(0,0,1,0,X,true);h.closePath();h.fill();h.restore()}}}}function Ma(H,U,Q,L){if(L.opacity!=0){Ca(L.opacity);ya(L.blending);h.beginPath();h.moveTo(H.positionScreen.x,H.positionScreen.y);h.lineTo(U.positionScreen.x,U.positionScreen.y);h.closePath();if(L instanceof THREE.LineBasicMaterial){j.__styleString=L.color.__styleString;H=L.linewidth;if(r!=H)h.lineWidth=r=H;H=j.__styleString;if(u!=H)h.strokeStyle=u=H;h.stroke();B.inflate(L.linewidth*
+2)}}}function Ga(H,U,Q,L,P,Z){if(P.opacity!=0){Ca(P.opacity);ya(P.blending);K=H.positionScreen.x;I=H.positionScreen.y;D=U.positionScreen.x;n=U.positionScreen.y;i=Q.positionScreen.x;o=Q.positionScreen.y;h.beginPath();h.moveTo(K,I);h.lineTo(D,n);h.lineTo(i,o);h.lineTo(K,I);h.closePath();if(P instanceof THREE.MeshBasicMaterial)if(P.map)P.map.image.loaded&&P.map.mapping instanceof THREE.UVMapping&&sa(K,I,D,n,i,o,P.map.image,L.uvs[0].u,L.uvs[0].v,L.uvs[1].u,L.uvs[1].v,L.uvs[2].u,L.uvs[2].v);else if(P.env_map){if(P.env_map.image.loaded)if(P.env_map.mapping instanceof
 THREE.SphericalReflectionMapping){H=wa.matrix;Y.copy(L.vertexNormalsWorld[0]);R=(Y.x*H.n11+Y.y*H.n12+Y.z*H.n13)*0.5+0.5;C=-(Y.x*H.n21+Y.y*H.n22+Y.z*H.n23)*0.5+0.5;Y.copy(L.vertexNormalsWorld[1]);V=(Y.x*H.n11+Y.y*H.n12+Y.z*H.n13)*0.5+0.5;T=-(Y.x*H.n21+Y.y*H.n22+Y.z*H.n23)*0.5+0.5;Y.copy(L.vertexNormalsWorld[2]);$=(Y.x*H.n11+Y.y*H.n12+Y.z*H.n13)*0.5+0.5;W=-(Y.x*H.n21+Y.y*H.n22+Y.z*H.n23)*0.5+0.5;sa(K,I,D,n,i,o,P.env_map.image,R,C,V,T,$,W)}}else P.wireframe?za(P.color.__styleString,P.wireframe_linewidth):
 THREE.SphericalReflectionMapping){H=wa.matrix;Y.copy(L.vertexNormalsWorld[0]);R=(Y.x*H.n11+Y.y*H.n12+Y.z*H.n13)*0.5+0.5;C=-(Y.x*H.n21+Y.y*H.n22+Y.z*H.n23)*0.5+0.5;Y.copy(L.vertexNormalsWorld[1]);V=(Y.x*H.n11+Y.y*H.n12+Y.z*H.n13)*0.5+0.5;T=-(Y.x*H.n21+Y.y*H.n22+Y.z*H.n23)*0.5+0.5;Y.copy(L.vertexNormalsWorld[2]);$=(Y.x*H.n11+Y.y*H.n12+Y.z*H.n13)*0.5+0.5;W=-(Y.x*H.n21+Y.y*H.n22+Y.z*H.n23)*0.5+0.5;sa(K,I,D,n,i,o,P.env_map.image,R,C,V,T,$,W)}}else P.wireframe?za(P.color.__styleString,P.wireframe_linewidth):
 Aa(P.color.__styleString);else if(P instanceof THREE.MeshLambertMaterial){if(P.map&&!P.wireframe){P.map.mapping instanceof THREE.UVMapping&&sa(K,I,D,n,i,o,P.map.image,L.uvs[0].u,L.uvs[0].v,L.uvs[1].u,L.uvs[1].v,L.uvs[2].u,L.uvs[2].v);ya(THREE.SubtractiveBlending)}if(S)if(!P.wireframe&&P.shading==THREE.SmoothShading&&L.vertexNormalsWorld.length==3){v.r=q.r=m.r=t.r;v.g=q.g=m.g=t.g;v.b=q.b=m.b=t.b;xa(Z,L.v1.positionWorld,L.vertexNormalsWorld[0],v);xa(Z,L.v2.positionWorld,L.vertexNormalsWorld[1],q);xa(Z,
 Aa(P.color.__styleString);else if(P instanceof THREE.MeshLambertMaterial){if(P.map&&!P.wireframe){P.map.mapping instanceof THREE.UVMapping&&sa(K,I,D,n,i,o,P.map.image,L.uvs[0].u,L.uvs[0].v,L.uvs[1].u,L.uvs[1].v,L.uvs[2].u,L.uvs[2].v);ya(THREE.SubtractiveBlending)}if(S)if(!P.wireframe&&P.shading==THREE.SmoothShading&&L.vertexNormalsWorld.length==3){v.r=q.r=m.r=t.r;v.g=q.g=m.g=t.g;v.b=q.b=m.b=t.b;xa(Z,L.v1.positionWorld,L.vertexNormalsWorld[0],v);xa(Z,L.v2.positionWorld,L.vertexNormalsWorld[1],q);xa(Z,
 L.v3.positionWorld,L.vertexNormalsWorld[2],m);A.r=(q.r+m.r)*0.5;A.g=(q.g+m.g)*0.5;A.b=(q.b+m.b)*0.5;J=Ha(v,q,m,A);sa(K,I,D,n,i,o,J,0,0,1,0,0,1)}else{p.r=t.r;p.g=t.g;p.b=t.b;xa(Z,L.centroidWorld,L.normalWorld,p);j.r=P.color.r*p.r;j.g=P.color.g*p.g;j.b=P.color.b*p.b;j.updateStyleString();P.wireframe?za(j.__styleString,P.wireframe_linewidth):Aa(j.__styleString)}else P.wireframe?za(P.color.__styleString,P.wireframe_linewidth):Aa(P.color.__styleString)}else if(P instanceof THREE.MeshDepthMaterial){F=P.__2near;
 L.v3.positionWorld,L.vertexNormalsWorld[2],m);A.r=(q.r+m.r)*0.5;A.g=(q.g+m.g)*0.5;A.b=(q.b+m.b)*0.5;J=Ha(v,q,m,A);sa(K,I,D,n,i,o,J,0,0,1,0,0,1)}else{p.r=t.r;p.g=t.g;p.b=t.b;xa(Z,L.centroidWorld,L.normalWorld,p);j.r=P.color.r*p.r;j.g=P.color.g*p.g;j.b=P.color.b*p.b;j.updateStyleString();P.wireframe?za(j.__styleString,P.wireframe_linewidth):Aa(j.__styleString)}else P.wireframe?za(P.color.__styleString,P.wireframe_linewidth):Aa(P.color.__styleString)}else if(P instanceof THREE.MeshDepthMaterial){F=P.__2near;
@@ -114,7 +114,7 @@ M=P.__farPlusNear;x=P.__farMinusNear;v.r=v.g=v.b=1-F/(M-H.positionScreen.z*x);q.
 u=H;if(r!=U)h.lineWidth=r=U;h.stroke();B.inflate(U*2)}function Aa(H){if(y!=H)h.fillStyle=y=H;h.fill()}function sa(H,U,Q,L,P,Z,ba,ca,da,ja,ga,ka,ta){var na,la;na=ba.width-1;la=ba.height-1;ca*=na;da*=la;ja*=na;ga*=la;ka*=na;ta*=la;Q-=H;L-=U;P-=H;Z-=U;ja-=ca;ga-=da;ka-=ca;ta-=da;la=1/(ja*ta-ka*ga);na=(ta*Q-ga*P)*la;ga=(ta*L-ga*Z)*la;Q=(ja*P-ka*Q)*la;L=(ja*Z-ka*L)*la;H=H-na*ca-Q*da;U=U-ga*ca-L*da;h.save();h.transform(na,ga,Q,L,H,U);h.clip();h.drawImage(ba,0,0);h.restore()}function Ca(H){if(k!=H)h.globalAlpha=
 u=H;if(r!=U)h.lineWidth=r=U;h.stroke();B.inflate(U*2)}function Aa(H){if(y!=H)h.fillStyle=y=H;h.fill()}function sa(H,U,Q,L,P,Z,ba,ca,da,ja,ga,ka,ta){var na,la;na=ba.width-1;la=ba.height-1;ca*=na;da*=la;ja*=na;ga*=la;ka*=na;ta*=la;Q-=H;L-=U;P-=H;Z-=U;ja-=ca;ga-=da;ka-=ca;ta-=da;la=1/(ja*ta-ka*ga);na=(ta*Q-ga*P)*la;ga=(ta*L-ga*Z)*la;Q=(ja*P-ka*Q)*la;L=(ja*Z-ka*L)*la;H=H-na*ca-Q*da;U=U-ga*ca-L*da;h.save();h.transform(na,ga,Q,L,H,U);h.clip();h.drawImage(ba,0,0);h.restore()}function Ca(H){if(k!=H)h.globalAlpha=
 k=H}function ya(H){if(c!=H){switch(H){case THREE.NormalBlending:h.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:h.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:h.globalCompositeOperation="darker"}c=H}}function Ha(H,U,Q,L){var P=~~(H.r*255),Z=~~(H.g*255);H=~~(H.b*255);var ba=~~(U.r*255),ca=~~(U.g*255);U=~~(U.b*255);var da=~~(Q.r*255),ja=~~(Q.g*255);Q=~~(Q.b*255);var ga=~~(L.r*255),ka=~~(L.g*255);L=~~(L.b*255);fa[0]=P<0?0:P>255?255:P;fa[1]=Z<0?0:
 k=H}function ya(H){if(c!=H){switch(H){case THREE.NormalBlending:h.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:h.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:h.globalCompositeOperation="darker"}c=H}}function Ha(H,U,Q,L){var P=~~(H.r*255),Z=~~(H.g*255);H=~~(H.b*255);var ba=~~(U.r*255),ca=~~(U.g*255);U=~~(U.b*255);var da=~~(Q.r*255),ja=~~(Q.g*255);Q=~~(Q.b*255);var ga=~~(L.r*255),ka=~~(L.g*255);L=~~(L.b*255);fa[0]=P<0?0:P>255?255:P;fa[1]=Z<0?0:
 Z>255?255:Z;fa[2]=H<0?0:H>255?255:H;fa[4]=ba<0?0:ba>255?255:ba;fa[5]=ca<0?0:ca>255?255:ca;fa[6]=U<0?0:U>255?255:U;fa[8]=da<0?0:da>255?255:da;fa[9]=ja<0?0:ja>255?255:ja;fa[10]=Q<0?0:Q>255?255:Q;fa[12]=ga<0?0:ga>255?255:ga;fa[13]=ka<0?0:ka>255?255:ka;fa[14]=L<0?0:L>255?255:L;ma.putImageData(oa,0,0);va.drawImage(ea,0,0);return ra}function Da(H){H=(H+1)*0.5;return H<0?0:H>1?1:H}function Ea(H,U){var Q=U.x-H.x,L=U.y-H.y,P=1/Math.sqrt(Q*Q+L*L);Q*=P;L*=P;U.x+=Q;U.y+=L;H.x-=Q;H.y-=L}var Ba,Ia,aa,ha,qa,Fa,
 Z>255?255:Z;fa[2]=H<0?0:H>255?255:H;fa[4]=ba<0?0:ba>255?255:ba;fa[5]=ca<0?0:ca>255?255:ca;fa[6]=U<0?0:U>255?255:U;fa[8]=da<0?0:da>255?255:da;fa[9]=ja<0?0:ja>255?255:ja;fa[10]=Q<0?0:Q>255?255:Q;fa[12]=ga<0?0:ga>255?255:ga;fa[13]=ka<0?0:ka>255?255:ka;fa[14]=L<0?0:L>255?255:L;ma.putImageData(oa,0,0);va.drawImage(ea,0,0);return ra}function Da(H){H=(H+1)*0.5;return H<0?0:H>1?1:H}function Ea(H,U){var Q=U.x-H.x,L=U.y-H.y,P=1/Math.sqrt(Q*Q+L*L);Q*=P;L*=P;U.x+=Q;U.y+=L;H.x-=Q;H.y-=L}var Ba,Ia,aa,ha,qa,Fa,
-Ja,ua;h.setTransform(1,0,0,-1,g,l);this.autoClear&&this.clear();a=b.projectScene(ia,wa,true);(S=ia.lights.length>0)&&Ka(ia);Ba=0;for(Ia=a.length;Ba<Ia;Ba++){aa=a[Ba];B.empty();if(aa instanceof THREE.RenderableParticle){s=aa;s.x*=g;s.y*=l;ha=0;for(qa=aa.material.length;ha<qa;ha++)La(s,aa,aa.material[ha],ia)}else if(aa instanceof THREE.RenderableLine){s=aa.v1;w=aa.v2;s.positionScreen.x*=g;s.positionScreen.y*=l;w.positionScreen.x*=g;w.positionScreen.y*=l;B.addPoint(s.positionScreen.x,s.positionScreen.y);
+Ja,ua;h.setTransform(1,0,0,-1,g,l);this.autoClear&&this.clear();a=b.projectScene(ia,wa,this.sortElements);(S=ia.lights.length>0)&&Ka(ia);Ba=0;for(Ia=a.length;Ba<Ia;Ba++){aa=a[Ba];B.empty();if(aa instanceof THREE.RenderableParticle){s=aa;s.x*=g;s.y*=l;ha=0;for(qa=aa.material.length;ha<qa;ha++)La(s,aa,aa.material[ha],ia)}else if(aa instanceof THREE.RenderableLine){s=aa.v1;w=aa.v2;s.positionScreen.x*=g;s.positionScreen.y*=l;w.positionScreen.x*=g;w.positionScreen.y*=l;B.addPoint(s.positionScreen.x,s.positionScreen.y);
 B.addPoint(w.positionScreen.x,w.positionScreen.y);if(O.instersects(B)){ha=0;for(qa=aa.material.length;ha<qa;)Ma(s,w,aa,aa.material[ha++],ia)}}else if(aa instanceof THREE.RenderableFace3){s=aa.v1;w=aa.v2;z=aa.v3;s.positionScreen.x*=g;s.positionScreen.y*=l;w.positionScreen.x*=g;w.positionScreen.y*=l;z.positionScreen.x*=g;z.positionScreen.y*=l;if(aa.overdraw){Ea(s.positionScreen,w.positionScreen);Ea(w.positionScreen,z.positionScreen);Ea(z.positionScreen,s.positionScreen)}B.add3Points(s.positionScreen.x,
 B.addPoint(w.positionScreen.x,w.positionScreen.y);if(O.instersects(B)){ha=0;for(qa=aa.material.length;ha<qa;)Ma(s,w,aa,aa.material[ha++],ia)}}else if(aa instanceof THREE.RenderableFace3){s=aa.v1;w=aa.v2;z=aa.v3;s.positionScreen.x*=g;s.positionScreen.y*=l;w.positionScreen.x*=g;w.positionScreen.y*=l;z.positionScreen.x*=g;z.positionScreen.y*=l;if(aa.overdraw){Ea(s.positionScreen,w.positionScreen);Ea(w.positionScreen,z.positionScreen);Ea(z.positionScreen,s.positionScreen)}B.add3Points(s.positionScreen.x,
 s.positionScreen.y,w.positionScreen.x,w.positionScreen.y,z.positionScreen.x,z.positionScreen.y);if(O.instersects(B)){ha=0;for(qa=aa.meshMaterial.length;ha<qa;){ua=aa.meshMaterial[ha++];if(ua instanceof THREE.MeshFaceMaterial){Fa=0;for(Ja=aa.faceMaterial.length;Fa<Ja;)(ua=aa.faceMaterial[Fa++])&&Ga(s,w,z,aa,ua,ia)}else Ga(s,w,z,aa,ua,ia)}}}G.addRectangle(B)}h.setTransform(1,0,0,1,0,0)}};
 s.positionScreen.y,w.positionScreen.x,w.positionScreen.y,z.positionScreen.x,z.positionScreen.y);if(O.instersects(B)){ha=0;for(qa=aa.meshMaterial.length;ha<qa;){ua=aa.meshMaterial[ha++];if(ua instanceof THREE.MeshFaceMaterial){Fa=0;for(Ja=aa.faceMaterial.length;Fa<Ja;)(ua=aa.faceMaterial[Fa++])&&Ga(s,w,z,aa,ua,ia)}else Ga(s,w,z,aa,ua,ia)}}}G.addRectangle(B)}h.setTransform(1,0,0,1,0,0)}};
 THREE.SVGRenderer=function(){function a(T,$,W){var O,G,B,S;O=0;for(G=T.lights.length;O<G;O++){B=T.lights[O];if(B instanceof THREE.DirectionalLight){S=$.normalWorld.dot(B.position)*B.intensity;if(S>0){W.r+=B.color.r*S;W.g+=B.color.g*S;W.b+=B.color.b*S}}else if(B instanceof THREE.PointLight){m.sub(B.position,$.centroidWorld);m.normalize();S=$.normalWorld.dot(m)*B.intensity;if(S>0){W.r+=B.color.r*S;W.g+=B.color.g*S;W.b+=B.color.b*S}}}}function b(T,$,W,O,G,B){x=d(J++);x.setAttribute("d","M "+T.positionScreen.x+
 THREE.SVGRenderer=function(){function a(T,$,W){var O,G,B,S;O=0;for(G=T.lights.length;O<G;O++){B=T.lights[O];if(B instanceof THREE.DirectionalLight){S=$.normalWorld.dot(B.position)*B.intensity;if(S>0){W.r+=B.color.r*S;W.g+=B.color.g*S;W.b+=B.color.b*S}}else if(B instanceof THREE.PointLight){m.sub(B.position,$.centroidWorld);m.normalize();S=$.normalWorld.dot(m)*B.intensity;if(S>0){W.r+=B.color.r*S;W.g+=B.color.g*S;W.b+=B.color.b*S}}}}function b(T,$,W,O,G,B){x=d(J++);x.setAttribute("d","M "+T.positionScreen.x+
@@ -123,14 +123,14 @@ n.setRGB(q,q,q)}else G instanceof THREE.MeshNormalMaterial&&n.setRGB(f(O.normalW
 "M "+T.positionScreen.x+" "+T.positionScreen.y+" L "+$.positionScreen.x+" "+$.positionScreen.y+" L "+W.positionScreen.x+","+W.positionScreen.y+" L "+O.positionScreen.x+","+O.positionScreen.y+"z");if(B instanceof THREE.MeshBasicMaterial)n.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshLambertMaterial)if(D){i.r=o.r;i.g=o.g;i.b=o.b;a(S,G,i);n.r=B.color.r*i.r;n.g=B.color.g*i.g;n.b=B.color.b*i.b;n.updateStyleString()}else n.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshDepthMaterial){q=
 "M "+T.positionScreen.x+" "+T.positionScreen.y+" L "+$.positionScreen.x+" "+$.positionScreen.y+" L "+W.positionScreen.x+","+W.positionScreen.y+" L "+O.positionScreen.x+","+O.positionScreen.y+"z");if(B instanceof THREE.MeshBasicMaterial)n.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshLambertMaterial)if(D){i.r=o.r;i.g=o.g;i.b=o.b;a(S,G,i);n.r=B.color.r*i.r;n.g=B.color.g*i.g;n.b=B.color.b*i.b;n.updateStyleString()}else n.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshDepthMaterial){q=
 1-B.__2near/(B.__farPlusNear-G.z*B.__farMinusNear);n.setRGB(q,q,q)}else B instanceof THREE.MeshNormalMaterial&&n.setRGB(f(G.normalWorld.x),f(G.normalWorld.y),f(G.normalWorld.z));B.wireframe?x.setAttribute("style","fill: none; stroke: "+n.__styleString+"; stroke-width: "+B.wireframe_linewidth+"; stroke-opacity: "+B.opacity+"; stroke-linecap: "+B.wireframe_linecap+"; stroke-linejoin: "+B.wireframe_linejoin):x.setAttribute("style","fill: "+n.__styleString+"; fill-opacity: "+B.opacity);h.appendChild(x)}
 1-B.__2near/(B.__farPlusNear-G.z*B.__farMinusNear);n.setRGB(q,q,q)}else B instanceof THREE.MeshNormalMaterial&&n.setRGB(f(G.normalWorld.x),f(G.normalWorld.y),f(G.normalWorld.z));B.wireframe?x.setAttribute("style","fill: none; stroke: "+n.__styleString+"; stroke-width: "+B.wireframe_linewidth+"; stroke-opacity: "+B.opacity+"; stroke-linecap: "+B.wireframe_linecap+"; stroke-linejoin: "+B.wireframe_linejoin):x.setAttribute("style","fill: "+n.__styleString+"; fill-opacity: "+B.opacity);h.appendChild(x)}
 function d(T){if(A[T]==null){A[T]=document.createElementNS("http://www.w3.org/2000/svg","path");V==0&&A[T].setAttribute("shape-rendering","crispEdges");return A[T]}return A[T]}function f(T){return T<0?Math.min((1+T)*0.5,0.5):0.5+Math.min(T*0.5,0.5)}var g=null,l=new THREE.Projector,h=document.createElementNS("http://www.w3.org/2000/svg","svg"),k,c,u,y,r,s,w,z,K=new THREE.Rectangle,I=new THREE.Rectangle,D=false,n=new THREE.Color(16777215),i=new THREE.Color(16777215),o=new THREE.Color(0),j=new THREE.Color(0),
 function d(T){if(A[T]==null){A[T]=document.createElementNS("http://www.w3.org/2000/svg","path");V==0&&A[T].setAttribute("shape-rendering","crispEdges");return A[T]}return A[T]}function f(T){return T<0?Math.min((1+T)*0.5,0.5):0.5+Math.min(T*0.5,0.5)}var g=null,l=new THREE.Projector,h=document.createElementNS("http://www.w3.org/2000/svg","svg"),k,c,u,y,r,s,w,z,K=new THREE.Rectangle,I=new THREE.Rectangle,D=false,n=new THREE.Color(16777215),i=new THREE.Color(16777215),o=new THREE.Color(0),j=new THREE.Color(0),
-v=new THREE.Color(0),q,m=new THREE.Vector3,A=[],F=[],M=[],x,J,R,C,V=1;this.domElement=h;this.autoClear=true;this.setQuality=function(T){switch(T){case "high":V=1;break;case "low":V=0}};this.setSize=function(T,$){k=T;c=$;u=k/2;y=c/2;h.setAttribute("viewBox",-u+" "+-y+" "+k+" "+c);h.setAttribute("width",k);h.setAttribute("height",c);K.set(-u,-y,u,y)};this.clear=function(){for(;h.childNodes.length>0;)h.removeChild(h.childNodes[0])};this.render=function(T,$){var W,O,G,B,S,p,t,E;this.autoClear&&this.clear();
-g=l.projectScene(T,$,true);C=R=J=0;if(D=T.lights.length>0){t=T.lights;o.setRGB(0,0,0);j.setRGB(0,0,0);v.setRGB(0,0,0);W=0;for(O=t.length;W<O;W++){G=t[W];B=G.color;if(G instanceof THREE.AmbientLight){o.r+=B.r;o.g+=B.g;o.b+=B.b}else if(G instanceof THREE.DirectionalLight){j.r+=B.r;j.g+=B.g;j.b+=B.b}else if(G instanceof THREE.PointLight){v.r+=B.r;v.g+=B.g;v.b+=B.b}}}W=0;for(O=g.length;W<O;W++){t=g[W];I.empty();if(t instanceof THREE.RenderableParticle){r=t;r.x*=u;r.y*=-y;G=0;for(B=t.material.length;G<
-B;G++)if(E=t.material[G]){S=r;p=t;E=E;var N=R++;if(F[N]==null){F[N]=document.createElementNS("http://www.w3.org/2000/svg","circle");V==0&&F[N].setAttribute("shape-rendering","crispEdges")}x=F[N];x.setAttribute("cx",S.x);x.setAttribute("cy",S.y);x.setAttribute("r",p.scale.x*u);if(E instanceof THREE.ParticleCircleMaterial){if(D){i.r=o.r+j.r+v.r;i.g=o.g+j.g+v.g;i.b=o.b+j.b+v.b;n.r=E.color.r*i.r;n.g=E.color.g*i.g;n.b=E.color.b*i.b;n.updateStyleString()}else n=E.color;x.setAttribute("style","fill: "+n.__styleString)}h.appendChild(x)}}else if(t instanceof
-THREE.RenderableLine){r=t.v1;s=t.v2;r.positionScreen.x*=u;r.positionScreen.y*=-y;s.positionScreen.x*=u;s.positionScreen.y*=-y;I.addPoint(r.positionScreen.x,r.positionScreen.y);I.addPoint(s.positionScreen.x,s.positionScreen.y);if(K.instersects(I)){G=0;for(B=t.material.length;G<B;)if(E=t.material[G++]){S=r;p=s;E=E;N=C++;if(M[N]==null){M[N]=document.createElementNS("http://www.w3.org/2000/svg","line");V==0&&M[N].setAttribute("shape-rendering","crispEdges")}x=M[N];x.setAttribute("x1",S.positionScreen.x);
-x.setAttribute("y1",S.positionScreen.y);x.setAttribute("x2",p.positionScreen.x);x.setAttribute("y2",p.positionScreen.y);if(E instanceof THREE.LineBasicMaterial){n.__styleString=E.color.__styleString;x.setAttribute("style","fill: none; stroke: "+n.__styleString+"; stroke-width: "+E.linewidth+"; stroke-opacity: "+E.opacity+"; stroke-linecap: "+E.linecap+"; stroke-linejoin: "+E.linejoin);h.appendChild(x)}}}}else if(t instanceof THREE.RenderableFace3){r=t.v1;s=t.v2;w=t.v3;r.positionScreen.x*=u;r.positionScreen.y*=
--y;s.positionScreen.x*=u;s.positionScreen.y*=-y;w.positionScreen.x*=u;w.positionScreen.y*=-y;I.addPoint(r.positionScreen.x,r.positionScreen.y);I.addPoint(s.positionScreen.x,s.positionScreen.y);I.addPoint(w.positionScreen.x,w.positionScreen.y);if(K.instersects(I)){G=0;for(B=t.meshMaterial.length;G<B;){E=t.meshMaterial[G++];if(E instanceof THREE.MeshFaceMaterial){S=0;for(p=t.faceMaterial.length;S<p;)(E=t.faceMaterial[S++])&&b(r,s,w,t,E,T)}else E&&b(r,s,w,t,E,T)}}}else if(t instanceof THREE.RenderableFace4){r=
-t.v1;s=t.v2;w=t.v3;z=t.v4;r.positionScreen.x*=u;r.positionScreen.y*=-y;s.positionScreen.x*=u;s.positionScreen.y*=-y;w.positionScreen.x*=u;w.positionScreen.y*=-y;z.positionScreen.x*=u;z.positionScreen.y*=-y;I.addPoint(r.positionScreen.x,r.positionScreen.y);I.addPoint(s.positionScreen.x,s.positionScreen.y);I.addPoint(w.positionScreen.x,w.positionScreen.y);I.addPoint(z.positionScreen.x,z.positionScreen.y);if(K.instersects(I)){G=0;for(B=t.meshMaterial.length;G<B;){E=t.meshMaterial[G++];if(E instanceof
-THREE.MeshFaceMaterial){S=0;for(p=t.faceMaterial.length;S<p;)(E=t.faceMaterial[S++])&&e(r,s,w,z,t,E,T)}else E&&e(r,s,w,z,t,E,T)}}}}}};
+v=new THREE.Color(0),q,m=new THREE.Vector3,A=[],F=[],M=[],x,J,R,C,V=1;this.domElement=h;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(T){switch(T){case "high":V=1;break;case "low":V=0}};this.setSize=function(T,$){k=T;c=$;u=k/2;y=c/2;h.setAttribute("viewBox",-u+" "+-y+" "+k+" "+c);h.setAttribute("width",k);h.setAttribute("height",c);K.set(-u,-y,u,y)};this.clear=function(){for(;h.childNodes.length>0;)h.removeChild(h.childNodes[0])};this.render=function(T,$){var W,O,
+G,B,S,p,t,E;this.autoClear&&this.clear();g=l.projectScene(T,$,this.sortElements);C=R=J=0;if(D=T.lights.length>0){t=T.lights;o.setRGB(0,0,0);j.setRGB(0,0,0);v.setRGB(0,0,0);W=0;for(O=t.length;W<O;W++){G=t[W];B=G.color;if(G instanceof THREE.AmbientLight){o.r+=B.r;o.g+=B.g;o.b+=B.b}else if(G instanceof THREE.DirectionalLight){j.r+=B.r;j.g+=B.g;j.b+=B.b}else if(G instanceof THREE.PointLight){v.r+=B.r;v.g+=B.g;v.b+=B.b}}}W=0;for(O=g.length;W<O;W++){t=g[W];I.empty();if(t instanceof THREE.RenderableParticle){r=
+t;r.x*=u;r.y*=-y;G=0;for(B=t.material.length;G<B;G++)if(E=t.material[G]){S=r;p=t;E=E;var N=R++;if(F[N]==null){F[N]=document.createElementNS("http://www.w3.org/2000/svg","circle");V==0&&F[N].setAttribute("shape-rendering","crispEdges")}x=F[N];x.setAttribute("cx",S.x);x.setAttribute("cy",S.y);x.setAttribute("r",p.scale.x*u);if(E instanceof THREE.ParticleCircleMaterial){if(D){i.r=o.r+j.r+v.r;i.g=o.g+j.g+v.g;i.b=o.b+j.b+v.b;n.r=E.color.r*i.r;n.g=E.color.g*i.g;n.b=E.color.b*i.b;n.updateStyleString()}else n=
+E.color;x.setAttribute("style","fill: "+n.__styleString)}h.appendChild(x)}}else if(t instanceof THREE.RenderableLine){r=t.v1;s=t.v2;r.positionScreen.x*=u;r.positionScreen.y*=-y;s.positionScreen.x*=u;s.positionScreen.y*=-y;I.addPoint(r.positionScreen.x,r.positionScreen.y);I.addPoint(s.positionScreen.x,s.positionScreen.y);if(K.instersects(I)){G=0;for(B=t.material.length;G<B;)if(E=t.material[G++]){S=r;p=s;E=E;N=C++;if(M[N]==null){M[N]=document.createElementNS("http://www.w3.org/2000/svg","line");V==
+0&&M[N].setAttribute("shape-rendering","crispEdges")}x=M[N];x.setAttribute("x1",S.positionScreen.x);x.setAttribute("y1",S.positionScreen.y);x.setAttribute("x2",p.positionScreen.x);x.setAttribute("y2",p.positionScreen.y);if(E instanceof THREE.LineBasicMaterial){n.__styleString=E.color.__styleString;x.setAttribute("style","fill: none; stroke: "+n.__styleString+"; stroke-width: "+E.linewidth+"; stroke-opacity: "+E.opacity+"; stroke-linecap: "+E.linecap+"; stroke-linejoin: "+E.linejoin);h.appendChild(x)}}}}else if(t instanceof
+THREE.RenderableFace3){r=t.v1;s=t.v2;w=t.v3;r.positionScreen.x*=u;r.positionScreen.y*=-y;s.positionScreen.x*=u;s.positionScreen.y*=-y;w.positionScreen.x*=u;w.positionScreen.y*=-y;I.addPoint(r.positionScreen.x,r.positionScreen.y);I.addPoint(s.positionScreen.x,s.positionScreen.y);I.addPoint(w.positionScreen.x,w.positionScreen.y);if(K.instersects(I)){G=0;for(B=t.meshMaterial.length;G<B;){E=t.meshMaterial[G++];if(E instanceof THREE.MeshFaceMaterial){S=0;for(p=t.faceMaterial.length;S<p;)(E=t.faceMaterial[S++])&&
+b(r,s,w,t,E,T)}else E&&b(r,s,w,t,E,T)}}}else if(t instanceof THREE.RenderableFace4){r=t.v1;s=t.v2;w=t.v3;z=t.v4;r.positionScreen.x*=u;r.positionScreen.y*=-y;s.positionScreen.x*=u;s.positionScreen.y*=-y;w.positionScreen.x*=u;w.positionScreen.y*=-y;z.positionScreen.x*=u;z.positionScreen.y*=-y;I.addPoint(r.positionScreen.x,r.positionScreen.y);I.addPoint(s.positionScreen.x,s.positionScreen.y);I.addPoint(w.positionScreen.x,w.positionScreen.y);I.addPoint(z.positionScreen.x,z.positionScreen.y);if(K.instersects(I)){G=
+0;for(B=t.meshMaterial.length;G<B;){E=t.meshMaterial[G++];if(E instanceof THREE.MeshFaceMaterial){S=0;for(p=t.faceMaterial.length;S<p;)(E=t.faceMaterial[S++])&&e(r,s,w,z,t,E,T)}else E&&e(r,s,w,z,t,E,T)}}}}}};
 THREE.WebGLRenderer=function(a){function b(i,o){var j=c.createProgram(),v=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(j,l("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"+
 THREE.WebGLRenderer=function(a){function b(i,o){var j=c.createProgram(),v=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(j,l("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"+
 i));c.attachShader(j,l("vertex",v+o));c.linkProgram(j);c.getProgramParameter(j,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(j,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");j.uniforms={};j.attributes={};return j}function e(i,o){if(i.image.length==6){if(!i.image.__webGLTextureCube&&!i.image.__cubeMapInitialized&&i.image.loadCount==6){i.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,i.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,
 i));c.attachShader(j,l("vertex",v+o));c.linkProgram(j);c.getProgramParameter(j,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(j,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");j.uniforms={};j.attributes={};return j}function e(i,o){if(i.image.length==6){if(!i.image.__webGLTextureCube&&!i.image.__cubeMapInitialized&&i.image.loadCount==6){i.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,i.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,
 c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var j=0;j<6;++j)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+j,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,i.image[j]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);i.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+o);c.bindTexture(c.TEXTURE_CUBE_MAP,
 c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var j=0;j<6;++j)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+j,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,i.image[j]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);i.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+o);c.bindTexture(c.TEXTURE_CUBE_MAP,

+ 122 - 0
examples/materials_grass.html

@@ -0,0 +1,122 @@
+<!DOCTYPE HTML>
+<html lang="en">
+	<head>
+		<title>three.js - grass</title>
+		<meta charset="utf-8">
+		<style type="text/css">
+			body {
+				background:#030;
+				color:#fff;
+				padding:0;
+				margin:0;
+				overflow:hidden;
+				font-family:georgia;
+				text-align:center;
+			}
+		</style>
+	</head>
+
+	<body>
+		<script type="text/javascript" src="../build/Three.js"></script>
+		<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
+
+
+		<script type="text/javascript">
+
+			var camera, scene, renderer,
+			mesh, levels = [];
+
+			init();
+			setInterval( loop, 1000 / 60 );
+
+			function init() {
+
+				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
+				camera.position.y = 75;
+				camera.position.z = 100;
+
+				scene = new THREE.Scene();
+
+				var geometry = new Plane( 100, 100 );
+
+				var texture = generateTextureBase();
+
+				for ( var i = 0; i < 10; i ++ ) {
+
+					mesh = levels[ i ] = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { map: new THREE.Texture( generateTextureLevel( texture ), new THREE.UVMapping(), THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping ) } ) );
+					mesh.rotation.x = - 90 * ( Math.PI / 180 );
+					mesh.position.y = i * 0.5;
+					scene.addObject( mesh );
+
+				}
+
+				renderer = new THREE.WebGLRenderer();
+				renderer.sortObjects = false;
+				renderer.setSize( window.innerWidth, window.innerHeight );
+				document.body.appendChild( renderer.domElement );
+
+			}
+
+			function generateTextureBase() {
+
+				var canvas = document.createElement( 'canvas' );
+				canvas.loaded = true;
+				canvas.width = 1024;
+				canvas.height = 1024;
+
+				var context = canvas.getContext( '2d' );
+
+				for ( var i = 0; i < 20000; i ++ ) {
+
+					context.fillStyle = 'rgba(0,' + Math.floor( Math.random() * 64 + 32 ) + ',16,1)';
+					context.beginPath();
+					context.arc( Math.random() * canvas.width, Math.random() * canvas.height, Math.random() * 3 + 1, 0, Math.PI * 2, true );
+					context.closePath();
+					context.fill();
+
+				}
+
+				context.globalAlpha = 0.1;
+				context.globalCompositeOperation = 'lighter';
+
+				return canvas;
+			}
+
+			function generateTextureLevel( texture ) {
+
+				texture.getContext( '2d' ).drawImage( texture, 0, 0 );
+
+				var canvas = document.createElement( 'canvas' );
+				canvas.loaded = true;
+				canvas.width = texture.width;
+				canvas.height = texture.height;
+
+				canvas.getContext( '2d' ).drawImage( texture, 0, 0 );
+
+				return canvas;
+
+			}
+
+			function loop() {
+
+				var time = new Date().getTime() / 6000;
+
+				camera.position.x = 100 * Math.cos( time );
+				camera.position.z = 100 * Math.sin( time );
+
+				for ( var i = 0, l = levels.length; i < l; i ++ ) {
+
+					mesh = levels[ i ];
+					mesh.position.x = Math.sin( time * 4 ) * i * i * 0.02;
+					mesh.position.z = Math.cos( time * 6 ) * i * i * 0.02;
+
+				}
+
+				renderer.render( scene, camera );
+
+			}
+
+		</script>
+
+	</body>
+</html>

+ 4 - 1
src/renderers/CanvasRenderer.js

@@ -66,7 +66,10 @@ THREE.CanvasRenderer = function () {
 	_gradientMapQuality --; // Fix UVs
 	_gradientMapQuality --; // Fix UVs
 
 
 	this.domElement = _canvas;
 	this.domElement = _canvas;
+
 	this.autoClear = true;
 	this.autoClear = true;
+	this.sortObjects = true;
+	this.sortElements = true;
 
 
 	this.setSize = function ( width, height ) {
 	this.setSize = function ( width, height ) {
 
 
@@ -104,7 +107,7 @@ THREE.CanvasRenderer = function () {
 
 
 		this.autoClear && this.clear();
 		this.autoClear && this.clear();
 
 
-		_renderList = _projector.projectScene( scene, camera, true );
+		_renderList = _projector.projectScene( scene, camera, this.sortElements );
 
 
 		/* DEBUG
 		/* DEBUG
 		_context.fillStyle = 'rgba(0, 255, 255, 0.5)';
 		_context.fillStyle = 'rgba(0, 255, 255, 0.5)';

+ 4 - 1
src/renderers/SVGRenderer.js

@@ -29,7 +29,10 @@ THREE.SVGRenderer = function () {
 	_quality = 1;
 	_quality = 1;
 
 
 	this.domElement = _svg;
 	this.domElement = _svg;
+
 	this.autoClear = true;
 	this.autoClear = true;
+	this.sortObjects = true;
+	this.sortElements = true;
 
 
 	this.setQuality = function( quality ) {
 	this.setQuality = function( quality ) {
 
 
@@ -75,7 +78,7 @@ THREE.SVGRenderer = function () {
 
 
 		}
 		}
 
 
-		_renderList = _projector.projectScene( scene, camera, true );
+		_renderList = _projector.projectScene( scene, camera, this.sortElements );
 
 
 		_pathCount = 0; _circleCount = 0; _lineCount = 0;
 		_pathCount = 0; _circleCount = 0; _lineCount = 0;
 
 

+ 5 - 1
src/renderers/WebGLRenderer2.js

@@ -44,7 +44,9 @@ THREE.WebGLRenderer2 = function () {
 	_gl.clearColor( 0, 0, 0, 0 );
 	_gl.clearColor( 0, 0, 0, 0 );
 
 
 	this.domElement = _canvas;
 	this.domElement = _canvas;
+
 	this.autoClear = true;
 	this.autoClear = true;
+	this.sortObjects = true;
 
 
 	this.setSize = function ( width, height ) {
 	this.setSize = function ( width, height ) {
 
 
@@ -83,7 +85,7 @@ THREE.WebGLRenderer2 = function () {
 		}
 		}
 		*/
 		*/
 
 
-		_renderList = _projector.projectObjects( scene, camera, true );
+		_renderList = _projector.projectObjects( scene, camera, this.sortObjects );
 
 
 		for ( o = 0, ol = _renderList.length; o < ol; o++ ) {
 		for ( o = 0, ol = _renderList.length; o < ol; o++ ) {
 
 
@@ -468,6 +470,8 @@ THREE.WebGLRenderer2 = function () {
 
 
 					pfs += 'uniform sampler2D tMap;\n';
 					pfs += 'uniform sampler2D tMap;\n';
 					pfs += 'varying vec2 vUv;\n';
 					pfs += 'varying vec2 vUv;\n';
+					// fs += 'vec4 mapColor = texture2D( tMap, vUv );\n';
+					// fs += 'mapColor.xyz *= mapColor.w;\n';
 					fs += 'gl_FragColor *= texture2D( tMap, vUv );\n';
 					fs += 'gl_FragColor *= texture2D( tMap, vUv );\n';
 
 
 					identifiers.push( 'tMap' );
 					identifiers.push( 'tMap' );