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