@galacean/engine-loader 2.0.0-alpha.29 → 2.0.0-alpha.30
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 +596 -747
- package/dist/main.js.map +1 -1
- package/dist/module.js +597 -748
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/SceneLoader.d.ts +8 -1
- package/types/gltf/extensions/GLTFExtensionSchema.d.ts +2 -3
- package/types/index.d.ts +1 -1
- package/types/prefab/PrefabParser.d.ts +9 -6
- package/types/resource-deserialize/index.d.ts +1 -1
- package/types/resource-deserialize/resources/parser/HierarchyParser.d.ts +22 -27
- package/types/resource-deserialize/resources/parser/ParserContext.d.ts +11 -11
- package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +37 -18
- package/types/resource-deserialize/resources/scene/SceneParser.d.ts +6 -7
- package/types/schema/BasicSchema.d.ts +21 -0
- package/types/schema/CommonSchema.d.ts +29 -0
- package/types/schema/HierarchySchema.d.ts +71 -0
- package/types/schema/MaterialSchema.d.ts +70 -0
- package/types/schema/PrefabSchema.d.ts +4 -0
- package/types/schema/SceneSchema.d.ts +59 -0
- package/types/{resource-deserialize/resources/schema → schema}/index.d.ts +4 -1
- package/types/schema/refs.d.ts +2 -0
- package/types/resource-deserialize/resources/schema/BasicSchema.d.ts +0 -105
- package/types/resource-deserialize/resources/schema/MaterialSchema.d.ts +0 -102
- package/types/resource-deserialize/resources/schema/SceneSchema.d.ts +0 -80
- /package/types/{resource-deserialize/resources/schema → schema}/ProjectSchema.d.ts +0 -0
package/dist/main.js
CHANGED
|
@@ -643,37 +643,27 @@ function float32ArrayToVector2(float32Array, vertexCount) {
|
|
|
643
643
|
return array;
|
|
644
644
|
}
|
|
645
645
|
|
|
646
|
-
function
|
|
647
|
-
|
|
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();
|
|
646
|
+
function _object_without_properties_loose(source, excluded) {
|
|
647
|
+
if (source == null) return {};
|
|
669
648
|
|
|
670
|
-
|
|
649
|
+
var target = {};
|
|
650
|
+
var sourceKeys = Object.keys(source);
|
|
651
|
+
var key, i;
|
|
671
652
|
|
|
672
|
-
|
|
673
|
-
|
|
653
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
654
|
+
key = sourceKeys[i];
|
|
655
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
656
|
+
target[key] = source[key];
|
|
674
657
|
}
|
|
675
658
|
|
|
676
|
-
return
|
|
659
|
+
return target;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function resolveRefItem(refs, index, owner, label) {
|
|
663
|
+
if (!Number.isInteger(index) || index < 0 || index >= refs.length) {
|
|
664
|
+
throw new Error(owner + ": invalid ref index " + index + " for " + label);
|
|
665
|
+
}
|
|
666
|
+
return refs[index];
|
|
677
667
|
}
|
|
678
668
|
|
|
679
669
|
var ParserType = /*#__PURE__*/ function(ParserType) {
|
|
@@ -689,32 +679,20 @@ var ParserType = /*#__PURE__*/ function(ParserType) {
|
|
|
689
679
|
this.engine = engine;
|
|
690
680
|
this.type = type;
|
|
691
681
|
this.resource = resource;
|
|
692
|
-
this.
|
|
693
|
-
this
|
|
694
|
-
this.components = new Map();
|
|
695
|
-
this.componentConfigMap = new Map();
|
|
696
|
-
this.rootIds = [];
|
|
697
|
-
this.strippedIds = [];
|
|
698
|
-
this._tasks = new Set();
|
|
682
|
+
this./** Runtime Entity instances, indexed by the flat entities[] position. */ entityInstances = [];
|
|
683
|
+
this./** Components waiting for props/calls application (Stage 4). */ pendingComponents = [];
|
|
699
684
|
this._loaded = 0;
|
|
700
685
|
this._total = 0;
|
|
701
686
|
this.resourceManager = engine.resourceManager;
|
|
702
687
|
}
|
|
703
688
|
var _proto = ParserContext.prototype;
|
|
704
689
|
_proto.clear = function clear() {
|
|
705
|
-
this.
|
|
706
|
-
this.
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
this.rootIds.length = 0;
|
|
710
|
-
this.strippedIds.length = 0;
|
|
711
|
-
};
|
|
712
|
-
/** @internal */ _proto._addDependentAsset = function _addDependentAsset(url, promise) {
|
|
690
|
+
this.entityInstances.length = 0;
|
|
691
|
+
this.pendingComponents.length = 0;
|
|
692
|
+
};
|
|
693
|
+
/** @internal */ _proto._addDependentAsset = function _addDependentAsset(promise) {
|
|
713
694
|
var _this = this;
|
|
714
|
-
var tasks = this._tasks;
|
|
715
|
-
if (tasks.has(url)) return;
|
|
716
695
|
++this._total;
|
|
717
|
-
tasks.add(url);
|
|
718
696
|
promise.finally(function() {
|
|
719
697
|
++_this._loaded;
|
|
720
698
|
_this._setTaskCompleteProgress(_this._loaded, _this._total);
|
|
@@ -724,230 +702,198 @@ var ParserType = /*#__PURE__*/ function(ParserType) {
|
|
|
724
702
|
}();
|
|
725
703
|
|
|
726
704
|
var ReflectionParser = /*#__PURE__*/ function() {
|
|
727
|
-
function ReflectionParser(_context) {
|
|
705
|
+
function ReflectionParser(_context, _refs) {
|
|
728
706
|
this._context = _context;
|
|
707
|
+
this._refs = _refs;
|
|
729
708
|
}
|
|
730
709
|
var _proto = ReflectionParser.prototype;
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : true;
|
|
736
|
-
var transform = entity.transform;
|
|
737
|
-
var transformConfig = entityConfig.transform;
|
|
738
|
-
if (transformConfig) {
|
|
739
|
-
_this.parsePropsAndMethods(transform, transformConfig);
|
|
740
|
-
} else {
|
|
741
|
-
var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale;
|
|
742
|
-
if (position) transform.position.copyFrom(position);
|
|
743
|
-
if (rotation) transform.rotation.copyFrom(rotation);
|
|
744
|
-
if (scale) transform.scale.copyFrom(scale);
|
|
745
|
-
}
|
|
746
|
-
var _entityConfig_layer;
|
|
747
|
-
entity.layer = (_entityConfig_layer = entityConfig.layer) != null ? _entityConfig_layer : entity.layer;
|
|
748
|
-
// @ts-ignore
|
|
749
|
-
_this._context.type === ParserType.Prefab && entity._markAsTemplate(_this._context.resource);
|
|
750
|
-
return entity;
|
|
751
|
-
});
|
|
752
|
-
};
|
|
753
|
-
_proto.parseClassObject = function parseClassObject(item) {
|
|
754
|
-
var _this = this;
|
|
755
|
-
var Class = engineCore.Loader.getClass(item.class);
|
|
756
|
-
var _item_constructParams;
|
|
757
|
-
var params = (_item_constructParams = item.constructParams) != null ? _item_constructParams : [];
|
|
758
|
-
return Promise.all(params.map(function(param) {
|
|
759
|
-
return _this.parseBasicType(param);
|
|
760
|
-
})).then(function(resultParams) {
|
|
761
|
-
return _construct(Class, [].concat(resultParams));
|
|
762
|
-
}).then(function(instance) {
|
|
763
|
-
return _this.parsePropsAndMethods(instance, item);
|
|
764
|
-
});
|
|
765
|
-
};
|
|
766
|
-
_proto.parsePropsAndMethods = function parsePropsAndMethods(instance, item) {
|
|
710
|
+
/**
|
|
711
|
+
* Apply v2 props to a component/object instance.
|
|
712
|
+
* Each prop value is resolved recursively (handling $ref, $type, $entity, $component, $signal).
|
|
713
|
+
*/ _proto.parseProps = function parseProps(instance, props) {
|
|
767
714
|
var promises = [];
|
|
768
|
-
if (
|
|
769
|
-
for(var methodName in item.methods){
|
|
770
|
-
var methodParams = item.methods[methodName];
|
|
771
|
-
for(var i = 0, count = methodParams.length; i < count; i++){
|
|
772
|
-
promises.push(this.parseMethod(instance, methodName, methodParams[i]));
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
if (item.props) {
|
|
715
|
+
if (props) {
|
|
777
716
|
var _this, _loop = function(key) {
|
|
778
|
-
var
|
|
779
|
-
|
|
780
|
-
return instance[key] = v;
|
|
717
|
+
var promise = _this._resolveValue(props[key], instance[key]).then(function(v) {
|
|
718
|
+
instance[key] = v;
|
|
781
719
|
});
|
|
782
720
|
promises.push(promise);
|
|
783
721
|
};
|
|
784
|
-
for(var key in
|
|
722
|
+
for(var key in props)_this = this, _loop(key);
|
|
785
723
|
}
|
|
786
724
|
return Promise.all(promises).then(function() {
|
|
787
725
|
return instance;
|
|
788
726
|
});
|
|
789
727
|
};
|
|
790
|
-
|
|
728
|
+
/**
|
|
729
|
+
* Execute calls sequentially on a target instance.
|
|
730
|
+
* Call args are resolved with the same v2 value rules as props.
|
|
731
|
+
*/ _proto.parseCalls = function parseCalls(instance, calls) {
|
|
732
|
+
var _loop = function(i, n) {
|
|
733
|
+
var call = calls[i];
|
|
734
|
+
chain = chain.then(function() {
|
|
735
|
+
var method = instance == null ? void 0 : instance[call.method];
|
|
736
|
+
if (typeof method !== "function") {
|
|
737
|
+
return Promise.reject(new Error('Call target does not have method "' + call.method + '"'));
|
|
738
|
+
}
|
|
739
|
+
var _call_args;
|
|
740
|
+
return Promise.all(((_call_args = call.args) != null ? _call_args : []).map(function(arg) {
|
|
741
|
+
return _this._resolveValue(arg);
|
|
742
|
+
})).then(function(resolvedArgs) {
|
|
743
|
+
return Promise.resolve(method.apply(instance, resolvedArgs));
|
|
744
|
+
}).then(function(result) {
|
|
745
|
+
if (!call.result) return result;
|
|
746
|
+
if (result == null || (typeof result === "undefined" ? "undefined" : _type_of(result)) !== "object" && typeof result !== "function") {
|
|
747
|
+
return Promise.reject(new Error('Call "' + call.method + '" returned ' + result + " and cannot be mutated by result"));
|
|
748
|
+
}
|
|
749
|
+
return _this.parseMutationBlock(result, call.result);
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
};
|
|
791
753
|
var _this = this;
|
|
792
|
-
|
|
793
|
-
var
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
var _instance;
|
|
798
|
-
var methodResult = (_instance = instance)[methodName].apply(_instance, [].concat(result));
|
|
799
|
-
if (isMethodObject && methodParams.result) {
|
|
800
|
-
return _this.parsePropsAndMethods(methodResult, methodParams.result);
|
|
801
|
-
} else {
|
|
802
|
-
return methodResult;
|
|
803
|
-
}
|
|
754
|
+
if (!(calls == null ? void 0 : calls.length)) return Promise.resolve(instance);
|
|
755
|
+
var chain = Promise.resolve();
|
|
756
|
+
for(var i = 0, n = calls.length; i < n; i++)_loop(i);
|
|
757
|
+
return chain.then(function() {
|
|
758
|
+
return instance;
|
|
804
759
|
});
|
|
805
760
|
};
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
return Promise.
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
]).then(function(param) {
|
|
816
|
-
var target = param[0], resolvedArgs = param[1];
|
|
817
|
-
if (target) {
|
|
818
|
-
var _signal;
|
|
819
|
-
(_signal = signal).on.apply(_signal, [].concat([
|
|
820
|
-
target,
|
|
821
|
-
listener.methodName
|
|
822
|
-
], resolvedArgs));
|
|
823
|
-
}
|
|
824
|
-
});
|
|
825
|
-
})).then(function() {
|
|
826
|
-
return signal;
|
|
761
|
+
/**
|
|
762
|
+
* Apply props and calls from the same mutation block without imposing ordering between them.
|
|
763
|
+
*/ _proto.parseMutationBlock = function parseMutationBlock(target, block) {
|
|
764
|
+
if (!block) return Promise.resolve(target);
|
|
765
|
+
return Promise.all([
|
|
766
|
+
this.parseProps(target, block.props),
|
|
767
|
+
this.parseCalls(target, block.calls)
|
|
768
|
+
]).then(function() {
|
|
769
|
+
return target;
|
|
827
770
|
});
|
|
828
771
|
};
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
772
|
+
/**
|
|
773
|
+
* Resolve a v2 value with $ prefix detection.
|
|
774
|
+
*
|
|
775
|
+
* Priority:
|
|
776
|
+
* 1. null/undefined/primitive → passthrough
|
|
777
|
+
* 2. Array → recurse each element
|
|
778
|
+
* 3. { $ref } → asset reference
|
|
779
|
+
* 4. { $type } → polymorphic type construct
|
|
780
|
+
* 5. { $entity } → entity reference by path (flat index + optional children descent)
|
|
781
|
+
* 6. { $component } → component reference
|
|
782
|
+
* 7. { $signal } → signal binding
|
|
783
|
+
* 8. plain object → recurse values (modify originValue in place if exists)
|
|
784
|
+
*/ _proto._resolveValue = function _resolveValue(value, originValue) {
|
|
785
|
+
var _this, _loop = function(key) {
|
|
786
|
+
promises.push(_this._resolveValue(obj[key], target[key]).then(function(v) {
|
|
787
|
+
return target[key] = v;
|
|
834
788
|
}));
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
return resource;
|
|
851
|
-
});
|
|
852
|
-
} else if (ReflectionParser._isComponentRef(value)) {
|
|
853
|
-
var entity = this._resolveEntityByPath(value.entityPath);
|
|
854
|
-
if (!entity) return Promise.resolve(null);
|
|
855
|
-
var type = engineCore.Loader.getClass(value.componentType);
|
|
856
|
-
if (!type) return Promise.resolve(null);
|
|
857
|
-
var _entity_getComponents_value_componentIndex;
|
|
858
|
-
return Promise.resolve((_entity_getComponents_value_componentIndex = entity.getComponents(type, [])[value.componentIndex]) != null ? _entity_getComponents_value_componentIndex : null);
|
|
859
|
-
} else if (ReflectionParser._isEntityRef(value)) {
|
|
860
|
-
return Promise.resolve(this._resolveEntityByPath(value.entityPath));
|
|
861
|
-
} else if (ReflectionParser._isSignalRef(value)) {
|
|
862
|
-
return this.parseSignal(value);
|
|
863
|
-
} else if (originValue) {
|
|
864
|
-
var _this2, _loop = function(key) {
|
|
865
|
-
if (key === "methods") {
|
|
866
|
-
var methods = value[key];
|
|
867
|
-
for(var methodName in methods){
|
|
868
|
-
var methodParams = methods[methodName];
|
|
869
|
-
for(var i = 0, count = methodParams.length; i < count; i++){
|
|
870
|
-
var params = methodParams[i];
|
|
871
|
-
var promise = _this2.parseMethod(originValue, methodName, params);
|
|
872
|
-
promises.push(promise);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
} else {
|
|
876
|
-
promises.push(_this2.parseBasicType(value[key], originValue[key]).then(function(v) {
|
|
877
|
-
return originValue[key] = v;
|
|
878
|
-
}));
|
|
879
|
-
}
|
|
880
|
-
};
|
|
881
|
-
var promises = [];
|
|
882
|
-
for(var key in value)_this2 = this, _loop(key);
|
|
883
|
-
return Promise.all(promises).then(function() {
|
|
884
|
-
return originValue;
|
|
885
|
-
});
|
|
789
|
+
};
|
|
790
|
+
var _this1 = this;
|
|
791
|
+
if (value == null || (typeof value === "undefined" ? "undefined" : _type_of(value)) !== "object") return Promise.resolve(value);
|
|
792
|
+
if (Array.isArray(value)) return Promise.all(value.map(function(v) {
|
|
793
|
+
return _this1._resolveValue(v);
|
|
794
|
+
}));
|
|
795
|
+
var obj = value;
|
|
796
|
+
// $ref — asset reference (index into refs array)
|
|
797
|
+
if ("$ref" in obj) {
|
|
798
|
+
var _this2 = this, context = _this2._context;
|
|
799
|
+
var refItem;
|
|
800
|
+
try {
|
|
801
|
+
refItem = resolveRefItem(this._refs, obj.$ref, "ReflectionParser", "$ref");
|
|
802
|
+
} catch (error) {
|
|
803
|
+
return Promise.reject(error);
|
|
886
804
|
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
};
|
|
891
|
-
_proto._getEntityByConfig = function _getEntityByConfig(entityConfig) {
|
|
892
|
-
var _this = this;
|
|
893
|
-
// @ts-ignore
|
|
894
|
-
var assetUrl = entityConfig.assetUrl;
|
|
895
|
-
var engine = this._context.engine;
|
|
896
|
-
if (assetUrl) {
|
|
897
|
-
return engine.resourceManager// @ts-ignore
|
|
898
|
-
.getResourceByRef({
|
|
899
|
-
url: assetUrl,
|
|
900
|
-
key: entityConfig.key,
|
|
901
|
-
isClone: entityConfig.isClone
|
|
902
|
-
}).then(function(entity) {
|
|
903
|
-
// @ts-ignore
|
|
904
|
-
var resource = engine.resourceManager._objectPool[assetUrl];
|
|
905
|
-
if (resource && _this._context.type === ParserType.Prefab) {
|
|
805
|
+
// @ts-ignore
|
|
806
|
+
return context.resourceManager.getResourceByRef(refItem).then(function(resource) {
|
|
807
|
+
if (resource && context.type === ParserType.Prefab) {
|
|
906
808
|
// @ts-ignore
|
|
907
|
-
|
|
809
|
+
context.resource._addDependenceAsset(resource);
|
|
908
810
|
}
|
|
909
|
-
|
|
910
|
-
return entity;
|
|
811
|
+
return resource;
|
|
911
812
|
});
|
|
912
|
-
} else {
|
|
913
|
-
var transform = entityConfig.transform;
|
|
914
|
-
var entity = new engineCore.Entity(engine, entityConfig.name, transform ? engineCore.Loader.getClass(transform.class) : engineCore.Transform);
|
|
915
|
-
return Promise.resolve(entity);
|
|
916
813
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
814
|
+
// $type — polymorphic type: construct instance and apply remaining props
|
|
815
|
+
if ("$type" in obj) {
|
|
816
|
+
var $type = obj.$type, rest = _object_without_properties_loose(obj, [
|
|
817
|
+
"$type"
|
|
818
|
+
]);
|
|
819
|
+
var typeName = $type;
|
|
820
|
+
var Class = engineCore.Loader.getClass(typeName);
|
|
821
|
+
if (!Class) return Promise.reject(new Error('Loader.getClass: class "' + typeName + '" is not registered'));
|
|
822
|
+
var instance = new Class();
|
|
823
|
+
if (Object.keys(rest).length > 0) {
|
|
824
|
+
return this.parseProps(instance, rest);
|
|
825
|
+
}
|
|
826
|
+
return Promise.resolve(instance);
|
|
925
827
|
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
828
|
+
// $entity — entity reference by path (first element = flat index, subsequent = children indices)
|
|
829
|
+
if ("$entity" in obj) {
|
|
830
|
+
return Promise.resolve(this._resolveEntityRef(obj.$entity));
|
|
831
|
+
}
|
|
832
|
+
// $component — component reference: { entity, type, index }
|
|
833
|
+
if ("$component" in obj) {
|
|
834
|
+
return Promise.resolve(this._resolveComponent(obj.$component));
|
|
835
|
+
}
|
|
836
|
+
// $signal — signal binding: register listeners on the existing Signal instance
|
|
837
|
+
if ("$signal" in obj) {
|
|
838
|
+
return this._resolveSignal(originValue, obj.$signal);
|
|
839
|
+
}
|
|
840
|
+
// Plain object — recurse each value, modifying originValue in place or building a new object
|
|
841
|
+
var target = originValue && (typeof originValue === "undefined" ? "undefined" : _type_of(originValue)) === "object" && !Array.isArray(originValue) ? originValue : {};
|
|
842
|
+
var promises = [];
|
|
843
|
+
for(var key in obj)_this = this, _loop(key);
|
|
844
|
+
return Promise.all(promises).then(function() {
|
|
845
|
+
return target;
|
|
846
|
+
});
|
|
939
847
|
};
|
|
940
|
-
|
|
941
|
-
|
|
848
|
+
_proto._resolveSignal = function _resolveSignal(signal, listeners) {
|
|
849
|
+
var _this = this;
|
|
850
|
+
if (!signal || typeof signal.on !== "function") {
|
|
851
|
+
return Promise.reject(new Error("$signal requires a pre-initialized Signal instance on the target property"));
|
|
852
|
+
}
|
|
853
|
+
var promises = listeners.map(function(listener) {
|
|
854
|
+
var targetComponent = _this._resolveComponent(listener.target.$component);
|
|
855
|
+
if (!targetComponent) return Promise.resolve();
|
|
856
|
+
var _listener_args;
|
|
857
|
+
return Promise.all(((_listener_args = listener.args) != null ? _listener_args : []).map(function(a) {
|
|
858
|
+
return _this._resolveValue(a);
|
|
859
|
+
})).then(function(resolvedArgs) {
|
|
860
|
+
var _signal;
|
|
861
|
+
(_signal = signal).on.apply(_signal, [].concat([
|
|
862
|
+
targetComponent,
|
|
863
|
+
listener.methodName
|
|
864
|
+
], resolvedArgs));
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
return Promise.all(promises).then(function() {
|
|
868
|
+
return signal;
|
|
869
|
+
});
|
|
942
870
|
};
|
|
943
|
-
|
|
944
|
-
|
|
871
|
+
_proto._resolveComponent = function _resolveComponent(comp) {
|
|
872
|
+
var entity = this._resolveEntityRef(comp.entity);
|
|
873
|
+
if (!entity) return null;
|
|
874
|
+
var type = engineCore.Loader.getClass(comp.type);
|
|
875
|
+
if (!type) return null;
|
|
876
|
+
var buffer = ReflectionParser._componentBuffer;
|
|
877
|
+
buffer.length = 0;
|
|
878
|
+
entity.getComponents(type, buffer);
|
|
879
|
+
var _buffer_comp_index;
|
|
880
|
+
var result = (_buffer_comp_index = buffer[comp.index]) != null ? _buffer_comp_index : null;
|
|
881
|
+
buffer.length = 0;
|
|
882
|
+
return result;
|
|
945
883
|
};
|
|
946
|
-
|
|
947
|
-
|
|
884
|
+
_proto._resolveEntityRef = function _resolveEntityRef(path) {
|
|
885
|
+
if (!path || path.length === 0) return null;
|
|
886
|
+
var _this__context_entityInstances_path_;
|
|
887
|
+
var entity = (_this__context_entityInstances_path_ = this._context.entityInstances[path[0]]) != null ? _this__context_entityInstances_path_ : null;
|
|
888
|
+
for(var i = 1, n = path.length; entity && i < n; i++){
|
|
889
|
+
var _entity_children_path_i;
|
|
890
|
+
entity = (_entity_children_path_i = entity.children[path[i]]) != null ? _entity_children_path_i : null;
|
|
891
|
+
}
|
|
892
|
+
return entity;
|
|
948
893
|
};
|
|
949
894
|
return ReflectionParser;
|
|
950
895
|
}();
|
|
896
|
+
/** @internal shared with HierarchyParser; each use must length=0 -> getComponents -> read -> length=0 synchronously. */ ReflectionParser._componentBuffer = [];
|
|
951
897
|
|
|
952
898
|
/**
|
|
953
899
|
* HDR (Radiance RGBE) image decoder.
|
|
@@ -1249,45 +1195,6 @@ function _instanceof(left, right) {
|
|
|
1249
1195
|
} else return left instanceof right;
|
|
1250
1196
|
}
|
|
1251
1197
|
|
|
1252
|
-
function _array_like_to_array(arr, len) {
|
|
1253
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
1254
|
-
|
|
1255
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
1256
|
-
|
|
1257
|
-
return arr2;
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
1261
|
-
if (!o) return;
|
|
1262
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
1263
|
-
|
|
1264
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1265
|
-
|
|
1266
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1267
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1268
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
1272
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
1273
|
-
|
|
1274
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
1275
|
-
// Fallback for engines without symbol support
|
|
1276
|
-
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
1277
|
-
if (it) o = it;
|
|
1278
|
-
|
|
1279
|
-
var i = 0;
|
|
1280
|
-
|
|
1281
|
-
return function() {
|
|
1282
|
-
if (i >= o.length) return { done: true };
|
|
1283
|
-
|
|
1284
|
-
return { done: false, value: o[i++] };
|
|
1285
|
-
};
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
1198
|
/**
|
|
1292
1199
|
* The Prefab resource.
|
|
1293
1200
|
*/ var PrefabResource = /*#__PURE__*/ function(ReferResource1) {
|
|
@@ -1319,8 +1226,9 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
1319
1226
|
};
|
|
1320
1227
|
_proto._onDestroy = function _onDestroy() {
|
|
1321
1228
|
var _this = this;
|
|
1229
|
+
var _this__root;
|
|
1322
1230
|
ReferResource1.prototype._onDestroy.call(this);
|
|
1323
|
-
this._root.destroy();
|
|
1231
|
+
(_this__root = this._root) == null ? void 0 : _this__root.destroy();
|
|
1324
1232
|
this._dependenceAssets.forEach(function(asset) {
|
|
1325
1233
|
if (_instanceof(asset, engineCore.ReferResource)) {
|
|
1326
1234
|
// @ts-ignore
|
|
@@ -1336,319 +1244,260 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
1336
1244
|
var _this = this;
|
|
1337
1245
|
this.data = data;
|
|
1338
1246
|
this.context = context;
|
|
1339
|
-
|
|
1340
|
-
|
|
1247
|
+
if (data.version !== "2.0") {
|
|
1248
|
+
var resourceType = context.type === ParserType.Scene ? "scene" : "prefab";
|
|
1249
|
+
throw new Error("Unsupported " + resourceType + ' format version "' + data.version + '". Expected "2.0".');
|
|
1250
|
+
}
|
|
1341
1251
|
this._engine = this.context.engine;
|
|
1342
|
-
this._organizeEntities = this._organizeEntities.bind(this);
|
|
1343
|
-
this._parseComponents = this._parseComponents.bind(this);
|
|
1344
|
-
this._parsePrefabModification = this._parsePrefabModification.bind(this);
|
|
1345
|
-
this._parseAddedComponents = this._parseAddedComponents.bind(this);
|
|
1346
|
-
this._parseComponentsPropsAndMethods = this._parseComponentsPropsAndMethods.bind(this);
|
|
1347
|
-
this._parsePrefabRemovedEntities = this._parsePrefabRemovedEntities.bind(this);
|
|
1348
|
-
this._parsePrefabRemovedComponents = this._parsePrefabRemovedComponents.bind(this);
|
|
1349
|
-
this._clearAndResolve = this._clearAndResolve.bind(this);
|
|
1350
1252
|
this.promise = new Promise(function(resolve, reject) {
|
|
1351
1253
|
_this._reject = reject;
|
|
1352
1254
|
_this._resolve = resolve;
|
|
1353
1255
|
});
|
|
1354
|
-
this._reflectionParser = new ReflectionParser(context);
|
|
1256
|
+
this._reflectionParser = new ReflectionParser(context, data.refs);
|
|
1355
1257
|
}
|
|
1356
1258
|
var _proto = HierarchyParser.prototype;
|
|
1357
|
-
|
|
1358
|
-
this._parseEntities().then(this._organizeEntities).then(this._parseComponents).then(this._parseAddedComponents).then(this._parseComponentsPropsAndMethods).then(this._parsePrefabModification).then(this._parsePrefabRemovedEntities).then(this._parsePrefabRemovedComponents).then(this._clearAndResolve).then(this._resolve).catch(this._reject);
|
|
1359
|
-
};
|
|
1360
|
-
_proto._applyEntityData = function _applyEntityData(entity, entityConfig) {
|
|
1361
|
-
if (entityConfig === void 0) entityConfig = {};
|
|
1362
|
-
var _entityConfig_isActive;
|
|
1363
|
-
entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : entity.isActive;
|
|
1364
|
-
var _entityConfig_name;
|
|
1365
|
-
entity.name = (_entityConfig_name = entityConfig.name) != null ? _entityConfig_name : entity.name;
|
|
1366
|
-
var transform = entity.transform;
|
|
1367
|
-
var transformConfig = entityConfig.transform;
|
|
1368
|
-
if (transformConfig) {
|
|
1369
|
-
this._reflectionParser.parsePropsAndMethods(transform, transformConfig);
|
|
1370
|
-
} else {
|
|
1371
|
-
var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale;
|
|
1372
|
-
if (position) transform.position.copyFrom(position);
|
|
1373
|
-
if (rotation) transform.rotation.copyFrom(rotation);
|
|
1374
|
-
if (scale) transform.scale.copyFrom(scale);
|
|
1375
|
-
}
|
|
1376
|
-
if (entityConfig.layer) entity.layer = entityConfig.layer;
|
|
1377
|
-
return entity;
|
|
1378
|
-
};
|
|
1379
|
-
_proto._parseEntities = function _parseEntities() {
|
|
1259
|
+
_proto.start = function start() {
|
|
1380
1260
|
var _this = this;
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
return _this.
|
|
1391
|
-
});
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
for(var i = 0, l = entitiesConfig.length; i < l; i++){
|
|
1410
|
-
var entityConfig = entitiesConfig[i];
|
|
1411
|
-
if (entityConfig.strippedId) {
|
|
1412
|
-
continue;
|
|
1413
|
-
}
|
|
1414
|
-
var entity = entityMap.get(entityConfig.id);
|
|
1415
|
-
this._addComponents(entity, entityConfig.components);
|
|
1416
|
-
}
|
|
1417
|
-
};
|
|
1418
|
-
_proto._parsePrefabModification = function _parsePrefabModification() {
|
|
1419
|
-
var _loop = function(i, l) {
|
|
1420
|
-
var entityConfig = entitiesConfig[i];
|
|
1421
|
-
var id = entityConfig.id, modifications = entityConfig.modifications;
|
|
1422
|
-
if (modifications == null ? void 0 : modifications.length) {
|
|
1423
|
-
var _promises;
|
|
1424
|
-
var rootEntity = entityMap.get(id);
|
|
1425
|
-
(_promises = promises).push.apply(_promises, [].concat(modifications.map(function(modification) {
|
|
1426
|
-
var target = modification.target, props = modification.props, methods = modification.methods;
|
|
1427
|
-
var entityId = target.entityId, componentId = target.componentId;
|
|
1428
|
-
var context = _this._prefabContextMap.get(rootEntity);
|
|
1429
|
-
var targetEntity = context.entityMap.get(entityId);
|
|
1430
|
-
var targetComponent = context.components.get(componentId);
|
|
1431
|
-
if (targetComponent) {
|
|
1432
|
-
return _this._reflectionParser.parsePropsAndMethods(targetComponent, {
|
|
1433
|
-
props: props,
|
|
1434
|
-
methods: methods
|
|
1435
|
-
});
|
|
1436
|
-
} else if (targetEntity) {
|
|
1437
|
-
return Promise.resolve(_this._applyEntityData(targetEntity, props));
|
|
1438
|
-
}
|
|
1439
|
-
})));
|
|
1261
|
+
this._parseEntities().then(function() {
|
|
1262
|
+
return _this._organizeEntities();
|
|
1263
|
+
}).then(function() {
|
|
1264
|
+
return _this._parseComponents();
|
|
1265
|
+
}).then(function() {
|
|
1266
|
+
return _this._parseComponentsPropsAndCalls();
|
|
1267
|
+
}).then(function() {
|
|
1268
|
+
return _this._parsePrefabOverrides();
|
|
1269
|
+
}).then(function() {
|
|
1270
|
+
return _this._clearAndResolve();
|
|
1271
|
+
}).then(this._resolve).catch(this._reject);
|
|
1272
|
+
};
|
|
1273
|
+
_proto._onEntityCreated = function _onEntityCreated(_entity) {};
|
|
1274
|
+
// ---------------------------------------------------------------------------
|
|
1275
|
+
// Stage 1: Create entity instances
|
|
1276
|
+
// ---------------------------------------------------------------------------
|
|
1277
|
+
_proto._parseEntities = function _parseEntities() {
|
|
1278
|
+
var _this, _loop = function(i, n) {
|
|
1279
|
+
var entityConfig = entities[i];
|
|
1280
|
+
if (HierarchyParser._isPrefabInstanceEntity(entityConfig)) {
|
|
1281
|
+
promises.push(_this._loadPrefabInstance(entityConfig, engine).then(function(entity) {
|
|
1282
|
+
entityInstances[i] = entity;
|
|
1283
|
+
}));
|
|
1284
|
+
} else {
|
|
1285
|
+
var entity = new engineCore.Entity(engine, entityConfig.name);
|
|
1286
|
+
HierarchyParser._applyEntityProps(entity, entityConfig);
|
|
1287
|
+
_this._onEntityCreated(entity);
|
|
1288
|
+
entityInstances[i] = entity;
|
|
1440
1289
|
}
|
|
1441
1290
|
};
|
|
1442
|
-
var
|
|
1443
|
-
var
|
|
1444
|
-
var
|
|
1291
|
+
var entities = this.data.entities;
|
|
1292
|
+
var entityInstances = this.context.entityInstances;
|
|
1293
|
+
var engine = this._engine;
|
|
1445
1294
|
var promises = [];
|
|
1446
|
-
for(var i = 0,
|
|
1295
|
+
for(var i = 0, n = entities.length; i < n; i++)_this = this, _loop(i);
|
|
1447
1296
|
return Promise.all(promises);
|
|
1448
1297
|
};
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
var
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
var entityConfig = entitiesConfig[i];
|
|
1465
|
-
var id = entityConfig.id, removedEntities = entityConfig.removedEntities;
|
|
1466
|
-
if (removedEntities == null ? void 0 : removedEntities.length) {
|
|
1467
|
-
var rootEntity = entityMap.get(id);
|
|
1468
|
-
for(var j = 0, m = removedEntities.length; j < m; j++){
|
|
1469
|
-
var target = removedEntities[j];
|
|
1470
|
-
var entityId = target.entityId;
|
|
1471
|
-
var context = this._prefabContextMap.get(rootEntity);
|
|
1472
|
-
var targetEntity = context.entityMap.get(entityId);
|
|
1473
|
-
if (targetEntity) {
|
|
1474
|
-
targetEntity.destroy();
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1298
|
+
// ---------------------------------------------------------------------------
|
|
1299
|
+
// Stage 2: Build parent-child hierarchy
|
|
1300
|
+
// ---------------------------------------------------------------------------
|
|
1301
|
+
_proto._organizeEntities = function _organizeEntities() {
|
|
1302
|
+
var entities = this.data.entities;
|
|
1303
|
+
var entityInstances = this.context.entityInstances;
|
|
1304
|
+
for(var i = 0, n = entities.length; i < n; i++){
|
|
1305
|
+
var entityConfig = entities[i];
|
|
1306
|
+
// Prefab instance entities manage their own children.
|
|
1307
|
+
if (HierarchyParser._isPrefabInstanceEntity(entityConfig)) continue;
|
|
1308
|
+
var children = entityConfig.children;
|
|
1309
|
+
if (!children) continue;
|
|
1310
|
+
var parent = entityInstances[i];
|
|
1311
|
+
for(var j = 0, m = children.length; j < m; j++){
|
|
1312
|
+
parent.addChild(entityInstances[children[j]]);
|
|
1477
1313
|
}
|
|
1478
1314
|
}
|
|
1315
|
+
var rootIndices = this._getRootIndices();
|
|
1316
|
+
for(var i1 = 0, n1 = rootIndices.length; i1 < n1; i1++){
|
|
1317
|
+
this._handleRootEntity(rootIndices[i1]);
|
|
1318
|
+
}
|
|
1479
1319
|
};
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1320
|
+
// ---------------------------------------------------------------------------
|
|
1321
|
+
// Stage 3: Add components to entities
|
|
1322
|
+
// ---------------------------------------------------------------------------
|
|
1323
|
+
_proto._parseComponents = function _parseComponents() {
|
|
1324
|
+
var entities = this.data.entities;
|
|
1325
|
+
var allComponents = this.data.components;
|
|
1326
|
+
var entityInstances = this.context.entityInstances;
|
|
1327
|
+
var pendingComponents = this.context.pendingComponents;
|
|
1328
|
+
var refs = this.data.refs;
|
|
1329
|
+
for(var i = 0, n = entities.length; i < n; i++){
|
|
1330
|
+
var entityConfig = entities[i];
|
|
1331
|
+
if (HierarchyParser._isPrefabInstanceEntity(entityConfig)) continue;
|
|
1332
|
+
var entity = entityInstances[i];
|
|
1333
|
+
var componentIndices = entityConfig.components;
|
|
1334
|
+
if (!componentIndices) continue;
|
|
1335
|
+
for(var j = 0, m = componentIndices.length; j < m; j++){
|
|
1336
|
+
var config = allComponents[componentIndices[j]];
|
|
1337
|
+
var instance = HierarchyParser._addComponentFromConfig(entity, config, refs);
|
|
1338
|
+
pendingComponents.push({
|
|
1339
|
+
instance: instance,
|
|
1340
|
+
config: config
|
|
1341
|
+
});
|
|
1498
1342
|
}
|
|
1499
1343
|
}
|
|
1500
1344
|
};
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1345
|
+
// ---------------------------------------------------------------------------
|
|
1346
|
+
// Stage 4: Apply props and execute calls on components
|
|
1347
|
+
// ---------------------------------------------------------------------------
|
|
1348
|
+
_proto._parseComponentsPropsAndCalls = function _parseComponentsPropsAndCalls() {
|
|
1349
|
+
var pendingComponents = this.context.pendingComponents;
|
|
1350
|
+
var reflectionParser = this._reflectionParser;
|
|
1351
|
+
var promises = [];
|
|
1352
|
+
for(var i = 0, n = pendingComponents.length; i < n; i++){
|
|
1353
|
+
var _pendingComponents_i = pendingComponents[i], instance = _pendingComponents_i.instance, config = _pendingComponents_i.config;
|
|
1354
|
+
promises.push(reflectionParser.parseMutationBlock(instance, config));
|
|
1509
1355
|
}
|
|
1356
|
+
return Promise.all(promises);
|
|
1510
1357
|
};
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1358
|
+
// ---------------------------------------------------------------------------
|
|
1359
|
+
// Stage 5: Apply prefab instance overrides
|
|
1360
|
+
// ---------------------------------------------------------------------------
|
|
1361
|
+
_proto._parsePrefabOverrides = function _parsePrefabOverrides() {
|
|
1362
|
+
var entities = this.data.entities;
|
|
1363
|
+
var entityInstances = this.context.entityInstances;
|
|
1364
|
+
var promises = [];
|
|
1365
|
+
for(var i = 0, n = entities.length; i < n; i++){
|
|
1366
|
+
var entityConfig = entities[i];
|
|
1367
|
+
if (!HierarchyParser._isPrefabInstanceEntity(entityConfig)) continue;
|
|
1368
|
+
var overrides = entityConfig.instance.overrides;
|
|
1369
|
+
if (!overrides) continue;
|
|
1370
|
+
this._applyOverrides(entityInstances[i], overrides, promises);
|
|
1520
1371
|
}
|
|
1521
|
-
return
|
|
1522
|
-
return _this._applyEntityData(entity, entityConfig);
|
|
1523
|
-
});
|
|
1372
|
+
return Promise.all(promises);
|
|
1524
1373
|
};
|
|
1525
|
-
_proto.
|
|
1526
|
-
var
|
|
1527
|
-
var
|
|
1528
|
-
|
|
1529
|
-
|
|
1374
|
+
_proto._applyOverrides = function _applyOverrides(rootEntity, overrides, promises) {
|
|
1375
|
+
var refs = this.data.refs;
|
|
1376
|
+
var reflectionParser = this._reflectionParser;
|
|
1377
|
+
// entityProps — entity-level property overrides
|
|
1378
|
+
if (overrides.entityProps) {
|
|
1379
|
+
for(var j = 0, m = overrides.entityProps.length; j < m; j++){
|
|
1380
|
+
var override = overrides.entityProps[j];
|
|
1381
|
+
HierarchyParser._applyEntityProps(HierarchyParser._resolveEntity(rootEntity, override.path), override);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
// componentProps — component-level property overrides
|
|
1385
|
+
if (overrides.componentProps) {
|
|
1386
|
+
for(var j1 = 0, m1 = overrides.componentProps.length; j1 < m1; j1++){
|
|
1387
|
+
var override1 = overrides.componentProps[j1];
|
|
1388
|
+
var entity = HierarchyParser._resolveEntity(rootEntity, override1.path);
|
|
1389
|
+
var target = HierarchyParser._resolveComponent(entity, override1.selector);
|
|
1390
|
+
promises.push(reflectionParser.parseMutationBlock(target, override1));
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
// addedComponents — attach top-level components[index] to a prefab entity and parse props
|
|
1394
|
+
if (overrides.addedComponents) {
|
|
1395
|
+
var allComponents = this.data.components;
|
|
1396
|
+
for(var j2 = 0, m2 = overrides.addedComponents.length; j2 < m2; j2++){
|
|
1397
|
+
var added = overrides.addedComponents[j2];
|
|
1398
|
+
var entity1 = HierarchyParser._resolveEntity(rootEntity, added.target);
|
|
1399
|
+
var config = allComponents[added.component];
|
|
1400
|
+
var component = HierarchyParser._addComponentFromConfig(entity1, config, refs);
|
|
1401
|
+
promises.push(reflectionParser.parseMutationBlock(component, config));
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
// addedEntities — attach already-created top-level entityInstances[index] as a child
|
|
1405
|
+
if (overrides.addedEntities) {
|
|
1406
|
+
var entityInstances = this.context.entityInstances;
|
|
1407
|
+
for(var j3 = 0, m3 = overrides.addedEntities.length; j3 < m3; j3++){
|
|
1408
|
+
var added1 = overrides.addedEntities[j3];
|
|
1409
|
+
var parent = HierarchyParser._resolveEntity(rootEntity, added1.parent);
|
|
1410
|
+
parent.addChild(entityInstances[added1.entity]);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
// removedEntities — pre-resolve all targets then destroy (destroy shifts sibling indices)
|
|
1414
|
+
if (overrides.removedEntities) {
|
|
1415
|
+
var removed = overrides.removedEntities;
|
|
1416
|
+
var targets = new Array(removed.length);
|
|
1417
|
+
for(var j4 = 0, m4 = removed.length; j4 < m4; j4++){
|
|
1418
|
+
targets[j4] = HierarchyParser._resolveEntity(rootEntity, removed[j4]);
|
|
1419
|
+
}
|
|
1420
|
+
for(var j5 = 0, m5 = targets.length; j5 < m5; j5++){
|
|
1421
|
+
targets[j5].destroy();
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
// removedComponents — pre-resolve all targets then destroy (destroy shifts component indices)
|
|
1425
|
+
if (overrides.removedComponents) {
|
|
1426
|
+
var targets1 = [];
|
|
1427
|
+
for(var j6 = 0, m6 = overrides.removedComponents.length; j6 < m6; j6++){
|
|
1428
|
+
var override2 = overrides.removedComponents[j6];
|
|
1429
|
+
var entity2 = HierarchyParser._resolveEntity(rootEntity, override2.path);
|
|
1430
|
+
var selectors = override2.selectors;
|
|
1431
|
+
for(var k = 0, p = selectors.length; k < p; k++){
|
|
1432
|
+
targets1.push(HierarchyParser._resolveComponent(entity2, selectors[k]));
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
for(var j7 = 0, m7 = targets1.length; j7 < m7; j7++){
|
|
1436
|
+
targets1[j7].destroy();
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1530
1439
|
};
|
|
1531
|
-
|
|
1440
|
+
// ---------------------------------------------------------------------------
|
|
1441
|
+
// Prefab instance loading
|
|
1442
|
+
// ---------------------------------------------------------------------------
|
|
1443
|
+
_proto._loadPrefabInstance = function _loadPrefabInstance(entityConfig, engine) {
|
|
1532
1444
|
var _this = this;
|
|
1533
|
-
var
|
|
1445
|
+
var instance = entityConfig.instance;
|
|
1446
|
+
var refItem;
|
|
1447
|
+
try {
|
|
1448
|
+
refItem = resolveRefItem(this.data.refs, instance.asset, "HierarchyParser", "instance.asset");
|
|
1449
|
+
} catch (error) {
|
|
1450
|
+
return Promise.reject(error);
|
|
1451
|
+
}
|
|
1534
1452
|
return engine.resourceManager// @ts-ignore
|
|
1535
|
-
.getResourceByRef({
|
|
1536
|
-
url: assetUrl
|
|
1537
|
-
}).then(function(prefabResource) {
|
|
1453
|
+
.getResourceByRef(refItem).then(function(prefabResource) {
|
|
1538
1454
|
var entity = _instanceof(prefabResource, PrefabResource) ? prefabResource.instantiate() : prefabResource.instantiateSceneRoot();
|
|
1539
|
-
|
|
1540
|
-
_this._generateInstanceContext(entity, instanceContext, "");
|
|
1541
|
-
_this._prefabContextMap.set(entity, instanceContext);
|
|
1542
|
-
var cbArray = _this._prefabPromiseMap.get(entityConfig.id);
|
|
1543
|
-
if (cbArray) {
|
|
1544
|
-
for(var i = 0, n = cbArray.length; i < n; i++){
|
|
1545
|
-
cbArray[i].resolve(instanceContext);
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1455
|
+
_this._onEntityCreated(entity);
|
|
1548
1456
|
return entity;
|
|
1549
1457
|
});
|
|
1550
1458
|
};
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
reject: reject
|
|
1560
|
-
});
|
|
1561
|
-
_this._prefabPromiseMap.set(entityConfig.prefabInstanceId, cbArray);
|
|
1562
|
-
}).then(function(context) {
|
|
1563
|
-
var entityId = entityConfig.prefabSource.entityId;
|
|
1564
|
-
return context.entityMap.get(entityId);
|
|
1565
|
-
});
|
|
1566
|
-
};
|
|
1567
|
-
_proto._parseChildren = function _parseChildren(parentId) {
|
|
1568
|
-
var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap;
|
|
1569
|
-
var children = entityConfigMap.get(parentId).children;
|
|
1570
|
-
if (children && children.length > 0) {
|
|
1571
|
-
var parent = entityMap.get(parentId);
|
|
1572
|
-
for(var i = 0; i < children.length; i++){
|
|
1573
|
-
var childId = children[i];
|
|
1574
|
-
var entity = entityMap.get(childId);
|
|
1575
|
-
parent.addChild(entity);
|
|
1576
|
-
this._parseChildren(childId);
|
|
1577
|
-
}
|
|
1459
|
+
// ---------------------------------------------------------------------------
|
|
1460
|
+
// Utilities
|
|
1461
|
+
// ---------------------------------------------------------------------------
|
|
1462
|
+
/** Resolve an entity inside a prefab instance by walking the child-index path from root */ HierarchyParser._resolveEntity = function _resolveEntity(root, path) {
|
|
1463
|
+
var entity = root;
|
|
1464
|
+
for(var i = 0, n = path.length; i < n; i++){
|
|
1465
|
+
entity = entity.children[path[i]];
|
|
1466
|
+
if (!entity) throw new Error("HierarchyParser: override target entity not found at path [" + path + "], failed at depth " + i);
|
|
1578
1467
|
}
|
|
1468
|
+
return entity;
|
|
1579
1469
|
};
|
|
1580
|
-
|
|
1581
|
-
var
|
|
1582
|
-
|
|
1583
|
-
var
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
componentConfigMap.set(componentId, componentConfig);
|
|
1591
|
-
this._addComponentPlugin(componentId, component);
|
|
1592
|
-
}
|
|
1593
|
-
};
|
|
1594
|
-
_proto._generateInstanceContext = function _generateInstanceContext(entity, context, path) {
|
|
1595
|
-
var entityMap = context.entityMap, components = context.components;
|
|
1596
|
-
var componentsMap = {};
|
|
1597
|
-
var componentIndexMap = {};
|
|
1598
|
-
entityMap.set(path, entity);
|
|
1599
|
-
// @ts-ignore
|
|
1600
|
-
entity._components.forEach(function(component) {
|
|
1601
|
-
// @ts-ignore
|
|
1602
|
-
var name = engineCore.Loader.getClassName(component.constructor);
|
|
1603
|
-
if (!componentsMap[name]) {
|
|
1604
|
-
componentsMap[name] = entity.getComponents(component.constructor, []);
|
|
1605
|
-
componentIndexMap[name] = 0;
|
|
1606
|
-
}
|
|
1607
|
-
components.set(path + ":" + name + "/" + componentIndexMap[name]++, component);
|
|
1608
|
-
});
|
|
1609
|
-
for(var i = 0, n = entity.children.length; i < n; i++){
|
|
1610
|
-
var child = entity.children[i];
|
|
1611
|
-
var childPath = path ? path + "/" + i : "" + i;
|
|
1612
|
-
this._generateInstanceContext(child, context, childPath);
|
|
1613
|
-
}
|
|
1470
|
+
/** Resolve a component on an entity by type name + per-type index */ HierarchyParser._resolveComponent = function _resolveComponent(entity, selector) {
|
|
1471
|
+
var type = engineCore.Loader.getClass(selector.type);
|
|
1472
|
+
if (!type) throw new Error('HierarchyParser: override target component type "' + selector.type + '" is not registered');
|
|
1473
|
+
var buffer = ReflectionParser._componentBuffer;
|
|
1474
|
+
buffer.length = 0;
|
|
1475
|
+
entity.getComponents(type, buffer);
|
|
1476
|
+
var result = buffer[selector.index];
|
|
1477
|
+
buffer.length = 0;
|
|
1478
|
+
if (!result) throw new Error("HierarchyParser: override target component not found: " + selector.type + "/" + selector.index);
|
|
1479
|
+
return result;
|
|
1614
1480
|
};
|
|
1615
|
-
|
|
1616
|
-
var
|
|
1617
|
-
var
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1481
|
+
/** Resolve component class from config and add to entity. Throws if class is not registered. */ HierarchyParser._addComponentFromConfig = function _addComponentFromConfig(entity, config, refs) {
|
|
1482
|
+
var key = config.script != null ? resolveRefItem(refs, config.script, "HierarchyParser", "component.script").url : config.type;
|
|
1483
|
+
var Class = engineCore.Loader.getClass(key);
|
|
1484
|
+
if (!Class) throw new Error('Loader.getClass: class "' + key + '" is not registered');
|
|
1485
|
+
return entity.addComponent(Class);
|
|
1486
|
+
};
|
|
1487
|
+
HierarchyParser._isPrefabInstanceEntity = function _isPrefabInstanceEntity(entityConfig) {
|
|
1488
|
+
return "instance" in entityConfig;
|
|
1489
|
+
};
|
|
1490
|
+
/** Apply entity-level props (name, isActive, layer, transform) to an entity. */ HierarchyParser._applyEntityProps = function _applyEntityProps(entity, props) {
|
|
1491
|
+
if (props.name != null) entity.name = props.name;
|
|
1492
|
+
if (props.isActive != null) entity.isActive = props.isActive;
|
|
1493
|
+
if (props.layer != null) entity.layer = props.layer;
|
|
1494
|
+
if (props.position) entity.transform.position.set(props.position[0], props.position[1], props.position[2]);
|
|
1495
|
+
if (props.rotation) entity.transform.rotation.set(props.rotation[0], props.rotation[1], props.rotation[2]);
|
|
1496
|
+
if (props.scale) entity.transform.scale.set(props.scale[0], props.scale[1], props.scale[2]);
|
|
1628
1497
|
};
|
|
1629
|
-
_proto._addComponentPlugin = function _addComponentPlugin(componentId, component) {};
|
|
1630
|
-
_proto._addEntityPlugin = function _addEntityPlugin(entityId, entity) {};
|
|
1631
1498
|
return HierarchyParser;
|
|
1632
1499
|
}();
|
|
1633
1500
|
|
|
1634
|
-
var MaterialLoaderType = /*#__PURE__*/ function(MaterialLoaderType) {
|
|
1635
|
-
MaterialLoaderType["Vector2"] = "Vector2";
|
|
1636
|
-
MaterialLoaderType["Vector3"] = "Vector3";
|
|
1637
|
-
MaterialLoaderType["Vector4"] = "Vector4";
|
|
1638
|
-
MaterialLoaderType["Color"] = "Color";
|
|
1639
|
-
MaterialLoaderType["Float"] = "Float";
|
|
1640
|
-
MaterialLoaderType["Texture"] = "Texture";
|
|
1641
|
-
MaterialLoaderType["Boolean"] = "Boolean";
|
|
1642
|
-
MaterialLoaderType["Integer"] = "Integer";
|
|
1643
|
-
return MaterialLoaderType;
|
|
1644
|
-
}({});
|
|
1645
|
-
|
|
1646
|
-
var SpecularMode = /*#__PURE__*/ function(SpecularMode) {
|
|
1647
|
-
SpecularMode["Sky"] = "Sky";
|
|
1648
|
-
SpecularMode["Custom"] = "Custom";
|
|
1649
|
-
return SpecularMode;
|
|
1650
|
-
}({});
|
|
1651
|
-
|
|
1652
1501
|
/** @Internal */ var SceneParser = /*#__PURE__*/ function(HierarchyParser) {
|
|
1653
1502
|
_inherits(SceneParser, HierarchyParser);
|
|
1654
1503
|
function SceneParser(data, context, scene) {
|
|
@@ -1662,91 +1511,43 @@ var SpecularMode = /*#__PURE__*/ function(SpecularMode) {
|
|
|
1662
1511
|
*/ _proto._collectDependentAssets = function _collectDependentAssets(data) {
|
|
1663
1512
|
var context = this.context;
|
|
1664
1513
|
var resourceManager = context.resourceManager;
|
|
1665
|
-
|
|
1666
|
-
var
|
|
1667
|
-
var ambient = scene.ambient;
|
|
1668
|
-
if (ambient) {
|
|
1669
|
-
var useCustomAmbient = ambient.specularMode === SpecularMode.Custom;
|
|
1670
|
-
var useSH = ambient.diffuseMode === engineCore.DiffuseMode.SphericalHarmonics;
|
|
1671
|
-
var customAmbientLight = ambient.customAmbientLight, ambientLight = ambient.ambientLight;
|
|
1672
|
-
if (useCustomAmbient && customAmbientLight) {
|
|
1673
|
-
// @ts-ignore
|
|
1674
|
-
context._addDependentAsset(customAmbientLight.url, resourceManager.getResourceByRef(customAmbientLight));
|
|
1675
|
-
}
|
|
1676
|
-
if (ambientLight && (!useCustomAmbient || useSH)) {
|
|
1677
|
-
// @ts-ignore
|
|
1678
|
-
context._addDependentAsset(ambientLight.url, resourceManager.getResourceByRef(ambientLight));
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
var background = scene.background;
|
|
1682
|
-
var backgroundMode = background.mode;
|
|
1683
|
-
if (backgroundMode === engineCore.BackgroundMode.Texture) {
|
|
1684
|
-
var texture = background.texture;
|
|
1514
|
+
var refs = data.refs;
|
|
1515
|
+
for(var i = 0, n = refs.length; i < n; i++){
|
|
1685
1516
|
// @ts-ignore
|
|
1686
|
-
|
|
1687
|
-
} else if (backgroundMode === engineCore.BackgroundMode.Sky) {
|
|
1688
|
-
var skyMesh = background.skyMesh, skyMaterial = background.skyMaterial;
|
|
1689
|
-
if (skyMesh && skyMaterial) {
|
|
1690
|
-
// @ts-ignore
|
|
1691
|
-
context._addDependentAsset(skyMesh.url, resourceManager.getResourceByRef(skyMesh));
|
|
1692
|
-
// @ts-ignore
|
|
1693
|
-
context._addDependentAsset(skyMaterial.url, resourceManager.getResourceByRef(skyMaterial));
|
|
1694
|
-
}
|
|
1517
|
+
context._addDependentAsset(resourceManager.getResourceByRef(refs[i]));
|
|
1695
1518
|
}
|
|
1696
1519
|
};
|
|
1697
|
-
_proto.
|
|
1698
|
-
|
|
1699
|
-
|
|
1520
|
+
_proto._getRootIndices = function _getRootIndices() {
|
|
1521
|
+
return this.data.scene.entities;
|
|
1522
|
+
};
|
|
1523
|
+
_proto._handleRootEntity = function _handleRootEntity(index) {
|
|
1524
|
+
this.scene.addRootEntity(this.context.entityInstances[index]);
|
|
1700
1525
|
};
|
|
1701
1526
|
_proto._clearAndResolve = function _clearAndResolve() {
|
|
1702
1527
|
this.context.clear();
|
|
1703
1528
|
return this.scene;
|
|
1704
1529
|
};
|
|
1705
|
-
_proto._parseDependentAssets = function _parseDependentAssets(file) {
|
|
1706
|
-
var entities = file.entities;
|
|
1707
|
-
for(var i = 0, n = entities.length; i < n; i++){
|
|
1708
|
-
var entity = entities[i];
|
|
1709
|
-
if (!!entity.assetUrl) {
|
|
1710
|
-
var context = this.context;
|
|
1711
|
-
var url = entity.assetUrl, key = entity.key;
|
|
1712
|
-
// @ts-ignore
|
|
1713
|
-
context._addDependentAsset(url, context.resourceManager.getResourceByRef({
|
|
1714
|
-
url: url,
|
|
1715
|
-
key: key
|
|
1716
|
-
}));
|
|
1717
|
-
} else if (entity.strippedId) {
|
|
1718
|
-
continue;
|
|
1719
|
-
} else {
|
|
1720
|
-
var components = entity.components;
|
|
1721
|
-
for(var j = 0, m = components.length; j < m; j++){
|
|
1722
|
-
var component = components[j];
|
|
1723
|
-
this._searchDependentAssets(component.methods);
|
|
1724
|
-
this._searchDependentAssets(component.props);
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
};
|
|
1729
|
-
_proto._searchDependentAssets = function _searchDependentAssets(value) {
|
|
1730
|
-
if (Array.isArray(value)) {
|
|
1731
|
-
for(var i = 0, n = value.length; i < n; i++){
|
|
1732
|
-
this._searchDependentAssets(value[i]);
|
|
1733
|
-
}
|
|
1734
|
-
} else if (!!value && (typeof value === "undefined" ? "undefined" : _type_of(value)) === "object") {
|
|
1735
|
-
// @ts-ignore
|
|
1736
|
-
if (ReflectionParser._isAssetRef(value)) {
|
|
1737
|
-
var context = this.context;
|
|
1738
|
-
// @ts-ignore
|
|
1739
|
-
context._addDependentAsset(value.url, context.resourceManager.getResourceByRef(value));
|
|
1740
|
-
} else {
|
|
1741
|
-
for(var key in value){
|
|
1742
|
-
this._searchDependentAssets(value[key]);
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
};
|
|
1747
1530
|
return SceneParser;
|
|
1748
1531
|
}(HierarchyParser);
|
|
1749
1532
|
|
|
1533
|
+
var SpecularMode = /*#__PURE__*/ function(SpecularMode) {
|
|
1534
|
+
SpecularMode["Sky"] = "Sky";
|
|
1535
|
+
SpecularMode["Custom"] = "Custom";
|
|
1536
|
+
return SpecularMode;
|
|
1537
|
+
}({});
|
|
1538
|
+
|
|
1539
|
+
var MaterialLoaderType = /*#__PURE__*/ function(MaterialLoaderType) {
|
|
1540
|
+
MaterialLoaderType["Vector2"] = "Vector2";
|
|
1541
|
+
MaterialLoaderType["Vector3"] = "Vector3";
|
|
1542
|
+
MaterialLoaderType["Vector4"] = "Vector4";
|
|
1543
|
+
MaterialLoaderType["Color"] = "Color";
|
|
1544
|
+
MaterialLoaderType["Float"] = "Float";
|
|
1545
|
+
MaterialLoaderType["Texture"] = "Texture";
|
|
1546
|
+
MaterialLoaderType["Boolean"] = "Boolean";
|
|
1547
|
+
MaterialLoaderType["Integer"] = "Integer";
|
|
1548
|
+
return MaterialLoaderType;
|
|
1549
|
+
}({});
|
|
1550
|
+
|
|
1750
1551
|
/**
|
|
1751
1552
|
* Decode engine binary resource.
|
|
1752
1553
|
* @param arrayBuffer - array buffer of decode binary file
|
|
@@ -3228,6 +3029,45 @@ function getMeshoptDecoder() {
|
|
|
3228
3029
|
return GLTFResource;
|
|
3229
3030
|
}(engineCore.ReferResource);
|
|
3230
3031
|
|
|
3032
|
+
function _array_like_to_array(arr, len) {
|
|
3033
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3034
|
+
|
|
3035
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
3036
|
+
|
|
3037
|
+
return arr2;
|
|
3038
|
+
}
|
|
3039
|
+
|
|
3040
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
3041
|
+
if (!o) return;
|
|
3042
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
3043
|
+
|
|
3044
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
3045
|
+
|
|
3046
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
3047
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
3048
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
3049
|
+
}
|
|
3050
|
+
|
|
3051
|
+
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
3052
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
3053
|
+
|
|
3054
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
3055
|
+
// Fallback for engines without symbol support
|
|
3056
|
+
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
3057
|
+
if (it) o = it;
|
|
3058
|
+
|
|
3059
|
+
var i = 0;
|
|
3060
|
+
|
|
3061
|
+
return function() {
|
|
3062
|
+
if (i >= o.length) return { done: true };
|
|
3063
|
+
|
|
3064
|
+
return { done: false, value: o[i++] };
|
|
3065
|
+
};
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3231
3071
|
/**
|
|
3232
3072
|
* Module for glTF 2.0 Interface
|
|
3233
3073
|
*/ /**
|
|
@@ -5497,15 +5337,17 @@ var PrefabParser = /*#__PURE__*/ function(HierarchyParser) {
|
|
|
5497
5337
|
return _this;
|
|
5498
5338
|
}
|
|
5499
5339
|
var _proto = PrefabParser.prototype;
|
|
5500
|
-
_proto.
|
|
5501
|
-
if (entityConfig === void 0) entityConfig = {};
|
|
5502
|
-
HierarchyParser.prototype._applyEntityData.call(this, entity, entityConfig);
|
|
5340
|
+
_proto._onEntityCreated = function _onEntityCreated(entity) {
|
|
5503
5341
|
// @ts-ignore
|
|
5504
5342
|
entity._markAsTemplate(this.context.resource);
|
|
5505
|
-
return entity;
|
|
5506
5343
|
};
|
|
5507
|
-
_proto.
|
|
5508
|
-
|
|
5344
|
+
_proto._getRootIndices = function _getRootIndices() {
|
|
5345
|
+
return [
|
|
5346
|
+
this.data.root
|
|
5347
|
+
];
|
|
5348
|
+
};
|
|
5349
|
+
_proto._handleRootEntity = function _handleRootEntity(index) {
|
|
5350
|
+
this.prefabResource._root = this.context.entityInstances[index];
|
|
5509
5351
|
};
|
|
5510
5352
|
_proto._clearAndResolve = function _clearAndResolve() {
|
|
5511
5353
|
this.context.clear();
|
|
@@ -5516,9 +5358,7 @@ var PrefabParser = /*#__PURE__*/ function(HierarchyParser) {
|
|
|
5516
5358
|
var context = new ParserContext(engine, ParserType.Prefab, prefabResource);
|
|
5517
5359
|
var parser = new PrefabParser(data, context, prefabResource);
|
|
5518
5360
|
parser.start();
|
|
5519
|
-
return parser.promise
|
|
5520
|
-
return prefabResource;
|
|
5521
|
-
});
|
|
5361
|
+
return parser.promise;
|
|
5522
5362
|
};
|
|
5523
5363
|
return PrefabParser;
|
|
5524
5364
|
}(HierarchyParser);
|
|
@@ -6649,6 +6489,122 @@ RenderTargetLoader = __decorate([
|
|
|
6649
6489
|
])
|
|
6650
6490
|
], RenderTargetLoader);
|
|
6651
6491
|
|
|
6492
|
+
function loadRef(refs, index, resourceManager, label) {
|
|
6493
|
+
var ref = resolveRefItem(refs, index, "SceneLoader", label);
|
|
6494
|
+
// @ts-ignore
|
|
6495
|
+
return resourceManager.getResourceByRef(ref);
|
|
6496
|
+
}
|
|
6497
|
+
/**
|
|
6498
|
+
* Apply scene-level data (ambient, background, shadow, fog, AO) to a Scene.
|
|
6499
|
+
* @internal
|
|
6500
|
+
*/ function applySceneData(scene, sceneData, resourceManager, refs) {
|
|
6501
|
+
var promises = [];
|
|
6502
|
+
try {
|
|
6503
|
+
// parse ambient light
|
|
6504
|
+
var ambient = sceneData.ambient;
|
|
6505
|
+
if (ambient) {
|
|
6506
|
+
var useCustomAmbient = ambient.specularMode === SpecularMode.Custom;
|
|
6507
|
+
var useSH = ambient.diffuseMode === engineCore.DiffuseMode.SphericalHarmonics;
|
|
6508
|
+
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
6509
|
+
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
6510
|
+
scene.ambientLight.diffuseMode = ambient.diffuseMode;
|
|
6511
|
+
var solidColor = ambient.diffuseSolidColor;
|
|
6512
|
+
if (solidColor) {
|
|
6513
|
+
scene.ambientLight.diffuseSolidColor.set(solidColor[0], solidColor[1], solidColor[2], solidColor[3]);
|
|
6514
|
+
}
|
|
6515
|
+
if (useCustomAmbient && ambient.customAmbientLight != null) {
|
|
6516
|
+
promises.push(loadRef(refs, ambient.customAmbientLight, resourceManager, "scene.ambient.customAmbientLight").then(function(ambientLight) {
|
|
6517
|
+
scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
|
|
6518
|
+
}));
|
|
6519
|
+
}
|
|
6520
|
+
if (ambient.ambientLight != null && (!useCustomAmbient || useSH)) {
|
|
6521
|
+
promises.push(loadRef(refs, ambient.ambientLight, resourceManager, "scene.ambient.ambientLight").then(function(ambientLight) {
|
|
6522
|
+
if (!useCustomAmbient) {
|
|
6523
|
+
scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
|
|
6524
|
+
}
|
|
6525
|
+
if (useSH) {
|
|
6526
|
+
scene.ambientLight.diffuseSphericalHarmonics = ambientLight == null ? void 0 : ambientLight.diffuseSphericalHarmonics;
|
|
6527
|
+
}
|
|
6528
|
+
}));
|
|
6529
|
+
}
|
|
6530
|
+
}
|
|
6531
|
+
// parse background
|
|
6532
|
+
var background = sceneData.background;
|
|
6533
|
+
scene.background.mode = background.mode;
|
|
6534
|
+
switch(scene.background.mode){
|
|
6535
|
+
case engineCore.BackgroundMode.SolidColor:
|
|
6536
|
+
{
|
|
6537
|
+
var color = background.color;
|
|
6538
|
+
scene.background.solidColor.set(color[0], color[1], color[2], color[3]);
|
|
6539
|
+
break;
|
|
6540
|
+
}
|
|
6541
|
+
case engineCore.BackgroundMode.Sky:
|
|
6542
|
+
if (background.skyMesh != null && background.skyMaterial != null) {
|
|
6543
|
+
promises.push(loadRef(refs, background.skyMesh, resourceManager, "scene.background.skyMesh").then(function(mesh) {
|
|
6544
|
+
scene.background.sky.mesh = mesh;
|
|
6545
|
+
}), loadRef(refs, background.skyMaterial, resourceManager, "scene.background.skyMaterial").then(function(material) {
|
|
6546
|
+
scene.background.sky.material = material;
|
|
6547
|
+
}));
|
|
6548
|
+
} else {
|
|
6549
|
+
engineCore.Logger.warn("Sky background mode requires skyMesh and skyMaterial");
|
|
6550
|
+
}
|
|
6551
|
+
break;
|
|
6552
|
+
case engineCore.BackgroundMode.Texture:
|
|
6553
|
+
if (background.texture != null) {
|
|
6554
|
+
promises.push(loadRef(refs, background.texture, resourceManager, "scene.background.texture").then(function(texture) {
|
|
6555
|
+
scene.background.texture = texture;
|
|
6556
|
+
}));
|
|
6557
|
+
var _background_textureFillMode;
|
|
6558
|
+
scene.background.textureFillMode = (_background_textureFillMode = background.textureFillMode) != null ? _background_textureFillMode : scene.background.textureFillMode;
|
|
6559
|
+
}
|
|
6560
|
+
break;
|
|
6561
|
+
}
|
|
6562
|
+
} catch (error) {
|
|
6563
|
+
return Promise.reject(error);
|
|
6564
|
+
}
|
|
6565
|
+
// parse shadow
|
|
6566
|
+
var shadow = sceneData.shadow;
|
|
6567
|
+
if (shadow) {
|
|
6568
|
+
if (shadow.castShadows != undefined) scene.castShadows = shadow.castShadows;
|
|
6569
|
+
if (shadow.shadowResolution != undefined) scene.shadowResolution = shadow.shadowResolution;
|
|
6570
|
+
if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
|
|
6571
|
+
if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
|
|
6572
|
+
if (shadow.enableTransparentShadow != undefined) scene.enableTransparentShadow = shadow.enableTransparentShadow;
|
|
6573
|
+
if (shadow.shadowTwoCascadeSplits != undefined) scene.shadowTwoCascadeSplits = shadow.shadowTwoCascadeSplits;
|
|
6574
|
+
if (shadow.shadowFourCascadeSplits) {
|
|
6575
|
+
var splits = shadow.shadowFourCascadeSplits;
|
|
6576
|
+
scene.shadowFourCascadeSplits.set(splits[0], splits[1], splits[2]);
|
|
6577
|
+
}
|
|
6578
|
+
if (shadow.shadowFadeBorder != undefined) scene.shadowFadeBorder = shadow.shadowFadeBorder;
|
|
6579
|
+
}
|
|
6580
|
+
// parse fog
|
|
6581
|
+
var fog = sceneData.fog;
|
|
6582
|
+
if (fog) {
|
|
6583
|
+
if (fog.fogMode != undefined) scene.fogMode = fog.fogMode;
|
|
6584
|
+
if (fog.fogStart != undefined) scene.fogStart = fog.fogStart;
|
|
6585
|
+
if (fog.fogEnd != undefined) scene.fogEnd = fog.fogEnd;
|
|
6586
|
+
if (fog.fogDensity != undefined) scene.fogDensity = fog.fogDensity;
|
|
6587
|
+
if (fog.fogColor) scene.fogColor.set(fog.fogColor[0], fog.fogColor[1], fog.fogColor[2], fog.fogColor[3]);
|
|
6588
|
+
}
|
|
6589
|
+
// Post Process
|
|
6590
|
+
if (sceneData.postProcess) {
|
|
6591
|
+
engineCore.Logger.warn("Post Process is not supported in scene yet, please add PostProcess component in entity instead.");
|
|
6592
|
+
}
|
|
6593
|
+
// Ambient Occlusion
|
|
6594
|
+
var ambientOcclusion = sceneData.ambientOcclusion;
|
|
6595
|
+
if (ambientOcclusion) {
|
|
6596
|
+
var sceneAO = scene.ambientOcclusion;
|
|
6597
|
+
if (ambientOcclusion.enabledAmbientOcclusion != undefined) sceneAO.enabled = ambientOcclusion.enabledAmbientOcclusion;
|
|
6598
|
+
if (ambientOcclusion.quality != undefined) sceneAO.quality = ambientOcclusion.quality;
|
|
6599
|
+
if (ambientOcclusion.intensity != undefined) sceneAO.intensity = ambientOcclusion.intensity;
|
|
6600
|
+
if (ambientOcclusion.radius != undefined) sceneAO.radius = ambientOcclusion.radius;
|
|
6601
|
+
if (ambientOcclusion.bias != undefined) sceneAO.bias = ambientOcclusion.bias;
|
|
6602
|
+
if (ambientOcclusion.power != undefined) sceneAO.power = ambientOcclusion.power;
|
|
6603
|
+
if (ambientOcclusion.bilateralThreshold != undefined) sceneAO.bilateralThreshold = ambientOcclusion.bilateralThreshold;
|
|
6604
|
+
if (ambientOcclusion.minHorizonAngle != undefined) sceneAO.minHorizonAngle = ambientOcclusion.minHorizonAngle;
|
|
6605
|
+
}
|
|
6606
|
+
return Promise.all(promises).then(function() {});
|
|
6607
|
+
}
|
|
6652
6608
|
var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
6653
6609
|
_inherits(SceneLoader, Loader);
|
|
6654
6610
|
function SceneLoader() {
|
|
@@ -6662,122 +6618,15 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6662
6618
|
._request(item.url, _extends({}, item, {
|
|
6663
6619
|
type: "json"
|
|
6664
6620
|
})).then(function(data) {
|
|
6665
|
-
var
|
|
6666
|
-
var scene = new engineCore.Scene(engine, (
|
|
6621
|
+
var _data_scene_name;
|
|
6622
|
+
var scene = new engineCore.Scene(engine, (_data_scene_name = data.scene.name) != null ? _data_scene_name : "");
|
|
6667
6623
|
var context = new ParserContext(engine, ParserType.Scene, scene);
|
|
6668
6624
|
var parser = new SceneParser(data, context, scene);
|
|
6669
6625
|
parser._collectDependentAssets(data);
|
|
6670
6626
|
context._setTaskCompleteProgress = setTaskCompleteProgress;
|
|
6671
6627
|
parser.start();
|
|
6672
6628
|
return parser.promise.then(function() {
|
|
6673
|
-
|
|
6674
|
-
// parse ambient light
|
|
6675
|
-
var ambient = data.scene.ambient;
|
|
6676
|
-
if (ambient) {
|
|
6677
|
-
var useCustomAmbient = ambient.specularMode === SpecularMode.Custom;
|
|
6678
|
-
var useSH = ambient.diffuseMode === engineCore.DiffuseMode.SphericalHarmonics;
|
|
6679
|
-
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
6680
|
-
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
6681
|
-
scene.ambientLight.diffuseMode = ambient.diffuseMode;
|
|
6682
|
-
scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
|
|
6683
|
-
if (useCustomAmbient && ambient.customAmbientLight) {
|
|
6684
|
-
promises.push(// @ts-ignore
|
|
6685
|
-
resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
|
|
6686
|
-
scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
|
|
6687
|
-
}));
|
|
6688
|
-
}
|
|
6689
|
-
if (ambient.ambientLight && (!useCustomAmbient || useSH)) {
|
|
6690
|
-
promises.push(// @ts-ignore
|
|
6691
|
-
resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
|
|
6692
|
-
if (!useCustomAmbient) {
|
|
6693
|
-
scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
|
|
6694
|
-
}
|
|
6695
|
-
if (useSH) {
|
|
6696
|
-
scene.ambientLight.diffuseSphericalHarmonics = ambientLight == null ? void 0 : ambientLight.diffuseSphericalHarmonics;
|
|
6697
|
-
}
|
|
6698
|
-
}));
|
|
6699
|
-
}
|
|
6700
|
-
}
|
|
6701
|
-
// parse background
|
|
6702
|
-
var background = data.scene.background;
|
|
6703
|
-
scene.background.mode = background.mode;
|
|
6704
|
-
switch(scene.background.mode){
|
|
6705
|
-
case engineCore.BackgroundMode.SolidColor:
|
|
6706
|
-
scene.background.solidColor.copyFrom(background.color);
|
|
6707
|
-
break;
|
|
6708
|
-
case engineCore.BackgroundMode.Sky:
|
|
6709
|
-
if (background.skyMesh && background.skyMaterial) {
|
|
6710
|
-
// @ts-ignore
|
|
6711
|
-
var skyMeshPromise = resourceManager.getResourceByRef(background.skyMesh).then(function(mesh) {
|
|
6712
|
-
scene.background.sky.mesh = mesh;
|
|
6713
|
-
});
|
|
6714
|
-
// @ts-ignore
|
|
6715
|
-
// prettier-ignore
|
|
6716
|
-
var skyMaterialPromise = resourceManager.getResourceByRef(background.skyMaterial).then(function(material) {
|
|
6717
|
-
scene.background.sky.material = material;
|
|
6718
|
-
});
|
|
6719
|
-
promises.push(skyMeshPromise, skyMaterialPromise);
|
|
6720
|
-
} else {
|
|
6721
|
-
engineCore.Logger.warn("Sky background mode requires skyMesh and skyMaterial");
|
|
6722
|
-
}
|
|
6723
|
-
break;
|
|
6724
|
-
case engineCore.BackgroundMode.Texture:
|
|
6725
|
-
if (background.texture) {
|
|
6726
|
-
// @ts-ignore
|
|
6727
|
-
// prettier-ignore
|
|
6728
|
-
var backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
|
|
6729
|
-
scene.background.texture = texture;
|
|
6730
|
-
});
|
|
6731
|
-
promises.push(backgroundPromise);
|
|
6732
|
-
var _background_textureFillMode;
|
|
6733
|
-
scene.background.textureFillMode = (_background_textureFillMode = background.textureFillMode) != null ? _background_textureFillMode : scene.background.textureFillMode;
|
|
6734
|
-
}
|
|
6735
|
-
break;
|
|
6736
|
-
}
|
|
6737
|
-
// parse shadow
|
|
6738
|
-
var shadow = data.scene.shadow;
|
|
6739
|
-
if (shadow) {
|
|
6740
|
-
if (shadow.castShadows != undefined) scene.castShadows = shadow.castShadows;
|
|
6741
|
-
if (shadow.shadowResolution != undefined) scene.shadowResolution = shadow.shadowResolution;
|
|
6742
|
-
if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
|
|
6743
|
-
if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
|
|
6744
|
-
if (shadow.enableTransparentShadow != undefined) {
|
|
6745
|
-
scene.enableTransparentShadow = shadow.enableTransparentShadow;
|
|
6746
|
-
}
|
|
6747
|
-
var _shadow_shadowTwoCascadeSplits;
|
|
6748
|
-
scene.shadowTwoCascadeSplits = (_shadow_shadowTwoCascadeSplits = shadow.shadowTwoCascadeSplits) != null ? _shadow_shadowTwoCascadeSplits : scene.shadowTwoCascadeSplits;
|
|
6749
|
-
shadow.shadowFourCascadeSplits && scene.shadowFourCascadeSplits.copyFrom(shadow.shadowFourCascadeSplits);
|
|
6750
|
-
var _shadow_shadowFadeBorder;
|
|
6751
|
-
scene.shadowFadeBorder = (_shadow_shadowFadeBorder = shadow.shadowFadeBorder) != null ? _shadow_shadowFadeBorder : scene.shadowFadeBorder;
|
|
6752
|
-
}
|
|
6753
|
-
// parse fog
|
|
6754
|
-
var fog = data.scene.fog;
|
|
6755
|
-
if (fog) {
|
|
6756
|
-
if (fog.fogMode != undefined) scene.fogMode = fog.fogMode;
|
|
6757
|
-
if (fog.fogStart != undefined) scene.fogStart = fog.fogStart;
|
|
6758
|
-
if (fog.fogEnd != undefined) scene.fogEnd = fog.fogEnd;
|
|
6759
|
-
if (fog.fogDensity != undefined) scene.fogDensity = fog.fogDensity;
|
|
6760
|
-
if (fog.fogColor != undefined) scene.fogColor.copyFrom(fog.fogColor);
|
|
6761
|
-
}
|
|
6762
|
-
// Post Process
|
|
6763
|
-
var postProcessData = data.scene.postProcess;
|
|
6764
|
-
if (postProcessData) {
|
|
6765
|
-
engineCore.Logger.warn("Post Process is not supported in scene yet, please add PostProcess component in entity instead.");
|
|
6766
|
-
}
|
|
6767
|
-
// Ambient Occlusion
|
|
6768
|
-
var ambientOcclusion = data.scene.ambientOcclusion;
|
|
6769
|
-
if (ambientOcclusion) {
|
|
6770
|
-
var sceneAmbientOcclusion = scene.ambientOcclusion;
|
|
6771
|
-
sceneAmbientOcclusion.enabled = ambientOcclusion.enabledAmbientOcclusion;
|
|
6772
|
-
sceneAmbientOcclusion.intensity = ambientOcclusion.intensity;
|
|
6773
|
-
sceneAmbientOcclusion.radius = ambientOcclusion.radius;
|
|
6774
|
-
sceneAmbientOcclusion.bias = ambientOcclusion.bias;
|
|
6775
|
-
sceneAmbientOcclusion.power = ambientOcclusion.power;
|
|
6776
|
-
sceneAmbientOcclusion.quality = ambientOcclusion.quality;
|
|
6777
|
-
sceneAmbientOcclusion.bilateralThreshold = ambientOcclusion.bilateralThreshold;
|
|
6778
|
-
sceneAmbientOcclusion.minHorizonAngle = ambientOcclusion.minHorizonAngle;
|
|
6779
|
-
}
|
|
6780
|
-
return Promise.all(promises).then(function() {
|
|
6629
|
+
return applySceneData(scene, data.scene, resourceManager, data.refs).then(function() {
|
|
6781
6630
|
resolve(scene);
|
|
6782
6631
|
});
|
|
6783
6632
|
});
|