GC.js 742 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // 材质销毁
  2. const materialDispose = (material) => {
  3. if (material instanceof Array) {
  4. material.forEach(materialDispose)
  5. } else {
  6. if (material.map) {
  7. material.map.dispose()
  8. }
  9. material.dispose()
  10. }
  11. }
  12. // 销毁
  13. const deallocate = (obj) => {
  14. if (obj.geometry) {
  15. obj.geometry.dispose()
  16. }
  17. if (obj.material) {
  18. materialDispose(obj.material)
  19. }
  20. if (obj.texture) {
  21. obj.texture.dispose()
  22. }
  23. if (obj.children) {
  24. obj.children.forEach(deallocate)
  25. }
  26. }
  27. // 清空对象
  28. const emptyObject = (obj) => {
  29. if (obj && obj.children)
  30. while (obj.children.length) {
  31. const childObj = obj.children[0]
  32. obj.remove(childObj)
  33. deallocate(childObj)
  34. }
  35. }
  36. export { emptyObject, deallocate }