浏览代码

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

Michael Herzog 2 年之前
父节点
当前提交
4844199ecb
共有 2 个文件被更改,包括 49 次插入0 次删除
  1. 24 0
      examples/jsm/animation/CCDIKSolver.js
  2. 25 0
      examples/jsm/animation/MMDPhysics.js

+ 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
 	// private method
 
 
 	_init() {
 	_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.
 	 * Updates Rigid Bodies visualization.
 	 */
 	 */