@galacean/engine-loader 2.0.0-alpha.38 → 2.0.0-alpha.40
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 +132 -71
- package/dist/main.js.map +1 -1
- package/dist/module.js +132 -71
- 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/main.js
CHANGED
|
@@ -643,6 +643,39 @@ function float32ArrayToVector2(float32Array, vertexCount) {
|
|
|
643
643
|
return array;
|
|
644
644
|
}
|
|
645
645
|
|
|
646
|
+
function _is_native_reflect_construct() {
|
|
647
|
+
// Since Reflect.construct can't be properly polyfilled, some
|
|
648
|
+
// implementations (e.g. core-js@2) don't set the correct internal slots.
|
|
649
|
+
// Those polyfills don't allow us to subclass built-ins, so we need to
|
|
650
|
+
// use our fallback implementation.
|
|
651
|
+
try {
|
|
652
|
+
// If the internal slots aren't set, this throws an error similar to
|
|
653
|
+
// TypeError: this is not a Boolean object.
|
|
654
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
655
|
+
} catch (_) {}
|
|
656
|
+
return (_is_native_reflect_construct = function() {
|
|
657
|
+
return !!result;
|
|
658
|
+
})();
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
function _construct(Parent, args, Class) {
|
|
662
|
+
if (_is_native_reflect_construct()) _construct = Reflect.construct;
|
|
663
|
+
else {
|
|
664
|
+
_construct = function construct(Parent, args, Class) {
|
|
665
|
+
var a = [null];
|
|
666
|
+
a.push.apply(a, args);
|
|
667
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
668
|
+
var instance = new Constructor();
|
|
669
|
+
|
|
670
|
+
if (Class) _set_prototype_of(instance, Class.prototype);
|
|
671
|
+
|
|
672
|
+
return instance;
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
return _construct.apply(null, arguments);
|
|
677
|
+
}
|
|
678
|
+
|
|
646
679
|
function _object_without_properties_loose(source, excluded) {
|
|
647
680
|
if (source == null) return {};
|
|
648
681
|
|
|
@@ -659,6 +692,45 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
659
692
|
return target;
|
|
660
693
|
}
|
|
661
694
|
|
|
695
|
+
function _array_like_to_array(arr, len) {
|
|
696
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
697
|
+
|
|
698
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
699
|
+
|
|
700
|
+
return arr2;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
704
|
+
if (!o) return;
|
|
705
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
706
|
+
|
|
707
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
708
|
+
|
|
709
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
710
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
711
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
715
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
716
|
+
|
|
717
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
718
|
+
// Fallback for engines without symbol support
|
|
719
|
+
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
720
|
+
if (it) o = it;
|
|
721
|
+
|
|
722
|
+
var i = 0;
|
|
723
|
+
|
|
724
|
+
return function() {
|
|
725
|
+
if (i >= o.length) return { done: true };
|
|
726
|
+
|
|
727
|
+
return { done: false, value: o[i++] };
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
732
|
+
}
|
|
733
|
+
|
|
662
734
|
function resolveRefItem(refs, index, owner, label) {
|
|
663
735
|
if (!Number.isInteger(index) || index < 0 || index >= refs.length) {
|
|
664
736
|
throw new Error(owner + ": invalid ref index " + index + " for " + label);
|
|
@@ -709,7 +781,7 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
709
781
|
var _proto = ReflectionParser.prototype;
|
|
710
782
|
/**
|
|
711
783
|
* Apply v2 props to a component/object instance.
|
|
712
|
-
* Each prop value is resolved recursively (handling $ref, $type, $class, $entity, $component, $signal).
|
|
784
|
+
* Each prop value is resolved recursively (handling $ref, $number, $type, $class, $entity, $component, $signal).
|
|
713
785
|
*/ _proto.parseProps = function parseProps(instance, props) {
|
|
714
786
|
var promises = [];
|
|
715
787
|
if (props) {
|
|
@@ -732,15 +804,29 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
732
804
|
var _loop = function(i, n) {
|
|
733
805
|
var call = calls[i];
|
|
734
806
|
chain = chain.then(function() {
|
|
735
|
-
var
|
|
807
|
+
var target = instance;
|
|
808
|
+
if (call.target !== undefined) {
|
|
809
|
+
if (!Array.isArray(call.target) || call.target.some(function(key) {
|
|
810
|
+
return typeof key !== "string" || key.length === 0;
|
|
811
|
+
})) {
|
|
812
|
+
return Promise.reject(new Error('Call "' + call.method + '" target must be an array of non-empty strings'));
|
|
813
|
+
}
|
|
814
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(call.target), _step; !(_step = _iterator()).done;){
|
|
815
|
+
var key = _step.value;
|
|
816
|
+
target = target == null ? void 0 : target[key];
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
var method = target == null ? void 0 : target[call.method];
|
|
736
820
|
if (typeof method !== "function") {
|
|
737
|
-
|
|
821
|
+
var _call_target;
|
|
822
|
+
var path = ((_call_target = call.target) == null ? void 0 : _call_target.length) ? "" + call.target.join(".") + "." : "";
|
|
823
|
+
return Promise.reject(new Error('Call target does not have method "' + path + call.method + '"'));
|
|
738
824
|
}
|
|
739
825
|
var _call_args;
|
|
740
826
|
return Promise.all(((_call_args = call.args) != null ? _call_args : []).map(function(arg) {
|
|
741
827
|
return _this._resolveValue(arg);
|
|
742
828
|
})).then(function(resolvedArgs) {
|
|
743
|
-
return Promise.resolve(method.apply(
|
|
829
|
+
return Promise.resolve(method.apply(target, resolvedArgs));
|
|
744
830
|
}).then(function(result) {
|
|
745
831
|
if (!call.result) return result;
|
|
746
832
|
if (result == null || (typeof result === "undefined" ? "undefined" : _type_of(result)) !== "object" && typeof result !== "function") {
|
|
@@ -759,13 +845,13 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
759
845
|
});
|
|
760
846
|
};
|
|
761
847
|
/**
|
|
762
|
-
* Apply props
|
|
848
|
+
* Apply props before executing calls from the same mutation block.
|
|
763
849
|
*/ _proto.parseMutationBlock = function parseMutationBlock(target, block) {
|
|
850
|
+
var _this = this;
|
|
764
851
|
if (!block) return Promise.resolve(target);
|
|
765
|
-
return
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
]).then(function() {
|
|
852
|
+
return this.parseProps(target, block.props).then(function() {
|
|
853
|
+
return _this.parseCalls(target, block.calls);
|
|
854
|
+
}).then(function() {
|
|
769
855
|
return target;
|
|
770
856
|
});
|
|
771
857
|
};
|
|
@@ -776,12 +862,13 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
776
862
|
* 1. null/undefined/primitive → passthrough
|
|
777
863
|
* 2. Array → recurse each element
|
|
778
864
|
* 3. { $ref } → asset reference
|
|
779
|
-
* 4. { $
|
|
780
|
-
* 5. { $
|
|
781
|
-
* 6. { $
|
|
782
|
-
* 7. { $
|
|
783
|
-
* 8. { $
|
|
784
|
-
* 9.
|
|
865
|
+
* 4. { $number } → JSON-safe special number
|
|
866
|
+
* 5. { $type, $args? } → polymorphic type construct
|
|
867
|
+
* 6. { $class } → registered class constructor
|
|
868
|
+
* 7. { $entity } → entity reference by path (flat index + optional children descent)
|
|
869
|
+
* 8. { $component } → component reference
|
|
870
|
+
* 9. { $signal } → signal binding
|
|
871
|
+
* 10. plain object → recurse values (modify originValue in place if exists)
|
|
785
872
|
*/ _proto._resolveValue = function _resolveValue(value, originValue) {
|
|
786
873
|
var _this, _loop = function(key) {
|
|
787
874
|
promises.push(_this._resolveValue(obj[key], target[key]).then(function(v) {
|
|
@@ -794,6 +881,9 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
794
881
|
return _this1._resolveValue(v);
|
|
795
882
|
}));
|
|
796
883
|
var obj = value;
|
|
884
|
+
if ("$args" in obj && !("$type" in obj)) {
|
|
885
|
+
return Promise.reject(new Error("$args requires $type"));
|
|
886
|
+
}
|
|
797
887
|
// $ref — asset reference (index into refs array)
|
|
798
888
|
if ("$ref" in obj) {
|
|
799
889
|
var _this2 = this, context = _this2._context;
|
|
@@ -812,14 +902,29 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
812
902
|
return resource;
|
|
813
903
|
});
|
|
814
904
|
}
|
|
815
|
-
|
|
905
|
+
if ("$number" in obj) {
|
|
906
|
+
if (Object.keys(obj).length !== 1 || obj.$number !== "Infinity") {
|
|
907
|
+
return Promise.reject(new Error('$number must be exactly "Infinity"'));
|
|
908
|
+
}
|
|
909
|
+
return Promise.resolve(Infinity);
|
|
910
|
+
}
|
|
911
|
+
// $type — polymorphic type: resolve constructor args, construct instance, then apply remaining props
|
|
816
912
|
if ("$type" in obj) {
|
|
817
|
-
var $type = obj.$type, rest = _object_without_properties_loose(obj, [
|
|
818
|
-
"$type"
|
|
913
|
+
var $type = obj.$type, $args = obj.$args, rest = _object_without_properties_loose(obj, [
|
|
914
|
+
"$type",
|
|
915
|
+
"$args"
|
|
819
916
|
]);
|
|
917
|
+
if ($args !== undefined && !Array.isArray($args)) {
|
|
918
|
+
return Promise.reject(new Error("$args must be an array when used with $type"));
|
|
919
|
+
}
|
|
920
|
+
var constructorArgs = Array.isArray($args) ? $args : [];
|
|
820
921
|
return this._resolveRegisteredClass($type, "$type").then(function(Class) {
|
|
821
|
-
|
|
822
|
-
|
|
922
|
+
return Promise.all(constructorArgs.map(function(arg) {
|
|
923
|
+
return _this1._resolveValue(arg);
|
|
924
|
+
})).then(function(args) {
|
|
925
|
+
var instance = _construct(Class, [].concat(args));
|
|
926
|
+
return Object.keys(rest).length > 0 ? _this1.parseProps(instance, rest) : instance;
|
|
927
|
+
});
|
|
823
928
|
});
|
|
824
929
|
}
|
|
825
930
|
// $class — registered class constructor for factory-style methods.
|
|
@@ -3045,45 +3150,6 @@ function getMeshoptDecoder() {
|
|
|
3045
3150
|
return GLTFResource;
|
|
3046
3151
|
}(engineCore.ReferResource);
|
|
3047
3152
|
|
|
3048
|
-
function _array_like_to_array(arr, len) {
|
|
3049
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
3050
|
-
|
|
3051
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
3052
|
-
|
|
3053
|
-
return arr2;
|
|
3054
|
-
}
|
|
3055
|
-
|
|
3056
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
3057
|
-
if (!o) return;
|
|
3058
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
3059
|
-
|
|
3060
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
3061
|
-
|
|
3062
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
3063
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
3064
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
3065
|
-
}
|
|
3066
|
-
|
|
3067
|
-
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
3068
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
3069
|
-
|
|
3070
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
3071
|
-
// Fallback for engines without symbol support
|
|
3072
|
-
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
3073
|
-
if (it) o = it;
|
|
3074
|
-
|
|
3075
|
-
var i = 0;
|
|
3076
|
-
|
|
3077
|
-
return function() {
|
|
3078
|
-
if (i >= o.length) return { done: true };
|
|
3079
|
-
|
|
3080
|
-
return { done: false, value: o[i++] };
|
|
3081
|
-
};
|
|
3082
|
-
}
|
|
3083
|
-
|
|
3084
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
3085
|
-
}
|
|
3086
|
-
|
|
3087
3153
|
/**
|
|
3088
3154
|
* Module for glTF 2.0 Interface
|
|
3089
3155
|
*/ /**
|
|
@@ -5889,8 +5955,7 @@ var ProjectLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5889
5955
|
._request(item.url, _extends({}, item, {
|
|
5890
5956
|
type: "json"
|
|
5891
5957
|
})).then(function(data) {
|
|
5892
|
-
|
|
5893
|
-
engine.resourceManager.initVirtualResources(data.files);
|
|
5958
|
+
engine.resourceManager.registerVirtualResources(data.files);
|
|
5894
5959
|
return resourceManager.load({
|
|
5895
5960
|
type: engineCore.AssetType.Scene,
|
|
5896
5961
|
url: data.scene
|
|
@@ -6331,19 +6396,15 @@ var ShaderLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6331
6396
|
var _proto = ShaderLoader.prototype;
|
|
6332
6397
|
_proto.load = function load(item, resourceManager) {
|
|
6333
6398
|
var url = item.url;
|
|
6334
|
-
|
|
6335
|
-
// @ts-ignore
|
|
6336
|
-
return resourceManager._request(url, _extends({}, item, {
|
|
6337
|
-
type: "json"
|
|
6338
|
-
})).then(function(data) {
|
|
6339
|
-
// @ts-ignore - _createFromPrecompiled is @internal
|
|
6340
|
-
return engineCore.Shader._createFromPrecompiled(data);
|
|
6341
|
-
});
|
|
6342
|
-
}
|
|
6343
|
-
// @ts-ignore
|
|
6399
|
+
// @ts-expect-error _request is @internal
|
|
6344
6400
|
return resourceManager._request(url, _extends({}, item, {
|
|
6345
6401
|
type: "text"
|
|
6346
6402
|
})).then(function(code) {
|
|
6403
|
+
var source = code.trimStart();
|
|
6404
|
+
if (source.startsWith("{")) {
|
|
6405
|
+
// @ts-expect-error _createFromPrecompiled is @internal
|
|
6406
|
+
return engineCore.Shader._createFromPrecompiled(JSON.parse(source));
|
|
6407
|
+
}
|
|
6347
6408
|
return engineCore.Shader.create(code, undefined, url);
|
|
6348
6409
|
});
|
|
6349
6410
|
};
|