@galacean/engine-loader 1.4.0-alpha.0 → 1.4.0-alpha.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/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Utils, ModelMesh, BlendShape, Texture2D, Loader, Entity, AnimationClip, AnimationEvent, AnimationStringCurve, Keyframe, AnimationBoolCurve, AnimationRefCurve, AnimationQuaternionCurve, AnimationColorCurve, AnimationVector4Curve, AnimationVector3Curve, AnimationVector2Curve, AnimationFloatArrayCurve, AnimationArrayCurve, AnimationFloatCurve, ReferResource, Scene, resourceLoader, AssetPromise, AssetType, AnimatorController, AnimatorControllerLayer, AnimatorStateTransition, TextureCube, TextureFilterMode, TextureCubeFace, AmbientLight, DiffuseMode, Font, Animator, IndexFormat, VertexElementFormat, GLCapabilityType, Logger, TextureFormat, request, ContentRestorer, InterpolationType, SkinnedMeshRenderer, Transform, PBRMaterial, BlinnPhongMaterial, PBRSpecularMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, Camera, MeshRenderer, Skin, TextureWrapMode as TextureWrapMode$1, AnimatorStateMachine, SystemInfo, Shader, Material, PrimitiveMesh, SpriteAtlas, Sprite, ShaderFactory, ShaderLib, BackgroundMode, DirectLight, PointLight, SpotLight, UnlitMaterial } from '@galacean/engine-core';
1
+ import { Utils, ModelMesh, BlendShape, Texture2D, Loader, Entity, AnimationClip, AnimationEvent, AnimationStringCurve, Keyframe, AnimationBoolCurve, AnimationRefCurve, AnimationQuaternionCurve, AnimationColorCurve, AnimationVector4Curve, AnimationVector3Curve, AnimationVector2Curve, AnimationFloatArrayCurve, AnimationArrayCurve, AnimationFloatCurve, ReferResource, Scene, resourceLoader, AssetPromise, AssetType, AnimatorController, AnimatorControllerLayer, AnimatorStateTransition, AmbientLight, DiffuseMode, TextureCube, TextureFilterMode, TextureCubeFace, request, ContentRestorer, Font, Animator, IndexFormat, VertexElementFormat, GLCapabilityType, Logger, TextureFormat, InterpolationType, SkinnedMeshRenderer, Transform, PBRMaterial, BlinnPhongMaterial, PBRSpecularMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, Camera, MeshRenderer, Skin, TextureWrapMode as TextureWrapMode$1, AnimatorStateMachine, SystemInfo, Shader, Material, PrimitiveMesh, SpriteAtlas, Sprite, AudioClip, AudioManager, ShaderFactory, ShaderLib, BackgroundMode, DirectLight, PointLight, SpotLight, UnlitMaterial } from '@galacean/engine-core';
2
2
  import { Color, Vector4, Vector3, Vector2, Quaternion, SphericalHarmonics3, MathUtil, BoundingBox, Matrix, Rect } from '@galacean/engine-math';
3
3
  import { GLCompressedTextureInternalFormat } from '@galacean/engine-rhi-webgl';
4
4
 
@@ -1570,32 +1570,18 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
1570
1570
  var _proto = EnvLoader.prototype;
1571
1571
  _proto.load = function load(item, resourceManager) {
1572
1572
  return new AssetPromise(function(resolve, reject) {
1573
- resourceManager// @ts-ignore
1574
- ._request(item.url, _extends({}, item, {
1573
+ var requestConfig = _extends({}, item, {
1575
1574
  type: "arraybuffer"
1576
- })).then(function(arraybuffer) {
1577
- var _this;
1578
- var shArray = new Float32Array(arraybuffer, 0, 27);
1579
- var shByteLength = 27 * 4;
1580
- var size = (_this = new Uint16Array(arraybuffer, shByteLength, 1)) == null ? void 0 : _this[0];
1581
- var engine = resourceManager.engine;
1582
- var texture = new TextureCube(engine, size);
1583
- texture.filterMode = TextureFilterMode.Trilinear;
1584
- var mipmapCount = texture.mipmapCount;
1585
- var offset = shByteLength + 2;
1586
- for(var mipLevel = 0; mipLevel < mipmapCount; mipLevel++){
1587
- var mipSize = size >> mipLevel;
1588
- for(var face = 0; face < 6; face++){
1589
- var dataSize = mipSize * mipSize * 4;
1590
- var data = new Uint8Array(arraybuffer, offset, dataSize);
1591
- offset += dataSize;
1592
- texture.setPixelBuffer(TextureCubeFace.PositiveX + face, data, mipLevel);
1593
- }
1594
- }
1575
+ });
1576
+ var engine = resourceManager.engine;
1577
+ resourceManager// @ts-ignore
1578
+ ._request(item.url, requestConfig).then(function(arraybuffer) {
1579
+ var texture = EnvLoader._setTextureByBuffer(engine, arraybuffer);
1580
+ engine.resourceManager.addContentRestorer(new EnvContentRestorer(texture, item.url, requestConfig));
1595
1581
  var ambientLight = new AmbientLight(engine);
1596
1582
  var sh = new SphericalHarmonics3();
1597
1583
  ambientLight.diffuseMode = DiffuseMode.SphericalHarmonics;
1598
- sh.copyFromArray(shArray);
1584
+ sh.copyFromArray(new Float32Array(arraybuffer, 0, 27));
1599
1585
  ambientLight.diffuseSphericalHarmonics = sh;
1600
1586
  ambientLight.specularTexture = texture;
1601
1587
  ambientLight.specularTextureDecodeRGBM = true;
@@ -1605,6 +1591,27 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
1605
1591
  });
1606
1592
  });
1607
1593
  };
1594
+ /**
1595
+ * @internal
1596
+ */ EnvLoader._setTextureByBuffer = function _setTextureByBuffer(engine, buffer, texture) {
1597
+ var _this;
1598
+ var shByteLength = 27 * 4;
1599
+ var size = (_this = new Uint16Array(buffer, shByteLength, 1)) == null ? void 0 : _this[0];
1600
+ texture || (texture = new TextureCube(engine, size));
1601
+ texture.filterMode = TextureFilterMode.Trilinear;
1602
+ var mipmapCount = texture.mipmapCount;
1603
+ var offset = shByteLength + 2;
1604
+ for(var mipLevel = 0; mipLevel < mipmapCount; mipLevel++){
1605
+ var mipSize = size >> mipLevel;
1606
+ for(var face = 0; face < 6; face++){
1607
+ var dataSize = mipSize * mipSize * 4;
1608
+ var data = new Uint8Array(buffer, offset, dataSize);
1609
+ offset += dataSize;
1610
+ texture.setPixelBuffer(TextureCubeFace.PositiveX + face, data, mipLevel);
1611
+ }
1612
+ }
1613
+ return texture;
1614
+ };
1608
1615
  return EnvLoader;
1609
1616
  }(Loader);
1610
1617
  EnvLoader = __decorate([
@@ -1612,6 +1619,27 @@ EnvLoader = __decorate([
1612
1619
  "env"
1613
1620
  ])
1614
1621
  ], EnvLoader);
1622
+ /**
1623
+ * @internal
1624
+ */ var EnvContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
1625
+ _inherits(EnvContentRestorer, ContentRestorer);
1626
+ function EnvContentRestorer(resource, url, requestConfig) {
1627
+ var _this;
1628
+ _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
1629
+ return _this;
1630
+ }
1631
+ var _proto = EnvContentRestorer.prototype;
1632
+ _proto.restoreContent = function restoreContent() {
1633
+ var _this = this;
1634
+ return new AssetPromise(function(resolve, reject) {
1635
+ request(_this.url, _this.requestConfig).then(function(buffer) {
1636
+ EnvLoader._setTextureByBuffer(_this.resource.engine, buffer, _this.resource);
1637
+ resolve(_this.resource);
1638
+ }).catch(reject);
1639
+ });
1640
+ };
1641
+ return EnvContentRestorer;
1642
+ }(ContentRestorer);
1615
1643
 
1616
1644
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1617
1645
  try {
@@ -2029,7 +2057,7 @@ FontLoader = __decorate([
2029
2057
  task.total += 1;
2030
2058
  taskPromise.then(function() {
2031
2059
  _this._setTaskCompleteProgress(++task.loaded, task.total);
2032
- });
2060
+ }, function() {});
2033
2061
  };
2034
2062
  _proto._handleSubAsset = function _handleSubAsset(resource, type, index) {
2035
2063
  var _this = this;
@@ -6319,6 +6347,45 @@ TextureCubeLoader = __decorate([
6319
6347
  ])
6320
6348
  ], TextureCubeLoader);
6321
6349
 
6350
+ var AudioLoader = /*#__PURE__*/ function(Loader) {
6351
+ _inherits(AudioLoader, Loader);
6352
+ function AudioLoader() {
6353
+ return Loader.apply(this, arguments) || this;
6354
+ }
6355
+ var _proto = AudioLoader.prototype;
6356
+ _proto.load = function load(item, resourceManager) {
6357
+ return new AssetPromise(function(resolve, reject) {
6358
+ var url = item.url;
6359
+ var requestConfig = _extends({}, item, {
6360
+ type: "arraybuffer"
6361
+ });
6362
+ // @ts-ignore
6363
+ resourceManager._request(url, requestConfig).then(function(arrayBuffer) {
6364
+ var audioClip = new AudioClip(resourceManager.engine);
6365
+ AudioManager.getContext().decodeAudioData(arrayBuffer).then(function(result) {
6366
+ // @ts-ignore
6367
+ audioClip._setAudioSource(result);
6368
+ if (url.indexOf("data:") !== 0) {
6369
+ var index = url.lastIndexOf("/");
6370
+ audioClip.name = url.substring(index + 1);
6371
+ }
6372
+ resolve(audioClip);
6373
+ }).catch(function(e) {
6374
+ reject(e);
6375
+ });
6376
+ });
6377
+ });
6378
+ };
6379
+ return AudioLoader;
6380
+ }(Loader);
6381
+ AudioLoader = __decorate([
6382
+ resourceLoader(AssetType.Audio, [
6383
+ "mp3",
6384
+ "ogg",
6385
+ "wav"
6386
+ ])
6387
+ ], AudioLoader);
6388
+
6322
6389
  var ShaderChunkLoader = /*#__PURE__*/ function(Loader) {
6323
6390
  _inherits(ShaderChunkLoader, Loader);
6324
6391
  function ShaderChunkLoader() {
@@ -6356,7 +6423,7 @@ var ShaderChunkLoader = /*#__PURE__*/ function(Loader) {
6356
6423
  };
6357
6424
  return ShaderChunkLoader;
6358
6425
  }(Loader);
6359
- ShaderChunkLoader._shaderIncludeRegex = /\s#include\s+"([./][^\\"]+)"/gm;
6426
+ ShaderChunkLoader._shaderIncludeRegex = /#include\s+"([./][^\\"]+)"/gm;
6360
6427
  ShaderChunkLoader = __decorate([
6361
6428
  resourceLoader("ShaderChunk", [
6362
6429
  "glsl"
@@ -6694,6 +6761,37 @@ KHR_materials_pbrSpecularGlossiness = __decorate([
6694
6761
  registerGLTFExtension("KHR_materials_pbrSpecularGlossiness", GLTFExtensionMode.CreateAndParse)
6695
6762
  ], KHR_materials_pbrSpecularGlossiness);
6696
6763
 
6764
+ var KHR_materials_sheen = /*#__PURE__*/ function(GLTFExtensionParser) {
6765
+ _inherits(KHR_materials_sheen, GLTFExtensionParser);
6766
+ function KHR_materials_sheen() {
6767
+ return GLTFExtensionParser.apply(this, arguments) || this;
6768
+ }
6769
+ var _proto = KHR_materials_sheen.prototype;
6770
+ _proto.additiveParse = function additiveParse(context, material, schema) {
6771
+ var sheenColorFactor = schema.sheenColorFactor, sheenColorTexture = schema.sheenColorTexture, _schema_sheenRoughnessFactor = schema.sheenRoughnessFactor, sheenRoughnessFactor = _schema_sheenRoughnessFactor === void 0 ? 0 : _schema_sheenRoughnessFactor, sheenRoughnessTexture = schema.sheenRoughnessTexture;
6772
+ if (sheenColorFactor) {
6773
+ material.sheenColor.set(Color.linearToGammaSpace(sheenColorFactor[0]), Color.linearToGammaSpace(sheenColorFactor[1]), Color.linearToGammaSpace(sheenColorFactor[2]), undefined);
6774
+ }
6775
+ material.sheenRoughness = sheenRoughnessFactor;
6776
+ if (sheenColorTexture) {
6777
+ GLTFMaterialParser._checkOtherTextureTransform(sheenColorTexture, "Sheen texture");
6778
+ context.get(GLTFParserType.Texture, sheenColorTexture.index).then(function(texture) {
6779
+ material.sheenColorTexture = texture;
6780
+ });
6781
+ }
6782
+ if (sheenRoughnessTexture) {
6783
+ GLTFMaterialParser._checkOtherTextureTransform(sheenRoughnessTexture, "SheenRoughness texture");
6784
+ context.get(GLTFParserType.Texture, sheenRoughnessTexture.index).then(function(texture) {
6785
+ material.sheenRoughnessTexture = texture;
6786
+ });
6787
+ }
6788
+ };
6789
+ return KHR_materials_sheen;
6790
+ }(GLTFExtensionParser);
6791
+ KHR_materials_sheen = __decorate([
6792
+ registerGLTFExtension("KHR_materials_sheen", GLTFExtensionMode.AdditiveParse)
6793
+ ], KHR_materials_sheen);
6794
+
6697
6795
  var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
6698
6796
  _inherits(KHR_materials_unlit, GLTFExtensionParser);
6699
6797
  function KHR_materials_unlit() {