addPipelineExtras.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. ForEach.compressedImage(image, function(compressedImage) {
  22. addExtras(compressedImage);
  23. });
  24. });
  25. addExtras(gltf);
  26. return gltf;
  27. }
  28. function addExtras(object) {
  29. object.extras = defined(object.extras) ? object.extras : {};
  30. object.extras._pipeline = defined(object.extras._pipeline) ? object.extras._pipeline : {};
  31. }
  32. export default addPipelineExtras;