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