@galacean/engine-loader 1.1.0-beta.8 → 1.2.0-alpha.0

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.
Files changed (31) hide show
  1. package/dist/main.js +499 -245
  2. package/dist/main.js.map +1 -1
  3. package/dist/miniprogram.js +499 -245
  4. package/dist/module.js +501 -247
  5. package/dist/module.js.map +1 -1
  6. package/package.json +5 -5
  7. package/types/GLTFLoader.d.ts +1 -0
  8. package/types/Texture2DLoader.d.ts +9 -1
  9. package/types/gltf/GLTFResource.d.ts +50 -16
  10. package/types/gltf/extensions/GLTFExtensionSchema.d.ts +9 -1
  11. package/types/gltf/extensions/KHR_materials_anisotropy.d.ts +1 -0
  12. package/types/gltf/extensions/index.d.ts +1 -0
  13. package/types/gltf/parser/GLTFJSONParser.d.ts +7 -0
  14. package/types/gltf/parser/GLTFParserContext.d.ts +17 -2
  15. package/types/gltf/parser/GLTFSceneParser.d.ts +0 -1
  16. package/types/index.d.ts +1 -1
  17. package/types/ktx2/KTX2Loader.d.ts +16 -5
  18. package/types/ktx2/transcoder/AbstractTranscoder.d.ts +1 -1
  19. package/types/ktx2/transcoder/BinomialLLCTranscoder.d.ts +1 -1
  20. package/types/ktx2/transcoder/BinomialLLCWorkerCode.d.ts +1 -1
  21. package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +1 -1
  22. package/types/resource-deserialize/resources/schema/MaterialSchema.d.ts +1 -1
  23. package/types/resource-deserialize/resources/schema/SceneSchema.d.ts +3 -1
  24. package/types/resource-deserialize/utils/BufferReader.d.ts +1 -1
  25. package/types/ktx2/BinomialLLCTranscoder/BinomialLLCTranscoder.d.ts +0 -13
  26. package/types/ktx2/BinomialLLCTranscoder/TranscodeWorkerCode.d.ts +0 -33
  27. package/types/ktx2/KhronosTranscoder/KhronosTranscoder.d.ts +0 -17
  28. package/types/ktx2/KhronosTranscoder/TranscoderWorkerCode.d.ts +0 -34
  29. package/types/ktx2/TranscodeResult.d.ts +0 -10
  30. package/types/ktx2/constants.d.ts +0 -7
  31. package/types/ktx2/zstddec.d.ts +0 -62
@@ -121,116 +121,116 @@ var BufferReader = /*#__PURE__*/ function() {
121
121
  this.data = data;
122
122
  this._dataView = new DataView(data.buffer, data.byteOffset + byteOffset, byteLength != null ? byteLength : data.byteLength - byteOffset);
123
123
  this._littleEndian = littleEndian;
124
- this._offset = 0;
124
+ this._position = 0;
125
125
  this._baseOffset = byteOffset;
126
126
  }
127
127
  var _proto = BufferReader.prototype;
128
128
  _proto.nextUint8 = function nextUint8() {
129
- var value = this._dataView.getUint8(this._offset);
130
- this._offset += 1;
129
+ var value = this._dataView.getUint8(this._position);
130
+ this._position += 1;
131
131
  return value;
132
132
  };
133
133
  _proto.nextUint16 = function nextUint16() {
134
- var value = this._dataView.getUint16(this._offset, this._littleEndian);
135
- this._offset += 2;
134
+ var value = this._dataView.getUint16(this._position, this._littleEndian);
135
+ this._position += 2;
136
136
  return value;
137
137
  };
138
138
  _proto.nextUint32 = function nextUint32() {
139
- var value = this._dataView.getUint32(this._offset, this._littleEndian);
140
- this._offset += 4;
139
+ var value = this._dataView.getUint32(this._position, this._littleEndian);
140
+ this._position += 4;
141
141
  return value;
142
142
  };
143
143
  _proto.nextInt32 = function nextInt32() {
144
- var value = this._dataView.getInt32(this._offset, this._littleEndian);
145
- this._offset += 4;
144
+ var value = this._dataView.getInt32(this._position, this._littleEndian);
145
+ this._position += 4;
146
146
  return value;
147
147
  };
148
148
  _proto.nextInt32Array = function nextInt32Array(len) {
149
- var value = new Int32Array(this.data.buffer, this._offset + this._dataView.byteOffset, len);
150
- this._offset += 4 * len;
149
+ var value = new Int32Array(this.data.buffer, this._position + this._dataView.byteOffset, len);
150
+ this._position += 4 * len;
151
151
  return value;
152
152
  };
153
153
  _proto.nextFloat32 = function nextFloat32() {
154
- var value = this._dataView.getFloat32(this._offset, this._littleEndian);
155
- this._offset += 4;
154
+ var value = this._dataView.getFloat32(this._position, this._littleEndian);
155
+ this._position += 4;
156
156
  return value;
157
157
  };
158
158
  _proto.nextFloat32Array = function nextFloat32Array(len) {
159
- var value = new Float32Array(this.data.buffer, this._offset + this._dataView.byteOffset, len);
160
- this._offset += 4 * len;
159
+ var value = new Float32Array(this.data.buffer, this._position + this._dataView.byteOffset, len);
160
+ this._position += 4 * len;
161
161
  return value;
162
162
  };
163
163
  _proto.nextUint32Array = function nextUint32Array(len) {
164
- var value = new Uint32Array(this.data.buffer, this._offset + this._dataView.byteOffset, len);
165
- this._offset += 4 * len;
164
+ var value = new Uint32Array(this.data.buffer, this._position + this._dataView.byteOffset, len);
165
+ this._position += 4 * len;
166
166
  return value;
167
167
  };
168
168
  _proto.nextUint8Array = function nextUint8Array(len) {
169
- var value = new Uint8Array(this.data.buffer, this._offset + this._dataView.byteOffset, len);
170
- this._offset += len;
169
+ var value = new Uint8Array(this.data.buffer, this._position + this._dataView.byteOffset, len);
170
+ this._position += len;
171
171
  return value;
172
172
  };
173
173
  _proto.nextUint64 = function nextUint64() {
174
- var left = this._dataView.getUint32(this._offset, this._littleEndian);
175
- var right = this._dataView.getUint32(this._offset + 4, this._littleEndian);
174
+ var left = this._dataView.getUint32(this._position, this._littleEndian);
175
+ var right = this._dataView.getUint32(this._position + 4, this._littleEndian);
176
176
  var value = left + Math.pow(2, 32) * right;
177
- this._offset += 8;
177
+ this._position += 8;
178
178
  return value;
179
179
  };
180
180
  _proto.nextStr = function nextStr() {
181
181
  var strByteLength = this.nextUint16();
182
- var uint8Array = new Uint8Array(this.data.buffer, this._offset + this._dataView.byteOffset, strByteLength);
183
- this._offset += strByteLength;
182
+ var uint8Array = new Uint8Array(this.data.buffer, this._position + this._dataView.byteOffset, strByteLength);
183
+ this._position += strByteLength;
184
184
  return miniprogram.Utils.decodeText(uint8Array);
185
185
  };
186
186
  /**
187
187
  * image data 放在最后
188
188
  */ _proto.nextImageData = function nextImageData(count) {
189
- return new Uint8Array(this.data.buffer, this.data.byteOffset + this._offset);
189
+ return new Uint8Array(this.data.buffer, this.data.byteOffset + this._position);
190
190
  };
191
191
  _proto.nextImagesData = function nextImagesData(count) {
192
192
  var imagesLen = new Array(count);
193
193
  // 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
194
194
  for(var i = 0; i < count; i++){
195
- var len = this._dataView.getUint32(this._offset, this._littleEndian);
195
+ var len = this._dataView.getUint32(this._position, this._littleEndian);
196
196
  imagesLen[i] = len;
197
- this._offset += 4;
197
+ this._position += 4;
198
198
  }
199
199
  var imagesData = [];
200
200
  for(var i1 = 0; i1 < count; i1++){
201
201
  var len1 = imagesLen[i1];
202
- var buffer = new Uint8Array(this.data.buffer, this._dataView.byteOffset + this._offset, len1);
203
- this._offset += len1;
202
+ var buffer = new Uint8Array(this.data.buffer, this._dataView.byteOffset + this._position, len1);
203
+ this._position += len1;
204
204
  imagesData.push(buffer);
205
205
  }
206
206
  return imagesData;
207
207
  };
208
208
  _proto.skip = function skip(bytes) {
209
- this._offset += bytes;
209
+ this._position += bytes;
210
210
  return this;
211
211
  };
212
212
  _proto.scan = function scan(maxByteLength, term) {
213
213
  if (term === void 0) term = 0x00;
214
- var byteOffset = this._offset;
214
+ var byteOffset = this._position;
215
215
  var byteLength = 0;
216
- while(this._dataView.getUint8(this._offset) !== term && byteLength < maxByteLength){
216
+ while(this._dataView.getUint8(this._position) !== term && byteLength < maxByteLength){
217
217
  byteLength++;
218
- this._offset++;
218
+ this._position++;
219
219
  }
220
- if (byteLength < maxByteLength) this._offset++;
220
+ if (byteLength < maxByteLength) this._position++;
221
221
  return new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + byteOffset, byteLength);
222
222
  };
223
223
  _create_class(BufferReader, [
224
224
  {
225
225
  key: "position",
226
226
  get: function get() {
227
- return this._offset;
227
+ return this._position;
228
228
  }
229
229
  },
230
230
  {
231
231
  key: "offset",
232
232
  get: function get() {
233
- return this._offset + this._baseOffset;
233
+ return this._position + this._baseOffset;
234
234
  }
235
235
  }
236
236
  ]);
@@ -294,75 +294,74 @@ exports.MeshDecoder = /*#__PURE__*/ function() {
294
294
  var encodedMeshData = JSON.parse(jsonDataString);
295
295
  // @ts-ignore Vector3 is not compatible with {x: number, y: number, z: number}.
296
296
  encodedMeshData.bounds && modelMesh.bounds.copyFrom(encodedMeshData.bounds);
297
- var offset = Math.ceil(bufferReader.offset / 4) * 4;
297
+ var offset = Math.ceil(bufferReader.offset / 4) * 4 + bufferReader.data.byteOffset;
298
298
  var buffer = bufferReader.data.buffer;
299
- var byteOffset = bufferReader.data.byteOffset;
300
- var float32Array = new Float32Array(buffer, encodedMeshData.positions.start + offset + byteOffset, (encodedMeshData.positions.end - encodedMeshData.positions.start) / 4);
299
+ var float32Array = new Float32Array(buffer, encodedMeshData.positions.start + offset, (encodedMeshData.positions.end - encodedMeshData.positions.start) / 4);
301
300
  var vertexCount = float32Array.length / 3;
302
301
  var positions = float32ArrayToVector3(float32Array, vertexCount);
303
302
  modelMesh.setPositions(positions);
304
303
  if (encodedMeshData.normals) {
305
- var float32Array1 = new Float32Array(buffer, encodedMeshData.normals.start + offset + byteOffset, (encodedMeshData.normals.end - encodedMeshData.normals.start) / 4);
304
+ var float32Array1 = new Float32Array(buffer, encodedMeshData.normals.start + offset, (encodedMeshData.normals.end - encodedMeshData.normals.start) / 4);
306
305
  var normals = float32ArrayToVector3(float32Array1, vertexCount);
307
306
  modelMesh.setNormals(normals);
308
307
  }
309
308
  if (encodedMeshData.uvs) {
310
- var float32Array2 = new Float32Array(buffer, encodedMeshData.uvs.start + offset + byteOffset, (encodedMeshData.uvs.end - encodedMeshData.uvs.start) / 4);
309
+ var float32Array2 = new Float32Array(buffer, encodedMeshData.uvs.start + offset, (encodedMeshData.uvs.end - encodedMeshData.uvs.start) / 4);
311
310
  modelMesh.setUVs(float32ArrayToVector2(float32Array2, vertexCount));
312
311
  }
313
312
  if (encodedMeshData.uv1) {
314
- var float32Array3 = new Float32Array(buffer, encodedMeshData.uv1.start + offset + byteOffset, (encodedMeshData.uv1.end - encodedMeshData.uv1.start) / 4);
313
+ var float32Array3 = new Float32Array(buffer, encodedMeshData.uv1.start + offset, (encodedMeshData.uv1.end - encodedMeshData.uv1.start) / 4);
315
314
  modelMesh.setUVs(float32ArrayToVector2(float32Array3, vertexCount), 1);
316
315
  }
317
316
  if (encodedMeshData.uv2) {
318
- var float32Array4 = new Float32Array(buffer, encodedMeshData.uv2.start + offset + byteOffset, (encodedMeshData.uv2.end - encodedMeshData.uv2.start) / 4);
317
+ var float32Array4 = new Float32Array(buffer, encodedMeshData.uv2.start + offset, (encodedMeshData.uv2.end - encodedMeshData.uv2.start) / 4);
319
318
  modelMesh.setUVs(float32ArrayToVector2(float32Array4, vertexCount), 2);
320
319
  }
321
320
  if (encodedMeshData.uv3) {
322
- var float32Array5 = new Float32Array(buffer, encodedMeshData.uv3.start + offset + byteOffset, (encodedMeshData.uv3.end - encodedMeshData.uv3.start) / 4);
321
+ var float32Array5 = new Float32Array(buffer, encodedMeshData.uv3.start + offset, (encodedMeshData.uv3.end - encodedMeshData.uv3.start) / 4);
323
322
  modelMesh.setUVs(float32ArrayToVector2(float32Array5, vertexCount), 3);
324
323
  }
325
324
  if (encodedMeshData.uv4) {
326
- var float32Array6 = new Float32Array(buffer, encodedMeshData.uv4.start + offset + byteOffset, (encodedMeshData.uv4.end - encodedMeshData.uv4.start) / 4);
325
+ var float32Array6 = new Float32Array(buffer, encodedMeshData.uv4.start + offset, (encodedMeshData.uv4.end - encodedMeshData.uv4.start) / 4);
327
326
  modelMesh.setUVs(float32ArrayToVector2(float32Array6, vertexCount), 4);
328
327
  }
329
328
  if (encodedMeshData.uv5) {
330
- var float32Array7 = new Float32Array(buffer, encodedMeshData.uv5.start + offset + byteOffset, (encodedMeshData.uv5.end - encodedMeshData.uv5.start) / 4);
329
+ var float32Array7 = new Float32Array(buffer, encodedMeshData.uv5.start + offset, (encodedMeshData.uv5.end - encodedMeshData.uv5.start) / 4);
331
330
  modelMesh.setUVs(float32ArrayToVector2(float32Array7, vertexCount), 5);
332
331
  }
333
332
  if (encodedMeshData.uv6) {
334
- var float32Array8 = new Float32Array(buffer, encodedMeshData.uv6.start + offset + byteOffset, (encodedMeshData.uv6.end - encodedMeshData.uv6.start) / 4);
333
+ var float32Array8 = new Float32Array(buffer, encodedMeshData.uv6.start + offset, (encodedMeshData.uv6.end - encodedMeshData.uv6.start) / 4);
335
334
  modelMesh.setUVs(float32ArrayToVector2(float32Array8, vertexCount), 6);
336
335
  }
337
336
  if (encodedMeshData.uv7) {
338
- var float32Array9 = new Float32Array(buffer, encodedMeshData.uv7.start + offset + byteOffset, (encodedMeshData.uv7.end - encodedMeshData.uv7.start) / 4);
337
+ var float32Array9 = new Float32Array(buffer, encodedMeshData.uv7.start + offset, (encodedMeshData.uv7.end - encodedMeshData.uv7.start) / 4);
339
338
  modelMesh.setUVs(float32ArrayToVector2(float32Array9, vertexCount), 7);
340
339
  }
341
340
  if (encodedMeshData.colors) {
342
- var float32Array10 = new Float32Array(buffer, encodedMeshData.colors.start + offset + byteOffset, (encodedMeshData.colors.end - encodedMeshData.colors.start) / 4);
341
+ var float32Array10 = new Float32Array(buffer, encodedMeshData.colors.start + offset, (encodedMeshData.colors.end - encodedMeshData.colors.start) / 4);
343
342
  modelMesh.setColors(float32ArrayToVColor(float32Array10, vertexCount));
344
343
  }
345
344
  if (encodedMeshData.boneWeights) {
346
- var float32Array11 = new Float32Array(buffer, encodedMeshData.boneWeights.start + offset + byteOffset, (encodedMeshData.boneWeights.end - encodedMeshData.boneWeights.start) / 4);
345
+ var float32Array11 = new Float32Array(buffer, encodedMeshData.boneWeights.start + offset, (encodedMeshData.boneWeights.end - encodedMeshData.boneWeights.start) / 4);
347
346
  modelMesh.setBoneWeights(float32ArrayToVector4(float32Array11, vertexCount));
348
347
  }
349
348
  if (encodedMeshData.boneIndices) {
350
- var float32Array12 = new Float32Array(buffer, encodedMeshData.boneIndices.start + offset + byteOffset, (encodedMeshData.boneIndices.end - encodedMeshData.boneIndices.start) / 4);
349
+ var float32Array12 = new Float32Array(buffer, encodedMeshData.boneIndices.start + offset, (encodedMeshData.boneIndices.end - encodedMeshData.boneIndices.start) / 4);
351
350
  modelMesh.setBoneIndices(float32ArrayToVector4(float32Array12, vertexCount));
352
351
  }
353
352
  if (encodedMeshData.blendShapes) {
354
353
  encodedMeshData.blendShapes.forEach(function(blendShapeData) {
355
354
  var blendShape = new miniprogram.BlendShape(blendShapeData.name);
356
355
  blendShapeData.frames.forEach(function(frameData) {
357
- var positionArray = new Float32Array(buffer, frameData.deltaPosition.start + offset + byteOffset, (frameData.deltaPosition.end - frameData.deltaPosition.start) / 4);
356
+ var positionArray = new Float32Array(buffer, frameData.deltaPosition.start + offset, (frameData.deltaPosition.end - frameData.deltaPosition.start) / 4);
358
357
  var count = positionArray.length / 3;
359
358
  var deltaPosition = float32ArrayToVector3(positionArray, count);
360
359
  if (frameData.deltaNormals) {
361
- var normalsArray = new Float32Array(buffer, frameData.deltaNormals.start + offset + byteOffset, (frameData.deltaNormals.end - frameData.deltaNormals.start) / 4);
360
+ var normalsArray = new Float32Array(buffer, frameData.deltaNormals.start + offset, (frameData.deltaNormals.end - frameData.deltaNormals.start) / 4);
362
361
  float32ArrayToVector3(normalsArray, count);
363
362
  }
364
363
  if (frameData.deltaTangents) {
365
- var tangentsArray = new Float32Array(buffer, frameData.deltaTangents.start + offset + byteOffset, (frameData.deltaTangents.end - frameData.deltaTangents.start) / 4);
364
+ var tangentsArray = new Float32Array(buffer, frameData.deltaTangents.start + offset, (frameData.deltaTangents.end - frameData.deltaTangents.start) / 4);
366
365
  float32ArrayToVector4(tangentsArray, count);
367
366
  }
368
367
  blendShape.addFrame(frameData.weight, deltaPosition);
@@ -373,9 +372,9 @@ exports.MeshDecoder = /*#__PURE__*/ function() {
373
372
  if (encodedMeshData.indices) {
374
373
  var indices = null;
375
374
  if (encodedMeshData.indices.type === 0) {
376
- indices = new Uint16Array(buffer, encodedMeshData.indices.start + offset + byteOffset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 2);
375
+ indices = new Uint16Array(buffer, encodedMeshData.indices.start + offset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 2);
377
376
  } else {
378
- indices = new Uint32Array(buffer, encodedMeshData.indices.start + offset + byteOffset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 4);
377
+ indices = new Uint32Array(buffer, encodedMeshData.indices.start + offset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 4);
379
378
  }
380
379
  modelMesh.setIndices(indices);
381
380
  }
@@ -544,11 +543,17 @@ var ReflectionParser = /*#__PURE__*/ function() {
544
543
  });
545
544
  };
546
545
  _proto.parseClassObject = function parseClassObject(item) {
546
+ var _this = this;
547
547
  var Class = miniprogram.Loader.getClass(item.class);
548
548
  var _item_constructParams;
549
549
  var params = (_item_constructParams = item.constructParams) != null ? _item_constructParams : [];
550
- var instance = _construct(Class, [].concat(params));
551
- return this.parsePropsAndMethods(instance, item);
550
+ return Promise.all(params.map(function(param) {
551
+ return _this.parseBasicType(param);
552
+ })).then(function(resultParams) {
553
+ return _construct(Class, [].concat(resultParams));
554
+ }).then(function(instance) {
555
+ return _this.parsePropsAndMethods(instance, item);
556
+ });
552
557
  };
553
558
  _proto.parsePropsAndMethods = function parsePropsAndMethods(instance, item) {
554
559
  var promises = [];
@@ -556,16 +561,14 @@ var ReflectionParser = /*#__PURE__*/ function() {
556
561
  for(var methodName in item.methods){
557
562
  var methodParams = item.methods[methodName];
558
563
  for(var i = 0, count = methodParams.length; i < count; i++){
559
- var params = methodParams[i];
560
- var promise = this.parseMethod(instance, methodName, params);
561
- promises.push(promise);
564
+ promises.push(this.parseMethod(instance, methodName, methodParams[i]));
562
565
  }
563
566
  }
564
567
  }
565
568
  if (item.props) {
566
569
  var _this = this, _loop = function(key) {
567
570
  var value = item.props[key];
568
- var promise = _this.parseBasicType(value).then(function(v) {
571
+ var promise = _this.parseBasicType(value, instance[key]).then(function(v) {
569
572
  return instance[key] = v;
570
573
  });
571
574
  promises.push(promise);
@@ -587,7 +590,7 @@ var ReflectionParser = /*#__PURE__*/ function() {
587
590
  return (_instance = instance)[methodName].apply(_instance, [].concat(result));
588
591
  });
589
592
  };
590
- _proto.parseBasicType = function parseBasicType(value) {
593
+ _proto.parseBasicType = function parseBasicType(value, originValue) {
591
594
  var _this = this;
592
595
  if (Array.isArray(value)) {
593
596
  return Promise.all(value.map(function(item) {
@@ -604,13 +607,33 @@ var ReflectionParser = /*#__PURE__*/ function() {
604
607
  } else if (ReflectionParser._isEntityRef(value)) {
605
608
  // entity reference
606
609
  return Promise.resolve(this._context.entityMap.get(value.entityId));
607
- } else {
608
- // basic type
609
- return Promise.resolve(value);
610
+ } else if (originValue) {
611
+ var _this1 = this, _loop = function(key) {
612
+ if (key === "methods") {
613
+ var methods = value[key];
614
+ for(var methodName in methods){
615
+ var methodParams = methods[methodName];
616
+ for(var i = 0, count = methodParams.length; i < count; i++){
617
+ var params = methodParams[i];
618
+ var promise = _this1.parseMethod(originValue, methodName, params);
619
+ promises.push(promise);
620
+ }
621
+ }
622
+ } else {
623
+ promises.push(_this1.parseBasicType(value[key], originValue[key]).then(function(v) {
624
+ return originValue[key] = v;
625
+ }));
626
+ }
627
+ };
628
+ var promises = [];
629
+ for(var key in value)_loop(key);
630
+ return Promise.all(promises).then(function() {
631
+ return originValue;
632
+ });
610
633
  }
611
- } else {
612
- return Promise.resolve(value);
613
634
  }
635
+ // primitive type
636
+ return Promise.resolve(value);
614
637
  };
615
638
  _proto._getEntityByConfig = function _getEntityByConfig(entityConfig) {
616
639
  // @ts-ignore
@@ -715,6 +738,7 @@ exports.AnimationClipDecoder = /*#__PURE__*/ function() {
715
738
  var componentStr = bufferReader.nextStr();
716
739
  var componentType = ComponentMap[componentStr];
717
740
  var property = bufferReader.nextStr();
741
+ var getProperty = bufferReader.nextStr();
718
742
  var curve = void 0;
719
743
  var interpolation = bufferReader.nextUint8();
720
744
  var keysLen = bufferReader.nextUint16();
@@ -839,13 +863,42 @@ exports.AnimationClipDecoder = /*#__PURE__*/ function() {
839
863
  for(var j7 = 0; j7 < keysLen; ++j7){
840
864
  var keyframe8 = new miniprogram.Keyframe();
841
865
  keyframe8.time = bufferReader.nextFloat32();
842
- keyframe8.value = JSON.parse(bufferReader.nextStr());
866
+ var str = bufferReader.nextStr();
867
+ if (str) {
868
+ keyframe8.value = JSON.parse(str);
869
+ } else {
870
+ keyframe8.value = null;
871
+ }
843
872
  curve.addKey(keyframe8);
844
873
  }
845
874
  break;
846
875
  }
876
+ case "AnimationBoolCurve":
877
+ {
878
+ curve = new miniprogram.AnimationBoolCurve();
879
+ curve.interpolation = interpolation;
880
+ for(var j8 = 0; j8 < keysLen; ++j8){
881
+ var keyframe9 = new miniprogram.Keyframe();
882
+ keyframe9.time = bufferReader.nextFloat32();
883
+ keyframe9.value = bufferReader.nextUint8() === 1;
884
+ curve.addKey(keyframe9);
885
+ }
886
+ break;
887
+ }
888
+ case "AnimationStringCurve":
889
+ {
890
+ curve = new miniprogram.AnimationStringCurve();
891
+ curve.interpolation = interpolation;
892
+ for(var j9 = 0; j9 < keysLen; ++j9){
893
+ var keyframe10 = new miniprogram.Keyframe();
894
+ keyframe10.time = bufferReader.nextFloat32();
895
+ keyframe10.value = bufferReader.nextStr();
896
+ curve.addKey(keyframe10);
897
+ }
898
+ break;
899
+ }
847
900
  }
848
- clip.addCurveBinding(relativePath, componentType, property, curve);
901
+ clip.addCurveBinding(relativePath, componentType, property, getProperty, curve);
849
902
  }
850
903
  resolve(clip);
851
904
  });
@@ -1099,26 +1152,34 @@ var AnimationClipLoader = /*#__PURE__*/ function(Loader1) {
1099
1152
  var curveBindingPromises = clip.curveBindings.map(function(curveBinding) {
1100
1153
  var curve = curveBinding.curve;
1101
1154
  var promises = curve.keys.map(function(key) {
1102
- var value = key.value;
1103
- if (typeof value === "object" && value.refId) {
1104
- return new Promise(function(resolve) {
1105
- resourceManager// @ts-ignore
1106
- .getResourceByRef(value).then(function(asset) {
1107
- key.value = asset;
1108
- resolve(key);
1109
- }).catch(reject);
1110
- });
1111
- }
1155
+ return _this._parseKeyframeValue(key, resourceManager).then(function(actualValue) {
1156
+ key.value = actualValue;
1157
+ });
1112
1158
  });
1113
1159
  return Promise.all(promises);
1114
1160
  });
1115
1161
  return Promise.all(curveBindingPromises).then(function() {
1116
1162
  resolve(clip);
1117
1163
  });
1118
- });
1164
+ }).catch(reject);
1119
1165
  }).catch(reject);
1120
1166
  });
1121
1167
  };
1168
+ _proto._parseKeyframeValue = function _parseKeyframeValue(keyframe, resourceManager) {
1169
+ var _value;
1170
+ var value = keyframe.value;
1171
+ if (typeof value === "object" && ((_value = value) == null ? void 0 : _value.refId)) {
1172
+ return new Promise(function(resolve) {
1173
+ resourceManager// @ts-ignore
1174
+ .getResourceByRef(value).then(function(asset) {
1175
+ keyframe.value = asset;
1176
+ resolve(keyframe);
1177
+ });
1178
+ });
1179
+ } else {
1180
+ return Promise.resolve(keyframe.value);
1181
+ }
1182
+ };
1122
1183
  return AnimationClipLoader;
1123
1184
  }(miniprogram.Loader);
1124
1185
  AnimationClipLoader = __decorate([
@@ -1394,6 +1455,60 @@ FontLoader = __decorate([
1394
1455
  _this.url = url;
1395
1456
  return _this;
1396
1457
  }
1458
+ var _proto = GLTFResource.prototype;
1459
+ /**
1460
+ * Instantiate scene root entity.
1461
+ * @param sceneIndex - Scene index
1462
+ * @returns Root entity
1463
+ */ _proto.instantiateSceneRoot = function instantiateSceneRoot(sceneIndex) {
1464
+ var sceneRoot = sceneIndex === undefined ? this._defaultSceneRoot : this._sceneRoots[sceneIndex];
1465
+ return sceneRoot.clone();
1466
+ };
1467
+ _proto._onDestroy = function _onDestroy() {
1468
+ ReferResource1.prototype._onDestroy.call(this);
1469
+ var _this = this, textures = _this.textures, materials = _this.materials, meshes = _this.meshes;
1470
+ textures && this._disassociationSuperResource(textures);
1471
+ materials && this._disassociationSuperResource(materials);
1472
+ if (meshes) {
1473
+ for(var i = 0, n = meshes.length; i < n; i++){
1474
+ this._disassociationSuperResource(meshes[i]);
1475
+ }
1476
+ }
1477
+ };
1478
+ _proto._disassociationSuperResource = function _disassociationSuperResource(resources) {
1479
+ for(var i = 0, n = resources.length; i < n; i++){
1480
+ // @ts-ignore
1481
+ resources[i]._disassociationSuperResource(this);
1482
+ }
1483
+ };
1484
+ _create_class(GLTFResource, [
1485
+ {
1486
+ key: "extensionsData",
1487
+ get: /**
1488
+ * Extensions data.
1489
+ */ function get() {
1490
+ return this._extensionsData;
1491
+ }
1492
+ },
1493
+ {
1494
+ key: "sceneRoots",
1495
+ get: /**
1496
+ * @deprecated Please use `instantiateSceneRoot` instead.
1497
+ * RootEntities after SceneParser.
1498
+ */ function get() {
1499
+ return this._sceneRoots;
1500
+ }
1501
+ },
1502
+ {
1503
+ key: "defaultSceneRoot",
1504
+ get: /**
1505
+ * @deprecated Please use `instantiateSceneRoot` instead.
1506
+ * RootEntity after SceneParser.
1507
+ */ function get() {
1508
+ return this._defaultSceneRoot;
1509
+ }
1510
+ }
1511
+ ]);
1397
1512
  return GLTFResource;
1398
1513
  }(miniprogram.ReferResource);
1399
1514
 
@@ -1547,12 +1662,29 @@ var TextureWrapMode;
1547
1662
  /**
1548
1663
  * @internal
1549
1664
  */ var GLTFParserContext = /*#__PURE__*/ function() {
1550
- function GLTFParserContext(glTFResource, resourceManager, keepMeshData) {
1665
+ function GLTFParserContext(glTFResource, resourceManager, params) {
1666
+ var _this = this;
1551
1667
  this.glTFResource = glTFResource;
1552
1668
  this.resourceManager = resourceManager;
1553
- this.keepMeshData = keepMeshData;
1669
+ this.params = params;
1554
1670
  this.accessorBufferCache = {};
1555
1671
  this._resourceCache = new Map();
1672
+ this._progress = {
1673
+ taskDetail: {},
1674
+ taskComplete: {
1675
+ loaded: 0,
1676
+ total: 0
1677
+ }
1678
+ };
1679
+ this./**
1680
+ * @internal
1681
+ */ _onTaskDetail = function(url, loaded, total) {
1682
+ var _this__progress_taskDetail, _url;
1683
+ var detail = (_this__progress_taskDetail = _this._progress.taskDetail)[_url = url] || (_this__progress_taskDetail[_url] = {});
1684
+ detail.loaded = loaded;
1685
+ detail.total = total;
1686
+ _this._setTaskDetailProgress(url, loaded, total);
1687
+ };
1556
1688
  this.contentRestorer = new GLTFContentRestorer(glTFResource);
1557
1689
  }
1558
1690
  var _proto = GLTFParserContext.prototype;
@@ -1593,7 +1725,7 @@ var TextureWrapMode;
1593
1725
  };
1594
1726
  _proto.parse = function parse() {
1595
1727
  var _this = this;
1596
- return this.get(0).then(function(json) {
1728
+ var promise = this.get(0).then(function(json) {
1597
1729
  _this.glTF = json;
1598
1730
  return Promise.all([
1599
1731
  _this.get(1),
@@ -1604,10 +1736,48 @@ var TextureWrapMode;
1604
1736
  _this.get(9),
1605
1737
  _this.get(2)
1606
1738
  ]).then(function() {
1739
+ var glTFResource = _this.glTFResource;
1740
+ if (glTFResource.skins || glTFResource.animations) {
1741
+ _this._createAnimator(_this, glTFResource.animations);
1742
+ }
1607
1743
  _this.resourceManager.addContentRestorer(_this.contentRestorer);
1608
- return _this.glTFResource;
1744
+ return glTFResource;
1609
1745
  });
1610
1746
  });
1747
+ this._addTaskCompletePromise(promise);
1748
+ return promise;
1749
+ };
1750
+ /**
1751
+ * @internal
1752
+ */ _proto._addTaskCompletePromise = function _addTaskCompletePromise(taskPromise) {
1753
+ var _this = this;
1754
+ var task = this._progress.taskComplete;
1755
+ task.total += 1;
1756
+ taskPromise.then(function() {
1757
+ _this._setTaskCompleteProgress(++task.loaded, task.total);
1758
+ });
1759
+ };
1760
+ _proto._createAnimator = function _createAnimator(context, animations) {
1761
+ var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
1762
+ var animator = defaultSceneRoot.addComponent(miniprogram.Animator);
1763
+ var animatorController = new miniprogram.AnimatorController();
1764
+ var layer = new miniprogram.AnimatorControllerLayer("layer");
1765
+ var animatorStateMachine = new miniprogram.AnimatorStateMachine();
1766
+ animatorController.addLayer(layer);
1767
+ animator.animatorController = animatorController;
1768
+ layer.stateMachine = animatorStateMachine;
1769
+ if (animations) {
1770
+ for(var i = 0; i < animations.length; i++){
1771
+ var animationClip = animations[i];
1772
+ var name = animationClip.name;
1773
+ var uniqueName = animatorStateMachine.makeUniqueStateName(name);
1774
+ if (uniqueName !== name) {
1775
+ console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
1776
+ }
1777
+ var animatorState = animatorStateMachine.addState(uniqueName);
1778
+ animatorState.clip = animationClip;
1779
+ }
1780
+ }
1611
1781
  };
1612
1782
  _proto._handleSubAsset = function _handleSubAsset(resource, type, index) {
1613
1783
  var _this = this;
@@ -1671,7 +1841,7 @@ exports.GLTFParserType = void 0;
1671
1841
  var _obj;
1672
1842
  var glTFSchemaMap = (_obj = {}, _obj[2] = "scenes", _obj[3] = "buffers", _obj[4] = "textures", _obj[5] = "materials", _obj[6] = "meshes", _obj[7] = "nodes", _obj[8] = "skins", _obj[9] = "animations", _obj);
1673
1843
  var _obj1;
1674
- var glTFResourceMap = (_obj1 = {}, _obj1[2] = "sceneRoots", _obj1[4] = "textures", _obj1[5] = "materials", _obj1[6] = "meshes", _obj1[7] = "entities", _obj1[8] = "skins", _obj1[9] = "animations", _obj1);
1844
+ var glTFResourceMap = (_obj1 = {}, _obj1[2] = "_sceneRoots", _obj1[4] = "textures", _obj1[5] = "materials", _obj1[6] = "meshes", _obj1[7] = "entities", _obj1[8] = "skins", _obj1[9] = "animations", _obj1);
1675
1845
  function registerGLTFParser(pipeline) {
1676
1846
  return function(Parser) {
1677
1847
  var parser = new Parser();
@@ -2248,7 +2418,7 @@ var SupercompressionScheme;
2248
2418
  alphaSliceByteLength: sgdReader.nextUint32()
2249
2419
  };
2250
2420
  }
2251
- var endpointsByteOffset = sgdByteOffset + sgdReader.offset;
2421
+ var endpointsByteOffset = sgdByteOffset + sgdReader.position;
2252
2422
  var selectorsByteOffset = endpointsByteOffset + endpointsByteLength;
2253
2423
  var tablesByteOffset = selectorsByteOffset + selectorsByteLength;
2254
2424
  var extendedByteOffset = tablesByteOffset + tablesByteLength;
@@ -2440,6 +2610,25 @@ var AbstractTranscoder = /*#__PURE__*/ function() {
2440
2610
  }();
2441
2611
 
2442
2612
  /** @internal */ function TranscodeWorkerCode$1() {
2613
+ var initPromise;
2614
+ var init = function init(wasmBinary) {
2615
+ if (!initPromise) {
2616
+ initPromise = new Promise(function(resolve, reject) {
2617
+ var BasisModule = {
2618
+ wasmBinary: wasmBinary,
2619
+ onRuntimeInitialized: function() {
2620
+ return resolve(BasisModule);
2621
+ },
2622
+ onAbort: reject
2623
+ };
2624
+ self["BASIS"](BasisModule);
2625
+ }).then(function(BasisModule) {
2626
+ BasisModule.initializeBasis();
2627
+ return BasisModule.KTX2File;
2628
+ });
2629
+ }
2630
+ return initPromise;
2631
+ };
2443
2632
  self.onmessage = function onmessage(event) {
2444
2633
  var message = event.data;
2445
2634
  switch(message.type){
@@ -2554,6 +2743,10 @@ function transcode(buffer, targetFormat, KTX2File) {
2554
2743
  cleanup();
2555
2744
  throw new Error("Invalid or unsupported .ktx2 file");
2556
2745
  }
2746
+ if (!ktx2File.startTranscoding()) {
2747
+ cleanup();
2748
+ throw new Error("KTX2 startTranscoding failed");
2749
+ }
2557
2750
  var width = ktx2File.getWidth();
2558
2751
  var height = ktx2File.getHeight();
2559
2752
  var layerCount = ktx2File.getLayers() || 1;
@@ -2562,6 +2755,7 @@ function transcode(buffer, targetFormat, KTX2File) {
2562
2755
  var faceCount = ktx2File.getFaces();
2563
2756
  var format = getTranscodeFormatFromTarget(targetFormat, hasAlpha);
2564
2757
  var faces = new Array(faceCount);
2758
+ var isBC = format === 2 || format === 3 || format === 7;
2565
2759
  for(var face = 0; face < faceCount; face++){
2566
2760
  var mipmaps = new Array(levelCount);
2567
2761
  for(var mip = 0; mip < levelCount; mip++){
@@ -2569,8 +2763,15 @@ function transcode(buffer, targetFormat, KTX2File) {
2569
2763
  var mipWidth = void 0, mipHeight = void 0;
2570
2764
  for(var layer = 0; layer < layerCount; layer++){
2571
2765
  var levelInfo = ktx2File.getImageLevelInfo(mip, layer, face);
2572
- mipWidth = levelInfo.origWidth;
2573
- mipHeight = levelInfo.origHeight;
2766
+ // see: https://github.com/KhronosGroup/KTX-Software/issues/254
2767
+ if (isBC && mip === 0 && (width !== levelInfo.width || height !== levelInfo.height)) {
2768
+ width = mipWidth = levelInfo.width;
2769
+ height = mipHeight = levelInfo.height;
2770
+ console.warn("KTX2 transcode to BC will resize to width: " + width + ", height: " + height + ". You'd better use an image whose size if multiple of 4.");
2771
+ } else {
2772
+ mipWidth = levelInfo.origWidth;
2773
+ mipHeight = levelInfo.origHeight;
2774
+ }
2574
2775
  var dst = new Uint8Array(ktx2File.getImageTranscodedSizeInBytes(mip, layer, 0, format));
2575
2776
  var status = ktx2File.transcodeImage(dst, mip, layer, face, format, 0, -1, -1);
2576
2777
  if (!status) {
@@ -2636,7 +2837,7 @@ function transcode(buffer, targetFormat, KTX2File) {
2636
2837
  } else {
2637
2838
  var funcCode = TranscodeWorkerCode$1.toString();
2638
2839
  var transcodeString = funcCode.substring(funcCode.indexOf("{"), funcCode.lastIndexOf("}") + 1);
2639
- var workerCode = "\n " + jsCode + "\n var init = (" + _init.toString() + ")();\n " + transcode.toString() + "\n " + transcodeString + "\n ";
2840
+ var workerCode = "\n " + jsCode + "\n " + transcode.toString() + "\n " + transcodeString + "\n ";
2640
2841
  var workerURL = engineMiniprogramAdapter.URL.createObjectURL(new engineMiniprogramAdapter.Blob([
2641
2842
  workerCode
2642
2843
  ], {
@@ -2882,10 +3083,14 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
2882
3083
  return Loader1.apply(this, arguments);
2883
3084
  }
2884
3085
  var _proto = KTX2Loader1.prototype;
2885
- _proto.initialize = function initialize(engine, configuration) {
3086
+ _proto.initialize = function initialize(_, configuration) {
2886
3087
  if (configuration.ktx2Loader) {
2887
3088
  var options = configuration.ktx2Loader;
2888
- if (this._isKhronosSupported(options.priorityFormats, engine) && options.workerCount !== 0) {
3089
+ if (options.priorityFormats) {
3090
+ exports.KTX2Loader._priorityFormats["etc1s"] = options.priorityFormats;
3091
+ exports.KTX2Loader._priorityFormats["uastc"] = options.priorityFormats;
3092
+ }
3093
+ if (options.transcoder === /** Khronos transcoder. */ 1) {
2889
3094
  return exports.KTX2Loader._getKhronosTranscoder(options.workerCount).init();
2890
3095
  } else {
2891
3096
  return exports.KTX2Loader._getBinomialLLCTranscoder(options.workerCount).init();
@@ -2895,34 +3100,16 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
2895
3100
  /**
2896
3101
  * @internal
2897
3102
  */ _proto.load = function load(item, resourceManager) {
2898
- return this.request(item.url, {
2899
- type: "arraybuffer"
2900
- }).then(function(buffer) {
2901
- return exports.KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then(function(param) {
2902
- var engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
2903
- return exports.KTX2Loader._createTextureByBuffer(engine, result, targetFormat, params);
2904
- });
2905
- });
2906
- };
2907
- _proto._isKhronosSupported = function _isKhronosSupported(priorityFormats, engine) {
2908
- if (priorityFormats === void 0) priorityFormats = [
2909
- exports.KTX2TargetFormat.ASTC,
2910
- exports.KTX2TargetFormat.ETC,
2911
- exports.KTX2TargetFormat.BC7,
2912
- exports.KTX2TargetFormat.BC1_BC3,
2913
- exports.KTX2TargetFormat.PVRTC,
2914
- exports.KTX2TargetFormat.R8G8B8A8
2915
- ];
2916
- var supportedList = new Array();
2917
- if (Array.isArray(priorityFormats[0])) {
2918
- for(var i = 0; i < priorityFormats.length; i++){
2919
- supportedList.push(exports.KTX2Loader._detectSupportedFormat(engine._hardwareRenderer, priorityFormats[i]));
2920
- }
2921
- } else {
2922
- supportedList.push(exports.KTX2Loader._detectSupportedFormat(engine._hardwareRenderer, priorityFormats));
2923
- }
2924
- return supportedList.every(function(format) {
2925
- return KhronosTranscoder.transcoderMap[format];
3103
+ var _this = this;
3104
+ return new miniprogram.AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
3105
+ _this.request(item.url, {
3106
+ type: "arraybuffer"
3107
+ }).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
3108
+ return exports.KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then(function(param) {
3109
+ var engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
3110
+ return exports.KTX2Loader._createTextureByBuffer(engine, result, targetFormat, params);
3111
+ });
3112
+ }).then(resolve).catch(reject);
2926
3113
  });
2927
3114
  };
2928
3115
  /**
@@ -2937,7 +3124,8 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
2937
3124
  /** @internal */ KTX2Loader1._parseBuffer = function _parseBuffer(buffer, engine, params) {
2938
3125
  var _params;
2939
3126
  var ktx2Container = new KTX2Container(buffer);
2940
- var formatPriorities = (_params = params) == null ? void 0 : _params.priorityFormats;
3127
+ var _params_priorityFormats;
3128
+ var formatPriorities = (_params_priorityFormats = (_params = params) == null ? void 0 : _params.priorityFormats) != null ? _params_priorityFormats : exports.KTX2Loader._priorityFormats[ktx2Container.isUASTC ? "uastc" : "etc1s"];
2941
3129
  var targetFormat = exports.KTX2Loader._decideTargetFormat(engine, ktx2Container, formatPriorities);
2942
3130
  var transcodeResultPromise;
2943
3131
  if (exports.KTX2Loader._isBinomialInit || !KhronosTranscoder.transcoderMap[targetFormat] || !ktx2Container.isUASTC) {
@@ -3004,18 +3192,22 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
3004
3192
  return targetFormat;
3005
3193
  };
3006
3194
  KTX2Loader1._detectSupportedFormat = function _detectSupportedFormat(renderer, priorityFormats) {
3007
- if (priorityFormats === void 0) priorityFormats = [
3008
- exports.KTX2TargetFormat.ASTC,
3009
- exports.KTX2TargetFormat.ETC,
3010
- exports.KTX2TargetFormat.BC7,
3011
- exports.KTX2TargetFormat.BC1_BC3,
3012
- exports.KTX2TargetFormat.PVRTC
3013
- ];
3014
3195
  for(var i = 0; i < priorityFormats.length; i++){
3015
- var capabilities = this._supportedMap[priorityFormats[i]];
3016
- for(var j = 0; j < capabilities.length; j++){
3017
- if (renderer.canIUse(capabilities[j])) {
3018
- return priorityFormats[i];
3196
+ var format = priorityFormats[i];
3197
+ var capabilities = this._supportedMap[format];
3198
+ if (capabilities) {
3199
+ for(var j = 0; j < capabilities.length; j++){
3200
+ if (renderer.canIUse(capabilities[j])) {
3201
+ return format;
3202
+ }
3203
+ }
3204
+ } else {
3205
+ switch(priorityFormats[i]){
3206
+ case exports.KTX2TargetFormat.R8G8B8A8:
3207
+ return format;
3208
+ case exports.KTX2TargetFormat.R8:
3209
+ case exports.KTX2TargetFormat.R8G8:
3210
+ if (renderer.isWebGL2) return format;
3019
3211
  }
3020
3212
  }
3021
3213
  }
@@ -3052,6 +3244,23 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
3052
3244
  return KTX2Loader1;
3053
3245
  }(miniprogram.Loader), function() {
3054
3246
  _KTX2Loader._isBinomialInit = false;
3247
+ }(), function() {
3248
+ _KTX2Loader._priorityFormats = {
3249
+ etc1s: [
3250
+ exports.KTX2TargetFormat.ETC,
3251
+ exports.KTX2TargetFormat.BC7,
3252
+ exports.KTX2TargetFormat.ASTC,
3253
+ exports.KTX2TargetFormat.BC1_BC3,
3254
+ exports.KTX2TargetFormat.PVRTC
3255
+ ],
3256
+ uastc: [
3257
+ exports.KTX2TargetFormat.ASTC,
3258
+ exports.KTX2TargetFormat.BC7,
3259
+ exports.KTX2TargetFormat.ETC,
3260
+ exports.KTX2TargetFormat.BC1_BC3,
3261
+ exports.KTX2TargetFormat.PVRTC
3262
+ ]
3263
+ };
3055
3264
  }(), function() {
3056
3265
  var _obj;
3057
3266
  _KTX2Loader._supportedMap = (_obj = {}, _obj[exports.KTX2TargetFormat.ASTC] = [
@@ -3072,6 +3281,11 @@ exports.KTX2Loader = __decorate([
3072
3281
  "ktx2"
3073
3282
  ])
3074
3283
  ], exports.KTX2Loader);
3284
+ exports.KTX2Transcoder = void 0;
3285
+ (function(KTX2Transcoder) {
3286
+ KTX2Transcoder[KTX2Transcoder[/** BinomialLLC transcoder. */ "BinomialLLC"] = 0] = "BinomialLLC";
3287
+ KTX2Transcoder[KTX2Transcoder["Khronos"] = 1] = "Khronos";
3288
+ })(exports.KTX2Transcoder || (exports.KTX2Transcoder = {}));
3075
3289
 
3076
3290
  /**
3077
3291
  * @internal
@@ -3422,7 +3636,7 @@ exports.GLTFSchemaParser = /*#__PURE__*/ function(GLTFParser1) {
3422
3636
  };
3423
3637
  var isGLB = this._isGLB(url);
3424
3638
  contentRestorer.isGLB = isGLB;
3425
- var promise = isGLB ? miniprogram.request(url, requestConfig).then(function(glb) {
3639
+ var promise = isGLB ? miniprogram.request(url, requestConfig).onProgress(undefined, context._onTaskDetail).then(function(glb) {
3426
3640
  restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
3427
3641
  return GLTFUtils.parseGLB(context, glb);
3428
3642
  }).then(function(param) {
@@ -3431,7 +3645,7 @@ exports.GLTFSchemaParser = /*#__PURE__*/ function(GLTFParser1) {
3431
3645
  return glTF;
3432
3646
  }) : miniprogram.request(url, {
3433
3647
  type: "json"
3434
- });
3648
+ }).onProgress(undefined, context._onTaskDetail);
3435
3649
  return promise;
3436
3650
  };
3437
3651
  _proto._isGLB = function _isGLB(url) {
@@ -3463,9 +3677,9 @@ exports.GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3463
3677
  * @internal
3464
3678
  */ GLTFAnimationParser1._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
3465
3679
  var _loop = function(j, m) {
3466
- var gltfSampler = samplers[j];
3467
- var inputAccessor = accessors[gltfSampler.input];
3468
- var outputAccessor = accessors[gltfSampler.output];
3680
+ var glTFSampler = samplers[j];
3681
+ var inputAccessor = accessors[glTFSampler.input];
3682
+ var outputAccessor = accessors[glTFSampler.output];
3469
3683
  var promise = Promise.all([
3470
3684
  GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor),
3471
3685
  GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor)
@@ -3481,8 +3695,8 @@ exports.GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3481
3695
  output = scaled;
3482
3696
  }
3483
3697
  var outputStride = output.length / input.length;
3484
- var _gltfSampler_interpolation;
3485
- var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
3698
+ var _glTFSampler_interpolation;
3699
+ var interpolation = (_glTFSampler_interpolation = glTFSampler.interpolation) != null ? _glTFSampler_interpolation : AnimationSamplerInterpolation.Linear;
3486
3700
  var samplerInterpolation;
3487
3701
  switch(interpolation){
3488
3702
  case AnimationSamplerInterpolation.CubicSpine:
@@ -3515,10 +3729,11 @@ exports.GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3515
3729
  var promises = new Array();
3516
3730
  // parse samplers
3517
3731
  for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
3732
+ promises.push(context.get(exports.GLTFParserType.Scene));
3518
3733
  return Promise.all(promises).then(function() {
3519
3734
  for(var j = 0, m = channels.length; j < m; j++){
3520
- var gltfChannel = channels[j];
3521
- var target = gltfChannel.target;
3735
+ var glTFChannel = channels[j];
3736
+ var target = glTFChannel.target;
3522
3737
  var channelTargetEntity = entities[target.node];
3523
3738
  var relativePath = "";
3524
3739
  var entity = channelTargetEntity;
@@ -3526,6 +3741,10 @@ exports.GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3526
3741
  relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
3527
3742
  entity = entity.parent;
3528
3743
  }
3744
+ // If the target node is in the default scene, relativePath will be empty
3745
+ if (context.glTFResource.sceneRoots.indexOf(entity) === -1) {
3746
+ continue;
3747
+ }
3529
3748
  var ComponentType = void 0;
3530
3749
  var propertyName = void 0;
3531
3750
  switch(target.path){
@@ -3546,14 +3765,21 @@ exports.GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3546
3765
  propertyName = "blendShapeWeights";
3547
3766
  break;
3548
3767
  }
3549
- var curve = _this._addCurve(target.path, gltfChannel, sampleDataCollection);
3550
- animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
3768
+ var curve = _this._addCurve(target.path, glTFChannel, sampleDataCollection);
3769
+ if (target.path === AnimationChannelTargetPath.WEIGHTS) {
3770
+ var mesh = glTF.nodes[target.node].mesh;
3771
+ for(var i = 0, n = glTF.meshes[mesh].primitives.length; i < n; i++){
3772
+ animationClip.addCurveBinding(relativePath, ComponentType, i, propertyName, curve);
3773
+ }
3774
+ } else {
3775
+ animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
3776
+ }
3551
3777
  }
3552
3778
  return animationClip;
3553
3779
  });
3554
3780
  };
3555
- GLTFAnimationParser1._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
3556
- var sampleData = sampleDataCollection[gltfChannel.sampler];
3781
+ GLTFAnimationParser1._addCurve = function _addCurve(animationChannelTargetPath, glTFChannel, sampleDataCollection) {
3782
+ var sampleData = sampleDataCollection[glTFChannel.sampler];
3557
3783
  var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
3558
3784
  switch(animationChannelTargetPath){
3559
3785
  case AnimationChannelTargetPath.TRANSLATION:
@@ -3645,7 +3871,9 @@ exports.GLTFBufferParser = /*#__PURE__*/ function(GLTFParser1) {
3645
3871
  };
3646
3872
  var absoluteUrl = miniprogram.Utils.resolveAbsoluteUrl(url, bufferInfo.uri);
3647
3873
  restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
3648
- return miniprogram.request(absoluteUrl, requestConfig);
3874
+ var promise = miniprogram.request(absoluteUrl, requestConfig).onProgress(undefined, context._onTaskDetail);
3875
+ context._addTaskCompletePromise(promise);
3876
+ return promise;
3649
3877
  };
3650
3878
  return GLTFBufferParser;
3651
3879
  }(GLTFParser);
@@ -3660,10 +3888,13 @@ exports.GLTFEntityParser = /*#__PURE__*/ function(GLTFParser1) {
3660
3888
  }
3661
3889
  var _proto = GLTFEntityParser.prototype;
3662
3890
  _proto.parse = function parse(context, index) {
3891
+ var glTFResource = context.glTFResource;
3663
3892
  var entityInfo = context.glTF.nodes[index];
3664
- var engine = context.glTFResource.engine;
3893
+ var engine = glTFResource.engine;
3665
3894
  var matrix = entityInfo.matrix, translation = entityInfo.translation, rotation = entityInfo.rotation, scale = entityInfo.scale, extensions = entityInfo.extensions;
3666
3895
  var entity = new miniprogram.Entity(engine, entityInfo.name || "_GLTF_ENTITY_" + index);
3896
+ // @ts-ignore
3897
+ entity._markAsTemplate(glTFResource);
3667
3898
  var transform = entity.transform;
3668
3899
  if (matrix) {
3669
3900
  var localMatrix = transform.localMatrix;
@@ -3705,7 +3936,8 @@ exports.GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
3705
3936
  var _proto = GLTFMaterialParser1.prototype;
3706
3937
  _proto.parse = function parse(context, index) {
3707
3938
  var materialInfo = context.glTF.materials[index];
3708
- var engine = context.glTFResource.engine;
3939
+ var glTFResource = context.glTFResource;
3940
+ var engine = glTFResource.engine;
3709
3941
  var material = GLTFParser.executeExtensionsCreateAndParse(materialInfo.extensions, context, materialInfo);
3710
3942
  if (!material) {
3711
3943
  material = new miniprogram.PBRMaterial(engine);
@@ -3713,8 +3945,10 @@ exports.GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
3713
3945
  exports.GLTFMaterialParser._parseStandardProperty(context, material, materialInfo);
3714
3946
  }
3715
3947
  return Promise.resolve(material).then(function(material) {
3716
- material || (material = exports.GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine));
3948
+ material || (material = exports.GLTFMaterialParser._getDefaultMaterial(engine));
3717
3949
  GLTFParser.executeExtensionsAdditiveAndParse(materialInfo.extensions, context, material, materialInfo);
3950
+ // @ts-ignore
3951
+ material._associationSuperResource(glTFResource);
3718
3952
  return material;
3719
3953
  });
3720
3954
  };
@@ -3835,14 +4069,20 @@ exports.GLTFMeshParser = (_GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1)
3835
4069
  var mesh = GLTFParser.executeExtensionsCreateAndParse(gltfPrimitive.extensions, context, gltfPrimitive, meshInfo);
3836
4070
  if (mesh) {
3837
4071
  if (_instanceof(mesh, miniprogram.ModelMesh)) {
4072
+ // @ts-ignore
4073
+ mesh._associationSuperResource(glTFResource);
3838
4074
  resolve(mesh);
3839
4075
  } else {
3840
4076
  mesh.then(function(mesh) {
3841
- return resolve(mesh);
4077
+ // @ts-ignore
4078
+ mesh._associationSuperResource(glTFResource);
4079
+ resolve(mesh);
3842
4080
  });
3843
4081
  }
3844
4082
  } else {
3845
4083
  var mesh1 = new miniprogram.ModelMesh(engine, meshInfo.name || i + "");
4084
+ // @ts-ignore
4085
+ mesh1._associationSuperResource(glTFResource);
3846
4086
  var meshRestoreInfo = new ModelMeshRestoreInfo();
3847
4087
  meshRestoreInfo.mesh = mesh1;
3848
4088
  context.contentRestorer.meshes.push(meshRestoreInfo);
@@ -3862,12 +4102,13 @@ exports.GLTFMeshParser = (_GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1)
3862
4102
  return context.get(exports.GLTFParserType.Buffer).then(function(buffers) {
3863
4103
  return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
3864
4104
  });
3865
- }, context.keepMeshData).then(resolve);
4105
+ }, context.params.keepMeshData).then(resolve);
3866
4106
  }
3867
4107
  });
3868
4108
  };
3869
4109
  var meshInfo = context.glTF.meshes[index];
3870
- var glTF = context.glTF, engine = context.glTFResource.engine;
4110
+ var glTF = context.glTF, glTFResource = context.glTFResource;
4111
+ var engine = glTFResource.engine;
3871
4112
  var primitivePromises = new Array();
3872
4113
  for(var i = 0, length = meshInfo.primitives.length; i < length; i++)_loop(i);
3873
4114
  return Promise.all(primitivePromises);
@@ -4040,9 +4281,9 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4040
4281
  }
4041
4282
  var _proto = GLTFSceneParser.prototype;
4042
4283
  _proto.parse = function parse(context, index) {
4043
- var _this = this;
4044
4284
  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;
4045
4285
  var sceneInfo = scenes[index];
4286
+ var sceneExtensions = sceneInfo.extensions;
4046
4287
  var engine = glTFResource.engine;
4047
4288
  var isDefaultScene = scene === index;
4048
4289
  var sceneNodes = sceneInfo.nodes;
@@ -4056,30 +4297,15 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4056
4297
  sceneRoot.addChild(childEntity);
4057
4298
  }
4058
4299
  }
4059
- // @ts-ignore
4060
- sceneRoot._hookResource = glTFResource;
4061
- // @ts-ignore
4062
- glTFResource._addReferCount(1);
4063
4300
  if (isDefaultScene) {
4064
- glTFResource.defaultSceneRoot = sceneRoot;
4301
+ glTFResource._defaultSceneRoot = sceneRoot;
4065
4302
  }
4066
4303
  var promises = new Array();
4067
4304
  for(var i1 = 0; i1 < sceneNodes.length; i1++){
4068
4305
  promises.push(this._parseEntityComponent(context, sceneNodes[i1]));
4069
4306
  }
4070
4307
  return Promise.all(promises).then(function() {
4071
- if (isDefaultScene) {
4072
- return Promise.all([
4073
- context.get(exports.GLTFParserType.Skin),
4074
- context.get(exports.GLTFParserType.Animation)
4075
- ]).then(function(param) {
4076
- var skins = param[0], animations = param[1];
4077
- if (skins || animations) {
4078
- _this._createAnimator(context, animations);
4079
- }
4080
- return sceneRoot;
4081
- });
4082
- }
4308
+ GLTFParser.executeExtensionsAdditiveAndParse(sceneExtensions, context, sceneRoot, sceneInfo);
4083
4309
  return sceneRoot;
4084
4310
  });
4085
4311
  };
@@ -4191,28 +4417,6 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4191
4417
  for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
4192
4418
  return Promise.all(promises);
4193
4419
  };
4194
- _proto._createAnimator = function _createAnimator(context, animations) {
4195
- var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
4196
- var animator = defaultSceneRoot.addComponent(miniprogram.Animator);
4197
- var animatorController = new miniprogram.AnimatorController();
4198
- var layer = new miniprogram.AnimatorControllerLayer("layer");
4199
- var animatorStateMachine = new miniprogram.AnimatorStateMachine();
4200
- animatorController.addLayer(layer);
4201
- animator.animatorController = animatorController;
4202
- layer.stateMachine = animatorStateMachine;
4203
- if (animations) {
4204
- for(var i = 0; i < animations.length; i++){
4205
- var animationClip = animations[i];
4206
- var name = animationClip.name;
4207
- var uniqueName = animatorStateMachine.makeUniqueStateName(name);
4208
- if (uniqueName !== name) {
4209
- console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
4210
- }
4211
- var animatorState = animatorStateMachine.addState(uniqueName);
4212
- animatorState.clip = animationClip;
4213
- }
4214
- }
4215
- };
4216
4420
  _proto._computeLocalBounds = function _computeLocalBounds(skinnedMeshRenderer, mesh, bones, rootBone, inverseBindMatrices) {
4217
4421
  var rootBoneIndex = bones.indexOf(rootBone);
4218
4422
  if (rootBoneIndex !== -1) {
@@ -4361,11 +4565,12 @@ exports.GLTFTextureParser = (_GLTFTextureParser = /*#__PURE__*/ function(GLTFPar
4361
4565
  params: {
4362
4566
  mipmap: (_samplerInfo = samplerInfo) == null ? void 0 : _samplerInfo.mipmap
4363
4567
  }
4364
- }).then(function(texture) {
4568
+ }).onProgress(undefined, context._onTaskDetail).then(function(texture) {
4365
4569
  texture.name = textureName || imageName || texture.name || "texture_" + index;
4366
4570
  useSampler && GLTFUtils.parseSampler(texture, samplerInfo);
4367
4571
  return texture;
4368
4572
  });
4573
+ context._addTaskCompletePromise(texture);
4369
4574
  } else {
4370
4575
  var bufferView = glTF.bufferViews[bufferViewIndex];
4371
4576
  texture = context.get(exports.GLTFParserType.Buffer).then(function(buffers) {
@@ -4387,6 +4592,8 @@ exports.GLTFTextureParser = (_GLTFTextureParser = /*#__PURE__*/ function(GLTFPar
4387
4592
  }
4388
4593
  return Promise.resolve(texture).then(function(texture) {
4389
4594
  GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, texture, textureInfo);
4595
+ // @ts-ignore
4596
+ texture._associationSuperResource(glTFResource);
4390
4597
  return texture;
4391
4598
  });
4392
4599
  };
@@ -4444,12 +4651,17 @@ var GLTFLoader = /*#__PURE__*/ function(Loader1) {
4444
4651
  }
4445
4652
  var _proto = GLTFLoader.prototype;
4446
4653
  _proto.load = function load(item, resourceManager) {
4447
- var _params;
4448
4654
  var url = item.url;
4449
4655
  var params = item.params;
4450
4656
  var glTFResource = new GLTFResource(resourceManager.engine, url);
4451
- var context = new GLTFParserContext(glTFResource, resourceManager, !!((_params = params) == null ? void 0 : _params.keepMeshData));
4452
- return context.parse();
4657
+ var context = new GLTFParserContext(glTFResource, resourceManager, _extends({
4658
+ keepMeshData: false
4659
+ }, params));
4660
+ return new miniprogram.AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
4661
+ context._setTaskCompleteProgress = setTaskCompleteProgress;
4662
+ context._setTaskDetailProgress = setTaskDetailProgress;
4663
+ context.parse().then(resolve).catch(reject);
4664
+ });
4453
4665
  };
4454
4666
  return GLTFLoader;
4455
4667
  }(miniprogram.Loader);
@@ -5096,6 +5308,12 @@ var MaterialLoader = /*#__PURE__*/ function(Loader1) {
5096
5308
  materialShaderData.setTexture(key, texture);
5097
5309
  }));
5098
5310
  break;
5311
+ case "Boolean":
5312
+ materialShaderData.setInt(key, value ? 1 : 0);
5313
+ break;
5314
+ case "Integer":
5315
+ materialShaderData.setInt(key, Number(value));
5316
+ break;
5099
5317
  }
5100
5318
  };
5101
5319
  var engine = resourceManager.engine;
@@ -5216,7 +5434,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader1) {
5216
5434
  var _proto = SpriteAtlasLoader.prototype;
5217
5435
  _proto.load = function load(item, resourceManager) {
5218
5436
  var _this = this;
5219
- return new miniprogram.AssetPromise(function(resolve, reject, _, onCancel) {
5437
+ return new miniprogram.AssetPromise(function(resolve, reject, _, __, onCancel) {
5220
5438
  var chainPromises = [];
5221
5439
  onCancel(function() {
5222
5440
  for(var i = 0; i < chainPromises.length; i++){
@@ -5231,9 +5449,10 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader1) {
5231
5449
  var _loop = function(i) {
5232
5450
  var atlasItem = atlasItems[i];
5233
5451
  if (atlasItem.img) {
5452
+ var _atlasItem_type;
5234
5453
  chainPromises.push(resourceManager.load({
5235
5454
  url: miniprogram.Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
5236
- type: miniprogram.AssetType.Texture2D,
5455
+ type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : miniprogram.AssetType.Texture2D,
5237
5456
  params: {
5238
5457
  format: format,
5239
5458
  mipmap: mipmap
@@ -5363,15 +5582,19 @@ var Texture2DLoader = /*#__PURE__*/ function(Loader1) {
5363
5582
  var _proto = Texture2DLoader.prototype;
5364
5583
  _proto.load = function load(item, resourceManager) {
5365
5584
  var _this = this;
5366
- return new miniprogram.AssetPromise(function(resolve, reject) {
5585
+ return new miniprogram.AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
5367
5586
  var url = item.url;
5368
5587
  var requestConfig = _extends({}, item, {
5369
5588
  type: "image"
5370
5589
  });
5371
- _this.request(url, requestConfig).then(function(image) {
5372
- var _params, _params1;
5373
- var params = item.params;
5374
- var texture = new miniprogram.Texture2D(resourceManager.engine, image.width, image.height, (_params = params) == null ? void 0 : _params.format, (_params1 = params) == null ? void 0 : _params1.mipmap);
5590
+ _this.request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(image) {
5591
+ var _item_params;
5592
+ var _ref = (_item_params = item.params) != null ? _item_params : {}, format = _ref.format, mipmap = _ref.mipmap, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
5593
+ var texture = new miniprogram.Texture2D(resourceManager.engine, image.width, image.height, format, mipmap);
5594
+ texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
5595
+ texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
5596
+ texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
5597
+ texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
5375
5598
  texture.setImageSource(image);
5376
5599
  texture.generateMipmaps();
5377
5600
  if (url.indexOf("data:") !== 0) {
@@ -5519,33 +5742,34 @@ var SceneLoader = /*#__PURE__*/ function(Loader1) {
5519
5742
  var promises = [];
5520
5743
  // parse ambient light
5521
5744
  var ambient = data.scene.ambient;
5522
- var useCustomAmbient = ambient.specularMode === "Custom";
5523
- if (useCustomAmbient && ambient.customAmbientLight) {
5524
- // @ts-ignore
5525
- // prettier-ignore
5526
- var customAmbientPromise = resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
5527
- scene.ambientLight = ambientLight;
5528
- scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
5529
- scene.ambientLight.specularIntensity = ambient.specularIntensity;
5530
- scene.ambientLight.diffuseMode = ambient.diffuseMode;
5531
- scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
5532
- });
5533
- promises.push(customAmbientPromise);
5534
- } else if (!useCustomAmbient && ambient.ambientLight) {
5535
- // @ts-ignore
5536
- // prettier-ignore
5537
- var ambientLightPromise = resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
5538
- scene.ambientLight = ambientLight;
5539
- scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
5540
- scene.ambientLight.specularIntensity = ambient.specularIntensity;
5541
- scene.ambientLight.diffuseMode = ambient.diffuseMode;
5542
- scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
5543
- });
5544
- promises.push(ambientLightPromise);
5545
- } else {
5745
+ if (ambient) {
5746
+ var useCustomAmbient = ambient.specularMode === "Custom";
5747
+ var useSH = ambient.diffuseMode === miniprogram.DiffuseMode.SphericalHarmonics;
5546
5748
  scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
5547
5749
  scene.ambientLight.specularIntensity = ambient.specularIntensity;
5750
+ scene.ambientLight.diffuseMode = ambient.diffuseMode;
5548
5751
  scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
5752
+ scene.ambientLight.specularTextureDecodeRGBM = true;
5753
+ if (useCustomAmbient && ambient.customAmbientLight) {
5754
+ promises.push(// @ts-ignore
5755
+ resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
5756
+ var _ambientLight;
5757
+ scene.ambientLight.specularTexture = (_ambientLight = ambientLight) == null ? void 0 : _ambientLight.specularTexture;
5758
+ }));
5759
+ }
5760
+ if (ambient.ambientLight && (!useCustomAmbient || useSH)) {
5761
+ promises.push(// @ts-ignore
5762
+ resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
5763
+ if (!useCustomAmbient) {
5764
+ var _ambientLight;
5765
+ scene.ambientLight.specularTexture = (_ambientLight = ambientLight) == null ? void 0 : _ambientLight.specularTexture;
5766
+ }
5767
+ if (useSH) {
5768
+ var _ambientLight1;
5769
+ scene.ambientLight.diffuseSphericalHarmonics = (_ambientLight1 = ambientLight) == null ? void 0 : _ambientLight1.diffuseSphericalHarmonics;
5770
+ }
5771
+ }));
5772
+ }
5549
5773
  }
5550
5774
  var background = data.scene.background;
5551
5775
  scene.background.mode = background.mode;
@@ -5587,6 +5811,9 @@ var SceneLoader = /*#__PURE__*/ function(Loader1) {
5587
5811
  if (shadow.shadowResolution != undefined) scene.shadowResolution = shadow.shadowResolution;
5588
5812
  if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
5589
5813
  if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
5814
+ var _shadow_shadowTwoCascadeSplits;
5815
+ scene.shadowTwoCascadeSplits = (_shadow_shadowTwoCascadeSplits = shadow.shadowTwoCascadeSplits) != null ? _shadow_shadowTwoCascadeSplits : scene.shadowTwoCascadeSplits;
5816
+ shadow.shadowFourCascadeSplits && scene.shadowFourCascadeSplits.copyFrom(shadow.shadowFourCascadeSplits);
5590
5817
  }
5591
5818
  return Promise.all(promises).then(function() {
5592
5819
  resolve(scene);
@@ -5602,13 +5829,13 @@ SceneLoader = __decorate([
5602
5829
  "scene"
5603
5830
  ], true)
5604
5831
  ], SceneLoader);
5605
- ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _async_to_generator(function(instance, item, engine) {
5832
+ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _async_to_generator(function(instance, item) {
5606
5833
  var props;
5607
5834
  return __generator(this, function(_state) {
5608
5835
  props = item.props;
5609
5836
  if (!props.font) {
5610
5837
  // @ts-ignore
5611
- instance.font = miniprogram.Font.createFromOS(engine, props.fontFamily || "Arial");
5838
+ instance.font = miniprogram.Font.createFromOS(instance.engine, props.fontFamily || "Arial");
5612
5839
  }
5613
5840
  return [
5614
5841
  2,
@@ -5664,7 +5891,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
5664
5891
  throw "BlendShape animation is not supported when using draco.";
5665
5892
  }, function() {
5666
5893
  return decodedGeometry.index.array;
5667
- }, context.keepMeshData);
5894
+ }, context.params.keepMeshData);
5668
5895
  });
5669
5896
  });
5670
5897
  };
@@ -5955,7 +6182,7 @@ var KHR_materials_variants = /*#__PURE__*/ function(GLTFExtensionParser1) {
5955
6182
  var _glTFResource;
5956
6183
  var _context_glTF = context.glTF, _context_glTF_extensions = _context_glTF.extensions, _context_glTF_extensions_KHR_materials_variants = _context_glTF_extensions.KHR_materials_variants, variantNames = _context_glTF_extensions_KHR_materials_variants.variants, glTFResource = context.glTFResource;
5957
6184
  var mappings = schema.mappings;
5958
- (_glTFResource = glTFResource).extensionsData || (_glTFResource.extensionsData = {});
6185
+ (_glTFResource = glTFResource)._extensionsData || (_glTFResource._extensionsData = {});
5959
6186
  var extensionData = [];
5960
6187
  glTFResource.extensionsData.variants = extensionData;
5961
6188
  for(var i = 0; i < mappings.length; i++)_loop(i);
@@ -5985,7 +6212,7 @@ var KHR_texture_basisu = /*#__PURE__*/ function(GLTFExtensionParser1) {
5985
6212
  var _proto = KHR_texture_basisu.prototype;
5986
6213
  _proto.createAndParse = function createAndParse(context, schema, textureInfo) {
5987
6214
  return _async_to_generator(function() {
5988
- var glTF, glTFResource, engine, url, sampler, textureName, source, _glTF_images_source, uri, bufferViewIndex, mimeType, imageName, samplerInfo, index, bufferView;
6215
+ var glTF, glTFResource, engine, url, sampler, textureName, source, _glTF_images_source, uri, bufferViewIndex, mimeType, imageName, samplerInfo, index, promise, bufferView;
5989
6216
  return __generator(this, function(_state) {
5990
6217
  glTF = context.glTF, glTFResource = context.glTFResource;
5991
6218
  engine = glTFResource.engine, url = glTFResource.url;
@@ -5995,20 +6222,22 @@ var KHR_texture_basisu = /*#__PURE__*/ function(GLTFExtensionParser1) {
5995
6222
  samplerInfo = sampler !== undefined && GLTFUtils.getSamplerInfo(glTF.samplers[sampler]);
5996
6223
  if (uri) {
5997
6224
  index = uri.lastIndexOf(".");
6225
+ promise = engine.resourceManager.load({
6226
+ url: miniprogram.Utils.resolveAbsoluteUrl(url, uri),
6227
+ type: miniprogram.AssetType.KTX2
6228
+ }).onProgress(undefined, context._onTaskDetail).then(function(texture) {
6229
+ if (!texture.name) {
6230
+ texture.name = textureName || imageName || "texture_" + index;
6231
+ }
6232
+ if (sampler !== undefined) {
6233
+ GLTFUtils.parseSampler(texture, samplerInfo);
6234
+ }
6235
+ return texture;
6236
+ });
6237
+ context._addTaskCompletePromise(promise);
5998
6238
  return [
5999
6239
  2,
6000
- engine.resourceManager.load({
6001
- url: miniprogram.Utils.resolveAbsoluteUrl(url, uri),
6002
- type: miniprogram.AssetType.KTX2
6003
- }).then(function(texture) {
6004
- if (!texture.name) {
6005
- texture.name = textureName || imageName || "texture_" + index;
6006
- }
6007
- if (sampler !== undefined) {
6008
- GLTFUtils.parseSampler(texture, samplerInfo);
6009
- }
6010
- return texture;
6011
- })
6240
+ promise
6012
6241
  ];
6013
6242
  } else {
6014
6243
  bufferView = glTF.bufferViews[bufferViewIndex];
@@ -6078,7 +6307,9 @@ var GALACEAN_materials_remap = /*#__PURE__*/ function(GLTFExtensionParser1) {
6078
6307
  _proto.createAndParse = function createAndParse(context, schema) {
6079
6308
  var engine = context.glTFResource.engine;
6080
6309
  // @ts-ignore
6081
- return engine.resourceManager.getResourceByRef(schema);
6310
+ var promise = engine.resourceManager.getResourceByRef(schema);
6311
+ context._addTaskCompletePromise(promise);
6312
+ return promise;
6082
6313
  };
6083
6314
  return GALACEAN_materials_remap;
6084
6315
  }(GLTFExtensionParser);
@@ -6109,6 +6340,29 @@ GALACEAN_animation_event = __decorate([
6109
6340
  registerGLTFExtension("GALACEAN_animation_event", exports.GLTFExtensionMode.AdditiveParse)
6110
6341
  ], GALACEAN_animation_event);
6111
6342
 
6343
+ var KHR_materials_anisotropy = /*#__PURE__*/ function(GLTFExtensionParser1) {
6344
+ _inherits(KHR_materials_anisotropy, GLTFExtensionParser1);
6345
+ function KHR_materials_anisotropy() {
6346
+ return GLTFExtensionParser1.apply(this, arguments);
6347
+ }
6348
+ var _proto = KHR_materials_anisotropy.prototype;
6349
+ _proto.additiveParse = function additiveParse(context, material, schema) {
6350
+ var _schema_anisotropyStrength = schema.anisotropyStrength, anisotropyStrength = _schema_anisotropyStrength === void 0 ? 0 : _schema_anisotropyStrength, _schema_anisotropyRotation = schema.anisotropyRotation, anisotropyRotation = _schema_anisotropyRotation === void 0 ? 0 : _schema_anisotropyRotation, anisotropyTexture = schema.anisotropyTexture;
6351
+ material.anisotropy = anisotropyStrength;
6352
+ material.anisotropyRotation = anisotropyRotation;
6353
+ if (anisotropyTexture) {
6354
+ exports.GLTFMaterialParser._checkOtherTextureTransform(anisotropyTexture, "Anisotropy texture");
6355
+ context.get(exports.GLTFParserType.Texture, anisotropyTexture.index).then(function(texture) {
6356
+ material.anisotropyTexture = texture;
6357
+ });
6358
+ }
6359
+ };
6360
+ return KHR_materials_anisotropy;
6361
+ }(GLTFExtensionParser);
6362
+ KHR_materials_anisotropy = __decorate([
6363
+ registerGLTFExtension("KHR_materials_anisotropy", exports.GLTFExtensionMode.AdditiveParse)
6364
+ ], KHR_materials_anisotropy);
6365
+
6112
6366
  exports.ComponentMap = ComponentMap;
6113
6367
  exports.GLTFExtensionParser = GLTFExtensionParser;
6114
6368
  exports.GLTFParser = GLTFParser;