diff --git a/build/Three.js b/build/Three.js index 2adec278..978da95a 100644 --- a/build/Three.js +++ b/build/Three.js @@ -138,9 +138,9 @@ new THREE.Vector3(b.x,b.y,b.z);this.geometry.skinVerticesA.push(c[k].multiplyVec THREE.MorphAnimMesh=function(a,c){THREE.Mesh.call(this,a,c);this.duration=1E3;this.mirroredLoop=!1;this.currentKeyframe=this.lastKeyframe=this.time=0;this.direction=1;this.directionBackwards=!1};THREE.MorphAnimMesh.prototype=new THREE.Mesh;THREE.MorphAnimMesh.prototype.constructor=THREE.MorphAnimMesh; THREE.MorphAnimMesh.prototype.updateAnimation=function(a){var c=this.duration/(this.geometry.morphTargets.length-1);this.time+=this.direction*a;if(this.mirroredLoop){if(this.time>this.duration||this.time<0){this.direction*=-1;if(this.time>this.duration)this.time=this.duration,this.directionBackwards=!0;if(this.time<0)this.time=0,this.directionBackwards=!1}}else this.time%=this.duration;a=THREE.Math.clamp(Math.floor(this.time/c),0,this.geometry.morphTargets.length-1);if(a!=this.currentKeyframe)this.morphTargetInfluences[this.lastKeyframe]= 0,this.morphTargetInfluences[this.currentKeyframe]=1,this.morphTargetInfluences[a]=0,this.lastKeyframe=this.currentKeyframe,this.currentKeyframe=a;c=this.time%c/c;this.directionBackwards&&(c=1-c);this.morphTargetInfluences[this.currentKeyframe]=c;this.morphTargetInfluences[this.lastKeyframe]=1-c};THREE.Ribbon=function(a,c){THREE.Object3D.call(this);this.geometry=a;this.material=c};THREE.Ribbon.prototype=new THREE.Object3D;THREE.Ribbon.prototype.constructor=THREE.Ribbon; -THREE.LOD=function(){THREE.Object3D.call(this);this.LODs=[]};THREE.LOD.prototype=new THREE.Object3D;THREE.LOD.prototype.constructor=THREE.LOD;THREE.LOD.prototype.supr=THREE.Object3D.prototype;THREE.LOD.prototype.addLevel=function(a,c){c===void 0&&(c=0);for(var c=Math.abs(c),b=0;b1){a=b.matrixWorldInverse;a=-(a.n31*this.position.x+a.n32*this.position.y+a.n33*this.position.z+a.n34);this.LODs[0].object3D.visible=!0;for(var e=1;e=this.LODs[e].visibleAtDistance)this.LODs[e-1].object3D.visible=!1, -this.LODs[e].object3D.visible=!0;else break;for(;e1){var c=c.matrixWorldInverse,b=-(c.n31*this.position.x+c.n32*this.position.y+c.n33*this.position.z+c.n34);this.LODs[0].object3D.visible=!0;for(c=1;c=this.LODs[c].visibleAtDistance)this.LODs[c- +1].object3D.visible=!1,this.LODs[c].object3D.visible=!0;else break;for(;c1){a=c.matrixWorldInverse;a=-(a.n31*this.position.x+a.n32*this.position.y+a.n33*this.position.z+a.n34);this.LODs[0].object3D.visible=!0;for(var e=1;e=this.LODs[e].visibleAtDistance)this.LODs[e-1].object3D.visible=!1, -this.LODs[e].object3D.visible=!0;else break;for(;e1){var b=b.matrixWorldInverse,c=-(b.n31*this.position.x+b.n32*this.position.y+b.n33*this.position.z+b.n34);this.LODs[0].object3D.visible=!0;for(b=1;b=this.LODs[b].visibleAtDistance)this.LODs[b- +1].object3D.visible=!1,this.LODs[b].object3D.visible=!0;else break;for(;b=0)b=b.geometry.materials[d],b.transparent?(a.transparent=b,a.opaque=null):(a.opaque=b,a.transparent=null)}else if(b=c)b.transparent?(a.transparent=b, +Math.max(a.scale.y,a.scale.z)),c=0;c<6;c++)if(a=Z[c].x*b.n14+Z[c].y*b.n24+Z[c].z*b.n34+Z[c].w,a<=d)return!1;return!0}function r(a){var b=a.object.material;b.transparent?(a.transparent=b,a.opaque=null):(a.opaque=b,a.transparent=null)}function v(a){var b=a.object,c=a.buffer,d;d=b.material;if(d instanceof THREE.MeshFaceMaterial){if(c=c.materialIndex,c>=0)b=b.geometry.materials[c],b.transparent?(a.transparent=b,a.opaque=null):(a.opaque=b,a.transparent=null)}else if(b=d)b.transparent?(a.transparent=b, a.opaque=null):(a.opaque=b,a.transparent=null)}function z(a,b){return b.z-a.z}function B(a){var b,c,n,sa=0,J,l,u,p,q=a.lights;ja||(ja=new THREE.PerspectiveCamera(A.shadowCameraFov,A.shadowMapWidth/A.shadowMapHeight,A.shadowCameraNear,A.shadowCameraFar));b=0;for(c=q.length;b - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/webgl_lod.html b/examples/webgl_lod.html index c447483a..78760fe3 100644 --- a/examples/webgl_lod.html +++ b/examples/webgl_lod.html @@ -35,8 +35,126 @@ three.js - level-of-details WebGL example - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -96,7 +214,7 @@ for ( j = 0; j < 1000; j ++ ) { - lod = new THREE.LOD(); + lod = new THREE.LOD( camera ); for ( i = 0; i < geometry.length; i++ ) { diff --git a/examples/webgl_lod_text.html b/examples/webgl_lod_text.html index 1bb672b0..490d9d7d 100644 --- a/examples/webgl_lod_text.html +++ b/examples/webgl_lod_text.html @@ -129,7 +129,7 @@ for ( j = 0; j < 1000; j ++ ) { - lod = new THREE.LOD(); + lod = new THREE.LOD( camera ); for ( i = 0; i < geometry.length; i++ ) { diff --git a/src/objects/LOD.js b/src/objects/LOD.js index 142075f6..14d1f9f8 100644 --- a/src/objects/LOD.js +++ b/src/objects/LOD.js @@ -1,11 +1,13 @@ /** * @author mikael emtinger / http://gomo.se/ + * @author alteredq / http://alteredqualia.com/ */ -THREE.LOD = function() { +THREE.LOD = function( camera ) { THREE.Object3D.call( this ); + this.camera = camera; this.LODs = []; }; @@ -43,28 +45,17 @@ THREE.LOD.prototype.addLevel = function ( object3D, visibleAtDistance ) { }; +THREE.LOD.prototype.updateMatrixWorld = function ( force ) { -/* - * Update - */ + this.matrixAutoUpdate && this.updateMatrix(); -THREE.LOD.prototype.update = function ( parentMatrixWorld, forceUpdate, camera ) { + // update matrixWorld - // update local + if ( this.matrixWorldNeedsUpdate || force ) { - if ( this.matrixAutoUpdate ) { + if ( this.parent ) { - forceUpdate |= this.updateMatrix(); - - } - - // update global - - if ( forceUpdate || this.matrixWorldNeedsUpdate ) { - - if ( parentMatrixWorld ) { - - this.matrixWorld.multiply( parentMatrixWorld, this.matrix ); + this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix ); } else { @@ -73,15 +64,16 @@ THREE.LOD.prototype.update = function ( parentMatrixWorld, forceUpdate, camera ) } this.matrixWorldNeedsUpdate = false; - forceUpdate = true; + + force = true; } - // update LODs - if ( this.LODs.length > 1 ) { + var camera = this.camera; + if ( this.LODs.length > 1 ) { var inverse = camera.matrixWorldInverse; var radius = this.boundRadius * this.boundRadiusScale; @@ -112,13 +104,13 @@ THREE.LOD.prototype.update = function ( parentMatrixWorld, forceUpdate, camera ) } + // update children - for ( var c = 0; c < this.children.length; c++ ) { + for ( var i = 0, l = this.children.length; i < l; i ++ ) { - this.children[ c ].update( this.matrixWorld, forceUpdate, camera ); + this.children[ i ].updateMatrixWorld( force ); } - };