Explorar o código

LOD: Rename .objects to .levels. See #6661.

Mr.doob %!s(int64=10) %!d(string=hai) anos
pai
achega
13591237f0
Modificáronse 1 ficheiros con 32 adicións e 14 borrados
  1. 32 14
      src/objects/LOD.js

+ 32 - 14
src/objects/LOD.js

@@ -8,7 +8,18 @@ THREE.LOD = function () {
 
 	THREE.Object3D.call( this );
 
-	this.objects = [];
+	Object.defineProperties( this, {
+		levels: {
+			enumerable: true,
+			value: []
+		},
+		objects: {
+			get: function () {
+				console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
+				return this.levels;
+			}
+		}
+	} );
 
 };
 
@@ -22,9 +33,11 @@ THREE.LOD.prototype.addLevel = function ( object, distance ) {
 
 	distance = Math.abs( distance );
 
-	for ( var l = 0; l < this.objects.length; l ++ ) {
+	var levels = this.levels;
+
+	for ( var l = 0; l < levels.length; l ++ ) {
 
-		if ( distance < this.objects[ l ].distance ) {
+		if ( distance < levels[ l ].distance ) {
 
 			break;
 
@@ -32,16 +45,19 @@ THREE.LOD.prototype.addLevel = function ( object, distance ) {
 
 	}
 
-	this.objects.splice( l, 0, { distance: distance, object: object } );
+	levels.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 ++ ) {
+	var levels = this.levels;
+
+	for ( var i = 1, l = levels.length; i < l; i ++ ) {
 
-		if ( distance < this.objects[ i ].distance ) {
+		if ( distance < levels[ i ].distance ) {
 
 			break;
 
@@ -49,7 +65,7 @@ THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
 
 	}
 
-	return this.objects[ i - 1 ].object;
+	return levels[ i - 1 ].object;
 
 };
 
@@ -76,21 +92,23 @@ THREE.LOD.prototype.update = function () {
 
 	return function ( camera ) {
 
-		if ( this.objects.length > 1 ) {
+		var levels = this.levels;
+
+		if ( levels.length > 1 ) {
 
 			v1.setFromMatrixPosition( camera.matrixWorld );
 			v2.setFromMatrixPosition( this.matrixWorld );
 
 			var distance = v1.distanceTo( v2 );
 
-			this.objects[ 0 ].object.visible = true;
+			levels[ 0 ].object.visible = true;
 
-			for ( var i = 1, l = this.objects.length; i < l; i ++ ) {
+			for ( var i = 1, l = levels.length; i < l; i ++ ) {
 
-				if ( distance >= this.objects[ i ].distance ) {
+				if ( distance >= levels[ i ].distance ) {
 
-					this.objects[ i - 1 ].object.visible = false;
-					this.objects[ i     ].object.visible = true;
+					levels[ i - 1 ].object.visible = false;
+					levels[ i     ].object.visible = true;
 
 				} else {
 
@@ -102,7 +120,7 @@ THREE.LOD.prototype.update = function () {
 
 			for ( ; i < l; i ++ ) {
 
-				this.objects[ i ].object.visible = false;
+				levels[ i ].object.visible = false;
 
 			}