removePipelineExtras.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import ForEach from './ForEach.js'
  2. import defined from '../../Core/defined.js'
  3. /**
  4. * Iterate through the objects within the glTF and delete their pipeline extras object.
  5. *
  6. * @param {Object} gltf A javascript object containing a glTF asset.
  7. * @returns {Object} glTF with no pipeline extras.
  8. *
  9. * @private
  10. */
  11. function removePipelineExtras(gltf) {
  12. ForEach.shader(gltf, function(shader) {
  13. removeExtras(shader);
  14. });
  15. ForEach.buffer(gltf, function(buffer) {
  16. removeExtras(buffer);
  17. });
  18. ForEach.image(gltf, function (image) {
  19. removeExtras(image);
  20. ForEach.compressedImage(image, function(compressedImage) {
  21. removeExtras(compressedImage);
  22. });
  23. });
  24. removeExtras(gltf);
  25. return gltf;
  26. }
  27. function removeExtras(object) {
  28. if (!defined(object.extras)) {
  29. return;
  30. }
  31. if (defined(object.extras._pipeline)) {
  32. delete object.extras._pipeline;
  33. }
  34. if (Object.keys(object.extras).length === 0) {
  35. delete object.extras;
  36. }
  37. }
  38. export default removePipelineExtras;