#72 epic refactoring
This commit is contained in:
+40
-1
@@ -86,7 +86,46 @@ function bottomOrigin(object){
|
||||
return group;
|
||||
}
|
||||
|
||||
function clearObject(o){
|
||||
let disposables = []
|
||||
o.traverse(object => {
|
||||
if (object.isMesh) {
|
||||
disposables.push(object);
|
||||
}
|
||||
if (object.isLight){
|
||||
object.shadow?.map?.dispose();
|
||||
object.shadow?.dispose();
|
||||
object.dispose();
|
||||
}
|
||||
if (object.userData?._io){
|
||||
object.userData._io.dispose?.();
|
||||
}
|
||||
});
|
||||
disposables.forEach(object=>{
|
||||
object.removeFromParent();
|
||||
object.geometry.dispose();
|
||||
if (object.material.isMaterial) {
|
||||
clearMaterial(object.material)
|
||||
} else {
|
||||
for (const material of object.material) clearMaterial(material)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function clearMaterial(material) {
|
||||
material.dispose();
|
||||
for (const key of Object.keys(material)) {
|
||||
const value = material[key]
|
||||
if (value && typeof value == 'object' && 'minFilter' in value) {
|
||||
//console.log('Disposing', value.name, this.renderer.info.memory.textures );
|
||||
value.dispose();
|
||||
//console.log('Disposed', value.name, this.renderer.info.memory.textures );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
assignParams, assignMaterial, autoScale, centerOrigin, wrapInGroup, bottomOrigin,
|
||||
getBoundingBox, getBoundingBoxSize, getBoundingBoxMaxLength, getBoundingBoxCenterPoint
|
||||
getBoundingBox, getBoundingBoxSize, getBoundingBoxMaxLength, getBoundingBoxCenterPoint,
|
||||
clearObject, clearMaterial
|
||||
}
|
||||
Reference in New Issue
Block a user