ModelLoadResources.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import Queue from "../Core/Queue.js";
  2. /**
  3. * @private
  4. */
  5. function ModelLoadResources() {
  6. this.initialized = false;
  7. this.resourcesParsed = false;
  8. this.vertexBuffersToCreate = new Queue();
  9. this.indexBuffersToCreate = new Queue();
  10. this.buffers = {};
  11. this.pendingBufferLoads = 0;
  12. this.programsToCreate = new Queue();
  13. this.shaders = {};
  14. this.pendingShaderLoads = 0;
  15. this.texturesToCreate = new Queue();
  16. this.pendingTextureLoads = 0;
  17. this.texturesToCreateFromBufferView = new Queue();
  18. this.pendingBufferViewToImage = 0;
  19. this.createSamplers = true;
  20. this.createSkins = true;
  21. this.createRuntimeAnimations = true;
  22. this.createVertexArrays = true;
  23. this.createRenderStates = true;
  24. this.createUniformMaps = true;
  25. this.createRuntimeNodes = true;
  26. this.createdBufferViews = {};
  27. this.primitivesToDecode = new Queue();
  28. this.activeDecodingTasks = 0;
  29. this.pendingDecodingCache = false;
  30. this.skinnedNodesIds = [];
  31. }
  32. /**
  33. * This function differs from the normal subarray function
  34. * because it takes offset and length, rather than begin and end.
  35. * @private
  36. */
  37. function getSubarray(array, offset, length) {
  38. return array.subarray(offset, offset + length);
  39. }
  40. ModelLoadResources.prototype.getBuffer = function (bufferView) {
  41. return getSubarray(
  42. this.buffers[bufferView.buffer],
  43. bufferView.byteOffset,
  44. bufferView.byteLength
  45. );
  46. };
  47. ModelLoadResources.prototype.finishedPendingBufferLoads = function () {
  48. return this.pendingBufferLoads === 0;
  49. };
  50. ModelLoadResources.prototype.finishedBuffersCreation = function () {
  51. return (
  52. this.pendingBufferLoads === 0 &&
  53. this.vertexBuffersToCreate.length === 0 &&
  54. this.indexBuffersToCreate.length === 0
  55. );
  56. };
  57. ModelLoadResources.prototype.finishedProgramCreation = function () {
  58. return this.pendingShaderLoads === 0 && this.programsToCreate.length === 0;
  59. };
  60. ModelLoadResources.prototype.finishedTextureCreation = function () {
  61. const finishedPendingLoads = this.pendingTextureLoads === 0;
  62. const finishedResourceCreation =
  63. this.texturesToCreate.length === 0 &&
  64. this.texturesToCreateFromBufferView.length === 0;
  65. return finishedPendingLoads && finishedResourceCreation;
  66. };
  67. ModelLoadResources.prototype.finishedEverythingButTextureCreation = function () {
  68. const finishedPendingLoads =
  69. this.pendingBufferLoads === 0 && this.pendingShaderLoads === 0;
  70. const finishedResourceCreation =
  71. this.vertexBuffersToCreate.length === 0 &&
  72. this.indexBuffersToCreate.length === 0 &&
  73. this.programsToCreate.length === 0 &&
  74. this.pendingBufferViewToImage === 0;
  75. return (
  76. this.finishedDecoding() && finishedPendingLoads && finishedResourceCreation
  77. );
  78. };
  79. ModelLoadResources.prototype.finishedDecoding = function () {
  80. return (
  81. this.primitivesToDecode.length === 0 &&
  82. this.activeDecodingTasks === 0 &&
  83. !this.pendingDecodingCache
  84. );
  85. };
  86. ModelLoadResources.prototype.finished = function () {
  87. return (
  88. this.finishedDecoding() &&
  89. this.finishedTextureCreation() &&
  90. this.finishedEverythingButTextureCreation()
  91. );
  92. };
  93. export default ModelLoadResources;