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