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