addPipelineExtras.js 929 B

123456789101112131415161718192021222324252627282930313233343536
  1. import ForEach from "./ForEach.js";
  2. import defined from "../../Core/defined.js";
  3. /**
  4. * Adds extras._pipeline to each object that can have extras in the glTF asset.
  5. * This stage runs before updateVersion and handles both glTF 1.0 and glTF 2.0 assets.
  6. *
  7. * @param {Object} gltf A javascript object containing a glTF asset.
  8. * @returns {Object} The glTF asset with the added pipeline extras.
  9. *
  10. * @private
  11. */
  12. function addPipelineExtras(gltf) {
  13. ForEach.shader(gltf, function (shader) {
  14. addExtras(shader);
  15. });
  16. ForEach.buffer(gltf, function (buffer) {
  17. addExtras(buffer);
  18. });
  19. ForEach.image(gltf, function (image) {
  20. addExtras(image);
  21. });
  22. addExtras(gltf);
  23. return gltf;
  24. }
  25. function addExtras(object) {
  26. object.extras = defined(object.extras) ? object.extras : {};
  27. object.extras._pipeline = defined(object.extras._pipeline)
  28. ? object.extras._pipeline
  29. : {};
  30. }
  31. export default addPipelineExtras;