@galacean/engine-loader 2.0.0-alpha.59 → 2.0.0-alpha.60

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 CHANGED
@@ -514,140 +514,6 @@ exports.AnimationClipDecoder = __decorate([
514
514
  decoder("AnimationClip")
515
515
  ], exports.AnimationClipDecoder);
516
516
 
517
- exports.MeshDecoder = /*#__PURE__*/ function() {
518
- function MeshDecoder() {}
519
- MeshDecoder.decode = function decode(engine, bufferReader, restoredMesh) {
520
- return new engineCore.AssetPromise(function(resolve) {
521
- var modelMesh = restoredMesh || new engineCore.ModelMesh(engine);
522
- var jsonDataString = bufferReader.nextStr();
523
- var encodedMeshData = JSON.parse(jsonDataString);
524
- // @ts-ignore Vector3 is not compatible with {x: number, y: number, z: number}.
525
- encodedMeshData.bounds && modelMesh.bounds.copyFrom(encodedMeshData.bounds);
526
- var offset = Math.ceil(bufferReader.offset / 4) * 4 + bufferReader.data.byteOffset;
527
- var buffer = bufferReader.data.buffer;
528
- var float32Array = new Float32Array(buffer, encodedMeshData.positions.start + offset, (encodedMeshData.positions.end - encodedMeshData.positions.start) / 4);
529
- var vertexCount = float32Array.length / 3;
530
- var positions = float32ArrayToVector3(float32Array, vertexCount);
531
- modelMesh.setPositions(positions);
532
- if (encodedMeshData.normals) {
533
- var float32Array1 = new Float32Array(buffer, encodedMeshData.normals.start + offset, (encodedMeshData.normals.end - encodedMeshData.normals.start) / 4);
534
- var normals = float32ArrayToVector3(float32Array1, vertexCount);
535
- modelMesh.setNormals(normals);
536
- }
537
- if (encodedMeshData.uvs) {
538
- var float32Array2 = new Float32Array(buffer, encodedMeshData.uvs.start + offset, (encodedMeshData.uvs.end - encodedMeshData.uvs.start) / 4);
539
- modelMesh.setUVs(float32ArrayToVector2(float32Array2, vertexCount));
540
- }
541
- if (encodedMeshData.uv1) {
542
- var float32Array3 = new Float32Array(buffer, encodedMeshData.uv1.start + offset, (encodedMeshData.uv1.end - encodedMeshData.uv1.start) / 4);
543
- modelMesh.setUVs(float32ArrayToVector2(float32Array3, vertexCount), 1);
544
- }
545
- if (encodedMeshData.uv2) {
546
- var float32Array4 = new Float32Array(buffer, encodedMeshData.uv2.start + offset, (encodedMeshData.uv2.end - encodedMeshData.uv2.start) / 4);
547
- modelMesh.setUVs(float32ArrayToVector2(float32Array4, vertexCount), 2);
548
- }
549
- if (encodedMeshData.uv3) {
550
- var float32Array5 = new Float32Array(buffer, encodedMeshData.uv3.start + offset, (encodedMeshData.uv3.end - encodedMeshData.uv3.start) / 4);
551
- modelMesh.setUVs(float32ArrayToVector2(float32Array5, vertexCount), 3);
552
- }
553
- if (encodedMeshData.uv4) {
554
- var float32Array6 = new Float32Array(buffer, encodedMeshData.uv4.start + offset, (encodedMeshData.uv4.end - encodedMeshData.uv4.start) / 4);
555
- modelMesh.setUVs(float32ArrayToVector2(float32Array6, vertexCount), 4);
556
- }
557
- if (encodedMeshData.uv5) {
558
- var float32Array7 = new Float32Array(buffer, encodedMeshData.uv5.start + offset, (encodedMeshData.uv5.end - encodedMeshData.uv5.start) / 4);
559
- modelMesh.setUVs(float32ArrayToVector2(float32Array7, vertexCount), 5);
560
- }
561
- if (encodedMeshData.uv6) {
562
- var float32Array8 = new Float32Array(buffer, encodedMeshData.uv6.start + offset, (encodedMeshData.uv6.end - encodedMeshData.uv6.start) / 4);
563
- modelMesh.setUVs(float32ArrayToVector2(float32Array8, vertexCount), 6);
564
- }
565
- if (encodedMeshData.uv7) {
566
- var float32Array9 = new Float32Array(buffer, encodedMeshData.uv7.start + offset, (encodedMeshData.uv7.end - encodedMeshData.uv7.start) / 4);
567
- modelMesh.setUVs(float32ArrayToVector2(float32Array9, vertexCount), 7);
568
- }
569
- if (encodedMeshData.colors) {
570
- var float32Array10 = new Float32Array(buffer, encodedMeshData.colors.start + offset, (encodedMeshData.colors.end - encodedMeshData.colors.start) / 4);
571
- modelMesh.setColors(float32ArrayToVColor(float32Array10, vertexCount));
572
- }
573
- if (encodedMeshData.boneWeights) {
574
- var float32Array11 = new Float32Array(buffer, encodedMeshData.boneWeights.start + offset, (encodedMeshData.boneWeights.end - encodedMeshData.boneWeights.start) / 4);
575
- modelMesh.setBoneWeights(float32ArrayToVector4(float32Array11, vertexCount));
576
- }
577
- if (encodedMeshData.boneIndices) {
578
- var float32Array12 = new Float32Array(buffer, encodedMeshData.boneIndices.start + offset, (encodedMeshData.boneIndices.end - encodedMeshData.boneIndices.start) / 4);
579
- modelMesh.setBoneIndices(float32ArrayToVector4(float32Array12, vertexCount));
580
- }
581
- if (encodedMeshData.blendShapes) {
582
- encodedMeshData.blendShapes.forEach(function(blendShapeData) {
583
- var blendShape = new engineCore.BlendShape(blendShapeData.name);
584
- blendShapeData.frames.forEach(function(frameData) {
585
- var positionArray = new Float32Array(buffer, frameData.deltaPosition.start + offset, (frameData.deltaPosition.end - frameData.deltaPosition.start) / 4);
586
- var count = positionArray.length / 3;
587
- var deltaPosition = float32ArrayToVector3(positionArray, count);
588
- if (frameData.deltaNormals) {
589
- var normalsArray = new Float32Array(buffer, frameData.deltaNormals.start + offset, (frameData.deltaNormals.end - frameData.deltaNormals.start) / 4);
590
- float32ArrayToVector3(normalsArray, count);
591
- }
592
- if (frameData.deltaTangents) {
593
- var tangentsArray = new Float32Array(buffer, frameData.deltaTangents.start + offset, (frameData.deltaTangents.end - frameData.deltaTangents.start) / 4);
594
- float32ArrayToVector4(tangentsArray, count);
595
- }
596
- blendShape.addFrame(frameData.weight, deltaPosition);
597
- });
598
- modelMesh.addBlendShape(blendShape);
599
- });
600
- }
601
- if (encodedMeshData.indices) {
602
- var indices = null;
603
- if (encodedMeshData.indices.type === 0) {
604
- indices = new Uint16Array(buffer, encodedMeshData.indices.start + offset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 2);
605
- } else {
606
- indices = new Uint32Array(buffer, encodedMeshData.indices.start + offset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 4);
607
- }
608
- modelMesh.setIndices(indices);
609
- }
610
- encodedMeshData.subMeshes.forEach(function(subMesh) {
611
- return modelMesh.addSubMesh(subMesh);
612
- });
613
- modelMesh.uploadData(false);
614
- resolve(modelMesh);
615
- });
616
- };
617
- return MeshDecoder;
618
- }();
619
- exports.MeshDecoder = __decorate([
620
- decoder("Mesh")
621
- ], exports.MeshDecoder);
622
- function float32ArrayToVColor(float32Array, vertexCount) {
623
- var array = new Array(vertexCount);
624
- for(var i = 0; i < vertexCount; i++){
625
- array[i] = new engineMath.Color(float32Array[i * 4], float32Array[i * 4 + 1], float32Array[i * 4 + 2], float32Array[i * 4 + 3]);
626
- }
627
- return array;
628
- }
629
- function float32ArrayToVector4(float32Array, vertexCount) {
630
- var array = new Array(vertexCount);
631
- for(var i = 0; i < vertexCount; i++){
632
- array[i] = new engineMath.Vector4(float32Array[i * 4], float32Array[i * 4 + 1], float32Array[i * 4 + 2], float32Array[i * 4 + 3]);
633
- }
634
- return array;
635
- }
636
- function float32ArrayToVector3(float32Array, vertexCount) {
637
- var array = new Array(vertexCount);
638
- for(var i = 0; i < vertexCount; i++){
639
- array[i] = new engineMath.Vector3(float32Array[i * 3], float32Array[i * 3 + 1], float32Array[i * 3 + 2]);
640
- }
641
- return array;
642
- }
643
- function float32ArrayToVector2(float32Array, vertexCount) {
644
- var array = new Array(vertexCount);
645
- for(var i = 0; i < vertexCount; i++){
646
- array[i] = new engineMath.Vector2(float32Array[i * 2], float32Array[i * 2 + 1]);
647
- }
648
- return array;
649
- }
650
-
651
517
  function _is_native_reflect_construct() {
652
518
  // Since Reflect.construct can't be properly polyfilled, some
653
519
  // implementations (e.g. core-js@2) don't set the correct internal slots.
@@ -2512,12 +2378,7 @@ exports.KTX2Loader = /*#__PURE__*/ function(Loader) {
2512
2378
  var _proto = KTX2Loader.prototype;
2513
2379
  _proto.initialize = function initialize(_, configuration) {
2514
2380
  if (configuration.ktx2Loader) {
2515
- var options = configuration.ktx2Loader;
2516
- if (options.priorityFormats) {
2517
- KTX2Loader._priorityFormats["etc1s"] = options.priorityFormats;
2518
- KTX2Loader._priorityFormats["uastc"] = options.priorityFormats;
2519
- }
2520
- return KTX2Loader._getBinomialLLCTranscoder(options.workerCount).init();
2381
+ return KTX2Loader._getBinomialLLCTranscoder(configuration.ktx2Loader.workerCount).init();
2521
2382
  }
2522
2383
  };
2523
2384
  /**
@@ -2612,20 +2473,18 @@ exports.KTX2Loader = /*#__PURE__*/ function(Loader) {
2612
2473
  for(var i = 0; i < priorityFormats.length; i++){
2613
2474
  var _this__capabilityMap_format;
2614
2475
  var format = priorityFormats[i];
2615
- var capabilities = (_this__capabilityMap_format = this._capabilityMap[format]) == null ? void 0 : _this__capabilityMap_format[isSRGB ? DFDTransferFunction.sRGB : DFDTransferFunction.linear];
2616
- if (capabilities) {
2617
- for(var j = 0; j < capabilities.length; j++){
2618
- if (renderer.canIUse(capabilities[j])) {
2619
- return format;
2620
- }
2621
- }
2476
+ var capability = (_this__capabilityMap_format = this._capabilityMap[format]) == null ? void 0 : _this__capabilityMap_format[isSRGB ? DFDTransferFunction.sRGB : DFDTransferFunction.linear];
2477
+ if (capability) {
2478
+ if (renderer.canIUse(capability)) return format;
2622
2479
  } else {
2623
2480
  switch(priorityFormats[i]){
2624
2481
  case KTX2TargetFormat.R8G8B8A8:
2625
2482
  return format;
2626
2483
  case KTX2TargetFormat.R8:
2627
2484
  case KTX2TargetFormat.R8G8:
2628
- if (renderer.isWebGL2) return format;
2485
+ return format;
2486
+ case KTX2TargetFormat.R16G16B16A16:
2487
+ if (!isSRGB) return format;
2629
2488
  }
2630
2489
  }
2631
2490
  }
@@ -2679,37 +2538,8 @@ exports.KTX2Loader._priorityFormats = (_obj$2 = {}, _obj$2[ColorModel.ETC1S] = [
2679
2538
  KTX2TargetFormat.BC6H,
2680
2539
  KTX2TargetFormat.R16G16B16A16
2681
2540
  ], _obj$2);
2682
- var _obj1$1, _obj2, _obj3, _obj4, _obj5, _obj6, _obj7, _obj8, _obj9;
2683
- exports.KTX2Loader._capabilityMap = (_obj9 = {}, _obj9[KTX2TargetFormat.ASTC] = (_obj1$1 = {}, _obj1$1[DFDTransferFunction.linear] = [
2684
- engineCore.GLCapabilityType.astc,
2685
- engineCore.GLCapabilityType.astc_webkit
2686
- ], _obj1$1[DFDTransferFunction.sRGB] = [
2687
- engineCore.GLCapabilityType.astc,
2688
- engineCore.GLCapabilityType.astc_webkit
2689
- ], _obj1$1), _obj9[KTX2TargetFormat.ETC] = (_obj2 = {}, _obj2[DFDTransferFunction.linear] = [
2690
- engineCore.GLCapabilityType.etc,
2691
- engineCore.GLCapabilityType.etc_webkit
2692
- ], _obj2[DFDTransferFunction.sRGB] = [
2693
- engineCore.GLCapabilityType.etc,
2694
- engineCore.GLCapabilityType.etc_webkit
2695
- ], _obj2), _obj9[KTX2TargetFormat.BC7] = (_obj3 = {}, _obj3[DFDTransferFunction.linear] = [
2696
- engineCore.GLCapabilityType.bptc
2697
- ], _obj3[DFDTransferFunction.sRGB] = [
2698
- engineCore.GLCapabilityType.bptc
2699
- ], _obj3), _obj9[KTX2TargetFormat.BC1_BC3] = (_obj4 = {}, _obj4[DFDTransferFunction.linear] = [
2700
- engineCore.GLCapabilityType.s3tc
2701
- ], _obj4[DFDTransferFunction.sRGB] = [
2702
- engineCore.GLCapabilityType.s3tc_srgb
2703
- ], _obj4), _obj9[KTX2TargetFormat.BC6H] = (_obj5 = {}, _obj5[DFDTransferFunction.linear] = [
2704
- engineCore.GLCapabilityType.bptc
2705
- ], _obj5), _obj9[KTX2TargetFormat.ASTC_HDR_4x4] = (_obj6 = {}, _obj6[DFDTransferFunction.linear] = [
2706
- engineCore.GLCapabilityType.astc_hdr
2707
- ], _obj6), _obj9[KTX2TargetFormat.R16G16B16A16] = (_obj7 = {}, _obj7[DFDTransferFunction.linear] = [
2708
- engineCore.GLCapabilityType.textureHalfFloat
2709
- ], _obj7), _obj9[KTX2TargetFormat.PVRTC] = (_obj8 = {}, _obj8[DFDTransferFunction.linear] = [
2710
- engineCore.GLCapabilityType.pvrtc,
2711
- engineCore.GLCapabilityType.pvrtc_webkit
2712
- ], _obj8), _obj9);
2541
+ var _obj1$1, _obj2, _obj3, _obj4, _obj5, _obj6, _obj7, _obj8;
2542
+ exports.KTX2Loader._capabilityMap = (_obj8 = {}, _obj8[KTX2TargetFormat.ASTC] = (_obj1$1 = {}, _obj1$1[DFDTransferFunction.linear] = engineCore.GLCapabilityType.astc, _obj1$1[DFDTransferFunction.sRGB] = engineCore.GLCapabilityType.astc, _obj1$1), _obj8[KTX2TargetFormat.ETC] = (_obj2 = {}, _obj2[DFDTransferFunction.linear] = engineCore.GLCapabilityType.etc, _obj2[DFDTransferFunction.sRGB] = engineCore.GLCapabilityType.etc, _obj2), _obj8[KTX2TargetFormat.BC7] = (_obj3 = {}, _obj3[DFDTransferFunction.linear] = engineCore.GLCapabilityType.bptc, _obj3[DFDTransferFunction.sRGB] = engineCore.GLCapabilityType.bptc, _obj3), _obj8[KTX2TargetFormat.BC1_BC3] = (_obj4 = {}, _obj4[DFDTransferFunction.linear] = engineCore.GLCapabilityType.s3tc, _obj4[DFDTransferFunction.sRGB] = engineCore.GLCapabilityType.s3tc_srgb, _obj4), _obj8[KTX2TargetFormat.BC6H] = (_obj5 = {}, _obj5[DFDTransferFunction.linear] = engineCore.GLCapabilityType.bptc, _obj5), _obj8[KTX2TargetFormat.ASTC_HDR_4x4] = (_obj6 = {}, _obj6[DFDTransferFunction.linear] = engineCore.GLCapabilityType.astc_hdr, _obj6), _obj8[KTX2TargetFormat.PVRTC] = (_obj7 = {}, _obj7[DFDTransferFunction.linear] = engineCore.GLCapabilityType.pvrtc, _obj7), _obj8);
2713
2543
  exports.KTX2Loader = __decorate([
2714
2544
  engineCore.resourceLoader(engineCore.AssetType.KTX2, [
2715
2545
  "ktx2"
@@ -5209,7 +5039,7 @@ exports.GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
5209
5039
  var width = image.width, height = image.height;
5210
5040
  var format = engineCore.TextureFormat.R8G8B8A8;
5211
5041
  var _samplerInfo_mipmap;
5212
- var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, (_samplerInfo_mipmap = samplerInfo == null ? void 0 : samplerInfo.mipmap) != null ? _samplerInfo_mipmap : true, isSRGBColorSpace);
5042
+ var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(format, (_samplerInfo_mipmap = samplerInfo == null ? void 0 : samplerInfo.mipmap) != null ? _samplerInfo_mipmap : true, isSRGBColorSpace);
5213
5043
  var texture = new engineCore.Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
5214
5044
  texture.setImageSource(image);
5215
5045
  texture.generateMipmaps();
@@ -5885,56 +5715,6 @@ MaterialLoader = __decorate([
5885
5715
  ])
5886
5716
  ], MaterialLoader);
5887
5717
 
5888
- var MeshLoader = /*#__PURE__*/ function(Loader) {
5889
- _inherits(MeshLoader, Loader);
5890
- function MeshLoader() {
5891
- return Loader.apply(this, arguments) || this;
5892
- }
5893
- var _proto = MeshLoader.prototype;
5894
- _proto.load = function load(item, resourceManager) {
5895
- var requestConfig = _extends({}, item, {
5896
- type: "arraybuffer"
5897
- });
5898
- var remoteUrl = resourceManager._getRemoteUrl(item.url);
5899
- return new engineCore.AssetPromise(function(resolve, reject) {
5900
- resourceManager._requestByRemoteUrl(remoteUrl, requestConfig).then(function(data) {
5901
- return decode(data, resourceManager.engine);
5902
- }).then(function(mesh) {
5903
- resourceManager.addContentRestorer(new MeshContentRestorer(mesh, remoteUrl, requestConfig));
5904
- resolve(mesh);
5905
- }).catch(reject);
5906
- });
5907
- };
5908
- return MeshLoader;
5909
- }(engineCore.Loader);
5910
- MeshLoader = __decorate([
5911
- engineCore.resourceLoader(engineCore.AssetType.Mesh, [
5912
- "mesh"
5913
- ])
5914
- ], MeshLoader);
5915
- var MeshContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
5916
- _inherits(MeshContentRestorer, ContentRestorer);
5917
- function MeshContentRestorer(resource, remoteUrl, requestConfig) {
5918
- var _this;
5919
- _this = ContentRestorer.call(this, resource) || this, _this.remoteUrl = remoteUrl, _this.requestConfig = requestConfig;
5920
- return _this;
5921
- }
5922
- var _proto = MeshContentRestorer.prototype;
5923
- _proto.restoreContent = function restoreContent() {
5924
- var _this = this;
5925
- var resource = this.resource;
5926
- var engine = resource.engine;
5927
- return new engineCore.AssetPromise(function(resolve, reject) {
5928
- engine.resourceManager._requestByRemoteUrl(_this.remoteUrl, _this.requestConfig).then(function(data) {
5929
- return decode(data, engine, resource);
5930
- }).then(function(mesh) {
5931
- resolve(mesh);
5932
- }).catch(reject);
5933
- });
5934
- };
5935
- return MeshContentRestorer;
5936
- }(engineCore.ContentRestorer);
5937
-
5938
5718
  var PrimitiveMeshLoader = /*#__PURE__*/ function(Loader) {
5939
5719
  _inherits(PrimitiveMeshLoader, Loader);
5940
5720
  function PrimitiveMeshLoader() {
@@ -6045,7 +5825,7 @@ var PrimitiveMeshLoader = /*#__PURE__*/ function(Loader) {
6045
5825
  PrimitiveMeshLoader = __decorate([
6046
5826
  engineCore.resourceLoader(engineCore.AssetType.PrimitiveMesh, [
6047
5827
  "mesh"
6048
- ], false)
5828
+ ])
6049
5829
  ], PrimitiveMeshLoader);
6050
5830
 
6051
5831
  var ProjectLoader = /*#__PURE__*/ function(Loader) {
@@ -6346,7 +6126,7 @@ var TextureLoader = /*#__PURE__*/ function(Loader) {
6346
6126
  var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? engineCore.TextureFormat.R8G8B8A8 : _ref_format, _ref_isSRGBColorSpace = _ref.isSRGBColorSpace, isSRGBColorSpace = _ref_isSRGBColorSpace === void 0 ? true : _ref_isSRGBColorSpace, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
6347
6127
  var engine = resourceManager.engine;
6348
6128
  var width = img.width, height = img.height;
6349
- var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
6129
+ var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(format, mipmap, isSRGBColorSpace);
6350
6130
  var texture = new engineCore.Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
6351
6131
  texture.setImageSource(img);
6352
6132
  generateMipmap && texture.generateMipmaps();