@galacean/engine-loader 1.0.0-beta.9 → 1.0.1
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 +534 -411
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +534 -411
- package/dist/module.js +536 -413
- package/dist/module.js.map +1 -1
- package/package.json +5 -5
- package/types/GLTFContentRestorer.d.ts +18 -8
- package/types/ProjectLoader.d.ts +1 -0
- package/types/gltf/GLTFResource.d.ts +2 -6
- package/types/gltf/GLTFUtil.d.ts +3 -3
- package/types/gltf/GLTFUtils.d.ts +3 -2
- package/types/gltf/extensions/GLTFExtensionSchema.d.ts +1 -1
- package/types/gltf/parser/GLTFAnimationParser.d.ts +2 -2
- package/types/gltf/parser/GLTFMeshParser.d.ts +5 -5
- package/types/gltf/parser/GLTFParser.d.ts +1 -1
- package/types/gltf/parser/GLTFParserContext.d.ts +7 -2
- package/types/gltf/parser/GLTFSceneParser.d.ts +2 -2
- package/types/gltf/parser/GLTFSchemaParser.d.ts +7 -0
- package/types/gltf/parser/GLTFSkinParser.d.ts +2 -1
- package/types/gltf/parser/GLTFTextureParser.d.ts +3 -2
- package/types/ktx2/BinomialLLCTranscoder/BinomialLLCTranscoder.d.ts +13 -0
- package/types/ktx2/BinomialLLCTranscoder/TranscodeWorkerCode.d.ts +33 -0
- package/types/ktx2/KTX2Container.d.ts +72 -0
- package/types/ktx2/KTX2Loader.d.ts +53 -0
- package/types/ktx2/KTX2TargetFormat.d.ts +21 -0
- package/types/ktx2/KhronosTranscoder/KhronosTranscoder.d.ts +17 -0
- package/types/ktx2/KhronosTranscoder/TranscoderWorkerCode.d.ts +34 -0
- package/types/ktx2/TranscodeResult.d.ts +10 -0
- package/types/ktx2/WorkerPool.d.ts +32 -0
- package/types/ktx2/constants.d.ts +7 -0
- package/types/ktx2/transcoder/AbstractTranscoder.d.ts +55 -0
- package/types/ktx2/transcoder/BinomialLLCTranscoder.d.ts +8 -0
- package/types/ktx2/transcoder/BinomialLLCWorkerCode.d.ts +2 -0
- package/types/ktx2/transcoder/KhronosTranscoder.d.ts +13 -0
- package/types/ktx2/transcoder/KhronosWorkerCode.d.ts +1 -0
- package/types/ktx2/zstddec.d.ts +62 -0
- package/types/resource-deserialize/index.d.ts +3 -3
- package/types/resource-deserialize/resources/mesh/MeshDecoder.d.ts +1 -1
- package/types/resource-deserialize/resources/parser/PrefabParser.d.ts +5 -0
- package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +14 -0
- package/types/resource-deserialize/resources/prefab/PrefabDesign.d.ts +4 -4
- package/types/resource-deserialize/resources/scene/SceneParser.d.ts +1 -1
- package/types/resource-deserialize/resources/scene/SceneParserContext.d.ts +1 -1
- package/types/resource-deserialize/resources/schema/BasicSchema.d.ts +61 -0
- package/types/resource-deserialize/resources/schema/MaterialSchema.d.ts +91 -0
- package/types/resource-deserialize/resources/schema/ProjectSchema.d.ts +9 -0
- package/types/resource-deserialize/resources/schema/SceneSchema.d.ts +41 -0
- package/types/resource-deserialize/resources/schema/index.d.ts +3 -0
package/dist/main.js
CHANGED
|
@@ -121,7 +121,8 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
|
|
|
121
121
|
state.wrapMode = wrapMode;
|
|
122
122
|
state.clipStartTime = clipStartNormalizedTime;
|
|
123
123
|
state.clipEndTime = clipEndNormalizedTime;
|
|
124
|
-
|
|
124
|
+
var scriptsObject = JSON.parse(scripts);
|
|
125
|
+
scriptsObject == null ? void 0 : scriptsObject.forEach(function(script) {
|
|
125
126
|
state.addStateMachineScript(engineCore.Loader.getClass(script));
|
|
126
127
|
});
|
|
127
128
|
if (clipData) {
|
|
@@ -221,7 +222,8 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
|
|
|
221
222
|
var shArray = new Float32Array(arraybuffer, 0, 27);
|
|
222
223
|
var shByteLength = 27 * 4;
|
|
223
224
|
var size = (_ref = new Uint16Array(arraybuffer, shByteLength, 1)) == null ? void 0 : _ref[0];
|
|
224
|
-
var
|
|
225
|
+
var engine = resourceManager.engine;
|
|
226
|
+
var texture = new engineCore.TextureCube(engine, size);
|
|
225
227
|
texture.filterMode = engineCore.TextureFilterMode.Trilinear;
|
|
226
228
|
var mipmapCount = texture.mipmapCount;
|
|
227
229
|
var offset = shByteLength + 2;
|
|
@@ -234,7 +236,7 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
|
|
|
234
236
|
texture.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + face, data, mipLevel);
|
|
235
237
|
}
|
|
236
238
|
}
|
|
237
|
-
var ambientLight = new engineCore.AmbientLight();
|
|
239
|
+
var ambientLight = new engineCore.AmbientLight(engine);
|
|
238
240
|
var sh = new engineMath.SphericalHarmonics3();
|
|
239
241
|
ambientLight.diffuseMode = engineCore.DiffuseMode.SphericalHarmonics;
|
|
240
242
|
sh.copyFromArray(shArray);
|
|
@@ -441,15 +443,18 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
441
443
|
for(var _iterator2 = _create_for_of_iterator_helper_loose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
|
|
442
444
|
var restoreInfo = _step2.value;
|
|
443
445
|
var frame = restoreInfo.blendShape.frames[0];
|
|
444
|
-
var
|
|
445
|
-
|
|
446
|
+
var position = restoreInfo.position;
|
|
447
|
+
var positionData = _this._getBufferData(buffers, position.buffer);
|
|
448
|
+
frame.deltaPositions = GLTFUtils.bufferToVector3Array(positionData, position.stride, position.byteOffset, position.count);
|
|
446
449
|
if (restoreInfo.normal) {
|
|
447
|
-
var
|
|
448
|
-
|
|
450
|
+
var normal = restoreInfo.normal;
|
|
451
|
+
var normalData = _this._getBufferData(buffers, normal.buffer);
|
|
452
|
+
frame.deltaNormals = GLTFUtils.bufferToVector3Array(normalData, normal.stride, normal.byteOffset, normal.count);
|
|
449
453
|
}
|
|
450
454
|
if (restoreInfo.tangent) {
|
|
451
|
-
var
|
|
452
|
-
|
|
455
|
+
var tangent = restoreInfo.tangent;
|
|
456
|
+
var tangentData = _this._getBufferData(buffers, tangent.buffer);
|
|
457
|
+
frame.deltaTangents = GLTFUtils.bufferToVector3Array(tangentData, tangent.stride, tangent.byteOffset, tangent.count);
|
|
453
458
|
}
|
|
454
459
|
}
|
|
455
460
|
mesh.uploadData(true);
|
|
@@ -533,6 +538,14 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
533
538
|
this.normal = normal;
|
|
534
539
|
this.tangent = tangent;
|
|
535
540
|
};
|
|
541
|
+
/**
|
|
542
|
+
* @internal
|
|
543
|
+
*/ var BlendShapeDataRestoreInfo = function BlendShapeDataRestoreInfo(buffer, stride, byteOffset, count) {
|
|
544
|
+
this.buffer = buffer;
|
|
545
|
+
this.stride = stride;
|
|
546
|
+
this.byteOffset = byteOffset;
|
|
547
|
+
this.count = count;
|
|
548
|
+
};
|
|
536
549
|
|
|
537
550
|
/**
|
|
538
551
|
* Module for glTF 2.0 Interface
|
|
@@ -704,6 +717,11 @@ var TextureWrapMode;
|
|
|
704
717
|
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
705
718
|
}
|
|
706
719
|
var _proto = GLTFParserContext.prototype;
|
|
720
|
+
/**
|
|
721
|
+
* Get all the buffer data.
|
|
722
|
+
*/ _proto.getBuffers = function getBuffers() {
|
|
723
|
+
return Promise.resolve(this._buffers);
|
|
724
|
+
};
|
|
707
725
|
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
708
726
|
var promise = new engineCore.AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
709
727
|
promiseInfo.resolve = resolve;
|
|
@@ -825,44 +843,58 @@ var TextureWrapMode;
|
|
|
825
843
|
}
|
|
826
844
|
};
|
|
827
845
|
GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
|
|
828
|
-
var buffers = context.buffers;
|
|
829
846
|
var componentType = accessor.componentType;
|
|
830
847
|
var bufferView = bufferViews[accessor.bufferView];
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
var
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
var
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
848
|
+
return context.getBuffers().then(function(buffers) {
|
|
849
|
+
var bufferIndex = bufferView.buffer;
|
|
850
|
+
var buffer = buffers[bufferIndex];
|
|
851
|
+
var _bufferView_byteOffset;
|
|
852
|
+
var bufferByteOffset = (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0;
|
|
853
|
+
var _accessor_byteOffset;
|
|
854
|
+
var byteOffset = (_accessor_byteOffset = accessor.byteOffset) != null ? _accessor_byteOffset : 0;
|
|
855
|
+
var TypedArray = GLTFUtils.getComponentType(componentType);
|
|
856
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
857
|
+
var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
858
|
+
var elementStride = dataElementSize * dataElementBytes;
|
|
859
|
+
var accessorCount = accessor.count;
|
|
860
|
+
var bufferStride = bufferView.byteStride;
|
|
861
|
+
var bufferInfo;
|
|
862
|
+
// According to the glTF official documentation only byteStride not undefined is allowed
|
|
863
|
+
if (bufferStride !== undefined && bufferStride !== elementStride) {
|
|
864
|
+
var bufferSlice = Math.floor(byteOffset / bufferStride);
|
|
865
|
+
var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
|
|
866
|
+
var accessorBufferCache = context.accessorBufferCache;
|
|
867
|
+
bufferInfo = accessorBufferCache[bufferCacheKey];
|
|
868
|
+
if (!bufferInfo) {
|
|
869
|
+
var offset = bufferByteOffset + bufferSlice * bufferStride;
|
|
870
|
+
var count = accessorCount * (bufferStride / dataElementBytes);
|
|
871
|
+
var data = new TypedArray(buffer, offset, count);
|
|
872
|
+
accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
|
|
873
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
|
|
874
|
+
}
|
|
875
|
+
} else {
|
|
876
|
+
var offset1 = bufferByteOffset + byteOffset;
|
|
877
|
+
var count1 = accessorCount * dataElementSize;
|
|
878
|
+
var data1 = new TypedArray(buffer, offset1, count1);
|
|
879
|
+
bufferInfo = new BufferInfo(data1, false, elementStride);
|
|
880
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
854
881
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
882
|
+
if (accessor.sparse) {
|
|
883
|
+
GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
|
|
884
|
+
}
|
|
885
|
+
return bufferInfo;
|
|
886
|
+
});
|
|
887
|
+
};
|
|
888
|
+
GLTFUtils.bufferToVector3Array = function bufferToVector3Array(data, byteStride, accessorByteOffset, count) {
|
|
889
|
+
var bytesPerElement = data.BYTES_PER_ELEMENT;
|
|
890
|
+
var offset = accessorByteOffset % byteStride / bytesPerElement;
|
|
891
|
+
var stride = byteStride / bytesPerElement;
|
|
892
|
+
var vector3s = new Array(count);
|
|
893
|
+
for(var i = 0; i < count; i++){
|
|
894
|
+
var index = offset + i * stride;
|
|
895
|
+
vector3s[i] = new engineMath.Vector3(data[index], data[index + 1], data[index + 2]);
|
|
864
896
|
}
|
|
865
|
-
return
|
|
897
|
+
return vector3s;
|
|
866
898
|
};
|
|
867
899
|
/**
|
|
868
900
|
* @deprecated
|
|
@@ -1328,7 +1360,7 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1328
1360
|
}
|
|
1329
1361
|
var _proto = GLTFAnimationParser.prototype;
|
|
1330
1362
|
_proto.parse = function parse(context) {
|
|
1331
|
-
var glTF = context.glTF
|
|
1363
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1332
1364
|
glTFResource.entities;
|
|
1333
1365
|
var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
|
|
1334
1366
|
if (!animations) {
|
|
@@ -1338,106 +1370,120 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1338
1370
|
var animationClipCount = animations.length;
|
|
1339
1371
|
var animationClipPromises = [];
|
|
1340
1372
|
new Array(animationClipCount);
|
|
1373
|
+
var parseStandardPropertyPromises = new Array();
|
|
1341
1374
|
for(var i = 0; i < animationClipCount; i++){
|
|
1342
1375
|
var animationInfo = animations[i];
|
|
1343
1376
|
var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
|
|
1344
1377
|
var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
|
|
1345
1378
|
if (!animationClip) {
|
|
1346
1379
|
animationClip = new engineCore.AnimationClip(name);
|
|
1347
|
-
GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
|
|
1380
|
+
parseStandardPropertyPromises.push(GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo));
|
|
1348
1381
|
}
|
|
1349
1382
|
animationClipPromises.push(animationClip);
|
|
1350
1383
|
}
|
|
1351
|
-
return engineCore.AssetPromise.all(
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
var
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1384
|
+
return engineCore.AssetPromise.all(parseStandardPropertyPromises).then(function() {
|
|
1385
|
+
return engineCore.AssetPromise.all(animationClipPromises).then(function(animationClips) {
|
|
1386
|
+
glTFResource.animations = animationClips;
|
|
1387
|
+
for(var i = 0; i < glTF.animations.length; i++){
|
|
1388
|
+
var animationInfo = glTF.animations[i];
|
|
1389
|
+
GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
|
|
1390
|
+
}
|
|
1391
|
+
animationClipsPromiseInfo.resolve(animationClips);
|
|
1392
|
+
return animationClipsPromiseInfo.promise;
|
|
1393
|
+
});
|
|
1359
1394
|
});
|
|
1360
1395
|
};
|
|
1361
1396
|
/**
|
|
1362
1397
|
* @internal
|
|
1363
1398
|
*/ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
|
|
1399
|
+
var _loop = function(j, m) {
|
|
1400
|
+
var gltfSampler = samplers[j];
|
|
1401
|
+
var inputAccessor = accessors[gltfSampler.input];
|
|
1402
|
+
var outputAccessor = accessors[gltfSampler.output];
|
|
1403
|
+
var promise = Promise.all([
|
|
1404
|
+
GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor),
|
|
1405
|
+
GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor)
|
|
1406
|
+
]).then(function(bufferInfos) {
|
|
1407
|
+
var input = bufferInfos[0].data;
|
|
1408
|
+
var output = bufferInfos[1].data;
|
|
1409
|
+
if (outputAccessor.normalized) {
|
|
1410
|
+
var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
|
|
1411
|
+
var scaled = new Float32Array(output.length);
|
|
1412
|
+
for(var k = 0, v = output.length; k < v; k++){
|
|
1413
|
+
scaled[k] = output[k] * scale;
|
|
1414
|
+
}
|
|
1415
|
+
output = scaled;
|
|
1416
|
+
}
|
|
1417
|
+
var outputStride = output.length / input.length;
|
|
1418
|
+
var _gltfSampler_interpolation;
|
|
1419
|
+
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
1420
|
+
var samplerInterpolation;
|
|
1421
|
+
switch(interpolation){
|
|
1422
|
+
case AnimationSamplerInterpolation.CubicSpine:
|
|
1423
|
+
samplerInterpolation = engineCore.InterpolationType.CubicSpine;
|
|
1424
|
+
break;
|
|
1425
|
+
case AnimationSamplerInterpolation.Step:
|
|
1426
|
+
samplerInterpolation = engineCore.InterpolationType.Step;
|
|
1427
|
+
break;
|
|
1428
|
+
case AnimationSamplerInterpolation.Linear:
|
|
1429
|
+
samplerInterpolation = engineCore.InterpolationType.Linear;
|
|
1430
|
+
break;
|
|
1431
|
+
}
|
|
1432
|
+
input[input.length - 1];
|
|
1433
|
+
sampleDataCollection.push({
|
|
1434
|
+
type: outputAccessor.type,
|
|
1435
|
+
interpolation: samplerInterpolation,
|
|
1436
|
+
input: input,
|
|
1437
|
+
output: output,
|
|
1438
|
+
outputSize: outputStride
|
|
1439
|
+
});
|
|
1440
|
+
});
|
|
1441
|
+
promises.push(promise);
|
|
1442
|
+
};
|
|
1443
|
+
var _this = this;
|
|
1364
1444
|
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1365
1445
|
var entities = glTFResource.entities;
|
|
1366
1446
|
var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
|
|
1367
1447
|
var channels = animationInfo.channels, samplers = animationInfo.samplers;
|
|
1368
1448
|
var sampleDataCollection = new Array();
|
|
1449
|
+
var promises = new Array();
|
|
1369
1450
|
// parse samplers
|
|
1370
|
-
for(var j = 0, m = samplers.length; j < m; j++)
|
|
1371
|
-
|
|
1372
|
-
var
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
var
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1451
|
+
for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
|
|
1452
|
+
return Promise.all(promises).then(function() {
|
|
1453
|
+
for(var j = 0, m = channels.length; j < m; j++){
|
|
1454
|
+
var gltfChannel = channels[j];
|
|
1455
|
+
var target = gltfChannel.target;
|
|
1456
|
+
var channelTargetEntity = entities[target.node];
|
|
1457
|
+
var relativePath = "";
|
|
1458
|
+
var entity = channelTargetEntity;
|
|
1459
|
+
while(entity.parent){
|
|
1460
|
+
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
1461
|
+
entity = entity.parent;
|
|
1381
1462
|
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
output: output,
|
|
1405
|
-
outputSize: outputStride
|
|
1406
|
-
});
|
|
1407
|
-
}
|
|
1408
|
-
for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
|
|
1409
|
-
var gltfChannel = channels[j1];
|
|
1410
|
-
var target = gltfChannel.target;
|
|
1411
|
-
var channelTargetEntity = entities[target.node];
|
|
1412
|
-
var relativePath = "";
|
|
1413
|
-
var entity = channelTargetEntity;
|
|
1414
|
-
while(entity.parent){
|
|
1415
|
-
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
1416
|
-
entity = entity.parent;
|
|
1417
|
-
}
|
|
1418
|
-
var ComponentType = void 0;
|
|
1419
|
-
var propertyName = void 0;
|
|
1420
|
-
switch(target.path){
|
|
1421
|
-
case AnimationChannelTargetPath.TRANSLATION:
|
|
1422
|
-
ComponentType = engineCore.Transform;
|
|
1423
|
-
propertyName = "position";
|
|
1424
|
-
break;
|
|
1425
|
-
case AnimationChannelTargetPath.ROTATION:
|
|
1426
|
-
ComponentType = engineCore.Transform;
|
|
1427
|
-
propertyName = "rotationQuaternion";
|
|
1428
|
-
break;
|
|
1429
|
-
case AnimationChannelTargetPath.SCALE:
|
|
1430
|
-
ComponentType = engineCore.Transform;
|
|
1431
|
-
propertyName = "scale";
|
|
1432
|
-
break;
|
|
1433
|
-
case AnimationChannelTargetPath.WEIGHTS:
|
|
1434
|
-
ComponentType = engineCore.SkinnedMeshRenderer;
|
|
1435
|
-
propertyName = "blendShapeWeights";
|
|
1436
|
-
break;
|
|
1463
|
+
var ComponentType = void 0;
|
|
1464
|
+
var propertyName = void 0;
|
|
1465
|
+
switch(target.path){
|
|
1466
|
+
case AnimationChannelTargetPath.TRANSLATION:
|
|
1467
|
+
ComponentType = engineCore.Transform;
|
|
1468
|
+
propertyName = "position";
|
|
1469
|
+
break;
|
|
1470
|
+
case AnimationChannelTargetPath.ROTATION:
|
|
1471
|
+
ComponentType = engineCore.Transform;
|
|
1472
|
+
propertyName = "rotationQuaternion";
|
|
1473
|
+
break;
|
|
1474
|
+
case AnimationChannelTargetPath.SCALE:
|
|
1475
|
+
ComponentType = engineCore.Transform;
|
|
1476
|
+
propertyName = "scale";
|
|
1477
|
+
break;
|
|
1478
|
+
case AnimationChannelTargetPath.WEIGHTS:
|
|
1479
|
+
ComponentType = engineCore.SkinnedMeshRenderer;
|
|
1480
|
+
propertyName = "blendShapeWeights";
|
|
1481
|
+
break;
|
|
1482
|
+
}
|
|
1483
|
+
var curve = _this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
1484
|
+
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1437
1485
|
}
|
|
1438
|
-
|
|
1439
|
-
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1440
|
-
}
|
|
1486
|
+
});
|
|
1441
1487
|
};
|
|
1442
1488
|
GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
|
|
1443
1489
|
var sampleData = sampleDataCollection[gltfChannel.sampler];
|
|
@@ -1532,20 +1578,18 @@ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1532
1578
|
}).then(function(param) {
|
|
1533
1579
|
var glTF = param.glTF, buffers = param.buffers;
|
|
1534
1580
|
context.glTF = glTF;
|
|
1535
|
-
context.
|
|
1581
|
+
context._buffers = buffers;
|
|
1536
1582
|
});
|
|
1537
1583
|
} else {
|
|
1538
1584
|
return engineCore.request(url, {
|
|
1539
1585
|
type: "json"
|
|
1540
1586
|
}).then(function(glTF) {
|
|
1541
1587
|
context.glTF = glTF;
|
|
1542
|
-
|
|
1588
|
+
context._buffers = Promise.all(glTF.buffers.map(function(buffer) {
|
|
1543
1589
|
var absoluteUrl = engineCore.Utils.resolveAbsoluteUrl(url, buffer.uri);
|
|
1544
1590
|
restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
|
|
1545
1591
|
return engineCore.request(absoluteUrl, requestConfig);
|
|
1546
|
-
}))
|
|
1547
|
-
context.buffers = buffers;
|
|
1548
|
-
});
|
|
1592
|
+
}));
|
|
1549
1593
|
});
|
|
1550
1594
|
}
|
|
1551
1595
|
};
|
|
@@ -1624,6 +1668,10 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
1624
1668
|
}
|
|
1625
1669
|
sceneRoots[i] = rootEntity;
|
|
1626
1670
|
}
|
|
1671
|
+
// @ts-ignore
|
|
1672
|
+
sceneRoots[i]._hookResource = glTFResource;
|
|
1673
|
+
// @ts-ignore
|
|
1674
|
+
glTFResource._addReferCount(1);
|
|
1627
1675
|
}
|
|
1628
1676
|
glTFResource.sceneRoots = sceneRoots;
|
|
1629
1677
|
glTFResource.defaultSceneRoot = sceneRoots[sceneID];
|
|
@@ -1790,7 +1838,9 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1790
1838
|
}
|
|
1791
1839
|
}, function() {
|
|
1792
1840
|
var indexAccessor = glTF.accessors[gltfPrimitive.indices];
|
|
1793
|
-
return
|
|
1841
|
+
return context.getBuffers().then(function(buffers) {
|
|
1842
|
+
return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
|
|
1843
|
+
});
|
|
1794
1844
|
}, context.keepMeshData).then(resolve);
|
|
1795
1845
|
}
|
|
1796
1846
|
});
|
|
@@ -1800,7 +1850,7 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1800
1850
|
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1801
1851
|
meshPromises[i] = Promise.all(primitivePromises);
|
|
1802
1852
|
};
|
|
1803
|
-
var glTF = context.glTF,
|
|
1853
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
1804
1854
|
var engine = glTFResource.engine;
|
|
1805
1855
|
if (!glTF.meshes) return;
|
|
1806
1856
|
var meshesPromiseInfo = context.meshesPromiseInfo;
|
|
@@ -1815,8 +1865,109 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1815
1865
|
/**
|
|
1816
1866
|
* @internal
|
|
1817
1867
|
*/ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1868
|
+
var _loop = function(attribute) {
|
|
1869
|
+
var accessor = accessors[attributes[attribute]];
|
|
1870
|
+
var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor).then(function(accessorBuffer) {
|
|
1871
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
1872
|
+
var accessorCount = accessor.count;
|
|
1873
|
+
var vertices = accessorBuffer.data;
|
|
1874
|
+
var vertexElement;
|
|
1875
|
+
var meshId = mesh.instanceId;
|
|
1876
|
+
var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
|
|
1877
|
+
var elementNormalized = accessor.normalized;
|
|
1878
|
+
var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
|
|
1879
|
+
var scaleFactor;
|
|
1880
|
+
elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
|
|
1881
|
+
var elementOffset;
|
|
1882
|
+
if (accessorBuffer.interleaved) {
|
|
1883
|
+
var byteOffset = accessor.byteOffset || 0;
|
|
1884
|
+
var stride = accessorBuffer.stride;
|
|
1885
|
+
elementOffset = byteOffset % stride;
|
|
1886
|
+
if (vertexBindingInfos[meshId] === undefined) {
|
|
1887
|
+
vertexElement = new engineCore.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1888
|
+
var vertexBuffer = accessorBuffer.vertexBuffer;
|
|
1889
|
+
if (!vertexBuffer) {
|
|
1890
|
+
vertexBuffer = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
|
|
1891
|
+
vertexBuffer.setData(vertices);
|
|
1892
|
+
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
1893
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
1894
|
+
}
|
|
1895
|
+
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
1896
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1897
|
+
} else {
|
|
1898
|
+
vertexElement = new engineCore.VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
|
|
1899
|
+
}
|
|
1900
|
+
} else {
|
|
1901
|
+
elementOffset = 0;
|
|
1902
|
+
vertexElement = new engineCore.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1903
|
+
var vertexBuffer1 = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
|
|
1904
|
+
vertexBuffer1.setData(vertices);
|
|
1905
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
|
|
1906
|
+
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
1907
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1908
|
+
}
|
|
1909
|
+
vertexElements.push(vertexElement);
|
|
1910
|
+
if (attribute === "POSITION") {
|
|
1911
|
+
vertexCount = accessorCount;
|
|
1912
|
+
var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
|
|
1913
|
+
if (accessor.min && accessor.max) {
|
|
1914
|
+
min.copyFromArray(accessor.min);
|
|
1915
|
+
max.copyFromArray(accessor.max);
|
|
1916
|
+
if (keepMeshData) {
|
|
1917
|
+
var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1918
|
+
var stride1 = vertices.length / accessorCount;
|
|
1919
|
+
for(var j = 0; j < accessorCount; j++){
|
|
1920
|
+
var offset = baseOffset + j * stride1;
|
|
1921
|
+
var position = new engineMath.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
1922
|
+
elementNormalized && position.scale(scaleFactor);
|
|
1923
|
+
positions[j] = position;
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
} else {
|
|
1927
|
+
var position1 = GLTFMeshParser._tempVector3;
|
|
1928
|
+
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1929
|
+
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1930
|
+
var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1931
|
+
var stride2 = vertices.length / accessorCount;
|
|
1932
|
+
for(var j1 = 0; j1 < accessorCount; j1++){
|
|
1933
|
+
var offset1 = baseOffset1 + j1 * stride2;
|
|
1934
|
+
position1.copyFromArray(vertices, offset1);
|
|
1935
|
+
engineMath.Vector3.min(min, position1, min);
|
|
1936
|
+
engineMath.Vector3.max(max, position1, max);
|
|
1937
|
+
if (keepMeshData) {
|
|
1938
|
+
var clonePosition = position1.clone();
|
|
1939
|
+
elementNormalized && clonePosition.scale(scaleFactor);
|
|
1940
|
+
positions[j1] = clonePosition;
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
if (elementNormalized) {
|
|
1945
|
+
min.scale(scaleFactor);
|
|
1946
|
+
max.scale(scaleFactor);
|
|
1947
|
+
}
|
|
1948
|
+
} else if (attribute === "JOINTS_0" && keepMeshData) {
|
|
1949
|
+
var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1950
|
+
var stride3 = vertices.length / accessorCount;
|
|
1951
|
+
for(var j2 = 0; j2 < accessorCount; j2++){
|
|
1952
|
+
var offset2 = baseOffset2 + j2 * stride3;
|
|
1953
|
+
var boneIndex = new engineMath.Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
|
|
1954
|
+
elementNormalized && boneIndex.scale(scaleFactor);
|
|
1955
|
+
boneIndices[j2] = boneIndex;
|
|
1956
|
+
}
|
|
1957
|
+
} else if (attribute === "WEIGHTS_0" && keepMeshData) {
|
|
1958
|
+
var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1959
|
+
var stride4 = vertices.length / accessorCount;
|
|
1960
|
+
for(var j3 = 0; j3 < accessorCount; j3++){
|
|
1961
|
+
var offset3 = baseOffset3 + j3 * stride4;
|
|
1962
|
+
var boneWeight = new engineMath.Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
|
|
1963
|
+
elementNormalized && boneWeight.scale(scaleFactor);
|
|
1964
|
+
boneWeights[j3] = boneWeight;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
});
|
|
1968
|
+
promises.push(promise);
|
|
1969
|
+
};
|
|
1818
1970
|
var accessors = gltf.accessors;
|
|
1819
|
-
context.buffers;
|
|
1820
1971
|
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
1821
1972
|
var engine = mesh.engine;
|
|
1822
1973
|
var vertexElements = new Array();
|
|
@@ -1830,145 +1981,85 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
1830
1981
|
boneIndices = new Array(vertexCount);
|
|
1831
1982
|
boneWeights = new Array(vertexCount);
|
|
1832
1983
|
}
|
|
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 engineCore.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1853
|
-
var vertexBuffer = accessorBuffer.vertexBuffer;
|
|
1854
|
-
if (!vertexBuffer) {
|
|
1855
|
-
vertexBuffer = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.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 engineCore.VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
|
|
1864
|
-
}
|
|
1984
|
+
var promises = new Array();
|
|
1985
|
+
for(var attribute in attributes)_loop(attribute);
|
|
1986
|
+
return Promise.all(promises).then(function() {
|
|
1987
|
+
mesh.setVertexElements(vertexElements);
|
|
1988
|
+
// Indices
|
|
1989
|
+
if (indices !== undefined) {
|
|
1990
|
+
var indexAccessor = gltf.accessors[indices];
|
|
1991
|
+
var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor).then(function(accessorBuffer) {
|
|
1992
|
+
mesh.setIndices(accessorBuffer.data);
|
|
1993
|
+
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
1994
|
+
meshRestoreInfo.indexBuffer = accessorBuffer.restoreInfo;
|
|
1995
|
+
});
|
|
1996
|
+
promises.push(promise);
|
|
1865
1997
|
} else {
|
|
1866
|
-
|
|
1867
|
-
vertexElement = new engineCore.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1868
|
-
var vertexBuffer1 = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.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++;
|
|
1998
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
1873
1999
|
}
|
|
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 engineMath.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
|
-
engineMath.Vector3.min(min, position1, min);
|
|
1901
|
-
engineMath.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 engineMath.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 engineMath.Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
|
|
1928
|
-
elementNormalized && boneWeight.scale(scaleFactor);
|
|
1929
|
-
boneWeights[j3] = boneWeight;
|
|
1930
|
-
}
|
|
2000
|
+
// BlendShapes
|
|
2001
|
+
if (targets) {
|
|
2002
|
+
promises.push(GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, accessors, targets, getBlendShapeData));
|
|
1931
2003
|
}
|
|
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);
|
|
2004
|
+
return Promise.all(promises).then(function() {
|
|
2005
|
+
mesh.uploadData(!keepMeshData);
|
|
2006
|
+
//@ts-ignore
|
|
2007
|
+
mesh._positions = positions;
|
|
2008
|
+
//@ts-ignore
|
|
2009
|
+
mesh._boneIndices = boneIndices;
|
|
2010
|
+
//@ts-ignore
|
|
2011
|
+
mesh._boneWeights = boneWeights;
|
|
2012
|
+
return Promise.resolve(mesh);
|
|
2013
|
+
});
|
|
2014
|
+
});
|
|
1954
2015
|
};
|
|
1955
2016
|
/**
|
|
1956
2017
|
* @internal
|
|
1957
|
-
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
1958
|
-
var
|
|
1959
|
-
for(var i = 0, n = glTFTargets.length; i < n; i++){
|
|
2018
|
+
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, accessors, glTFTargets, getBlendShapeData) {
|
|
2019
|
+
var _loop = function(i, n) {
|
|
1960
2020
|
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
1961
|
-
var
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
2021
|
+
var promise = Promise.all([
|
|
2022
|
+
getBlendShapeData("POSITION", i),
|
|
2023
|
+
getBlendShapeData("NORMAL", i),
|
|
2024
|
+
getBlendShapeData("TANGENT", i)
|
|
2025
|
+
]).then(function(infos) {
|
|
2026
|
+
var posBufferInfo = infos[0];
|
|
2027
|
+
var norBufferInfo = infos[1];
|
|
2028
|
+
var tanBufferInfo = infos[2];
|
|
2029
|
+
var target = glTFTargets[i];
|
|
2030
|
+
var posAccessor;
|
|
2031
|
+
var norAccessor;
|
|
2032
|
+
var tanAccessor;
|
|
2033
|
+
var positions = null;
|
|
2034
|
+
if (posBufferInfo) {
|
|
2035
|
+
posAccessor = accessors[target["POSITION"]];
|
|
2036
|
+
var _posAccessor_byteOffset;
|
|
2037
|
+
positions = GLTFUtils.bufferToVector3Array(posBufferInfo.data, posBufferInfo.stride, (_posAccessor_byteOffset = posAccessor.byteOffset) != null ? _posAccessor_byteOffset : 0, posAccessor.count);
|
|
2038
|
+
}
|
|
2039
|
+
var normals = null;
|
|
2040
|
+
if (norBufferInfo) {
|
|
2041
|
+
norAccessor = accessors[target["NORMAL"]];
|
|
2042
|
+
var _norAccessor_byteOffset;
|
|
2043
|
+
normals = GLTFUtils.bufferToVector3Array(norBufferInfo.data, norBufferInfo.stride, (_norAccessor_byteOffset = norAccessor.byteOffset) != null ? _norAccessor_byteOffset : 0, norAccessor.count);
|
|
2044
|
+
}
|
|
2045
|
+
var tangents = null;
|
|
2046
|
+
if (tanBufferInfo) {
|
|
2047
|
+
tanAccessor = accessors[target["NORMAL"]];
|
|
2048
|
+
var _tanAccessor_byteOffset;
|
|
2049
|
+
tangents = GLTFUtils.bufferToVector3Array(tanBufferInfo.data, tanBufferInfo.stride, (_tanAccessor_byteOffset = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset : 0, tanAccessor.count);
|
|
2050
|
+
}
|
|
2051
|
+
var blendShape = new engineCore.BlendShape(name);
|
|
2052
|
+
blendShape.addFrame(1.0, positions, normals, tangents);
|
|
2053
|
+
mesh.addBlendShape(blendShape);
|
|
2054
|
+
var _posAccessor_byteOffset1, _norAccessor_byteOffset1, _tanAccessor_byteOffset1;
|
|
2055
|
+
meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, new BlendShapeDataRestoreInfo(posBufferInfo.restoreInfo, posBufferInfo.stride, (_posAccessor_byteOffset1 = posAccessor.byteOffset) != null ? _posAccessor_byteOffset1 : 0, posAccessor.count), norBufferInfo ? new BlendShapeDataRestoreInfo(norBufferInfo.restoreInfo, norBufferInfo.stride, (_norAccessor_byteOffset1 = norAccessor.byteOffset) != null ? _norAccessor_byteOffset1 : 0, norAccessor.count) : null, tanBufferInfo ? new BlendShapeDataRestoreInfo(tanBufferInfo.restoreInfo, tanBufferInfo.stride, (_tanAccessor_byteOffset1 = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset1 : 0, tanAccessor.count) : null));
|
|
2056
|
+
});
|
|
2057
|
+
promises.push(promise);
|
|
2058
|
+
};
|
|
2059
|
+
var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
|
|
2060
|
+
var promises = new Array();
|
|
2061
|
+
for(var i = 0, n = glTFTargets.length; i < n; i++)_loop(i);
|
|
2062
|
+
return Promise.all(promises);
|
|
1972
2063
|
};
|
|
1973
2064
|
return GLTFMeshParser;
|
|
1974
2065
|
}(GLTFParser);
|
|
@@ -2120,51 +2211,58 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2120
2211
|
}
|
|
2121
2212
|
var _proto = GLTFSkinParser.prototype;
|
|
2122
2213
|
_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++){
|
|
2214
|
+
var _loop = function(i) {
|
|
2130
2215
|
var _gltfSkins_i = gltfSkins[i], inverseBindMatrices = _gltfSkins_i.inverseBindMatrices, skeleton = _gltfSkins_i.skeleton, joints = _gltfSkins_i.joints, _gltfSkins_i_name = _gltfSkins_i.name, name = _gltfSkins_i_name === void 0 ? "SKIN_" + i : _gltfSkins_i_name;
|
|
2131
2216
|
var jointCount = joints.length;
|
|
2132
2217
|
var skin = new engineCore.Skin(name);
|
|
2133
2218
|
skin.inverseBindMatrices.length = jointCount;
|
|
2134
2219
|
// parse IBM
|
|
2135
2220
|
var accessor = glTF.accessors[inverseBindMatrices];
|
|
2136
|
-
var
|
|
2137
|
-
|
|
2138
|
-
var
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2221
|
+
var promise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
|
|
2222
|
+
var buffer = bufferInfo.data;
|
|
2223
|
+
for(var i = 0; i < jointCount; i++){
|
|
2224
|
+
var inverseBindMatrix = new engineMath.Matrix();
|
|
2225
|
+
inverseBindMatrix.copyFromArray(buffer, i * 16);
|
|
2226
|
+
skin.inverseBindMatrices[i] = inverseBindMatrix;
|
|
2227
|
+
// get joints
|
|
2228
|
+
for(var i1 = 0; i1 < jointCount; i1++){
|
|
2229
|
+
var jointIndex = joints[i1];
|
|
2230
|
+
var jointName = entities[jointIndex].name;
|
|
2231
|
+
skin.joints[i1] = jointName;
|
|
2232
|
+
// @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
|
|
2233
|
+
for(var j = entities.length - 1; j >= 0; j--){
|
|
2234
|
+
if (jointIndex !== j && entities[j].name === jointName) {
|
|
2235
|
+
entities[j].name = jointName + "_" + j;
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
// get skeleton
|
|
2240
|
+
if (skeleton !== undefined) {
|
|
2241
|
+
skin.skeleton = entities[skeleton].name;
|
|
2242
|
+
} else {
|
|
2243
|
+
var rootBone = _this._findSkeletonRootBone(joints, entities);
|
|
2244
|
+
if (rootBone) {
|
|
2245
|
+
skin.skeleton = rootBone.name;
|
|
2246
|
+
} else {
|
|
2247
|
+
throw "Failed to find skeleton root bone.";
|
|
2248
|
+
}
|
|
2151
2249
|
}
|
|
2152
2250
|
}
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2251
|
+
return skin;
|
|
2252
|
+
});
|
|
2253
|
+
promises.push(promise);
|
|
2254
|
+
};
|
|
2255
|
+
var _this = this;
|
|
2256
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2257
|
+
var entities = glTFResource.entities;
|
|
2258
|
+
var gltfSkins = glTF.skins;
|
|
2259
|
+
if (!gltfSkins) return;
|
|
2260
|
+
var count = gltfSkins.length;
|
|
2261
|
+
var promises = new Array();
|
|
2262
|
+
for(var i = 0; i < count; i++)_loop(i);
|
|
2263
|
+
return engineCore.AssetPromise.all(promises).then(function(skins) {
|
|
2264
|
+
glTFResource.skins = skins;
|
|
2265
|
+
});
|
|
2168
2266
|
};
|
|
2169
2267
|
_proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
|
|
2170
2268
|
var paths = {};
|
|
@@ -2205,13 +2303,14 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2205
2303
|
var _proto = GLTFTextureParser.prototype;
|
|
2206
2304
|
_proto.parse = function parse(context) {
|
|
2207
2305
|
var _this = this;
|
|
2208
|
-
var glTFResource = context.glTFResource, glTF = context.glTF
|
|
2306
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
2209
2307
|
var engine = glTFResource.engine, url = glTFResource.url;
|
|
2210
2308
|
if (glTF.textures) {
|
|
2211
2309
|
var texturesPromiseInfo = context.texturesPromiseInfo;
|
|
2212
2310
|
engineCore.AssetPromise.all(glTF.textures.map(function(param, index) {
|
|
2213
2311
|
var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
|
|
2214
2312
|
var _glTF_images_source = glTF.images[source], uri = _glTF_images_source.uri, bufferViewIndex = _glTF_images_source.bufferView, mimeType = _glTF_images_source.mimeType, imageName = _glTF_images_source.name;
|
|
2313
|
+
var samplerInfo = sampler !== undefined && _this._getSamplerInfo(glTF.samplers[sampler]);
|
|
2215
2314
|
if (uri) {
|
|
2216
2315
|
// TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
|
|
2217
2316
|
var index1 = uri.lastIndexOf(".");
|
|
@@ -2219,31 +2318,36 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2219
2318
|
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.Texture2D;
|
|
2220
2319
|
return engine.resourceManager.load({
|
|
2221
2320
|
url: engineCore.Utils.resolveAbsoluteUrl(url, uri),
|
|
2222
|
-
type: type
|
|
2321
|
+
type: type,
|
|
2322
|
+
params: {
|
|
2323
|
+
mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap
|
|
2324
|
+
}
|
|
2223
2325
|
}).then(function(texture) {
|
|
2224
2326
|
if (!texture.name) {
|
|
2225
2327
|
texture.name = textureName || imageName || "texture_" + index1;
|
|
2226
2328
|
}
|
|
2227
2329
|
if (sampler !== undefined) {
|
|
2228
|
-
_this._parseSampler(texture,
|
|
2330
|
+
_this._parseSampler(texture, samplerInfo);
|
|
2229
2331
|
}
|
|
2230
2332
|
return texture;
|
|
2231
2333
|
});
|
|
2232
2334
|
} else {
|
|
2233
2335
|
var bufferView = glTF.bufferViews[bufferViewIndex];
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2336
|
+
return context.getBuffers().then(function(buffers) {
|
|
2337
|
+
var buffer = buffers[bufferView.buffer];
|
|
2338
|
+
var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
2339
|
+
return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
|
|
2340
|
+
var texture = new engineCore.Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap);
|
|
2341
|
+
texture.setImageSource(image);
|
|
2342
|
+
texture.generateMipmaps();
|
|
2343
|
+
texture.name = textureName || imageName || "texture_" + index;
|
|
2344
|
+
if (sampler !== undefined) {
|
|
2345
|
+
_this._parseSampler(texture, samplerInfo);
|
|
2346
|
+
}
|
|
2347
|
+
var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
|
|
2348
|
+
context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
|
|
2349
|
+
return texture;
|
|
2350
|
+
});
|
|
2247
2351
|
});
|
|
2248
2352
|
}
|
|
2249
2353
|
})).then(function(textures) {
|
|
@@ -2253,22 +2357,39 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
2253
2357
|
return texturesPromiseInfo.promise;
|
|
2254
2358
|
}
|
|
2255
2359
|
};
|
|
2256
|
-
_proto.
|
|
2257
|
-
var
|
|
2258
|
-
|
|
2360
|
+
_proto._getSamplerInfo = function _getSamplerInfo(sampler) {
|
|
2361
|
+
var minFilter = sampler.minFilter, magFilter = sampler.magFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
|
|
2362
|
+
var info = {};
|
|
2363
|
+
if (minFilter || magFilter) {
|
|
2364
|
+
info.mipmap = minFilter >= TextureMinFilter.NEAREST_MIPMAP_NEAREST;
|
|
2259
2365
|
if (magFilter === TextureMagFilter.NEAREST) {
|
|
2260
|
-
|
|
2261
|
-
} else if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
2262
|
-
texture.filterMode = engineCore.TextureFilterMode.Bilinear;
|
|
2366
|
+
info.filterMode = engineCore.TextureFilterMode.Point;
|
|
2263
2367
|
} else {
|
|
2264
|
-
|
|
2368
|
+
if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
2369
|
+
info.filterMode = engineCore.TextureFilterMode.Bilinear;
|
|
2370
|
+
} else {
|
|
2371
|
+
info.filterMode = engineCore.TextureFilterMode.Trilinear;
|
|
2372
|
+
}
|
|
2265
2373
|
}
|
|
2266
2374
|
}
|
|
2267
2375
|
if (wrapS) {
|
|
2268
|
-
|
|
2376
|
+
info.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
|
|
2269
2377
|
}
|
|
2270
2378
|
if (wrapT) {
|
|
2271
|
-
|
|
2379
|
+
info.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
|
|
2380
|
+
}
|
|
2381
|
+
return info;
|
|
2382
|
+
};
|
|
2383
|
+
_proto._parseSampler = function _parseSampler(texture, samplerInfo) {
|
|
2384
|
+
var filterMode = samplerInfo.filterMode, wrapModeU = samplerInfo.wrapModeU, wrapModeV = samplerInfo.wrapModeV;
|
|
2385
|
+
if (filterMode !== undefined) {
|
|
2386
|
+
texture.filterMode = filterMode;
|
|
2387
|
+
}
|
|
2388
|
+
if (wrapModeU !== undefined) {
|
|
2389
|
+
texture.wrapModeU = wrapModeU;
|
|
2390
|
+
}
|
|
2391
|
+
if (wrapModeV !== undefined) {
|
|
2392
|
+
texture.wrapModeV = wrapModeV;
|
|
2272
2393
|
}
|
|
2273
2394
|
};
|
|
2274
2395
|
return GLTFTextureParser;
|
|
@@ -2366,33 +2487,16 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
2366
2487
|
|
|
2367
2488
|
/**
|
|
2368
2489
|
* Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
|
|
2369
|
-
*/ var GLTFResource = /*#__PURE__*/ function(
|
|
2370
|
-
_inherits(GLTFResource,
|
|
2490
|
+
*/ var GLTFResource = /*#__PURE__*/ function(ReferResource) {
|
|
2491
|
+
_inherits(GLTFResource, ReferResource);
|
|
2371
2492
|
function GLTFResource(engine, url) {
|
|
2372
2493
|
var _this;
|
|
2373
|
-
_this =
|
|
2494
|
+
_this = ReferResource.call(this, engine) || this;
|
|
2374
2495
|
_this.url = url;
|
|
2375
2496
|
return _this;
|
|
2376
2497
|
}
|
|
2377
|
-
var _proto = GLTFResource.prototype;
|
|
2378
|
-
/**
|
|
2379
|
-
* @internal
|
|
2380
|
-
*/ _proto._onDestroy = function _onDestroy() {
|
|
2381
|
-
EngineObject.prototype._onDestroy.call(this);
|
|
2382
|
-
this.defaultSceneRoot.destroy();
|
|
2383
|
-
this.textures = null;
|
|
2384
|
-
this.materials = null;
|
|
2385
|
-
this.meshes = null;
|
|
2386
|
-
this.skins = null;
|
|
2387
|
-
this.animations = null;
|
|
2388
|
-
this.entities = null;
|
|
2389
|
-
this.cameras = null;
|
|
2390
|
-
this.lights = null;
|
|
2391
|
-
this.sceneRoots = null;
|
|
2392
|
-
this.extensionsData = null;
|
|
2393
|
-
};
|
|
2394
2498
|
return GLTFResource;
|
|
2395
|
-
}(engineCore.
|
|
2499
|
+
}(engineCore.ReferResource);
|
|
2396
2500
|
|
|
2397
2501
|
var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
2398
2502
|
_inherits(GLTFLoader, Loader);
|
|
@@ -2422,8 +2526,14 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
|
2422
2526
|
resourceManager.addContentRestorer(restorer);
|
|
2423
2527
|
masterPromiseInfo.resolve(glTFResource);
|
|
2424
2528
|
}).catch(function(e) {
|
|
2425
|
-
|
|
2426
|
-
|
|
2529
|
+
var msg = "Error loading glTF model from " + url + " : " + e;
|
|
2530
|
+
engineCore.Logger.error(msg);
|
|
2531
|
+
masterPromiseInfo.reject(msg);
|
|
2532
|
+
context.defaultSceneRootPromiseInfo.reject(e);
|
|
2533
|
+
context.texturesPromiseInfo.reject(e);
|
|
2534
|
+
context.materialsPromiseInfo.reject(e);
|
|
2535
|
+
context.meshesPromiseInfo.reject(e);
|
|
2536
|
+
context.animationClipsPromiseInfo.reject(e);
|
|
2427
2537
|
});
|
|
2428
2538
|
return context.promiseMap;
|
|
2429
2539
|
};
|
|
@@ -3025,6 +3135,15 @@ KTXLoader = __decorate([
|
|
|
3025
3135
|
])
|
|
3026
3136
|
], KTXLoader);
|
|
3027
3137
|
|
|
3138
|
+
function parseProperty(object, key, value) {
|
|
3139
|
+
if (typeof value === "object") {
|
|
3140
|
+
for(var subKey in value){
|
|
3141
|
+
parseProperty(object[key], subKey, value[subKey]);
|
|
3142
|
+
}
|
|
3143
|
+
} else {
|
|
3144
|
+
object[key] = value;
|
|
3145
|
+
}
|
|
3146
|
+
}
|
|
3028
3147
|
var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
3029
3148
|
_inherits(MaterialLoader, Loader);
|
|
3030
3149
|
function MaterialLoader() {
|
|
@@ -3036,7 +3155,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
3036
3155
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
3037
3156
|
_this.request(item.url, _extends({}, item, {
|
|
3038
3157
|
type: "json"
|
|
3039
|
-
})).then(function(
|
|
3158
|
+
})).then(function(materialSchema) {
|
|
3040
3159
|
var _loop = function(key) {
|
|
3041
3160
|
var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
|
|
3042
3161
|
switch(type){
|
|
@@ -3064,27 +3183,8 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
3064
3183
|
}
|
|
3065
3184
|
};
|
|
3066
3185
|
var engine = resourceManager.engine;
|
|
3067
|
-
var name =
|
|
3068
|
-
var material;
|
|
3069
|
-
switch(shader){
|
|
3070
|
-
case "pbr":
|
|
3071
|
-
material = new engineCore.PBRMaterial(engine);
|
|
3072
|
-
break;
|
|
3073
|
-
case "pbr-specular":
|
|
3074
|
-
material = new engineCore.PBRSpecularMaterial(engine);
|
|
3075
|
-
break;
|
|
3076
|
-
case "unlit":
|
|
3077
|
-
material = new engineCore.UnlitMaterial(engine);
|
|
3078
|
-
break;
|
|
3079
|
-
case "blinn-phong":
|
|
3080
|
-
material = new engineCore.BlinnPhongMaterial(engine);
|
|
3081
|
-
break;
|
|
3082
|
-
case "bake-pbr":
|
|
3083
|
-
// @todo refactor custom shader later
|
|
3084
|
-
// @ts-ignore
|
|
3085
|
-
material = new engineCore.PBRBaseMaterial(engine, engineCore.Shader.find("bake-pbr"));
|
|
3086
|
-
break;
|
|
3087
|
-
}
|
|
3186
|
+
var name = materialSchema.name, shader = materialSchema.shader, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
|
|
3187
|
+
var material = new engineCore.Material(engine, engineCore.Shader.find(shader));
|
|
3088
3188
|
material.name = name;
|
|
3089
3189
|
var texturePromises = new Array();
|
|
3090
3190
|
var materialShaderData = material.shaderData;
|
|
@@ -3097,9 +3197,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
3097
3197
|
materialShaderData.enableMacro(name1, value);
|
|
3098
3198
|
}
|
|
3099
3199
|
}
|
|
3100
|
-
|
|
3101
|
-
material[key1] = renderState[key1];
|
|
3102
|
-
}
|
|
3200
|
+
parseProperty(material, "renderState", renderState);
|
|
3103
3201
|
return Promise.all(texturePromises).then(function() {
|
|
3104
3202
|
resolve(material);
|
|
3105
3203
|
});
|
|
@@ -3854,6 +3952,12 @@ exports.AnimationClipDecoder = __decorate([
|
|
|
3854
3952
|
decoder("AnimationClip")
|
|
3855
3953
|
], exports.AnimationClipDecoder);
|
|
3856
3954
|
|
|
3955
|
+
exports.SpecularMode = void 0;
|
|
3956
|
+
(function(SpecularMode) {
|
|
3957
|
+
SpecularMode["Sky"] = "Sky";
|
|
3958
|
+
SpecularMode["Custom"] = "Custom";
|
|
3959
|
+
})(exports.SpecularMode || (exports.SpecularMode = {}));
|
|
3960
|
+
|
|
3857
3961
|
var SceneParserContext = /*#__PURE__*/ function() {
|
|
3858
3962
|
function SceneParserContext(originalData, scene) {
|
|
3859
3963
|
this.originalData = originalData;
|
|
@@ -3981,7 +4085,7 @@ exports.MeshLoader = /*#__PURE__*/ function(Loader) {
|
|
|
3981
4085
|
decode(data, resourceManager.engine).then(function(mesh) {
|
|
3982
4086
|
resolve(mesh);
|
|
3983
4087
|
});
|
|
3984
|
-
});
|
|
4088
|
+
}).catch(reject);
|
|
3985
4089
|
});
|
|
3986
4090
|
};
|
|
3987
4091
|
return MeshLoader;
|
|
@@ -4000,14 +4104,14 @@ exports.EditorTextureLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4000
4104
|
var _proto = EditorTextureLoader.prototype;
|
|
4001
4105
|
_proto.load = function load(item, resourceManager) {
|
|
4002
4106
|
var _this = this;
|
|
4003
|
-
return new engineCore.AssetPromise(function(resolve) {
|
|
4107
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
4004
4108
|
_this.request(item.url, {
|
|
4005
4109
|
type: "arraybuffer"
|
|
4006
4110
|
}).then(function(data) {
|
|
4007
4111
|
decode(data, resourceManager.engine).then(function(texture) {
|
|
4008
4112
|
resolve(texture);
|
|
4009
4113
|
});
|
|
4010
|
-
});
|
|
4114
|
+
}).catch(reject);
|
|
4011
4115
|
});
|
|
4012
4116
|
};
|
|
4013
4117
|
return EditorTextureLoader;
|
|
@@ -4384,7 +4488,7 @@ var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4384
4488
|
_this.request(item.url, _extends({}, item, {
|
|
4385
4489
|
type: "arraybuffer"
|
|
4386
4490
|
})).then(function(data) {
|
|
4387
|
-
return decode(data, resourceManager.engine);
|
|
4491
|
+
return decode(data, resourceManager.engine).then(resolve);
|
|
4388
4492
|
}).catch(reject);
|
|
4389
4493
|
});
|
|
4390
4494
|
};
|
|
@@ -4412,16 +4516,32 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4412
4516
|
// @ts-ignore
|
|
4413
4517
|
engine.resourceManager.initVirtualResources(data.files);
|
|
4414
4518
|
return SceneParser.parse(engine, data).then(function(scene) {
|
|
4519
|
+
var promises = [];
|
|
4415
4520
|
// parse ambient light
|
|
4416
4521
|
var ambient = data.scene.ambient;
|
|
4417
|
-
var
|
|
4418
|
-
if (ambient.
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4522
|
+
var useCustomAmbient = ambient.specularMode === "Custom";
|
|
4523
|
+
if (useCustomAmbient && ambient.customAmbientLight) {
|
|
4524
|
+
// @ts-ignore
|
|
4525
|
+
// prettier-ignore
|
|
4526
|
+
var customAmbientPromise = resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
|
|
4527
|
+
scene.ambientLight = ambientLight;
|
|
4528
|
+
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
4529
|
+
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
4530
|
+
scene.ambientLight.diffuseMode = ambient.diffuseMode;
|
|
4531
|
+
scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
|
|
4532
|
+
});
|
|
4533
|
+
promises.push(customAmbientPromise);
|
|
4534
|
+
} else if (!useCustomAmbient && ambient.ambientLight) {
|
|
4535
|
+
// @ts-ignore
|
|
4536
|
+
// prettier-ignore
|
|
4537
|
+
var ambientLightPromise = resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
|
|
4538
|
+
scene.ambientLight = ambientLight;
|
|
4422
4539
|
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
4423
4540
|
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
4541
|
+
scene.ambientLight.diffuseMode = ambient.diffuseMode;
|
|
4542
|
+
scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
|
|
4424
4543
|
});
|
|
4544
|
+
promises.push(ambientLightPromise);
|
|
4425
4545
|
} else {
|
|
4426
4546
|
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
4427
4547
|
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
@@ -4429,30 +4549,34 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4429
4549
|
}
|
|
4430
4550
|
var background = data.scene.background;
|
|
4431
4551
|
scene.background.mode = background.mode;
|
|
4432
|
-
var backgroundPromise = Promise.resolve();
|
|
4433
4552
|
switch(scene.background.mode){
|
|
4434
4553
|
case engineCore.BackgroundMode.SolidColor:
|
|
4435
4554
|
scene.background.solidColor.copyFrom(background.color);
|
|
4436
4555
|
break;
|
|
4437
4556
|
case engineCore.BackgroundMode.Sky:
|
|
4438
|
-
if (background.
|
|
4557
|
+
if (background.skyMesh && background.skyMaterial) {
|
|
4558
|
+
// @ts-ignore
|
|
4559
|
+
var skyMeshPromise = resourceManager.getResourceByRef(background.skyMesh).then(function(mesh) {
|
|
4560
|
+
scene.background.sky.mesh = mesh;
|
|
4561
|
+
});
|
|
4439
4562
|
// @ts-ignore
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
skyMaterial.texture = light.specularTexture;
|
|
4444
|
-
skyMaterial.textureDecodeRGBM = true;
|
|
4445
|
-
sky.material = skyMaterial;
|
|
4446
|
-
sky.mesh = engineCore.PrimitiveMesh.createCuboid(engine, 1, 1, 1);
|
|
4563
|
+
// prettier-ignore
|
|
4564
|
+
var skyMaterialPromise = resourceManager.getResourceByRef(background.skyMaterial).then(function(material) {
|
|
4565
|
+
scene.background.sky.material = material;
|
|
4447
4566
|
});
|
|
4567
|
+
promises.push(skyMeshPromise, skyMaterialPromise);
|
|
4568
|
+
} else {
|
|
4569
|
+
engineCore.Logger.warn("Sky background mode requires skyMesh and skyMaterial");
|
|
4448
4570
|
}
|
|
4449
4571
|
break;
|
|
4450
4572
|
case engineCore.BackgroundMode.Texture:
|
|
4451
4573
|
if (background.texture) {
|
|
4452
4574
|
// @ts-ignore
|
|
4453
|
-
|
|
4575
|
+
// prettier-ignore
|
|
4576
|
+
var backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
|
|
4454
4577
|
scene.background.texture = texture;
|
|
4455
4578
|
});
|
|
4579
|
+
promises.push(backgroundPromise);
|
|
4456
4580
|
}
|
|
4457
4581
|
break;
|
|
4458
4582
|
}
|
|
@@ -4464,10 +4588,7 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
4464
4588
|
if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
|
|
4465
4589
|
if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
|
|
4466
4590
|
}
|
|
4467
|
-
return Promise.all(
|
|
4468
|
-
ambientLightPromise,
|
|
4469
|
-
backgroundPromise
|
|
4470
|
-
]).then(function() {
|
|
4591
|
+
return Promise.all(promises).then(function() {
|
|
4471
4592
|
resolve(scene);
|
|
4472
4593
|
});
|
|
4473
4594
|
});
|
|
@@ -4510,7 +4631,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
|
|
|
4510
4631
|
};
|
|
4511
4632
|
_proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
|
|
4512
4633
|
var _this = this;
|
|
4513
|
-
var glTF = context.glTF,
|
|
4634
|
+
var glTF = context.glTF, engine = context.glTFResource.engine;
|
|
4514
4635
|
var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
|
|
4515
4636
|
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
4516
4637
|
var attributeMap = {};
|
|
@@ -4532,21 +4653,23 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
|
|
|
4532
4653
|
useUniqueIDs: true,
|
|
4533
4654
|
indexType: indexType
|
|
4534
4655
|
};
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4656
|
+
return context.getBuffers().then(function(buffers) {
|
|
4657
|
+
var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
4658
|
+
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
|
|
4659
|
+
var mesh = new engineCore.ModelMesh(engine, glTFMesh.name);
|
|
4660
|
+
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
|
|
4661
|
+
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
4662
|
+
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
4663
|
+
return decodedGeometry.attributes[j].array;
|
|
4664
|
+
}
|
|
4542
4665
|
}
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
}
|
|
4666
|
+
return null;
|
|
4667
|
+
}, function(attributeSemantic, shapeIndex) {
|
|
4668
|
+
throw "BlendShape animation is not supported when using draco.";
|
|
4669
|
+
}, function() {
|
|
4670
|
+
return decodedGeometry.index.array;
|
|
4671
|
+
}, context.keepMeshData);
|
|
4672
|
+
});
|
|
4550
4673
|
});
|
|
4551
4674
|
};
|
|
4552
4675
|
_proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
@@ -4645,7 +4768,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
|
|
|
4645
4768
|
mesh.addSubMesh(0, vertexCount, mode);
|
|
4646
4769
|
}
|
|
4647
4770
|
// BlendShapes
|
|
4648
|
-
targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
|
|
4771
|
+
targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, accessors, targets, getBlendShapeData);
|
|
4649
4772
|
mesh.uploadData(!keepMeshData);
|
|
4650
4773
|
return Promise.resolve(mesh);
|
|
4651
4774
|
};
|