Przeglądaj źródła

LOD: Add `removeLevel()`. (#29359)

* feat(app): 29074 Add removeLevel method for LOD

* fix: rename parameter

* refactor: using for loop

* refactor: apply suggestions in method structure

* Update LOD.html

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
Jaime A Torrealba C 1 tydzień temu
rodzic
commit
f51df3879e
2 zmienionych plików z 30 dodań i 0 usunięć
  1. 9 0
      docs/api/en/objects/LOD.html
  2. 21 0
      src/objects/LOD.js

+ 9 - 0
docs/api/en/objects/LOD.html

@@ -85,6 +85,15 @@
 			Adds a mesh that will display at a certain distance and greater. Typically
 			the further away the distance, the lower the detail on the mesh.
 		</p>
+		<h3>
+			[method:Boolean removeLevel]( [param:Float distance])
+		</h3>
+		<p>
+			distance - Distance of the level to delete.<br /><br />
+
+			Removes an existing level, based on the distance from the camera.
+			Returns `true` when the level has been removed. Otherwise `false`.
+		</p>
 
 		<h3>[method:Integer getCurrentLevel]()</h3>
 		<p>Get the currently active LOD level. As index of the levels array.</p>

+ 21 - 0
src/objects/LOD.js

@@ -74,6 +74,27 @@ class LOD extends Object3D {
 
 	}
 
+	removeLevel( distance ) {
+
+		const levels = this.levels;
+
+		for ( let i = 0; i < levels.length; i ++ ) {
+
+			if ( levels[ i ].distance === distance ) {
+
+				const removedElements = levels.splice( i, 1 );
+				this.remove( removedElements[ 0 ].object );
+
+				return true;
+
+			}
+
+		}
+
+		return false;
+
+	}
+
 	getCurrentLevel() {
 
 		return this._currentLevel;