@galacean/engine-loader 0.0.0-experimental-2.0-migrate.5 → 0.0.0-experimental-2.0-migrate.6
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 +167 -110
- package/dist/main.js.map +1 -1
- package/dist/module.js +167 -110
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +9 -8
- package/types/schema/CommonSchema.d.ts +12 -0
- package/types/schema/ProjectSchema.d.ts +3 -6
package/dist/module.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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(
|
|
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
|
|
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
|
|
762
|
-
|
|
763
|
-
|
|
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. { $
|
|
776
|
-
* 5. { $
|
|
777
|
-
* 6. { $
|
|
778
|
-
* 7. { $
|
|
779
|
-
* 8. { $
|
|
780
|
-
* 9.
|
|
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
|
-
|
|
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
|
-
|
|
818
|
-
|
|
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.
|
|
@@ -1297,45 +1402,6 @@ function _instanceof(left, right) {
|
|
|
1297
1402
|
return GLTFResource;
|
|
1298
1403
|
}(ReferResource);
|
|
1299
1404
|
|
|
1300
|
-
function _array_like_to_array(arr, len) {
|
|
1301
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
1302
|
-
|
|
1303
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
1304
|
-
|
|
1305
|
-
return arr2;
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
1309
|
-
if (!o) return;
|
|
1310
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
1311
|
-
|
|
1312
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1313
|
-
|
|
1314
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1315
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1316
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
1320
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
1321
|
-
|
|
1322
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
1323
|
-
// Fallback for engines without symbol support
|
|
1324
|
-
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
1325
|
-
if (it) o = it;
|
|
1326
|
-
|
|
1327
|
-
var i = 0;
|
|
1328
|
-
|
|
1329
|
-
return function() {
|
|
1330
|
-
if (i >= o.length) return { done: true };
|
|
1331
|
-
|
|
1332
|
-
return { done: false, value: o[i++] };
|
|
1333
|
-
};
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
1405
|
var DFDTransferFunction = /*#__PURE__*/ function(DFDTransferFunction) {
|
|
1340
1406
|
DFDTransferFunction[DFDTransferFunction["linear"] = 1] = "linear";
|
|
1341
1407
|
DFDTransferFunction[DFDTransferFunction["sRGB"] = 2] = "sRGB";
|
|
@@ -6457,8 +6523,7 @@ var ProjectLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6457
6523
|
._request(item.url, _extends({}, item, {
|
|
6458
6524
|
type: "json"
|
|
6459
6525
|
})).then(function(data) {
|
|
6460
|
-
|
|
6461
|
-
engine.resourceManager.initVirtualResources(data.files);
|
|
6526
|
+
engine.resourceManager.registerVirtualResources(data.files);
|
|
6462
6527
|
return resourceManager.load({
|
|
6463
6528
|
type: AssetType.Scene,
|
|
6464
6529
|
url: data.scene
|
|
@@ -6747,29 +6812,17 @@ var TextureLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6747
6812
|
};
|
|
6748
6813
|
_proto._decodeImage = function _decodeImage(buffer, item, resourceManager) {
|
|
6749
6814
|
var _this = this;
|
|
6750
|
-
return
|
|
6751
|
-
var
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
var img =
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
var generateMipmap = TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
|
|
6762
|
-
var texture = new Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
|
|
6763
|
-
texture.setImageSource(img);
|
|
6764
|
-
generateMipmap && texture.generateMipmaps();
|
|
6765
|
-
_this._applyParams(texture, item);
|
|
6766
|
-
resolve(texture);
|
|
6767
|
-
};
|
|
6768
|
-
img.onerror = function(e) {
|
|
6769
|
-
URL.revokeObjectURL(img.src);
|
|
6770
|
-
reject(e);
|
|
6771
|
-
};
|
|
6772
|
-
img.src = URL.createObjectURL(blob);
|
|
6815
|
+
return decodeImage(buffer, item.url).then(function(img) {
|
|
6816
|
+
var _item_params;
|
|
6817
|
+
var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? 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;
|
|
6818
|
+
var engine = resourceManager.engine;
|
|
6819
|
+
var width = img.width, height = img.height;
|
|
6820
|
+
var generateMipmap = TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
|
|
6821
|
+
var texture = new Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
|
|
6822
|
+
texture.setImageSource(img);
|
|
6823
|
+
generateMipmap && texture.generateMipmaps();
|
|
6824
|
+
_this._applyParams(texture, item);
|
|
6825
|
+
return texture;
|
|
6773
6826
|
});
|
|
6774
6827
|
};
|
|
6775
6828
|
_proto._applyParams = function _applyParams(texture, item) {
|
|
@@ -6819,27 +6872,35 @@ var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
|
6819
6872
|
texture.mipmapCount > 1 && texture.generateMipmaps();
|
|
6820
6873
|
return texture;
|
|
6821
6874
|
}
|
|
6822
|
-
return
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
var img = new Image();
|
|
6827
|
-
img.onload = function() {
|
|
6828
|
-
URL.revokeObjectURL(img.src);
|
|
6829
|
-
texture.setImageSource(img);
|
|
6830
|
-
texture.mipmapCount > 1 && texture.generateMipmaps();
|
|
6831
|
-
resolve(texture);
|
|
6832
|
-
};
|
|
6833
|
-
img.onerror = function(e) {
|
|
6834
|
-
URL.revokeObjectURL(img.src);
|
|
6835
|
-
reject(e);
|
|
6836
|
-
};
|
|
6837
|
-
img.src = URL.createObjectURL(blob);
|
|
6875
|
+
return decodeImage(buffer, _this.url).then(function(img) {
|
|
6876
|
+
texture.setImageSource(img);
|
|
6877
|
+
texture.mipmapCount > 1 && texture.generateMipmaps();
|
|
6878
|
+
return texture;
|
|
6838
6879
|
});
|
|
6839
6880
|
});
|
|
6840
6881
|
};
|
|
6841
6882
|
return TextureContentRestorer;
|
|
6842
6883
|
}(ContentRestorer);
|
|
6884
|
+
function decodeImage(buffer, url) {
|
|
6885
|
+
return new AssetPromise(function(resolve, reject) {
|
|
6886
|
+
var objectUrl = URL.createObjectURL(new Blob([
|
|
6887
|
+
buffer
|
|
6888
|
+
]));
|
|
6889
|
+
var image = new Image();
|
|
6890
|
+
var releaseObjectUrl = function() {
|
|
6891
|
+
return URL.revokeObjectURL(objectUrl);
|
|
6892
|
+
};
|
|
6893
|
+
image.onload = function() {
|
|
6894
|
+
releaseObjectUrl();
|
|
6895
|
+
resolve(image);
|
|
6896
|
+
};
|
|
6897
|
+
image.onerror = function() {
|
|
6898
|
+
releaseObjectUrl();
|
|
6899
|
+
reject(new Error('TextureLoader: failed to decode texture "' + url + '" (' + buffer.byteLength + " bytes)."));
|
|
6900
|
+
};
|
|
6901
|
+
image.src = objectUrl;
|
|
6902
|
+
});
|
|
6903
|
+
}
|
|
6843
6904
|
|
|
6844
6905
|
var AudioLoader = /*#__PURE__*/ function(Loader) {
|
|
6845
6906
|
_inherits(AudioLoader, Loader);
|
|
@@ -6899,19 +6960,15 @@ var ShaderLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6899
6960
|
var _proto = ShaderLoader.prototype;
|
|
6900
6961
|
_proto.load = function load(item, resourceManager) {
|
|
6901
6962
|
var url = item.url;
|
|
6902
|
-
|
|
6903
|
-
// @ts-ignore
|
|
6904
|
-
return resourceManager._request(url, _extends({}, item, {
|
|
6905
|
-
type: "json"
|
|
6906
|
-
})).then(function(data) {
|
|
6907
|
-
// @ts-ignore - _createFromPrecompiled is @internal
|
|
6908
|
-
return Shader._createFromPrecompiled(data);
|
|
6909
|
-
});
|
|
6910
|
-
}
|
|
6911
|
-
// @ts-ignore
|
|
6963
|
+
// @ts-expect-error _request is @internal
|
|
6912
6964
|
return resourceManager._request(url, _extends({}, item, {
|
|
6913
6965
|
type: "text"
|
|
6914
6966
|
})).then(function(code) {
|
|
6967
|
+
var source = code.trimStart();
|
|
6968
|
+
if (source.startsWith("{")) {
|
|
6969
|
+
// @ts-expect-error _createFromPrecompiled is @internal
|
|
6970
|
+
return Shader._createFromPrecompiled(JSON.parse(source));
|
|
6971
|
+
}
|
|
6915
6972
|
return Shader.create(code, undefined, url);
|
|
6916
6973
|
});
|
|
6917
6974
|
};
|