ModelLoadResources.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. */
  36. function getSubarray(array, offset, length) {
  37. return array.subarray(offset, offset + length);
  38. }
  39. ModelLoadResources.prototype.getBuffer = function(bufferView) {
  40. return getSubarray(this.buffers[bufferView.buffer], bufferView.byteOffset, bufferView.byteLength);
  41. };
  42. ModelLoadResources.prototype.finishedPendingBufferLoads = function() {
  43. return (this.pendingBufferLoads === 0);
  44. };
  45. ModelLoadResources.prototype.finishedBuffersCreation = function() {
  46. return ((this.pendingBufferLoads === 0) &&
  47. (this.vertexBuffersToCreate.length === 0) &&
  48. (this.indexBuffersToCreate.length === 0));
  49. };
  50. ModelLoadResources.prototype.finishedProgramCreation = function() {
  51. return ((this.pendingShaderLoads === 0) && (this.programsToCreate.length === 0));
  52. };
  53. ModelLoadResources.prototype.finishedTextureCreation = function() {
  54. var finishedPendingLoads = (this.pendingTextureLoads === 0);
  55. var finishedResourceCreation =
  56. (this.texturesToCreate.length === 0) &&
  57. (this.texturesToCreateFromBufferView.length === 0);
  58. return finishedPendingLoads && finishedResourceCreation;
  59. };
  60. ModelLoadResources.prototype.finishedEverythingButTextureCreation = function() {
  61. var finishedPendingLoads =
  62. (this.pendingBufferLoads === 0) &&
  63. (this.pendingShaderLoads === 0);
  64. var finishedResourceCreation =
  65. (this.vertexBuffersToCreate.length === 0) &&
  66. (this.indexBuffersToCreate.length === 0) &&
  67. (this.programsToCreate.length === 0) &&
  68. (this.pendingBufferViewToImage === 0);
  69. return this.finishedDecoding() && finishedPendingLoads && finishedResourceCreation;
  70. };
  71. ModelLoadResources.prototype.finishedDecoding = function() {
  72. return this.primitivesToDecode.length === 0 && this.activeDecodingTasks === 0 && !this.pendingDecodingCache;
  73. };
  74. ModelLoadResources.prototype.finished = function() {
  75. return this.finishedDecoding() && this.finishedTextureCreation() && this.finishedEverythingButTextureCreation();
  76. };
  77. export default ModelLoadResources;