From 5916682ea6eb926dac27d4f8aa186ffcc931df52 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Tue, 25 Oct 2011 05:59:13 +0200 Subject: [PATCH] Reverting again Actually, this would break cameras added as childs of objects, reverting. So there is no clear and simple way to handling multiple scenes unfortunatelly. Encouraging `scene.add( camera )` seems like the right thing to do then, less problems. --- README.md | 5 +++-- build/Three.js | 20 ++++++++++---------- build/custom/ThreeCanvas.js | 15 ++++++++------- build/custom/ThreeDOM.js | 15 ++++++++------- build/custom/ThreeSVG.js | 15 ++++++++------- build/custom/ThreeWebGL.js | 20 ++++++++++---------- src/core/Projector.js | 7 ++++++- src/renderers/WebGLRenderer.js | 7 ++++++- 8 files changed, 59 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 2bb8d158..ad39be67 100644 --- a/README.md +++ b/README.md @@ -99,10 +99,11 @@ 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 = new THREE.Scene(); + scene.add( camera ); geometry = new THREE.CubeGeometry( 200, 200, 200 ); material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } ); diff --git a/build/Three.js b/build/Three.js index cf604d78..993fd884 100644 --- a/build/Three.js +++ b/build/Three.js @@ -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;cf&&l.positionScreen.z0&&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===void 0&&(console.warn("DEPRECATED: Camera hasn't been added to a 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;af&&l.positionScreen.z0&&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=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=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!==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=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;Fg&&h.positionScreen.z0&&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===void 0&&(console.warn("DEPRECATED: Camera hasn't been added to a 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;ag&&h.positionScreen.z0&&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= diff --git a/build/custom/ThreeDOM.js b/build/custom/ThreeDOM.js index 2628fb5c..96633af9 100644 --- a/build/custom/ThreeDOM.js +++ b/build/custom/ThreeDOM.js @@ -59,13 +59,14 @@ 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;cg&&h.positionScreen.z0&&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===void 0&&(console.warn("DEPRECATED: Camera hasn't been added to a 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;ag&&h.positionScreen.z0&&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= diff --git a/build/custom/ThreeSVG.js b/build/custom/ThreeSVG.js index 3a622685..03d700e7 100644 --- a/build/custom/ThreeSVG.js +++ b/build/custom/ThreeSVG.js @@ -59,13 +59,14 @@ 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;cg&&h.positionScreen.z0&&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===void 0&&(console.warn("DEPRECATED: Camera hasn't been added to a 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;ag&&h.positionScreen.z0&&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= diff --git a/build/custom/ThreeWebGL.js b/build/custom/ThreeWebGL.js index c861ee1b..a460e4cc 100644 --- a/build/custom/ThreeWebGL.js +++ b/build/custom/ThreeWebGL.js @@ -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;bd&&j.positionScreen.z0&&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===void 0&&(console.warn("DEPRECATED: Camera hasn't been added to a 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;ad&&j.positionScreen.z0&&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=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=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!==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=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