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