| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /**
- * @author mikael emtinger / http://gomo.se/
- * @author alteredq / http://alteredqualia.com/
- * @author mrdoob / http://mrdoob.com/
- */
- THREE.LOD = function () {
- THREE.Object3D.call( this );
- this.objects = [];
- };
- THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
- THREE.LOD.prototype.addLevel = function ( object, distance ) {
- if ( distance === undefined ) distance = 0;
- distance = Math.abs( distance );
- for ( var l = 0; l < this.objects.length; l ++ ) {
- if ( distance < this.objects[ l ].distance ) {
- break;
- }
- }
- this.objects.splice( l, 0, { distance: distance, object: object } );
- this.add( object );
- };
- THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
- for ( var i = 1, l = this.objects.length; i < l; i ++ ) {
- if ( distance < this.objects[ i ].distance ) {
- break;
- }
- }
- return this.objects[ i - 1 ].object;
- };
- THREE.LOD.prototype.update = function () {
- var v1 = new THREE.Vector3();
- var v2 = new THREE.Vector3();
- return function ( camera ) {
- if ( this.objects.length > 1 ) {
- v1.getPositionFromMatrix( camera.matrixWorld );
- v2.getPositionFromMatrix( this.matrixWorld );
- var distance = v1.distanceTo( v2 );
- this.objects[ 0 ].object.visible = true;
- for ( var i = 1, l = this.objects.length; i < l; i ++ ) {
- if ( distance >= this.objects[ i ].distance ) {
- this.objects[ i - 1 ].object.visible = false;
- this.objects[ i ].object.visible = true;
- } else {
- break;
- }
- }
- for( ; i < l; i ++ ) {
- this.objects[ i ].object.visible = false;
- }
- }
- };
- }();
- THREE.LOD.prototype.clone = function () {
- // TODO
- };
|