@galacean/engine-loader 1.1.0-beta.16 → 1.1.0-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -120,116 +120,116 @@ var BufferReader = /*#__PURE__*/ function() {
120
120
  this.data = data;
121
121
  this._dataView = new DataView(data.buffer, data.byteOffset + byteOffset, byteLength != null ? byteLength : data.byteLength - byteOffset);
122
122
  this._littleEndian = littleEndian;
123
- this._offset = 0;
123
+ this._position = 0;
124
124
  this._baseOffset = byteOffset;
125
125
  }
126
126
  var _proto = BufferReader.prototype;
127
127
  _proto.nextUint8 = function nextUint8() {
128
- var value = this._dataView.getUint8(this._offset);
129
- this._offset += 1;
128
+ var value = this._dataView.getUint8(this._position);
129
+ this._position += 1;
130
130
  return value;
131
131
  };
132
132
  _proto.nextUint16 = function nextUint16() {
133
- var value = this._dataView.getUint16(this._offset, this._littleEndian);
134
- this._offset += 2;
133
+ var value = this._dataView.getUint16(this._position, this._littleEndian);
134
+ this._position += 2;
135
135
  return value;
136
136
  };
137
137
  _proto.nextUint32 = function nextUint32() {
138
- var value = this._dataView.getUint32(this._offset, this._littleEndian);
139
- this._offset += 4;
138
+ var value = this._dataView.getUint32(this._position, this._littleEndian);
139
+ this._position += 4;
140
140
  return value;
141
141
  };
142
142
  _proto.nextInt32 = function nextInt32() {
143
- var value = this._dataView.getInt32(this._offset, this._littleEndian);
144
- this._offset += 4;
143
+ var value = this._dataView.getInt32(this._position, this._littleEndian);
144
+ this._position += 4;
145
145
  return value;
146
146
  };
147
147
  _proto.nextInt32Array = function nextInt32Array(len) {
148
- var value = new Int32Array(this.data.buffer, this._offset + this._dataView.byteOffset, len);
149
- this._offset += 4 * len;
148
+ var value = new Int32Array(this.data.buffer, this._position + this._dataView.byteOffset, len);
149
+ this._position += 4 * len;
150
150
  return value;
151
151
  };
152
152
  _proto.nextFloat32 = function nextFloat32() {
153
- var value = this._dataView.getFloat32(this._offset, this._littleEndian);
154
- this._offset += 4;
153
+ var value = this._dataView.getFloat32(this._position, this._littleEndian);
154
+ this._position += 4;
155
155
  return value;
156
156
  };
157
157
  _proto.nextFloat32Array = function nextFloat32Array(len) {
158
- var value = new Float32Array(this.data.buffer, this._offset + this._dataView.byteOffset, len);
159
- this._offset += 4 * len;
158
+ var value = new Float32Array(this.data.buffer, this._position + this._dataView.byteOffset, len);
159
+ this._position += 4 * len;
160
160
  return value;
161
161
  };
162
162
  _proto.nextUint32Array = function nextUint32Array(len) {
163
- var value = new Uint32Array(this.data.buffer, this._offset + this._dataView.byteOffset, len);
164
- this._offset += 4 * len;
163
+ var value = new Uint32Array(this.data.buffer, this._position + this._dataView.byteOffset, len);
164
+ this._position += 4 * len;
165
165
  return value;
166
166
  };
167
167
  _proto.nextUint8Array = function nextUint8Array(len) {
168
- var value = new Uint8Array(this.data.buffer, this._offset + this._dataView.byteOffset, len);
169
- this._offset += len;
168
+ var value = new Uint8Array(this.data.buffer, this._position + this._dataView.byteOffset, len);
169
+ this._position += len;
170
170
  return value;
171
171
  };
172
172
  _proto.nextUint64 = function nextUint64() {
173
- var left = this._dataView.getUint32(this._offset, this._littleEndian);
174
- var right = this._dataView.getUint32(this._offset + 4, this._littleEndian);
173
+ var left = this._dataView.getUint32(this._position, this._littleEndian);
174
+ var right = this._dataView.getUint32(this._position + 4, this._littleEndian);
175
175
  var value = left + Math.pow(2, 32) * right;
176
- this._offset += 8;
176
+ this._position += 8;
177
177
  return value;
178
178
  };
179
179
  _proto.nextStr = function nextStr() {
180
180
  var strByteLength = this.nextUint16();
181
- var uint8Array = new Uint8Array(this.data.buffer, this._offset + this._dataView.byteOffset, strByteLength);
182
- this._offset += strByteLength;
181
+ var uint8Array = new Uint8Array(this.data.buffer, this._position + this._dataView.byteOffset, strByteLength);
182
+ this._position += strByteLength;
183
183
  return engineCore.Utils.decodeText(uint8Array);
184
184
  };
185
185
  /**
186
186
  * image data 放在最后
187
187
  */ _proto.nextImageData = function nextImageData(count) {
188
- return new Uint8Array(this.data.buffer, this.data.byteOffset + this._offset);
188
+ return new Uint8Array(this.data.buffer, this.data.byteOffset + this._position);
189
189
  };
190
190
  _proto.nextImagesData = function nextImagesData(count) {
191
191
  var imagesLen = new Array(count);
192
192
  // Start offset of Uint32Array should be a multiple of 4. ref: https://stackoverflow.com/questions/15417310/why-typed-array-constructors-require-offset-to-be-multiple-of-underlying-type-si
193
193
  for(var i = 0; i < count; i++){
194
- var len = this._dataView.getUint32(this._offset, this._littleEndian);
194
+ var len = this._dataView.getUint32(this._position, this._littleEndian);
195
195
  imagesLen[i] = len;
196
- this._offset += 4;
196
+ this._position += 4;
197
197
  }
198
198
  var imagesData = [];
199
199
  for(var i1 = 0; i1 < count; i1++){
200
200
  var len1 = imagesLen[i1];
201
- var buffer = new Uint8Array(this.data.buffer, this._dataView.byteOffset + this._offset, len1);
202
- this._offset += len1;
201
+ var buffer = new Uint8Array(this.data.buffer, this._dataView.byteOffset + this._position, len1);
202
+ this._position += len1;
203
203
  imagesData.push(buffer);
204
204
  }
205
205
  return imagesData;
206
206
  };
207
207
  _proto.skip = function skip(bytes) {
208
- this._offset += bytes;
208
+ this._position += bytes;
209
209
  return this;
210
210
  };
211
211
  _proto.scan = function scan(maxByteLength, term) {
212
212
  if (term === void 0) term = 0x00;
213
- var byteOffset = this._offset;
213
+ var byteOffset = this._position;
214
214
  var byteLength = 0;
215
- while(this._dataView.getUint8(this._offset) !== term && byteLength < maxByteLength){
215
+ while(this._dataView.getUint8(this._position) !== term && byteLength < maxByteLength){
216
216
  byteLength++;
217
- this._offset++;
217
+ this._position++;
218
218
  }
219
- if (byteLength < maxByteLength) this._offset++;
219
+ if (byteLength < maxByteLength) this._position++;
220
220
  return new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + byteOffset, byteLength);
221
221
  };
222
222
  _create_class(BufferReader, [
223
223
  {
224
224
  key: "position",
225
225
  get: function get() {
226
- return this._offset;
226
+ return this._position;
227
227
  }
228
228
  },
229
229
  {
230
230
  key: "offset",
231
231
  get: function get() {
232
- return this._offset + this._baseOffset;
232
+ return this._position + this._baseOffset;
233
233
  }
234
234
  }
235
235
  ]);
@@ -293,75 +293,74 @@ exports.MeshDecoder = /*#__PURE__*/ function() {
293
293
  var encodedMeshData = JSON.parse(jsonDataString);
294
294
  // @ts-ignore Vector3 is not compatible with {x: number, y: number, z: number}.
295
295
  encodedMeshData.bounds && modelMesh.bounds.copyFrom(encodedMeshData.bounds);
296
- var offset = Math.ceil(bufferReader.position / 4) * 4;
296
+ var offset = Math.ceil(bufferReader.offset / 4) * 4 + bufferReader.data.byteOffset;
297
297
  var buffer = bufferReader.data.buffer;
298
- var byteOffset = bufferReader.data.byteOffset;
299
- var float32Array = new Float32Array(buffer, encodedMeshData.positions.start + offset + byteOffset, (encodedMeshData.positions.end - encodedMeshData.positions.start) / 4);
298
+ var float32Array = new Float32Array(buffer, encodedMeshData.positions.start + offset, (encodedMeshData.positions.end - encodedMeshData.positions.start) / 4);
300
299
  var vertexCount = float32Array.length / 3;
301
300
  var positions = float32ArrayToVector3(float32Array, vertexCount);
302
301
  modelMesh.setPositions(positions);
303
302
  if (encodedMeshData.normals) {
304
- var float32Array1 = new Float32Array(buffer, encodedMeshData.normals.start + offset + byteOffset, (encodedMeshData.normals.end - encodedMeshData.normals.start) / 4);
303
+ var float32Array1 = new Float32Array(buffer, encodedMeshData.normals.start + offset, (encodedMeshData.normals.end - encodedMeshData.normals.start) / 4);
305
304
  var normals = float32ArrayToVector3(float32Array1, vertexCount);
306
305
  modelMesh.setNormals(normals);
307
306
  }
308
307
  if (encodedMeshData.uvs) {
309
- var float32Array2 = new Float32Array(buffer, encodedMeshData.uvs.start + offset + byteOffset, (encodedMeshData.uvs.end - encodedMeshData.uvs.start) / 4);
308
+ var float32Array2 = new Float32Array(buffer, encodedMeshData.uvs.start + offset, (encodedMeshData.uvs.end - encodedMeshData.uvs.start) / 4);
310
309
  modelMesh.setUVs(float32ArrayToVector2(float32Array2, vertexCount));
311
310
  }
312
311
  if (encodedMeshData.uv1) {
313
- var float32Array3 = new Float32Array(buffer, encodedMeshData.uv1.start + offset + byteOffset, (encodedMeshData.uv1.end - encodedMeshData.uv1.start) / 4);
312
+ var float32Array3 = new Float32Array(buffer, encodedMeshData.uv1.start + offset, (encodedMeshData.uv1.end - encodedMeshData.uv1.start) / 4);
314
313
  modelMesh.setUVs(float32ArrayToVector2(float32Array3, vertexCount), 1);
315
314
  }
316
315
  if (encodedMeshData.uv2) {
317
- var float32Array4 = new Float32Array(buffer, encodedMeshData.uv2.start + offset + byteOffset, (encodedMeshData.uv2.end - encodedMeshData.uv2.start) / 4);
316
+ var float32Array4 = new Float32Array(buffer, encodedMeshData.uv2.start + offset, (encodedMeshData.uv2.end - encodedMeshData.uv2.start) / 4);
318
317
  modelMesh.setUVs(float32ArrayToVector2(float32Array4, vertexCount), 2);
319
318
  }
320
319
  if (encodedMeshData.uv3) {
321
- var float32Array5 = new Float32Array(buffer, encodedMeshData.uv3.start + offset + byteOffset, (encodedMeshData.uv3.end - encodedMeshData.uv3.start) / 4);
320
+ var float32Array5 = new Float32Array(buffer, encodedMeshData.uv3.start + offset, (encodedMeshData.uv3.end - encodedMeshData.uv3.start) / 4);
322
321
  modelMesh.setUVs(float32ArrayToVector2(float32Array5, vertexCount), 3);
323
322
  }
324
323
  if (encodedMeshData.uv4) {
325
- var float32Array6 = new Float32Array(buffer, encodedMeshData.uv4.start + offset + byteOffset, (encodedMeshData.uv4.end - encodedMeshData.uv4.start) / 4);
324
+ var float32Array6 = new Float32Array(buffer, encodedMeshData.uv4.start + offset, (encodedMeshData.uv4.end - encodedMeshData.uv4.start) / 4);
326
325
  modelMesh.setUVs(float32ArrayToVector2(float32Array6, vertexCount), 4);
327
326
  }
328
327
  if (encodedMeshData.uv5) {
329
- var float32Array7 = new Float32Array(buffer, encodedMeshData.uv5.start + offset + byteOffset, (encodedMeshData.uv5.end - encodedMeshData.uv5.start) / 4);
328
+ var float32Array7 = new Float32Array(buffer, encodedMeshData.uv5.start + offset, (encodedMeshData.uv5.end - encodedMeshData.uv5.start) / 4);
330
329
  modelMesh.setUVs(float32ArrayToVector2(float32Array7, vertexCount), 5);
331
330
  }
332
331
  if (encodedMeshData.uv6) {
333
- var float32Array8 = new Float32Array(buffer, encodedMeshData.uv6.start + offset + byteOffset, (encodedMeshData.uv6.end - encodedMeshData.uv6.start) / 4);
332
+ var float32Array8 = new Float32Array(buffer, encodedMeshData.uv6.start + offset, (encodedMeshData.uv6.end - encodedMeshData.uv6.start) / 4);
334
333
  modelMesh.setUVs(float32ArrayToVector2(float32Array8, vertexCount), 6);
335
334
  }
336
335
  if (encodedMeshData.uv7) {
337
- var float32Array9 = new Float32Array(buffer, encodedMeshData.uv7.start + offset + byteOffset, (encodedMeshData.uv7.end - encodedMeshData.uv7.start) / 4);
336
+ var float32Array9 = new Float32Array(buffer, encodedMeshData.uv7.start + offset, (encodedMeshData.uv7.end - encodedMeshData.uv7.start) / 4);
338
337
  modelMesh.setUVs(float32ArrayToVector2(float32Array9, vertexCount), 7);
339
338
  }
340
339
  if (encodedMeshData.colors) {
341
- var float32Array10 = new Float32Array(buffer, encodedMeshData.colors.start + offset + byteOffset, (encodedMeshData.colors.end - encodedMeshData.colors.start) / 4);
340
+ var float32Array10 = new Float32Array(buffer, encodedMeshData.colors.start + offset, (encodedMeshData.colors.end - encodedMeshData.colors.start) / 4);
342
341
  modelMesh.setColors(float32ArrayToVColor(float32Array10, vertexCount));
343
342
  }
344
343
  if (encodedMeshData.boneWeights) {
345
- var float32Array11 = new Float32Array(buffer, encodedMeshData.boneWeights.start + offset + byteOffset, (encodedMeshData.boneWeights.end - encodedMeshData.boneWeights.start) / 4);
344
+ var float32Array11 = new Float32Array(buffer, encodedMeshData.boneWeights.start + offset, (encodedMeshData.boneWeights.end - encodedMeshData.boneWeights.start) / 4);
346
345
  modelMesh.setBoneWeights(float32ArrayToVector4(float32Array11, vertexCount));
347
346
  }
348
347
  if (encodedMeshData.boneIndices) {
349
- var float32Array12 = new Float32Array(buffer, encodedMeshData.boneIndices.start + offset + byteOffset, (encodedMeshData.boneIndices.end - encodedMeshData.boneIndices.start) / 4);
348
+ var float32Array12 = new Float32Array(buffer, encodedMeshData.boneIndices.start + offset, (encodedMeshData.boneIndices.end - encodedMeshData.boneIndices.start) / 4);
350
349
  modelMesh.setBoneIndices(float32ArrayToVector4(float32Array12, vertexCount));
351
350
  }
352
351
  if (encodedMeshData.blendShapes) {
353
352
  encodedMeshData.blendShapes.forEach(function(blendShapeData) {
354
353
  var blendShape = new engineCore.BlendShape(blendShapeData.name);
355
354
  blendShapeData.frames.forEach(function(frameData) {
356
- var positionArray = new Float32Array(buffer, frameData.deltaPosition.start + offset + byteOffset, (frameData.deltaPosition.end - frameData.deltaPosition.start) / 4);
355
+ var positionArray = new Float32Array(buffer, frameData.deltaPosition.start + offset, (frameData.deltaPosition.end - frameData.deltaPosition.start) / 4);
357
356
  var count = positionArray.length / 3;
358
357
  var deltaPosition = float32ArrayToVector3(positionArray, count);
359
358
  if (frameData.deltaNormals) {
360
- var normalsArray = new Float32Array(buffer, frameData.deltaNormals.start + offset + byteOffset, (frameData.deltaNormals.end - frameData.deltaNormals.start) / 4);
359
+ var normalsArray = new Float32Array(buffer, frameData.deltaNormals.start + offset, (frameData.deltaNormals.end - frameData.deltaNormals.start) / 4);
361
360
  float32ArrayToVector3(normalsArray, count);
362
361
  }
363
362
  if (frameData.deltaTangents) {
364
- var tangentsArray = new Float32Array(buffer, frameData.deltaTangents.start + offset + byteOffset, (frameData.deltaTangents.end - frameData.deltaTangents.start) / 4);
363
+ var tangentsArray = new Float32Array(buffer, frameData.deltaTangents.start + offset, (frameData.deltaTangents.end - frameData.deltaTangents.start) / 4);
365
364
  float32ArrayToVector4(tangentsArray, count);
366
365
  }
367
366
  blendShape.addFrame(frameData.weight, deltaPosition);
@@ -372,9 +371,9 @@ exports.MeshDecoder = /*#__PURE__*/ function() {
372
371
  if (encodedMeshData.indices) {
373
372
  var indices = null;
374
373
  if (encodedMeshData.indices.type === 0) {
375
- indices = new Uint16Array(buffer, encodedMeshData.indices.start + offset + byteOffset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 2);
374
+ indices = new Uint16Array(buffer, encodedMeshData.indices.start + offset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 2);
376
375
  } else {
377
- indices = new Uint32Array(buffer, encodedMeshData.indices.start + offset + byteOffset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 4);
376
+ indices = new Uint32Array(buffer, encodedMeshData.indices.start + offset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 4);
378
377
  }
379
378
  modelMesh.setIndices(indices);
380
379
  }
@@ -1603,11 +1602,37 @@ var TextureWrapMode;
1603
1602
  _this.get(9),
1604
1603
  _this.get(2)
1605
1604
  ]).then(function() {
1605
+ var glTFResource = _this.glTFResource;
1606
+ if (glTFResource.skins || glTFResource.animations) {
1607
+ _this._createAnimator(_this, glTFResource.animations);
1608
+ }
1606
1609
  _this.resourceManager.addContentRestorer(_this.contentRestorer);
1607
- return _this.glTFResource;
1610
+ return glTFResource;
1608
1611
  });
1609
1612
  });
1610
1613
  };
1614
+ _proto._createAnimator = function _createAnimator(context, animations) {
1615
+ var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
1616
+ var animator = defaultSceneRoot.addComponent(engineCore.Animator);
1617
+ var animatorController = new engineCore.AnimatorController();
1618
+ var layer = new engineCore.AnimatorControllerLayer("layer");
1619
+ var animatorStateMachine = new engineCore.AnimatorStateMachine();
1620
+ animatorController.addLayer(layer);
1621
+ animator.animatorController = animatorController;
1622
+ layer.stateMachine = animatorStateMachine;
1623
+ if (animations) {
1624
+ for(var i = 0; i < animations.length; i++){
1625
+ var animationClip = animations[i];
1626
+ var name = animationClip.name;
1627
+ var uniqueName = animatorStateMachine.makeUniqueStateName(name);
1628
+ if (uniqueName !== name) {
1629
+ console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
1630
+ }
1631
+ var animatorState = animatorStateMachine.addState(uniqueName);
1632
+ animatorState.clip = animationClip;
1633
+ }
1634
+ }
1635
+ };
1611
1636
  _proto._handleSubAsset = function _handleSubAsset(resource, type, index) {
1612
1637
  var _this = this;
1613
1638
  var glTFResourceKey = glTFResourceMap[type];
@@ -3533,6 +3558,7 @@ exports.GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3533
3558
  var promises = new Array();
3534
3559
  // parse samplers
3535
3560
  for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
3561
+ promises.push(context.get(exports.GLTFParserType.Scene));
3536
3562
  return Promise.all(promises).then(function() {
3537
3563
  for(var j = 0, m = channels.length; j < m; j++){
3538
3564
  var gltfChannel = channels[j];
@@ -3545,7 +3571,7 @@ exports.GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3545
3571
  entity = entity.parent;
3546
3572
  }
3547
3573
  // If the target node is in the default scene, relativePath will be empty
3548
- if (entity !== context.glTFResource.defaultSceneRoot) {
3574
+ if (context.glTFResource.sceneRoots.indexOf(entity) === -1) {
3549
3575
  continue;
3550
3576
  }
3551
3577
  var ComponentType = void 0;
@@ -4062,7 +4088,6 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4062
4088
  }
4063
4089
  var _proto = GLTFSceneParser.prototype;
4064
4090
  _proto.parse = function parse(context, index) {
4065
- var _this = this;
4066
4091
  var _context_glTF = context.glTF, scenes = _context_glTF.scenes, _context_glTF_scene = _context_glTF.scene, scene = _context_glTF_scene === void 0 ? 0 : _context_glTF_scene, glTFResource = context.glTFResource;
4067
4092
  var sceneInfo = scenes[index];
4068
4093
  var sceneExtensions = sceneInfo.extensions;
@@ -4092,18 +4117,6 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4092
4117
  }
4093
4118
  return Promise.all(promises).then(function() {
4094
4119
  GLTFParser.executeExtensionsAdditiveAndParse(sceneExtensions, context, sceneRoot, sceneInfo);
4095
- if (isDefaultScene) {
4096
- return Promise.all([
4097
- context.get(exports.GLTFParserType.Skin),
4098
- context.get(exports.GLTFParserType.Animation)
4099
- ]).then(function(param) {
4100
- var skins = param[0], animations = param[1];
4101
- if (skins || animations) {
4102
- _this._createAnimator(context, animations);
4103
- }
4104
- return sceneRoot;
4105
- });
4106
- }
4107
4120
  return sceneRoot;
4108
4121
  });
4109
4122
  };
@@ -4215,28 +4228,6 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4215
4228
  for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
4216
4229
  return Promise.all(promises);
4217
4230
  };
4218
- _proto._createAnimator = function _createAnimator(context, animations) {
4219
- var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
4220
- var animator = defaultSceneRoot.addComponent(engineCore.Animator);
4221
- var animatorController = new engineCore.AnimatorController();
4222
- var layer = new engineCore.AnimatorControllerLayer("layer");
4223
- var animatorStateMachine = new engineCore.AnimatorStateMachine();
4224
- animatorController.addLayer(layer);
4225
- animator.animatorController = animatorController;
4226
- layer.stateMachine = animatorStateMachine;
4227
- if (animations) {
4228
- for(var i = 0; i < animations.length; i++){
4229
- var animationClip = animations[i];
4230
- var name = animationClip.name;
4231
- var uniqueName = animatorStateMachine.makeUniqueStateName(name);
4232
- if (uniqueName !== name) {
4233
- console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
4234
- }
4235
- var animatorState = animatorStateMachine.addState(uniqueName);
4236
- animatorState.clip = animationClip;
4237
- }
4238
- }
4239
- };
4240
4231
  _proto._computeLocalBounds = function _computeLocalBounds(skinnedMeshRenderer, mesh, bones, rootBone, inverseBindMatrices) {
4241
4232
  var rootBoneIndex = bones.indexOf(rootBone);
4242
4233
  if (rootBoneIndex !== -1) {