Skip to content

Commit 4844199

Browse files
authored
MMDLoader: Add dispose() to helper classes. (#24670)
1 parent 1c1a861 commit 4844199

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

examples/jsm/animation/CCDIKSolver.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,30 @@ class CCDIKHelper extends Object3D {
393393

394394
}
395395

396+
/**
397+
* Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
398+
*/
399+
dispose() {
400+
401+
this.sphereGeometry.dispose();
402+
403+
this.targetSphereMaterial.dispose();
404+
this.effectorSphereMaterial.dispose();
405+
this.linkSphereMaterial.dispose();
406+
this.lineMaterial.dispose();
407+
408+
const children = this.children;
409+
410+
for ( let i = 0; i < children.length; i ++ ) {
411+
412+
const child = children[ i ];
413+
414+
if ( child.isLine ) child.geometry.dispose();
415+
416+
}
417+
418+
}
419+
396420
// private method
397421

398422
_init() {

examples/jsm/animation/MMDPhysics.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,31 @@ class MMDPhysicsHelper extends Object3D {
12921292

12931293
}
12941294

1295+
1296+
/**
1297+
* Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
1298+
*/
1299+
dispose() {
1300+
1301+
const materials = this.materials;
1302+
const children = this.children;
1303+
1304+
for ( let i = 0; i < materials.length; i ++ ) {
1305+
1306+
materials[ i ].dispose();
1307+
1308+
}
1309+
1310+
for ( let i = 0; i < children.length; i ++ ) {
1311+
1312+
const child = children[ i ];
1313+
1314+
if ( child.isMesh ) child.geometry.dispose();
1315+
1316+
}
1317+
1318+
}
1319+
12951320
/**
12961321
* Updates Rigid Bodies visualization.
12971322
*/

0 commit comments

Comments
 (0)