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