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