THREE.RenderableObject=function(){this.id=0;this.object=null;this.z=0;this.renderOrder=0};THREE.RenderableFace=function(){this.id=0;this.v1=new THREE.RenderableVertex();this.v2=new THREE.RenderableVertex();this.v3=new THREE.RenderableVertex();this.normalModel=new THREE.Vector3();this.vertexNormalsModel=[new THREE.Vector3(),new THREE.Vector3(),new THREE.Vector3()];this.vertexNormalsLength=0;this.color=new THREE.Color();this.material=null;this.uvs=[new THREE.Vector2(),new THREE.Vector2(),new THREE.Vector2()];this.z=0;this.renderOrder=0};THREE.RenderableVertex=function(){this.position=new THREE.Vector3();this.positionWorld=new THREE.Vector3();this.positionScreen=new THREE.Vector4();this.visible=true};THREE.RenderableVertex.prototype.copy=function(a){this.positionWorld.copy(a.positionWorld);this.positionScreen.copy(a.positionScreen)};THREE.RenderableLine=function(){this.id=0;this.v1=new THREE.RenderableVertex();this.v2=new THREE.RenderableVertex();this.vertexColors=[new THREE.Color(),new THREE.Color()];this.material=null;this.z=0;this.renderOrder=0};THREE.RenderableSprite=function(){this.id=0;this.object=null;this.x=0;this.y=0;this.z=0;this.rotation=0;this.scale=new THREE.Vector2();this.material=null;this.renderOrder=0};THREE.Projector=function(){var S,F,M=[],o=0,x,c,f=[],b=0,m,C,I=[],z=0,i,O,Q=[],u=0,A,r,e=[],R=0,K={objects:[],lights:[],elements:[]},L=new THREE.Vector3(),J=new THREE.Vector4(),s=new THREE.Box3(new THREE.Vector3(-1,-1,-1),new THREE.Vector3(1,1,1)),T=new THREE.Box3(),N=new Array(3),a=new THREE.Matrix4(),g=new THREE.Matrix4(),B,E=new THREE.Matrix4(),p=new THREE.Matrix3(),P=new THREE.Frustum(),t=new THREE.Vector4(),h=new THREE.Vector4();this.projectVector=function(U,V){console.warn("THREE.Projector: .projectVector() is now vector.project().");U.project(V)};this.unprojectVector=function(U,V){console.warn("THREE.Projector: .unprojectVector() is now vector.unproject().");U.unproject(V)};this.pickingRay=function(){console.error("THREE.Projector: .pickingRay() is now raycaster.setFromCamera().")};var d=function(){var ah=[];var W=[];var ad=[];var ac=null;var af=null;var ab=new THREE.Matrix3();function Z(ak){ac=ak;af=ac.material;ab.getNormalMatrix(ac.matrixWorld);ah.length=0;W.length=0;ad.length=0}function ae(am){var ak=am.position;var an=am.positionWorld;var al=am.positionScreen;an.copy(ak).applyMatrix4(B);al.copy(an).applyMatrix4(g);var ao=1/al.w;al.x*=ao;al.y*=ao;al.z*=ao;am.visible=al.x>=-1&&al.x<=1&&al.y>=-1&&al.y<=1&&al.z>=-1&&al.z<=1}function V(ak,am,al){x=v();x.position.set(ak,am,al);ae(x)}function Y(ak,am,al){ah.push(ak,am,al)}function ai(am,al,ak){W.push(am,al,ak)}function X(ak,al){ad.push(ak,al)}function aa(am,al,ak){if(am.visible===true||al.visible===true||ak.visible===true){return true}N[0]=am.positionScreen;N[1]=al.positionScreen;N[2]=ak.positionScreen;return s.intersectsBox(T.setFromPoints(N))}function ag(am,al,ak){return((ak.positionScreen.x-am.positionScreen.x)*(al.positionScreen.y-am.positionScreen.y)-(ak.positionScreen.y-am.positionScreen.y)*(al.positionScreen.x-am.positionScreen.x))<0}function aj(al,ak){var an=f[al];var am=f[ak];an.positionScreen.copy(an.position).applyMatrix4(E);am.positionScreen.copy(am.position).applyMatrix4(E);if(y(an.positionScreen,am.positionScreen)===true){an.positionScreen.multiplyScalar(1/an.positionScreen.w);am.positionScreen.multiplyScalar(1/am.positionScreen.w);i=H();i.id=ac.id;i.v1.copy(an);i.v2.copy(am);i.z=Math.max(an.positionScreen.z,am.positionScreen.z);i.renderOrder=ac.renderOrder;i.material=ac.material;if(ac.material.vertexColors===THREE.VertexColors){i.vertexColors[0].fromArray(W,al*3);i.vertexColors[1].fromArray(W,ak*3)}K.elements.push(i)}}function U(ar,ap,an){var at=f[ar];var aq=f[ap];var ao=f[an];if(aa(at,aq,ao)===false){return}if(af.side===THREE.DoubleSide||ag(at,aq,ao)===true){m=l();m.id=ac.id;m.v1.copy(at);m.v2.copy(aq);m.v3.copy(ao);m.z=(at.positionScreen.z+aq.positionScreen.z+ao.positionScreen.z)/3;m.renderOrder=ac.renderOrder;m.normalModel.fromArray(ah,ar*3);m.normalModel.applyMatrix3(ab).normalize();for(var al=0;al<3;al++){var am=m.vertexNormalsModel[al];am.fromArray(ah,arguments[al]*3);am.applyMatrix3(ab).normalize();var ak=m.uvs[al];ak.fromArray(ad,arguments[al]*2)}m.vertexNormalsLength=3;m.material=ac.material;K.elements.push(m)}}return{setObject:Z,projectVertex:ae,checkTriangleVisibility:aa,checkBackfaceCulling:ag,pushVertex:V,pushNormal:Y,pushColor:ai,pushUv:X,pushLine:aj,pushTriangle:U}};var G=new d();function D(V){if(V.visible===false){return}if(V instanceof THREE.Light){K.lights.push(V)}else{if(V instanceof THREE.Mesh||V instanceof THREE.Line||V instanceof THREE.Points){if(V.material.visible===false){return}if(V.frustumCulled===true&&P.intersectsObject(V)===false){return}w(V)}else{if(V instanceof THREE.Sprite){if(V.material.visible===false){return}if(V.frustumCulled===true&&P.intersectsSprite(V)===false){return}w(V)}}}var X=V.children;for(var W=0,U=X.length;W<U;W++){D(X[W])}}function w(U){S=n();S.id=U.id;S.object=U;L.setFromMatrixPosition(U.matrixWorld);L.applyMatrix4(g);S.z=L.z;S.renderOrder=U.renderOrder;K.objects.push(S)}this.projectScene=function(aq,ai,at,Y){C=0;O=0;r=0;K.elements.length=0;if(aq.autoUpdate===true){aq.updateMatrixWorld()}if(ai.parent===null){ai.updateMatrixWorld()}a.copy(ai.matrixWorldInverse);g.multiplyMatrices(ai.projectionMatrix,a);P.setFromMatrix(g);F=0;K.objects.length=0;K.lights.length=0;D(aq);if(at===true){K.objects.sort(q)}var aF=K.objects;for(var aG=0,av=aF.length;aG<av;aG++){var aA=aF[aG].object;var ae=aA.geometry;G.setObject(aA);B=aA.matrixWorld;c=0;if(aA instanceof THREE.Mesh){if(ae instanceof THREE.BufferGeometry){var az=ae.attributes;var aa=ae.groups;if(az.position===undefined){continue}var ac=az.position.array;for(var aL=0,aJ=ac.length;aL<aJ;aL+=3){G.pushVertex(ac[aL],ac[aL+1],ac[aL+2])}if(az.normal!==undefined){var am=az.normal.array;for(var aL=0,aJ=am.length;aL<aJ;aL+=3){G.pushNormal(am[aL],am[aL+1],am[aL+2])}}if(az.uv!==undefined){var ay=az.uv.array;for(var aL=0,aJ=ay.length;aL<aJ;aL+=2){G.pushUv(ay[aL],ay[aL+1])}}if(ae.index!==null){var X=ae.index.array;if(aa.length>0){for(var aM=0;aM<aa.length;aM++){var al=aa[aM];for(var aL=al.start,aJ=al.start+al.count;aL<aJ;aL+=3){G.pushTriangle(X[aL],X[aL+1],X[aL+2])}}}else{for(var aL=0,aJ=X.length;aL<aJ;aL+=3){G.pushTriangle(X[aL],X[aL+1],X[aL+2])}}}else{for(var aL=0,aJ=ac.length/3;aL<aJ;aL+=3){G.pushTriangle(aL,aL+1,aL+2)}}}else{if(ae instanceof THREE.Geometry){var W=ae.vertices;var ad=ae.faces;var ax=ae.faceVertexUvs[0];p.getNormalMatrix(B);var aK=aA.material;var an=Array.isArray(aK);for(var aB=0,ah=W.length;aB<ah;aB++){var ak=W[aB];L.copy(ak);if(aK.morphTargets===true){var af=ae.morphTargets;var aI=aA.morphTargetInfluences;for(var aD=0,V=af.length;aD<V;aD++){var aw=aI[aD];if(aw===0){continue}var U=af[aD];var ap=U.vertices[aB];L.x+=(ap.x-ak.x)*aw;L.y+=(ap.y-ak.y)*aw;L.z+=(ap.z-ak.z)*aw}}G.pushVertex(L.x,L.y,L.z)}for(var aN=0,ar=ad.length;aN<ar;aN++){var ab=ad[aN];aK=an===true?aA.material[ab.materialIndex]:aA.material;if(aK===undefined){continue}var ag=aK.side;var aS=f[ab.a];var aQ=f[ab.b];var aO=f[ab.c];if(G.checkTriangleVisibility(aS,aQ,aO)===false){continue}var ao=G.checkBackfaceCulling(aS,aQ,aO);if(ag!==THREE.DoubleSide){if(ag===THREE.FrontSide&&ao===false){continue}if(ag===THREE.BackSide&&ao===true){continue}}m=l();m.id=aA.id;m.v1.copy(aS);m.v2.copy(aQ);m.v3.copy(aO);m.normalModel.copy(ab.normal);if(ao===false&&(ag===THREE.BackSide||ag===THREE.DoubleSide)){m.normalModel.negate()}m.normalModel.applyMatrix3(p).normalize();var Z=ab.vertexNormals;for(var aH=0,aP=Math.min(Z.length,3);aH<aP;aH++){var aR=m.vertexNormalsModel[aH];aR.copy(Z[aH]);if(ao===false&&(ag===THREE.BackSide||ag===THREE.DoubleSide)){aR.negate()}aR.applyMatrix3(p).normalize()}m.vertexNormalsLength=Z.length;var aj=ax[aN];if(aj!==undefined){for(var aC=0;aC<3;aC++){m.uvs[aC].copy(aj[aC])}}m.color=ab.color;m.material=aK;m.z=(aS.positionScreen.z+aQ.positionScreen.z+aO.positionScreen.z)/3;m.renderOrder=aA.renderOrder;K.elements.push(m)}}}}else{if(aA instanceof THREE.Line){E.multiplyMatrices(g,B);if(ae instanceof THREE.BufferGeometry){var az=ae.attributes;if(az.position!==undefined){var ac=az.position.array;for(var aL=0,aJ=ac.length;aL<aJ;aL+=3){G.pushVertex(ac[aL],ac[aL+1],ac[aL+2])}if(az.color!==undefined){var aE=az.color.array;for(var aL=0,aJ=aE.length;aL<aJ;aL+=3){G.pushColor(aE[aL],aE[aL+1],aE[aL+2])}}if(ae.index!==null){var X=ae.index.array;for(var aL=0,aJ=X.length;aL<aJ;aL+=2){G.pushLine(X[aL],X[aL+1])}}else{var au=aA instanceof THREE.LineSegments?2:1;for(var aL=0,aJ=(ac.length/3)-1;aL<aJ;aL+=au){G.pushLine(aL,aL+1)}}}}else{if(ae instanceof THREE.Geometry){var W=aA.geometry.vertices;if(W.length===0){continue}aS=v();aS.positionScreen.copy(W[0]).applyMatrix4(E);var au=aA instanceof THREE.LineSegments?2:1;for(var aB=1,ah=W.length;aB<ah;aB++){aS=v();aS.positionScreen.copy(W[aB]).applyMatrix4(E);if((aB+1)%au>0){continue}aQ=f[c-2];t.copy(aS.positionScreen);h.copy(aQ.positionScreen);if(y(t,h)===true){t.multiplyScalar(1/t.w);h.multiplyScalar(1/h.w);i=H();i.id=aA.id;i.v1.positionScreen.copy(t);i.v2.positionScreen.copy(h);i.z=Math.max(t.z,h.z);i.renderOrder=aA.renderOrder;i.material=aA.material;if(aA.material.vertexColors===THREE.VertexColors){i.vertexColors[0].copy(aA.geometry.colors[aB]);i.vertexColors[1].copy(aA.geometry.colors[aB-1])}K.elements.push(i)}}}}}else{if(aA instanceof THREE.Points){E.multiplyMatrices(g,B);if(ae instanceof THREE.Geometry){var W=aA.geometry.vertices;for(var aB=0,ah=W.length;aB<ah;aB++){var ak=W[aB];J.set(ak.x,ak.y,ak.z,1);J.applyMatrix4(E);j(J,aA,ai)}}else{if(ae instanceof THREE.BufferGeometry){var az=ae.attributes;if(az.position!==undefined){var ac=az.position.array;for(var aL=0,aJ=ac.length;aL<aJ;aL+=3){J.set(ac[aL],ac[aL+1],ac[aL+2],1);J.applyMatrix4(E);j(J,aA,ai)}}}}}else{if(aA instanceof THREE.Sprite){J.set(B.elements[12],B.elements[13],B.elements[14],1);J.applyMatrix4(g);j(J,aA,ai)}}}}}if(Y===true){K.elements.sort(q)}return K};function j(U,V,W){var X=1/U.w;U.z*=X;if(U.z>=-1&&U.z<=1){A=k();A.id=V.id;A.x=U.x*X;A.y=U.y*X;A.z=U.z;A.renderOrder=V.renderOrder;A.object=V;A.rotation=V.rotation;A.scale.x=V.scale.x*Math.abs(A.x-(U.x+W.projectionMatrix.elements[0])/(U.w+W.projectionMatrix.elements[12]));A.scale.y=V.scale.y*Math.abs(A.y-(U.y+W.projectionMatrix.elements[5])/(U.w+W.projectionMatrix.elements[13]));A.material=V.material;K.elements.push(A)}}function n(){if(F===o){var U=new THREE.RenderableObject();M.push(U);o++;F++;return U}return M[F++]}function v(){if(c===b){var U=new THREE.RenderableVertex();f.push(U);b++;c++;return U}return f[c++]}function l(){if(C===z){var U=new THREE.RenderableFace();I.push(U);z++;C++;return U}return I[C++]}function H(){if(O===u){var U=new THREE.RenderableLine();Q.push(U);u++;O++;return U}return Q[O++]}function k(){if(r===R){var U=new THREE.RenderableSprite();e.push(U);R++;r++;return U}return e[r++]}function q(V,U){if(V.renderOrder!==U.renderOrder){return V.renderOrder-U.renderOrder}else{if(V.z!==U.z){return U.z-V.z}else{if(V.id!==U.id){return V.id-U.id}else{return 0}}}}function y(Y,X){var W=0,ab=1,Z=Y.z+Y.w,V=X.z+X.w,U=-Y.z+Y.w,aa=-X.z+X.w;if(Z>=0&&V>=0&&U>=0&&aa>=0){return true}else{if((Z<0&&V<0)||(U<0&&aa<0)){return false}else{if(Z<0){W=Math.max(W,Z/(Z-V))}else{if(V<0){ab=Math.min(ab,Z/(Z-V))}}if(U<0){W=Math.max(W,U/(U-aa))}else{if(aa<0){ab=Math.min(ab,U/(U-aa))}}if(ab<W){return false}else{Y.lerp(X,W);X.lerp(Y,1-ab);return true}}}}};