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