@galacean/engine-loader 1.0.0-beta.15 → 1.0.0-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +409 -334
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +409 -334
- package/dist/module.js +410 -335
- 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) {
|
|
@@ -221,7 +222,8 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
|
|
|
221
222
|
var shArray = new Float32Array(arraybuffer, 0, 27);
|
|
222
223
|
var shByteLength = 27 * 4;
|
|
223
224
|
var size = (_ref = new Uint16Array(arraybuffer, shByteLength, 1)) == null ? void 0 : _ref[0];
|
|
224
|
-
var
|
|
225
|
+
var engine = resourceManager.engine;
|
|
226
|
+
var texture = new engineCore.TextureCube(engine, size);
|
|
225
227
|
texture.filterMode = engineCore.TextureFilterMode.Trilinear;
|
|
226
228
|
var mipmapCount = texture.mipmapCount;
|
|
227
229
|
var offset = shByteLength + 2;
|
|
@@ -234,7 +236,7 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
|
|
|
234
236
|
texture.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + face, data, mipLevel);
|
|
235
237
|
}
|
|
236
238
|
}
|
|
237
|
-
var ambientLight = new engineCore.AmbientLight();
|
|
239
|
+
var ambientLight = new engineCore.AmbientLight(engine);
|
|
238
240
|
var sh = new engineMath.SphericalHarmonics3();
|
|
239
241
|
ambientLight.diffuseMode = engineCore.DiffuseMode.SphericalHarmonics;
|
|
240
242
|
sh.copyFromArray(shArray);
|
|
@@ -704,6 +706,11 @@ var TextureWrapMode;
|
|
|
704
706
|
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
705
707
|
}
|
|
706
708
|
var _proto = GLTFParserContext.prototype;
|
|
709
|
+
/**
|
|
710
|
+
* Get all the buffer data.
|
|
711
|
+
*/ _proto.getBuffers = function getBuffers() {
|
|
712
|
+
return Promise.resolve(this._buffers);
|
|
713
|
+
};
|
|
707
714
|
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
708
715
|
var promise = new engineCore.AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
709
716
|
promiseInfo.resolve = resolve;
|
|
@@ -825,44 +832,45 @@ var TextureWrapMode;
|
|
|
825
832
|
}
|
|
826
833
|
};
|
|
827
834
|
GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
|
|
828
|
-
var buffers = context.buffers;
|
|
829
835
|
var componentType = accessor.componentType;
|
|
830
836
|
var bufferView = bufferViews[accessor.bufferView];
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
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));
|
|
854
868
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
861
|
-
}
|
|
862
|
-
if (accessor.sparse) {
|
|
863
|
-
GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
|
|
864
|
-
}
|
|
865
|
-
return bufferInfo;
|
|
869
|
+
if (accessor.sparse) {
|
|
870
|
+
GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
|
|
871
|
+
}
|
|
872
|
+
return bufferInfo;
|
|
873
|
+
});
|
|
866
874
|
};
|
|
867
875
|
/**
|
|
868
876
|
* @deprecated
|
|
@@ -1328,7 +1336,7 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1328
1336
|
}
|
|
1329
1337
|
var _proto = GLTFAnimationParser.prototype;
|
|
1330
1338
|
_proto.parse = function parse(context) {
|
|
1331
|
-
var glTF = context.glTF
|
|
1339
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1332
1340
|
glTFResource.entities;
|
|
1333
1341
|
var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
|
|
1334
1342
|
if (!animations) {
|
|
@@ -1338,106 +1346,120 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1338
1346
|
var animationClipCount = animations.length;
|
|
1339
1347
|
var animationClipPromises = [];
|
|
1340
1348
|
new Array(animationClipCount);
|
|
1349
|
+
var parseStandardPropertyPromises = new Array();
|
|
1341
1350
|
for(var i = 0; i < animationClipCount; i++){
|
|
1342
1351
|
var animationInfo = animations[i];
|
|
1343
1352
|
var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
|
|
1344
1353
|
var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
|
|
1345
1354
|
if (!animationClip) {
|
|
1346
1355
|
animationClip = new engineCore.AnimationClip(name);
|
|
1347
|
-
GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
|
|
1356
|
+
parseStandardPropertyPromises.push(GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo));
|
|
1348
1357
|
}
|
|
1349
1358
|
animationClipPromises.push(animationClip);
|
|
1350
1359
|
}
|
|
1351
|
-
return engineCore.AssetPromise.all(
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
var
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
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
|
+
});
|
|
1359
1370
|
});
|
|
1360
1371
|
};
|
|
1361
1372
|
/**
|
|
1362
1373
|
* @internal
|
|
1363
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;
|
|
1364
1420
|
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1365
1421
|
var entities = glTFResource.entities;
|
|
1366
1422
|
var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
|
|
1367
1423
|
var channels = animationInfo.channels, samplers = animationInfo.samplers;
|
|
1368
1424
|
var sampleDataCollection = new Array();
|
|
1425
|
+
var promises = new Array();
|
|
1369
1426
|
// parse samplers
|
|
1370
|
-
for(var j = 0, m = samplers.length; j < m; j++)
|
|
1371
|
-
|
|
1372
|
-
var
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
var
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
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;
|
|
1381
1438
|
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
output: output,
|
|
1405
|
-
outputSize: outputStride
|
|
1406
|
-
});
|
|
1407
|
-
}
|
|
1408
|
-
for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
|
|
1409
|
-
var gltfChannel = channels[j1];
|
|
1410
|
-
var target = gltfChannel.target;
|
|
1411
|
-
var channelTargetEntity = entities[target.node];
|
|
1412
|
-
var relativePath = "";
|
|
1413
|
-
var entity = channelTargetEntity;
|
|
1414
|
-
while(entity.parent){
|
|
1415
|
-
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
1416
|
-
entity = entity.parent;
|
|
1417
|
-
}
|
|
1418
|
-
var ComponentType = void 0;
|
|
1419
|
-
var propertyName = void 0;
|
|
1420
|
-
switch(target.path){
|
|
1421
|
-
case AnimationChannelTargetPath.TRANSLATION:
|
|
1422
|
-
ComponentType = engineCore.Transform;
|
|
1423
|
-
propertyName = "position";
|
|
1424
|
-
break;
|
|
1425
|
-
case AnimationChannelTargetPath.ROTATION:
|
|
1426
|
-
ComponentType = engineCore.Transform;
|
|
1427
|
-
propertyName = "rotationQuaternion";
|
|
1428
|
-
break;
|
|
1429
|
-
case AnimationChannelTargetPath.SCALE:
|
|
1430
|
-
ComponentType = engineCore.Transform;
|
|
1431
|
-
propertyName = "scale";
|
|
1432
|
-
break;
|
|
1433
|
-
case AnimationChannelTargetPath.WEIGHTS:
|
|
1434
|
-
ComponentType = engineCore.SkinnedMeshRenderer;
|
|
1435
|
-
propertyName = "blendShapeWeights";
|
|
1436
|
-
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);
|
|
1437
1461
|
}
|
|
1438
|
-
|
|
1439
|
-
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1440
|
-
}
|
|
1462
|
+
});
|
|
1441
1463
|
};
|
|
1442
1464
|
GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
|
|
1443
1465
|
var sampleData = sampleDataCollection[gltfChannel.sampler];
|
|
@@ -1532,20 +1554,18 @@ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1532
1554
|
}).then(function(param) {
|
|
1533
1555
|
var glTF = param.glTF, buffers = param.buffers;
|
|
1534
1556
|
context.glTF = glTF;
|
|
1535
|
-
context.
|
|
1557
|
+
context._buffers = buffers;
|
|
1536
1558
|
});
|
|
1537
1559
|
} else {
|
|
1538
1560
|
return engineCore.request(url, {
|
|
1539
1561
|
type: "json"
|
|
1540
1562
|
}).then(function(glTF) {
|
|
1541
1563
|
context.glTF = glTF;
|
|
1542
|
-
|
|
1564
|
+
context._buffers = Promise.all(glTF.buffers.map(function(buffer) {
|
|
1543
1565
|
var absoluteUrl = engineCore.Utils.resolveAbsoluteUrl(url, buffer.uri);
|
|
1544
1566
|
restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
|
|
1545
1567
|
return engineCore.request(absoluteUrl, requestConfig);
|
|
1546
|
-
}))
|
|
1547
|
-
context.buffers = buffers;
|
|
1548
|
-
});
|
|
1568
|
+
}));
|
|
1549
1569
|
});
|
|
1550
1570
|
}
|
|
1551
1571
|
};
|
|
@@ -1794,7 +1814,9 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1794
1814
|
}
|
|
1795
1815
|
}, function() {
|
|
1796
1816
|
var indexAccessor = glTF.accessors[gltfPrimitive.indices];
|
|
1797
|
-
return
|
|
1817
|
+
return context.getBuffers().then(function(buffers) {
|
|
1818
|
+
return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
|
|
1819
|
+
});
|
|
1798
1820
|
}, context.keepMeshData).then(resolve);
|
|
1799
1821
|
}
|
|
1800
1822
|
});
|
|
@@ -1804,7 +1826,7 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1804
1826
|
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1805
1827
|
meshPromises[i] = Promise.all(primitivePromises);
|
|
1806
1828
|
};
|
|
1807
|
-
var glTF = context.glTF,
|
|
1829
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1808
1830
|
var engine = glTFResource.engine;
|
|
1809
1831
|
if (!glTF.meshes) return;
|
|
1810
1832
|
var meshesPromiseInfo = context.meshesPromiseInfo;
|
|
@@ -1819,8 +1841,109 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1819
1841
|
/**
|
|
1820
1842
|
* @internal
|
|
1821
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
|
+
};
|
|
1822
1946
|
var accessors = gltf.accessors;
|
|
1823
|
-
context.buffers;
|
|
1824
1947
|
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
1825
1948
|
var engine = mesh.engine;
|
|
1826
1949
|
var vertexElements = new Array();
|
|
@@ -1834,145 +1957,65 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1834
1957
|
boneIndices = new Array(vertexCount);
|
|
1835
1958
|
boneWeights = new Array(vertexCount);
|
|
1836
1959
|
}
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
var elementOffset = void 0;
|
|
1851
|
-
if (accessorBuffer.interleaved) {
|
|
1852
|
-
var byteOffset = accessor.byteOffset || 0;
|
|
1853
|
-
var stride = accessorBuffer.stride;
|
|
1854
|
-
elementOffset = byteOffset % stride;
|
|
1855
|
-
if (vertexBindingInfos[meshId] === undefined) {
|
|
1856
|
-
vertexElement = new engineCore.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1857
|
-
var vertexBuffer = accessorBuffer.vertexBuffer;
|
|
1858
|
-
if (!vertexBuffer) {
|
|
1859
|
-
vertexBuffer = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
|
|
1860
|
-
vertexBuffer.setData(vertices);
|
|
1861
|
-
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
1862
|
-
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
1863
|
-
}
|
|
1864
|
-
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
1865
|
-
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1866
|
-
} else {
|
|
1867
|
-
vertexElement = new engineCore.VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
|
|
1868
|
-
}
|
|
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);
|
|
1869
1973
|
} else {
|
|
1870
|
-
|
|
1871
|
-
vertexElement = new engineCore.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1872
|
-
var vertexBuffer1 = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
|
|
1873
|
-
vertexBuffer1.setData(vertices);
|
|
1874
|
-
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
|
|
1875
|
-
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
1876
|
-
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1974
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
1877
1975
|
}
|
|
1878
|
-
|
|
1879
|
-
if (
|
|
1880
|
-
|
|
1881
|
-
var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
|
|
1882
|
-
if (accessor.min && accessor.max) {
|
|
1883
|
-
min.copyFromArray(accessor.min);
|
|
1884
|
-
max.copyFromArray(accessor.max);
|
|
1885
|
-
if (keepMeshData) {
|
|
1886
|
-
var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1887
|
-
var stride1 = vertices.length / accessorCount;
|
|
1888
|
-
for(var j = 0; j < accessorCount; j++){
|
|
1889
|
-
var offset = baseOffset + j * stride1;
|
|
1890
|
-
var position = new engineMath.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
1891
|
-
elementNormalized && position.scale(scaleFactor);
|
|
1892
|
-
positions[j] = position;
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
} else {
|
|
1896
|
-
var position1 = GLTFMeshParser._tempVector3;
|
|
1897
|
-
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1898
|
-
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1899
|
-
var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1900
|
-
var stride2 = vertices.length / accessorCount;
|
|
1901
|
-
for(var j1 = 0; j1 < accessorCount; j1++){
|
|
1902
|
-
var offset1 = baseOffset1 + j1 * stride2;
|
|
1903
|
-
position1.copyFromArray(vertices, offset1);
|
|
1904
|
-
engineMath.Vector3.min(min, position1, min);
|
|
1905
|
-
engineMath.Vector3.max(max, position1, max);
|
|
1906
|
-
if (keepMeshData) {
|
|
1907
|
-
var clonePosition = position1.clone();
|
|
1908
|
-
elementNormalized && clonePosition.scale(scaleFactor);
|
|
1909
|
-
positions[j1] = clonePosition;
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
if (elementNormalized) {
|
|
1914
|
-
min.scale(scaleFactor);
|
|
1915
|
-
max.scale(scaleFactor);
|
|
1916
|
-
}
|
|
1917
|
-
} else if (attribute === "JOINTS_0" && keepMeshData) {
|
|
1918
|
-
var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1919
|
-
var stride3 = vertices.length / accessorCount;
|
|
1920
|
-
for(var j2 = 0; j2 < accessorCount; j2++){
|
|
1921
|
-
var offset2 = baseOffset2 + j2 * stride3;
|
|
1922
|
-
var boneIndex = new engineMath.Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
|
|
1923
|
-
elementNormalized && boneIndex.scale(scaleFactor);
|
|
1924
|
-
boneIndices[j2] = boneIndex;
|
|
1925
|
-
}
|
|
1926
|
-
} else if (attribute === "WEIGHTS_0" && keepMeshData) {
|
|
1927
|
-
var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1928
|
-
var stride4 = vertices.length / accessorCount;
|
|
1929
|
-
for(var j3 = 0; j3 < accessorCount; j3++){
|
|
1930
|
-
var offset3 = baseOffset3 + j3 * stride4;
|
|
1931
|
-
var boneWeight = new engineMath.Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
|
|
1932
|
-
elementNormalized && boneWeight.scale(scaleFactor);
|
|
1933
|
-
boneWeights[j3] = boneWeight;
|
|
1934
|
-
}
|
|
1976
|
+
// BlendShapes
|
|
1977
|
+
if (targets) {
|
|
1978
|
+
promises.push(GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData));
|
|
1935
1979
|
}
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
}
|
|
1948
|
-
// BlendShapes
|
|
1949
|
-
targets && GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData);
|
|
1950
|
-
mesh.uploadData(!keepMeshData);
|
|
1951
|
-
//@ts-ignore
|
|
1952
|
-
mesh._positions = positions;
|
|
1953
|
-
//@ts-ignore
|
|
1954
|
-
mesh._boneIndices = boneIndices;
|
|
1955
|
-
//@ts-ignore
|
|
1956
|
-
mesh._boneWeights = boneWeights;
|
|
1957
|
-
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
|
+
});
|
|
1958
1991
|
};
|
|
1959
1992
|
/**
|
|
1960
1993
|
* @internal
|
|
1961
1994
|
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
1962
|
-
var
|
|
1963
|
-
for(var i = 0, n = glTFTargets.length; i < n; i++){
|
|
1995
|
+
var _loop = function(i, n) {
|
|
1964
1996
|
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
1965
|
-
var
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
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);
|
|
1976
2019
|
};
|
|
1977
2020
|
return GLTFMeshParser;
|
|
1978
2021
|
}(GLTFParser);
|
|
@@ -2124,51 +2167,58 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2124
2167
|
}
|
|
2125
2168
|
var _proto = GLTFSkinParser.prototype;
|
|
2126
2169
|
_proto.parse = function parse(context) {
|
|
2127
|
-
var
|
|
2128
|
-
var entities = glTFResource.entities;
|
|
2129
|
-
var gltfSkins = glTF.skins;
|
|
2130
|
-
if (!gltfSkins) return;
|
|
2131
|
-
var count = gltfSkins.length;
|
|
2132
|
-
var skins = new Array(count);
|
|
2133
|
-
for(var i = 0; i < count; i++){
|
|
2170
|
+
var _loop = function(i) {
|
|
2134
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;
|
|
2135
2172
|
var jointCount = joints.length;
|
|
2136
2173
|
var skin = new engineCore.Skin(name);
|
|
2137
2174
|
skin.inverseBindMatrices.length = jointCount;
|
|
2138
2175
|
// parse IBM
|
|
2139
2176
|
var accessor = glTF.accessors[inverseBindMatrices];
|
|
2140
|
-
var
|
|
2141
|
-
|
|
2142
|
-
var
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
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
|
+
}
|
|
2155
2205
|
}
|
|
2156
2206
|
}
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
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
|
+
});
|
|
2172
2222
|
};
|
|
2173
2223
|
_proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
|
|
2174
2224
|
var paths = {};
|
|
@@ -2209,13 +2259,14 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2209
2259
|
var _proto = GLTFTextureParser.prototype;
|
|
2210
2260
|
_proto.parse = function parse(context) {
|
|
2211
2261
|
var _this = this;
|
|
2212
|
-
var glTFResource = context.glTFResource, glTF = context.glTF
|
|
2262
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2213
2263
|
var engine = glTFResource.engine, url = glTFResource.url;
|
|
2214
2264
|
if (glTF.textures) {
|
|
2215
2265
|
var texturesPromiseInfo = context.texturesPromiseInfo;
|
|
2216
2266
|
engineCore.AssetPromise.all(glTF.textures.map(function(param, index) {
|
|
2217
2267
|
var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
|
|
2218
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]);
|
|
2219
2270
|
if (uri) {
|
|
2220
2271
|
// TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
|
|
2221
2272
|
var index1 = uri.lastIndexOf(".");
|
|
@@ -2223,31 +2274,36 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2223
2274
|
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.Texture2D;
|
|
2224
2275
|
return engine.resourceManager.load({
|
|
2225
2276
|
url: engineCore.Utils.resolveAbsoluteUrl(url, uri),
|
|
2226
|
-
type: type
|
|
2277
|
+
type: type,
|
|
2278
|
+
params: {
|
|
2279
|
+
mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap
|
|
2280
|
+
}
|
|
2227
2281
|
}).then(function(texture) {
|
|
2228
2282
|
if (!texture.name) {
|
|
2229
2283
|
texture.name = textureName || imageName || "texture_" + index1;
|
|
2230
2284
|
}
|
|
2231
2285
|
if (sampler !== undefined) {
|
|
2232
|
-
_this._parseSampler(texture,
|
|
2286
|
+
_this._parseSampler(texture, samplerInfo);
|
|
2233
2287
|
}
|
|
2234
2288
|
return texture;
|
|
2235
2289
|
});
|
|
2236
2290
|
} else {
|
|
2237
2291
|
var bufferView = glTF.bufferViews[bufferViewIndex];
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
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
|
+
});
|
|
2251
2307
|
});
|
|
2252
2308
|
}
|
|
2253
2309
|
})).then(function(textures) {
|
|
@@ -2257,22 +2313,39 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2257
2313
|
return texturesPromiseInfo.promise;
|
|
2258
2314
|
}
|
|
2259
2315
|
};
|
|
2260
|
-
_proto.
|
|
2261
|
-
var
|
|
2262
|
-
|
|
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;
|
|
2263
2321
|
if (magFilter === TextureMagFilter.NEAREST) {
|
|
2264
|
-
|
|
2265
|
-
} else if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
2266
|
-
texture.filterMode = engineCore.TextureFilterMode.Bilinear;
|
|
2322
|
+
info.filterMode = engineCore.TextureFilterMode.Point;
|
|
2267
2323
|
} else {
|
|
2268
|
-
|
|
2324
|
+
if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
2325
|
+
info.filterMode = engineCore.TextureFilterMode.Bilinear;
|
|
2326
|
+
} else {
|
|
2327
|
+
info.filterMode = engineCore.TextureFilterMode.Trilinear;
|
|
2328
|
+
}
|
|
2269
2329
|
}
|
|
2270
2330
|
}
|
|
2271
2331
|
if (wrapS) {
|
|
2272
|
-
|
|
2332
|
+
info.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
|
|
2273
2333
|
}
|
|
2274
2334
|
if (wrapT) {
|
|
2275
|
-
|
|
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;
|
|
2276
2349
|
}
|
|
2277
2350
|
};
|
|
2278
2351
|
return GLTFTextureParser;
|
|
@@ -4371,7 +4444,7 @@ var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4371
4444
|
_this.request(item.url, _extends({}, item, {
|
|
4372
4445
|
type: "arraybuffer"
|
|
4373
4446
|
})).then(function(data) {
|
|
4374
|
-
return decode(data, resourceManager.engine);
|
|
4447
|
+
return decode(data, resourceManager.engine).then(resolve);
|
|
4375
4448
|
}).catch(reject);
|
|
4376
4449
|
});
|
|
4377
4450
|
};
|
|
@@ -4510,7 +4583,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
|
|
|
4510
4583
|
};
|
|
4511
4584
|
_proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
|
|
4512
4585
|
var _this = this;
|
|
4513
|
-
var glTF = context.glTF,
|
|
4586
|
+
var glTF = context.glTF, engine = context.glTFResource.engine;
|
|
4514
4587
|
var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
|
|
4515
4588
|
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
4516
4589
|
var attributeMap = {};
|
|
@@ -4532,21 +4605,23 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
|
|
|
4532
4605
|
useUniqueIDs: true,
|
|
4533
4606
|
indexType: indexType
|
|
4534
4607
|
};
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
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
|
+
}
|
|
4542
4617
|
}
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
}
|
|
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
|
+
});
|
|
4550
4625
|
});
|
|
4551
4626
|
};
|
|
4552
4627
|
_proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|