@galacean/engine-loader 2.0.0-alpha.37 → 2.0.0-alpha.39

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, AudioManager, 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, 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
 
@@ -639,6 +639,39 @@ function float32ArrayToVector2(float32Array, vertexCount) {
639
639
  return array;
640
640
  }
641
641
 
642
+ function _is_native_reflect_construct() {
643
+ // Since Reflect.construct can't be properly polyfilled, some
644
+ // implementations (e.g. core-js@2) don't set the correct internal slots.
645
+ // Those polyfills don't allow us to subclass built-ins, so we need to
646
+ // use our fallback implementation.
647
+ try {
648
+ // If the internal slots aren't set, this throws an error similar to
649
+ // TypeError: this is not a Boolean object.
650
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
651
+ } catch (_) {}
652
+ return (_is_native_reflect_construct = function() {
653
+ return !!result;
654
+ })();
655
+ }
656
+
657
+ function _construct(Parent, args, Class) {
658
+ if (_is_native_reflect_construct()) _construct = Reflect.construct;
659
+ else {
660
+ _construct = function construct(Parent, args, Class) {
661
+ var a = [null];
662
+ a.push.apply(a, args);
663
+ var Constructor = Function.bind.apply(Parent, a);
664
+ var instance = new Constructor();
665
+
666
+ if (Class) _set_prototype_of(instance, Class.prototype);
667
+
668
+ return instance;
669
+ };
670
+ }
671
+
672
+ return _construct.apply(null, arguments);
673
+ }
674
+
642
675
  function _object_without_properties_loose(source, excluded) {
643
676
  if (source == null) return {};
644
677
 
@@ -655,6 +688,45 @@ function _object_without_properties_loose(source, excluded) {
655
688
  return target;
656
689
  }
657
690
 
691
+ function _array_like_to_array(arr, len) {
692
+ if (len == null || len > arr.length) len = arr.length;
693
+
694
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
695
+
696
+ return arr2;
697
+ }
698
+
699
+ function _unsupported_iterable_to_array(o, minLen) {
700
+ if (!o) return;
701
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
702
+
703
+ var n = Object.prototype.toString.call(o).slice(8, -1);
704
+
705
+ if (n === "Object" && o.constructor) n = o.constructor.name;
706
+ if (n === "Map" || n === "Set") return Array.from(n);
707
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
708
+ }
709
+
710
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
711
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
712
+
713
+ if (it) return (it = it.call(o)).next.bind(it);
714
+ // Fallback for engines without symbol support
715
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
716
+ if (it) o = it;
717
+
718
+ var i = 0;
719
+
720
+ return function() {
721
+ if (i >= o.length) return { done: true };
722
+
723
+ return { done: false, value: o[i++] };
724
+ };
725
+ }
726
+
727
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
728
+ }
729
+
658
730
  function resolveRefItem(refs, index, owner, label) {
659
731
  if (!Number.isInteger(index) || index < 0 || index >= refs.length) {
660
732
  throw new Error(owner + ": invalid ref index " + index + " for " + label);
@@ -705,7 +777,7 @@ var ReflectionParser = /*#__PURE__*/ function() {
705
777
  var _proto = ReflectionParser.prototype;
706
778
  /**
707
779
  * Apply v2 props to a component/object instance.
708
- * Each prop value is resolved recursively (handling $ref, $type, $class, $entity, $component, $signal).
780
+ * Each prop value is resolved recursively (handling $ref, $number, $type, $class, $entity, $component, $signal).
709
781
  */ _proto.parseProps = function parseProps(instance, props) {
710
782
  var promises = [];
711
783
  if (props) {
@@ -728,15 +800,29 @@ var ReflectionParser = /*#__PURE__*/ function() {
728
800
  var _loop = function(i, n) {
729
801
  var call = calls[i];
730
802
  chain = chain.then(function() {
731
- var method = instance == null ? void 0 : instance[call.method];
803
+ var target = instance;
804
+ if (call.target !== undefined) {
805
+ if (!Array.isArray(call.target) || call.target.some(function(key) {
806
+ return typeof key !== "string" || key.length === 0;
807
+ })) {
808
+ return Promise.reject(new Error('Call "' + call.method + '" target must be an array of non-empty strings'));
809
+ }
810
+ for(var _iterator = _create_for_of_iterator_helper_loose(call.target), _step; !(_step = _iterator()).done;){
811
+ var key = _step.value;
812
+ target = target == null ? void 0 : target[key];
813
+ }
814
+ }
815
+ var method = target == null ? void 0 : target[call.method];
732
816
  if (typeof method !== "function") {
733
- return Promise.reject(new Error('Call target does not have method "' + call.method + '"'));
817
+ var _call_target;
818
+ var path = ((_call_target = call.target) == null ? void 0 : _call_target.length) ? "" + call.target.join(".") + "." : "";
819
+ return Promise.reject(new Error('Call target does not have method "' + path + call.method + '"'));
734
820
  }
735
821
  var _call_args;
736
822
  return Promise.all(((_call_args = call.args) != null ? _call_args : []).map(function(arg) {
737
823
  return _this._resolveValue(arg);
738
824
  })).then(function(resolvedArgs) {
739
- return Promise.resolve(method.apply(instance, resolvedArgs));
825
+ return Promise.resolve(method.apply(target, resolvedArgs));
740
826
  }).then(function(result) {
741
827
  if (!call.result) return result;
742
828
  if (result == null || (typeof result === "undefined" ? "undefined" : _type_of(result)) !== "object" && typeof result !== "function") {
@@ -755,13 +841,13 @@ var ReflectionParser = /*#__PURE__*/ function() {
755
841
  });
756
842
  };
757
843
  /**
758
- * Apply props and calls from the same mutation block without imposing ordering between them.
844
+ * Apply props before executing calls from the same mutation block.
759
845
  */ _proto.parseMutationBlock = function parseMutationBlock(target, block) {
846
+ var _this = this;
760
847
  if (!block) return Promise.resolve(target);
761
- return Promise.all([
762
- this.parseProps(target, block.props),
763
- this.parseCalls(target, block.calls)
764
- ]).then(function() {
848
+ return this.parseProps(target, block.props).then(function() {
849
+ return _this.parseCalls(target, block.calls);
850
+ }).then(function() {
765
851
  return target;
766
852
  });
767
853
  };
@@ -772,12 +858,13 @@ var ReflectionParser = /*#__PURE__*/ function() {
772
858
  * 1. null/undefined/primitive → passthrough
773
859
  * 2. Array → recurse each element
774
860
  * 3. { $ref } → asset reference
775
- * 4. { $type } polymorphic type construct
776
- * 5. { $class } registered class constructor
777
- * 6. { $entity } entity reference by path (flat index + optional children descent)
778
- * 7. { $component } component reference
779
- * 8. { $signal } signal binding
780
- * 9. plain object recurse values (modify originValue in place if exists)
861
+ * 4. { $number } JSON-safe special number
862
+ * 5. { $type, $args? } polymorphic type construct
863
+ * 6. { $class } registered class constructor
864
+ * 7. { $entity } entity reference by path (flat index + optional children descent)
865
+ * 8. { $component } component reference
866
+ * 9. { $signal } signal binding
867
+ * 10. plain object → recurse values (modify originValue in place if exists)
781
868
  */ _proto._resolveValue = function _resolveValue(value, originValue) {
782
869
  var _this, _loop = function(key) {
783
870
  promises.push(_this._resolveValue(obj[key], target[key]).then(function(v) {
@@ -790,6 +877,9 @@ var ReflectionParser = /*#__PURE__*/ function() {
790
877
  return _this1._resolveValue(v);
791
878
  }));
792
879
  var obj = value;
880
+ if ("$args" in obj && !("$type" in obj)) {
881
+ return Promise.reject(new Error("$args requires $type"));
882
+ }
793
883
  // $ref — asset reference (index into refs array)
794
884
  if ("$ref" in obj) {
795
885
  var _this2 = this, context = _this2._context;
@@ -808,14 +898,29 @@ var ReflectionParser = /*#__PURE__*/ function() {
808
898
  return resource;
809
899
  });
810
900
  }
811
- // $type polymorphic type: construct instance and apply remaining props
901
+ if ("$number" in obj) {
902
+ if (Object.keys(obj).length !== 1 || obj.$number !== "Infinity") {
903
+ return Promise.reject(new Error('$number must be exactly "Infinity"'));
904
+ }
905
+ return Promise.resolve(Infinity);
906
+ }
907
+ // $type — polymorphic type: resolve constructor args, construct instance, then apply remaining props
812
908
  if ("$type" in obj) {
813
- var $type = obj.$type, rest = _object_without_properties_loose(obj, [
814
- "$type"
909
+ var $type = obj.$type, $args = obj.$args, rest = _object_without_properties_loose(obj, [
910
+ "$type",
911
+ "$args"
815
912
  ]);
913
+ if ($args !== undefined && !Array.isArray($args)) {
914
+ return Promise.reject(new Error("$args must be an array when used with $type"));
915
+ }
916
+ var constructorArgs = Array.isArray($args) ? $args : [];
816
917
  return this._resolveRegisteredClass($type, "$type").then(function(Class) {
817
- var instance = new Class();
818
- return Object.keys(rest).length > 0 ? _this1.parseProps(instance, rest) : instance;
918
+ return Promise.all(constructorArgs.map(function(arg) {
919
+ return _this1._resolveValue(arg);
920
+ })).then(function(args) {
921
+ var instance = _construct(Class, [].concat(args));
922
+ return Object.keys(rest).length > 0 ? _this1.parseProps(instance, rest) : instance;
923
+ });
819
924
  });
820
925
  }
821
926
  // $class — registered class constructor for factory-style methods.
@@ -3041,45 +3146,6 @@ function getMeshoptDecoder() {
3041
3146
  return GLTFResource;
3042
3147
  }(ReferResource);
3043
3148
 
3044
- function _array_like_to_array(arr, len) {
3045
- if (len == null || len > arr.length) len = arr.length;
3046
-
3047
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
3048
-
3049
- return arr2;
3050
- }
3051
-
3052
- function _unsupported_iterable_to_array(o, minLen) {
3053
- if (!o) return;
3054
- if (typeof o === "string") return _array_like_to_array(o, minLen);
3055
-
3056
- var n = Object.prototype.toString.call(o).slice(8, -1);
3057
-
3058
- if (n === "Object" && o.constructor) n = o.constructor.name;
3059
- if (n === "Map" || n === "Set") return Array.from(n);
3060
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
3061
- }
3062
-
3063
- function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
3064
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
3065
-
3066
- if (it) return (it = it.call(o)).next.bind(it);
3067
- // Fallback for engines without symbol support
3068
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
3069
- if (it) o = it;
3070
-
3071
- var i = 0;
3072
-
3073
- return function() {
3074
- if (i >= o.length) return { done: true };
3075
-
3076
- return { done: false, value: o[i++] };
3077
- };
3078
- }
3079
-
3080
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3081
- }
3082
-
3083
3149
  /**
3084
3150
  * Module for glTF 2.0 Interface
3085
3151
  */ /**
@@ -5885,8 +5951,7 @@ var ProjectLoader = /*#__PURE__*/ function(Loader) {
5885
5951
  ._request(item.url, _extends({}, item, {
5886
5952
  type: "json"
5887
5953
  })).then(function(data) {
5888
- // @ts-ignore
5889
- engine.resourceManager.initVirtualResources(data.files);
5954
+ engine.resourceManager.registerVirtualResources(data.files);
5890
5955
  return resourceManager.load({
5891
5956
  type: AssetType.Scene,
5892
5957
  url: data.scene
@@ -6284,8 +6349,7 @@ var AudioLoader = /*#__PURE__*/ function(Loader) {
6284
6349
  resourceManager// @ts-ignore
6285
6350
  ._request(url, requestConfig).then(function(arrayBuffer) {
6286
6351
  var audioClip = new AudioClip(resourceManager.engine);
6287
- // @ts-ignore
6288
- AudioManager.getContext().decodeAudioData(arrayBuffer).then(function(result) {
6352
+ AudioLoader._getDecodeContext().decodeAudioData(arrayBuffer).then(function(result) {
6289
6353
  // @ts-ignore
6290
6354
  audioClip._setAudioSource(result);
6291
6355
  if (url.indexOf("data:") !== 0) {
@@ -6301,6 +6365,12 @@ var AudioLoader = /*#__PURE__*/ function(Loader) {
6301
6365
  });
6302
6366
  });
6303
6367
  };
6368
+ AudioLoader._getDecodeContext = function _getDecodeContext() {
6369
+ var _AudioLoader;
6370
+ // length/channels are decode-only placeholders; 44100 is the safest cross-browser rate.
6371
+ // decodeAudioData resamples once to this rate then again to the playback rate, so pitch/duration are unaffected
6372
+ return (_AudioLoader = AudioLoader)._decodeContext || (_AudioLoader._decodeContext = new OfflineAudioContext(1, 1, 44100));
6373
+ };
6304
6374
  return AudioLoader;
6305
6375
  }(Loader);
6306
6376
  AudioLoader = __decorate([