@galacean/engine-loader 1.2.0-beta.5 → 1.3.0-alpha.0
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 +494 -415
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +494 -415
- package/dist/module.js +495 -416
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/PrefabLoader.d.ts +5 -0
- package/types/gltf/GLTFResource.d.ts +1 -1
- package/types/gltf/GLTFSchema.d.ts +1 -1
- package/types/index.d.ts +3 -0
- package/types/prefab/PrefabParser.d.ts +11 -0
- package/types/prefab/PrefabResource.d.ts +25 -0
- package/types/resource-deserialize/index.d.ts +0 -1
- package/types/resource-deserialize/resources/parser/HierarchyParser.d.ts +12 -10
- package/types/resource-deserialize/resources/parser/ParserContext.d.ts +13 -12
- package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +2 -2
- package/types/resource-deserialize/resources/scene/SceneParser.d.ts +7 -4
- package/types/resource-deserialize/resources/schema/BasicSchema.d.ts +1 -1
- package/types/resource-deserialize/resources/schema/SceneSchema.d.ts +4 -3
package/dist/main.js
CHANGED
|
@@ -524,12 +524,51 @@ function _construct(Parent, args, Class) {
|
|
|
524
524
|
return _construct.apply(null, arguments);
|
|
525
525
|
}
|
|
526
526
|
|
|
527
|
+
exports.ParserType = void 0;
|
|
528
|
+
(function(ParserType) {
|
|
529
|
+
ParserType[ParserType["Prefab"] = 0] = "Prefab";
|
|
530
|
+
ParserType[ParserType["Scene"] = 1] = "Scene";
|
|
531
|
+
})(exports.ParserType || (exports.ParserType = {}));
|
|
532
|
+
/**
|
|
533
|
+
* Parser context
|
|
534
|
+
* @export
|
|
535
|
+
* @class ParserContext
|
|
536
|
+
* @template T
|
|
537
|
+
* @template I
|
|
538
|
+
*/ var ParserContext = /*#__PURE__*/ function() {
|
|
539
|
+
function ParserContext(engine, type, resource) {
|
|
540
|
+
if (type === void 0) type = 1;
|
|
541
|
+
this.engine = engine;
|
|
542
|
+
this.type = type;
|
|
543
|
+
this.resource = resource;
|
|
544
|
+
this.entityMap = new Map();
|
|
545
|
+
this.entityConfigMap = new Map();
|
|
546
|
+
this.components = new Map();
|
|
547
|
+
this.rootIds = [];
|
|
548
|
+
this.strippedIds = [];
|
|
549
|
+
this.resourceManager = engine.resourceManager;
|
|
550
|
+
}
|
|
551
|
+
var _proto = ParserContext.prototype;
|
|
552
|
+
/**
|
|
553
|
+
* Destroy the context.
|
|
554
|
+
* @memberof ParserContext
|
|
555
|
+
*/ _proto.clear = function clear() {
|
|
556
|
+
this.entityMap.clear();
|
|
557
|
+
this.components.clear();
|
|
558
|
+
this.entityConfigMap.clear();
|
|
559
|
+
this.rootIds.length = 0;
|
|
560
|
+
this.strippedIds.length = 0;
|
|
561
|
+
};
|
|
562
|
+
return ParserContext;
|
|
563
|
+
}();
|
|
564
|
+
|
|
527
565
|
var ReflectionParser = /*#__PURE__*/ function() {
|
|
528
566
|
function ReflectionParser(_context) {
|
|
529
567
|
this._context = _context;
|
|
530
568
|
}
|
|
531
569
|
var _proto = ReflectionParser.prototype;
|
|
532
570
|
_proto.parseEntity = function parseEntity(entityConfig) {
|
|
571
|
+
var _this = this;
|
|
533
572
|
return this._getEntityByConfig(entityConfig).then(function(entity) {
|
|
534
573
|
var _entityConfig_isActive;
|
|
535
574
|
entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : true;
|
|
@@ -539,6 +578,8 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
539
578
|
if (scale) entity.transform.scale.copyFrom(scale);
|
|
540
579
|
var _entityConfig_layer;
|
|
541
580
|
entity.layer = (_entityConfig_layer = entityConfig.layer) != null ? _entityConfig_layer : entity.layer;
|
|
581
|
+
// @ts-ignore
|
|
582
|
+
_this._context.type === exports.ParserType.Prefab && entity._markAsTemplate(_this._context.resource);
|
|
542
583
|
return entity;
|
|
543
584
|
});
|
|
544
585
|
};
|
|
@@ -601,26 +642,33 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
601
642
|
// class object
|
|
602
643
|
return this.parseClassObject(value);
|
|
603
644
|
} else if (ReflectionParser._isAssetRef(value)) {
|
|
645
|
+
var _this1 = this, context = _this1._context;
|
|
604
646
|
// reference object
|
|
605
647
|
// @ts-ignore
|
|
606
|
-
return
|
|
648
|
+
return context.resourceManager.getResourceByRef(value).then(function(resource) {
|
|
649
|
+
if (context.type === exports.ParserType.Prefab) {
|
|
650
|
+
// @ts-ignore
|
|
651
|
+
context.resource._addDependenceAsset(resource);
|
|
652
|
+
}
|
|
653
|
+
return resource;
|
|
654
|
+
});
|
|
607
655
|
} else if (ReflectionParser._isEntityRef(value)) {
|
|
608
656
|
// entity reference
|
|
609
657
|
return Promise.resolve(this._context.entityMap.get(value.entityId));
|
|
610
658
|
} else if (originValue) {
|
|
611
|
-
var
|
|
659
|
+
var _this2 = this, _loop = function(key) {
|
|
612
660
|
if (key === "methods") {
|
|
613
661
|
var methods = value[key];
|
|
614
662
|
for(var methodName in methods){
|
|
615
663
|
var methodParams = methods[methodName];
|
|
616
664
|
for(var i = 0, count = methodParams.length; i < count; i++){
|
|
617
665
|
var params = methodParams[i];
|
|
618
|
-
var promise =
|
|
666
|
+
var promise = _this2.parseMethod(originValue, methodName, params);
|
|
619
667
|
promises.push(promise);
|
|
620
668
|
}
|
|
621
669
|
}
|
|
622
670
|
} else {
|
|
623
|
-
promises.push(
|
|
671
|
+
promises.push(_this2.parseBasicType(value[key], originValue[key]).then(function(v) {
|
|
624
672
|
return originValue[key] = v;
|
|
625
673
|
}));
|
|
626
674
|
}
|
|
@@ -636,15 +684,23 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
636
684
|
return Promise.resolve(value);
|
|
637
685
|
};
|
|
638
686
|
_proto._getEntityByConfig = function _getEntityByConfig(entityConfig) {
|
|
687
|
+
var _this = this;
|
|
639
688
|
// @ts-ignore
|
|
640
689
|
var assetRefId = entityConfig.assetRefId;
|
|
641
690
|
var engine = this._context.engine;
|
|
642
691
|
if (assetRefId) {
|
|
643
|
-
return engine.resourceManager
|
|
692
|
+
return engine.resourceManager// @ts-ignore
|
|
693
|
+
.getResourceByRef({
|
|
644
694
|
refId: assetRefId,
|
|
645
695
|
key: entityConfig.key,
|
|
646
696
|
isClone: entityConfig.isClone
|
|
647
697
|
}).then(function(entity) {
|
|
698
|
+
// @ts-ignore
|
|
699
|
+
var resource = engine.resourceManager._objectPool[assetRefId];
|
|
700
|
+
if (_this._context.type === exports.ParserType.Prefab) {
|
|
701
|
+
// @ts-ignore
|
|
702
|
+
_this._context.resource._addDependenceAsset(resource);
|
|
703
|
+
}
|
|
648
704
|
entity.name = entityConfig.name;
|
|
649
705
|
return entity;
|
|
650
706
|
});
|
|
@@ -671,374 +727,6 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
671
727
|
ReflectionParser.customParseComponentHandles = new Map();
|
|
672
728
|
})();
|
|
673
729
|
|
|
674
|
-
/**
|
|
675
|
-
* Parser context
|
|
676
|
-
* @export
|
|
677
|
-
* @abstract
|
|
678
|
-
* @class ParserContext
|
|
679
|
-
* @template T
|
|
680
|
-
* @template I
|
|
681
|
-
*/ var ParserContext = /*#__PURE__*/ function() {
|
|
682
|
-
function ParserContext(originalData, engine, target) {
|
|
683
|
-
this.originalData = originalData;
|
|
684
|
-
this.engine = engine;
|
|
685
|
-
this.target = target;
|
|
686
|
-
this.entityMap = new Map();
|
|
687
|
-
this.components = new Map();
|
|
688
|
-
this.assets = new Map();
|
|
689
|
-
this.entityConfigMap = new Map();
|
|
690
|
-
this.rootIds = [];
|
|
691
|
-
this.strippedIds = [];
|
|
692
|
-
this.resourceManager = engine.resourceManager;
|
|
693
|
-
}
|
|
694
|
-
var _proto = ParserContext.prototype;
|
|
695
|
-
/**
|
|
696
|
-
* Destroy the context.
|
|
697
|
-
* @abstract
|
|
698
|
-
* @memberof ParserContext
|
|
699
|
-
*/ _proto.destroy = function destroy() {
|
|
700
|
-
this.entityMap.clear();
|
|
701
|
-
this.components.clear();
|
|
702
|
-
this.assets.clear();
|
|
703
|
-
this.entityConfigMap.clear();
|
|
704
|
-
this.rootIds.length = 0;
|
|
705
|
-
};
|
|
706
|
-
return ParserContext;
|
|
707
|
-
}();
|
|
708
|
-
|
|
709
|
-
var PrefabParserContext = /*#__PURE__*/ function(ParserContext1) {
|
|
710
|
-
_inherits(PrefabParserContext, ParserContext1);
|
|
711
|
-
function PrefabParserContext() {
|
|
712
|
-
return ParserContext1.apply(this, arguments);
|
|
713
|
-
}
|
|
714
|
-
return PrefabParserContext;
|
|
715
|
-
}(ParserContext);
|
|
716
|
-
|
|
717
|
-
function _array_like_to_array(arr, len) {
|
|
718
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
719
|
-
|
|
720
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
721
|
-
|
|
722
|
-
return arr2;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
726
|
-
if (!o) return;
|
|
727
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
728
|
-
|
|
729
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
730
|
-
|
|
731
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
732
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
733
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
737
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
738
|
-
|
|
739
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
740
|
-
// Fallback for engines without symbol support
|
|
741
|
-
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
742
|
-
if (it) o = it;
|
|
743
|
-
|
|
744
|
-
var i = 0;
|
|
745
|
-
|
|
746
|
-
return function() {
|
|
747
|
-
if (i >= o.length) return { done: true };
|
|
748
|
-
|
|
749
|
-
return { done: false, value: o[i++] };
|
|
750
|
-
};
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
var HierarchyParser = /*#__PURE__*/ function() {
|
|
757
|
-
function HierarchyParser(context) {
|
|
758
|
-
var _this = this;
|
|
759
|
-
this.context = context;
|
|
760
|
-
this.prefabContextMap = new WeakMap();
|
|
761
|
-
this.prefabPromiseMap = new Map();
|
|
762
|
-
this._engine = this.context.engine;
|
|
763
|
-
this._organizeEntities = this._organizeEntities.bind(this);
|
|
764
|
-
this._parseComponents = this._parseComponents.bind(this);
|
|
765
|
-
this._parsePrefabModification = this._parsePrefabModification.bind(this);
|
|
766
|
-
this._parsePrefabRemovedEntities = this._parsePrefabRemovedEntities.bind(this);
|
|
767
|
-
this._parsePrefabRemovedComponents = this._parsePrefabRemovedComponents.bind(this);
|
|
768
|
-
this._clearAndResolve = this._clearAndResolve.bind(this);
|
|
769
|
-
this.promise = new Promise(function(resolve, reject) {
|
|
770
|
-
_this._reject = reject;
|
|
771
|
-
_this._resolve = resolve;
|
|
772
|
-
});
|
|
773
|
-
this._reflectionParser = new ReflectionParser(context);
|
|
774
|
-
}
|
|
775
|
-
var _proto = HierarchyParser.prototype;
|
|
776
|
-
/** start parse the scene or prefab or others */ _proto.start = function start() {
|
|
777
|
-
this._parseEntities().then(this._organizeEntities).then(this._parseComponents).then(this._parsePrefabModification).then(this._parsePrefabRemovedEntities).then(this._parsePrefabRemovedComponents).then(this._clearAndResolve).then(this._resolve).catch(this._reject);
|
|
778
|
-
};
|
|
779
|
-
_proto._parseEntities = function _parseEntities() {
|
|
780
|
-
var _this = this;
|
|
781
|
-
var entitiesConfig = this.context.originalData.entities;
|
|
782
|
-
var entityConfigMap = this.context.entityConfigMap;
|
|
783
|
-
var entityMap = this.context.entityMap;
|
|
784
|
-
var engine = this._engine;
|
|
785
|
-
var promises = entitiesConfig.map(function(entityConfig) {
|
|
786
|
-
var _entityConfig_strippedId;
|
|
787
|
-
var id = (_entityConfig_strippedId = entityConfig.strippedId) != null ? _entityConfig_strippedId : entityConfig.id;
|
|
788
|
-
entityConfig.id = id;
|
|
789
|
-
entityConfigMap.set(id, entityConfig);
|
|
790
|
-
return _this._getEntityByConfig(entityConfig, engine);
|
|
791
|
-
});
|
|
792
|
-
return Promise.all(promises).then(function(entities) {
|
|
793
|
-
for(var i = 0, l = entities.length; i < l; i++){
|
|
794
|
-
entityMap.set(entitiesConfig[i].id, entities[i]);
|
|
795
|
-
}
|
|
796
|
-
return entities;
|
|
797
|
-
});
|
|
798
|
-
};
|
|
799
|
-
_proto._parseComponents = function _parseComponents() {
|
|
800
|
-
var entitiesConfig = this.context.originalData.entities;
|
|
801
|
-
var entityMap = this.context.entityMap;
|
|
802
|
-
var components = this.context.components;
|
|
803
|
-
var promises = [];
|
|
804
|
-
for(var i = 0, l = entitiesConfig.length; i < l; i++){
|
|
805
|
-
var entityConfig = entitiesConfig[i];
|
|
806
|
-
var entity = entityMap.get(entityConfig.id);
|
|
807
|
-
for(var i1 = 0; i1 < entityConfig.components.length; i1++){
|
|
808
|
-
var componentConfig = entityConfig.components[i1];
|
|
809
|
-
var key = !componentConfig.refId ? componentConfig.class : componentConfig.refId;
|
|
810
|
-
var component = entity.addComponent(engineCore.Loader.getClass(key));
|
|
811
|
-
components.set(componentConfig.id, component);
|
|
812
|
-
var promise = this._reflectionParser.parsePropsAndMethods(component, componentConfig);
|
|
813
|
-
promises.push(promise);
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
return Promise.all(promises);
|
|
817
|
-
};
|
|
818
|
-
_proto._parsePrefabModification = function _parsePrefabModification() {
|
|
819
|
-
var _loop = function(i, l) {
|
|
820
|
-
var _modifications;
|
|
821
|
-
var entityConfig = entitiesConfig[i];
|
|
822
|
-
var id = entityConfig.id, modifications = entityConfig.modifications;
|
|
823
|
-
if ((_modifications = modifications) == null ? void 0 : _modifications.length) {
|
|
824
|
-
var _promises;
|
|
825
|
-
var rootEntity = entityMap.get(id);
|
|
826
|
-
(_promises = promises).push.apply(_promises, [].concat(modifications.map(function(modification) {
|
|
827
|
-
var target = modification.target, props = modification.props, methods = modification.methods;
|
|
828
|
-
var entityId = target.entityId, componentId = target.componentId;
|
|
829
|
-
var context = _this.prefabContextMap.get(rootEntity);
|
|
830
|
-
var targetEntity = context.entityMap.get(entityId);
|
|
831
|
-
var targetComponent = context.components.get(componentId);
|
|
832
|
-
if (targetComponent) {
|
|
833
|
-
return _this._reflectionParser.parsePropsAndMethods(targetComponent, {
|
|
834
|
-
props: props,
|
|
835
|
-
methods: methods
|
|
836
|
-
});
|
|
837
|
-
} else if (targetEntity) {
|
|
838
|
-
return Promise.resolve(_this._applyEntityData(targetEntity, props));
|
|
839
|
-
}
|
|
840
|
-
})));
|
|
841
|
-
}
|
|
842
|
-
};
|
|
843
|
-
var _this = this;
|
|
844
|
-
var entitiesConfig = this.context.originalData.entities;
|
|
845
|
-
var entityMap = this.context.entityMap;
|
|
846
|
-
var promises = [];
|
|
847
|
-
for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
|
|
848
|
-
return Promise.all(promises);
|
|
849
|
-
};
|
|
850
|
-
_proto._parsePrefabRemovedEntities = function _parsePrefabRemovedEntities() {
|
|
851
|
-
var _loop = function(i, l) {
|
|
852
|
-
var _removedEntities;
|
|
853
|
-
var entityConfig = entitiesConfig[i];
|
|
854
|
-
var id = entityConfig.id, removedEntities = entityConfig.removedEntities;
|
|
855
|
-
if ((_removedEntities = removedEntities) == null ? void 0 : _removedEntities.length) {
|
|
856
|
-
var _promises;
|
|
857
|
-
var rootEntity = entityMap.get(id);
|
|
858
|
-
(_promises = promises).push.apply(_promises, [].concat(removedEntities.map(function(target) {
|
|
859
|
-
var entityId = target.entityId;
|
|
860
|
-
var context = _this.prefabContextMap.get(rootEntity);
|
|
861
|
-
var targetEntity = context.entityMap.get(entityId);
|
|
862
|
-
if (targetEntity) {
|
|
863
|
-
targetEntity.destroy();
|
|
864
|
-
}
|
|
865
|
-
})));
|
|
866
|
-
}
|
|
867
|
-
};
|
|
868
|
-
var _this = this;
|
|
869
|
-
var entitiesConfig = this.context.originalData.entities;
|
|
870
|
-
var entityMap = this.context.entityMap;
|
|
871
|
-
var promises = [];
|
|
872
|
-
for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
|
|
873
|
-
return Promise.all(promises);
|
|
874
|
-
};
|
|
875
|
-
_proto._parsePrefabRemovedComponents = function _parsePrefabRemovedComponents() {
|
|
876
|
-
var _loop = function(i, l) {
|
|
877
|
-
var _removedComponents;
|
|
878
|
-
var entityConfig = entitiesConfig[i];
|
|
879
|
-
var id = entityConfig.id, removedComponents = entityConfig.removedComponents;
|
|
880
|
-
if ((_removedComponents = removedComponents) == null ? void 0 : _removedComponents.length) {
|
|
881
|
-
var _promises;
|
|
882
|
-
var rootEntity = entityMap.get(id);
|
|
883
|
-
(_promises = promises).concat.apply(_promises, [].concat(removedComponents.map(function(target) {
|
|
884
|
-
var componentId = target.componentId;
|
|
885
|
-
var context = _this.prefabContextMap.get(rootEntity);
|
|
886
|
-
var targetComponent = context.components.get(componentId);
|
|
887
|
-
if (targetComponent) {
|
|
888
|
-
targetComponent.destroy();
|
|
889
|
-
}
|
|
890
|
-
})));
|
|
891
|
-
}
|
|
892
|
-
};
|
|
893
|
-
var _this = this;
|
|
894
|
-
var entitiesConfig = this.context.originalData.entities;
|
|
895
|
-
var entityMap = this.context.entityMap;
|
|
896
|
-
var promises = [];
|
|
897
|
-
for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
|
|
898
|
-
return Promise.all(promises);
|
|
899
|
-
};
|
|
900
|
-
_proto._clearAndResolve = function _clearAndResolve() {
|
|
901
|
-
var target = this.context.target;
|
|
902
|
-
return target;
|
|
903
|
-
};
|
|
904
|
-
_proto._organizeEntities = function _organizeEntities() {
|
|
905
|
-
var _this_context = this.context, rootIds = _this_context.rootIds, strippedIds = _this_context.strippedIds;
|
|
906
|
-
var parentIds = rootIds.concat(strippedIds);
|
|
907
|
-
for(var _iterator = _create_for_of_iterator_helper_loose(parentIds), _step; !(_step = _iterator()).done;){
|
|
908
|
-
var parentId = _step.value;
|
|
909
|
-
this._parseChildren(parentId);
|
|
910
|
-
}
|
|
911
|
-
for(var i = 0; i < rootIds.length; i++){
|
|
912
|
-
this.handleRootEntity(rootIds[i]);
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
_proto._getEntityByConfig = function _getEntityByConfig(entityConfig, engine) {
|
|
916
|
-
var _this = this;
|
|
917
|
-
var entityPromise;
|
|
918
|
-
if (entityConfig.assetRefId) {
|
|
919
|
-
entityPromise = this._parseGLTF(entityConfig, engine);
|
|
920
|
-
} else if (entityConfig.strippedId) {
|
|
921
|
-
entityPromise = this._parseStrippedEntity(entityConfig);
|
|
922
|
-
} else {
|
|
923
|
-
entityPromise = this._parseEntity(entityConfig, engine);
|
|
924
|
-
}
|
|
925
|
-
return entityPromise.then(function(entity) {
|
|
926
|
-
return _this._applyEntityData(entity, entityConfig);
|
|
927
|
-
});
|
|
928
|
-
};
|
|
929
|
-
_proto._parseEntity = function _parseEntity(entityConfig, engine) {
|
|
930
|
-
var entity = new engineCore.Entity(engine, entityConfig.name);
|
|
931
|
-
if (!entityConfig.parent) this.context.rootIds.push(entityConfig.id);
|
|
932
|
-
return Promise.resolve(entity);
|
|
933
|
-
};
|
|
934
|
-
_proto._parseGLTF = function _parseGLTF(entityConfig, engine) {
|
|
935
|
-
var _this = this;
|
|
936
|
-
var assetRefId = entityConfig.assetRefId;
|
|
937
|
-
var context = new ParserContext(null, engine);
|
|
938
|
-
return engine.resourceManager// @ts-ignore
|
|
939
|
-
.getResourceByRef({
|
|
940
|
-
refId: assetRefId
|
|
941
|
-
}).then(function(glTFResource) {
|
|
942
|
-
var entity = glTFResource.instantiateSceneRoot();
|
|
943
|
-
if (!entityConfig.parent) _this.context.rootIds.push(entityConfig.id);
|
|
944
|
-
_this._traverseAddEntityToMap(entity, context, "");
|
|
945
|
-
_this.prefabContextMap.set(entity, context);
|
|
946
|
-
var cbArray = _this.prefabPromiseMap.get(entityConfig.id);
|
|
947
|
-
cbArray && cbArray.forEach(function(cb) {
|
|
948
|
-
cb.resolve(context);
|
|
949
|
-
});
|
|
950
|
-
return entity;
|
|
951
|
-
});
|
|
952
|
-
};
|
|
953
|
-
_proto._parseStrippedEntity = function _parseStrippedEntity(entityConfig) {
|
|
954
|
-
var _this = this;
|
|
955
|
-
this.context.strippedIds.push(entityConfig.id);
|
|
956
|
-
return new Promise(function(resolve, reject) {
|
|
957
|
-
var _this_prefabPromiseMap_get;
|
|
958
|
-
var cbArray = (_this_prefabPromiseMap_get = _this.prefabPromiseMap.get(entityConfig.prefabInstanceId)) != null ? _this_prefabPromiseMap_get : [];
|
|
959
|
-
cbArray.push({
|
|
960
|
-
resolve: resolve,
|
|
961
|
-
reject: reject
|
|
962
|
-
});
|
|
963
|
-
_this.prefabPromiseMap.set(entityConfig.prefabInstanceId, cbArray);
|
|
964
|
-
}).then(function(context) {
|
|
965
|
-
var entityId = entityConfig.prefabSource.entityId;
|
|
966
|
-
return context.entityMap.get(entityId);
|
|
967
|
-
});
|
|
968
|
-
};
|
|
969
|
-
_proto._parseChildren = function _parseChildren(parentId) {
|
|
970
|
-
var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap;
|
|
971
|
-
var children = entityConfigMap.get(parentId).children;
|
|
972
|
-
if (children && children.length > 0) {
|
|
973
|
-
var parent = entityMap.get(parentId);
|
|
974
|
-
for(var i = 0; i < children.length; i++){
|
|
975
|
-
var childId = children[i];
|
|
976
|
-
var entity = entityMap.get(childId);
|
|
977
|
-
parent.addChild(entity);
|
|
978
|
-
this._parseChildren(childId);
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
};
|
|
982
|
-
_proto._applyEntityData = function _applyEntityData(entity, entityConfig) {
|
|
983
|
-
if (entityConfig === void 0) entityConfig = {};
|
|
984
|
-
var _entityConfig_isActive;
|
|
985
|
-
entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : entity.isActive;
|
|
986
|
-
var _entityConfig_name;
|
|
987
|
-
entity.name = (_entityConfig_name = entityConfig.name) != null ? _entityConfig_name : entity.name;
|
|
988
|
-
var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale, layer = entityConfig.layer;
|
|
989
|
-
if (position) entity.transform.position.copyFrom(position);
|
|
990
|
-
if (rotation) entity.transform.rotation.copyFrom(rotation);
|
|
991
|
-
if (scale) entity.transform.scale.copyFrom(scale);
|
|
992
|
-
if (layer) entity.layer = layer;
|
|
993
|
-
return entity;
|
|
994
|
-
};
|
|
995
|
-
_proto._traverseAddEntityToMap = function _traverseAddEntityToMap(entity, context, path) {
|
|
996
|
-
var entityMap = context.entityMap, components = context.components;
|
|
997
|
-
var componentsMap = {};
|
|
998
|
-
var componentIndexMap = {};
|
|
999
|
-
entityMap.set(path, entity);
|
|
1000
|
-
// @ts-ignore
|
|
1001
|
-
entity._components.forEach(function(component) {
|
|
1002
|
-
// @ts-ignore
|
|
1003
|
-
var name = engineCore.Loader.getClassName(component.constructor);
|
|
1004
|
-
if (!componentsMap[name]) {
|
|
1005
|
-
componentsMap[name] = entity.getComponents(component.constructor, []);
|
|
1006
|
-
componentIndexMap[name] = 0;
|
|
1007
|
-
}
|
|
1008
|
-
components.set(path + ":" + name + "/" + componentIndexMap[name]++, component);
|
|
1009
|
-
});
|
|
1010
|
-
for(var i = 0, n = entity.children.length; i < n; i++){
|
|
1011
|
-
var child = entity.children[i];
|
|
1012
|
-
var childPath = path ? path + "/" + i : "" + i;
|
|
1013
|
-
this._traverseAddEntityToMap(child, context, childPath);
|
|
1014
|
-
}
|
|
1015
|
-
};
|
|
1016
|
-
return HierarchyParser;
|
|
1017
|
-
}();
|
|
1018
|
-
|
|
1019
|
-
var PrefabParser = /*#__PURE__*/ function(HierarchyParser1) {
|
|
1020
|
-
_inherits(PrefabParser, HierarchyParser1);
|
|
1021
|
-
function PrefabParser() {
|
|
1022
|
-
return HierarchyParser1.apply(this, arguments);
|
|
1023
|
-
}
|
|
1024
|
-
var _proto = PrefabParser.prototype;
|
|
1025
|
-
_proto.handleRootEntity = function handleRootEntity(id) {
|
|
1026
|
-
this.context.target = this.context.entityMap.get(id);
|
|
1027
|
-
};
|
|
1028
|
-
/**
|
|
1029
|
-
* Parse prefab data.
|
|
1030
|
-
* @param engine - the engine of the parser context
|
|
1031
|
-
* @param prefabData - prefab data which is exported by editor
|
|
1032
|
-
* @returns a promise of prefab
|
|
1033
|
-
*/ PrefabParser.parse = function parse(engine, prefabData) {
|
|
1034
|
-
var context = new PrefabParserContext(prefabData, engine);
|
|
1035
|
-
var parser = new PrefabParser(context);
|
|
1036
|
-
parser.start();
|
|
1037
|
-
return parser;
|
|
1038
|
-
};
|
|
1039
|
-
return PrefabParser;
|
|
1040
|
-
}(HierarchyParser);
|
|
1041
|
-
|
|
1042
730
|
exports.InterpolableValueType = void 0;
|
|
1043
731
|
(function(InterpolableValueType) {
|
|
1044
732
|
InterpolableValueType[InterpolableValueType["Float"] = 0] = "Float";
|
|
@@ -1233,45 +921,384 @@ exports.AnimationClipDecoder = /*#__PURE__*/ function() {
|
|
|
1233
921
|
break;
|
|
1234
922
|
}
|
|
1235
923
|
}
|
|
1236
|
-
clip.addCurveBinding(relativePath, componentType, property, getProperty, curve);
|
|
924
|
+
clip.addCurveBinding(relativePath, componentType, property, getProperty, curve);
|
|
925
|
+
}
|
|
926
|
+
resolve(clip);
|
|
927
|
+
});
|
|
928
|
+
};
|
|
929
|
+
return AnimationClipDecoder;
|
|
930
|
+
}();
|
|
931
|
+
exports.AnimationClipDecoder = __decorate([
|
|
932
|
+
decoder("AnimationClip")
|
|
933
|
+
], exports.AnimationClipDecoder);
|
|
934
|
+
|
|
935
|
+
exports.SpecularMode = void 0;
|
|
936
|
+
(function(SpecularMode) {
|
|
937
|
+
SpecularMode["Sky"] = "Sky";
|
|
938
|
+
SpecularMode["Custom"] = "Custom";
|
|
939
|
+
})(exports.SpecularMode || (exports.SpecularMode = {}));
|
|
940
|
+
|
|
941
|
+
function _instanceof(left, right) {
|
|
942
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
943
|
+
return !!right[Symbol.hasInstance](left);
|
|
944
|
+
} else return left instanceof right;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
function _array_like_to_array(arr, len) {
|
|
948
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
949
|
+
|
|
950
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
951
|
+
|
|
952
|
+
return arr2;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
956
|
+
if (!o) return;
|
|
957
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
958
|
+
|
|
959
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
960
|
+
|
|
961
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
962
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
963
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
967
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
968
|
+
|
|
969
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
970
|
+
// Fallback for engines without symbol support
|
|
971
|
+
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
972
|
+
if (it) o = it;
|
|
973
|
+
|
|
974
|
+
var i = 0;
|
|
975
|
+
|
|
976
|
+
return function() {
|
|
977
|
+
if (i >= o.length) return { done: true };
|
|
978
|
+
|
|
979
|
+
return { done: false, value: o[i++] };
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
/**
|
|
987
|
+
* The Prefab resource.
|
|
988
|
+
*/ var PrefabResource = /*#__PURE__*/ function(ReferResource1) {
|
|
989
|
+
_inherits(PrefabResource, ReferResource1);
|
|
990
|
+
function PrefabResource(engine, url) {
|
|
991
|
+
var _this;
|
|
992
|
+
_this = ReferResource1.call(this, engine) || this;
|
|
993
|
+
_this.url = url;
|
|
994
|
+
_this._dependenceAssets = new Set();
|
|
995
|
+
return _this;
|
|
996
|
+
}
|
|
997
|
+
var _proto = PrefabResource.prototype;
|
|
998
|
+
/**
|
|
999
|
+
* Instantiate prefab.
|
|
1000
|
+
* @returns prefab's root entity
|
|
1001
|
+
*/ _proto.instantiate = function instantiate() {
|
|
1002
|
+
var _this__root;
|
|
1003
|
+
return (_this__root = this._root) == null ? void 0 : _this__root.clone();
|
|
1004
|
+
};
|
|
1005
|
+
/**
|
|
1006
|
+
* @internal
|
|
1007
|
+
*/ _proto._addDependenceAsset = function _addDependenceAsset(resource) {
|
|
1008
|
+
this._dependenceAssets.add(resource);
|
|
1009
|
+
// @ts-ignore
|
|
1010
|
+
resource._associationSuperResource(this);
|
|
1011
|
+
};
|
|
1012
|
+
_proto._onDestroy = function _onDestroy() {
|
|
1013
|
+
var _this = this;
|
|
1014
|
+
ReferResource1.prototype._onDestroy.call(this);
|
|
1015
|
+
this._root.destroy();
|
|
1016
|
+
this._dependenceAssets.forEach(function(asset) {
|
|
1017
|
+
// @ts-ignore
|
|
1018
|
+
asset._disassociationSuperResource(_this);
|
|
1019
|
+
});
|
|
1020
|
+
};
|
|
1021
|
+
return PrefabResource;
|
|
1022
|
+
}(engineCore.ReferResource);
|
|
1023
|
+
|
|
1024
|
+
/** @Internal */ var HierarchyParser = /*#__PURE__*/ function() {
|
|
1025
|
+
function HierarchyParser(data, context) {
|
|
1026
|
+
var _this = this;
|
|
1027
|
+
this.data = data;
|
|
1028
|
+
this.context = context;
|
|
1029
|
+
this._prefabContextMap = new WeakMap();
|
|
1030
|
+
this._prefabPromiseMap = new Map();
|
|
1031
|
+
this._engine = this.context.engine;
|
|
1032
|
+
this._organizeEntities = this._organizeEntities.bind(this);
|
|
1033
|
+
this._parseComponents = this._parseComponents.bind(this);
|
|
1034
|
+
this._parsePrefabModification = this._parsePrefabModification.bind(this);
|
|
1035
|
+
this._parsePrefabRemovedEntities = this._parsePrefabRemovedEntities.bind(this);
|
|
1036
|
+
this._parsePrefabRemovedComponents = this._parsePrefabRemovedComponents.bind(this);
|
|
1037
|
+
this._clearAndResolve = this._clearAndResolve.bind(this);
|
|
1038
|
+
this.promise = new Promise(function(resolve, reject) {
|
|
1039
|
+
_this._reject = reject;
|
|
1040
|
+
_this._resolve = resolve;
|
|
1041
|
+
});
|
|
1042
|
+
this._reflectionParser = new ReflectionParser(context);
|
|
1043
|
+
}
|
|
1044
|
+
var _proto = HierarchyParser.prototype;
|
|
1045
|
+
/** start parse the scene or prefab or others */ _proto.start = function start() {
|
|
1046
|
+
this._parseEntities().then(this._organizeEntities).then(this._parseComponents).then(this._parsePrefabModification).then(this._parsePrefabRemovedEntities).then(this._parsePrefabRemovedComponents).then(this._clearAndResolve).then(this._resolve).catch(this._reject);
|
|
1047
|
+
};
|
|
1048
|
+
_proto._parseEntities = function _parseEntities() {
|
|
1049
|
+
var _this = this;
|
|
1050
|
+
var entitiesConfig = this.data.entities;
|
|
1051
|
+
var entityConfigMap = this.context.entityConfigMap;
|
|
1052
|
+
var entityMap = this.context.entityMap;
|
|
1053
|
+
var engine = this._engine;
|
|
1054
|
+
var promises = entitiesConfig.map(function(entityConfig) {
|
|
1055
|
+
var _entityConfig_strippedId;
|
|
1056
|
+
var id = (_entityConfig_strippedId = entityConfig.strippedId) != null ? _entityConfig_strippedId : entityConfig.id;
|
|
1057
|
+
entityConfig.id = id;
|
|
1058
|
+
entityConfigMap.set(id, entityConfig);
|
|
1059
|
+
return _this._getEntityByConfig(entityConfig, engine);
|
|
1060
|
+
});
|
|
1061
|
+
return Promise.all(promises).then(function(entities) {
|
|
1062
|
+
for(var i = 0, l = entities.length; i < l; i++){
|
|
1063
|
+
entityMap.set(entitiesConfig[i].id, entities[i]);
|
|
1064
|
+
}
|
|
1065
|
+
return entities;
|
|
1066
|
+
});
|
|
1067
|
+
};
|
|
1068
|
+
_proto._parseComponents = function _parseComponents() {
|
|
1069
|
+
var entitiesConfig = this.data.entities;
|
|
1070
|
+
var entityMap = this.context.entityMap;
|
|
1071
|
+
var components = this.context.components;
|
|
1072
|
+
var promises = [];
|
|
1073
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++){
|
|
1074
|
+
var entityConfig = entitiesConfig[i];
|
|
1075
|
+
var entity = entityMap.get(entityConfig.id);
|
|
1076
|
+
for(var i1 = 0; i1 < entityConfig.components.length; i1++){
|
|
1077
|
+
var componentConfig = entityConfig.components[i1];
|
|
1078
|
+
var key = !componentConfig.refId ? componentConfig.class : componentConfig.refId;
|
|
1079
|
+
var component = entity.addComponent(engineCore.Loader.getClass(key));
|
|
1080
|
+
components.set(componentConfig.id, component);
|
|
1081
|
+
var promise = this._reflectionParser.parsePropsAndMethods(component, componentConfig);
|
|
1082
|
+
promises.push(promise);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
return Promise.all(promises);
|
|
1086
|
+
};
|
|
1087
|
+
_proto._parsePrefabModification = function _parsePrefabModification() {
|
|
1088
|
+
var _loop = function(i, l) {
|
|
1089
|
+
var _modifications;
|
|
1090
|
+
var entityConfig = entitiesConfig[i];
|
|
1091
|
+
var id = entityConfig.id, modifications = entityConfig.modifications;
|
|
1092
|
+
if ((_modifications = modifications) == null ? void 0 : _modifications.length) {
|
|
1093
|
+
var _promises;
|
|
1094
|
+
var rootEntity = entityMap.get(id);
|
|
1095
|
+
(_promises = promises).push.apply(_promises, [].concat(modifications.map(function(modification) {
|
|
1096
|
+
var target = modification.target, props = modification.props, methods = modification.methods;
|
|
1097
|
+
var entityId = target.entityId, componentId = target.componentId;
|
|
1098
|
+
var context = _this._prefabContextMap.get(rootEntity);
|
|
1099
|
+
var targetEntity = context.entityMap.get(entityId);
|
|
1100
|
+
var targetComponent = context.components.get(componentId);
|
|
1101
|
+
if (targetComponent) {
|
|
1102
|
+
return _this._reflectionParser.parsePropsAndMethods(targetComponent, {
|
|
1103
|
+
props: props,
|
|
1104
|
+
methods: methods
|
|
1105
|
+
});
|
|
1106
|
+
} else if (targetEntity) {
|
|
1107
|
+
return Promise.resolve(_this._applyEntityData(targetEntity, props));
|
|
1108
|
+
}
|
|
1109
|
+
})));
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
var _this = this;
|
|
1113
|
+
var entitiesConfig = this.data.entities;
|
|
1114
|
+
var entityMap = this.context.entityMap;
|
|
1115
|
+
var promises = [];
|
|
1116
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
|
|
1117
|
+
return Promise.all(promises);
|
|
1118
|
+
};
|
|
1119
|
+
_proto._parsePrefabRemovedEntities = function _parsePrefabRemovedEntities() {
|
|
1120
|
+
var _loop = function(i, l) {
|
|
1121
|
+
var _removedEntities;
|
|
1122
|
+
var entityConfig = entitiesConfig[i];
|
|
1123
|
+
var id = entityConfig.id, removedEntities = entityConfig.removedEntities;
|
|
1124
|
+
if ((_removedEntities = removedEntities) == null ? void 0 : _removedEntities.length) {
|
|
1125
|
+
var _promises;
|
|
1126
|
+
var rootEntity = entityMap.get(id);
|
|
1127
|
+
(_promises = promises).push.apply(_promises, [].concat(removedEntities.map(function(target) {
|
|
1128
|
+
var entityId = target.entityId;
|
|
1129
|
+
var context = _this._prefabContextMap.get(rootEntity);
|
|
1130
|
+
var targetEntity = context.entityMap.get(entityId);
|
|
1131
|
+
if (targetEntity) {
|
|
1132
|
+
targetEntity.destroy();
|
|
1133
|
+
}
|
|
1134
|
+
})));
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
var _this = this;
|
|
1138
|
+
var entitiesConfig = this.data.entities;
|
|
1139
|
+
var entityMap = this.context.entityMap;
|
|
1140
|
+
var promises = [];
|
|
1141
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
|
|
1142
|
+
return Promise.all(promises);
|
|
1143
|
+
};
|
|
1144
|
+
_proto._parsePrefabRemovedComponents = function _parsePrefabRemovedComponents() {
|
|
1145
|
+
var _loop = function(i, l) {
|
|
1146
|
+
var _removedComponents;
|
|
1147
|
+
var entityConfig = entitiesConfig[i];
|
|
1148
|
+
var id = entityConfig.id, removedComponents = entityConfig.removedComponents;
|
|
1149
|
+
if ((_removedComponents = removedComponents) == null ? void 0 : _removedComponents.length) {
|
|
1150
|
+
var _promises;
|
|
1151
|
+
var rootEntity = entityMap.get(id);
|
|
1152
|
+
(_promises = promises).concat.apply(_promises, [].concat(removedComponents.map(function(target) {
|
|
1153
|
+
var componentId = target.componentId;
|
|
1154
|
+
var context = _this._prefabContextMap.get(rootEntity);
|
|
1155
|
+
var targetComponent = context.components.get(componentId);
|
|
1156
|
+
if (targetComponent) {
|
|
1157
|
+
targetComponent.destroy();
|
|
1158
|
+
}
|
|
1159
|
+
})));
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
var _this = this;
|
|
1163
|
+
var entitiesConfig = this.data.entities;
|
|
1164
|
+
var entityMap = this.context.entityMap;
|
|
1165
|
+
var promises = [];
|
|
1166
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
|
|
1167
|
+
return Promise.all(promises);
|
|
1168
|
+
};
|
|
1169
|
+
_proto._organizeEntities = function _organizeEntities() {
|
|
1170
|
+
var _this_context = this.context, rootIds = _this_context.rootIds, strippedIds = _this_context.strippedIds;
|
|
1171
|
+
var parentIds = rootIds.concat(strippedIds);
|
|
1172
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(parentIds), _step; !(_step = _iterator()).done;){
|
|
1173
|
+
var parentId = _step.value;
|
|
1174
|
+
this._parseChildren(parentId);
|
|
1175
|
+
}
|
|
1176
|
+
for(var i = 0; i < rootIds.length; i++){
|
|
1177
|
+
this._handleRootEntity(rootIds[i]);
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
_proto._getEntityByConfig = function _getEntityByConfig(entityConfig, engine) {
|
|
1181
|
+
var _this = this;
|
|
1182
|
+
var entityPromise;
|
|
1183
|
+
if (entityConfig.assetRefId) {
|
|
1184
|
+
entityPromise = this._parsePrefab(entityConfig, engine);
|
|
1185
|
+
} else if (entityConfig.strippedId) {
|
|
1186
|
+
entityPromise = this._parseStrippedEntity(entityConfig);
|
|
1187
|
+
} else {
|
|
1188
|
+
entityPromise = this._parseEntity(entityConfig, engine);
|
|
1189
|
+
}
|
|
1190
|
+
return entityPromise.then(function(entity) {
|
|
1191
|
+
return _this._applyEntityData(entity, entityConfig);
|
|
1192
|
+
});
|
|
1193
|
+
};
|
|
1194
|
+
_proto._parseEntity = function _parseEntity(entityConfig, engine) {
|
|
1195
|
+
var entity = new engineCore.Entity(engine, entityConfig.name);
|
|
1196
|
+
if (!entityConfig.parent) this.context.rootIds.push(entityConfig.id);
|
|
1197
|
+
return Promise.resolve(entity);
|
|
1198
|
+
};
|
|
1199
|
+
_proto._parsePrefab = function _parsePrefab(entityConfig, engine) {
|
|
1200
|
+
var _this = this;
|
|
1201
|
+
var assetRefId = entityConfig.assetRefId;
|
|
1202
|
+
return engine.resourceManager// @ts-ignore
|
|
1203
|
+
.getResourceByRef({
|
|
1204
|
+
refId: assetRefId
|
|
1205
|
+
}).then(function(prefabResource) {
|
|
1206
|
+
var entity = _instanceof(prefabResource, PrefabResource) ? prefabResource.instantiate() : prefabResource.instantiateSceneRoot();
|
|
1207
|
+
var instanceContext = new ParserContext(engine, exports.ParserType.Prefab, null);
|
|
1208
|
+
if (!entityConfig.parent) _this.context.rootIds.push(entityConfig.id);
|
|
1209
|
+
_this._generateInstanceContext(entity, instanceContext, "");
|
|
1210
|
+
_this._prefabContextMap.set(entity, instanceContext);
|
|
1211
|
+
var cbArray = _this._prefabPromiseMap.get(entityConfig.id);
|
|
1212
|
+
if (cbArray) {
|
|
1213
|
+
for(var i = 0, n = cbArray.length; i < n; i++){
|
|
1214
|
+
cbArray[i].resolve(instanceContext);
|
|
1215
|
+
}
|
|
1237
1216
|
}
|
|
1238
|
-
|
|
1217
|
+
return entity;
|
|
1239
1218
|
});
|
|
1240
1219
|
};
|
|
1241
|
-
|
|
1220
|
+
_proto._parseStrippedEntity = function _parseStrippedEntity(entityConfig) {
|
|
1221
|
+
var _this = this;
|
|
1222
|
+
this.context.strippedIds.push(entityConfig.id);
|
|
1223
|
+
return new Promise(function(resolve, reject) {
|
|
1224
|
+
var _this__prefabPromiseMap_get;
|
|
1225
|
+
var cbArray = (_this__prefabPromiseMap_get = _this._prefabPromiseMap.get(entityConfig.prefabInstanceId)) != null ? _this__prefabPromiseMap_get : [];
|
|
1226
|
+
cbArray.push({
|
|
1227
|
+
resolve: resolve,
|
|
1228
|
+
reject: reject
|
|
1229
|
+
});
|
|
1230
|
+
_this._prefabPromiseMap.set(entityConfig.prefabInstanceId, cbArray);
|
|
1231
|
+
}).then(function(context) {
|
|
1232
|
+
var entityId = entityConfig.prefabSource.entityId;
|
|
1233
|
+
return context.entityMap.get(entityId);
|
|
1234
|
+
});
|
|
1235
|
+
};
|
|
1236
|
+
_proto._parseChildren = function _parseChildren(parentId) {
|
|
1237
|
+
var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap;
|
|
1238
|
+
var children = entityConfigMap.get(parentId).children;
|
|
1239
|
+
if (children && children.length > 0) {
|
|
1240
|
+
var parent = entityMap.get(parentId);
|
|
1241
|
+
for(var i = 0; i < children.length; i++){
|
|
1242
|
+
var childId = children[i];
|
|
1243
|
+
var entity = entityMap.get(childId);
|
|
1244
|
+
parent.addChild(entity);
|
|
1245
|
+
this._parseChildren(childId);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
1249
|
+
_proto._applyEntityData = function _applyEntityData(entity, entityConfig) {
|
|
1250
|
+
if (entityConfig === void 0) entityConfig = {};
|
|
1251
|
+
var _entityConfig_isActive;
|
|
1252
|
+
entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : entity.isActive;
|
|
1253
|
+
var _entityConfig_name;
|
|
1254
|
+
entity.name = (_entityConfig_name = entityConfig.name) != null ? _entityConfig_name : entity.name;
|
|
1255
|
+
var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale, layer = entityConfig.layer;
|
|
1256
|
+
if (position) entity.transform.position.copyFrom(position);
|
|
1257
|
+
if (rotation) entity.transform.rotation.copyFrom(rotation);
|
|
1258
|
+
if (scale) entity.transform.scale.copyFrom(scale);
|
|
1259
|
+
if (layer) entity.layer = layer;
|
|
1260
|
+
return entity;
|
|
1261
|
+
};
|
|
1262
|
+
_proto._generateInstanceContext = function _generateInstanceContext(entity, context, path) {
|
|
1263
|
+
var entityMap = context.entityMap, components = context.components;
|
|
1264
|
+
var componentsMap = {};
|
|
1265
|
+
var componentIndexMap = {};
|
|
1266
|
+
entityMap.set(path, entity);
|
|
1267
|
+
// @ts-ignore
|
|
1268
|
+
entity._components.forEach(function(component) {
|
|
1269
|
+
// @ts-ignore
|
|
1270
|
+
var name = engineCore.Loader.getClassName(component.constructor);
|
|
1271
|
+
if (!componentsMap[name]) {
|
|
1272
|
+
componentsMap[name] = entity.getComponents(component.constructor, []);
|
|
1273
|
+
componentIndexMap[name] = 0;
|
|
1274
|
+
}
|
|
1275
|
+
components.set(path + ":" + name + "/" + componentIndexMap[name]++, component);
|
|
1276
|
+
});
|
|
1277
|
+
for(var i = 0, n = entity.children.length; i < n; i++){
|
|
1278
|
+
var child = entity.children[i];
|
|
1279
|
+
var childPath = path ? path + "/" + i : "" + i;
|
|
1280
|
+
this._generateInstanceContext(child, context, childPath);
|
|
1281
|
+
}
|
|
1282
|
+
};
|
|
1283
|
+
return HierarchyParser;
|
|
1242
1284
|
}();
|
|
1243
|
-
exports.AnimationClipDecoder = __decorate([
|
|
1244
|
-
decoder("AnimationClip")
|
|
1245
|
-
], exports.AnimationClipDecoder);
|
|
1246
|
-
|
|
1247
|
-
exports.SpecularMode = void 0;
|
|
1248
|
-
(function(SpecularMode) {
|
|
1249
|
-
SpecularMode["Sky"] = "Sky";
|
|
1250
|
-
SpecularMode["Custom"] = "Custom";
|
|
1251
|
-
})(exports.SpecularMode || (exports.SpecularMode = {}));
|
|
1252
1285
|
|
|
1253
|
-
var
|
|
1254
|
-
_inherits(
|
|
1255
|
-
function
|
|
1286
|
+
/** @Internal */ var SceneParser = /*#__PURE__*/ function(HierarchyParser1) {
|
|
1287
|
+
_inherits(SceneParser, HierarchyParser1);
|
|
1288
|
+
function SceneParser(data, context, scene) {
|
|
1256
1289
|
var _this;
|
|
1257
|
-
_this =
|
|
1258
|
-
_this.originalData = originalData;
|
|
1259
|
-
_this.engine = engine;
|
|
1290
|
+
_this = HierarchyParser1.call(this, data, context) || this;
|
|
1260
1291
|
_this.scene = scene;
|
|
1261
1292
|
return _this;
|
|
1262
1293
|
}
|
|
1263
|
-
return SceneParserContext;
|
|
1264
|
-
}(ParserContext);
|
|
1265
|
-
|
|
1266
|
-
/** @Internal */ var SceneParser = /*#__PURE__*/ function(HierarchyParser1) {
|
|
1267
|
-
_inherits(SceneParser, HierarchyParser1);
|
|
1268
|
-
function SceneParser() {
|
|
1269
|
-
return HierarchyParser1.apply(this, arguments);
|
|
1270
|
-
}
|
|
1271
1294
|
var _proto = SceneParser.prototype;
|
|
1272
|
-
_proto.
|
|
1273
|
-
var
|
|
1274
|
-
|
|
1295
|
+
_proto._handleRootEntity = function _handleRootEntity(id) {
|
|
1296
|
+
var entityMap = this.context.entityMap;
|
|
1297
|
+
this.scene.addRootEntity(entityMap.get(id));
|
|
1298
|
+
};
|
|
1299
|
+
_proto._clearAndResolve = function _clearAndResolve() {
|
|
1300
|
+
this.context.clear();
|
|
1301
|
+
return this.scene;
|
|
1275
1302
|
};
|
|
1276
1303
|
/**
|
|
1277
1304
|
* Parse scene data.
|
|
@@ -1280,10 +1307,12 @@ var SceneParserContext = /*#__PURE__*/ function(ParserContext1) {
|
|
|
1280
1307
|
* @returns a promise of scene
|
|
1281
1308
|
*/ SceneParser.parse = function parse(engine, sceneData) {
|
|
1282
1309
|
var scene = new engineCore.Scene(engine);
|
|
1283
|
-
var context = new
|
|
1284
|
-
var parser = new SceneParser(context);
|
|
1310
|
+
var context = new ParserContext(engine, exports.ParserType.Scene, scene);
|
|
1311
|
+
var parser = new SceneParser(sceneData, context, scene);
|
|
1285
1312
|
parser.start();
|
|
1286
|
-
return parser.promise
|
|
1313
|
+
return parser.promise.then(function() {
|
|
1314
|
+
return scene;
|
|
1315
|
+
});
|
|
1287
1316
|
};
|
|
1288
1317
|
return SceneParser;
|
|
1289
1318
|
}(HierarchyParser);
|
|
@@ -1664,7 +1693,7 @@ FontLoader = __decorate([
|
|
|
1664
1693
|
], FontLoader);
|
|
1665
1694
|
|
|
1666
1695
|
/**
|
|
1667
|
-
*
|
|
1696
|
+
* The glTF resource.
|
|
1668
1697
|
*/ var GLTFResource = /*#__PURE__*/ function(ReferResource1) {
|
|
1669
1698
|
_inherits(GLTFResource, ReferResource1);
|
|
1670
1699
|
function GLTFResource(engine, url) {
|
|
@@ -4224,12 +4253,6 @@ exports.GLTFMaterialParser = __decorate([
|
|
|
4224
4253
|
registerGLTFParser(exports.GLTFParserType.Material)
|
|
4225
4254
|
], exports.GLTFMaterialParser);
|
|
4226
4255
|
|
|
4227
|
-
function _instanceof(left, right) {
|
|
4228
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
4229
|
-
return !!right[Symbol.hasInstance](left);
|
|
4230
|
-
} else return left instanceof right;
|
|
4231
|
-
}
|
|
4232
|
-
|
|
4233
4256
|
var _GLTFMeshParser;
|
|
4234
4257
|
exports.GLTFMeshParser = (_GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
4235
4258
|
_inherits(GLTFMeshParser1, GLTFParser1);
|
|
@@ -4452,7 +4475,7 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
4452
4475
|
var sceneExtensions = sceneInfo.extensions;
|
|
4453
4476
|
var engine = glTFResource.engine;
|
|
4454
4477
|
var isDefaultScene = scene === index;
|
|
4455
|
-
var sceneNodes = sceneInfo.nodes;
|
|
4478
|
+
var sceneNodes = sceneInfo.nodes || [];
|
|
4456
4479
|
var sceneRoot;
|
|
4457
4480
|
if (sceneNodes.length === 1) {
|
|
4458
4481
|
sceneRoot = context.get(exports.GLTFParserType.Entity, sceneNodes[0]);
|
|
@@ -4542,7 +4565,8 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
4542
4565
|
var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
|
|
4543
4566
|
var materialPromises = new Array(rendererCount);
|
|
4544
4567
|
for(var i = 0; i < rendererCount; i++){
|
|
4545
|
-
|
|
4568
|
+
var _glTFMeshPrimitives_i_material;
|
|
4569
|
+
materialPromises[i] = context.get(exports.GLTFParserType.Material, (_glTFMeshPrimitives_i_material = glTFMeshPrimitives[i].material) != null ? _glTFMeshPrimitives_i_material : -1);
|
|
4546
4570
|
}
|
|
4547
4571
|
return Promise.all([
|
|
4548
4572
|
context.get(exports.GLTFParserType.Mesh, meshID),
|
|
@@ -5104,6 +5128,59 @@ exports.GLTFLoader = __decorate([
|
|
|
5104
5128
|
])
|
|
5105
5129
|
], exports.GLTFLoader);
|
|
5106
5130
|
|
|
5131
|
+
var PrefabParser = /*#__PURE__*/ function(HierarchyParser1) {
|
|
5132
|
+
_inherits(PrefabParser, HierarchyParser1);
|
|
5133
|
+
function PrefabParser(data, context, prefabResource) {
|
|
5134
|
+
var _this;
|
|
5135
|
+
_this = HierarchyParser1.call(this, data, context) || this;
|
|
5136
|
+
_this.prefabResource = prefabResource;
|
|
5137
|
+
return _this;
|
|
5138
|
+
}
|
|
5139
|
+
var _proto = PrefabParser.prototype;
|
|
5140
|
+
_proto._handleRootEntity = function _handleRootEntity(id) {
|
|
5141
|
+
this.prefabResource._root = this.context.entityMap.get(id);
|
|
5142
|
+
};
|
|
5143
|
+
_proto._clearAndResolve = function _clearAndResolve() {
|
|
5144
|
+
this.context.clear();
|
|
5145
|
+
return this.prefabResource;
|
|
5146
|
+
};
|
|
5147
|
+
PrefabParser.parse = function parse(engine, url, data) {
|
|
5148
|
+
var prefabResource = new PrefabResource(engine, url);
|
|
5149
|
+
var context = new ParserContext(engine, exports.ParserType.Prefab, prefabResource);
|
|
5150
|
+
var parser = new PrefabParser(data, context, prefabResource);
|
|
5151
|
+
parser.start();
|
|
5152
|
+
return parser.promise.then(function() {
|
|
5153
|
+
return prefabResource;
|
|
5154
|
+
});
|
|
5155
|
+
};
|
|
5156
|
+
return PrefabParser;
|
|
5157
|
+
}(HierarchyParser);
|
|
5158
|
+
|
|
5159
|
+
exports.PrefabLoader = /*#__PURE__*/ function(Loader1) {
|
|
5160
|
+
_inherits(PrefabLoader, Loader1);
|
|
5161
|
+
function PrefabLoader() {
|
|
5162
|
+
return Loader1.apply(this, arguments);
|
|
5163
|
+
}
|
|
5164
|
+
var _proto = PrefabLoader.prototype;
|
|
5165
|
+
_proto.load = function load(item, resourceManager) {
|
|
5166
|
+
var _this = this;
|
|
5167
|
+
var engine = resourceManager.engine;
|
|
5168
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
5169
|
+
_this.request(item.url, _extends({}, item, {
|
|
5170
|
+
type: "json"
|
|
5171
|
+
})).then(function(data) {
|
|
5172
|
+
PrefabParser.parse(engine, item.url, data).then(resolve).catch(reject);
|
|
5173
|
+
});
|
|
5174
|
+
});
|
|
5175
|
+
};
|
|
5176
|
+
return PrefabLoader;
|
|
5177
|
+
}(engineCore.Loader);
|
|
5178
|
+
exports.PrefabLoader = __decorate([
|
|
5179
|
+
engineCore.resourceLoader(engineCore.AssetType.Prefab, [
|
|
5180
|
+
"prefab"
|
|
5181
|
+
])
|
|
5182
|
+
], exports.PrefabLoader);
|
|
5183
|
+
|
|
5107
5184
|
var _HDRLoader;
|
|
5108
5185
|
var PI = Math.PI;
|
|
5109
5186
|
var HDRLoader = (_HDRLoader = // referenece: https://www.flipcode.com/archives/HDR_Image_Reader.shtml
|
|
@@ -6302,6 +6379,8 @@ var SceneLoader = /*#__PURE__*/ function(Loader1) {
|
|
|
6302
6379
|
scene.background.texture = texture;
|
|
6303
6380
|
});
|
|
6304
6381
|
promises.push(backgroundPromise);
|
|
6382
|
+
var _background_textureFillMode;
|
|
6383
|
+
scene.background.textureFillMode = (_background_textureFillMode = background.textureFillMode) != null ? _background_textureFillMode : scene.background.textureFillMode;
|
|
6305
6384
|
}
|
|
6306
6385
|
break;
|
|
6307
6386
|
}
|
|
@@ -6735,7 +6814,7 @@ exports.GLTFParserContext = GLTFParserContext;
|
|
|
6735
6814
|
exports.GLTFResource = GLTFResource;
|
|
6736
6815
|
exports.GLTFUtils = GLTFUtils;
|
|
6737
6816
|
exports.ParserContext = ParserContext;
|
|
6738
|
-
exports.
|
|
6817
|
+
exports.PrefabResource = PrefabResource;
|
|
6739
6818
|
exports.ReflectionParser = ReflectionParser;
|
|
6740
6819
|
exports.SceneParser = SceneParser;
|
|
6741
6820
|
exports.decode = decode;
|