@galacean/engine-loader 0.0.0-experimental-double11.13 → 0.0.0-experimental-shaderlab.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.
@@ -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.position / 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
  }
@@ -540,15 +539,23 @@ var ReflectionParser = /*#__PURE__*/ function() {
540
539
  if (position) entity.transform.position.copyFrom(position);
541
540
  if (rotation) entity.transform.rotation.copyFrom(rotation);
542
541
  if (scale) entity.transform.scale.copyFrom(scale);
542
+ var _entityConfig_layer;
543
+ entity.layer = (_entityConfig_layer = entityConfig.layer) != null ? _entityConfig_layer : entity.layer;
543
544
  return entity;
544
545
  });
545
546
  };
546
547
  _proto.parseClassObject = function parseClassObject(item) {
548
+ var _this = this;
547
549
  var Class = miniprogram.Loader.getClass(item.class);
548
550
  var _item_constructParams;
549
551
  var params = (_item_constructParams = item.constructParams) != null ? _item_constructParams : [];
550
- var instance = _construct(Class, [].concat(params));
551
- return this.parsePropsAndMethods(instance, item);
552
+ return Promise.all(params.map(function(param) {
553
+ return _this.parseBasicType(param);
554
+ })).then(function(resultParams) {
555
+ return _construct(Class, [].concat(resultParams));
556
+ }).then(function(instance) {
557
+ return _this.parsePropsAndMethods(instance, item);
558
+ });
552
559
  };
553
560
  _proto.parsePropsAndMethods = function parsePropsAndMethods(instance, item) {
554
561
  var promises = [];
@@ -556,16 +563,14 @@ var ReflectionParser = /*#__PURE__*/ function() {
556
563
  for(var methodName in item.methods){
557
564
  var methodParams = item.methods[methodName];
558
565
  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);
566
+ promises.push(this.parseMethod(instance, methodName, methodParams[i]));
562
567
  }
563
568
  }
564
569
  }
565
570
  if (item.props) {
566
571
  var _this = this, _loop = function(key) {
567
572
  var value = item.props[key];
568
- var promise = _this.parseBasicType(value).then(function(v) {
573
+ var promise = _this.parseBasicType(value, instance[key]).then(function(v) {
569
574
  return instance[key] = v;
570
575
  });
571
576
  promises.push(promise);
@@ -587,7 +592,7 @@ var ReflectionParser = /*#__PURE__*/ function() {
587
592
  return (_instance = instance)[methodName].apply(_instance, [].concat(result));
588
593
  });
589
594
  };
590
- _proto.parseBasicType = function parseBasicType(value) {
595
+ _proto.parseBasicType = function parseBasicType(value, originValue) {
591
596
  var _this = this;
592
597
  if (Array.isArray(value)) {
593
598
  return Promise.all(value.map(function(item) {
@@ -604,13 +609,33 @@ var ReflectionParser = /*#__PURE__*/ function() {
604
609
  } else if (ReflectionParser._isEntityRef(value)) {
605
610
  // entity reference
606
611
  return Promise.resolve(this._context.entityMap.get(value.entityId));
607
- } else {
608
- // basic type
609
- return Promise.resolve(value);
612
+ } else if (originValue) {
613
+ var _this1 = this, _loop = function(key) {
614
+ if (key === "methods") {
615
+ var methods = value[key];
616
+ for(var methodName in methods){
617
+ var methodParams = methods[methodName];
618
+ for(var i = 0, count = methodParams.length; i < count; i++){
619
+ var params = methodParams[i];
620
+ var promise = _this1.parseMethod(originValue, methodName, params);
621
+ promises.push(promise);
622
+ }
623
+ }
624
+ } else {
625
+ promises.push(_this1.parseBasicType(value[key], originValue[key]).then(function(v) {
626
+ return originValue[key] = v;
627
+ }));
628
+ }
629
+ };
630
+ var promises = [];
631
+ for(var key in value)_loop(key);
632
+ return Promise.all(promises).then(function() {
633
+ return originValue;
634
+ });
610
635
  }
611
- } else {
612
- return Promise.resolve(value);
613
636
  }
637
+ // primitive type
638
+ return Promise.resolve(value);
614
639
  };
615
640
  _proto._getEntityByConfig = function _getEntityByConfig(entityConfig) {
616
641
  // @ts-ignore
@@ -1604,11 +1629,37 @@ var TextureWrapMode;
1604
1629
  _this.get(9),
1605
1630
  _this.get(2)
1606
1631
  ]).then(function() {
1632
+ var glTFResource = _this.glTFResource;
1633
+ if (glTFResource.skins || glTFResource.animations) {
1634
+ _this._createAnimator(_this, glTFResource.animations);
1635
+ }
1607
1636
  _this.resourceManager.addContentRestorer(_this.contentRestorer);
1608
- return _this.glTFResource;
1637
+ return glTFResource;
1609
1638
  });
1610
1639
  });
1611
1640
  };
1641
+ _proto._createAnimator = function _createAnimator(context, animations) {
1642
+ var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
1643
+ var animator = defaultSceneRoot.addComponent(miniprogram.Animator);
1644
+ var animatorController = new miniprogram.AnimatorController();
1645
+ var layer = new miniprogram.AnimatorControllerLayer("layer");
1646
+ var animatorStateMachine = new miniprogram.AnimatorStateMachine();
1647
+ animatorController.addLayer(layer);
1648
+ animator.animatorController = animatorController;
1649
+ layer.stateMachine = animatorStateMachine;
1650
+ if (animations) {
1651
+ for(var i = 0; i < animations.length; i++){
1652
+ var animationClip = animations[i];
1653
+ var name = animationClip.name;
1654
+ var uniqueName = animatorStateMachine.makeUniqueStateName(name);
1655
+ if (uniqueName !== name) {
1656
+ console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
1657
+ }
1658
+ var animatorState = animatorStateMachine.addState(uniqueName);
1659
+ animatorState.clip = animationClip;
1660
+ }
1661
+ }
1662
+ };
1612
1663
  _proto._handleSubAsset = function _handleSubAsset(resource, type, index) {
1613
1664
  var _this = this;
1614
1665
  var glTFResourceKey = glTFResourceMap[type];
@@ -2585,6 +2636,7 @@ function transcode(buffer, targetFormat, KTX2File) {
2585
2636
  var faceCount = ktx2File.getFaces();
2586
2637
  var format = getTranscodeFormatFromTarget(targetFormat, hasAlpha);
2587
2638
  var faces = new Array(faceCount);
2639
+ var isBC = format === 2 || format === 3 || format === 7;
2588
2640
  for(var face = 0; face < faceCount; face++){
2589
2641
  var mipmaps = new Array(levelCount);
2590
2642
  for(var mip = 0; mip < levelCount; mip++){
@@ -2592,8 +2644,15 @@ function transcode(buffer, targetFormat, KTX2File) {
2592
2644
  var mipWidth = void 0, mipHeight = void 0;
2593
2645
  for(var layer = 0; layer < layerCount; layer++){
2594
2646
  var levelInfo = ktx2File.getImageLevelInfo(mip, layer, face);
2595
- mipWidth = levelInfo.origWidth;
2596
- mipHeight = levelInfo.origHeight;
2647
+ // see: https://github.com/KhronosGroup/KTX-Software/issues/254
2648
+ if (isBC && mip === 0 && (width !== levelInfo.width || height !== levelInfo.height)) {
2649
+ width = mipWidth = levelInfo.width;
2650
+ height = mipHeight = levelInfo.height;
2651
+ 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.");
2652
+ } else {
2653
+ mipWidth = levelInfo.origWidth;
2654
+ mipHeight = levelInfo.origHeight;
2655
+ }
2597
2656
  var dst = new Uint8Array(ktx2File.getImageTranscodedSizeInBytes(mip, layer, 0, format));
2598
2657
  var status = ktx2File.transcodeImage(dst, mip, layer, face, format, 0, -1, -1);
2599
2658
  if (!status) {
@@ -2905,11 +2964,14 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
2905
2964
  return Loader1.apply(this, arguments);
2906
2965
  }
2907
2966
  var _proto = KTX2Loader1.prototype;
2908
- _proto.initialize = function initialize(engine, configuration) {
2967
+ _proto.initialize = function initialize(_, configuration) {
2909
2968
  if (configuration.ktx2Loader) {
2910
2969
  var options = configuration.ktx2Loader;
2911
- if (options.priorityFormats) exports.KTX2Loader._priorityFormats = options.priorityFormats;
2912
- if (this._isKhronosSupported(options.priorityFormats, engine) && options.workerCount !== 0) {
2970
+ if (options.priorityFormats) {
2971
+ exports.KTX2Loader._priorityFormats["etc1s"] = options.priorityFormats;
2972
+ exports.KTX2Loader._priorityFormats["uastc"] = options.priorityFormats;
2973
+ }
2974
+ if (options.transcoder === /** Khronos transcoder. */ 1) {
2913
2975
  return exports.KTX2Loader._getKhronosTranscoder(options.workerCount).init();
2914
2976
  } else {
2915
2977
  return exports.KTX2Loader._getBinomialLLCTranscoder(options.workerCount).init();
@@ -2928,17 +2990,6 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
2928
2990
  });
2929
2991
  });
2930
2992
  };
2931
- _proto._isKhronosSupported = function _isKhronosSupported(priorityFormats, engine) {
2932
- if (priorityFormats === void 0) priorityFormats = [
2933
- exports.KTX2TargetFormat.ASTC,
2934
- exports.KTX2TargetFormat.ETC,
2935
- exports.KTX2TargetFormat.BC7,
2936
- exports.KTX2TargetFormat.BC1_BC3,
2937
- exports.KTX2TargetFormat.PVRTC,
2938
- exports.KTX2TargetFormat.R8G8B8A8
2939
- ];
2940
- return !!KhronosTranscoder.transcoderMap[exports.KTX2Loader._detectSupportedFormat(engine._hardwareRenderer, priorityFormats)];
2941
- };
2942
2993
  /**
2943
2994
  * Destroy ktx2 transcoder worker.
2944
2995
  */ KTX2Loader1.destroy = function destroy() {
@@ -2952,7 +3003,7 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
2952
3003
  var _params;
2953
3004
  var ktx2Container = new KTX2Container(buffer);
2954
3005
  var _params_priorityFormats;
2955
- var formatPriorities = (_params_priorityFormats = (_params = params) == null ? void 0 : _params.priorityFormats) != null ? _params_priorityFormats : exports.KTX2Loader._priorityFormats;
3006
+ var formatPriorities = (_params_priorityFormats = (_params = params) == null ? void 0 : _params.priorityFormats) != null ? _params_priorityFormats : exports.KTX2Loader._priorityFormats[ktx2Container.isUASTC ? "uastc" : "etc1s"];
2956
3007
  var targetFormat = exports.KTX2Loader._decideTargetFormat(engine, ktx2Container, formatPriorities);
2957
3008
  var transcodeResultPromise;
2958
3009
  if (exports.KTX2Loader._isBinomialInit || !KhronosTranscoder.transcoderMap[targetFormat] || !ktx2Container.isUASTC) {
@@ -3020,11 +3071,21 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
3020
3071
  };
3021
3072
  KTX2Loader1._detectSupportedFormat = function _detectSupportedFormat(renderer, priorityFormats) {
3022
3073
  for(var i = 0; i < priorityFormats.length; i++){
3023
- var capabilities = this._supportedMap[priorityFormats[i]];
3024
- if (!capabilities) return null;
3025
- for(var j = 0; j < capabilities.length; j++){
3026
- if (renderer.canIUse(capabilities[j])) {
3027
- return priorityFormats[i];
3074
+ var format = priorityFormats[i];
3075
+ var capabilities = this._supportedMap[format];
3076
+ if (capabilities) {
3077
+ for(var j = 0; j < capabilities.length; j++){
3078
+ if (renderer.canIUse(capabilities[j])) {
3079
+ return format;
3080
+ }
3081
+ }
3082
+ } else {
3083
+ switch(priorityFormats[i]){
3084
+ case exports.KTX2TargetFormat.R8G8B8A8:
3085
+ return format;
3086
+ case exports.KTX2TargetFormat.R8:
3087
+ case exports.KTX2TargetFormat.R8G8:
3088
+ if (renderer.isWebGL2) return format;
3028
3089
  }
3029
3090
  }
3030
3091
  }
@@ -3062,13 +3123,22 @@ exports.KTX2Loader = (_KTX2Loader = /*#__PURE__*/ function(Loader1) {
3062
3123
  }(miniprogram.Loader), function() {
3063
3124
  _KTX2Loader._isBinomialInit = false;
3064
3125
  }(), function() {
3065
- _KTX2Loader._priorityFormats = [
3066
- exports.KTX2TargetFormat.BC7,
3067
- exports.KTX2TargetFormat.ASTC,
3068
- exports.KTX2TargetFormat.BC1_BC3,
3069
- exports.KTX2TargetFormat.ETC,
3070
- exports.KTX2TargetFormat.PVRTC
3071
- ];
3126
+ _KTX2Loader._priorityFormats = {
3127
+ etc1s: [
3128
+ exports.KTX2TargetFormat.ETC,
3129
+ exports.KTX2TargetFormat.BC7,
3130
+ exports.KTX2TargetFormat.ASTC,
3131
+ exports.KTX2TargetFormat.BC1_BC3,
3132
+ exports.KTX2TargetFormat.PVRTC
3133
+ ],
3134
+ uastc: [
3135
+ exports.KTX2TargetFormat.ASTC,
3136
+ exports.KTX2TargetFormat.BC7,
3137
+ exports.KTX2TargetFormat.ETC,
3138
+ exports.KTX2TargetFormat.BC1_BC3,
3139
+ exports.KTX2TargetFormat.PVRTC
3140
+ ]
3141
+ };
3072
3142
  }(), function() {
3073
3143
  var _obj;
3074
3144
  _KTX2Loader._supportedMap = (_obj = {}, _obj[exports.KTX2TargetFormat.ASTC] = [
@@ -3089,6 +3159,11 @@ exports.KTX2Loader = __decorate([
3089
3159
  "ktx2"
3090
3160
  ])
3091
3161
  ], exports.KTX2Loader);
3162
+ exports.KTX2Transcoder = void 0;
3163
+ (function(KTX2Transcoder) {
3164
+ KTX2Transcoder[KTX2Transcoder[/** BinomialLLC transcoder. */ "BinomialLLC"] = 0] = "BinomialLLC";
3165
+ KTX2Transcoder[KTX2Transcoder["Khronos"] = 1] = "Khronos";
3166
+ })(exports.KTX2Transcoder || (exports.KTX2Transcoder = {}));
3092
3167
 
3093
3168
  /**
3094
3169
  * @internal
@@ -3532,6 +3607,7 @@ exports.GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3532
3607
  var promises = new Array();
3533
3608
  // parse samplers
3534
3609
  for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
3610
+ promises.push(context.get(exports.GLTFParserType.Scene));
3535
3611
  return Promise.all(promises).then(function() {
3536
3612
  for(var j = 0, m = channels.length; j < m; j++){
3537
3613
  var gltfChannel = channels[j];
@@ -3543,6 +3619,10 @@ exports.GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
3543
3619
  relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
3544
3620
  entity = entity.parent;
3545
3621
  }
3622
+ // If the target node is in the default scene, relativePath will be empty
3623
+ if (context.glTFResource.sceneRoots.indexOf(entity) === -1) {
3624
+ continue;
3625
+ }
3546
3626
  var ComponentType = void 0;
3547
3627
  var propertyName = void 0;
3548
3628
  switch(target.path){
@@ -4057,7 +4137,6 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4057
4137
  }
4058
4138
  var _proto = GLTFSceneParser.prototype;
4059
4139
  _proto.parse = function parse(context, index) {
4060
- var _this = this;
4061
4140
  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;
4062
4141
  var sceneInfo = scenes[index];
4063
4142
  var sceneExtensions = sceneInfo.extensions;
@@ -4087,18 +4166,6 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4087
4166
  }
4088
4167
  return Promise.all(promises).then(function() {
4089
4168
  GLTFParser.executeExtensionsAdditiveAndParse(sceneExtensions, context, sceneRoot, sceneInfo);
4090
- if (isDefaultScene) {
4091
- return Promise.all([
4092
- context.get(exports.GLTFParserType.Skin),
4093
- context.get(exports.GLTFParserType.Animation)
4094
- ]).then(function(param) {
4095
- var skins = param[0], animations = param[1];
4096
- if (skins || animations) {
4097
- _this._createAnimator(context, animations);
4098
- }
4099
- return sceneRoot;
4100
- });
4101
- }
4102
4169
  return sceneRoot;
4103
4170
  });
4104
4171
  };
@@ -4210,28 +4277,6 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4210
4277
  for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
4211
4278
  return Promise.all(promises);
4212
4279
  };
4213
- _proto._createAnimator = function _createAnimator(context, animations) {
4214
- var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
4215
- var animator = defaultSceneRoot.addComponent(miniprogram.Animator);
4216
- var animatorController = new miniprogram.AnimatorController();
4217
- var layer = new miniprogram.AnimatorControllerLayer("layer");
4218
- var animatorStateMachine = new miniprogram.AnimatorStateMachine();
4219
- animatorController.addLayer(layer);
4220
- animator.animatorController = animatorController;
4221
- layer.stateMachine = animatorStateMachine;
4222
- if (animations) {
4223
- for(var i = 0; i < animations.length; i++){
4224
- var animationClip = animations[i];
4225
- var name = animationClip.name;
4226
- var uniqueName = animatorStateMachine.makeUniqueStateName(name);
4227
- if (uniqueName !== name) {
4228
- console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
4229
- }
4230
- var animatorState = animatorStateMachine.addState(uniqueName);
4231
- animatorState.clip = animationClip;
4232
- }
4233
- }
4234
- };
4235
4280
  _proto._computeLocalBounds = function _computeLocalBounds(skinnedMeshRenderer, mesh, bones, rootBone, inverseBindMatrices) {
4236
4281
  var rootBoneIndex = bones.indexOf(rootBone);
4237
4282
  if (rootBoneIndex !== -1) {
@@ -5116,6 +5161,12 @@ var MaterialLoader = /*#__PURE__*/ function(Loader1) {
5116
5161
  materialShaderData.setTexture(key, texture);
5117
5162
  }));
5118
5163
  break;
5164
+ case "Boolean":
5165
+ materialShaderData.setInt(key, value ? 1 : 0);
5166
+ break;
5167
+ case "Integer":
5168
+ materialShaderData.setInt(key, Number(value));
5169
+ break;
5119
5170
  }
5120
5171
  };
5121
5172
  var engine = resourceManager.engine;
@@ -5251,9 +5302,10 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader1) {
5251
5302
  var _loop = function(i) {
5252
5303
  var atlasItem = atlasItems[i];
5253
5304
  if (atlasItem.img) {
5305
+ var _atlasItem_type;
5254
5306
  chainPromises.push(resourceManager.load({
5255
5307
  url: miniprogram.Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
5256
- type: miniprogram.AssetType.Texture2D,
5308
+ type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : miniprogram.AssetType.Texture2D,
5257
5309
  params: {
5258
5310
  format: format,
5259
5311
  mipmap: mipmap
@@ -5389,9 +5441,13 @@ var Texture2DLoader = /*#__PURE__*/ function(Loader1) {
5389
5441
  type: "image"
5390
5442
  });
5391
5443
  _this.request(url, requestConfig).then(function(image) {
5392
- var _params, _params1;
5393
- var params = item.params;
5394
- 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);
5444
+ var _item_params;
5445
+ 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;
5446
+ var texture = new miniprogram.Texture2D(resourceManager.engine, image.width, image.height, format, mipmap);
5447
+ texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
5448
+ texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
5449
+ texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
5450
+ texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
5395
5451
  texture.setImageSource(image);
5396
5452
  texture.generateMipmaps();
5397
5453
  if (url.indexOf("data:") !== 0) {
@@ -5539,29 +5595,34 @@ var SceneLoader = /*#__PURE__*/ function(Loader1) {
5539
5595
  var promises = [];
5540
5596
  // parse ambient light
5541
5597
  var ambient = data.scene.ambient;
5542
- var useCustomAmbient = ambient.specularMode === "Custom";
5543
- var useSH = ambient.diffuseMode === miniprogram.DiffuseMode.SphericalHarmonics;
5544
- scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
5545
- scene.ambientLight.specularIntensity = ambient.specularIntensity;
5546
- scene.ambientLight.diffuseMode = ambient.diffuseMode;
5547
- scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
5548
- scene.ambientLight.specularTextureDecodeRGBM = true;
5549
- if (useCustomAmbient && ambient.customAmbientLight) {
5550
- promises.push(// @ts-ignore
5551
- resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
5552
- scene.ambientLight.specularTexture = ambientLight.specularTexture;
5553
- }));
5554
- }
5555
- if (ambient.ambientLight && (!useCustomAmbient || useSH)) {
5556
- promises.push(// @ts-ignore
5557
- resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
5558
- if (!useCustomAmbient) {
5559
- scene.ambientLight.specularTexture = ambientLight.specularTexture;
5560
- }
5561
- if (useSH) {
5562
- scene.ambientLight.diffuseSphericalHarmonics = ambientLight.diffuseSphericalHarmonics;
5563
- }
5564
- }));
5598
+ if (ambient) {
5599
+ var useCustomAmbient = ambient.specularMode === "Custom";
5600
+ var useSH = ambient.diffuseMode === miniprogram.DiffuseMode.SphericalHarmonics;
5601
+ scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
5602
+ scene.ambientLight.specularIntensity = ambient.specularIntensity;
5603
+ scene.ambientLight.diffuseMode = ambient.diffuseMode;
5604
+ scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
5605
+ scene.ambientLight.specularTextureDecodeRGBM = true;
5606
+ if (useCustomAmbient && ambient.customAmbientLight) {
5607
+ promises.push(// @ts-ignore
5608
+ resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
5609
+ var _ambientLight;
5610
+ scene.ambientLight.specularTexture = (_ambientLight = ambientLight) == null ? void 0 : _ambientLight.specularTexture;
5611
+ }));
5612
+ }
5613
+ if (ambient.ambientLight && (!useCustomAmbient || useSH)) {
5614
+ promises.push(// @ts-ignore
5615
+ resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
5616
+ if (!useCustomAmbient) {
5617
+ var _ambientLight;
5618
+ scene.ambientLight.specularTexture = (_ambientLight = ambientLight) == null ? void 0 : _ambientLight.specularTexture;
5619
+ }
5620
+ if (useSH) {
5621
+ var _ambientLight1;
5622
+ scene.ambientLight.diffuseSphericalHarmonics = (_ambientLight1 = ambientLight) == null ? void 0 : _ambientLight1.diffuseSphericalHarmonics;
5623
+ }
5624
+ }));
5625
+ }
5565
5626
  }
5566
5627
  var background = data.scene.background;
5567
5628
  scene.background.mode = background.mode;
@@ -5603,6 +5664,9 @@ var SceneLoader = /*#__PURE__*/ function(Loader1) {
5603
5664
  if (shadow.shadowResolution != undefined) scene.shadowResolution = shadow.shadowResolution;
5604
5665
  if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
5605
5666
  if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
5667
+ var _shadow_shadowTwoCascadeSplits;
5668
+ scene.shadowTwoCascadeSplits = (_shadow_shadowTwoCascadeSplits = shadow.shadowTwoCascadeSplits) != null ? _shadow_shadowTwoCascadeSplits : scene.shadowTwoCascadeSplits;
5669
+ shadow.shadowFourCascadeSplits && scene.shadowFourCascadeSplits.copyFrom(shadow.shadowFourCascadeSplits);
5606
5670
  }
5607
5671
  return Promise.all(promises).then(function() {
5608
5672
  resolve(scene);