Răsfoiți Sursa

MMDLoader: Add dispose() to helper classes. (#24670)

Michael Herzog 2 ani în urmă
părinte
comite
4844199ecb

+ 24 - 0
examples/jsm/animation/CCDIKSolver.js

@@ -393,6 +393,30 @@ class CCDIKHelper extends Object3D {
 
 	}
 
+	/**
+	 * Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
+	 */
+	dispose() {
+
+		this.sphereGeometry.dispose();
+
+		this.targetSphereMaterial.dispose();
+		this.effectorSphereMaterial.dispose();
+		this.linkSphereMaterial.dispose();
+		this.lineMaterial.dispose();
+
+		const children = this.children;
+
+		for ( let i = 0; i < children.length; i ++ ) {
+
+			const child = children[ i ];
+
+			if ( child.isLine ) child.geometry.dispose();
+
+		}
+
+	}
+
 	// private method
 
 	_init() {

+ 25 - 0
examples/jsm/animation/MMDPhysics.js

@@ -1292,6 +1292,31 @@ class MMDPhysicsHelper extends Object3D {
 
 	}
 
+
+	/**
+	 * Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
+	 */
+	dispose() {
+
+		const materials = this.materials;
+		const children = this.children;
+
+		for ( let i = 0; i < materials.length; i ++ ) {
+
+			materials[ i ].dispose();
+
+		}
+
+		for ( let i = 0; i < children.length; i ++ ) {
+
+			const child = children[ i ];
+
+			if ( child.isMesh ) child.geometry.dispose();
+
+		}
+
+	}
+
 	/**
 	 * Updates Rigid Bodies visualization.
 	 */