removePipelineExtras.js 902 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. });
  21. removeExtras(gltf);
  22. return gltf;
  23. }
  24. function removeExtras(object) {
  25. if (!defined(object.extras)) {
  26. return;
  27. }
  28. if (defined(object.extras._pipeline)) {
  29. delete object.extras._pipeline;
  30. }
  31. if (Object.keys(object.extras).length === 0) {
  32. delete object.extras;
  33. }
  34. }
  35. export default removePipelineExtras;