Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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