提交 13e4f78a 编写于 作者: M Mr.doob

Reverting my thought

Actually, I think this can be handled magically instead of requiring understanding of the concept that the camera is part of the scenegraph.
While I was at it, I fixed it so you can use a camera for rendering different scenes (the renderer will add it and remove from each scene graph)	.
上级 d902ca3b
......@@ -99,11 +99,10 @@ This code creates a camera, then creates a scene, adds a cube on it, creates a &
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 1000;
scene.add( camera );
scene = new THREE.Scene();
geometry = new THREE.CubeGeometry( 200, 200, 200 );
material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );
......
......@@ -60,14 +60,14 @@ t,p,w=[],v,z=[],x,y,G=[],A,B,D=[],O={objects:[],sprites:[],lights:[],elements:[]
a.n23,a.n44+a.n24);M[3].set(a.n41-a.n21,a.n42-a.n22,a.n43-a.n23,a.n44-a.n24);M[4].set(a.n41-a.n31,a.n42-a.n32,a.n43-a.n33,a.n44-a.n34);M[5].set(a.n41+a.n31,a.n42+a.n32,a.n43+a.n33,a.n44+a.n34);for(a=0;a<6;a++){var b=M[a];b.divideScalar(Math.sqrt(b.x*b.x+b.y*b.y+b.z*b.z))}};this.projectVector=function(a,b){b.matrixWorldInverse.getInverse(b.matrixWorld);P.multiply(b.projectionMatrix,b.matrixWorldInverse);P.multiplyVector3(a);return a};this.unprojectVector=function(a,b){b.projectionMatrixInverse.getInverse(b.projectionMatrix);
P.multiply(b.matrixWorld,b.projectionMatrixInverse);P.multiplyVector3(a);return a};this.pickingRay=function(a,b){var c;a.z=-1;c=new THREE.Vector3(a.x,a.y,1);this.unprojectVector(a,b);this.unprojectVector(c,b);c.subSelf(a).normalize();return new THREE.Ray(a,c)};this.projectGraph=function(c,e){k=0;O.objects.length=0;O.sprites.length=0;O.lights.length=0;var f=function(b){if(b.visible!==!1){var c;if(c=b instanceof THREE.Mesh||b instanceof THREE.Line)if(!(c=b.frustumCulled===!1))a:{for(var e=b.matrixWorld,
k=-b.geometry.boundingSphere.radius*Math.max(b.scale.x,Math.max(b.scale.y,b.scale.z)),l=0;l<6;l++)if(c=M[l].x*e.n14+M[l].y*e.n24+M[l].z*e.n34+M[l].w,c<=k){c=!1;break a}c=!0}c?(P.multiplyVector3(I.copy(b.position)),h=a(),h.object=b,h.z=I.z,O.objects.push(h)):b instanceof THREE.Sprite||b instanceof THREE.Particle?(P.multiplyVector3(I.copy(b.position)),h=a(),h.object=b,h.z=I.z,O.sprites.push(h)):b instanceof THREE.Light&&O.lights.push(b);c=0;for(e=b.children.length;c<e;c++)f(b.children[c])}};f(c);e&&
O.objects.sort(b);return O};this.projectScene=function(a,k,h){var f=k.near,I=k.far,T,M,W,C,da,V,X,la,fa,Z,ja,aa,ia,ga,ha,na;B=y=v=p=0;O.elements.length=0;k.parent==null&&(console.warn("DEPRECATED: Camera hasn't been added to the Scene. Adding it..."),a.add(k));a.updateMatrixWorld();k.matrixWorldInverse.getInverse(k.matrixWorld);P.multiply(k.projectionMatrix,k.matrixWorldInverse);this.computeFrustum(P);O=this.projectGraph(a,!1);a=0;for(T=O.objects.length;a<T;a++)if(fa=O.objects[a].object,Z=fa.matrixWorld,
aa=fa.material,n=0,fa instanceof THREE.Mesh){ja=fa.geometry;ia=fa.geometry.materials;C=ja.vertices;ga=ja.faces;ha=ja.faceVertexUvs;ja=fa.matrixRotationWorld.extractRotation(Z);M=0;for(W=C.length;M<W;M++)l=c(),l.positionWorld.copy(C[M].position),Z.multiplyVector3(l.positionWorld),l.positionScreen.copy(l.positionWorld),P.multiplyVector4(l.positionScreen),l.positionScreen.x/=l.positionScreen.w,l.positionScreen.y/=l.positionScreen.w,l.visible=l.positionScreen.z>f&&l.positionScreen.z<I;C=0;for(M=ga.length;C<
M;C++){W=ga[C];if(W instanceof THREE.Face3)if(da=u[W.a],V=u[W.b],X=u[W.c],da.visible&&V.visible&&X.visible&&(fa.doubleSided||fa.flipSided!=(X.positionScreen.x-da.positionScreen.x)*(V.positionScreen.y-da.positionScreen.y)-(X.positionScreen.y-da.positionScreen.y)*(V.positionScreen.x-da.positionScreen.x)<0))la=w[p]=w[p]||new THREE.RenderableFace3,p++,t=la,t.v1.copy(da),t.v2.copy(V),t.v3.copy(X);else continue;else if(W instanceof THREE.Face4)if(da=u[W.a],V=u[W.b],X=u[W.c],la=u[W.d],da.visible&&V.visible&&
X.visible&&la.visible&&(fa.doubleSided||fa.flipSided!=((la.positionScreen.x-da.positionScreen.x)*(V.positionScreen.y-da.positionScreen.y)-(la.positionScreen.y-da.positionScreen.y)*(V.positionScreen.x-da.positionScreen.x)<0||(V.positionScreen.x-X.positionScreen.x)*(la.positionScreen.y-X.positionScreen.y)-(V.positionScreen.y-X.positionScreen.y)*(la.positionScreen.x-X.positionScreen.x)<0)))na=z[v]=z[v]||new THREE.RenderableFace4,v++,t=na,t.v1.copy(da),t.v2.copy(V),t.v3.copy(X),t.v4.copy(la);else continue;
t.normalWorld.copy(W.normal);ja.multiplyVector3(t.normalWorld);t.centroidWorld.copy(W.centroid);Z.multiplyVector3(t.centroidWorld);t.centroidScreen.copy(t.centroidWorld);P.multiplyVector3(t.centroidScreen);X=W.vertexNormals;da=0;for(V=X.length;da<V;da++)la=t.vertexNormalsWorld[da],la.copy(X[da]),ja.multiplyVector3(la);da=0;for(V=ha.length;da<V;da++)if(na=ha[da][C]){X=0;for(la=na.length;X<la;X++)t.uvs[da][X]=na[X]}t.material=aa;t.faceMaterial=W.materialIndex!==null?ia[W.materialIndex]:null;t.z=t.centroidScreen.z;
O.elements.push(t)}}else if(fa instanceof THREE.Line){Q.multiply(P,Z);C=fa.geometry.vertices;da=c();da.positionScreen.copy(C[0].position);Q.multiplyVector4(da.positionScreen);M=1;for(W=C.length;M<W;M++)if(da=c(),da.positionScreen.copy(C[M].position),Q.multiplyVector4(da.positionScreen),V=u[n-2],K.copy(da.positionScreen),N.copy(V.positionScreen),e(K,N))K.multiplyScalar(1/K.w),N.multiplyScalar(1/N.w),fa=G[y]=G[y]||new THREE.RenderableLine,y++,x=fa,x.v1.positionScreen.copy(K),x.v2.positionScreen.copy(N),
x.z=Math.max(K.z,N.z),x.material=aa,O.elements.push(x)}a=0;for(T=O.sprites.length;a<T;a++)if(fa=O.sprites[a].object,Z=fa.matrixWorld,fa instanceof THREE.Particle&&(H.set(Z.n14,Z.n24,Z.n34,1),P.multiplyVector4(H),H.z/=H.w,H.z>0&&H.z<1))f=D[B]=D[B]||new THREE.RenderableParticle,B++,A=f,A.x=H.x/H.w,A.y=H.y/H.w,A.z=H.z,A.rotation=fa.rotation.z,A.scale.x=fa.scale.x*Math.abs(A.x-(H.x+k.projectionMatrix.n11)/(H.w+k.projectionMatrix.n14)),A.scale.y=fa.scale.y*Math.abs(A.y-(H.y+k.projectionMatrix.n22)/(H.w+
k.projectionMatrix.n24)),A.material=fa.material,O.elements.push(A);h&&O.elements.sort(b);return O}};THREE.Quaternion=function(a,c,b,e){this.set(a||0,c||0,b||0,e!==void 0?e:1)};
O.objects.sort(b);return O};this.projectScene=function(a,k,h){var f=k.near,I=k.far,T,M,W,C,da,V,X,la,fa,Z,ja,aa,ia,ga,ha,na;B=y=v=p=0;O.elements.length=0;k.parent!==a&&a.add(k);a.updateMatrixWorld();k.matrixWorldInverse.getInverse(k.matrixWorld);P.multiply(k.projectionMatrix,k.matrixWorldInverse);this.computeFrustum(P);O=this.projectGraph(a,!1);a=0;for(T=O.objects.length;a<T;a++)if(fa=O.objects[a].object,Z=fa.matrixWorld,aa=fa.material,n=0,fa instanceof THREE.Mesh){ja=fa.geometry;ia=fa.geometry.materials;
C=ja.vertices;ga=ja.faces;ha=ja.faceVertexUvs;ja=fa.matrixRotationWorld.extractRotation(Z);M=0;for(W=C.length;M<W;M++)l=c(),l.positionWorld.copy(C[M].position),Z.multiplyVector3(l.positionWorld),l.positionScreen.copy(l.positionWorld),P.multiplyVector4(l.positionScreen),l.positionScreen.x/=l.positionScreen.w,l.positionScreen.y/=l.positionScreen.w,l.visible=l.positionScreen.z>f&&l.positionScreen.z<I;C=0;for(M=ga.length;C<M;C++){W=ga[C];if(W instanceof THREE.Face3)if(da=u[W.a],V=u[W.b],X=u[W.c],da.visible&&
V.visible&&X.visible&&(fa.doubleSided||fa.flipSided!=(X.positionScreen.x-da.positionScreen.x)*(V.positionScreen.y-da.positionScreen.y)-(X.positionScreen.y-da.positionScreen.y)*(V.positionScreen.x-da.positionScreen.x)<0))la=w[p]=w[p]||new THREE.RenderableFace3,p++,t=la,t.v1.copy(da),t.v2.copy(V),t.v3.copy(X);else continue;else if(W instanceof THREE.Face4)if(da=u[W.a],V=u[W.b],X=u[W.c],la=u[W.d],da.visible&&V.visible&&X.visible&&la.visible&&(fa.doubleSided||fa.flipSided!=((la.positionScreen.x-da.positionScreen.x)*
(V.positionScreen.y-da.positionScreen.y)-(la.positionScreen.y-da.positionScreen.y)*(V.positionScreen.x-da.positionScreen.x)<0||(V.positionScreen.x-X.positionScreen.x)*(la.positionScreen.y-X.positionScreen.y)-(V.positionScreen.y-X.positionScreen.y)*(la.positionScreen.x-X.positionScreen.x)<0)))na=z[v]=z[v]||new THREE.RenderableFace4,v++,t=na,t.v1.copy(da),t.v2.copy(V),t.v3.copy(X),t.v4.copy(la);else continue;t.normalWorld.copy(W.normal);ja.multiplyVector3(t.normalWorld);t.centroidWorld.copy(W.centroid);
Z.multiplyVector3(t.centroidWorld);t.centroidScreen.copy(t.centroidWorld);P.multiplyVector3(t.centroidScreen);X=W.vertexNormals;da=0;for(V=X.length;da<V;da++)la=t.vertexNormalsWorld[da],la.copy(X[da]),ja.multiplyVector3(la);da=0;for(V=ha.length;da<V;da++)if(na=ha[da][C]){X=0;for(la=na.length;X<la;X++)t.uvs[da][X]=na[X]}t.material=aa;t.faceMaterial=W.materialIndex!==null?ia[W.materialIndex]:null;t.z=t.centroidScreen.z;O.elements.push(t)}}else if(fa instanceof THREE.Line){Q.multiply(P,Z);C=fa.geometry.vertices;
da=c();da.positionScreen.copy(C[0].position);Q.multiplyVector4(da.positionScreen);M=1;for(W=C.length;M<W;M++)if(da=c(),da.positionScreen.copy(C[M].position),Q.multiplyVector4(da.positionScreen),V=u[n-2],K.copy(da.positionScreen),N.copy(V.positionScreen),e(K,N))K.multiplyScalar(1/K.w),N.multiplyScalar(1/N.w),fa=G[y]=G[y]||new THREE.RenderableLine,y++,x=fa,x.v1.positionScreen.copy(K),x.v2.positionScreen.copy(N),x.z=Math.max(K.z,N.z),x.material=aa,O.elements.push(x)}a=0;for(T=O.sprites.length;a<T;a++)if(fa=
O.sprites[a].object,Z=fa.matrixWorld,fa instanceof THREE.Particle&&(H.set(Z.n14,Z.n24,Z.n34,1),P.multiplyVector4(H),H.z/=H.w,H.z>0&&H.z<1))f=D[B]=D[B]||new THREE.RenderableParticle,B++,A=f,A.x=H.x/H.w,A.y=H.y/H.w,A.z=H.z,A.rotation=fa.rotation.z,A.scale.x=fa.scale.x*Math.abs(A.x-(H.x+k.projectionMatrix.n11)/(H.w+k.projectionMatrix.n14)),A.scale.y=fa.scale.y*Math.abs(A.y-(H.y+k.projectionMatrix.n22)/(H.w+k.projectionMatrix.n24)),A.material=fa.material,O.elements.push(A);h&&O.elements.sort(b);return O}};
THREE.Quaternion=function(a,c,b,e){this.set(a||0,c||0,b||0,e!==void 0?e:1)};
THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,c,b,e){this.x=a;this.y=c;this.z=b;this.w=e;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var c=Math.PI/360,b=a.x*c,e=a.y*c,h=a.z*c,a=Math.cos(e),e=Math.sin(e),c=Math.cos(-h),h=Math.sin(-h),k=Math.cos(b),b=Math.sin(b),f=a*c,l=e*h;this.w=f*k-l*b;this.x=f*b+l*k;this.y=e*c*k+a*h*b;this.z=a*h*k-e*c*b;return this},setFromAxisAngle:function(a,c){var b=c/2,e=Math.sin(b);
this.x=a.x*e;this.y=a.y*e;this.z=a.z*e;this.w=Math.cos(b);return this},setFromRotationMatrix:function(a){var c=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,c+a.n11+a.n22+a.n33))/2;this.x=Math.sqrt(Math.max(0,c+a.n11-a.n22-a.n33))/2;this.y=Math.sqrt(Math.max(0,c-a.n11+a.n22-a.n33))/2;this.z=Math.sqrt(Math.max(0,c-a.n11-a.n22+a.n33))/2;this.x=a.n32-a.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=a.n13-a.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.n21-a.n12<0?-Math.abs(this.z):Math.abs(this.z);
this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a===0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},multiplySelf:function(a){var c=
......@@ -296,8 +296,8 @@ h=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+c.ma
N("vertex",e+u));o.linkProgram(F);o.getProgramParameter(F,o.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+o.getProgramParameter(F,o.VALIDATE_STATUS)+", gl error ["+o.getError()+"]");F.uniforms={};F.attributes={};var w,e=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","cameraInverseMatrix","boneGlobalMatrices","morphTargetInfluences"];for(w in n)e.push(w);w=e;e=0;for(n=w.length;e<n;e++)v=w[e],F.uniforms[v]=o.getUniformLocation(F,
v);e=["position","normal","uv","uv2","tangent","color","skinVertexA","skinVertexB","skinIndex","skinWeight"];for(w=0;w<c.maxMorphTargets;w++)e.push("morphTarget"+w);for(x in b)e.push(x);x=e;w=0;for(b=x.length;w<b;w++)c=x[w],F.attributes[c]=o.getAttribLocation(F,c);F.id=$.length;$.push({program:F,code:l});S.info.memory.programs=$.length;x=F}a.program=x;x=a.program.attributes;x.position>=0&&o.enableVertexAttribArray(x.position);x.color>=0&&o.enableVertexAttribArray(x.color);x.normal>=0&&o.enableVertexAttribArray(x.normal);
x.tangent>=0&&o.enableVertexAttribArray(x.tangent);a.skinning&&x.skinVertexA>=0&&x.skinVertexB>=0&&x.skinIndex>=0&&x.skinWeight>=0&&(o.enableVertexAttribArray(x.skinVertexA),o.enableVertexAttribArray(x.skinVertexB),o.enableVertexAttribArray(x.skinIndex),o.enableVertexAttribArray(x.skinWeight));if(a.attributes)for(f in a.attributes)x[f]!==void 0&&x[f]>=0&&o.enableVertexAttribArray(x[f]);if(a.morphTargets)for(f=a.numSupportedMorphTargets=0;f<this.maxMorphTargets;f++)w="morphTarget"+f,x[w]>=0&&(o.enableVertexAttribArray(x[w]),
a.numSupportedMorphTargets++);a.uniformsList=[];for(k in a.uniforms)a.uniformsList.push([a.uniforms[k],k])};this.clearTarget=function(a,b,c,e){M(a);this.clear(b,c,e)};this.updateShadowMap=function(a,b){x(a,b)};this.render=function(a,b,c,F){var ka,ca,A,B,D,J,ga,ra=a.lights,Q=a.fog;W=-1;this.autoUpdateObjects&&this.initWebGLObjects(a);this.shadowMapEnabled&&this.shadowMapAutoUpdate&&x(a,b);S.info.render.calls=0;S.info.render.vertices=0;S.info.render.faces=0;b.parent==null&&(console.warn("Camera is not on the Scene. Adding it..."),
a.add(b));this.autoUpdateScene&&a.updateMatrixWorld();b.matrixWorldInverse.getInverse(b.matrixWorld);b.matrixWorldInverse.flattenToArray(Da);b.projectionMatrix.flattenToArray(va);sa.multiply(b.projectionMatrix,b.matrixWorldInverse);t(sa);M(c);(this.autoClear||F)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);A=a.__webglObjects.length;for(F=0;F<A;F++)if(D=a.__webglObjects[F],J=D.object,J.visible)if(!(J instanceof THREE.Mesh)||!J.frustumCulled||p(J)){if(J.matrixWorld.flattenToArray(J._objectMatrixArray),
a.numSupportedMorphTargets++);a.uniformsList=[];for(k in a.uniforms)a.uniformsList.push([a.uniforms[k],k])};this.clearTarget=function(a,b,c,e){M(a);this.clear(b,c,e)};this.updateShadowMap=function(a,b){x(a,b)};this.render=function(a,b,c,F){var ka,ca,A,B,D,J,ga,ra=a.lights,Q=a.fog;W=-1;this.autoUpdateObjects&&this.initWebGLObjects(a);this.shadowMapEnabled&&this.shadowMapAutoUpdate&&x(a,b);S.info.render.calls=0;S.info.render.vertices=0;S.info.render.faces=0;b.parent!==a&&a.add(b);this.autoUpdateScene&&
a.updateMatrixWorld();b.matrixWorldInverse.getInverse(b.matrixWorld);b.matrixWorldInverse.flattenToArray(Da);b.projectionMatrix.flattenToArray(va);sa.multiply(b.projectionMatrix,b.matrixWorldInverse);t(sa);M(c);(this.autoClear||F)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);A=a.__webglObjects.length;for(F=0;F<A;F++)if(D=a.__webglObjects[F],J=D.object,J.visible)if(!(J instanceof THREE.Mesh)||!J.frustumCulled||p(J)){if(J.matrixWorld.flattenToArray(J._objectMatrixArray),
G(J,b,!0),v(D),D.render=!0,this.sortObjects)J.renderDepth?D.z=J.renderDepth:(Ba.copy(J.position),sa.multiplyVector3(Ba),D.z=Ba.z)}else D.render=!1;else D.render=!1;this.sortObjects&&a.__webglObjects.sort(z);B=a.__webglObjectsImmediate.length;for(F=0;F<B;F++)D=a.__webglObjectsImmediate[F],J=D.object,J.visible&&(J.matrixAutoUpdate&&J.matrixWorld.flattenToArray(J._objectMatrixArray),G(J,b,!0),w(D));if(a.overrideMaterial){l(a.overrideMaterial.depthTest);I(a.overrideMaterial.blending);for(F=0;F<A;F++)if(D=
a.__webglObjects[F],D.render)J=D.object,ga=D.buffer,f(J),h(b,ra,Q,a.overrideMaterial,ga,J);for(F=0;F<B;F++)D=a.__webglObjectsImmediate[F],J=D.object,J.visible&&(C=-1,f(J),ka=e(b,ra,Q,a.overrideMaterial,J),J.immediateRenderCallback?J.immediateRenderCallback(ka,o,pa):J.render(function(b){k(b,ka,a.overrideMaterial.shading)}))}else{I(THREE.NormalBlending);for(F=A-1;F>=0;F--)if(D=a.__webglObjects[F],D.render&&(J=D.object,ga=D.buffer,ca=D.opaque))f(J),l(ca.depthTest),n(ca.depthWrite),u(ca.polygonOffset,
ca.polygonOffsetFactor,ca.polygonOffsetUnits),h(b,ra,Q,ca,ga,J);for(F=0;F<B;F++)if(D=a.__webglObjectsImmediate[F],J=D.object,J.visible&&(C=-1,ca=D.opaque))f(J),l(ca.depthTest),n(ca.depthWrite),u(ca.polygonOffset,ca.polygonOffsetFactor,ca.polygonOffsetUnits),ka=e(b,ra,Q,ca,J),J.immediateRenderCallback?J.immediateRenderCallback(ka,o,pa):J.render(function(a){k(a,ka,ca.shading)});for(F=0;F<A;F++)if(D=a.__webglObjects[F],D.render&&(J=D.object,ga=D.buffer,ca=D.transparent))f(J),I(ca.blending),l(ca.depthTest),
......
......@@ -59,14 +59,13 @@ i,n,m=[],j,q=[],k,s,N=[],F,S,P=[],z={objects:[],sprites:[],lights:[],elements:[]
a.n23,a.n44+a.n24);r[3].set(a.n41-a.n21,a.n42-a.n22,a.n43-a.n23,a.n44-a.n24);r[4].set(a.n41-a.n31,a.n42-a.n32,a.n43-a.n33,a.n44-a.n34);r[5].set(a.n41+a.n31,a.n42+a.n32,a.n43+a.n33,a.n44+a.n34);for(a=0;a<6;a++){var b=r[a];b.divideScalar(Math.sqrt(b.x*b.x+b.y*b.y+b.z*b.z))}};this.projectVector=function(a,b){b.matrixWorldInverse.getInverse(b.matrixWorld);E.multiply(b.projectionMatrix,b.matrixWorldInverse);E.multiplyVector3(a);return a};this.unprojectVector=function(a,b){b.projectionMatrixInverse.getInverse(b.projectionMatrix);
E.multiply(b.matrixWorld,b.projectionMatrixInverse);E.multiplyVector3(a);return a};this.pickingRay=function(a,b){var c;a.z=-1;c=new THREE.Vector3(a.x,a.y,1);this.unprojectVector(a,b);this.unprojectVector(c,b);c.subSelf(a).normalize();return new THREE.Ray(a,c)};this.projectGraph=function(b,d){e=0;z.objects.length=0;z.sprites.length=0;z.lights.length=0;var g=function(b){if(b.visible!==!1){var c;if(c=b instanceof THREE.Mesh||b instanceof THREE.Line)if(!(c=b.frustumCulled===!1))a:{for(var d=b.matrixWorld,
e=-b.geometry.boundingSphere.radius*Math.max(b.scale.x,Math.max(b.scale.y,b.scale.z)),h=0;h<6;h++)if(c=r[h].x*d.n14+r[h].y*d.n24+r[h].z*d.n34+r[h].w,c<=e){c=!1;break a}c=!0}c?(E.multiplyVector3(A.copy(b.position)),f=a(),f.object=b,f.z=A.z,z.objects.push(f)):b instanceof THREE.Sprite||b instanceof THREE.Particle?(E.multiplyVector3(A.copy(b.position)),f=a(),f.object=b,f.z=A.z,z.sprites.push(f)):b instanceof THREE.Light&&z.lights.push(b);c=0;for(d=b.children.length;c<d;c++)g(b.children[c])}};g(b);d&&
z.objects.sort(c);return z};this.projectScene=function(a,e,f){var g=e.near,r=e.far,U,H,B,Q,v,M,K,A,G,t,y,w,x,I,ja,Z;S=s=j=n=0;z.elements.length=0;e.parent==null&&(console.warn("DEPRECATED: Camera hasn't been added to the Scene. Adding it..."),a.add(e));a.updateMatrixWorld();e.matrixWorldInverse.getInverse(e.matrixWorld);E.multiply(e.projectionMatrix,e.matrixWorldInverse);this.computeFrustum(E);z=this.projectGraph(a,!1);a=0;for(U=z.objects.length;a<U;a++)if(G=z.objects[a].object,t=G.matrixWorld,w=
G.material,l=0,G instanceof THREE.Mesh){y=G.geometry;x=G.geometry.materials;Q=y.vertices;I=y.faces;ja=y.faceVertexUvs;y=G.matrixRotationWorld.extractRotation(t);H=0;for(B=Q.length;H<B;H++)h=b(),h.positionWorld.copy(Q[H].position),t.multiplyVector3(h.positionWorld),h.positionScreen.copy(h.positionWorld),E.multiplyVector4(h.positionScreen),h.positionScreen.x/=h.positionScreen.w,h.positionScreen.y/=h.positionScreen.w,h.visible=h.positionScreen.z>g&&h.positionScreen.z<r;Q=0;for(H=I.length;Q<H;Q++){B=
I[Q];if(B instanceof THREE.Face3)if(v=o[B.a],M=o[B.b],K=o[B.c],v.visible&&M.visible&&K.visible&&(G.doubleSided||G.flipSided!=(K.positionScreen.x-v.positionScreen.x)*(M.positionScreen.y-v.positionScreen.y)-(K.positionScreen.y-v.positionScreen.y)*(M.positionScreen.x-v.positionScreen.x)<0))A=m[n]=m[n]||new THREE.RenderableFace3,n++,i=A,i.v1.copy(v),i.v2.copy(M),i.v3.copy(K);else continue;else if(B instanceof THREE.Face4)if(v=o[B.a],M=o[B.b],K=o[B.c],A=o[B.d],v.visible&&M.visible&&K.visible&&A.visible&&
(G.doubleSided||G.flipSided!=((A.positionScreen.x-v.positionScreen.x)*(M.positionScreen.y-v.positionScreen.y)-(A.positionScreen.y-v.positionScreen.y)*(M.positionScreen.x-v.positionScreen.x)<0||(M.positionScreen.x-K.positionScreen.x)*(A.positionScreen.y-K.positionScreen.y)-(M.positionScreen.y-K.positionScreen.y)*(A.positionScreen.x-K.positionScreen.x)<0)))Z=q[j]=q[j]||new THREE.RenderableFace4,j++,i=Z,i.v1.copy(v),i.v2.copy(M),i.v3.copy(K),i.v4.copy(A);else continue;i.normalWorld.copy(B.normal);y.multiplyVector3(i.normalWorld);
i.centroidWorld.copy(B.centroid);t.multiplyVector3(i.centroidWorld);i.centroidScreen.copy(i.centroidWorld);E.multiplyVector3(i.centroidScreen);K=B.vertexNormals;v=0;for(M=K.length;v<M;v++)A=i.vertexNormalsWorld[v],A.copy(K[v]),y.multiplyVector3(A);v=0;for(M=ja.length;v<M;v++)if(Z=ja[v][Q]){K=0;for(A=Z.length;K<A;K++)i.uvs[v][K]=Z[K]}i.material=w;i.faceMaterial=B.materialIndex!==null?x[B.materialIndex]:null;i.z=i.centroidScreen.z;z.elements.push(i)}}else if(G instanceof THREE.Line){u.multiply(E,t);
Q=G.geometry.vertices;v=b();v.positionScreen.copy(Q[0].position);u.multiplyVector4(v.positionScreen);H=1;for(B=Q.length;H<B;H++)if(v=b(),v.positionScreen.copy(Q[H].position),u.multiplyVector4(v.positionScreen),M=o[l-2],D.copy(v.positionScreen),J.copy(M.positionScreen),d(D,J))D.multiplyScalar(1/D.w),J.multiplyScalar(1/J.w),G=N[s]=N[s]||new THREE.RenderableLine,s++,k=G,k.v1.positionScreen.copy(D),k.v2.positionScreen.copy(J),k.z=Math.max(D.z,J.z),k.material=w,z.elements.push(k)}a=0;for(U=z.sprites.length;a<
U;a++)if(G=z.sprites[a].object,t=G.matrixWorld,G instanceof THREE.Particle&&(C.set(t.n14,t.n24,t.n34,1),E.multiplyVector4(C),C.z/=C.w,C.z>0&&C.z<1))g=P[S]=P[S]||new THREE.RenderableParticle,S++,F=g,F.x=C.x/C.w,F.y=C.y/C.w,F.z=C.z,F.rotation=G.rotation.z,F.scale.x=G.scale.x*Math.abs(F.x-(C.x+e.projectionMatrix.n11)/(C.w+e.projectionMatrix.n14)),F.scale.y=G.scale.y*Math.abs(F.y-(C.y+e.projectionMatrix.n22)/(C.w+e.projectionMatrix.n24)),F.material=G.material,z.elements.push(F);f&&z.elements.sort(c);
return z}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
z.objects.sort(c);return z};this.projectScene=function(a,e,f){var g=e.near,r=e.far,U,H,B,Q,v,M,K,A,G,t,y,w,x,I,ja,Z;S=s=j=n=0;z.elements.length=0;e.parent!==a&&a.add(e);a.updateMatrixWorld();e.matrixWorldInverse.getInverse(e.matrixWorld);E.multiply(e.projectionMatrix,e.matrixWorldInverse);this.computeFrustum(E);z=this.projectGraph(a,!1);a=0;for(U=z.objects.length;a<U;a++)if(G=z.objects[a].object,t=G.matrixWorld,w=G.material,l=0,G instanceof THREE.Mesh){y=G.geometry;x=G.geometry.materials;Q=y.vertices;
I=y.faces;ja=y.faceVertexUvs;y=G.matrixRotationWorld.extractRotation(t);H=0;for(B=Q.length;H<B;H++)h=b(),h.positionWorld.copy(Q[H].position),t.multiplyVector3(h.positionWorld),h.positionScreen.copy(h.positionWorld),E.multiplyVector4(h.positionScreen),h.positionScreen.x/=h.positionScreen.w,h.positionScreen.y/=h.positionScreen.w,h.visible=h.positionScreen.z>g&&h.positionScreen.z<r;Q=0;for(H=I.length;Q<H;Q++){B=I[Q];if(B instanceof THREE.Face3)if(v=o[B.a],M=o[B.b],K=o[B.c],v.visible&&M.visible&&K.visible&&
(G.doubleSided||G.flipSided!=(K.positionScreen.x-v.positionScreen.x)*(M.positionScreen.y-v.positionScreen.y)-(K.positionScreen.y-v.positionScreen.y)*(M.positionScreen.x-v.positionScreen.x)<0))A=m[n]=m[n]||new THREE.RenderableFace3,n++,i=A,i.v1.copy(v),i.v2.copy(M),i.v3.copy(K);else continue;else if(B instanceof THREE.Face4)if(v=o[B.a],M=o[B.b],K=o[B.c],A=o[B.d],v.visible&&M.visible&&K.visible&&A.visible&&(G.doubleSided||G.flipSided!=((A.positionScreen.x-v.positionScreen.x)*(M.positionScreen.y-v.positionScreen.y)-
(A.positionScreen.y-v.positionScreen.y)*(M.positionScreen.x-v.positionScreen.x)<0||(M.positionScreen.x-K.positionScreen.x)*(A.positionScreen.y-K.positionScreen.y)-(M.positionScreen.y-K.positionScreen.y)*(A.positionScreen.x-K.positionScreen.x)<0)))Z=q[j]=q[j]||new THREE.RenderableFace4,j++,i=Z,i.v1.copy(v),i.v2.copy(M),i.v3.copy(K),i.v4.copy(A);else continue;i.normalWorld.copy(B.normal);y.multiplyVector3(i.normalWorld);i.centroidWorld.copy(B.centroid);t.multiplyVector3(i.centroidWorld);i.centroidScreen.copy(i.centroidWorld);
E.multiplyVector3(i.centroidScreen);K=B.vertexNormals;v=0;for(M=K.length;v<M;v++)A=i.vertexNormalsWorld[v],A.copy(K[v]),y.multiplyVector3(A);v=0;for(M=ja.length;v<M;v++)if(Z=ja[v][Q]){K=0;for(A=Z.length;K<A;K++)i.uvs[v][K]=Z[K]}i.material=w;i.faceMaterial=B.materialIndex!==null?x[B.materialIndex]:null;i.z=i.centroidScreen.z;z.elements.push(i)}}else if(G instanceof THREE.Line){u.multiply(E,t);Q=G.geometry.vertices;v=b();v.positionScreen.copy(Q[0].position);u.multiplyVector4(v.positionScreen);H=1;for(B=
Q.length;H<B;H++)if(v=b(),v.positionScreen.copy(Q[H].position),u.multiplyVector4(v.positionScreen),M=o[l-2],D.copy(v.positionScreen),J.copy(M.positionScreen),d(D,J))D.multiplyScalar(1/D.w),J.multiplyScalar(1/J.w),G=N[s]=N[s]||new THREE.RenderableLine,s++,k=G,k.v1.positionScreen.copy(D),k.v2.positionScreen.copy(J),k.z=Math.max(D.z,J.z),k.material=w,z.elements.push(k)}a=0;for(U=z.sprites.length;a<U;a++)if(G=z.sprites[a].object,t=G.matrixWorld,G instanceof THREE.Particle&&(C.set(t.n14,t.n24,t.n34,1),
E.multiplyVector4(C),C.z/=C.w,C.z>0&&C.z<1))g=P[S]=P[S]||new THREE.RenderableParticle,S++,F=g,F.x=C.x/C.w,F.y=C.y/C.w,F.z=C.z,F.rotation=G.rotation.z,F.scale.x=G.scale.x*Math.abs(F.x-(C.x+e.projectionMatrix.n11)/(C.w+e.projectionMatrix.n14)),F.scale.y=G.scale.y*Math.abs(F.y-(C.y+e.projectionMatrix.n22)/(C.w+e.projectionMatrix.n24)),F.material=G.material,z.elements.push(F);f&&z.elements.sort(c);return z}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=Math.PI/360,c=a.x*b,d=a.y*b,f=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-f),f=Math.sin(-f),e=Math.cos(c),c=Math.sin(c),g=a*b,h=d*f;this.w=g*e-h*c;this.x=g*c+h*e;this.y=d*b*e+a*f*c;this.z=a*f*e-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c);
this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.n11+a.n22+a.n33))/2;this.x=Math.sqrt(Math.max(0,b+a.n11-a.n22-a.n33))/2;this.y=Math.sqrt(Math.max(0,b-a.n11+a.n22-a.n33))/2;this.z=Math.sqrt(Math.max(0,b-a.n11-a.n22+a.n33))/2;this.x=a.n32-a.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=a.n13-a.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.n21-a.n12<0?-Math.abs(this.z):Math.abs(this.z);
this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a===0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},multiplySelf:function(a){var b=
......
......@@ -59,14 +59,13 @@ i,l,n=[],m,p=[],o,q,K=[],A,H,L=[],s={objects:[],sprites:[],lights:[],elements:[]
a.n23,a.n44+a.n24);x[3].set(a.n41-a.n21,a.n42-a.n22,a.n43-a.n23,a.n44-a.n24);x[4].set(a.n41-a.n31,a.n42-a.n32,a.n43-a.n33,a.n44-a.n34);x[5].set(a.n41+a.n31,a.n42+a.n32,a.n43+a.n33,a.n44+a.n34);for(a=0;a<6;a++){var b=x[a];b.divideScalar(Math.sqrt(b.x*b.x+b.y*b.y+b.z*b.z))}};this.projectVector=function(a,b){b.matrixWorldInverse.getInverse(b.matrixWorld);z.multiply(b.projectionMatrix,b.matrixWorldInverse);z.multiplyVector3(a);return a};this.unprojectVector=function(a,b){b.projectionMatrixInverse.getInverse(b.projectionMatrix);
z.multiply(b.matrixWorld,b.projectionMatrixInverse);z.multiplyVector3(a);return a};this.pickingRay=function(a,b){var c;a.z=-1;c=new THREE.Vector3(a.x,a.y,1);this.unprojectVector(a,b);this.unprojectVector(c,b);c.subSelf(a).normalize();return new THREE.Ray(a,c)};this.projectGraph=function(b,d){f=0;s.objects.length=0;s.sprites.length=0;s.lights.length=0;var g=function(b){if(b.visible!==!1){var c;if(c=b instanceof THREE.Mesh||b instanceof THREE.Line)if(!(c=b.frustumCulled===!1))a:{for(var d=b.matrixWorld,
f=-b.geometry.boundingSphere.radius*Math.max(b.scale.x,Math.max(b.scale.y,b.scale.z)),h=0;h<6;h++)if(c=x[h].x*d.n14+x[h].y*d.n24+x[h].z*d.n34+x[h].w,c<=f){c=!1;break a}c=!0}c?(z.multiplyVector3(B.copy(b.position)),e=a(),e.object=b,e.z=B.z,s.objects.push(e)):b instanceof THREE.Sprite||b instanceof THREE.Particle?(z.multiplyVector3(B.copy(b.position)),e=a(),e.object=b,e.z=B.z,s.sprites.push(e)):b instanceof THREE.Light&&s.lights.push(b);c=0;for(d=b.children.length;c<d;c++)g(b.children[c])}};g(b);d&&
s.objects.sort(c);return s};this.projectScene=function(a,e,f){var g=e.near,x=e.far,B,G,w,D,r,y,v,C,t,I,M,T,W,U,V,N;H=q=m=l=0;s.elements.length=0;e.parent==null&&(console.warn("DEPRECATED: Camera hasn't been added to the Scene. Adding it..."),a.add(e));a.updateMatrixWorld();e.matrixWorldInverse.getInverse(e.matrixWorld);z.multiply(e.projectionMatrix,e.matrixWorldInverse);this.computeFrustum(z);s=this.projectGraph(a,!1);a=0;for(B=s.objects.length;a<B;a++)if(t=s.objects[a].object,I=t.matrixWorld,T=t.material,
j=0,t instanceof THREE.Mesh){M=t.geometry;W=t.geometry.materials;D=M.vertices;U=M.faces;V=M.faceVertexUvs;M=t.matrixRotationWorld.extractRotation(I);G=0;for(w=D.length;G<w;G++)h=b(),h.positionWorld.copy(D[G].position),I.multiplyVector3(h.positionWorld),h.positionScreen.copy(h.positionWorld),z.multiplyVector4(h.positionScreen),h.positionScreen.x/=h.positionScreen.w,h.positionScreen.y/=h.positionScreen.w,h.visible=h.positionScreen.z>g&&h.positionScreen.z<x;D=0;for(G=U.length;D<G;D++){w=U[D];if(w instanceof
THREE.Face3)if(r=k[w.a],y=k[w.b],v=k[w.c],r.visible&&y.visible&&v.visible&&(t.doubleSided||t.flipSided!=(v.positionScreen.x-r.positionScreen.x)*(y.positionScreen.y-r.positionScreen.y)-(v.positionScreen.y-r.positionScreen.y)*(y.positionScreen.x-r.positionScreen.x)<0))C=n[l]=n[l]||new THREE.RenderableFace3,l++,i=C,i.v1.copy(r),i.v2.copy(y),i.v3.copy(v);else continue;else if(w instanceof THREE.Face4)if(r=k[w.a],y=k[w.b],v=k[w.c],C=k[w.d],r.visible&&y.visible&&v.visible&&C.visible&&(t.doubleSided||t.flipSided!=
((C.positionScreen.x-r.positionScreen.x)*(y.positionScreen.y-r.positionScreen.y)-(C.positionScreen.y-r.positionScreen.y)*(y.positionScreen.x-r.positionScreen.x)<0||(y.positionScreen.x-v.positionScreen.x)*(C.positionScreen.y-v.positionScreen.y)-(y.positionScreen.y-v.positionScreen.y)*(C.positionScreen.x-v.positionScreen.x)<0)))N=p[m]=p[m]||new THREE.RenderableFace4,m++,i=N,i.v1.copy(r),i.v2.copy(y),i.v3.copy(v),i.v4.copy(C);else continue;i.normalWorld.copy(w.normal);M.multiplyVector3(i.normalWorld);
i.centroidWorld.copy(w.centroid);I.multiplyVector3(i.centroidWorld);i.centroidScreen.copy(i.centroidWorld);z.multiplyVector3(i.centroidScreen);v=w.vertexNormals;r=0;for(y=v.length;r<y;r++)C=i.vertexNormalsWorld[r],C.copy(v[r]),M.multiplyVector3(C);r=0;for(y=V.length;r<y;r++)if(N=V[r][D]){v=0;for(C=N.length;v<C;v++)i.uvs[r][v]=N[v]}i.material=T;i.faceMaterial=w.materialIndex!==null?W[w.materialIndex]:null;i.z=i.centroidScreen.z;s.elements.push(i)}}else if(t instanceof THREE.Line){J.multiply(z,I);D=
t.geometry.vertices;r=b();r.positionScreen.copy(D[0].position);J.multiplyVector4(r.positionScreen);G=1;for(w=D.length;G<w;G++)if(r=b(),r.positionScreen.copy(D[G].position),J.multiplyVector4(r.positionScreen),y=k[j-2],E.copy(r.positionScreen),F.copy(y.positionScreen),d(E,F))E.multiplyScalar(1/E.w),F.multiplyScalar(1/F.w),t=K[q]=K[q]||new THREE.RenderableLine,q++,o=t,o.v1.positionScreen.copy(E),o.v2.positionScreen.copy(F),o.z=Math.max(E.z,F.z),o.material=T,s.elements.push(o)}a=0;for(B=s.sprites.length;a<
B;a++)if(t=s.sprites[a].object,I=t.matrixWorld,t instanceof THREE.Particle&&(u.set(I.n14,I.n24,I.n34,1),z.multiplyVector4(u),u.z/=u.w,u.z>0&&u.z<1))g=L[H]=L[H]||new THREE.RenderableParticle,H++,A=g,A.x=u.x/u.w,A.y=u.y/u.w,A.z=u.z,A.rotation=t.rotation.z,A.scale.x=t.scale.x*Math.abs(A.x-(u.x+e.projectionMatrix.n11)/(u.w+e.projectionMatrix.n14)),A.scale.y=t.scale.y*Math.abs(A.y-(u.y+e.projectionMatrix.n22)/(u.w+e.projectionMatrix.n24)),A.material=t.material,s.elements.push(A);f&&s.elements.sort(c);
return s}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
s.objects.sort(c);return s};this.projectScene=function(a,e,f){var g=e.near,x=e.far,B,G,w,D,r,y,v,C,t,I,M,T,W,U,V,N;H=q=m=l=0;s.elements.length=0;e.parent!==a&&a.add(e);a.updateMatrixWorld();e.matrixWorldInverse.getInverse(e.matrixWorld);z.multiply(e.projectionMatrix,e.matrixWorldInverse);this.computeFrustum(z);s=this.projectGraph(a,!1);a=0;for(B=s.objects.length;a<B;a++)if(t=s.objects[a].object,I=t.matrixWorld,T=t.material,j=0,t instanceof THREE.Mesh){M=t.geometry;W=t.geometry.materials;D=M.vertices;
U=M.faces;V=M.faceVertexUvs;M=t.matrixRotationWorld.extractRotation(I);G=0;for(w=D.length;G<w;G++)h=b(),h.positionWorld.copy(D[G].position),I.multiplyVector3(h.positionWorld),h.positionScreen.copy(h.positionWorld),z.multiplyVector4(h.positionScreen),h.positionScreen.x/=h.positionScreen.w,h.positionScreen.y/=h.positionScreen.w,h.visible=h.positionScreen.z>g&&h.positionScreen.z<x;D=0;for(G=U.length;D<G;D++){w=U[D];if(w instanceof THREE.Face3)if(r=k[w.a],y=k[w.b],v=k[w.c],r.visible&&y.visible&&v.visible&&
(t.doubleSided||t.flipSided!=(v.positionScreen.x-r.positionScreen.x)*(y.positionScreen.y-r.positionScreen.y)-(v.positionScreen.y-r.positionScreen.y)*(y.positionScreen.x-r.positionScreen.x)<0))C=n[l]=n[l]||new THREE.RenderableFace3,l++,i=C,i.v1.copy(r),i.v2.copy(y),i.v3.copy(v);else continue;else if(w instanceof THREE.Face4)if(r=k[w.a],y=k[w.b],v=k[w.c],C=k[w.d],r.visible&&y.visible&&v.visible&&C.visible&&(t.doubleSided||t.flipSided!=((C.positionScreen.x-r.positionScreen.x)*(y.positionScreen.y-r.positionScreen.y)-
(C.positionScreen.y-r.positionScreen.y)*(y.positionScreen.x-r.positionScreen.x)<0||(y.positionScreen.x-v.positionScreen.x)*(C.positionScreen.y-v.positionScreen.y)-(y.positionScreen.y-v.positionScreen.y)*(C.positionScreen.x-v.positionScreen.x)<0)))N=p[m]=p[m]||new THREE.RenderableFace4,m++,i=N,i.v1.copy(r),i.v2.copy(y),i.v3.copy(v),i.v4.copy(C);else continue;i.normalWorld.copy(w.normal);M.multiplyVector3(i.normalWorld);i.centroidWorld.copy(w.centroid);I.multiplyVector3(i.centroidWorld);i.centroidScreen.copy(i.centroidWorld);
z.multiplyVector3(i.centroidScreen);v=w.vertexNormals;r=0;for(y=v.length;r<y;r++)C=i.vertexNormalsWorld[r],C.copy(v[r]),M.multiplyVector3(C);r=0;for(y=V.length;r<y;r++)if(N=V[r][D]){v=0;for(C=N.length;v<C;v++)i.uvs[r][v]=N[v]}i.material=T;i.faceMaterial=w.materialIndex!==null?W[w.materialIndex]:null;i.z=i.centroidScreen.z;s.elements.push(i)}}else if(t instanceof THREE.Line){J.multiply(z,I);D=t.geometry.vertices;r=b();r.positionScreen.copy(D[0].position);J.multiplyVector4(r.positionScreen);G=1;for(w=
D.length;G<w;G++)if(r=b(),r.positionScreen.copy(D[G].position),J.multiplyVector4(r.positionScreen),y=k[j-2],E.copy(r.positionScreen),F.copy(y.positionScreen),d(E,F))E.multiplyScalar(1/E.w),F.multiplyScalar(1/F.w),t=K[q]=K[q]||new THREE.RenderableLine,q++,o=t,o.v1.positionScreen.copy(E),o.v2.positionScreen.copy(F),o.z=Math.max(E.z,F.z),o.material=T,s.elements.push(o)}a=0;for(B=s.sprites.length;a<B;a++)if(t=s.sprites[a].object,I=t.matrixWorld,t instanceof THREE.Particle&&(u.set(I.n14,I.n24,I.n34,1),
z.multiplyVector4(u),u.z/=u.w,u.z>0&&u.z<1))g=L[H]=L[H]||new THREE.RenderableParticle,H++,A=g,A.x=u.x/u.w,A.y=u.y/u.w,A.z=u.z,A.rotation=t.rotation.z,A.scale.x=t.scale.x*Math.abs(A.x-(u.x+e.projectionMatrix.n11)/(u.w+e.projectionMatrix.n14)),A.scale.y=t.scale.y*Math.abs(A.y-(u.y+e.projectionMatrix.n22)/(u.w+e.projectionMatrix.n24)),A.material=t.material,s.elements.push(A);f&&s.elements.sort(c);return s}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=Math.PI/360,c=a.x*b,d=a.y*b,e=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-e),e=Math.sin(-e),f=Math.cos(c),c=Math.sin(c),g=a*b,h=d*e;this.w=g*f-h*c;this.x=g*c+h*f;this.y=d*b*f+a*e*c;this.z=a*e*f-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c);
this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.n11+a.n22+a.n33))/2;this.x=Math.sqrt(Math.max(0,b+a.n11-a.n22-a.n33))/2;this.y=Math.sqrt(Math.max(0,b-a.n11+a.n22-a.n33))/2;this.z=Math.sqrt(Math.max(0,b-a.n11-a.n22+a.n33))/2;this.x=a.n32-a.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=a.n13-a.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.n21-a.n12<0?-Math.abs(this.z):Math.abs(this.z);
this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a===0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},multiplySelf:function(a){var b=
......
......@@ -59,14 +59,13 @@ i,k,o=[],l,q=[],r,u,K=[],y,I,t=[],v={objects:[],sprites:[],lights:[],elements:[]
a.n23,a.n44+a.n24);x[3].set(a.n41-a.n21,a.n42-a.n22,a.n43-a.n23,a.n44-a.n24);x[4].set(a.n41-a.n31,a.n42-a.n32,a.n43-a.n33,a.n44-a.n34);x[5].set(a.n41+a.n31,a.n42+a.n32,a.n43+a.n33,a.n44+a.n34);for(a=0;a<6;a++){var b=x[a];b.divideScalar(Math.sqrt(b.x*b.x+b.y*b.y+b.z*b.z))}};this.projectVector=function(a,b){b.matrixWorldInverse.getInverse(b.matrixWorld);B.multiply(b.projectionMatrix,b.matrixWorldInverse);B.multiplyVector3(a);return a};this.unprojectVector=function(a,b){b.projectionMatrixInverse.getInverse(b.projectionMatrix);
B.multiply(b.matrixWorld,b.projectionMatrixInverse);B.multiplyVector3(a);return a};this.pickingRay=function(a,b){var c;a.z=-1;c=new THREE.Vector3(a.x,a.y,1);this.unprojectVector(a,b);this.unprojectVector(c,b);c.subSelf(a).normalize();return new THREE.Ray(a,c)};this.projectGraph=function(b,d){e=0;v.objects.length=0;v.sprites.length=0;v.lights.length=0;var g=function(b){if(b.visible!==!1){var c;if(c=b instanceof THREE.Mesh||b instanceof THREE.Line)if(!(c=b.frustumCulled===!1))a:{for(var d=b.matrixWorld,
e=-b.geometry.boundingSphere.radius*Math.max(b.scale.x,Math.max(b.scale.y,b.scale.z)),h=0;h<6;h++)if(c=x[h].x*d.n14+x[h].y*d.n24+x[h].z*d.n34+x[h].w,c<=e){c=!1;break a}c=!0}c?(B.multiplyVector3(E.copy(b.position)),f=a(),f.object=b,f.z=E.z,v.objects.push(f)):b instanceof THREE.Sprite||b instanceof THREE.Particle?(B.multiplyVector3(E.copy(b.position)),f=a(),f.object=b,f.z=E.z,v.sprites.push(f)):b instanceof THREE.Light&&v.lights.push(b);c=0;for(d=b.children.length;c<d;c++)g(b.children[c])}};g(b);d&&
v.objects.sort(c);return v};this.projectScene=function(a,e,f){var g=e.near,x=e.far,E,O,s,p,w,C,D,J,F,P,Q,U,X,V,W,S;I=u=l=k=0;v.elements.length=0;e.parent==null&&(console.warn("DEPRECATED: Camera hasn't been added to the Scene. Adding it..."),a.add(e));a.updateMatrixWorld();e.matrixWorldInverse.getInverse(e.matrixWorld);B.multiply(e.projectionMatrix,e.matrixWorldInverse);this.computeFrustum(B);v=this.projectGraph(a,!1);a=0;for(E=v.objects.length;a<E;a++)if(F=v.objects[a].object,P=F.matrixWorld,U=F.material,
j=0,F instanceof THREE.Mesh){Q=F.geometry;X=F.geometry.materials;p=Q.vertices;V=Q.faces;W=Q.faceVertexUvs;Q=F.matrixRotationWorld.extractRotation(P);O=0;for(s=p.length;O<s;O++)h=b(),h.positionWorld.copy(p[O].position),P.multiplyVector3(h.positionWorld),h.positionScreen.copy(h.positionWorld),B.multiplyVector4(h.positionScreen),h.positionScreen.x/=h.positionScreen.w,h.positionScreen.y/=h.positionScreen.w,h.visible=h.positionScreen.z>g&&h.positionScreen.z<x;p=0;for(O=V.length;p<O;p++){s=V[p];if(s instanceof
THREE.Face3)if(w=n[s.a],C=n[s.b],D=n[s.c],w.visible&&C.visible&&D.visible&&(F.doubleSided||F.flipSided!=(D.positionScreen.x-w.positionScreen.x)*(C.positionScreen.y-w.positionScreen.y)-(D.positionScreen.y-w.positionScreen.y)*(C.positionScreen.x-w.positionScreen.x)<0))J=o[k]=o[k]||new THREE.RenderableFace3,k++,i=J,i.v1.copy(w),i.v2.copy(C),i.v3.copy(D);else continue;else if(s instanceof THREE.Face4)if(w=n[s.a],C=n[s.b],D=n[s.c],J=n[s.d],w.visible&&C.visible&&D.visible&&J.visible&&(F.doubleSided||F.flipSided!=
((J.positionScreen.x-w.positionScreen.x)*(C.positionScreen.y-w.positionScreen.y)-(J.positionScreen.y-w.positionScreen.y)*(C.positionScreen.x-w.positionScreen.x)<0||(C.positionScreen.x-D.positionScreen.x)*(J.positionScreen.y-D.positionScreen.y)-(C.positionScreen.y-D.positionScreen.y)*(J.positionScreen.x-D.positionScreen.x)<0)))S=q[l]=q[l]||new THREE.RenderableFace4,l++,i=S,i.v1.copy(w),i.v2.copy(C),i.v3.copy(D),i.v4.copy(J);else continue;i.normalWorld.copy(s.normal);Q.multiplyVector3(i.normalWorld);
i.centroidWorld.copy(s.centroid);P.multiplyVector3(i.centroidWorld);i.centroidScreen.copy(i.centroidWorld);B.multiplyVector3(i.centroidScreen);D=s.vertexNormals;w=0;for(C=D.length;w<C;w++)J=i.vertexNormalsWorld[w],J.copy(D[w]),Q.multiplyVector3(J);w=0;for(C=W.length;w<C;w++)if(S=W[w][p]){D=0;for(J=S.length;D<J;D++)i.uvs[w][D]=S[D]}i.material=U;i.faceMaterial=s.materialIndex!==null?X[s.materialIndex]:null;i.z=i.centroidScreen.z;v.elements.push(i)}}else if(F instanceof THREE.Line){G.multiply(B,P);p=
F.geometry.vertices;w=b();w.positionScreen.copy(p[0].position);G.multiplyVector4(w.positionScreen);O=1;for(s=p.length;O<s;O++)if(w=b(),w.positionScreen.copy(p[O].position),G.multiplyVector4(w.positionScreen),C=n[j-2],H.copy(w.positionScreen),z.copy(C.positionScreen),d(H,z))H.multiplyScalar(1/H.w),z.multiplyScalar(1/z.w),F=K[u]=K[u]||new THREE.RenderableLine,u++,r=F,r.v1.positionScreen.copy(H),r.v2.positionScreen.copy(z),r.z=Math.max(H.z,z.z),r.material=U,v.elements.push(r)}a=0;for(E=v.sprites.length;a<
E;a++)if(F=v.sprites[a].object,P=F.matrixWorld,F instanceof THREE.Particle&&(A.set(P.n14,P.n24,P.n34,1),B.multiplyVector4(A),A.z/=A.w,A.z>0&&A.z<1))g=t[I]=t[I]||new THREE.RenderableParticle,I++,y=g,y.x=A.x/A.w,y.y=A.y/A.w,y.z=A.z,y.rotation=F.rotation.z,y.scale.x=F.scale.x*Math.abs(y.x-(A.x+e.projectionMatrix.n11)/(A.w+e.projectionMatrix.n14)),y.scale.y=F.scale.y*Math.abs(y.y-(A.y+e.projectionMatrix.n22)/(A.w+e.projectionMatrix.n24)),y.material=F.material,v.elements.push(y);f&&v.elements.sort(c);
return v}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
v.objects.sort(c);return v};this.projectScene=function(a,e,f){var g=e.near,x=e.far,E,O,s,p,w,C,D,J,F,P,Q,U,X,V,W,S;I=u=l=k=0;v.elements.length=0;e.parent!==a&&a.add(e);a.updateMatrixWorld();e.matrixWorldInverse.getInverse(e.matrixWorld);B.multiply(e.projectionMatrix,e.matrixWorldInverse);this.computeFrustum(B);v=this.projectGraph(a,!1);a=0;for(E=v.objects.length;a<E;a++)if(F=v.objects[a].object,P=F.matrixWorld,U=F.material,j=0,F instanceof THREE.Mesh){Q=F.geometry;X=F.geometry.materials;p=Q.vertices;
V=Q.faces;W=Q.faceVertexUvs;Q=F.matrixRotationWorld.extractRotation(P);O=0;for(s=p.length;O<s;O++)h=b(),h.positionWorld.copy(p[O].position),P.multiplyVector3(h.positionWorld),h.positionScreen.copy(h.positionWorld),B.multiplyVector4(h.positionScreen),h.positionScreen.x/=h.positionScreen.w,h.positionScreen.y/=h.positionScreen.w,h.visible=h.positionScreen.z>g&&h.positionScreen.z<x;p=0;for(O=V.length;p<O;p++){s=V[p];if(s instanceof THREE.Face3)if(w=n[s.a],C=n[s.b],D=n[s.c],w.visible&&C.visible&&D.visible&&
(F.doubleSided||F.flipSided!=(D.positionScreen.x-w.positionScreen.x)*(C.positionScreen.y-w.positionScreen.y)-(D.positionScreen.y-w.positionScreen.y)*(C.positionScreen.x-w.positionScreen.x)<0))J=o[k]=o[k]||new THREE.RenderableFace3,k++,i=J,i.v1.copy(w),i.v2.copy(C),i.v3.copy(D);else continue;else if(s instanceof THREE.Face4)if(w=n[s.a],C=n[s.b],D=n[s.c],J=n[s.d],w.visible&&C.visible&&D.visible&&J.visible&&(F.doubleSided||F.flipSided!=((J.positionScreen.x-w.positionScreen.x)*(C.positionScreen.y-w.positionScreen.y)-
(J.positionScreen.y-w.positionScreen.y)*(C.positionScreen.x-w.positionScreen.x)<0||(C.positionScreen.x-D.positionScreen.x)*(J.positionScreen.y-D.positionScreen.y)-(C.positionScreen.y-D.positionScreen.y)*(J.positionScreen.x-D.positionScreen.x)<0)))S=q[l]=q[l]||new THREE.RenderableFace4,l++,i=S,i.v1.copy(w),i.v2.copy(C),i.v3.copy(D),i.v4.copy(J);else continue;i.normalWorld.copy(s.normal);Q.multiplyVector3(i.normalWorld);i.centroidWorld.copy(s.centroid);P.multiplyVector3(i.centroidWorld);i.centroidScreen.copy(i.centroidWorld);
B.multiplyVector3(i.centroidScreen);D=s.vertexNormals;w=0;for(C=D.length;w<C;w++)J=i.vertexNormalsWorld[w],J.copy(D[w]),Q.multiplyVector3(J);w=0;for(C=W.length;w<C;w++)if(S=W[w][p]){D=0;for(J=S.length;D<J;D++)i.uvs[w][D]=S[D]}i.material=U;i.faceMaterial=s.materialIndex!==null?X[s.materialIndex]:null;i.z=i.centroidScreen.z;v.elements.push(i)}}else if(F instanceof THREE.Line){G.multiply(B,P);p=F.geometry.vertices;w=b();w.positionScreen.copy(p[0].position);G.multiplyVector4(w.positionScreen);O=1;for(s=
p.length;O<s;O++)if(w=b(),w.positionScreen.copy(p[O].position),G.multiplyVector4(w.positionScreen),C=n[j-2],H.copy(w.positionScreen),z.copy(C.positionScreen),d(H,z))H.multiplyScalar(1/H.w),z.multiplyScalar(1/z.w),F=K[u]=K[u]||new THREE.RenderableLine,u++,r=F,r.v1.positionScreen.copy(H),r.v2.positionScreen.copy(z),r.z=Math.max(H.z,z.z),r.material=U,v.elements.push(r)}a=0;for(E=v.sprites.length;a<E;a++)if(F=v.sprites[a].object,P=F.matrixWorld,F instanceof THREE.Particle&&(A.set(P.n14,P.n24,P.n34,1),
B.multiplyVector4(A),A.z/=A.w,A.z>0&&A.z<1))g=t[I]=t[I]||new THREE.RenderableParticle,I++,y=g,y.x=A.x/A.w,y.y=A.y/A.w,y.z=A.z,y.rotation=F.rotation.z,y.scale.x=F.scale.x*Math.abs(y.x-(A.x+e.projectionMatrix.n11)/(A.w+e.projectionMatrix.n14)),y.scale.y=F.scale.y*Math.abs(y.y-(A.y+e.projectionMatrix.n22)/(A.w+e.projectionMatrix.n24)),y.material=F.material,v.elements.push(y);f&&v.elements.sort(c);return v}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)};
THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=Math.PI/360,c=a.x*b,d=a.y*b,f=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-f),f=Math.sin(-f),e=Math.cos(c),c=Math.sin(c),g=a*b,h=d*f;this.w=g*e-h*c;this.x=g*c+h*e;this.y=d*b*e+a*f*c;this.z=a*f*e-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c);
this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.n11+a.n22+a.n33))/2;this.x=Math.sqrt(Math.max(0,b+a.n11-a.n22-a.n33))/2;this.y=Math.sqrt(Math.max(0,b-a.n11+a.n22-a.n33))/2;this.z=Math.sqrt(Math.max(0,b-a.n11-a.n22+a.n33))/2;this.x=a.n32-a.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=a.n13-a.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.n21-a.n12<0?-Math.abs(this.z):Math.abs(this.z);
this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a===0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},multiplySelf:function(a){var b=
......
......@@ -59,14 +59,14 @@ k,o,v=[],q,B=[],A,G,Z=[],ma,sa,va=[],R={objects:[],sprites:[],lights:[],elements
a.n43+a.n23,a.n44+a.n24);C[3].set(a.n41-a.n21,a.n42-a.n22,a.n43-a.n23,a.n44-a.n24);C[4].set(a.n41-a.n31,a.n42-a.n32,a.n43-a.n33,a.n44-a.n34);C[5].set(a.n41+a.n31,a.n42+a.n32,a.n43+a.n33,a.n44+a.n34);for(a=0;a<6;a++){var b=C[a];b.divideScalar(Math.sqrt(b.x*b.x+b.y*b.y+b.z*b.z))}};this.projectVector=function(a,b){b.matrixWorldInverse.getInverse(b.matrixWorld);O.multiply(b.projectionMatrix,b.matrixWorldInverse);O.multiplyVector3(a);return a};this.unprojectVector=function(a,b){b.projectionMatrixInverse.getInverse(b.projectionMatrix);
O.multiply(b.matrixWorld,b.projectionMatrixInverse);O.multiplyVector3(a);return a};this.pickingRay=function(a,b){var c;a.z=-1;c=new THREE.Vector3(a.x,a.y,1);this.unprojectVector(a,b);this.unprojectVector(c,b);c.subSelf(a).normalize();return new THREE.Ray(a,c)};this.projectGraph=function(b,e){h=0;R.objects.length=0;R.sprites.length=0;R.lights.length=0;var i=function(d){if(d.visible!==!1){var b;if(b=d instanceof THREE.Mesh||d instanceof THREE.Line)if(!(b=d.frustumCulled===!1))a:{for(var c=d.matrixWorld,
e=-d.geometry.boundingSphere.radius*Math.max(d.scale.x,Math.max(d.scale.y,d.scale.z)),h=0;h<6;h++)if(b=C[h].x*c.n14+C[h].y*c.n24+C[h].z*c.n34+C[h].w,b<=e){b=!1;break a}b=!0}b?(O.multiplyVector3(N.copy(d.position)),f=a(),f.object=d,f.z=N.z,R.objects.push(f)):d instanceof THREE.Sprite||d instanceof THREE.Particle?(O.multiplyVector3(N.copy(d.position)),f=a(),f.object=d,f.z=N.z,R.sprites.push(f)):d instanceof THREE.Light&&R.lights.push(d);b=0;for(c=d.children.length;b<c;b++)i(d.children[b])}};i(b);e&&
R.objects.sort(c);return R};this.projectScene=function(a,h,f){var d=h.near,i=h.far,N,C,J,Q,S,T,X,ka,U,ua,za,Ka,Qa,Ba,Ca,ta;sa=G=q=o=0;R.elements.length=0;h.parent==null&&(console.warn("DEPRECATED: Camera hasn't been added to the Scene. Adding it..."),a.add(h));a.updateMatrixWorld();h.matrixWorldInverse.getInverse(h.matrixWorld);O.multiply(h.projectionMatrix,h.matrixWorldInverse);this.computeFrustum(O);R=this.projectGraph(a,!1);a=0;for(N=R.objects.length;a<N;a++)if(U=R.objects[a].object,ua=U.matrixWorld,
Ka=U.material,l=0,U instanceof THREE.Mesh){za=U.geometry;Qa=U.geometry.materials;Q=za.vertices;Ba=za.faces;Ca=za.faceVertexUvs;za=U.matrixRotationWorld.extractRotation(ua);C=0;for(J=Q.length;C<J;C++)j=b(),j.positionWorld.copy(Q[C].position),ua.multiplyVector3(j.positionWorld),j.positionScreen.copy(j.positionWorld),O.multiplyVector4(j.positionScreen),j.positionScreen.x/=j.positionScreen.w,j.positionScreen.y/=j.positionScreen.w,j.visible=j.positionScreen.z>d&&j.positionScreen.z<i;Q=0;for(C=Ba.length;Q<
C;Q++){J=Ba[Q];if(J instanceof THREE.Face3)if(S=m[J.a],T=m[J.b],X=m[J.c],S.visible&&T.visible&&X.visible&&(U.doubleSided||U.flipSided!=(X.positionScreen.x-S.positionScreen.x)*(T.positionScreen.y-S.positionScreen.y)-(X.positionScreen.y-S.positionScreen.y)*(T.positionScreen.x-S.positionScreen.x)<0))ka=v[o]=v[o]||new THREE.RenderableFace3,o++,k=ka,k.v1.copy(S),k.v2.copy(T),k.v3.copy(X);else continue;else if(J instanceof THREE.Face4)if(S=m[J.a],T=m[J.b],X=m[J.c],ka=m[J.d],S.visible&&T.visible&&X.visible&&
ka.visible&&(U.doubleSided||U.flipSided!=((ka.positionScreen.x-S.positionScreen.x)*(T.positionScreen.y-S.positionScreen.y)-(ka.positionScreen.y-S.positionScreen.y)*(T.positionScreen.x-S.positionScreen.x)<0||(T.positionScreen.x-X.positionScreen.x)*(ka.positionScreen.y-X.positionScreen.y)-(T.positionScreen.y-X.positionScreen.y)*(ka.positionScreen.x-X.positionScreen.x)<0)))ta=B[q]=B[q]||new THREE.RenderableFace4,q++,k=ta,k.v1.copy(S),k.v2.copy(T),k.v3.copy(X),k.v4.copy(ka);else continue;k.normalWorld.copy(J.normal);
za.multiplyVector3(k.normalWorld);k.centroidWorld.copy(J.centroid);ua.multiplyVector3(k.centroidWorld);k.centroidScreen.copy(k.centroidWorld);O.multiplyVector3(k.centroidScreen);X=J.vertexNormals;S=0;for(T=X.length;S<T;S++)ka=k.vertexNormalsWorld[S],ka.copy(X[S]),za.multiplyVector3(ka);S=0;for(T=Ca.length;S<T;S++)if(ta=Ca[S][Q]){X=0;for(ka=ta.length;X<ka;X++)k.uvs[S][X]=ta[X]}k.material=Ka;k.faceMaterial=J.materialIndex!==null?Qa[J.materialIndex]:null;k.z=k.centroidScreen.z;R.elements.push(k)}}else if(U instanceof
THREE.Line){qa.multiply(O,ua);Q=U.geometry.vertices;S=b();S.positionScreen.copy(Q[0].position);qa.multiplyVector4(S.positionScreen);C=1;for(J=Q.length;C<J;C++)if(S=b(),S.positionScreen.copy(Q[C].position),qa.multiplyVector4(S.positionScreen),T=m[l-2],ja.copy(S.positionScreen),aa.copy(T.positionScreen),e(ja,aa))ja.multiplyScalar(1/ja.w),aa.multiplyScalar(1/aa.w),U=Z[G]=Z[G]||new THREE.RenderableLine,G++,A=U,A.v1.positionScreen.copy(ja),A.v2.positionScreen.copy(aa),A.z=Math.max(ja.z,aa.z),A.material=
Ka,R.elements.push(A)}a=0;for(N=R.sprites.length;a<N;a++)if(U=R.sprites[a].object,ua=U.matrixWorld,U instanceof THREE.Particle&&(E.set(ua.n14,ua.n24,ua.n34,1),O.multiplyVector4(E),E.z/=E.w,E.z>0&&E.z<1))d=va[sa]=va[sa]||new THREE.RenderableParticle,sa++,ma=d,ma.x=E.x/E.w,ma.y=E.y/E.w,ma.z=E.z,ma.rotation=U.rotation.z,ma.scale.x=U.scale.x*Math.abs(ma.x-(E.x+h.projectionMatrix.n11)/(E.w+h.projectionMatrix.n14)),ma.scale.y=U.scale.y*Math.abs(ma.y-(E.y+h.projectionMatrix.n22)/(E.w+h.projectionMatrix.n24)),
ma.material=U.material,R.elements.push(ma);f&&R.elements.sort(c);return R}};THREE.Quaternion=function(a,b,c,e){this.set(a||0,b||0,c||0,e!==void 0?e:1)};
R.objects.sort(c);return R};this.projectScene=function(a,h,f){var d=h.near,i=h.far,N,C,J,Q,S,T,X,ka,U,ua,za,Ka,Qa,Ba,Ca,ta;sa=G=q=o=0;R.elements.length=0;h.parent!==a&&a.add(h);a.updateMatrixWorld();h.matrixWorldInverse.getInverse(h.matrixWorld);O.multiply(h.projectionMatrix,h.matrixWorldInverse);this.computeFrustum(O);R=this.projectGraph(a,!1);a=0;for(N=R.objects.length;a<N;a++)if(U=R.objects[a].object,ua=U.matrixWorld,Ka=U.material,l=0,U instanceof THREE.Mesh){za=U.geometry;Qa=U.geometry.materials;
Q=za.vertices;Ba=za.faces;Ca=za.faceVertexUvs;za=U.matrixRotationWorld.extractRotation(ua);C=0;for(J=Q.length;C<J;C++)j=b(),j.positionWorld.copy(Q[C].position),ua.multiplyVector3(j.positionWorld),j.positionScreen.copy(j.positionWorld),O.multiplyVector4(j.positionScreen),j.positionScreen.x/=j.positionScreen.w,j.positionScreen.y/=j.positionScreen.w,j.visible=j.positionScreen.z>d&&j.positionScreen.z<i;Q=0;for(C=Ba.length;Q<C;Q++){J=Ba[Q];if(J instanceof THREE.Face3)if(S=m[J.a],T=m[J.b],X=m[J.c],S.visible&&
T.visible&&X.visible&&(U.doubleSided||U.flipSided!=(X.positionScreen.x-S.positionScreen.x)*(T.positionScreen.y-S.positionScreen.y)-(X.positionScreen.y-S.positionScreen.y)*(T.positionScreen.x-S.positionScreen.x)<0))ka=v[o]=v[o]||new THREE.RenderableFace3,o++,k=ka,k.v1.copy(S),k.v2.copy(T),k.v3.copy(X);else continue;else if(J instanceof THREE.Face4)if(S=m[J.a],T=m[J.b],X=m[J.c],ka=m[J.d],S.visible&&T.visible&&X.visible&&ka.visible&&(U.doubleSided||U.flipSided!=((ka.positionScreen.x-S.positionScreen.x)*
(T.positionScreen.y-S.positionScreen.y)-(ka.positionScreen.y-S.positionScreen.y)*(T.positionScreen.x-S.positionScreen.x)<0||(T.positionScreen.x-X.positionScreen.x)*(ka.positionScreen.y-X.positionScreen.y)-(T.positionScreen.y-X.positionScreen.y)*(ka.positionScreen.x-X.positionScreen.x)<0)))ta=B[q]=B[q]||new THREE.RenderableFace4,q++,k=ta,k.v1.copy(S),k.v2.copy(T),k.v3.copy(X),k.v4.copy(ka);else continue;k.normalWorld.copy(J.normal);za.multiplyVector3(k.normalWorld);k.centroidWorld.copy(J.centroid);
ua.multiplyVector3(k.centroidWorld);k.centroidScreen.copy(k.centroidWorld);O.multiplyVector3(k.centroidScreen);X=J.vertexNormals;S=0;for(T=X.length;S<T;S++)ka=k.vertexNormalsWorld[S],ka.copy(X[S]),za.multiplyVector3(ka);S=0;for(T=Ca.length;S<T;S++)if(ta=Ca[S][Q]){X=0;for(ka=ta.length;X<ka;X++)k.uvs[S][X]=ta[X]}k.material=Ka;k.faceMaterial=J.materialIndex!==null?Qa[J.materialIndex]:null;k.z=k.centroidScreen.z;R.elements.push(k)}}else if(U instanceof THREE.Line){qa.multiply(O,ua);Q=U.geometry.vertices;
S=b();S.positionScreen.copy(Q[0].position);qa.multiplyVector4(S.positionScreen);C=1;for(J=Q.length;C<J;C++)if(S=b(),S.positionScreen.copy(Q[C].position),qa.multiplyVector4(S.positionScreen),T=m[l-2],ja.copy(S.positionScreen),aa.copy(T.positionScreen),e(ja,aa))ja.multiplyScalar(1/ja.w),aa.multiplyScalar(1/aa.w),U=Z[G]=Z[G]||new THREE.RenderableLine,G++,A=U,A.v1.positionScreen.copy(ja),A.v2.positionScreen.copy(aa),A.z=Math.max(ja.z,aa.z),A.material=Ka,R.elements.push(A)}a=0;for(N=R.sprites.length;a<
N;a++)if(U=R.sprites[a].object,ua=U.matrixWorld,U instanceof THREE.Particle&&(E.set(ua.n14,ua.n24,ua.n34,1),O.multiplyVector4(E),E.z/=E.w,E.z>0&&E.z<1))d=va[sa]=va[sa]||new THREE.RenderableParticle,sa++,ma=d,ma.x=E.x/E.w,ma.y=E.y/E.w,ma.z=E.z,ma.rotation=U.rotation.z,ma.scale.x=U.scale.x*Math.abs(ma.x-(E.x+h.projectionMatrix.n11)/(E.w+h.projectionMatrix.n14)),ma.scale.y=U.scale.y*Math.abs(ma.y-(E.y+h.projectionMatrix.n22)/(E.w+h.projectionMatrix.n24)),ma.material=U.material,R.elements.push(ma);f&&
R.elements.sort(c);return R}};THREE.Quaternion=function(a,b,c,e){this.set(a||0,b||0,c||0,e!==void 0?e:1)};
THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,e){this.x=a;this.y=b;this.z=c;this.w=e;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=Math.PI/360,c=a.x*b,e=a.y*b,f=a.z*b,a=Math.cos(e),e=Math.sin(e),b=Math.cos(-f),f=Math.sin(-f),h=Math.cos(c),c=Math.sin(c),i=a*b,j=e*f;this.w=i*h-j*c;this.x=i*c+j*h;this.y=e*b*h+a*f*c;this.z=a*f*h-e*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,e=Math.sin(c);
this.x=a.x*e;this.y=a.y*e;this.z=a.z*e;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.n11+a.n22+a.n33))/2;this.x=Math.sqrt(Math.max(0,b+a.n11-a.n22-a.n33))/2;this.y=Math.sqrt(Math.max(0,b-a.n11+a.n22-a.n33))/2;this.z=Math.sqrt(Math.max(0,b-a.n11-a.n22+a.n33))/2;this.x=a.n32-a.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=a.n13-a.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.n21-a.n12<0?-Math.abs(this.z):Math.abs(this.z);
this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a===0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},multiplySelf:function(a){var b=
......@@ -248,8 +248,8 @@ i=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+c.ma
aa("vertex",e+m));d.linkProgram(q);d.getProgramParameter(q,d.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+d.getProgramParameter(q,d.VALIDATE_STATUS)+", gl error ["+d.getError()+"]");q.uniforms={};q.attributes={};var v,e=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","cameraInverseMatrix","boneGlobalMatrices","morphTargetInfluences"];for(v in k)e.push(v);v=e;e=0;for(k=v.length;e<k;e++)p=v[e],q.uniforms[p]=d.getUniformLocation(q,
p);e=["position","normal","uv","uv2","tangent","color","skinVertexA","skinVertexB","skinIndex","skinWeight"];for(v=0;v<c.maxMorphTargets;v++)e.push("morphTarget"+v);for(y in b)e.push(y);y=e;v=0;for(b=y.length;v<b;v++)c=y[v],q.attributes[c]=d.getAttribLocation(q,c);q.id=xa.length;xa.push({program:q,code:j});F.info.memory.programs=xa.length;y=q}a.program=y;y=a.program.attributes;y.position>=0&&d.enableVertexAttribArray(y.position);y.color>=0&&d.enableVertexAttribArray(y.color);y.normal>=0&&d.enableVertexAttribArray(y.normal);
y.tangent>=0&&d.enableVertexAttribArray(y.tangent);a.skinning&&y.skinVertexA>=0&&y.skinVertexB>=0&&y.skinIndex>=0&&y.skinWeight>=0&&(d.enableVertexAttribArray(y.skinVertexA),d.enableVertexAttribArray(y.skinVertexB),d.enableVertexAttribArray(y.skinIndex),d.enableVertexAttribArray(y.skinWeight));if(a.attributes)for(h in a.attributes)y[h]!==void 0&&y[h]>=0&&d.enableVertexAttribArray(y[h]);if(a.morphTargets)for(h=a.numSupportedMorphTargets=0;h<this.maxMorphTargets;h++)v="morphTarget"+h,y[v]>=0&&(d.enableVertexAttribArray(y[v]),
a.numSupportedMorphTargets++);a.uniformsList=[];for(f in a.uniforms)a.uniformsList.push([a.uniforms[f],f])};this.clearTarget=function(a,b,c,d){C(a);this.clear(b,c,d)};this.updateShadowMap=function(a,b){A(a,b)};this.render=function(a,b,c,s){var Ga,K,Ra,u,t,p,Oa,Pa=a.lights,Aa=a.fog;J=-1;this.autoUpdateObjects&&this.initWebGLObjects(a);this.shadowMapEnabled&&this.shadowMapAutoUpdate&&A(a,b);F.info.render.calls=0;F.info.render.vertices=0;F.info.render.faces=0;b.parent==null&&(console.warn("Camera is not on the Scene. Adding it..."),
a.add(b));this.autoUpdateScene&&a.updateMatrixWorld();b.matrixWorldInverse.getInverse(b.matrixWorld);b.matrixWorldInverse.flattenToArray(Ua);b.projectionMatrix.flattenToArray(Ta);Da.multiply(b.projectionMatrix,b.matrixWorldInverse);k(Da);C(c);(this.autoClear||s)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);Ra=a.__webglObjects.length;for(s=0;s<Ra;s++)if(t=a.__webglObjects[s],p=t.object,p.visible)if(!(p instanceof THREE.Mesh)||!p.frustumCulled||o(p)){if(p.matrixWorld.flattenToArray(p._objectMatrixArray),
a.numSupportedMorphTargets++);a.uniformsList=[];for(f in a.uniforms)a.uniformsList.push([a.uniforms[f],f])};this.clearTarget=function(a,b,c,d){C(a);this.clear(b,c,d)};this.updateShadowMap=function(a,b){A(a,b)};this.render=function(a,b,c,s){var Ga,K,Ra,u,t,p,Oa,Pa=a.lights,Aa=a.fog;J=-1;this.autoUpdateObjects&&this.initWebGLObjects(a);this.shadowMapEnabled&&this.shadowMapAutoUpdate&&A(a,b);F.info.render.calls=0;F.info.render.vertices=0;F.info.render.faces=0;b.parent!==a&&a.add(b);this.autoUpdateScene&&
a.updateMatrixWorld();b.matrixWorldInverse.getInverse(b.matrixWorld);b.matrixWorldInverse.flattenToArray(Ua);b.projectionMatrix.flattenToArray(Ta);Da.multiply(b.projectionMatrix,b.matrixWorldInverse);k(Da);C(c);(this.autoClear||s)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);Ra=a.__webglObjects.length;for(s=0;s<Ra;s++)if(t=a.__webglObjects[s],p=t.object,p.visible)if(!(p instanceof THREE.Mesh)||!p.frustumCulled||o(p)){if(p.matrixWorld.flattenToArray(p._objectMatrixArray),
Z(p,b,!0),q(t),t.render=!0,this.sortObjects)p.renderDepth?t.z=p.renderDepth:(Ha.copy(p.position),Da.multiplyVector3(Ha),t.z=Ha.z)}else t.render=!1;else t.render=!1;this.sortObjects&&a.__webglObjects.sort(B);u=a.__webglObjectsImmediate.length;for(s=0;s<u;s++)t=a.__webglObjectsImmediate[s],p=t.object,p.visible&&(p.matrixAutoUpdate&&p.matrixWorld.flattenToArray(p._objectMatrixArray),Z(p,b,!0),v(t));if(a.overrideMaterial){j(a.overrideMaterial.depthTest);N(a.overrideMaterial.blending);for(s=0;s<Ra;s++)if(t=
a.__webglObjects[s],t.render)p=t.object,Oa=t.buffer,i(p),f(b,Pa,Aa,a.overrideMaterial,Oa,p);for(s=0;s<u;s++)t=a.__webglObjectsImmediate[s],p=t.object,p.visible&&(Q=-1,i(p),Ga=e(b,Pa,Aa,a.overrideMaterial,p),p.immediateRenderCallback?p.immediateRenderCallback(Ga,d,ha):p.render(function(b){h(b,Ga,a.overrideMaterial.shading)}))}else{N(THREE.NormalBlending);for(s=Ra-1;s>=0;s--)if(t=a.__webglObjects[s],t.render&&(p=t.object,Oa=t.buffer,K=t.opaque))i(p),j(K.depthTest),l(K.depthWrite),m(K.polygonOffset,
K.polygonOffsetFactor,K.polygonOffsetUnits),f(b,Pa,Aa,K,Oa,p);for(s=0;s<u;s++)if(t=a.__webglObjectsImmediate[s],p=t.object,p.visible&&(Q=-1,K=t.opaque))i(p),j(K.depthTest),l(K.depthWrite),m(K.polygonOffset,K.polygonOffsetFactor,K.polygonOffsetUnits),Ga=e(b,Pa,Aa,K,p),p.immediateRenderCallback?p.immediateRenderCallback(Ga,d,ha):p.render(function(a){h(a,Ga,K.shading)});for(s=0;s<Ra;s++)if(t=a.__webglObjects[s],t.render&&(p=t.object,Oa=t.buffer,K=t.transparent))i(p),N(K.blending),j(K.depthTest),l(K.depthWrite),
......
......@@ -169,12 +169,7 @@ THREE.Projector = function() {
_renderData.elements.length = 0;
if ( camera.parent == null ) {
console.warn( 'DEPRECATED: Camera hasn\'t been added to the Scene. Adding it...' );
scene.add( camera );
}
if ( camera.parent !== scene ) scene.add( camera );
scene.updateMatrixWorld();
......
......@@ -3798,14 +3798,9 @@ THREE.WebGLRenderer = function ( parameters ) {
_this.info.render.vertices = 0;
_this.info.render.faces = 0;
if ( camera.parent == null ) {
if ( camera.parent !== scene ) scene.add( camera );
console.warn( "Camera is not on the Scene. Adding it..." );
scene.add( camera );
}
if ( this.autoUpdateScene ) scene.updateMatrixWorld();
if ( this.autoUpdateScene ) scene.updateMatrixWorld();
camera.matrixWorldInverse.getInverse( camera.matrixWorld );
camera.matrixWorldInverse.flattenToArray( _viewMatrixArray );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册