-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory leak when switching from first person view
- Loading branch information
1 parent
d304ee2
commit 3d78ee9
Showing
2 changed files
with
70 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
function disposeGeometry(geometry) { | ||
geometry.dispose(); | ||
} | ||
|
||
function disposeTexture(texture) { | ||
if (!texture) { | ||
return; | ||
} | ||
texture.dispose(); | ||
} | ||
|
||
function disposeMultimaterial(material) { | ||
if (!(material instanceof Three.MultiMaterial)) { | ||
return; | ||
} | ||
material.materials.forEach(material => { | ||
disposeMaterial(material); | ||
}); | ||
|
||
} | ||
|
||
function disposeMaterial(material) { | ||
if (!(material instanceof Three.Material)) { | ||
return; | ||
} | ||
|
||
disposeTexture(material.map); | ||
material.dispose(); | ||
} | ||
|
||
function disposeMesh(scene3D, mesh) { | ||
if (!(mesh instanceof Three.Mesh || mesh instanceof Three.BoxHelper)) { | ||
return; | ||
} | ||
scene3D.remove(mesh); | ||
disposeGeometry(mesh.geometry); | ||
disposeMultimaterial(mesh.material); | ||
disposeMaterial(mesh.material); | ||
} | ||
|
||
export function disposeScene(scene3D) { | ||
scene3D.traverse(child => { | ||
disposeMesh(scene3D, child); | ||
}); | ||
} | ||
|
||
export function disposeObject(scene3D, object) { | ||
object.traverse(child => { | ||
disposeMesh(scene3D, child); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters