@galacean/engine-loader 1.0.0-beta.16 → 1.0.0-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +458 -340
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +458 -340
- package/dist/module.js +459 -341
- package/dist/module.js.map +1 -1
- package/package.json +5 -5
- package/types/GLTFContentRestorer.d.ts +17 -7
- package/types/gltf/GLTFUtil.d.ts +3 -3
- package/types/gltf/GLTFUtils.d.ts +2 -1
- package/types/gltf/parser/GLTFAnimationParser.d.ts +2 -2
- package/types/gltf/parser/GLTFMeshParser.d.ts +5 -5
- package/types/gltf/parser/GLTFParserContext.d.ts +6 -1
- package/types/gltf/parser/GLTFSceneParser.d.ts +2 -2
- package/types/gltf/parser/GLTFSkinParser.d.ts +2 -1
- package/types/gltf/parser/GLTFTextureParser.d.ts +3 -2
package/dist/miniprogram.js
CHANGED
|
@@ -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
|
-
|
|
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) {
|
|
@@ -443,15 +444,18 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
443
444
|
for(var _iterator2 = _create_for_of_iterator_helper_loose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
|
|
444
445
|
var restoreInfo = _step2.value;
|
|
445
446
|
var frame = restoreInfo.blendShape.frames[0];
|
|
446
|
-
var
|
|
447
|
-
|
|
447
|
+
var position = restoreInfo.position;
|
|
448
|
+
var positionData = _this._getBufferData(buffers, position.buffer);
|
|
449
|
+
frame.deltaPositions = GLTFUtils.bufferToVector3Array(positionData, position.stride, position.byteOffset, position.count);
|
|
448
450
|
if (restoreInfo.normal) {
|
|
449
|
-
var
|
|
450
|
-
|
|
451
|
+
var normal = restoreInfo.normal;
|
|
452
|
+
var normalData = _this._getBufferData(buffers, normal.buffer);
|
|
453
|
+
frame.deltaNormals = GLTFUtils.bufferToVector3Array(normalData, normal.stride, normal.byteOffset, normal.count);
|
|
451
454
|
}
|
|
452
455
|
if (restoreInfo.tangent) {
|
|
453
|
-
var
|
|
454
|
-
|
|
456
|
+
var tangent = restoreInfo.tangent;
|
|
457
|
+
var tangentData = _this._getBufferData(buffers, tangent.buffer);
|
|
458
|
+
frame.deltaTangents = GLTFUtils.bufferToVector3Array(tangentData, tangent.stride, tangent.byteOffset, tangent.count);
|
|
455
459
|
}
|
|
456
460
|
}
|
|
457
461
|
mesh.uploadData(true);
|
|
@@ -535,6 +539,14 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
535
539
|
this.normal = normal;
|
|
536
540
|
this.tangent = tangent;
|
|
537
541
|
};
|
|
542
|
+
/**
|
|
543
|
+
* @internal
|
|
544
|
+
*/ var BlendShapeDataRestoreInfo = function BlendShapeDataRestoreInfo(buffer, stride, byteOffset, count) {
|
|
545
|
+
this.buffer = buffer;
|
|
546
|
+
this.stride = stride;
|
|
547
|
+
this.byteOffset = byteOffset;
|
|
548
|
+
this.count = count;
|
|
549
|
+
};
|
|
538
550
|
|
|
539
551
|
/**
|
|
540
552
|
* Module for glTF 2.0 Interface
|
|
@@ -706,6 +718,11 @@ var TextureWrapMode;
|
|
|
706
718
|
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
707
719
|
}
|
|
708
720
|
var _proto = GLTFParserContext.prototype;
|
|
721
|
+
/**
|
|
722
|
+
* Get all the buffer data.
|
|
723
|
+
*/ _proto.getBuffers = function getBuffers() {
|
|
724
|
+
return Promise.resolve(this._buffers);
|
|
725
|
+
};
|
|
709
726
|
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
710
727
|
var promise = new miniprogram.AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
711
728
|
promiseInfo.resolve = resolve;
|
|
@@ -827,44 +844,58 @@ var TextureWrapMode;
|
|
|
827
844
|
}
|
|
828
845
|
};
|
|
829
846
|
GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
|
|
830
|
-
var buffers = context.buffers;
|
|
831
847
|
var componentType = accessor.componentType;
|
|
832
848
|
var bufferView = bufferViews[accessor.bufferView];
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
var
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
var
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
849
|
+
return context.getBuffers().then(function(buffers) {
|
|
850
|
+
var bufferIndex = bufferView.buffer;
|
|
851
|
+
var buffer = buffers[bufferIndex];
|
|
852
|
+
var _bufferView_byteOffset;
|
|
853
|
+
var bufferByteOffset = (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0;
|
|
854
|
+
var _accessor_byteOffset;
|
|
855
|
+
var byteOffset = (_accessor_byteOffset = accessor.byteOffset) != null ? _accessor_byteOffset : 0;
|
|
856
|
+
var TypedArray = GLTFUtils.getComponentType(componentType);
|
|
857
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
858
|
+
var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
859
|
+
var elementStride = dataElementSize * dataElementBytes;
|
|
860
|
+
var accessorCount = accessor.count;
|
|
861
|
+
var bufferStride = bufferView.byteStride;
|
|
862
|
+
var bufferInfo;
|
|
863
|
+
// According to the glTF official documentation only byteStride not undefined is allowed
|
|
864
|
+
if (bufferStride !== undefined && bufferStride !== elementStride) {
|
|
865
|
+
var bufferSlice = Math.floor(byteOffset / bufferStride);
|
|
866
|
+
var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
|
|
867
|
+
var accessorBufferCache = context.accessorBufferCache;
|
|
868
|
+
bufferInfo = accessorBufferCache[bufferCacheKey];
|
|
869
|
+
if (!bufferInfo) {
|
|
870
|
+
var offset = bufferByteOffset + bufferSlice * bufferStride;
|
|
871
|
+
var count = accessorCount * (bufferStride / dataElementBytes);
|
|
872
|
+
var data = new TypedArray(buffer, offset, count);
|
|
873
|
+
accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
|
|
874
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
|
|
875
|
+
}
|
|
876
|
+
} else {
|
|
877
|
+
var offset1 = bufferByteOffset + byteOffset;
|
|
878
|
+
var count1 = accessorCount * dataElementSize;
|
|
879
|
+
var data1 = new TypedArray(buffer, offset1, count1);
|
|
880
|
+
bufferInfo = new BufferInfo(data1, false, elementStride);
|
|
881
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
856
882
|
}
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
883
|
+
if (accessor.sparse) {
|
|
884
|
+
GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
|
|
885
|
+
}
|
|
886
|
+
return bufferInfo;
|
|
887
|
+
});
|
|
888
|
+
};
|
|
889
|
+
GLTFUtils.bufferToVector3Array = function bufferToVector3Array(data, byteStride, accessorByteOffset, count) {
|
|
890
|
+
var bytesPerElement = data.BYTES_PER_ELEMENT;
|
|
891
|
+
var offset = accessorByteOffset % byteStride / bytesPerElement;
|
|
892
|
+
var stride = byteStride / bytesPerElement;
|
|
893
|
+
var vector3s = new Array(count);
|
|
894
|
+
for(var i = 0; i < count; i++){
|
|
895
|
+
var index = offset + i * stride;
|
|
896
|
+
vector3s[i] = new miniprogram$1.Vector3(data[index], data[index + 1], data[index + 2]);
|
|
866
897
|
}
|
|
867
|
-
return
|
|
898
|
+
return vector3s;
|
|
868
899
|
};
|
|
869
900
|
/**
|
|
870
901
|
* @deprecated
|
|
@@ -1330,7 +1361,7 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1330
1361
|
}
|
|
1331
1362
|
var _proto = GLTFAnimationParser.prototype;
|
|
1332
1363
|
_proto.parse = function parse(context) {
|
|
1333
|
-
var glTF = context.glTF
|
|
1364
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1334
1365
|
glTFResource.entities;
|
|
1335
1366
|
var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
|
|
1336
1367
|
if (!animations) {
|
|
@@ -1340,106 +1371,120 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1340
1371
|
var animationClipCount = animations.length;
|
|
1341
1372
|
var animationClipPromises = [];
|
|
1342
1373
|
new Array(animationClipCount);
|
|
1374
|
+
var parseStandardPropertyPromises = new Array();
|
|
1343
1375
|
for(var i = 0; i < animationClipCount; i++){
|
|
1344
1376
|
var animationInfo = animations[i];
|
|
1345
1377
|
var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
|
|
1346
1378
|
var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
|
|
1347
1379
|
if (!animationClip) {
|
|
1348
1380
|
animationClip = new miniprogram.AnimationClip(name);
|
|
1349
|
-
GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
|
|
1381
|
+
parseStandardPropertyPromises.push(GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo));
|
|
1350
1382
|
}
|
|
1351
1383
|
animationClipPromises.push(animationClip);
|
|
1352
1384
|
}
|
|
1353
|
-
return miniprogram.AssetPromise.all(
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
var
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1385
|
+
return miniprogram.AssetPromise.all(parseStandardPropertyPromises).then(function() {
|
|
1386
|
+
return miniprogram.AssetPromise.all(animationClipPromises).then(function(animationClips) {
|
|
1387
|
+
glTFResource.animations = animationClips;
|
|
1388
|
+
for(var i = 0; i < glTF.animations.length; i++){
|
|
1389
|
+
var animationInfo = glTF.animations[i];
|
|
1390
|
+
GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
|
|
1391
|
+
}
|
|
1392
|
+
animationClipsPromiseInfo.resolve(animationClips);
|
|
1393
|
+
return animationClipsPromiseInfo.promise;
|
|
1394
|
+
});
|
|
1361
1395
|
});
|
|
1362
1396
|
};
|
|
1363
1397
|
/**
|
|
1364
1398
|
* @internal
|
|
1365
1399
|
*/ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
|
|
1400
|
+
var _loop = function(j, m) {
|
|
1401
|
+
var gltfSampler = samplers[j];
|
|
1402
|
+
var inputAccessor = accessors[gltfSampler.input];
|
|
1403
|
+
var outputAccessor = accessors[gltfSampler.output];
|
|
1404
|
+
var promise = Promise.all([
|
|
1405
|
+
GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor),
|
|
1406
|
+
GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor)
|
|
1407
|
+
]).then(function(bufferInfos) {
|
|
1408
|
+
var input = bufferInfos[0].data;
|
|
1409
|
+
var output = bufferInfos[1].data;
|
|
1410
|
+
if (outputAccessor.normalized) {
|
|
1411
|
+
var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
|
|
1412
|
+
var scaled = new Float32Array(output.length);
|
|
1413
|
+
for(var k = 0, v = output.length; k < v; k++){
|
|
1414
|
+
scaled[k] = output[k] * scale;
|
|
1415
|
+
}
|
|
1416
|
+
output = scaled;
|
|
1417
|
+
}
|
|
1418
|
+
var outputStride = output.length / input.length;
|
|
1419
|
+
var _gltfSampler_interpolation;
|
|
1420
|
+
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
1421
|
+
var samplerInterpolation;
|
|
1422
|
+
switch(interpolation){
|
|
1423
|
+
case AnimationSamplerInterpolation.CubicSpine:
|
|
1424
|
+
samplerInterpolation = miniprogram.InterpolationType.CubicSpine;
|
|
1425
|
+
break;
|
|
1426
|
+
case AnimationSamplerInterpolation.Step:
|
|
1427
|
+
samplerInterpolation = miniprogram.InterpolationType.Step;
|
|
1428
|
+
break;
|
|
1429
|
+
case AnimationSamplerInterpolation.Linear:
|
|
1430
|
+
samplerInterpolation = miniprogram.InterpolationType.Linear;
|
|
1431
|
+
break;
|
|
1432
|
+
}
|
|
1433
|
+
input[input.length - 1];
|
|
1434
|
+
sampleDataCollection.push({
|
|
1435
|
+
type: outputAccessor.type,
|
|
1436
|
+
interpolation: samplerInterpolation,
|
|
1437
|
+
input: input,
|
|
1438
|
+
output: output,
|
|
1439
|
+
outputSize: outputStride
|
|
1440
|
+
});
|
|
1441
|
+
});
|
|
1442
|
+
promises.push(promise);
|
|
1443
|
+
};
|
|
1444
|
+
var _this = this;
|
|
1366
1445
|
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1367
1446
|
var entities = glTFResource.entities;
|
|
1368
1447
|
var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
|
|
1369
1448
|
var channels = animationInfo.channels, samplers = animationInfo.samplers;
|
|
1370
1449
|
var sampleDataCollection = new Array();
|
|
1450
|
+
var promises = new Array();
|
|
1371
1451
|
// parse samplers
|
|
1372
|
-
for(var j = 0, m = samplers.length; j < m; j++)
|
|
1373
|
-
|
|
1374
|
-
var
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
var
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1452
|
+
for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
|
|
1453
|
+
return Promise.all(promises).then(function() {
|
|
1454
|
+
for(var j = 0, m = channels.length; j < m; j++){
|
|
1455
|
+
var gltfChannel = channels[j];
|
|
1456
|
+
var target = gltfChannel.target;
|
|
1457
|
+
var channelTargetEntity = entities[target.node];
|
|
1458
|
+
var relativePath = "";
|
|
1459
|
+
var entity = channelTargetEntity;
|
|
1460
|
+
while(entity.parent){
|
|
1461
|
+
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
1462
|
+
entity = entity.parent;
|
|
1383
1463
|
}
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
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;
|
|
1464
|
+
var ComponentType = void 0;
|
|
1465
|
+
var propertyName = void 0;
|
|
1466
|
+
switch(target.path){
|
|
1467
|
+
case AnimationChannelTargetPath.TRANSLATION:
|
|
1468
|
+
ComponentType = miniprogram.Transform;
|
|
1469
|
+
propertyName = "position";
|
|
1470
|
+
break;
|
|
1471
|
+
case AnimationChannelTargetPath.ROTATION:
|
|
1472
|
+
ComponentType = miniprogram.Transform;
|
|
1473
|
+
propertyName = "rotationQuaternion";
|
|
1474
|
+
break;
|
|
1475
|
+
case AnimationChannelTargetPath.SCALE:
|
|
1476
|
+
ComponentType = miniprogram.Transform;
|
|
1477
|
+
propertyName = "scale";
|
|
1478
|
+
break;
|
|
1479
|
+
case AnimationChannelTargetPath.WEIGHTS:
|
|
1480
|
+
ComponentType = miniprogram.SkinnedMeshRenderer;
|
|
1481
|
+
propertyName = "blendShapeWeights";
|
|
1482
|
+
break;
|
|
1483
|
+
}
|
|
1484
|
+
var curve = _this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
1485
|
+
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1439
1486
|
}
|
|
1440
|
-
|
|
1441
|
-
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1442
|
-
}
|
|
1487
|
+
});
|
|
1443
1488
|
};
|
|
1444
1489
|
GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
|
|
1445
1490
|
var sampleData = sampleDataCollection[gltfChannel.sampler];
|
|
@@ -1534,20 +1579,18 @@ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1534
1579
|
}).then(function(param) {
|
|
1535
1580
|
var glTF = param.glTF, buffers = param.buffers;
|
|
1536
1581
|
context.glTF = glTF;
|
|
1537
|
-
context.
|
|
1582
|
+
context._buffers = buffers;
|
|
1538
1583
|
});
|
|
1539
1584
|
} else {
|
|
1540
1585
|
return miniprogram.request(url, {
|
|
1541
1586
|
type: "json"
|
|
1542
1587
|
}).then(function(glTF) {
|
|
1543
1588
|
context.glTF = glTF;
|
|
1544
|
-
|
|
1589
|
+
context._buffers = Promise.all(glTF.buffers.map(function(buffer) {
|
|
1545
1590
|
var absoluteUrl = miniprogram.Utils.resolveAbsoluteUrl(url, buffer.uri);
|
|
1546
1591
|
restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
|
|
1547
1592
|
return miniprogram.request(absoluteUrl, requestConfig);
|
|
1548
|
-
}))
|
|
1549
|
-
context.buffers = buffers;
|
|
1550
|
-
});
|
|
1593
|
+
}));
|
|
1551
1594
|
});
|
|
1552
1595
|
}
|
|
1553
1596
|
};
|
|
@@ -1796,7 +1839,9 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1796
1839
|
}
|
|
1797
1840
|
}, function() {
|
|
1798
1841
|
var indexAccessor = glTF.accessors[gltfPrimitive.indices];
|
|
1799
|
-
return
|
|
1842
|
+
return context.getBuffers().then(function(buffers) {
|
|
1843
|
+
return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
|
|
1844
|
+
});
|
|
1800
1845
|
}, context.keepMeshData).then(resolve);
|
|
1801
1846
|
}
|
|
1802
1847
|
});
|
|
@@ -1806,7 +1851,7 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1806
1851
|
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1807
1852
|
meshPromises[i] = Promise.all(primitivePromises);
|
|
1808
1853
|
};
|
|
1809
|
-
var glTF = context.glTF,
|
|
1854
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1810
1855
|
var engine = glTFResource.engine;
|
|
1811
1856
|
if (!glTF.meshes) return;
|
|
1812
1857
|
var meshesPromiseInfo = context.meshesPromiseInfo;
|
|
@@ -1821,8 +1866,109 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1821
1866
|
/**
|
|
1822
1867
|
* @internal
|
|
1823
1868
|
*/ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1869
|
+
var _loop = function(attribute) {
|
|
1870
|
+
var accessor = accessors[attributes[attribute]];
|
|
1871
|
+
var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor).then(function(accessorBuffer) {
|
|
1872
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
1873
|
+
var accessorCount = accessor.count;
|
|
1874
|
+
var vertices = accessorBuffer.data;
|
|
1875
|
+
var vertexElement;
|
|
1876
|
+
var meshId = mesh.instanceId;
|
|
1877
|
+
var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
|
|
1878
|
+
var elementNormalized = accessor.normalized;
|
|
1879
|
+
var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
|
|
1880
|
+
var scaleFactor;
|
|
1881
|
+
elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
|
|
1882
|
+
var elementOffset;
|
|
1883
|
+
if (accessorBuffer.interleaved) {
|
|
1884
|
+
var byteOffset = accessor.byteOffset || 0;
|
|
1885
|
+
var stride = accessorBuffer.stride;
|
|
1886
|
+
elementOffset = byteOffset % stride;
|
|
1887
|
+
if (vertexBindingInfos[meshId] === undefined) {
|
|
1888
|
+
vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1889
|
+
var vertexBuffer = accessorBuffer.vertexBuffer;
|
|
1890
|
+
if (!vertexBuffer) {
|
|
1891
|
+
vertexBuffer = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
|
|
1892
|
+
vertexBuffer.setData(vertices);
|
|
1893
|
+
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
1894
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
1895
|
+
}
|
|
1896
|
+
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
1897
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1898
|
+
} else {
|
|
1899
|
+
vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
|
|
1900
|
+
}
|
|
1901
|
+
} else {
|
|
1902
|
+
elementOffset = 0;
|
|
1903
|
+
vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1904
|
+
var vertexBuffer1 = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
|
|
1905
|
+
vertexBuffer1.setData(vertices);
|
|
1906
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
|
|
1907
|
+
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
1908
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1909
|
+
}
|
|
1910
|
+
vertexElements.push(vertexElement);
|
|
1911
|
+
if (attribute === "POSITION") {
|
|
1912
|
+
vertexCount = accessorCount;
|
|
1913
|
+
var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
|
|
1914
|
+
if (accessor.min && accessor.max) {
|
|
1915
|
+
min.copyFromArray(accessor.min);
|
|
1916
|
+
max.copyFromArray(accessor.max);
|
|
1917
|
+
if (keepMeshData) {
|
|
1918
|
+
var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1919
|
+
var stride1 = vertices.length / accessorCount;
|
|
1920
|
+
for(var j = 0; j < accessorCount; j++){
|
|
1921
|
+
var offset = baseOffset + j * stride1;
|
|
1922
|
+
var position = new miniprogram$1.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
1923
|
+
elementNormalized && position.scale(scaleFactor);
|
|
1924
|
+
positions[j] = position;
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
} else {
|
|
1928
|
+
var position1 = GLTFMeshParser._tempVector3;
|
|
1929
|
+
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1930
|
+
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1931
|
+
var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1932
|
+
var stride2 = vertices.length / accessorCount;
|
|
1933
|
+
for(var j1 = 0; j1 < accessorCount; j1++){
|
|
1934
|
+
var offset1 = baseOffset1 + j1 * stride2;
|
|
1935
|
+
position1.copyFromArray(vertices, offset1);
|
|
1936
|
+
miniprogram$1.Vector3.min(min, position1, min);
|
|
1937
|
+
miniprogram$1.Vector3.max(max, position1, max);
|
|
1938
|
+
if (keepMeshData) {
|
|
1939
|
+
var clonePosition = position1.clone();
|
|
1940
|
+
elementNormalized && clonePosition.scale(scaleFactor);
|
|
1941
|
+
positions[j1] = clonePosition;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
if (elementNormalized) {
|
|
1946
|
+
min.scale(scaleFactor);
|
|
1947
|
+
max.scale(scaleFactor);
|
|
1948
|
+
}
|
|
1949
|
+
} else if (attribute === "JOINTS_0" && keepMeshData) {
|
|
1950
|
+
var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1951
|
+
var stride3 = vertices.length / accessorCount;
|
|
1952
|
+
for(var j2 = 0; j2 < accessorCount; j2++){
|
|
1953
|
+
var offset2 = baseOffset2 + j2 * stride3;
|
|
1954
|
+
var boneIndex = new miniprogram$1.Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
|
|
1955
|
+
elementNormalized && boneIndex.scale(scaleFactor);
|
|
1956
|
+
boneIndices[j2] = boneIndex;
|
|
1957
|
+
}
|
|
1958
|
+
} else if (attribute === "WEIGHTS_0" && keepMeshData) {
|
|
1959
|
+
var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1960
|
+
var stride4 = vertices.length / accessorCount;
|
|
1961
|
+
for(var j3 = 0; j3 < accessorCount; j3++){
|
|
1962
|
+
var offset3 = baseOffset3 + j3 * stride4;
|
|
1963
|
+
var boneWeight = new miniprogram$1.Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
|
|
1964
|
+
elementNormalized && boneWeight.scale(scaleFactor);
|
|
1965
|
+
boneWeights[j3] = boneWeight;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
});
|
|
1969
|
+
promises.push(promise);
|
|
1970
|
+
};
|
|
1824
1971
|
var accessors = gltf.accessors;
|
|
1825
|
-
context.buffers;
|
|
1826
1972
|
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
1827
1973
|
var engine = mesh.engine;
|
|
1828
1974
|
var vertexElements = new Array();
|
|
@@ -1836,145 +1982,85 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1836
1982
|
boneIndices = new Array(vertexCount);
|
|
1837
1983
|
boneWeights = new Array(vertexCount);
|
|
1838
1984
|
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
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
|
-
}
|
|
1985
|
+
var promises = new Array();
|
|
1986
|
+
for(var attribute in attributes)_loop(attribute);
|
|
1987
|
+
return Promise.all(promises).then(function() {
|
|
1988
|
+
mesh.setVertexElements(vertexElements);
|
|
1989
|
+
// Indices
|
|
1990
|
+
if (indices !== undefined) {
|
|
1991
|
+
var indexAccessor = gltf.accessors[indices];
|
|
1992
|
+
var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor).then(function(accessorBuffer) {
|
|
1993
|
+
mesh.setIndices(accessorBuffer.data);
|
|
1994
|
+
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
1995
|
+
meshRestoreInfo.indexBuffer = accessorBuffer.restoreInfo;
|
|
1996
|
+
});
|
|
1997
|
+
promises.push(promise);
|
|
1871
1998
|
} else {
|
|
1872
|
-
|
|
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++;
|
|
1999
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
1879
2000
|
}
|
|
1880
|
-
|
|
1881
|
-
if (
|
|
1882
|
-
|
|
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
|
-
}
|
|
2001
|
+
// BlendShapes
|
|
2002
|
+
if (targets) {
|
|
2003
|
+
promises.push(GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, accessors, targets, getBlendShapeData));
|
|
1937
2004
|
}
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
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);
|
|
2005
|
+
return Promise.all(promises).then(function() {
|
|
2006
|
+
mesh.uploadData(!keepMeshData);
|
|
2007
|
+
//@ts-ignore
|
|
2008
|
+
mesh._positions = positions;
|
|
2009
|
+
//@ts-ignore
|
|
2010
|
+
mesh._boneIndices = boneIndices;
|
|
2011
|
+
//@ts-ignore
|
|
2012
|
+
mesh._boneWeights = boneWeights;
|
|
2013
|
+
return Promise.resolve(mesh);
|
|
2014
|
+
});
|
|
2015
|
+
});
|
|
1960
2016
|
};
|
|
1961
2017
|
/**
|
|
1962
2018
|
* @internal
|
|
1963
|
-
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
1964
|
-
var
|
|
1965
|
-
for(var i = 0, n = glTFTargets.length; i < n; i++){
|
|
2019
|
+
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, accessors, glTFTargets, getBlendShapeData) {
|
|
2020
|
+
var _loop = function(i, n) {
|
|
1966
2021
|
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
1967
|
-
var
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
2022
|
+
var promise = Promise.all([
|
|
2023
|
+
getBlendShapeData("POSITION", i),
|
|
2024
|
+
getBlendShapeData("NORMAL", i),
|
|
2025
|
+
getBlendShapeData("TANGENT", i)
|
|
2026
|
+
]).then(function(infos) {
|
|
2027
|
+
var posBufferInfo = infos[0];
|
|
2028
|
+
var norBufferInfo = infos[1];
|
|
2029
|
+
var tanBufferInfo = infos[2];
|
|
2030
|
+
var target = glTFTargets[i];
|
|
2031
|
+
var posAccessor;
|
|
2032
|
+
var norAccessor;
|
|
2033
|
+
var tanAccessor;
|
|
2034
|
+
var positions = null;
|
|
2035
|
+
if (posBufferInfo) {
|
|
2036
|
+
posAccessor = accessors[target["POSITION"]];
|
|
2037
|
+
var _posAccessor_byteOffset;
|
|
2038
|
+
positions = GLTFUtils.bufferToVector3Array(posBufferInfo.data, posBufferInfo.stride, (_posAccessor_byteOffset = posAccessor.byteOffset) != null ? _posAccessor_byteOffset : 0, posAccessor.count);
|
|
2039
|
+
}
|
|
2040
|
+
var normals = null;
|
|
2041
|
+
if (norBufferInfo) {
|
|
2042
|
+
norAccessor = accessors[target["NORMAL"]];
|
|
2043
|
+
var _norAccessor_byteOffset;
|
|
2044
|
+
normals = GLTFUtils.bufferToVector3Array(norBufferInfo.data, norBufferInfo.stride, (_norAccessor_byteOffset = norAccessor.byteOffset) != null ? _norAccessor_byteOffset : 0, norAccessor.count);
|
|
2045
|
+
}
|
|
2046
|
+
var tangents = null;
|
|
2047
|
+
if (tanBufferInfo) {
|
|
2048
|
+
tanAccessor = accessors[target["NORMAL"]];
|
|
2049
|
+
var _tanAccessor_byteOffset;
|
|
2050
|
+
tangents = GLTFUtils.bufferToVector3Array(tanBufferInfo.data, tanBufferInfo.stride, (_tanAccessor_byteOffset = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset : 0, tanAccessor.count);
|
|
2051
|
+
}
|
|
2052
|
+
var blendShape = new miniprogram.BlendShape(name);
|
|
2053
|
+
blendShape.addFrame(1.0, positions, normals, tangents);
|
|
2054
|
+
mesh.addBlendShape(blendShape);
|
|
2055
|
+
var _posAccessor_byteOffset1, _norAccessor_byteOffset1, _tanAccessor_byteOffset1;
|
|
2056
|
+
meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, new BlendShapeDataRestoreInfo(posBufferInfo.restoreInfo, posBufferInfo.stride, (_posAccessor_byteOffset1 = posAccessor.byteOffset) != null ? _posAccessor_byteOffset1 : 0, posAccessor.count), norBufferInfo ? new BlendShapeDataRestoreInfo(norBufferInfo.restoreInfo, norBufferInfo.stride, (_norAccessor_byteOffset1 = norAccessor.byteOffset) != null ? _norAccessor_byteOffset1 : 0, norAccessor.count) : null, tanBufferInfo ? new BlendShapeDataRestoreInfo(tanBufferInfo.restoreInfo, tanBufferInfo.stride, (_tanAccessor_byteOffset1 = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset1 : 0, tanAccessor.count) : null));
|
|
2057
|
+
});
|
|
2058
|
+
promises.push(promise);
|
|
2059
|
+
};
|
|
2060
|
+
var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
|
|
2061
|
+
var promises = new Array();
|
|
2062
|
+
for(var i = 0, n = glTFTargets.length; i < n; i++)_loop(i);
|
|
2063
|
+
return Promise.all(promises);
|
|
1978
2064
|
};
|
|
1979
2065
|
return GLTFMeshParser;
|
|
1980
2066
|
}(GLTFParser);
|
|
@@ -2126,51 +2212,58 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2126
2212
|
}
|
|
2127
2213
|
var _proto = GLTFSkinParser.prototype;
|
|
2128
2214
|
_proto.parse = function parse(context) {
|
|
2129
|
-
var
|
|
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++){
|
|
2215
|
+
var _loop = function(i) {
|
|
2136
2216
|
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
2217
|
var jointCount = joints.length;
|
|
2138
2218
|
var skin = new miniprogram.Skin(name);
|
|
2139
2219
|
skin.inverseBindMatrices.length = jointCount;
|
|
2140
2220
|
// parse IBM
|
|
2141
2221
|
var accessor = glTF.accessors[inverseBindMatrices];
|
|
2142
|
-
var
|
|
2143
|
-
|
|
2144
|
-
var
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2222
|
+
var promise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
|
|
2223
|
+
var buffer = bufferInfo.data;
|
|
2224
|
+
for(var i = 0; i < jointCount; i++){
|
|
2225
|
+
var inverseBindMatrix = new miniprogram$1.Matrix();
|
|
2226
|
+
inverseBindMatrix.copyFromArray(buffer, i * 16);
|
|
2227
|
+
skin.inverseBindMatrices[i] = inverseBindMatrix;
|
|
2228
|
+
// get joints
|
|
2229
|
+
for(var i1 = 0; i1 < jointCount; i1++){
|
|
2230
|
+
var jointIndex = joints[i1];
|
|
2231
|
+
var jointName = entities[jointIndex].name;
|
|
2232
|
+
skin.joints[i1] = jointName;
|
|
2233
|
+
// @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
|
|
2234
|
+
for(var j = entities.length - 1; j >= 0; j--){
|
|
2235
|
+
if (jointIndex !== j && entities[j].name === jointName) {
|
|
2236
|
+
entities[j].name = jointName + "_" + j;
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
// get skeleton
|
|
2241
|
+
if (skeleton !== undefined) {
|
|
2242
|
+
skin.skeleton = entities[skeleton].name;
|
|
2243
|
+
} else {
|
|
2244
|
+
var rootBone = _this._findSkeletonRootBone(joints, entities);
|
|
2245
|
+
if (rootBone) {
|
|
2246
|
+
skin.skeleton = rootBone.name;
|
|
2247
|
+
} else {
|
|
2248
|
+
throw "Failed to find skeleton root bone.";
|
|
2249
|
+
}
|
|
2157
2250
|
}
|
|
2158
2251
|
}
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2252
|
+
return skin;
|
|
2253
|
+
});
|
|
2254
|
+
promises.push(promise);
|
|
2255
|
+
};
|
|
2256
|
+
var _this = this;
|
|
2257
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2258
|
+
var entities = glTFResource.entities;
|
|
2259
|
+
var gltfSkins = glTF.skins;
|
|
2260
|
+
if (!gltfSkins) return;
|
|
2261
|
+
var count = gltfSkins.length;
|
|
2262
|
+
var promises = new Array();
|
|
2263
|
+
for(var i = 0; i < count; i++)_loop(i);
|
|
2264
|
+
return miniprogram.AssetPromise.all(promises).then(function(skins) {
|
|
2265
|
+
glTFResource.skins = skins;
|
|
2266
|
+
});
|
|
2174
2267
|
};
|
|
2175
2268
|
_proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
|
|
2176
2269
|
var paths = {};
|
|
@@ -2211,13 +2304,14 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2211
2304
|
var _proto = GLTFTextureParser.prototype;
|
|
2212
2305
|
_proto.parse = function parse(context) {
|
|
2213
2306
|
var _this = this;
|
|
2214
|
-
var glTFResource = context.glTFResource, glTF = context.glTF
|
|
2307
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2215
2308
|
var engine = glTFResource.engine, url = glTFResource.url;
|
|
2216
2309
|
if (glTF.textures) {
|
|
2217
2310
|
var texturesPromiseInfo = context.texturesPromiseInfo;
|
|
2218
2311
|
miniprogram.AssetPromise.all(glTF.textures.map(function(param, index) {
|
|
2219
2312
|
var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
|
|
2220
2313
|
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;
|
|
2314
|
+
var samplerInfo = sampler !== undefined && _this._getSamplerInfo(glTF.samplers[sampler]);
|
|
2221
2315
|
if (uri) {
|
|
2222
2316
|
// TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
|
|
2223
2317
|
var index1 = uri.lastIndexOf(".");
|
|
@@ -2225,31 +2319,36 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2225
2319
|
var type = ext.startsWith("ktx") ? miniprogram.AssetType.KTX : miniprogram.AssetType.Texture2D;
|
|
2226
2320
|
return engine.resourceManager.load({
|
|
2227
2321
|
url: miniprogram.Utils.resolveAbsoluteUrl(url, uri),
|
|
2228
|
-
type: type
|
|
2322
|
+
type: type,
|
|
2323
|
+
params: {
|
|
2324
|
+
mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap
|
|
2325
|
+
}
|
|
2229
2326
|
}).then(function(texture) {
|
|
2230
2327
|
if (!texture.name) {
|
|
2231
2328
|
texture.name = textureName || imageName || "texture_" + index1;
|
|
2232
2329
|
}
|
|
2233
2330
|
if (sampler !== undefined) {
|
|
2234
|
-
_this._parseSampler(texture,
|
|
2331
|
+
_this._parseSampler(texture, samplerInfo);
|
|
2235
2332
|
}
|
|
2236
2333
|
return texture;
|
|
2237
2334
|
});
|
|
2238
2335
|
} else {
|
|
2239
2336
|
var bufferView = glTF.bufferViews[bufferViewIndex];
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2337
|
+
return context.getBuffers().then(function(buffers) {
|
|
2338
|
+
var buffer = buffers[bufferView.buffer];
|
|
2339
|
+
var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
2340
|
+
return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
|
|
2341
|
+
var texture = new miniprogram.Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap);
|
|
2342
|
+
texture.setImageSource(image);
|
|
2343
|
+
texture.generateMipmaps();
|
|
2344
|
+
texture.name = textureName || imageName || "texture_" + index;
|
|
2345
|
+
if (sampler !== undefined) {
|
|
2346
|
+
_this._parseSampler(texture, samplerInfo);
|
|
2347
|
+
}
|
|
2348
|
+
var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
|
|
2349
|
+
context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
|
|
2350
|
+
return texture;
|
|
2351
|
+
});
|
|
2253
2352
|
});
|
|
2254
2353
|
}
|
|
2255
2354
|
})).then(function(textures) {
|
|
@@ -2259,22 +2358,39 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2259
2358
|
return texturesPromiseInfo.promise;
|
|
2260
2359
|
}
|
|
2261
2360
|
};
|
|
2262
|
-
_proto.
|
|
2263
|
-
var
|
|
2264
|
-
|
|
2361
|
+
_proto._getSamplerInfo = function _getSamplerInfo(sampler) {
|
|
2362
|
+
var minFilter = sampler.minFilter, magFilter = sampler.magFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
|
|
2363
|
+
var info = {};
|
|
2364
|
+
if (minFilter || magFilter) {
|
|
2365
|
+
info.mipmap = minFilter >= TextureMinFilter.NEAREST_MIPMAP_NEAREST;
|
|
2265
2366
|
if (magFilter === TextureMagFilter.NEAREST) {
|
|
2266
|
-
|
|
2267
|
-
} else if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
2268
|
-
texture.filterMode = miniprogram.TextureFilterMode.Bilinear;
|
|
2367
|
+
info.filterMode = miniprogram.TextureFilterMode.Point;
|
|
2269
2368
|
} else {
|
|
2270
|
-
|
|
2369
|
+
if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
2370
|
+
info.filterMode = miniprogram.TextureFilterMode.Bilinear;
|
|
2371
|
+
} else {
|
|
2372
|
+
info.filterMode = miniprogram.TextureFilterMode.Trilinear;
|
|
2373
|
+
}
|
|
2271
2374
|
}
|
|
2272
2375
|
}
|
|
2273
2376
|
if (wrapS) {
|
|
2274
|
-
|
|
2377
|
+
info.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
|
|
2275
2378
|
}
|
|
2276
2379
|
if (wrapT) {
|
|
2277
|
-
|
|
2380
|
+
info.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
|
|
2381
|
+
}
|
|
2382
|
+
return info;
|
|
2383
|
+
};
|
|
2384
|
+
_proto._parseSampler = function _parseSampler(texture, samplerInfo) {
|
|
2385
|
+
var filterMode = samplerInfo.filterMode, wrapModeU = samplerInfo.wrapModeU, wrapModeV = samplerInfo.wrapModeV;
|
|
2386
|
+
if (filterMode !== undefined) {
|
|
2387
|
+
texture.filterMode = filterMode;
|
|
2388
|
+
}
|
|
2389
|
+
if (wrapModeU !== undefined) {
|
|
2390
|
+
texture.wrapModeU = wrapModeU;
|
|
2391
|
+
}
|
|
2392
|
+
if (wrapModeV !== undefined) {
|
|
2393
|
+
texture.wrapModeV = wrapModeV;
|
|
2278
2394
|
}
|
|
2279
2395
|
};
|
|
2280
2396
|
return GLTFTextureParser;
|
|
@@ -2411,7 +2527,7 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2411
2527
|
resourceManager.addContentRestorer(restorer);
|
|
2412
2528
|
masterPromiseInfo.resolve(glTFResource);
|
|
2413
2529
|
}).catch(function(e) {
|
|
2414
|
-
var msg = "Error loading glTF model from " + url + "
|
|
2530
|
+
var msg = "Error loading glTF model from " + url + " : " + e;
|
|
2415
2531
|
miniprogram.Logger.error(msg);
|
|
2416
2532
|
masterPromiseInfo.reject(msg);
|
|
2417
2533
|
context.defaultSceneRootPromiseInfo.reject(e);
|
|
@@ -4373,7 +4489,7 @@ var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4373
4489
|
_this.request(item.url, _extends({}, item, {
|
|
4374
4490
|
type: "arraybuffer"
|
|
4375
4491
|
})).then(function(data) {
|
|
4376
|
-
return decode(data, resourceManager.engine);
|
|
4492
|
+
return decode(data, resourceManager.engine).then(resolve);
|
|
4377
4493
|
}).catch(reject);
|
|
4378
4494
|
});
|
|
4379
4495
|
};
|
|
@@ -4512,7 +4628,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
|
|
|
4512
4628
|
};
|
|
4513
4629
|
_proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
|
|
4514
4630
|
var _this = this;
|
|
4515
|
-
var glTF = context.glTF,
|
|
4631
|
+
var glTF = context.glTF, engine = context.glTFResource.engine;
|
|
4516
4632
|
var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
|
|
4517
4633
|
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
4518
4634
|
var attributeMap = {};
|
|
@@ -4534,21 +4650,23 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
|
|
|
4534
4650
|
useUniqueIDs: true,
|
|
4535
4651
|
indexType: indexType
|
|
4536
4652
|
};
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4653
|
+
return context.getBuffers().then(function(buffers) {
|
|
4654
|
+
var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
4655
|
+
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
|
|
4656
|
+
var mesh = new miniprogram.ModelMesh(engine, glTFMesh.name);
|
|
4657
|
+
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
|
|
4658
|
+
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
4659
|
+
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
4660
|
+
return decodedGeometry.attributes[j].array;
|
|
4661
|
+
}
|
|
4544
4662
|
}
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
}
|
|
4663
|
+
return null;
|
|
4664
|
+
}, function(attributeSemantic, shapeIndex) {
|
|
4665
|
+
throw "BlendShape animation is not supported when using draco.";
|
|
4666
|
+
}, function() {
|
|
4667
|
+
return decodedGeometry.index.array;
|
|
4668
|
+
}, context.keepMeshData);
|
|
4669
|
+
});
|
|
4552
4670
|
});
|
|
4553
4671
|
};
|
|
4554
4672
|
_proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
@@ -4647,7 +4765,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
|
|
|
4647
4765
|
mesh.addSubMesh(0, vertexCount, mode);
|
|
4648
4766
|
}
|
|
4649
4767
|
// BlendShapes
|
|
4650
|
-
targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
|
|
4768
|
+
targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, accessors, targets, getBlendShapeData);
|
|
4651
4769
|
mesh.uploadData(!keepMeshData);
|
|
4652
4770
|
return Promise.resolve(mesh);
|
|
4653
4771
|
};
|