@galacean/engine-loader 1.0.0-beta.15 → 1.0.0-beta.17

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.
@@ -122,7 +122,8 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
122
122
  state.wrapMode = wrapMode;
123
123
  state.clipStartTime = clipStartNormalizedTime;
124
124
  state.clipEndTime = clipEndNormalizedTime;
125
- scripts == null ? void 0 : scripts.forEach(function(script) {
125
+ var scriptsObject = JSON.parse(scripts);
126
+ scriptsObject == null ? void 0 : scriptsObject.forEach(function(script) {
126
127
  state.addStateMachineScript(miniprogram.Loader.getClass(script));
127
128
  });
128
129
  if (clipData) {
@@ -222,7 +223,8 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
222
223
  var shArray = new Float32Array(arraybuffer, 0, 27);
223
224
  var shByteLength = 27 * 4;
224
225
  var size = (_ref = new Uint16Array(arraybuffer, shByteLength, 1)) == null ? void 0 : _ref[0];
225
- var texture = new miniprogram.TextureCube(resourceManager.engine, size);
226
+ var engine = resourceManager.engine;
227
+ var texture = new miniprogram.TextureCube(engine, size);
226
228
  texture.filterMode = miniprogram.TextureFilterMode.Trilinear;
227
229
  var mipmapCount = texture.mipmapCount;
228
230
  var offset = shByteLength + 2;
@@ -235,7 +237,7 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
235
237
  texture.setPixelBuffer(miniprogram.TextureCubeFace.PositiveX + face, data, mipLevel);
236
238
  }
237
239
  }
238
- var ambientLight = new miniprogram.AmbientLight();
240
+ var ambientLight = new miniprogram.AmbientLight(engine);
239
241
  var sh = new miniprogram$1.SphericalHarmonics3();
240
242
  ambientLight.diffuseMode = miniprogram.DiffuseMode.SphericalHarmonics;
241
243
  sh.copyFromArray(shArray);
@@ -705,6 +707,11 @@ var TextureWrapMode;
705
707
  promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
706
708
  }
707
709
  var _proto = GLTFParserContext.prototype;
710
+ /**
711
+ * Get all the buffer data.
712
+ */ _proto.getBuffers = function getBuffers() {
713
+ return Promise.resolve(this._buffers);
714
+ };
708
715
  _proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
709
716
  var promise = new miniprogram.AssetPromise(function(resolve, reject, setProgress, onCancel) {
710
717
  promiseInfo.resolve = resolve;
@@ -826,44 +833,45 @@ var TextureWrapMode;
826
833
  }
827
834
  };
828
835
  GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
829
- var buffers = context.buffers;
830
836
  var componentType = accessor.componentType;
831
837
  var bufferView = bufferViews[accessor.bufferView];
832
- var bufferIndex = bufferView.buffer;
833
- var buffer = buffers[bufferIndex];
834
- var bufferByteOffset = bufferView.byteOffset || 0;
835
- var byteOffset = accessor.byteOffset || 0;
836
- var TypedArray = GLTFUtils.getComponentType(componentType);
837
- var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
838
- var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
839
- var elementStride = dataElementSize * dataElementBytes;
840
- var accessorCount = accessor.count;
841
- var bufferStride = bufferView.byteStride;
842
- var bufferInfo;
843
- // According to the glTF official documentation only byteStride not undefined is allowed
844
- if (bufferStride !== undefined && bufferStride !== elementStride) {
845
- var bufferSlice = Math.floor(byteOffset / bufferStride);
846
- var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
847
- var accessorBufferCache = context.accessorBufferCache;
848
- bufferInfo = accessorBufferCache[bufferCacheKey];
849
- if (!bufferInfo) {
850
- var offset = bufferByteOffset + bufferSlice * bufferStride;
851
- var count = accessorCount * (bufferStride / dataElementBytes);
852
- var data = new TypedArray(buffer, offset, count);
853
- accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
854
- bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
838
+ return context.getBuffers().then(function(buffers) {
839
+ var bufferIndex = bufferView.buffer;
840
+ var buffer = buffers[bufferIndex];
841
+ var bufferByteOffset = bufferView.byteOffset || 0;
842
+ var byteOffset = accessor.byteOffset || 0;
843
+ var TypedArray = GLTFUtils.getComponentType(componentType);
844
+ var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
845
+ var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
846
+ var elementStride = dataElementSize * dataElementBytes;
847
+ var accessorCount = accessor.count;
848
+ var bufferStride = bufferView.byteStride;
849
+ var bufferInfo;
850
+ // According to the glTF official documentation only byteStride not undefined is allowed
851
+ if (bufferStride !== undefined && bufferStride !== elementStride) {
852
+ var bufferSlice = Math.floor(byteOffset / bufferStride);
853
+ var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
854
+ var accessorBufferCache = context.accessorBufferCache;
855
+ bufferInfo = accessorBufferCache[bufferCacheKey];
856
+ if (!bufferInfo) {
857
+ var offset = bufferByteOffset + bufferSlice * bufferStride;
858
+ var count = accessorCount * (bufferStride / dataElementBytes);
859
+ var data = new TypedArray(buffer, offset, count);
860
+ accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
861
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
862
+ }
863
+ } else {
864
+ var offset1 = bufferByteOffset + byteOffset;
865
+ var count1 = accessorCount * dataElementSize;
866
+ var data1 = new TypedArray(buffer, offset1, count1);
867
+ bufferInfo = new BufferInfo(data1, false, elementStride);
868
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
855
869
  }
856
- } else {
857
- var offset1 = bufferByteOffset + byteOffset;
858
- var count1 = accessorCount * dataElementSize;
859
- var data1 = new TypedArray(buffer, offset1, count1);
860
- bufferInfo = new BufferInfo(data1, false, elementStride);
861
- bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
862
- }
863
- if (accessor.sparse) {
864
- GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
865
- }
866
- return bufferInfo;
870
+ if (accessor.sparse) {
871
+ GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
872
+ }
873
+ return bufferInfo;
874
+ });
867
875
  };
868
876
  /**
869
877
  * @deprecated
@@ -1329,7 +1337,7 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
1329
1337
  }
1330
1338
  var _proto = GLTFAnimationParser.prototype;
1331
1339
  _proto.parse = function parse(context) {
1332
- var glTF = context.glTF; context.buffers; var glTFResource = context.glTFResource;
1340
+ var glTF = context.glTF, glTFResource = context.glTFResource;
1333
1341
  glTFResource.entities;
1334
1342
  var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
1335
1343
  if (!animations) {
@@ -1339,106 +1347,120 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
1339
1347
  var animationClipCount = animations.length;
1340
1348
  var animationClipPromises = [];
1341
1349
  new Array(animationClipCount);
1350
+ var parseStandardPropertyPromises = new Array();
1342
1351
  for(var i = 0; i < animationClipCount; i++){
1343
1352
  var animationInfo = animations[i];
1344
1353
  var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
1345
1354
  var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
1346
1355
  if (!animationClip) {
1347
1356
  animationClip = new miniprogram.AnimationClip(name);
1348
- GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
1357
+ parseStandardPropertyPromises.push(GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo));
1349
1358
  }
1350
1359
  animationClipPromises.push(animationClip);
1351
1360
  }
1352
- return miniprogram.AssetPromise.all(animationClipPromises).then(function(animationClips) {
1353
- glTFResource.animations = animationClips;
1354
- for(var i = 0; i < glTF.animations.length; i++){
1355
- var animationInfo = glTF.animations[i];
1356
- GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
1357
- }
1358
- animationClipsPromiseInfo.resolve(animationClips);
1359
- return animationClipsPromiseInfo.promise;
1361
+ return miniprogram.AssetPromise.all(parseStandardPropertyPromises).then(function() {
1362
+ return miniprogram.AssetPromise.all(animationClipPromises).then(function(animationClips) {
1363
+ glTFResource.animations = animationClips;
1364
+ for(var i = 0; i < glTF.animations.length; i++){
1365
+ var animationInfo = glTF.animations[i];
1366
+ GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
1367
+ }
1368
+ animationClipsPromiseInfo.resolve(animationClips);
1369
+ return animationClipsPromiseInfo.promise;
1370
+ });
1360
1371
  });
1361
1372
  };
1362
1373
  /**
1363
1374
  * @internal
1364
1375
  */ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
1376
+ var _loop = function(j, m) {
1377
+ var gltfSampler = samplers[j];
1378
+ var inputAccessor = accessors[gltfSampler.input];
1379
+ var outputAccessor = accessors[gltfSampler.output];
1380
+ var promise = Promise.all([
1381
+ GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor),
1382
+ GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor)
1383
+ ]).then(function(bufferInfos) {
1384
+ var input = bufferInfos[0].data;
1385
+ var output = bufferInfos[1].data;
1386
+ if (outputAccessor.normalized) {
1387
+ var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
1388
+ var scaled = new Float32Array(output.length);
1389
+ for(var k = 0, v = output.length; k < v; k++){
1390
+ scaled[k] = output[k] * scale;
1391
+ }
1392
+ output = scaled;
1393
+ }
1394
+ var outputStride = output.length / input.length;
1395
+ var _gltfSampler_interpolation;
1396
+ var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
1397
+ var samplerInterpolation;
1398
+ switch(interpolation){
1399
+ case AnimationSamplerInterpolation.CubicSpine:
1400
+ samplerInterpolation = miniprogram.InterpolationType.CubicSpine;
1401
+ break;
1402
+ case AnimationSamplerInterpolation.Step:
1403
+ samplerInterpolation = miniprogram.InterpolationType.Step;
1404
+ break;
1405
+ case AnimationSamplerInterpolation.Linear:
1406
+ samplerInterpolation = miniprogram.InterpolationType.Linear;
1407
+ break;
1408
+ }
1409
+ input[input.length - 1];
1410
+ sampleDataCollection.push({
1411
+ type: outputAccessor.type,
1412
+ interpolation: samplerInterpolation,
1413
+ input: input,
1414
+ output: output,
1415
+ outputSize: outputStride
1416
+ });
1417
+ });
1418
+ promises.push(promise);
1419
+ };
1420
+ var _this = this;
1365
1421
  var glTF = context.glTF, glTFResource = context.glTFResource;
1366
1422
  var entities = glTFResource.entities;
1367
1423
  var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
1368
1424
  var channels = animationInfo.channels, samplers = animationInfo.samplers;
1369
1425
  var sampleDataCollection = new Array();
1426
+ var promises = new Array();
1370
1427
  // parse samplers
1371
- for(var j = 0, m = samplers.length; j < m; j++){
1372
- var gltfSampler = samplers[j];
1373
- var inputAccessor = accessors[gltfSampler.input];
1374
- var outputAccessor = accessors[gltfSampler.output];
1375
- var input = GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor).data;
1376
- var output = GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor).data;
1377
- if (outputAccessor.normalized) {
1378
- var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
1379
- var scaled = new Float32Array(output.length);
1380
- for(var k = 0, v = output.length; k < v; k++){
1381
- scaled[k] = output[k] * scale;
1428
+ for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
1429
+ return Promise.all(promises).then(function() {
1430
+ for(var j = 0, m = channels.length; j < m; j++){
1431
+ var gltfChannel = channels[j];
1432
+ var target = gltfChannel.target;
1433
+ var channelTargetEntity = entities[target.node];
1434
+ var relativePath = "";
1435
+ var entity = channelTargetEntity;
1436
+ while(entity.parent){
1437
+ relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
1438
+ entity = entity.parent;
1382
1439
  }
1383
- output = scaled;
1384
- }
1385
- var outputStride = output.length / input.length;
1386
- var _gltfSampler_interpolation;
1387
- var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
1388
- var samplerInterpolation = void 0;
1389
- switch(interpolation){
1390
- case AnimationSamplerInterpolation.CubicSpine:
1391
- samplerInterpolation = miniprogram.InterpolationType.CubicSpine;
1392
- break;
1393
- case AnimationSamplerInterpolation.Step:
1394
- samplerInterpolation = miniprogram.InterpolationType.Step;
1395
- break;
1396
- case AnimationSamplerInterpolation.Linear:
1397
- samplerInterpolation = miniprogram.InterpolationType.Linear;
1398
- break;
1399
- }
1400
- input[input.length - 1];
1401
- sampleDataCollection.push({
1402
- type: outputAccessor.type,
1403
- interpolation: samplerInterpolation,
1404
- input: input,
1405
- output: output,
1406
- outputSize: outputStride
1407
- });
1408
- }
1409
- for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
1410
- var gltfChannel = channels[j1];
1411
- var target = gltfChannel.target;
1412
- var channelTargetEntity = entities[target.node];
1413
- var relativePath = "";
1414
- var entity = channelTargetEntity;
1415
- while(entity.parent){
1416
- relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
1417
- entity = entity.parent;
1418
- }
1419
- var ComponentType = void 0;
1420
- var propertyName = void 0;
1421
- switch(target.path){
1422
- case AnimationChannelTargetPath.TRANSLATION:
1423
- ComponentType = miniprogram.Transform;
1424
- propertyName = "position";
1425
- break;
1426
- case AnimationChannelTargetPath.ROTATION:
1427
- ComponentType = miniprogram.Transform;
1428
- propertyName = "rotationQuaternion";
1429
- break;
1430
- case AnimationChannelTargetPath.SCALE:
1431
- ComponentType = miniprogram.Transform;
1432
- propertyName = "scale";
1433
- break;
1434
- case AnimationChannelTargetPath.WEIGHTS:
1435
- ComponentType = miniprogram.SkinnedMeshRenderer;
1436
- propertyName = "blendShapeWeights";
1437
- break;
1440
+ var ComponentType = void 0;
1441
+ var propertyName = void 0;
1442
+ switch(target.path){
1443
+ case AnimationChannelTargetPath.TRANSLATION:
1444
+ ComponentType = miniprogram.Transform;
1445
+ propertyName = "position";
1446
+ break;
1447
+ case AnimationChannelTargetPath.ROTATION:
1448
+ ComponentType = miniprogram.Transform;
1449
+ propertyName = "rotationQuaternion";
1450
+ break;
1451
+ case AnimationChannelTargetPath.SCALE:
1452
+ ComponentType = miniprogram.Transform;
1453
+ propertyName = "scale";
1454
+ break;
1455
+ case AnimationChannelTargetPath.WEIGHTS:
1456
+ ComponentType = miniprogram.SkinnedMeshRenderer;
1457
+ propertyName = "blendShapeWeights";
1458
+ break;
1459
+ }
1460
+ var curve = _this._addCurve(target.path, gltfChannel, sampleDataCollection);
1461
+ animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
1438
1462
  }
1439
- var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
1440
- animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
1441
- }
1463
+ });
1442
1464
  };
1443
1465
  GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
1444
1466
  var sampleData = sampleDataCollection[gltfChannel.sampler];
@@ -1533,20 +1555,18 @@ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
1533
1555
  }).then(function(param) {
1534
1556
  var glTF = param.glTF, buffers = param.buffers;
1535
1557
  context.glTF = glTF;
1536
- context.buffers = buffers;
1558
+ context._buffers = buffers;
1537
1559
  });
1538
1560
  } else {
1539
1561
  return miniprogram.request(url, {
1540
1562
  type: "json"
1541
1563
  }).then(function(glTF) {
1542
1564
  context.glTF = glTF;
1543
- return Promise.all(glTF.buffers.map(function(buffer) {
1565
+ context._buffers = Promise.all(glTF.buffers.map(function(buffer) {
1544
1566
  var absoluteUrl = miniprogram.Utils.resolveAbsoluteUrl(url, buffer.uri);
1545
1567
  restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
1546
1568
  return miniprogram.request(absoluteUrl, requestConfig);
1547
- })).then(function(buffers) {
1548
- context.buffers = buffers;
1549
- });
1569
+ }));
1550
1570
  });
1551
1571
  }
1552
1572
  };
@@ -1795,7 +1815,9 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1795
1815
  }
1796
1816
  }, function() {
1797
1817
  var indexAccessor = glTF.accessors[gltfPrimitive.indices];
1798
- return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
1818
+ return context.getBuffers().then(function(buffers) {
1819
+ return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
1820
+ });
1799
1821
  }, context.keepMeshData).then(resolve);
1800
1822
  }
1801
1823
  });
@@ -1805,7 +1827,7 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1805
1827
  for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
1806
1828
  meshPromises[i] = Promise.all(primitivePromises);
1807
1829
  };
1808
- var glTF = context.glTF, buffers = context.buffers, glTFResource = context.glTFResource;
1830
+ var glTF = context.glTF, glTFResource = context.glTFResource;
1809
1831
  var engine = glTFResource.engine;
1810
1832
  if (!glTF.meshes) return;
1811
1833
  var meshesPromiseInfo = context.meshesPromiseInfo;
@@ -1820,8 +1842,109 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1820
1842
  /**
1821
1843
  * @internal
1822
1844
  */ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1845
+ var _loop = function(attribute) {
1846
+ var accessor = accessors[attributes[attribute]];
1847
+ var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor).then(function(accessorBuffer) {
1848
+ var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
1849
+ var accessorCount = accessor.count;
1850
+ var vertices = accessorBuffer.data;
1851
+ var vertexElement;
1852
+ var meshId = mesh.instanceId;
1853
+ var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
1854
+ var elementNormalized = accessor.normalized;
1855
+ var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
1856
+ var scaleFactor;
1857
+ elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
1858
+ var elementOffset;
1859
+ if (accessorBuffer.interleaved) {
1860
+ var byteOffset = accessor.byteOffset || 0;
1861
+ var stride = accessorBuffer.stride;
1862
+ elementOffset = byteOffset % stride;
1863
+ if (vertexBindingInfos[meshId] === undefined) {
1864
+ vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
1865
+ var vertexBuffer = accessorBuffer.vertexBuffer;
1866
+ if (!vertexBuffer) {
1867
+ vertexBuffer = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
1868
+ vertexBuffer.setData(vertices);
1869
+ accessorBuffer.vertexBuffer = vertexBuffer;
1870
+ meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
1871
+ }
1872
+ mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
1873
+ vertexBindingInfos[meshId] = bufferBindIndex++;
1874
+ } else {
1875
+ vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
1876
+ }
1877
+ } else {
1878
+ elementOffset = 0;
1879
+ vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
1880
+ var vertexBuffer1 = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
1881
+ vertexBuffer1.setData(vertices);
1882
+ meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
1883
+ mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
1884
+ vertexBindingInfos[meshId] = bufferBindIndex++;
1885
+ }
1886
+ vertexElements.push(vertexElement);
1887
+ if (attribute === "POSITION") {
1888
+ vertexCount = accessorCount;
1889
+ var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
1890
+ if (accessor.min && accessor.max) {
1891
+ min.copyFromArray(accessor.min);
1892
+ max.copyFromArray(accessor.max);
1893
+ if (keepMeshData) {
1894
+ var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
1895
+ var stride1 = vertices.length / accessorCount;
1896
+ for(var j = 0; j < accessorCount; j++){
1897
+ var offset = baseOffset + j * stride1;
1898
+ var position = new miniprogram$1.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
1899
+ elementNormalized && position.scale(scaleFactor);
1900
+ positions[j] = position;
1901
+ }
1902
+ }
1903
+ } else {
1904
+ var position1 = GLTFMeshParser._tempVector3;
1905
+ min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1906
+ max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1907
+ var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
1908
+ var stride2 = vertices.length / accessorCount;
1909
+ for(var j1 = 0; j1 < accessorCount; j1++){
1910
+ var offset1 = baseOffset1 + j1 * stride2;
1911
+ position1.copyFromArray(vertices, offset1);
1912
+ miniprogram$1.Vector3.min(min, position1, min);
1913
+ miniprogram$1.Vector3.max(max, position1, max);
1914
+ if (keepMeshData) {
1915
+ var clonePosition = position1.clone();
1916
+ elementNormalized && clonePosition.scale(scaleFactor);
1917
+ positions[j1] = clonePosition;
1918
+ }
1919
+ }
1920
+ }
1921
+ if (elementNormalized) {
1922
+ min.scale(scaleFactor);
1923
+ max.scale(scaleFactor);
1924
+ }
1925
+ } else if (attribute === "JOINTS_0" && keepMeshData) {
1926
+ var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
1927
+ var stride3 = vertices.length / accessorCount;
1928
+ for(var j2 = 0; j2 < accessorCount; j2++){
1929
+ var offset2 = baseOffset2 + j2 * stride3;
1930
+ var boneIndex = new miniprogram$1.Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
1931
+ elementNormalized && boneIndex.scale(scaleFactor);
1932
+ boneIndices[j2] = boneIndex;
1933
+ }
1934
+ } else if (attribute === "WEIGHTS_0" && keepMeshData) {
1935
+ var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
1936
+ var stride4 = vertices.length / accessorCount;
1937
+ for(var j3 = 0; j3 < accessorCount; j3++){
1938
+ var offset3 = baseOffset3 + j3 * stride4;
1939
+ var boneWeight = new miniprogram$1.Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
1940
+ elementNormalized && boneWeight.scale(scaleFactor);
1941
+ boneWeights[j3] = boneWeight;
1942
+ }
1943
+ }
1944
+ });
1945
+ promises.push(promise);
1946
+ };
1823
1947
  var accessors = gltf.accessors;
1824
- context.buffers;
1825
1948
  var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
1826
1949
  var engine = mesh.engine;
1827
1950
  var vertexElements = new Array();
@@ -1835,145 +1958,65 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1835
1958
  boneIndices = new Array(vertexCount);
1836
1959
  boneWeights = new Array(vertexCount);
1837
1960
  }
1838
- for(var attribute in attributes){
1839
- var accessor = accessors[attributes[attribute]];
1840
- var accessorBuffer = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor);
1841
- var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
1842
- var accessorCount = accessor.count;
1843
- var vertices = accessorBuffer.data;
1844
- var vertexElement = void 0;
1845
- var meshId = mesh.instanceId;
1846
- var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
1847
- var elementNormalized = accessor.normalized;
1848
- var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
1849
- var scaleFactor = void 0;
1850
- elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
1851
- var elementOffset = void 0;
1852
- if (accessorBuffer.interleaved) {
1853
- var byteOffset = accessor.byteOffset || 0;
1854
- var stride = accessorBuffer.stride;
1855
- elementOffset = byteOffset % stride;
1856
- if (vertexBindingInfos[meshId] === undefined) {
1857
- vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
1858
- var vertexBuffer = accessorBuffer.vertexBuffer;
1859
- if (!vertexBuffer) {
1860
- vertexBuffer = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
1861
- vertexBuffer.setData(vertices);
1862
- accessorBuffer.vertexBuffer = vertexBuffer;
1863
- meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
1864
- }
1865
- mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
1866
- vertexBindingInfos[meshId] = bufferBindIndex++;
1867
- } else {
1868
- vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
1869
- }
1961
+ var promises = new Array();
1962
+ for(var attribute in attributes)_loop(attribute);
1963
+ return Promise.all(promises).then(function() {
1964
+ mesh.setVertexElements(vertexElements);
1965
+ // Indices
1966
+ if (indices !== undefined) {
1967
+ var indexAccessor = gltf.accessors[indices];
1968
+ var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor).then(function(accessorBuffer) {
1969
+ mesh.setIndices(accessorBuffer.data);
1970
+ mesh.addSubMesh(0, indexAccessor.count, mode);
1971
+ meshRestoreInfo.indexBuffer = accessorBuffer.restoreInfo;
1972
+ });
1973
+ promises.push(promise);
1870
1974
  } else {
1871
- elementOffset = 0;
1872
- vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
1873
- var vertexBuffer1 = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
1874
- vertexBuffer1.setData(vertices);
1875
- meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
1876
- mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
1877
- vertexBindingInfos[meshId] = bufferBindIndex++;
1975
+ mesh.addSubMesh(0, vertexCount, mode);
1878
1976
  }
1879
- vertexElements.push(vertexElement);
1880
- if (attribute === "POSITION") {
1881
- vertexCount = accessorCount;
1882
- var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
1883
- if (accessor.min && accessor.max) {
1884
- min.copyFromArray(accessor.min);
1885
- max.copyFromArray(accessor.max);
1886
- if (keepMeshData) {
1887
- var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
1888
- var stride1 = vertices.length / accessorCount;
1889
- for(var j = 0; j < accessorCount; j++){
1890
- var offset = baseOffset + j * stride1;
1891
- var position = new miniprogram$1.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
1892
- elementNormalized && position.scale(scaleFactor);
1893
- positions[j] = position;
1894
- }
1895
- }
1896
- } else {
1897
- var position1 = GLTFMeshParser._tempVector3;
1898
- min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1899
- max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1900
- var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
1901
- var stride2 = vertices.length / accessorCount;
1902
- for(var j1 = 0; j1 < accessorCount; j1++){
1903
- var offset1 = baseOffset1 + j1 * stride2;
1904
- position1.copyFromArray(vertices, offset1);
1905
- miniprogram$1.Vector3.min(min, position1, min);
1906
- miniprogram$1.Vector3.max(max, position1, max);
1907
- if (keepMeshData) {
1908
- var clonePosition = position1.clone();
1909
- elementNormalized && clonePosition.scale(scaleFactor);
1910
- positions[j1] = clonePosition;
1911
- }
1912
- }
1913
- }
1914
- if (elementNormalized) {
1915
- min.scale(scaleFactor);
1916
- max.scale(scaleFactor);
1917
- }
1918
- } else if (attribute === "JOINTS_0" && keepMeshData) {
1919
- var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
1920
- var stride3 = vertices.length / accessorCount;
1921
- for(var j2 = 0; j2 < accessorCount; j2++){
1922
- var offset2 = baseOffset2 + j2 * stride3;
1923
- var boneIndex = new miniprogram$1.Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
1924
- elementNormalized && boneIndex.scale(scaleFactor);
1925
- boneIndices[j2] = boneIndex;
1926
- }
1927
- } else if (attribute === "WEIGHTS_0" && keepMeshData) {
1928
- var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
1929
- var stride4 = vertices.length / accessorCount;
1930
- for(var j3 = 0; j3 < accessorCount; j3++){
1931
- var offset3 = baseOffset3 + j3 * stride4;
1932
- var boneWeight = new miniprogram$1.Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
1933
- elementNormalized && boneWeight.scale(scaleFactor);
1934
- boneWeights[j3] = boneWeight;
1935
- }
1977
+ // BlendShapes
1978
+ if (targets) {
1979
+ promises.push(GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData));
1936
1980
  }
1937
- }
1938
- mesh.setVertexElements(vertexElements);
1939
- // Indices
1940
- if (indices !== undefined) {
1941
- var indexAccessor = gltf.accessors[indices];
1942
- var accessorBuffer1 = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor);
1943
- mesh.setIndices(accessorBuffer1.data);
1944
- mesh.addSubMesh(0, indexAccessor.count, mode);
1945
- meshRestoreInfo.indexBuffer = accessorBuffer1.restoreInfo;
1946
- } else {
1947
- mesh.addSubMesh(0, vertexCount, mode);
1948
- }
1949
- // BlendShapes
1950
- targets && GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData);
1951
- mesh.uploadData(!keepMeshData);
1952
- //@ts-ignore
1953
- mesh._positions = positions;
1954
- //@ts-ignore
1955
- mesh._boneIndices = boneIndices;
1956
- //@ts-ignore
1957
- mesh._boneWeights = boneWeights;
1958
- return Promise.resolve(mesh);
1981
+ return Promise.all(promises).then(function() {
1982
+ mesh.uploadData(!keepMeshData);
1983
+ //@ts-ignore
1984
+ mesh._positions = positions;
1985
+ //@ts-ignore
1986
+ mesh._boneIndices = boneIndices;
1987
+ //@ts-ignore
1988
+ mesh._boneWeights = boneWeights;
1989
+ return Promise.resolve(mesh);
1990
+ });
1991
+ });
1959
1992
  };
1960
1993
  /**
1961
1994
  * @internal
1962
1995
  */ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
1963
- var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
1964
- for(var i = 0, n = glTFTargets.length; i < n; i++){
1996
+ var _loop = function(i, n) {
1965
1997
  var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
1966
- var deltaPosBufferInfo = getBlendShapeData("POSITION", i);
1967
- var deltaNorBufferInfo = getBlendShapeData("NORMAL", i);
1968
- var deltaTanBufferInfo = getBlendShapeData("TANGENT", i);
1969
- var deltaPositions = deltaPosBufferInfo.data ? GLTFUtils.floatBufferToVector3Array(deltaPosBufferInfo.data) : null;
1970
- var deltaNormals = (deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) : null;
1971
- var deltaTangents = (deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) : null;
1972
- var blendShape = new miniprogram.BlendShape(name);
1973
- blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
1974
- mesh.addBlendShape(blendShape);
1975
- meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
1976
- }
1998
+ var promise = Promise.all([
1999
+ getBlendShapeData("POSITION", i),
2000
+ getBlendShapeData("NORMAL", i),
2001
+ getBlendShapeData("TANGENT", i)
2002
+ ]).then(function(infos) {
2003
+ var deltaPosBufferInfo = infos[0];
2004
+ var deltaNorBufferInfo = infos[1];
2005
+ var deltaTanBufferInfo = infos[2];
2006
+ var deltaPositions = deltaPosBufferInfo.data ? GLTFUtils.floatBufferToVector3Array(deltaPosBufferInfo.data) : null;
2007
+ var deltaNormals = (deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) : null;
2008
+ var deltaTangents = (deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) : null;
2009
+ var blendShape = new miniprogram.BlendShape(name);
2010
+ blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
2011
+ mesh.addBlendShape(blendShape);
2012
+ meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
2013
+ });
2014
+ promises.push(promise);
2015
+ };
2016
+ var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
2017
+ var promises = new Array();
2018
+ for(var i = 0, n = glTFTargets.length; i < n; i++)_loop(i);
2019
+ return Promise.all(promises);
1977
2020
  };
1978
2021
  return GLTFMeshParser;
1979
2022
  }(GLTFParser);
@@ -2125,51 +2168,58 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
2125
2168
  }
2126
2169
  var _proto = GLTFSkinParser.prototype;
2127
2170
  _proto.parse = function parse(context) {
2128
- var glTFResource = context.glTFResource, glTF = context.glTF; context.buffers;
2129
- var entities = glTFResource.entities;
2130
- var gltfSkins = glTF.skins;
2131
- if (!gltfSkins) return;
2132
- var count = gltfSkins.length;
2133
- var skins = new Array(count);
2134
- for(var i = 0; i < count; i++){
2171
+ var _loop = function(i) {
2135
2172
  var _gltfSkins_i = gltfSkins[i], inverseBindMatrices = _gltfSkins_i.inverseBindMatrices, skeleton = _gltfSkins_i.skeleton, joints = _gltfSkins_i.joints, _gltfSkins_i_name = _gltfSkins_i.name, name = _gltfSkins_i_name === void 0 ? "SKIN_" + i : _gltfSkins_i_name;
2136
2173
  var jointCount = joints.length;
2137
2174
  var skin = new miniprogram.Skin(name);
2138
2175
  skin.inverseBindMatrices.length = jointCount;
2139
2176
  // parse IBM
2140
2177
  var accessor = glTF.accessors[inverseBindMatrices];
2141
- var buffer = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).data;
2142
- for(var i1 = 0; i1 < jointCount; i1++){
2143
- var inverseBindMatrix = new miniprogram$1.Matrix();
2144
- inverseBindMatrix.copyFromArray(buffer, i1 * 16);
2145
- skin.inverseBindMatrices[i1] = inverseBindMatrix;
2146
- }
2147
- // get joints
2148
- for(var i2 = 0; i2 < jointCount; i2++){
2149
- var jointIndex = joints[i2];
2150
- var jointName = entities[jointIndex].name;
2151
- skin.joints[i2] = jointName;
2152
- // @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
2153
- for(var j = entities.length - 1; j >= 0; j--){
2154
- if (jointIndex !== j && entities[j].name === jointName) {
2155
- entities[j].name = jointName + "_" + j;
2178
+ var promise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
2179
+ var buffer = bufferInfo.data;
2180
+ for(var i = 0; i < jointCount; i++){
2181
+ var inverseBindMatrix = new miniprogram$1.Matrix();
2182
+ inverseBindMatrix.copyFromArray(buffer, i * 16);
2183
+ skin.inverseBindMatrices[i] = inverseBindMatrix;
2184
+ // get joints
2185
+ for(var i1 = 0; i1 < jointCount; i1++){
2186
+ var jointIndex = joints[i1];
2187
+ var jointName = entities[jointIndex].name;
2188
+ skin.joints[i1] = jointName;
2189
+ // @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
2190
+ for(var j = entities.length - 1; j >= 0; j--){
2191
+ if (jointIndex !== j && entities[j].name === jointName) {
2192
+ entities[j].name = jointName + "_" + j;
2193
+ }
2194
+ }
2195
+ }
2196
+ // get skeleton
2197
+ if (skeleton !== undefined) {
2198
+ skin.skeleton = entities[skeleton].name;
2199
+ } else {
2200
+ var rootBone = _this._findSkeletonRootBone(joints, entities);
2201
+ if (rootBone) {
2202
+ skin.skeleton = rootBone.name;
2203
+ } else {
2204
+ throw "Failed to find skeleton root bone.";
2205
+ }
2156
2206
  }
2157
2207
  }
2158
- }
2159
- // get skeleton
2160
- if (skeleton !== undefined) {
2161
- skin.skeleton = entities[skeleton].name;
2162
- } else {
2163
- var rootBone = this._findSkeletonRootBone(joints, entities);
2164
- if (rootBone) {
2165
- skin.skeleton = rootBone.name;
2166
- } else {
2167
- throw "Failed to find skeleton root bone.";
2168
- }
2169
- }
2170
- skins[i] = skin;
2171
- }
2172
- glTFResource.skins = skins;
2208
+ return skin;
2209
+ });
2210
+ promises.push(promise);
2211
+ };
2212
+ var _this = this;
2213
+ var glTFResource = context.glTFResource, glTF = context.glTF;
2214
+ var entities = glTFResource.entities;
2215
+ var gltfSkins = glTF.skins;
2216
+ if (!gltfSkins) return;
2217
+ var count = gltfSkins.length;
2218
+ var promises = new Array();
2219
+ for(var i = 0; i < count; i++)_loop(i);
2220
+ return miniprogram.AssetPromise.all(promises).then(function(skins) {
2221
+ glTFResource.skins = skins;
2222
+ });
2173
2223
  };
2174
2224
  _proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
2175
2225
  var paths = {};
@@ -2210,13 +2260,14 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
2210
2260
  var _proto = GLTFTextureParser.prototype;
2211
2261
  _proto.parse = function parse(context) {
2212
2262
  var _this = this;
2213
- var glTFResource = context.glTFResource, glTF = context.glTF, buffers = context.buffers;
2263
+ var glTFResource = context.glTFResource, glTF = context.glTF;
2214
2264
  var engine = glTFResource.engine, url = glTFResource.url;
2215
2265
  if (glTF.textures) {
2216
2266
  var texturesPromiseInfo = context.texturesPromiseInfo;
2217
2267
  miniprogram.AssetPromise.all(glTF.textures.map(function(param, index) {
2218
2268
  var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
2219
2269
  var _glTF_images_source = glTF.images[source], uri = _glTF_images_source.uri, bufferViewIndex = _glTF_images_source.bufferView, mimeType = _glTF_images_source.mimeType, imageName = _glTF_images_source.name;
2270
+ var samplerInfo = sampler !== undefined && _this._getSamplerInfo(glTF.samplers[sampler]);
2220
2271
  if (uri) {
2221
2272
  // TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
2222
2273
  var index1 = uri.lastIndexOf(".");
@@ -2224,31 +2275,36 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
2224
2275
  var type = ext.startsWith("ktx") ? miniprogram.AssetType.KTX : miniprogram.AssetType.Texture2D;
2225
2276
  return engine.resourceManager.load({
2226
2277
  url: miniprogram.Utils.resolveAbsoluteUrl(url, uri),
2227
- type: type
2278
+ type: type,
2279
+ params: {
2280
+ mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap
2281
+ }
2228
2282
  }).then(function(texture) {
2229
2283
  if (!texture.name) {
2230
2284
  texture.name = textureName || imageName || "texture_" + index1;
2231
2285
  }
2232
2286
  if (sampler !== undefined) {
2233
- _this._parseSampler(texture, glTF.samplers[sampler]);
2287
+ _this._parseSampler(texture, samplerInfo);
2234
2288
  }
2235
2289
  return texture;
2236
2290
  });
2237
2291
  } else {
2238
2292
  var bufferView = glTF.bufferViews[bufferViewIndex];
2239
- var buffer = buffers[bufferView.buffer];
2240
- var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
2241
- return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
2242
- var texture = new miniprogram.Texture2D(engine, image.width, image.height);
2243
- texture.setImageSource(image);
2244
- texture.generateMipmaps();
2245
- texture.name = textureName || imageName || "texture_" + index;
2246
- if (sampler !== undefined) {
2247
- _this._parseSampler(texture, glTF.samplers[sampler]);
2248
- }
2249
- var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
2250
- context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
2251
- return texture;
2293
+ return context.getBuffers().then(function(buffers) {
2294
+ var buffer = buffers[bufferView.buffer];
2295
+ var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
2296
+ return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
2297
+ var texture = new miniprogram.Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap);
2298
+ texture.setImageSource(image);
2299
+ texture.generateMipmaps();
2300
+ texture.name = textureName || imageName || "texture_" + index;
2301
+ if (sampler !== undefined) {
2302
+ _this._parseSampler(texture, samplerInfo);
2303
+ }
2304
+ var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
2305
+ context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
2306
+ return texture;
2307
+ });
2252
2308
  });
2253
2309
  }
2254
2310
  })).then(function(textures) {
@@ -2258,22 +2314,39 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
2258
2314
  return texturesPromiseInfo.promise;
2259
2315
  }
2260
2316
  };
2261
- _proto._parseSampler = function _parseSampler(texture, sampler) {
2262
- var magFilter = sampler.magFilter, minFilter = sampler.minFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
2263
- if (magFilter || minFilter) {
2317
+ _proto._getSamplerInfo = function _getSamplerInfo(sampler) {
2318
+ var minFilter = sampler.minFilter, magFilter = sampler.magFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
2319
+ var info = {};
2320
+ if (minFilter || magFilter) {
2321
+ info.mipmap = minFilter >= TextureMinFilter.NEAREST_MIPMAP_NEAREST;
2264
2322
  if (magFilter === TextureMagFilter.NEAREST) {
2265
- texture.filterMode = miniprogram.TextureFilterMode.Point;
2266
- } else if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
2267
- texture.filterMode = miniprogram.TextureFilterMode.Bilinear;
2323
+ info.filterMode = miniprogram.TextureFilterMode.Point;
2268
2324
  } else {
2269
- texture.filterMode = miniprogram.TextureFilterMode.Trilinear;
2325
+ if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
2326
+ info.filterMode = miniprogram.TextureFilterMode.Bilinear;
2327
+ } else {
2328
+ info.filterMode = miniprogram.TextureFilterMode.Trilinear;
2329
+ }
2270
2330
  }
2271
2331
  }
2272
2332
  if (wrapS) {
2273
- texture.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
2333
+ info.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
2274
2334
  }
2275
2335
  if (wrapT) {
2276
- texture.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
2336
+ info.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
2337
+ }
2338
+ return info;
2339
+ };
2340
+ _proto._parseSampler = function _parseSampler(texture, samplerInfo) {
2341
+ var filterMode = samplerInfo.filterMode, wrapModeU = samplerInfo.wrapModeU, wrapModeV = samplerInfo.wrapModeV;
2342
+ if (filterMode) {
2343
+ texture.filterMode = filterMode;
2344
+ }
2345
+ if (wrapModeU) {
2346
+ texture.wrapModeU = wrapModeU;
2347
+ }
2348
+ if (wrapModeV) {
2349
+ texture.wrapModeV = wrapModeV;
2277
2350
  }
2278
2351
  };
2279
2352
  return GLTFTextureParser;
@@ -4372,7 +4445,7 @@ var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
4372
4445
  _this.request(item.url, _extends({}, item, {
4373
4446
  type: "arraybuffer"
4374
4447
  })).then(function(data) {
4375
- return decode(data, resourceManager.engine);
4448
+ return decode(data, resourceManager.engine).then(resolve);
4376
4449
  }).catch(reject);
4377
4450
  });
4378
4451
  };
@@ -4511,7 +4584,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
4511
4584
  };
4512
4585
  _proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
4513
4586
  var _this = this;
4514
- var glTF = context.glTF, buffers = context.buffers, engine = context.glTFResource.engine;
4587
+ var glTF = context.glTF, engine = context.glTFResource.engine;
4515
4588
  var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
4516
4589
  var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
4517
4590
  var attributeMap = {};
@@ -4533,21 +4606,23 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
4533
4606
  useUniqueIDs: true,
4534
4607
  indexType: indexType
4535
4608
  };
4536
- var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
4537
- return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
4538
- var mesh = new miniprogram.ModelMesh(engine, glTFMesh.name);
4539
- return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
4540
- for(var j = 0; j < decodedGeometry.attributes.length; j++){
4541
- if (decodedGeometry.attributes[j].name === attributeSemantic) {
4542
- return decodedGeometry.attributes[j].array;
4609
+ return context.getBuffers().then(function(buffers) {
4610
+ var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
4611
+ return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
4612
+ var mesh = new miniprogram.ModelMesh(engine, glTFMesh.name);
4613
+ return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
4614
+ for(var j = 0; j < decodedGeometry.attributes.length; j++){
4615
+ if (decodedGeometry.attributes[j].name === attributeSemantic) {
4616
+ return decodedGeometry.attributes[j].array;
4617
+ }
4543
4618
  }
4544
- }
4545
- return null;
4546
- }, function(attributeSemantic, shapeIndex) {
4547
- throw "BlendShape animation is not supported when using draco.";
4548
- }, function() {
4549
- return decodedGeometry.index.array;
4550
- }, context.keepMeshData);
4619
+ return null;
4620
+ }, function(attributeSemantic, shapeIndex) {
4621
+ throw "BlendShape animation is not supported when using draco.";
4622
+ }, function() {
4623
+ return decodedGeometry.index.array;
4624
+ }, context.keepMeshData);
4625
+ });
4551
4626
  });
4552
4627
  };
4553
4628
  _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {