Skip to content

Instantly share code, notes, and snippets.

@rclai
Created August 10, 2015 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rclai/13635dbf5ecc05502c85 to your computer and use it in GitHub Desktop.
Save rclai/13635dbf5ecc05502c85 to your computer and use it in GitHub Desktop.
Recursive function that cleans up Three.js rendering
function doDispose (obj) {
if (obj !== null) {
for (var i = 0; i < obj.children.length; i++) {
doDispose(obj.children[i]);
}
if (obj.geometry) {
obj.geometry.dispose();
obj.geometry = undefined;
}
if (obj.material) {
if (obj.material.materials) {
for (i = 0; i < obj.material.materials.length; i++) {
obj.material.materials[i].dispose();
}
}
else {
obj.material.dispose();
}
obj.material = undefined;
}
if (obj.texture) {
obj.texture.dispose();
obj.texture = undefined;
}
}
obj = undefined;
}
doDispose(sceneObject);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment