diff --git a/build/Three.js b/build/Three.js index 959096c3..05c3237d 100644 --- a/build/Three.js +++ b/build/Three.js @@ -49,7 +49,7 @@ this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y)"}};THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleCircleMaterial (
color: "+this.color+"
opacity: "+this.opacity+"
blending: "+this.blending+"
)"}}; THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};THREE.Texture=function(a,c,f,h){this.image=a;this.mapping=c!==undefined?c:THREE.UVMapping;this.wrap_s=f!==undefined?f:THREE.ClampToEdge;this.wrap_t=h!==undefined?h:THREE.ClampToEdge;this.toString=function(){return"THREE.Texture (
image: "+this.image+"
wrap_s: "+this.wrap_s+"
wrap_t: "+this.wrap_t+"
)"}};THREE.UVMapping=0; THREE.ReflectionMap=1;THREE.RefractionMap=2;THREE.Multiply=0;THREE.Mix=1;THREE.Repeat=0;THREE.ClampToEdge=1;THREE.MirroredRepeat=2;THREE.TextureCube=function(a,c){this.image=a;this.mapping=c?c:THREE.ReflectionMap;this.toString=function(){return"THREE.TextureCube (
image: "+this.image+"
mapping: "+this.mapping+"
)"}}; -THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}}; +THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){this.objects.push(a)};this.removeObject=function(a){var c=this.objects.indexOf(a);c!==-1&&this.objects.splice(c,1);a.__removed=true};this.addLight=function(a){this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}}; THREE.Projector=function(){function a(r,q){var l=0,Q=1,H=r.z+r.w,T=q.z+q.w,$=-r.z+r.w,t=-q.z+q.w;if(H>=0&&T>=0&&$>=0&&t>=0)return true;else if(H<0&&T<0||$<0&&t<0)return false;else{if(H<0)l=Math.max(l,H/(H-T));else if(T<0)Q=Math.min(Q,H/(H-T));if($<0)l=Math.max(l,$/($-t));else if(t<0)Q=Math.min(Q,$/($-t));if(Q0&&N.z<1}oa=t.geometry.faces;H=0;for(T= oa.length;H=0;g--){i=e.__webGLObjects[g].__object;i.__removed&&e.__webGLObjects.splice(g,1)}};this.setupMatrices=function(e,g){e.autoUpdateMatrix&&e.updateMatrix();p.multiply(g.matrix,e.matrix);d.viewMatrixArray=new Float32Array(g.matrix.flatten());d.modelViewMatrixArray= +new Float32Array(p.flatten());d.projectionMatrixArray=new Float32Array(g.projectionMatrix.flatten());s=THREE.Matrix4.makeInvert3x3(p).transpose();d.normalMatrixArray=new Float32Array(s.m);b.uniformMatrix4fv(d.viewMatrix,false,d.viewMatrixArray);b.uniformMatrix4fv(d.modelViewMatrix,false,d.modelViewMatrixArray);b.uniformMatrix4fv(d.projectionMatrix,false,d.projectionMatrixArray);b.uniformMatrix3fv(d.normalMatrix,false,d.normalMatrixArray);b.uniformMatrix4fv(d.objMatrix,false,new Float32Array(e.matrix.flatten()))}; +this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,g){if(e){!g||g=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(e=="back")b.cullFace(b.BACK);else e=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)}}; THREE.RenderableFace3=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.material=this.color=this.z=null}; THREE.RenderableFace4=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.v4=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.material=this.color=this.z=null};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=this.color=null}; THREE.RenderableLine=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=this.color=this.z=null}; diff --git a/build/ThreeDebug.js b/build/ThreeDebug.js index 6328d426..1a5c91ee 100644 --- a/build/ThreeDebug.js +++ b/build/ThreeDebug.js @@ -49,7 +49,7 @@ this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y)"}};THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleCircleMaterial (
color: "+this.color+"
opacity: "+this.opacity+"
blending: "+this.blending+"
)"}}; THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};THREE.Texture=function(a,c,f,h){this.image=a;this.mapping=c!==undefined?c:THREE.UVMapping;this.wrap_s=f!==undefined?f:THREE.ClampToEdge;this.wrap_t=h!==undefined?h:THREE.ClampToEdge;this.toString=function(){return"THREE.Texture (
image: "+this.image+"
wrap_s: "+this.wrap_s+"
wrap_t: "+this.wrap_t+"
)"}};THREE.UVMapping=0; THREE.ReflectionMap=1;THREE.RefractionMap=2;THREE.Multiply=0;THREE.Mix=1;THREE.Repeat=0;THREE.ClampToEdge=1;THREE.MirroredRepeat=2;THREE.TextureCube=function(a,c){this.image=a;this.mapping=c?c:THREE.ReflectionMap;this.toString=function(){return"THREE.TextureCube (
image: "+this.image+"
mapping: "+this.mapping+"
)"}}; -THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}}; +THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){this.objects.push(a)};this.removeObject=function(a){var c=this.objects.indexOf(a);c!==-1&&this.objects.splice(c,1);a.__removed=true};this.addLight=function(a){this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}}; THREE.Projector=function(){function a(r,q){var k=0,Q=1,H=r.z+r.w,T=q.z+q.w,$=-r.z+r.w,t=-q.z+q.w;if(H>=0&&T>=0&&$>=0&&t>=0)return true;else if(H<0&&T<0||$<0&&t<0)return false;else{if(H<0)k=Math.max(k,H/(H-T));else if(T<0)Q=Math.min(Q,H/(H-T));if($<0)k=Math.max(k,$/($-t));else if(t<0)Q=Math.min(Q,$/($-t));if(Q0&&N.z<1}pa=t.geometry.faces;H=0;for(T= pa.length;H=0;g--){i=e.__webGLObjects[g].__object;i.__removed&&e.__webGLObjects.splice(g,1)}};this.setupMatrices=function(e,g){e.autoUpdateMatrix&&e.updateMatrix();p.multiply(g.matrix,e.matrix);d.viewMatrixArray=new Float32Array(g.matrix.flatten());d.modelViewMatrixArray= +new Float32Array(p.flatten());d.projectionMatrixArray=new Float32Array(g.projectionMatrix.flatten());s=THREE.Matrix4.makeInvert3x3(p).transpose();d.normalMatrixArray=new Float32Array(s.m);b.uniformMatrix4fv(d.viewMatrix,false,d.viewMatrixArray);b.uniformMatrix4fv(d.modelViewMatrix,false,d.modelViewMatrixArray);b.uniformMatrix4fv(d.projectionMatrix,false,d.projectionMatrixArray);b.uniformMatrix3fv(d.normalMatrix,false,d.normalMatrixArray);b.uniformMatrix4fv(d.objMatrix,false,new Float32Array(e.matrix.flatten()))}; +this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,g){if(e){!g||g=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(e=="back")b.cullFace(b.BACK);else e=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)}}; THREE.RenderableFace3=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.material=this.color=this.z=null}; THREE.RenderableFace4=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.v4=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.material=this.color=this.z=null};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=this.color=null}; THREE.RenderableLine=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=this.color=this.z=null}; diff --git a/examples/lights_test.html b/examples/lights_test.html index 6ebe6c32..0fcf57d5 100644 --- a/examples/lights_test.html +++ b/examples/lights_test.html @@ -102,9 +102,9 @@ // SPHERES - sphere = new Sphere( 100, 16, 8, 0 ); + sphere = new Sphere( 100, 16, 8 ); for (var i=0; i<30; i++) { - mesh = new THREE.Mesh( sphere, new THREE.MeshLambertMaterial( { color: 0xffffff } ) ); + mesh = new THREE.Mesh( sphere, new THREE.MeshLambertMaterial( { color: 0xffffff, shading: THREE.FlatShading } ) ); mesh.position.x = 500 * (Math.random() - 0.5); mesh.position.y = 500 * (Math.random() - 0.5); mesh.position.z = 500 * (Math.random() - 0.5); @@ -133,7 +133,7 @@ scene.addLight( pointLight ); - sphere = new Sphere( 100, 16, 8, 1 ); + sphere = new Sphere( 100, 16, 8 ); lightMesh = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0xffaa00 } ) ); lightMesh.scale.x = lightMesh.scale.y = lightMesh.scale.z = 0.05; lightMesh.position = pointLight.position; diff --git a/src/extras/SceneUtils.js b/src/extras/SceneUtils.js index 80c81576..25a64175 100644 --- a/src/extras/SceneUtils.js +++ b/src/extras/SceneUtils.js @@ -12,6 +12,8 @@ var SceneUtils = { mesh.rotation.z = rz; scene.addObject( mesh ); + return mesh; + }, addPanoramaCubeWebGL: function ( scene, size, textureCube ) { @@ -21,6 +23,8 @@ var SceneUtils = { scene.addObject( mesh ); + return mesh; + }, addPanoramaCube: function( scene, size, images ) { @@ -35,6 +39,8 @@ var SceneUtils = { mesh = new THREE.Mesh( new Cube( size, size, size, 1, 1, materials, true ), new THREE.MeshFaceMaterial() ); scene.addObject( mesh ); + + return mesh; }, @@ -49,6 +55,8 @@ var SceneUtils = { SceneUtils.addMesh( scene, plane, 1, 0, hsize, 0, pi2, 0, pi, new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[2] ) } ) ); SceneUtils.addMesh( scene, plane, 1, 0, -hsize, 0, -pi2, 0, pi, new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[3] ) } ) ); + return mesh; + } } \ No newline at end of file diff --git a/src/objects/Object3D.js b/src/objects/Object3D.js index 5723d0f3..455a6110 100644 --- a/src/objects/Object3D.js +++ b/src/objects/Object3D.js @@ -15,6 +15,8 @@ THREE.Object3D = function ( material ) { this.screen = new THREE.Vector3(); + this.visible = true; + this.autoUpdateMatrix = true; this.updateMatrix = function () { diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 11b8dac2..71ad0d89 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -655,9 +655,13 @@ THREE.WebGLRenderer = function ( scene ) { for ( o = 0, ol = scene.__webGLObjects.length; o < ol; o++ ) { webGLObject = scene.__webGLObjects[ o ]; + + if ( webGLObject.__object.visible ) { - this.setupMatrices( webGLObject.__object, camera ); - this.renderPass( webGLObject.__object, webGLObject, THREE.NormalBlending, false ); + this.setupMatrices( webGLObject.__object, camera ); + this.renderPass( webGLObject.__object, webGLObject, THREE.NormalBlending, false ); + + } } @@ -667,18 +671,25 @@ THREE.WebGLRenderer = function ( scene ) { webGLObject = scene.__webGLObjects[ o ]; - this.setupMatrices( webGLObject.__object, camera ); + if ( webGLObject.__object.visible ) { + + this.setupMatrices( webGLObject.__object, camera ); - // opaque blended materials - this.renderPass( webGLObject.__object, webGLObject, THREE.AdditiveBlending, false ); - this.renderPass( webGLObject.__object, webGLObject, THREE.SubtractiveBlending, false ); - - // transparent blended materials - this.renderPass( webGLObject.__object, webGLObject, THREE.AdditiveBlending, true ); - this.renderPass( webGLObject.__object, webGLObject, THREE.SubtractiveBlending, true ); + // opaque blended materials + + this.renderPass( webGLObject.__object, webGLObject, THREE.AdditiveBlending, false ); + this.renderPass( webGLObject.__object, webGLObject, THREE.SubtractiveBlending, false ); + + // transparent blended materials + + this.renderPass( webGLObject.__object, webGLObject, THREE.AdditiveBlending, true ); + this.renderPass( webGLObject.__object, webGLObject, THREE.SubtractiveBlending, true ); - // transparent normal materials - this.renderPass( webGLObject.__object, webGLObject, THREE.NormalBlending, true ); + // transparent normal materials + + this.renderPass( webGLObject.__object, webGLObject, THREE.NormalBlending, true ); + + } } @@ -725,6 +736,20 @@ THREE.WebGLRenderer = function ( scene ) { }*/ } + + // clean up orphaned objects + + for ( o = scene.__webGLObjects.length - 1; o >= 0; o-- ) { + + object = scene.__webGLObjects[ o ].__object; + if ( object.__removed ) { + + scene.__webGLObjects.splice( o, 1 ); + + } + + } + }; diff --git a/src/scenes/Scene.js b/src/scenes/Scene.js index a39fa329..5b56934d 100644 --- a/src/scenes/Scene.js +++ b/src/scenes/Scene.js @@ -23,6 +23,8 @@ THREE.Scene = function () { } + object.__removed = true; + }; this.addLight = function ( light ) {