@galacean/engine-loader 2.0.0-alpha.43 → 2.0.0-alpha.44

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, AssetPromise, AnimationClip, AnimationEvent, Loader, AnimationStringCurve, Keyframe, AnimationBoolCurve, AnimationRefCurve, AnimationQuaternionCurve, AnimationColorCurve, AnimationVector4Curve, AnimationVector3Curve, AnimationVector2Curve, AnimationFloatArrayCurve, AnimationArrayCurve, AnimationFloatCurve, ModelMesh, BlendShape, TextureFormat, Texture2D, TextureCube, TextureCubeFace, ReferResource, Entity, resourceLoader, AssetType, AnimatorController, AnimatorControllerLayer, AnimatorStateTransition, BufferAsset, GLCapabilityType, Logger, ContentRestorer, AmbientLight, DiffuseMode, TextureFilterMode, Font, SystemInfo, Animator, IndexFormat, VertexElementFormat, request, InterpolationType, SkinnedMeshRenderer, Transform, PBRMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, Camera, MeshRenderer, Skin, TextureWrapMode as TextureWrapMode$1, TextureUtils, AnimatorStateMachine, JSONAsset, Shader, Material, PrimitiveMesh, SpriteAtlas, Sprite, TextAsset, AudioClip, PhysicsMaterial, RenderTarget, Scene, BackgroundMode, DirectLight, PointLight, SpotLight, UnlitMaterial } from '@galacean/engine-core';
1
+ import { Utils, AssetPromise, AnimationClip, AnimationEvent, Loader, AnimationStringCurve, Keyframe, AnimationBoolCurve, AnimationRefCurve, AnimationQuaternionCurve, AnimationColorCurve, AnimationVector4Curve, AnimationVector3Curve, AnimationVector2Curve, AnimationFloatArrayCurve, AnimationArrayCurve, AnimationFloatCurve, ModelMesh, BlendShape, TextureFormat, Texture2D, TextureCube, TextureCubeFace, ReferResource, Entity, resourceLoader, AssetType, AnimatorController, AnimatorControllerLayer, AnimatorStateTransition, BufferAsset, GLCapabilityType, Logger, ContentRestorer, AmbientLight, DiffuseMode, TextureFilterMode, Font, SystemInfo, Animator, IndexFormat, VertexElementFormat, request, InterpolationType, SkinnedMeshRenderer, Transform, PBRMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, Camera, MeshRenderer, Skin, TextureWrapMode as TextureWrapMode$1, TextureUtils, AnimatorStateMachine, JSONAsset, Shader, Material, Texture, PrimitiveMesh, SpriteAtlas, Sprite, TextAsset, AudioClip, PhysicsMaterial, RenderTarget, Scene, BackgroundMode, DirectLight, PointLight, SpotLight, UnlitMaterial } from '@galacean/engine-core';
2
2
  import { Quaternion, Vector4, Color, Vector3, Vector2, MathUtil, SphericalHarmonics3, Matrix, BoundingBox, Rect } from '@galacean/engine-math';
3
3
  import { GLCompressedTextureInternalFormat } from '@galacean/engine-rhi-webgl';
4
4
 
@@ -5776,6 +5776,7 @@ var KTXContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
5776
5776
  return KTXContentRestorer;
5777
5777
  }(ContentRestorer);
5778
5778
 
5779
+ var materialLoaderTypes = new Set(Object.values(MaterialLoaderType));
5779
5780
  var MaterialLoader = /*#__PURE__*/ function(Loader) {
5780
5781
  _inherits(MaterialLoader, Loader);
5781
5782
  function MaterialLoader() {
@@ -5784,23 +5785,32 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
5784
5785
  var _proto = MaterialLoader.prototype;
5785
5786
  _proto.load = function load(item, resourceManager) {
5786
5787
  var _this = this;
5787
- return new AssetPromise(function(resolve, reject) {
5788
- resourceManager// @ts-ignore
5789
- ._request(item.url, _extends({}, item, {
5790
- type: "json"
5791
- })).then(function(materialSchema) {
5792
- var engine = resourceManager.engine;
5793
- var shaderRef = materialSchema.shaderRef, shaderName = materialSchema.shader;
5794
- var shader = Shader.find(shaderName);
5795
- if (shader) {
5796
- resolve(_this._getMaterialByShader(materialSchema, shader, engine));
5797
- } else if (shaderRef) {
5798
- resolve(resourceManager// @ts-ignore
5799
- .getResourceByRef(shaderRef).then(function(shader) {
5800
- return _this._getMaterialByShader(materialSchema, shader, engine);
5801
- }));
5788
+ // @ts-expect-error _request is @internal
5789
+ return resourceManager._request(item.url, _extends({}, item, {
5790
+ type: "json"
5791
+ })).then(function(materialSchema) {
5792
+ var shaderData = materialSchema.shaderData, shaderRef = materialSchema.shaderRef, shaderName = materialSchema.shader;
5793
+ for(var key in shaderData){
5794
+ var type = shaderData[key].type;
5795
+ if (!materialLoaderTypes.has(type)) {
5796
+ throw new Error('MaterialLoader: unsupported shader data type "' + type + '".');
5802
5797
  }
5803
- }).catch(reject);
5798
+ }
5799
+ var engine = resourceManager.engine;
5800
+ var shader = Shader.find(shaderName);
5801
+ if (shader) {
5802
+ return _this._getMaterialByShader(materialSchema, shader, engine);
5803
+ }
5804
+ if (!shaderRef) {
5805
+ throw new Error('MaterialLoader: shader "' + shaderName + '" not found.');
5806
+ }
5807
+ // @ts-expect-error getResourceByRef is @internal
5808
+ return resourceManager.getResourceByRef(shaderRef).then(function(shader) {
5809
+ if (!_instanceof(shader, Shader)) {
5810
+ throw new Error('MaterialLoader: shader reference "' + shaderRef.url + '" did not resolve to a Shader.');
5811
+ }
5812
+ return _this._getMaterialByShader(materialSchema, shader, engine);
5813
+ });
5804
5814
  });
5805
5815
  };
5806
5816
  _proto._getMaterialByShader = function _getMaterialByShader(materialSchema, shader, engine) {
@@ -5823,8 +5833,11 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
5823
5833
  materialShaderData.setFloat(key, value);
5824
5834
  break;
5825
5835
  case MaterialLoaderType.Texture:
5826
- texturePromises.push(// @ts-ignore
5836
+ texturePromises.push(// @ts-expect-error getResourceByRef is @internal
5827
5837
  engine.resourceManager.getResourceByRef(value).then(function(texture) {
5838
+ if (!_instanceof(texture, Texture)) {
5839
+ throw new Error('MaterialLoader: texture reference "' + value.url + '" did not resolve to a Texture.');
5840
+ }
5828
5841
  materialShaderData.setTexture(key, texture);
5829
5842
  }));
5830
5843
  break;
@@ -5834,6 +5847,8 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
5834
5847
  case MaterialLoaderType.Integer:
5835
5848
  materialShaderData.setInt(key, Number(value));
5836
5849
  break;
5850
+ default:
5851
+ throw new Error('MaterialLoader: unsupported shader data type "' + type + '".');
5837
5852
  }
5838
5853
  };
5839
5854
  var name = materialSchema.name, shaderData = materialSchema.shaderData, macros = materialSchema.macros;
@@ -5852,6 +5867,9 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
5852
5867
  }
5853
5868
  return Promise.all(texturePromises).then(function() {
5854
5869
  return material;
5870
+ }, function(error) {
5871
+ material.destroy();
5872
+ throw error;
5855
5873
  });
5856
5874
  };
5857
5875
  return MaterialLoader;
@@ -6410,11 +6428,11 @@ var ShaderLoader = /*#__PURE__*/ function(Loader) {
6410
6428
  type: "text"
6411
6429
  })).then(function(code) {
6412
6430
  var source = code.trimStart();
6413
- if (source.startsWith("{")) {
6414
- // @ts-expect-error _createFromPrecompiled is @internal
6415
- return Shader._createFromPrecompiled(JSON.parse(source));
6431
+ var shader = source.startsWith("{") ? Shader._createFromPrecompiled(JSON.parse(source)) : Shader.create(code, undefined, url);
6432
+ if (!shader) {
6433
+ throw new Error('ShaderLoader: failed to create shader "' + url + '".');
6416
6434
  }
6417
- return Shader.create(code, undefined, url);
6435
+ return shader;
6418
6436
  });
6419
6437
  };
6420
6438
  return ShaderLoader;