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