pages235/renderer/viewer/three/threeJsUtils.ts
2025-03-25 04:01:43 +03:00

18 lines
578 B
TypeScript

import * as THREE from 'three'
export const disposeObject = (obj: THREE.Object3D, cleanTextures = false) => {
// not cleaning texture there as it might be used by other objects, but would be good to also do that
if (obj instanceof THREE.Mesh) {
obj.geometry?.dispose?.()
obj.material?.dispose?.()
}
if (obj.children) {
// eslint-disable-next-line unicorn/no-array-for-each
obj.children.forEach(child => disposeObject(child, cleanTextures))
}
if (cleanTextures) {
if (obj instanceof THREE.Mesh) {
obj.material?.map?.dispose?.()
}
}
}