ThreeJS onMaterialDispose

105 阅读1分钟
function onMaterialDispose(event) {
        const material = event.target;

        material.removeEventListener('dispose', onMaterialDispose);

        deallocateMaterial(material);
}

// Buffer deallocation

function deallocateMaterial(material) {
        releaseMaterialProgramReference(material);

        properties.remove(material);
}

function releaseMaterialProgramReference(material) {
        const programInfo = properties.get(material).program;

        if (programInfo !== undefined) {
                programCache.releaseProgram(programInfo);
        }
}