kitchen-simulator
Version:
It is a kitchen simulator (self-contained micro-frontend).
51 lines (50 loc) • 1.18 kB
JavaScript
import * as Three from 'three';
function disposeGeometry(geometry) {
geometry.dispose();
}
function disposeTexture(texture) {
if (!texture) {
return;
}
texture.dispose();
}
function disposeMultimaterial(material) {
if (!(material.isMaterial && !Array.isArray(material))) {
return;
}
material.materials.forEach(function (material) {
disposeMaterial(material);
});
}
function disposeMaterial(material) {
if (!(material instanceof Three.Material)) {
return;
}
// disposeTexture(material.map);
// material.map = null;
material.dispose();
}
function disposeMesh(mesh) {
if (!(mesh instanceof Three.Mesh || mesh instanceof Three.BoxHelper || mesh instanceof Three.LineSegments)) {
return;
}
if (mesh.geometry) {
disposeGeometry(mesh.geometry);
}
// disposeMultimaterial(mesh.material);
disposeMaterial(mesh.material);
mesh.geometry = null;
mesh.material = null;
}
export function disposeScene(scene3D) {
scene3D.traverse(function (child) {
disposeMesh(child);
child = null;
});
}
export function disposeObject(object) {
object.traverse(function (child) {
disposeMesh(child);
child = null;
});
}