@galacean/engine-loader 0.0.0-experimental-2.0-game.18 → 0.0.0-experimental-2.0-spine.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 +1104 -1406
- package/dist/main.js.map +1 -1
- package/dist/module.js +1105 -1407
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/HDRDecoder.d.ts +27 -8
- package/types/SceneLoader.d.ts +8 -1
- package/types/{Texture2DLoader.d.ts → TextureLoader.d.ts} +4 -4
- package/types/gltf/extensions/GLTFExtensionSchema.d.ts +2 -3
- package/types/gltf/parser/GLTFSceneParser.d.ts +1 -0
- package/types/gltf/parser/GLTFSkinParser.d.ts +5 -2
- package/types/index.d.ts +3 -5
- package/types/prefab/PrefabParser.d.ts +9 -6
- package/types/resource-deserialize/index.d.ts +3 -2
- 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 +41 -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 +33 -0
- package/types/schema/HierarchySchema.d.ts +71 -0
- package/types/schema/MaterialSchema.d.ts +27 -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/ShaderChunkLoader.d.ts +0 -9
- 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 -84
- package/types/resource-deserialize/resources/texture2D/TextureDecoder.d.ts +0 -9
- /package/types/{TextureCubeLoader.d.ts → resource-deserialize/resources/texture2D/Texture2DDecoder.d.ts} +0 -0
- /package/types/{gltf/parser/GLTFSkinParser.test.d.ts → resource-deserialize/resources/textureCube/TextureCubeDecoder.d.ts} +0 -0
- /package/types/{resource-deserialize/resources/schema → schema}/ProjectSchema.d.ts +0 -0
package/dist/main.js
CHANGED
|
@@ -643,37 +643,27 @@ function float32ArrayToVector2(float32Array, vertexCount) {
|
|
|
643
643
|
return array;
|
|
644
644
|
}
|
|
645
645
|
|
|
646
|
-
function
|
|
647
|
-
|
|
648
|
-
// implementations (e.g. core-js@2) don't set the correct internal slots.
|
|
649
|
-
// Those polyfills don't allow us to subclass built-ins, so we need to
|
|
650
|
-
// use our fallback implementation.
|
|
651
|
-
try {
|
|
652
|
-
// If the internal slots aren't set, this throws an error similar to
|
|
653
|
-
// TypeError: this is not a Boolean object.
|
|
654
|
-
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
655
|
-
} catch (_) {}
|
|
656
|
-
return (_is_native_reflect_construct = function() {
|
|
657
|
-
return !!result;
|
|
658
|
-
})();
|
|
659
|
-
}
|
|
646
|
+
function _object_without_properties_loose(source, excluded) {
|
|
647
|
+
if (source == null) return {};
|
|
660
648
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
_construct = function construct(Parent, args, Class) {
|
|
665
|
-
var a = [null];
|
|
666
|
-
a.push.apply(a, args);
|
|
667
|
-
var Constructor = Function.bind.apply(Parent, a);
|
|
668
|
-
var instance = new Constructor();
|
|
649
|
+
var target = {};
|
|
650
|
+
var sourceKeys = Object.keys(source);
|
|
651
|
+
var key, i;
|
|
669
652
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
653
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
654
|
+
key = sourceKeys[i];
|
|
655
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
656
|
+
target[key] = source[key];
|
|
674
657
|
}
|
|
675
658
|
|
|
676
|
-
return
|
|
659
|
+
return target;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function resolveRefItem(refs, index, owner, label) {
|
|
663
|
+
if (!Number.isInteger(index) || index < 0 || index >= refs.length) {
|
|
664
|
+
throw new Error(owner + ": invalid ref index " + index + " for " + label);
|
|
665
|
+
}
|
|
666
|
+
return refs[index];
|
|
677
667
|
}
|
|
678
668
|
|
|
679
669
|
var ParserType = /*#__PURE__*/ function(ParserType) {
|
|
@@ -689,32 +679,20 @@ var ParserType = /*#__PURE__*/ function(ParserType) {
|
|
|
689
679
|
this.engine = engine;
|
|
690
680
|
this.type = type;
|
|
691
681
|
this.resource = resource;
|
|
692
|
-
this.
|
|
693
|
-
this
|
|
694
|
-
this.components = new Map();
|
|
695
|
-
this.componentConfigMap = new Map();
|
|
696
|
-
this.rootIds = [];
|
|
697
|
-
this.strippedIds = [];
|
|
698
|
-
this._tasks = new Set();
|
|
682
|
+
this./** Runtime Entity instances, indexed by the flat entities[] position. */ entityInstances = [];
|
|
683
|
+
this./** Components waiting for props/calls application (Stage 4). */ pendingComponents = [];
|
|
699
684
|
this._loaded = 0;
|
|
700
685
|
this._total = 0;
|
|
701
686
|
this.resourceManager = engine.resourceManager;
|
|
702
687
|
}
|
|
703
688
|
var _proto = ParserContext.prototype;
|
|
704
689
|
_proto.clear = function clear() {
|
|
705
|
-
this.
|
|
706
|
-
this.
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
this.rootIds.length = 0;
|
|
710
|
-
this.strippedIds.length = 0;
|
|
711
|
-
};
|
|
712
|
-
/** @internal */ _proto._addDependentAsset = function _addDependentAsset(url, promise) {
|
|
690
|
+
this.entityInstances.length = 0;
|
|
691
|
+
this.pendingComponents.length = 0;
|
|
692
|
+
};
|
|
693
|
+
/** @internal */ _proto._addDependentAsset = function _addDependentAsset(promise) {
|
|
713
694
|
var _this = this;
|
|
714
|
-
var tasks = this._tasks;
|
|
715
|
-
if (tasks.has(url)) return;
|
|
716
695
|
++this._total;
|
|
717
|
-
tasks.add(url);
|
|
718
696
|
promise.finally(function() {
|
|
719
697
|
++_this._loaded;
|
|
720
698
|
_this._setTaskCompleteProgress(_this._loaded, _this._total);
|
|
@@ -724,243 +702,399 @@ var ParserType = /*#__PURE__*/ function(ParserType) {
|
|
|
724
702
|
}();
|
|
725
703
|
|
|
726
704
|
var ReflectionParser = /*#__PURE__*/ function() {
|
|
727
|
-
function ReflectionParser(_context) {
|
|
705
|
+
function ReflectionParser(_context, _refs) {
|
|
728
706
|
this._context = _context;
|
|
707
|
+
this._refs = _refs;
|
|
729
708
|
}
|
|
730
709
|
var _proto = ReflectionParser.prototype;
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : true;
|
|
736
|
-
var transform = entity.transform;
|
|
737
|
-
var transformConfig = entityConfig.transform;
|
|
738
|
-
if (transformConfig) {
|
|
739
|
-
_this.parsePropsAndMethods(transform, transformConfig);
|
|
740
|
-
} else {
|
|
741
|
-
var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale;
|
|
742
|
-
if (position) transform.position.copyFrom(position);
|
|
743
|
-
if (rotation) transform.rotation.copyFrom(rotation);
|
|
744
|
-
if (scale) transform.scale.copyFrom(scale);
|
|
745
|
-
}
|
|
746
|
-
var _entityConfig_layer;
|
|
747
|
-
entity.layer = (_entityConfig_layer = entityConfig.layer) != null ? _entityConfig_layer : entity.layer;
|
|
748
|
-
// @ts-ignore
|
|
749
|
-
_this._context.type === ParserType.Prefab && entity._markAsTemplate(_this._context.resource);
|
|
750
|
-
return entity;
|
|
751
|
-
});
|
|
752
|
-
};
|
|
753
|
-
_proto.parseClassObject = function parseClassObject(item) {
|
|
754
|
-
var _this = this;
|
|
755
|
-
var Class = engineCore.Loader.getClass(item.class);
|
|
756
|
-
var _item_constructParams;
|
|
757
|
-
var params = (_item_constructParams = item.constructParams) != null ? _item_constructParams : [];
|
|
758
|
-
return Promise.all(params.map(function(param) {
|
|
759
|
-
return _this.parseBasicType(param);
|
|
760
|
-
})).then(function(resultParams) {
|
|
761
|
-
return _construct(Class, [].concat(resultParams));
|
|
762
|
-
}).then(function(instance) {
|
|
763
|
-
return _this.parsePropsAndMethods(instance, item);
|
|
764
|
-
});
|
|
765
|
-
};
|
|
766
|
-
_proto.parsePropsAndMethods = function parsePropsAndMethods(instance, item) {
|
|
710
|
+
/**
|
|
711
|
+
* Apply v2 props to a component/object instance.
|
|
712
|
+
* Each prop value is resolved recursively (handling $ref, $type, $class, $entity, $component, $signal).
|
|
713
|
+
*/ _proto.parseProps = function parseProps(instance, props) {
|
|
767
714
|
var promises = [];
|
|
768
|
-
if (
|
|
769
|
-
for(var methodName in item.methods){
|
|
770
|
-
var methodParams = item.methods[methodName];
|
|
771
|
-
for(var i = 0, count = methodParams.length; i < count; i++){
|
|
772
|
-
promises.push(this.parseMethod(instance, methodName, methodParams[i]));
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
if (item.props) {
|
|
715
|
+
if (props) {
|
|
777
716
|
var _this, _loop = function(key) {
|
|
778
|
-
var
|
|
779
|
-
|
|
780
|
-
return instance[key] = v;
|
|
717
|
+
var promise = _this._resolveValue(props[key], instance[key]).then(function(v) {
|
|
718
|
+
instance[key] = v;
|
|
781
719
|
});
|
|
782
720
|
promises.push(promise);
|
|
783
721
|
};
|
|
784
|
-
for(var key in
|
|
722
|
+
for(var key in props)_this = this, _loop(key);
|
|
785
723
|
}
|
|
786
724
|
return Promise.all(promises).then(function() {
|
|
787
725
|
return instance;
|
|
788
726
|
});
|
|
789
727
|
};
|
|
790
|
-
|
|
728
|
+
/**
|
|
729
|
+
* Execute calls sequentially on a target instance.
|
|
730
|
+
* Call args are resolved with the same v2 value rules as props.
|
|
731
|
+
*/ _proto.parseCalls = function parseCalls(instance, calls) {
|
|
732
|
+
var _loop = function(i, n) {
|
|
733
|
+
var call = calls[i];
|
|
734
|
+
chain = chain.then(function() {
|
|
735
|
+
var method = instance == null ? void 0 : instance[call.method];
|
|
736
|
+
if (typeof method !== "function") {
|
|
737
|
+
return Promise.reject(new Error('Call target does not have method "' + call.method + '"'));
|
|
738
|
+
}
|
|
739
|
+
var _call_args;
|
|
740
|
+
return Promise.all(((_call_args = call.args) != null ? _call_args : []).map(function(arg) {
|
|
741
|
+
return _this._resolveValue(arg);
|
|
742
|
+
})).then(function(resolvedArgs) {
|
|
743
|
+
return Promise.resolve(method.apply(instance, resolvedArgs));
|
|
744
|
+
}).then(function(result) {
|
|
745
|
+
if (!call.result) return result;
|
|
746
|
+
if (result == null || (typeof result === "undefined" ? "undefined" : _type_of(result)) !== "object" && typeof result !== "function") {
|
|
747
|
+
return Promise.reject(new Error('Call "' + call.method + '" returned ' + result + " and cannot be mutated by result"));
|
|
748
|
+
}
|
|
749
|
+
return _this.parseMutationBlock(result, call.result);
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
};
|
|
791
753
|
var _this = this;
|
|
792
|
-
|
|
793
|
-
var
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
var _instance;
|
|
798
|
-
var methodResult = (_instance = instance)[methodName].apply(_instance, [].concat(result));
|
|
799
|
-
if (isMethodObject && methodParams.result) {
|
|
800
|
-
return _this.parsePropsAndMethods(methodResult, methodParams.result);
|
|
801
|
-
} else {
|
|
802
|
-
return methodResult;
|
|
803
|
-
}
|
|
754
|
+
if (!(calls == null ? void 0 : calls.length)) return Promise.resolve(instance);
|
|
755
|
+
var chain = Promise.resolve();
|
|
756
|
+
for(var i = 0, n = calls.length; i < n; i++)_loop(i);
|
|
757
|
+
return chain.then(function() {
|
|
758
|
+
return instance;
|
|
804
759
|
});
|
|
805
760
|
};
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
return Promise.
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
]).then(function(param) {
|
|
816
|
-
var target = param[0], resolvedArgs = param[1];
|
|
817
|
-
if (target) {
|
|
818
|
-
var _signal;
|
|
819
|
-
(_signal = signal).on.apply(_signal, [].concat([
|
|
820
|
-
target,
|
|
821
|
-
listener.methodName
|
|
822
|
-
], resolvedArgs));
|
|
823
|
-
}
|
|
824
|
-
});
|
|
825
|
-
})).then(function() {
|
|
826
|
-
return signal;
|
|
761
|
+
/**
|
|
762
|
+
* Apply props and calls from the same mutation block without imposing ordering between them.
|
|
763
|
+
*/ _proto.parseMutationBlock = function parseMutationBlock(target, block) {
|
|
764
|
+
if (!block) return Promise.resolve(target);
|
|
765
|
+
return Promise.all([
|
|
766
|
+
this.parseProps(target, block.props),
|
|
767
|
+
this.parseCalls(target, block.calls)
|
|
768
|
+
]).then(function() {
|
|
769
|
+
return target;
|
|
827
770
|
});
|
|
828
771
|
};
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
772
|
+
/**
|
|
773
|
+
* Resolve a v2 value with $ prefix detection.
|
|
774
|
+
*
|
|
775
|
+
* Priority:
|
|
776
|
+
* 1. null/undefined/primitive → passthrough
|
|
777
|
+
* 2. Array → recurse each element
|
|
778
|
+
* 3. { $ref } → asset reference
|
|
779
|
+
* 4. { $type } → polymorphic type construct
|
|
780
|
+
* 5. { $class } → registered class constructor
|
|
781
|
+
* 6. { $entity } → entity reference by path (flat index + optional children descent)
|
|
782
|
+
* 7. { $component } → component reference
|
|
783
|
+
* 8. { $signal } → signal binding
|
|
784
|
+
* 9. plain object → recurse values (modify originValue in place if exists)
|
|
785
|
+
*/ _proto._resolveValue = function _resolveValue(value, originValue) {
|
|
786
|
+
var _this, _loop = function(key) {
|
|
787
|
+
promises.push(_this._resolveValue(obj[key], target[key]).then(function(v) {
|
|
788
|
+
return target[key] = v;
|
|
834
789
|
}));
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
return resource;
|
|
851
|
-
});
|
|
852
|
-
} else if (ReflectionParser._isComponentRef(value)) {
|
|
853
|
-
var entity = this._resolveEntityByPath(value.entityPath);
|
|
854
|
-
if (!entity) return Promise.resolve(null);
|
|
855
|
-
var type = engineCore.Loader.getClass(value.componentType);
|
|
856
|
-
if (!type) return Promise.resolve(null);
|
|
857
|
-
// Try direct components first, fallback to children search (for GLB clone entities
|
|
858
|
-
// where the component lives on a child entity inside the clone)
|
|
859
|
-
var direct = entity.getComponents(type, []);
|
|
860
|
-
var result = direct[value.componentIndex];
|
|
861
|
-
if (result) return Promise.resolve(result);
|
|
862
|
-
var includeChildren = [];
|
|
863
|
-
entity.getComponentsIncludeChildren(type, includeChildren);
|
|
864
|
-
var _includeChildren_value_componentIndex;
|
|
865
|
-
return Promise.resolve((_includeChildren_value_componentIndex = includeChildren[value.componentIndex]) != null ? _includeChildren_value_componentIndex : null);
|
|
866
|
-
} else if (ReflectionParser._isEntityRef(value)) {
|
|
867
|
-
return Promise.resolve(this._resolveEntityByPath(value.entityPath));
|
|
868
|
-
} else if (ReflectionParser._isSignalRef(value)) {
|
|
869
|
-
return this.parseSignal(value);
|
|
870
|
-
} else if (originValue) {
|
|
871
|
-
var _this2, _loop = function(key) {
|
|
872
|
-
if (key === "methods") {
|
|
873
|
-
var methods = value[key];
|
|
874
|
-
for(var methodName in methods){
|
|
875
|
-
var methodParams = methods[methodName];
|
|
876
|
-
for(var i = 0, count = methodParams.length; i < count; i++){
|
|
877
|
-
var params = methodParams[i];
|
|
878
|
-
var promise = _this2.parseMethod(originValue, methodName, params);
|
|
879
|
-
promises.push(promise);
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
} else {
|
|
883
|
-
promises.push(_this2.parseBasicType(value[key], originValue[key]).then(function(v) {
|
|
884
|
-
return originValue[key] = v;
|
|
885
|
-
}));
|
|
886
|
-
}
|
|
887
|
-
};
|
|
888
|
-
var promises = [];
|
|
889
|
-
for(var key in value)_this2 = this, _loop(key);
|
|
890
|
-
return Promise.all(promises).then(function() {
|
|
891
|
-
return originValue;
|
|
892
|
-
});
|
|
790
|
+
};
|
|
791
|
+
var _this1 = this;
|
|
792
|
+
if (value == null || (typeof value === "undefined" ? "undefined" : _type_of(value)) !== "object") return Promise.resolve(value);
|
|
793
|
+
if (Array.isArray(value)) return Promise.all(value.map(function(v) {
|
|
794
|
+
return _this1._resolveValue(v);
|
|
795
|
+
}));
|
|
796
|
+
var obj = value;
|
|
797
|
+
// $ref — asset reference (index into refs array)
|
|
798
|
+
if ("$ref" in obj) {
|
|
799
|
+
var _this2 = this, context = _this2._context;
|
|
800
|
+
var refItem;
|
|
801
|
+
try {
|
|
802
|
+
refItem = resolveRefItem(this._refs, obj.$ref, "ReflectionParser", "$ref");
|
|
803
|
+
} catch (error) {
|
|
804
|
+
return Promise.reject(error);
|
|
893
805
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
};
|
|
898
|
-
_proto._getEntityByConfig = function _getEntityByConfig(entityConfig) {
|
|
899
|
-
var _this = this;
|
|
900
|
-
// @ts-ignore
|
|
901
|
-
var assetUrl = entityConfig.assetUrl;
|
|
902
|
-
var engine = this._context.engine;
|
|
903
|
-
if (assetUrl) {
|
|
904
|
-
return engine.resourceManager// @ts-ignore
|
|
905
|
-
.getResourceByRef({
|
|
906
|
-
url: assetUrl,
|
|
907
|
-
key: entityConfig.key,
|
|
908
|
-
isClone: entityConfig.isClone
|
|
909
|
-
}).then(function(entity) {
|
|
910
|
-
// @ts-ignore
|
|
911
|
-
var resource = engine.resourceManager._objectPool[assetUrl];
|
|
912
|
-
if (resource && _this._context.type === ParserType.Prefab) {
|
|
806
|
+
// @ts-ignore
|
|
807
|
+
return context.resourceManager.getResourceByRef(refItem).then(function(resource) {
|
|
808
|
+
if (resource && context.type === ParserType.Prefab) {
|
|
913
809
|
// @ts-ignore
|
|
914
|
-
|
|
810
|
+
context.resource._addDependenceAsset(resource);
|
|
915
811
|
}
|
|
916
|
-
|
|
917
|
-
return entity;
|
|
812
|
+
return resource;
|
|
918
813
|
});
|
|
919
|
-
} else {
|
|
920
|
-
var transform = entityConfig.transform;
|
|
921
|
-
var entity = new engineCore.Entity(engine, entityConfig.name, transform ? engineCore.Loader.getClass(transform.class) : engineCore.Transform);
|
|
922
|
-
return Promise.resolve(entity);
|
|
923
814
|
}
|
|
815
|
+
// $type — polymorphic type: construct instance and apply remaining props
|
|
816
|
+
if ("$type" in obj) {
|
|
817
|
+
var $type = obj.$type, rest = _object_without_properties_loose(obj, [
|
|
818
|
+
"$type"
|
|
819
|
+
]);
|
|
820
|
+
return this._resolveRegisteredClass($type, "$type").then(function(Class) {
|
|
821
|
+
var instance = new Class();
|
|
822
|
+
return Object.keys(rest).length > 0 ? _this1.parseProps(instance, rest) : instance;
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
// $class — registered class constructor for factory-style methods.
|
|
826
|
+
if ("$class" in obj) {
|
|
827
|
+
return this._resolveRegisteredClass(obj.$class, "$class");
|
|
828
|
+
}
|
|
829
|
+
// $entity — entity reference by path (first element = flat index, subsequent = children indices)
|
|
830
|
+
if ("$entity" in obj) {
|
|
831
|
+
return Promise.resolve(this._resolveEntityRef(obj.$entity));
|
|
832
|
+
}
|
|
833
|
+
// $component — component reference: { entity, type, index }
|
|
834
|
+
if ("$component" in obj) {
|
|
835
|
+
return Promise.resolve(this._resolveComponent(obj.$component));
|
|
836
|
+
}
|
|
837
|
+
// $signal — signal binding: register listeners on the existing Signal instance
|
|
838
|
+
if ("$signal" in obj) {
|
|
839
|
+
return this._resolveSignal(originValue, obj.$signal);
|
|
840
|
+
}
|
|
841
|
+
// Plain object — recurse each value, modifying originValue in place or building a new object
|
|
842
|
+
var target = originValue && (typeof originValue === "undefined" ? "undefined" : _type_of(originValue)) === "object" && !Array.isArray(originValue) ? originValue : {};
|
|
843
|
+
var promises = [];
|
|
844
|
+
for(var key in obj)_this = this, _loop(key);
|
|
845
|
+
return Promise.all(promises).then(function() {
|
|
846
|
+
return target;
|
|
847
|
+
});
|
|
924
848
|
};
|
|
925
|
-
_proto.
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
var entity = entityMap.get(rootIds[entityPath[0]]);
|
|
929
|
-
for(var i = 1; i < entityPath.length; i++){
|
|
930
|
-
if (!entity || entityPath[i] >= entity.children.length) return null;
|
|
931
|
-
entity = entity.children[entityPath[i]];
|
|
849
|
+
_proto._getRegisteredClass = function _getRegisteredClass(value, sentinel) {
|
|
850
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
851
|
+
throw new Error("" + sentinel + " must be a non-empty registered class name string");
|
|
932
852
|
}
|
|
933
|
-
|
|
853
|
+
var Class = engineCore.Loader.getClass(value);
|
|
854
|
+
if (!Class) throw new Error('Loader.getClass: class "' + value + '" is not registered');
|
|
855
|
+
return Class;
|
|
934
856
|
};
|
|
935
|
-
|
|
936
|
-
|
|
857
|
+
/** Promise-adapt {@link _getRegisteredClass} so $type/$class branches can fold into the resolver chain. */ _proto._resolveRegisteredClass = function _resolveRegisteredClass(value, sentinel) {
|
|
858
|
+
try {
|
|
859
|
+
return Promise.resolve(this._getRegisteredClass(value, sentinel));
|
|
860
|
+
} catch (error) {
|
|
861
|
+
return Promise.reject(error);
|
|
862
|
+
}
|
|
937
863
|
};
|
|
938
|
-
|
|
939
|
-
|
|
864
|
+
_proto._resolveSignal = function _resolveSignal(signal, listeners) {
|
|
865
|
+
var _this = this;
|
|
866
|
+
if (!signal || typeof signal.on !== "function") {
|
|
867
|
+
return Promise.reject(new Error("$signal requires a pre-initialized Signal instance on the target property"));
|
|
868
|
+
}
|
|
869
|
+
var promises = listeners.map(function(listener) {
|
|
870
|
+
var targetComponent = _this._resolveComponent(listener.target.$component);
|
|
871
|
+
if (!targetComponent) return Promise.resolve();
|
|
872
|
+
var _listener_args;
|
|
873
|
+
return Promise.all(((_listener_args = listener.args) != null ? _listener_args : []).map(function(a) {
|
|
874
|
+
return _this._resolveValue(a);
|
|
875
|
+
})).then(function(resolvedArgs) {
|
|
876
|
+
var _signal;
|
|
877
|
+
(_signal = signal).on.apply(_signal, [].concat([
|
|
878
|
+
targetComponent,
|
|
879
|
+
listener.methodName
|
|
880
|
+
], resolvedArgs));
|
|
881
|
+
});
|
|
882
|
+
});
|
|
883
|
+
return Promise.all(promises).then(function() {
|
|
884
|
+
return signal;
|
|
885
|
+
});
|
|
940
886
|
};
|
|
941
|
-
|
|
942
|
-
|
|
887
|
+
_proto._resolveComponent = function _resolveComponent(comp) {
|
|
888
|
+
var entity = this._resolveEntityRef(comp.entity);
|
|
889
|
+
if (!entity) return null;
|
|
890
|
+
var type = engineCore.Loader.getClass(comp.type);
|
|
891
|
+
if (!type) return null;
|
|
892
|
+
var buffer = ReflectionParser._componentBuffer;
|
|
893
|
+
buffer.length = 0;
|
|
894
|
+
entity.getComponents(type, buffer);
|
|
895
|
+
var _buffer_comp_index;
|
|
896
|
+
var result = (_buffer_comp_index = buffer[comp.index]) != null ? _buffer_comp_index : null;
|
|
897
|
+
buffer.length = 0;
|
|
898
|
+
return result;
|
|
943
899
|
};
|
|
944
|
-
|
|
945
|
-
|
|
900
|
+
_proto._resolveEntityRef = function _resolveEntityRef(path) {
|
|
901
|
+
if (!path || path.length === 0) return null;
|
|
902
|
+
var _this__context_entityInstances_path_;
|
|
903
|
+
var entity = (_this__context_entityInstances_path_ = this._context.entityInstances[path[0]]) != null ? _this__context_entityInstances_path_ : null;
|
|
904
|
+
for(var i = 1, n = path.length; entity && i < n; i++){
|
|
905
|
+
var _entity_children_path_i;
|
|
906
|
+
entity = (_entity_children_path_i = entity.children[path[i]]) != null ? _entity_children_path_i : null;
|
|
907
|
+
}
|
|
908
|
+
return entity;
|
|
946
909
|
};
|
|
947
|
-
ReflectionParser
|
|
948
|
-
|
|
910
|
+
return ReflectionParser;
|
|
911
|
+
}();
|
|
912
|
+
/** @internal shared with HierarchyParser; each use must length=0 -> getComponents -> read -> length=0 synchronously. */ ReflectionParser._componentBuffer = [];
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* HDR (Radiance RGBE) image decoder.
|
|
916
|
+
*
|
|
917
|
+
* Decodes .hdr files into pixel data. Supports parsing the header
|
|
918
|
+
* and decoding RLE-compressed RGBE scanlines into R16G16B16A16 half-float pixels.
|
|
919
|
+
*/ var HDRDecoder = /*#__PURE__*/ function() {
|
|
920
|
+
function HDRDecoder() {}
|
|
921
|
+
/**
|
|
922
|
+
* Parse the header of an HDR file.
|
|
923
|
+
* @returns Header info including width, height, and data start position.
|
|
924
|
+
*/ HDRDecoder.parseHeader = function parseHeader(uint8array) {
|
|
925
|
+
var line = this._readStringLine(uint8array, 0);
|
|
926
|
+
if (line[0] !== "#" || line[1] !== "?") {
|
|
927
|
+
throw "HDRDecoder: invalid file header";
|
|
928
|
+
}
|
|
929
|
+
var endOfHeader = false;
|
|
930
|
+
var findFormat = false;
|
|
931
|
+
var lineIndex = 0;
|
|
932
|
+
do {
|
|
933
|
+
lineIndex += line.length + 1;
|
|
934
|
+
line = this._readStringLine(uint8array, lineIndex);
|
|
935
|
+
if (line === "FORMAT=32-bit_rle_rgbe") findFormat = true;
|
|
936
|
+
else if (line.length === 0) endOfHeader = true;
|
|
937
|
+
}while (!endOfHeader);
|
|
938
|
+
if (!findFormat) {
|
|
939
|
+
throw "HDRDecoder: unsupported format, expected 32-bit_rle_rgbe";
|
|
940
|
+
}
|
|
941
|
+
lineIndex += line.length + 1;
|
|
942
|
+
line = this._readStringLine(uint8array, lineIndex);
|
|
943
|
+
var match = /^\-Y (.*) \+X (.*)$/g.exec(line);
|
|
944
|
+
if (!match || match.length < 3) {
|
|
945
|
+
throw "HDRDecoder: missing image size, only -Y +X layout is supported";
|
|
946
|
+
}
|
|
947
|
+
var width = parseInt(match[2]);
|
|
948
|
+
var height = parseInt(match[1]);
|
|
949
|
+
if (width < 8 || width > 0x7fff) {
|
|
950
|
+
throw "HDRDecoder: unsupported image width, must be between 8 and 32767";
|
|
951
|
+
}
|
|
952
|
+
return {
|
|
953
|
+
height: height,
|
|
954
|
+
width: width,
|
|
955
|
+
dataPosition: lineIndex + line.length + 1
|
|
956
|
+
};
|
|
949
957
|
};
|
|
950
|
-
|
|
951
|
-
|
|
958
|
+
/**
|
|
959
|
+
* Decode an HDR file buffer into R16G16B16A16 half-float pixel data.
|
|
960
|
+
* @param buffer - The full HDR file as Uint8Array.
|
|
961
|
+
* @returns Object with width, height, and half-float pixel data.
|
|
962
|
+
*/ HDRDecoder.decode = function decode(buffer) {
|
|
963
|
+
var header = this.parseHeader(buffer);
|
|
964
|
+
var width = header.width, height = header.height, dataPosition = header.dataPosition;
|
|
965
|
+
var rgbe = this._readPixels(buffer.subarray(dataPosition), width, height);
|
|
966
|
+
var pixels = this._rgbeToHalfFloat(rgbe, width, height);
|
|
967
|
+
return {
|
|
968
|
+
width: width,
|
|
969
|
+
height: height,
|
|
970
|
+
pixels: pixels
|
|
971
|
+
};
|
|
952
972
|
};
|
|
953
|
-
|
|
954
|
-
|
|
973
|
+
/**
|
|
974
|
+
* Convert RGBE pixel data to R16G16B16A16 half-float.
|
|
975
|
+
*/ HDRDecoder._rgbeToHalfFloat = function _rgbeToHalfFloat(rgbe, width, height) {
|
|
976
|
+
var floatView = this._floatView;
|
|
977
|
+
var uint32View = this._uint32View;
|
|
978
|
+
var _this__float2HalfTables = this._float2HalfTables, baseTable = _this__float2HalfTables.baseTable, shiftTable = _this__float2HalfTables.shiftTable;
|
|
979
|
+
var one = 0x3c00; // Half float 1.0
|
|
980
|
+
var pixelCount = width * height;
|
|
981
|
+
var result = new Uint16Array(pixelCount * 4);
|
|
982
|
+
for(var i = 0; i < pixelCount; i++){
|
|
983
|
+
var srcIdx = i * 4;
|
|
984
|
+
var dstIdx = i * 4;
|
|
985
|
+
var scaleFactor = Math.pow(2, rgbe[srcIdx + 3] - 128 - 8);
|
|
986
|
+
for(var c = 0; c < 3; c++){
|
|
987
|
+
floatView[0] = Math.min(rgbe[srcIdx + c] * scaleFactor, 65504);
|
|
988
|
+
var f = uint32View[0];
|
|
989
|
+
var e = f >> 23 & 0x1ff;
|
|
990
|
+
result[dstIdx + c] = baseTable[e] + ((f & 0x007fffff) >> shiftTable[e]);
|
|
991
|
+
}
|
|
992
|
+
result[dstIdx + 3] = one;
|
|
993
|
+
}
|
|
994
|
+
return result;
|
|
955
995
|
};
|
|
956
|
-
|
|
996
|
+
/**
|
|
997
|
+
* Decode RLE-compressed RGBE scanlines into raw RGBE pixel data.
|
|
998
|
+
*/ HDRDecoder._readPixels = function _readPixels(buffer, width, height) {
|
|
999
|
+
var byteLength = buffer.byteLength;
|
|
1000
|
+
var dataRGBA = new Uint8Array(4 * width * height);
|
|
1001
|
+
var offset = 0;
|
|
1002
|
+
var pos = 0;
|
|
1003
|
+
var ptrEnd = 4 * width;
|
|
1004
|
+
var scanLineBuffer = new Uint8Array(ptrEnd);
|
|
1005
|
+
var numScanLines = height;
|
|
1006
|
+
while(numScanLines > 0 && pos < byteLength){
|
|
1007
|
+
var a = buffer[pos++];
|
|
1008
|
+
var b = buffer[pos++];
|
|
1009
|
+
var c = buffer[pos++];
|
|
1010
|
+
var d = buffer[pos++];
|
|
1011
|
+
if (a !== 2 || b !== 2 || c & 0x80 || width < 8 || width > 32767) return buffer;
|
|
1012
|
+
if ((c << 8 | d) !== width) throw "HDRDecoder: wrong scanline width";
|
|
1013
|
+
var ptr = 0;
|
|
1014
|
+
while(ptr < ptrEnd && pos < byteLength){
|
|
1015
|
+
var count = buffer[pos++];
|
|
1016
|
+
var isEncodedRun = count > 128;
|
|
1017
|
+
if (isEncodedRun) count -= 128;
|
|
1018
|
+
if (count === 0 || ptr + count > ptrEnd) throw "HDRDecoder: bad scanline data";
|
|
1019
|
+
if (isEncodedRun) {
|
|
1020
|
+
var byteValue = buffer[pos++];
|
|
1021
|
+
for(var i = 0; i < count; i++)scanLineBuffer[ptr++] = byteValue;
|
|
1022
|
+
} else {
|
|
1023
|
+
scanLineBuffer.set(buffer.subarray(pos, pos + count), ptr);
|
|
1024
|
+
ptr += count;
|
|
1025
|
+
pos += count;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
for(var i1 = 0; i1 < width; i1++, offset += 4){
|
|
1029
|
+
dataRGBA[offset] = scanLineBuffer[i1];
|
|
1030
|
+
dataRGBA[offset + 1] = scanLineBuffer[i1 + width];
|
|
1031
|
+
dataRGBA[offset + 2] = scanLineBuffer[i1 + width * 2];
|
|
1032
|
+
dataRGBA[offset + 3] = scanLineBuffer[i1 + width * 3];
|
|
1033
|
+
}
|
|
1034
|
+
numScanLines--;
|
|
1035
|
+
}
|
|
1036
|
+
return dataRGBA;
|
|
1037
|
+
};
|
|
1038
|
+
HDRDecoder._generateFloat2HalfTables = function _generateFloat2HalfTables() {
|
|
1039
|
+
var baseTable = new Uint32Array(512);
|
|
1040
|
+
var shiftTable = new Uint32Array(512);
|
|
1041
|
+
for(var i = 0; i < 256; ++i){
|
|
1042
|
+
var e = i - 127;
|
|
1043
|
+
if (e < -27) {
|
|
1044
|
+
baseTable[i] = 0x0000;
|
|
1045
|
+
baseTable[i | 0x100] = 0x8000;
|
|
1046
|
+
shiftTable[i] = 24;
|
|
1047
|
+
shiftTable[i | 0x100] = 24;
|
|
1048
|
+
} else if (e < -14) {
|
|
1049
|
+
baseTable[i] = 0x0400 >> -e - 14;
|
|
1050
|
+
baseTable[i | 0x100] = 0x0400 >> -e - 14 | 0x8000;
|
|
1051
|
+
shiftTable[i] = -e - 1;
|
|
1052
|
+
shiftTable[i | 0x100] = -e - 1;
|
|
1053
|
+
} else if (e <= 15) {
|
|
1054
|
+
baseTable[i] = e + 15 << 10;
|
|
1055
|
+
baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
|
|
1056
|
+
shiftTable[i] = 13;
|
|
1057
|
+
shiftTable[i | 0x100] = 13;
|
|
1058
|
+
} else if (e < 128) {
|
|
1059
|
+
baseTable[i] = 0x7c00;
|
|
1060
|
+
baseTable[i | 0x100] = 0xfc00;
|
|
1061
|
+
shiftTable[i] = 24;
|
|
1062
|
+
shiftTable[i | 0x100] = 24;
|
|
1063
|
+
} else {
|
|
1064
|
+
baseTable[i] = 0x7c00;
|
|
1065
|
+
baseTable[i | 0x100] = 0xfc00;
|
|
1066
|
+
shiftTable[i] = 13;
|
|
1067
|
+
shiftTable[i | 0x100] = 13;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
return {
|
|
1071
|
+
baseTable: baseTable,
|
|
1072
|
+
shiftTable: shiftTable
|
|
1073
|
+
};
|
|
1074
|
+
};
|
|
1075
|
+
HDRDecoder._readStringLine = function _readStringLine(uint8array, startIndex) {
|
|
1076
|
+
var line = "";
|
|
1077
|
+
for(var i = startIndex, n = uint8array.length; i < n; i++){
|
|
1078
|
+
var character = String.fromCharCode(uint8array[i]);
|
|
1079
|
+
if (character === "\n") break;
|
|
1080
|
+
line += character;
|
|
1081
|
+
}
|
|
1082
|
+
return line;
|
|
1083
|
+
};
|
|
1084
|
+
return HDRDecoder;
|
|
957
1085
|
}();
|
|
1086
|
+
HDRDecoder._float2HalfTables = HDRDecoder._generateFloat2HalfTables();
|
|
1087
|
+
HDRDecoder._floatView = new Float32Array(1);
|
|
1088
|
+
HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
|
|
958
1089
|
|
|
959
|
-
|
|
1090
|
+
/**
|
|
1091
|
+
* Data format: [url] [mipmap(1B)] [filterMode(1B)] [anisoLevel(1B)] [wrapModeU(1B)] [wrapModeV(1B)]
|
|
1092
|
+
* [format(1B)] [width(2B)] [height(2B)] [isSRGBColorSpace(1B)] [Uint32(imageSize) + imageBytes]
|
|
1093
|
+
*/ var Texture2DDecoder = /*#__PURE__*/ function() {
|
|
960
1094
|
function Texture2DDecoder() {}
|
|
961
1095
|
Texture2DDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
|
|
962
1096
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
963
|
-
|
|
1097
|
+
bufferReader.nextStr();
|
|
964
1098
|
var mipmap = !!bufferReader.nextUint8();
|
|
965
1099
|
var filterMode = bufferReader.nextUint8();
|
|
966
1100
|
var anisoLevel = bufferReader.nextUint8();
|
|
@@ -969,58 +1103,34 @@ exports.Texture2DDecoder = /*#__PURE__*/ function() {
|
|
|
969
1103
|
var format = bufferReader.nextUint8();
|
|
970
1104
|
var width = bufferReader.nextUint16();
|
|
971
1105
|
var height = bufferReader.nextUint16();
|
|
972
|
-
var isPixelBuffer = bufferReader.nextUint8();
|
|
973
1106
|
var isSRGBColorSpace = !!bufferReader.nextUint8();
|
|
974
|
-
var
|
|
975
|
-
var
|
|
976
|
-
var
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
var pixelBuffer1 = imagesData[i];
|
|
988
|
-
texture2D.setPixelBuffer(pixelBuffer1, i);
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
// @ts-ignore
|
|
992
|
-
engine.resourceManager._objectPool[url] = texture2D;
|
|
993
|
-
resolve(texture2D);
|
|
1107
|
+
var imageData = bufferReader.nextImagesData(1)[0];
|
|
1108
|
+
var isHDR = imageData[0] === 0x23 && imageData[1] === 0x3f;
|
|
1109
|
+
var textureFormat = isHDR ? engineCore.TextureFormat.R16G16B16A16 : format;
|
|
1110
|
+
var texture = restoredTexture || new engineCore.Texture2D(engine, width, height, textureFormat, mipmap, isHDR ? false : isSRGBColorSpace);
|
|
1111
|
+
texture.filterMode = filterMode;
|
|
1112
|
+
texture.anisoLevel = anisoLevel;
|
|
1113
|
+
texture.wrapModeU = wrapModeU;
|
|
1114
|
+
texture.wrapModeV = wrapModeV;
|
|
1115
|
+
if (isHDR) {
|
|
1116
|
+
var pixels = HDRDecoder.decode(imageData).pixels;
|
|
1117
|
+
texture.setPixelBuffer(pixels);
|
|
1118
|
+
mipmap && texture.generateMipmaps();
|
|
1119
|
+
resolve(texture);
|
|
994
1120
|
} else {
|
|
995
|
-
var blob = new
|
|
996
|
-
|
|
1121
|
+
var blob = new Blob([
|
|
1122
|
+
imageData
|
|
997
1123
|
]);
|
|
998
1124
|
var img = new Image();
|
|
999
1125
|
img.onload = function() {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
onComplete();
|
|
1009
|
-
if (mipmap) {
|
|
1010
|
-
var _loop = function(i) {
|
|
1011
|
-
var blob = new window.Blob([
|
|
1012
|
-
imagesData[i]
|
|
1013
|
-
]);
|
|
1014
|
-
var img = new Image();
|
|
1015
|
-
img.onload = function() {
|
|
1016
|
-
texture2D.setImageSource(img, i);
|
|
1017
|
-
onComplete();
|
|
1018
|
-
};
|
|
1019
|
-
img.src = URL.createObjectURL(blob);
|
|
1020
|
-
};
|
|
1021
|
-
texture2D.generateMipmaps();
|
|
1022
|
-
for(var i = 1; i < mipCount; i++)_loop(i);
|
|
1023
|
-
}
|
|
1126
|
+
URL.revokeObjectURL(img.src);
|
|
1127
|
+
texture.setImageSource(img);
|
|
1128
|
+
mipmap && texture.generateMipmaps();
|
|
1129
|
+
resolve(texture);
|
|
1130
|
+
};
|
|
1131
|
+
img.onerror = function(e) {
|
|
1132
|
+
URL.revokeObjectURL(img.src);
|
|
1133
|
+
reject(e);
|
|
1024
1134
|
};
|
|
1025
1135
|
img.src = URL.createObjectURL(blob);
|
|
1026
1136
|
}
|
|
@@ -1028,9 +1138,72 @@ exports.Texture2DDecoder = /*#__PURE__*/ function() {
|
|
|
1028
1138
|
};
|
|
1029
1139
|
return Texture2DDecoder;
|
|
1030
1140
|
}();
|
|
1031
|
-
|
|
1141
|
+
Texture2DDecoder = __decorate([
|
|
1032
1142
|
decoder("Texture2D")
|
|
1033
|
-
],
|
|
1143
|
+
], Texture2DDecoder);
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* Data format: [url] [mipmap(1B)] [filterMode(1B)] [anisoLevel(1B)] [wrapModeU(1B)] [wrapModeV(1B)]
|
|
1147
|
+
* [format(1B)] [faceSize(2B)] [isSRGBColorSpace(1B)] [Uint32(size) + faceBytes] × 6
|
|
1148
|
+
*/ var TextureCubeDecoder = /*#__PURE__*/ function() {
|
|
1149
|
+
function TextureCubeDecoder() {}
|
|
1150
|
+
TextureCubeDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
|
|
1151
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
1152
|
+
bufferReader.nextStr();
|
|
1153
|
+
var mipmap = !!bufferReader.nextUint8();
|
|
1154
|
+
var filterMode = bufferReader.nextUint8();
|
|
1155
|
+
var anisoLevel = bufferReader.nextUint8();
|
|
1156
|
+
var wrapModeU = bufferReader.nextUint8();
|
|
1157
|
+
var wrapModeV = bufferReader.nextUint8();
|
|
1158
|
+
var format = bufferReader.nextUint8();
|
|
1159
|
+
var faceSize = bufferReader.nextUint16();
|
|
1160
|
+
var isSRGBColorSpace = !!bufferReader.nextUint8();
|
|
1161
|
+
var facesData = bufferReader.nextImagesData(6);
|
|
1162
|
+
// Detect format by first face's magic bytes
|
|
1163
|
+
var isHDR = facesData[0][0] === 0x23 && facesData[0][1] === 0x3f;
|
|
1164
|
+
var textureFormat = isHDR ? engineCore.TextureFormat.R16G16B16A16 : format;
|
|
1165
|
+
var texture = restoredTexture || new engineCore.TextureCube(engine, faceSize, textureFormat, mipmap, isSRGBColorSpace);
|
|
1166
|
+
texture.filterMode = filterMode;
|
|
1167
|
+
texture.anisoLevel = anisoLevel;
|
|
1168
|
+
texture.wrapModeU = wrapModeU;
|
|
1169
|
+
texture.wrapModeV = wrapModeV;
|
|
1170
|
+
if (isHDR) {
|
|
1171
|
+
for(var i = 0; i < 6; i++){
|
|
1172
|
+
var pixels = HDRDecoder.decode(facesData[i]).pixels;
|
|
1173
|
+
texture.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + i, pixels, 0);
|
|
1174
|
+
}
|
|
1175
|
+
mipmap && texture.generateMipmaps();
|
|
1176
|
+
resolve(texture);
|
|
1177
|
+
} else {
|
|
1178
|
+
var _loop = function(i1) {
|
|
1179
|
+
var blob = new Blob([
|
|
1180
|
+
facesData[i1]
|
|
1181
|
+
]);
|
|
1182
|
+
var img = new Image();
|
|
1183
|
+
img.onload = function() {
|
|
1184
|
+
URL.revokeObjectURL(img.src);
|
|
1185
|
+
texture.setImageSource(engineCore.TextureCubeFace.PositiveX + i1, img);
|
|
1186
|
+
if (++loadedCount === 6) {
|
|
1187
|
+
mipmap && texture.generateMipmaps();
|
|
1188
|
+
resolve(texture);
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
img.onerror = function(e) {
|
|
1192
|
+
URL.revokeObjectURL(img.src);
|
|
1193
|
+
reject(e);
|
|
1194
|
+
};
|
|
1195
|
+
img.src = URL.createObjectURL(blob);
|
|
1196
|
+
};
|
|
1197
|
+
var loadedCount = 0;
|
|
1198
|
+
for(var i1 = 0; i1 < 6; i1++)_loop(i1);
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
};
|
|
1202
|
+
return TextureCubeDecoder;
|
|
1203
|
+
}();
|
|
1204
|
+
TextureCubeDecoder = __decorate([
|
|
1205
|
+
decoder("TextureCube")
|
|
1206
|
+
], TextureCubeDecoder);
|
|
1034
1207
|
|
|
1035
1208
|
function _instanceof(left, right) {
|
|
1036
1209
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
@@ -1038,45 +1211,6 @@ function _instanceof(left, right) {
|
|
|
1038
1211
|
} else return left instanceof right;
|
|
1039
1212
|
}
|
|
1040
1213
|
|
|
1041
|
-
function _array_like_to_array(arr, len) {
|
|
1042
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
1043
|
-
|
|
1044
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
1045
|
-
|
|
1046
|
-
return arr2;
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
1050
|
-
if (!o) return;
|
|
1051
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
1052
|
-
|
|
1053
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1054
|
-
|
|
1055
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1056
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1057
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
1061
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
1062
|
-
|
|
1063
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
1064
|
-
// Fallback for engines without symbol support
|
|
1065
|
-
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
1066
|
-
if (it) o = it;
|
|
1067
|
-
|
|
1068
|
-
var i = 0;
|
|
1069
|
-
|
|
1070
|
-
return function() {
|
|
1071
|
-
if (i >= o.length) return { done: true };
|
|
1072
|
-
|
|
1073
|
-
return { done: false, value: o[i++] };
|
|
1074
|
-
};
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
1214
|
/**
|
|
1081
1215
|
* The Prefab resource.
|
|
1082
1216
|
*/ var PrefabResource = /*#__PURE__*/ function(ReferResource1) {
|
|
@@ -1108,8 +1242,9 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
1108
1242
|
};
|
|
1109
1243
|
_proto._onDestroy = function _onDestroy() {
|
|
1110
1244
|
var _this = this;
|
|
1245
|
+
var _this__root;
|
|
1111
1246
|
ReferResource1.prototype._onDestroy.call(this);
|
|
1112
|
-
this._root.destroy();
|
|
1247
|
+
(_this__root = this._root) == null ? void 0 : _this__root.destroy();
|
|
1113
1248
|
this._dependenceAssets.forEach(function(asset) {
|
|
1114
1249
|
if (_instanceof(asset, engineCore.ReferResource)) {
|
|
1115
1250
|
// @ts-ignore
|
|
@@ -1125,319 +1260,260 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
1125
1260
|
var _this = this;
|
|
1126
1261
|
this.data = data;
|
|
1127
1262
|
this.context = context;
|
|
1128
|
-
|
|
1129
|
-
|
|
1263
|
+
if (data.version !== "2.0") {
|
|
1264
|
+
var resourceType = context.type === ParserType.Scene ? "scene" : "prefab";
|
|
1265
|
+
throw new Error("Unsupported " + resourceType + ' format version "' + data.version + '". Expected "2.0".');
|
|
1266
|
+
}
|
|
1130
1267
|
this._engine = this.context.engine;
|
|
1131
|
-
this._organizeEntities = this._organizeEntities.bind(this);
|
|
1132
|
-
this._parseComponents = this._parseComponents.bind(this);
|
|
1133
|
-
this._parsePrefabModification = this._parsePrefabModification.bind(this);
|
|
1134
|
-
this._parseAddedComponents = this._parseAddedComponents.bind(this);
|
|
1135
|
-
this._parseComponentsPropsAndMethods = this._parseComponentsPropsAndMethods.bind(this);
|
|
1136
|
-
this._parsePrefabRemovedEntities = this._parsePrefabRemovedEntities.bind(this);
|
|
1137
|
-
this._parsePrefabRemovedComponents = this._parsePrefabRemovedComponents.bind(this);
|
|
1138
|
-
this._clearAndResolve = this._clearAndResolve.bind(this);
|
|
1139
1268
|
this.promise = new Promise(function(resolve, reject) {
|
|
1140
1269
|
_this._reject = reject;
|
|
1141
1270
|
_this._resolve = resolve;
|
|
1142
1271
|
});
|
|
1143
|
-
this._reflectionParser = new ReflectionParser(context);
|
|
1272
|
+
this._reflectionParser = new ReflectionParser(context, data.refs);
|
|
1144
1273
|
}
|
|
1145
1274
|
var _proto = HierarchyParser.prototype;
|
|
1146
|
-
|
|
1147
|
-
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);
|
|
1148
|
-
};
|
|
1149
|
-
_proto._applyEntityData = function _applyEntityData(entity, entityConfig) {
|
|
1150
|
-
if (entityConfig === void 0) entityConfig = {};
|
|
1151
|
-
var _entityConfig_isActive;
|
|
1152
|
-
entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : entity.isActive;
|
|
1153
|
-
var _entityConfig_name;
|
|
1154
|
-
entity.name = (_entityConfig_name = entityConfig.name) != null ? _entityConfig_name : entity.name;
|
|
1155
|
-
var transform = entity.transform;
|
|
1156
|
-
var transformConfig = entityConfig.transform;
|
|
1157
|
-
if (transformConfig) {
|
|
1158
|
-
this._reflectionParser.parsePropsAndMethods(transform, transformConfig);
|
|
1159
|
-
} else {
|
|
1160
|
-
var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale;
|
|
1161
|
-
if (position) transform.position.copyFrom(position);
|
|
1162
|
-
if (rotation) transform.rotation.copyFrom(rotation);
|
|
1163
|
-
if (scale) transform.scale.copyFrom(scale);
|
|
1164
|
-
}
|
|
1165
|
-
if (entityConfig.layer) entity.layer = entityConfig.layer;
|
|
1166
|
-
return entity;
|
|
1167
|
-
};
|
|
1168
|
-
_proto._parseEntities = function _parseEntities() {
|
|
1275
|
+
_proto.start = function start() {
|
|
1169
1276
|
var _this = this;
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
return _this.
|
|
1180
|
-
});
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
for(var i = 0, l = entitiesConfig.length; i < l; i++){
|
|
1199
|
-
var entityConfig = entitiesConfig[i];
|
|
1200
|
-
if (entityConfig.strippedId) {
|
|
1201
|
-
continue;
|
|
1202
|
-
}
|
|
1203
|
-
var entity = entityMap.get(entityConfig.id);
|
|
1204
|
-
this._addComponents(entity, entityConfig.components);
|
|
1205
|
-
}
|
|
1206
|
-
};
|
|
1207
|
-
_proto._parsePrefabModification = function _parsePrefabModification() {
|
|
1208
|
-
var _loop = function(i, l) {
|
|
1209
|
-
var entityConfig = entitiesConfig[i];
|
|
1210
|
-
var id = entityConfig.id, modifications = entityConfig.modifications;
|
|
1211
|
-
if (modifications == null ? void 0 : modifications.length) {
|
|
1212
|
-
var _promises;
|
|
1213
|
-
var rootEntity = entityMap.get(id);
|
|
1214
|
-
(_promises = promises).push.apply(_promises, [].concat(modifications.map(function(modification) {
|
|
1215
|
-
var target = modification.target, props = modification.props, methods = modification.methods;
|
|
1216
|
-
var entityId = target.entityId, componentId = target.componentId;
|
|
1217
|
-
var context = _this._prefabContextMap.get(rootEntity);
|
|
1218
|
-
var targetEntity = context.entityMap.get(entityId);
|
|
1219
|
-
var targetComponent = context.components.get(componentId);
|
|
1220
|
-
if (targetComponent) {
|
|
1221
|
-
return _this._reflectionParser.parsePropsAndMethods(targetComponent, {
|
|
1222
|
-
props: props,
|
|
1223
|
-
methods: methods
|
|
1224
|
-
});
|
|
1225
|
-
} else if (targetEntity) {
|
|
1226
|
-
return Promise.resolve(_this._applyEntityData(targetEntity, props));
|
|
1227
|
-
}
|
|
1228
|
-
})));
|
|
1277
|
+
this._parseEntities().then(function() {
|
|
1278
|
+
return _this._organizeEntities();
|
|
1279
|
+
}).then(function() {
|
|
1280
|
+
return _this._parseComponents();
|
|
1281
|
+
}).then(function() {
|
|
1282
|
+
return _this._parseComponentsPropsAndCalls();
|
|
1283
|
+
}).then(function() {
|
|
1284
|
+
return _this._parsePrefabOverrides();
|
|
1285
|
+
}).then(function() {
|
|
1286
|
+
return _this._clearAndResolve();
|
|
1287
|
+
}).then(this._resolve).catch(this._reject);
|
|
1288
|
+
};
|
|
1289
|
+
_proto._onEntityCreated = function _onEntityCreated(_entity) {};
|
|
1290
|
+
// ---------------------------------------------------------------------------
|
|
1291
|
+
// Stage 1: Create entity instances
|
|
1292
|
+
// ---------------------------------------------------------------------------
|
|
1293
|
+
_proto._parseEntities = function _parseEntities() {
|
|
1294
|
+
var _this, _loop = function(i, n) {
|
|
1295
|
+
var entityConfig = entities[i];
|
|
1296
|
+
if (HierarchyParser._isPrefabInstanceEntity(entityConfig)) {
|
|
1297
|
+
promises.push(_this._loadPrefabInstance(entityConfig, engine).then(function(entity) {
|
|
1298
|
+
entityInstances[i] = entity;
|
|
1299
|
+
}));
|
|
1300
|
+
} else {
|
|
1301
|
+
var entity = new engineCore.Entity(engine, entityConfig.name);
|
|
1302
|
+
HierarchyParser._applyEntityProps(entity, entityConfig);
|
|
1303
|
+
_this._onEntityCreated(entity);
|
|
1304
|
+
entityInstances[i] = entity;
|
|
1229
1305
|
}
|
|
1230
1306
|
};
|
|
1231
|
-
var
|
|
1232
|
-
var
|
|
1233
|
-
var
|
|
1307
|
+
var entities = this.data.entities;
|
|
1308
|
+
var entityInstances = this.context.entityInstances;
|
|
1309
|
+
var engine = this._engine;
|
|
1234
1310
|
var promises = [];
|
|
1235
|
-
for(var i = 0,
|
|
1311
|
+
for(var i = 0, n = entities.length; i < n; i++)_this = this, _loop(i);
|
|
1236
1312
|
return Promise.all(promises);
|
|
1237
1313
|
};
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
var
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
var entityConfig = entitiesConfig[i];
|
|
1254
|
-
var id = entityConfig.id, removedEntities = entityConfig.removedEntities;
|
|
1255
|
-
if (removedEntities == null ? void 0 : removedEntities.length) {
|
|
1256
|
-
var rootEntity = entityMap.get(id);
|
|
1257
|
-
for(var j = 0, m = removedEntities.length; j < m; j++){
|
|
1258
|
-
var target = removedEntities[j];
|
|
1259
|
-
var entityId = target.entityId;
|
|
1260
|
-
var context = this._prefabContextMap.get(rootEntity);
|
|
1261
|
-
var targetEntity = context.entityMap.get(entityId);
|
|
1262
|
-
if (targetEntity) {
|
|
1263
|
-
targetEntity.destroy();
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1314
|
+
// ---------------------------------------------------------------------------
|
|
1315
|
+
// Stage 2: Build parent-child hierarchy
|
|
1316
|
+
// ---------------------------------------------------------------------------
|
|
1317
|
+
_proto._organizeEntities = function _organizeEntities() {
|
|
1318
|
+
var entities = this.data.entities;
|
|
1319
|
+
var entityInstances = this.context.entityInstances;
|
|
1320
|
+
for(var i = 0, n = entities.length; i < n; i++){
|
|
1321
|
+
var entityConfig = entities[i];
|
|
1322
|
+
// Prefab instance entities manage their own children.
|
|
1323
|
+
if (HierarchyParser._isPrefabInstanceEntity(entityConfig)) continue;
|
|
1324
|
+
var children = entityConfig.children;
|
|
1325
|
+
if (!children) continue;
|
|
1326
|
+
var parent = entityInstances[i];
|
|
1327
|
+
for(var j = 0, m = children.length; j < m; j++){
|
|
1328
|
+
parent.addChild(entityInstances[children[j]]);
|
|
1266
1329
|
}
|
|
1267
1330
|
}
|
|
1331
|
+
var rootIndices = this._getRootIndices();
|
|
1332
|
+
for(var i1 = 0, n1 = rootIndices.length; i1 < n1; i1++){
|
|
1333
|
+
this._handleRootEntity(rootIndices[i1]);
|
|
1334
|
+
}
|
|
1268
1335
|
};
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1336
|
+
// ---------------------------------------------------------------------------
|
|
1337
|
+
// Stage 3: Add components to entities
|
|
1338
|
+
// ---------------------------------------------------------------------------
|
|
1339
|
+
_proto._parseComponents = function _parseComponents() {
|
|
1340
|
+
var entities = this.data.entities;
|
|
1341
|
+
var allComponents = this.data.components;
|
|
1342
|
+
var entityInstances = this.context.entityInstances;
|
|
1343
|
+
var pendingComponents = this.context.pendingComponents;
|
|
1344
|
+
var refs = this.data.refs;
|
|
1345
|
+
for(var i = 0, n = entities.length; i < n; i++){
|
|
1346
|
+
var entityConfig = entities[i];
|
|
1347
|
+
if (HierarchyParser._isPrefabInstanceEntity(entityConfig)) continue;
|
|
1348
|
+
var entity = entityInstances[i];
|
|
1349
|
+
var componentIndices = entityConfig.components;
|
|
1350
|
+
if (!componentIndices) continue;
|
|
1351
|
+
for(var j = 0, m = componentIndices.length; j < m; j++){
|
|
1352
|
+
var config = allComponents[componentIndices[j]];
|
|
1353
|
+
var instance = HierarchyParser._addComponentFromConfig(entity, config, refs);
|
|
1354
|
+
pendingComponents.push({
|
|
1355
|
+
instance: instance,
|
|
1356
|
+
config: config
|
|
1357
|
+
});
|
|
1287
1358
|
}
|
|
1288
1359
|
}
|
|
1289
1360
|
};
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1361
|
+
// ---------------------------------------------------------------------------
|
|
1362
|
+
// Stage 4: Apply props and execute calls on components
|
|
1363
|
+
// ---------------------------------------------------------------------------
|
|
1364
|
+
_proto._parseComponentsPropsAndCalls = function _parseComponentsPropsAndCalls() {
|
|
1365
|
+
var pendingComponents = this.context.pendingComponents;
|
|
1366
|
+
var reflectionParser = this._reflectionParser;
|
|
1367
|
+
var promises = [];
|
|
1368
|
+
for(var i = 0, n = pendingComponents.length; i < n; i++){
|
|
1369
|
+
var _pendingComponents_i = pendingComponents[i], instance = _pendingComponents_i.instance, config = _pendingComponents_i.config;
|
|
1370
|
+
promises.push(reflectionParser.parseMutationBlock(instance, config));
|
|
1298
1371
|
}
|
|
1372
|
+
return Promise.all(promises);
|
|
1299
1373
|
};
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1374
|
+
// ---------------------------------------------------------------------------
|
|
1375
|
+
// Stage 5: Apply prefab instance overrides
|
|
1376
|
+
// ---------------------------------------------------------------------------
|
|
1377
|
+
_proto._parsePrefabOverrides = function _parsePrefabOverrides() {
|
|
1378
|
+
var entities = this.data.entities;
|
|
1379
|
+
var entityInstances = this.context.entityInstances;
|
|
1380
|
+
var promises = [];
|
|
1381
|
+
for(var i = 0, n = entities.length; i < n; i++){
|
|
1382
|
+
var entityConfig = entities[i];
|
|
1383
|
+
if (!HierarchyParser._isPrefabInstanceEntity(entityConfig)) continue;
|
|
1384
|
+
var overrides = entityConfig.instance.overrides;
|
|
1385
|
+
if (!overrides) continue;
|
|
1386
|
+
this._applyOverrides(entityInstances[i], overrides, promises);
|
|
1309
1387
|
}
|
|
1310
|
-
return
|
|
1311
|
-
return _this._applyEntityData(entity, entityConfig);
|
|
1312
|
-
});
|
|
1388
|
+
return Promise.all(promises);
|
|
1313
1389
|
};
|
|
1314
|
-
_proto.
|
|
1315
|
-
var
|
|
1316
|
-
var
|
|
1317
|
-
|
|
1318
|
-
|
|
1390
|
+
_proto._applyOverrides = function _applyOverrides(rootEntity, overrides, promises) {
|
|
1391
|
+
var refs = this.data.refs;
|
|
1392
|
+
var reflectionParser = this._reflectionParser;
|
|
1393
|
+
// entityProps — entity-level property overrides
|
|
1394
|
+
if (overrides.entityProps) {
|
|
1395
|
+
for(var j = 0, m = overrides.entityProps.length; j < m; j++){
|
|
1396
|
+
var override = overrides.entityProps[j];
|
|
1397
|
+
HierarchyParser._applyEntityProps(HierarchyParser._resolveEntity(rootEntity, override.path), override);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
// componentProps — component-level property overrides
|
|
1401
|
+
if (overrides.componentProps) {
|
|
1402
|
+
for(var j1 = 0, m1 = overrides.componentProps.length; j1 < m1; j1++){
|
|
1403
|
+
var override1 = overrides.componentProps[j1];
|
|
1404
|
+
var entity = HierarchyParser._resolveEntity(rootEntity, override1.path);
|
|
1405
|
+
var target = HierarchyParser._resolveComponent(entity, override1.selector);
|
|
1406
|
+
promises.push(reflectionParser.parseMutationBlock(target, override1));
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
// addedComponents — attach top-level components[index] to a prefab entity and parse props
|
|
1410
|
+
if (overrides.addedComponents) {
|
|
1411
|
+
var allComponents = this.data.components;
|
|
1412
|
+
for(var j2 = 0, m2 = overrides.addedComponents.length; j2 < m2; j2++){
|
|
1413
|
+
var added = overrides.addedComponents[j2];
|
|
1414
|
+
var entity1 = HierarchyParser._resolveEntity(rootEntity, added.target);
|
|
1415
|
+
var config = allComponents[added.component];
|
|
1416
|
+
var component = HierarchyParser._addComponentFromConfig(entity1, config, refs);
|
|
1417
|
+
promises.push(reflectionParser.parseMutationBlock(component, config));
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
// addedEntities — attach already-created top-level entityInstances[index] as a child
|
|
1421
|
+
if (overrides.addedEntities) {
|
|
1422
|
+
var entityInstances = this.context.entityInstances;
|
|
1423
|
+
for(var j3 = 0, m3 = overrides.addedEntities.length; j3 < m3; j3++){
|
|
1424
|
+
var added1 = overrides.addedEntities[j3];
|
|
1425
|
+
var parent = HierarchyParser._resolveEntity(rootEntity, added1.parent);
|
|
1426
|
+
parent.addChild(entityInstances[added1.entity]);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
// removedEntities — pre-resolve all targets then destroy (destroy shifts sibling indices)
|
|
1430
|
+
if (overrides.removedEntities) {
|
|
1431
|
+
var removed = overrides.removedEntities;
|
|
1432
|
+
var targets = new Array(removed.length);
|
|
1433
|
+
for(var j4 = 0, m4 = removed.length; j4 < m4; j4++){
|
|
1434
|
+
targets[j4] = HierarchyParser._resolveEntity(rootEntity, removed[j4]);
|
|
1435
|
+
}
|
|
1436
|
+
for(var j5 = 0, m5 = targets.length; j5 < m5; j5++){
|
|
1437
|
+
targets[j5].destroy();
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
// removedComponents — pre-resolve all targets then destroy (destroy shifts component indices)
|
|
1441
|
+
if (overrides.removedComponents) {
|
|
1442
|
+
var targets1 = [];
|
|
1443
|
+
for(var j6 = 0, m6 = overrides.removedComponents.length; j6 < m6; j6++){
|
|
1444
|
+
var override2 = overrides.removedComponents[j6];
|
|
1445
|
+
var entity2 = HierarchyParser._resolveEntity(rootEntity, override2.path);
|
|
1446
|
+
var selectors = override2.selectors;
|
|
1447
|
+
for(var k = 0, p = selectors.length; k < p; k++){
|
|
1448
|
+
targets1.push(HierarchyParser._resolveComponent(entity2, selectors[k]));
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
for(var j7 = 0, m7 = targets1.length; j7 < m7; j7++){
|
|
1452
|
+
targets1[j7].destroy();
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1319
1455
|
};
|
|
1320
|
-
|
|
1456
|
+
// ---------------------------------------------------------------------------
|
|
1457
|
+
// Prefab instance loading
|
|
1458
|
+
// ---------------------------------------------------------------------------
|
|
1459
|
+
_proto._loadPrefabInstance = function _loadPrefabInstance(entityConfig, engine) {
|
|
1321
1460
|
var _this = this;
|
|
1322
|
-
var
|
|
1461
|
+
var instance = entityConfig.instance;
|
|
1462
|
+
var refItem;
|
|
1463
|
+
try {
|
|
1464
|
+
refItem = resolveRefItem(this.data.refs, instance.asset, "HierarchyParser", "instance.asset");
|
|
1465
|
+
} catch (error) {
|
|
1466
|
+
return Promise.reject(error);
|
|
1467
|
+
}
|
|
1323
1468
|
return engine.resourceManager// @ts-ignore
|
|
1324
|
-
.getResourceByRef({
|
|
1325
|
-
url: assetUrl
|
|
1326
|
-
}).then(function(prefabResource) {
|
|
1469
|
+
.getResourceByRef(refItem).then(function(prefabResource) {
|
|
1327
1470
|
var entity = _instanceof(prefabResource, PrefabResource) ? prefabResource.instantiate() : prefabResource.instantiateSceneRoot();
|
|
1328
|
-
|
|
1329
|
-
_this._generateInstanceContext(entity, instanceContext, "");
|
|
1330
|
-
_this._prefabContextMap.set(entity, instanceContext);
|
|
1331
|
-
var cbArray = _this._prefabPromiseMap.get(entityConfig.id);
|
|
1332
|
-
if (cbArray) {
|
|
1333
|
-
for(var i = 0, n = cbArray.length; i < n; i++){
|
|
1334
|
-
cbArray[i].resolve(instanceContext);
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1471
|
+
_this._onEntityCreated(entity);
|
|
1337
1472
|
return entity;
|
|
1338
1473
|
});
|
|
1339
1474
|
};
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
reject: reject
|
|
1349
|
-
});
|
|
1350
|
-
_this._prefabPromiseMap.set(entityConfig.prefabInstanceId, cbArray);
|
|
1351
|
-
}).then(function(context) {
|
|
1352
|
-
var entityId = entityConfig.prefabSource.entityId;
|
|
1353
|
-
return context.entityMap.get(entityId);
|
|
1354
|
-
});
|
|
1355
|
-
};
|
|
1356
|
-
_proto._parseChildren = function _parseChildren(parentId) {
|
|
1357
|
-
var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap;
|
|
1358
|
-
var children = entityConfigMap.get(parentId).children;
|
|
1359
|
-
if (children && children.length > 0) {
|
|
1360
|
-
var parent = entityMap.get(parentId);
|
|
1361
|
-
for(var i = 0; i < children.length; i++){
|
|
1362
|
-
var childId = children[i];
|
|
1363
|
-
var entity = entityMap.get(childId);
|
|
1364
|
-
parent.addChild(entity);
|
|
1365
|
-
this._parseChildren(childId);
|
|
1366
|
-
}
|
|
1475
|
+
// ---------------------------------------------------------------------------
|
|
1476
|
+
// Utilities
|
|
1477
|
+
// ---------------------------------------------------------------------------
|
|
1478
|
+
/** Resolve an entity inside a prefab instance by walking the child-index path from root */ HierarchyParser._resolveEntity = function _resolveEntity(root, path) {
|
|
1479
|
+
var entity = root;
|
|
1480
|
+
for(var i = 0, n = path.length; i < n; i++){
|
|
1481
|
+
entity = entity.children[path[i]];
|
|
1482
|
+
if (!entity) throw new Error("HierarchyParser: override target entity not found at path [" + path + "], failed at depth " + i);
|
|
1367
1483
|
}
|
|
1484
|
+
return entity;
|
|
1368
1485
|
};
|
|
1369
|
-
|
|
1370
|
-
var
|
|
1371
|
-
|
|
1372
|
-
var
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
componentConfigMap.set(componentId, componentConfig);
|
|
1380
|
-
this._addComponentPlugin(componentId, component);
|
|
1381
|
-
}
|
|
1382
|
-
};
|
|
1383
|
-
_proto._generateInstanceContext = function _generateInstanceContext(entity, context, path) {
|
|
1384
|
-
var entityMap = context.entityMap, components = context.components;
|
|
1385
|
-
var componentsMap = {};
|
|
1386
|
-
var componentIndexMap = {};
|
|
1387
|
-
entityMap.set(path, entity);
|
|
1388
|
-
// @ts-ignore
|
|
1389
|
-
entity._components.forEach(function(component) {
|
|
1390
|
-
// @ts-ignore
|
|
1391
|
-
var name = engineCore.Loader.getClassName(component.constructor);
|
|
1392
|
-
if (!componentsMap[name]) {
|
|
1393
|
-
componentsMap[name] = entity.getComponents(component.constructor, []);
|
|
1394
|
-
componentIndexMap[name] = 0;
|
|
1395
|
-
}
|
|
1396
|
-
components.set(path + ":" + name + "/" + componentIndexMap[name]++, component);
|
|
1397
|
-
});
|
|
1398
|
-
for(var i = 0, n = entity.children.length; i < n; i++){
|
|
1399
|
-
var child = entity.children[i];
|
|
1400
|
-
var childPath = path ? path + "/" + i : "" + i;
|
|
1401
|
-
this._generateInstanceContext(child, context, childPath);
|
|
1402
|
-
}
|
|
1486
|
+
/** Resolve a component on an entity by type name + per-type index */ HierarchyParser._resolveComponent = function _resolveComponent(entity, selector) {
|
|
1487
|
+
var type = engineCore.Loader.getClass(selector.type);
|
|
1488
|
+
if (!type) throw new Error('HierarchyParser: override target component type "' + selector.type + '" is not registered');
|
|
1489
|
+
var buffer = ReflectionParser._componentBuffer;
|
|
1490
|
+
buffer.length = 0;
|
|
1491
|
+
entity.getComponents(type, buffer);
|
|
1492
|
+
var result = buffer[selector.index];
|
|
1493
|
+
buffer.length = 0;
|
|
1494
|
+
if (!result) throw new Error("HierarchyParser: override target component not found: " + selector.type + "/" + selector.index);
|
|
1495
|
+
return result;
|
|
1403
1496
|
};
|
|
1404
|
-
|
|
1405
|
-
var
|
|
1406
|
-
var
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1497
|
+
/** Resolve component class from config and add to entity. Throws if class is not registered. */ HierarchyParser._addComponentFromConfig = function _addComponentFromConfig(entity, config, refs) {
|
|
1498
|
+
var key = config.script != null ? resolveRefItem(refs, config.script, "HierarchyParser", "component.script").url : config.type;
|
|
1499
|
+
var Class = engineCore.Loader.getClass(key);
|
|
1500
|
+
if (!Class) throw new Error('Loader.getClass: class "' + key + '" is not registered');
|
|
1501
|
+
return entity.addComponent(Class);
|
|
1502
|
+
};
|
|
1503
|
+
HierarchyParser._isPrefabInstanceEntity = function _isPrefabInstanceEntity(entityConfig) {
|
|
1504
|
+
return "instance" in entityConfig;
|
|
1505
|
+
};
|
|
1506
|
+
/** Apply entity-level props (name, isActive, layer, transform) to an entity. */ HierarchyParser._applyEntityProps = function _applyEntityProps(entity, props) {
|
|
1507
|
+
if (props.name != null) entity.name = props.name;
|
|
1508
|
+
if (props.isActive != null) entity.isActive = props.isActive;
|
|
1509
|
+
if (props.layer != null) entity.layer = props.layer;
|
|
1510
|
+
if (props.position) entity.transform.position.set(props.position[0], props.position[1], props.position[2]);
|
|
1511
|
+
if (props.rotation) entity.transform.rotation.set(props.rotation[0], props.rotation[1], props.rotation[2]);
|
|
1512
|
+
if (props.scale) entity.transform.scale.set(props.scale[0], props.scale[1], props.scale[2]);
|
|
1417
1513
|
};
|
|
1418
|
-
_proto._addComponentPlugin = function _addComponentPlugin(componentId, component) {};
|
|
1419
|
-
_proto._addEntityPlugin = function _addEntityPlugin(entityId, entity) {};
|
|
1420
1514
|
return HierarchyParser;
|
|
1421
1515
|
}();
|
|
1422
1516
|
|
|
1423
|
-
var MaterialLoaderType = /*#__PURE__*/ function(MaterialLoaderType) {
|
|
1424
|
-
MaterialLoaderType["Vector2"] = "Vector2";
|
|
1425
|
-
MaterialLoaderType["Vector3"] = "Vector3";
|
|
1426
|
-
MaterialLoaderType["Vector4"] = "Vector4";
|
|
1427
|
-
MaterialLoaderType["Color"] = "Color";
|
|
1428
|
-
MaterialLoaderType["Float"] = "Float";
|
|
1429
|
-
MaterialLoaderType["Texture"] = "Texture";
|
|
1430
|
-
MaterialLoaderType["Boolean"] = "Boolean";
|
|
1431
|
-
MaterialLoaderType["Integer"] = "Integer";
|
|
1432
|
-
return MaterialLoaderType;
|
|
1433
|
-
}({});
|
|
1434
|
-
|
|
1435
|
-
var SpecularMode = /*#__PURE__*/ function(SpecularMode) {
|
|
1436
|
-
SpecularMode["Sky"] = "Sky";
|
|
1437
|
-
SpecularMode["Custom"] = "Custom";
|
|
1438
|
-
return SpecularMode;
|
|
1439
|
-
}({});
|
|
1440
|
-
|
|
1441
1517
|
/** @Internal */ var SceneParser = /*#__PURE__*/ function(HierarchyParser) {
|
|
1442
1518
|
_inherits(SceneParser, HierarchyParser);
|
|
1443
1519
|
function SceneParser(data, context, scene) {
|
|
@@ -1451,91 +1527,43 @@ var SpecularMode = /*#__PURE__*/ function(SpecularMode) {
|
|
|
1451
1527
|
*/ _proto._collectDependentAssets = function _collectDependentAssets(data) {
|
|
1452
1528
|
var context = this.context;
|
|
1453
1529
|
var resourceManager = context.resourceManager;
|
|
1454
|
-
|
|
1455
|
-
var
|
|
1456
|
-
var ambient = scene.ambient;
|
|
1457
|
-
if (ambient) {
|
|
1458
|
-
var useCustomAmbient = ambient.specularMode === SpecularMode.Custom;
|
|
1459
|
-
var useSH = ambient.diffuseMode === engineCore.DiffuseMode.SphericalHarmonics;
|
|
1460
|
-
var customAmbientLight = ambient.customAmbientLight, ambientLight = ambient.ambientLight;
|
|
1461
|
-
if (useCustomAmbient && customAmbientLight) {
|
|
1462
|
-
// @ts-ignore
|
|
1463
|
-
context._addDependentAsset(customAmbientLight.url, resourceManager.getResourceByRef(customAmbientLight));
|
|
1464
|
-
}
|
|
1465
|
-
if (ambientLight && (!useCustomAmbient || useSH)) {
|
|
1466
|
-
// @ts-ignore
|
|
1467
|
-
context._addDependentAsset(ambientLight.url, resourceManager.getResourceByRef(ambientLight));
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
var background = scene.background;
|
|
1471
|
-
var backgroundMode = background.mode;
|
|
1472
|
-
if (backgroundMode === engineCore.BackgroundMode.Texture) {
|
|
1473
|
-
var texture = background.texture;
|
|
1530
|
+
var refs = data.refs;
|
|
1531
|
+
for(var i = 0, n = refs.length; i < n; i++){
|
|
1474
1532
|
// @ts-ignore
|
|
1475
|
-
|
|
1476
|
-
} else if (backgroundMode === engineCore.BackgroundMode.Sky) {
|
|
1477
|
-
var skyMesh = background.skyMesh, skyMaterial = background.skyMaterial;
|
|
1478
|
-
if (skyMesh && skyMaterial) {
|
|
1479
|
-
// @ts-ignore
|
|
1480
|
-
context._addDependentAsset(skyMesh.url, resourceManager.getResourceByRef(skyMesh));
|
|
1481
|
-
// @ts-ignore
|
|
1482
|
-
context._addDependentAsset(skyMaterial.url, resourceManager.getResourceByRef(skyMaterial));
|
|
1483
|
-
}
|
|
1533
|
+
context._addDependentAsset(resourceManager.getResourceByRef(refs[i]));
|
|
1484
1534
|
}
|
|
1485
1535
|
};
|
|
1486
|
-
_proto.
|
|
1487
|
-
|
|
1488
|
-
|
|
1536
|
+
_proto._getRootIndices = function _getRootIndices() {
|
|
1537
|
+
return this.data.scene.rootEntities;
|
|
1538
|
+
};
|
|
1539
|
+
_proto._handleRootEntity = function _handleRootEntity(index) {
|
|
1540
|
+
this.scene.addRootEntity(this.context.entityInstances[index]);
|
|
1489
1541
|
};
|
|
1490
1542
|
_proto._clearAndResolve = function _clearAndResolve() {
|
|
1491
1543
|
this.context.clear();
|
|
1492
1544
|
return this.scene;
|
|
1493
1545
|
};
|
|
1494
|
-
_proto._parseDependentAssets = function _parseDependentAssets(file) {
|
|
1495
|
-
var entities = file.entities;
|
|
1496
|
-
for(var i = 0, n = entities.length; i < n; i++){
|
|
1497
|
-
var entity = entities[i];
|
|
1498
|
-
if (!!entity.assetUrl) {
|
|
1499
|
-
var context = this.context;
|
|
1500
|
-
var url = entity.assetUrl, key = entity.key;
|
|
1501
|
-
// @ts-ignore
|
|
1502
|
-
context._addDependentAsset(url, context.resourceManager.getResourceByRef({
|
|
1503
|
-
url: url,
|
|
1504
|
-
key: key
|
|
1505
|
-
}));
|
|
1506
|
-
} else if (entity.strippedId) {
|
|
1507
|
-
continue;
|
|
1508
|
-
} else {
|
|
1509
|
-
var components = entity.components;
|
|
1510
|
-
for(var j = 0, m = components.length; j < m; j++){
|
|
1511
|
-
var component = components[j];
|
|
1512
|
-
this._searchDependentAssets(component.methods);
|
|
1513
|
-
this._searchDependentAssets(component.props);
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
};
|
|
1518
|
-
_proto._searchDependentAssets = function _searchDependentAssets(value) {
|
|
1519
|
-
if (Array.isArray(value)) {
|
|
1520
|
-
for(var i = 0, n = value.length; i < n; i++){
|
|
1521
|
-
this._searchDependentAssets(value[i]);
|
|
1522
|
-
}
|
|
1523
|
-
} else if (!!value && (typeof value === "undefined" ? "undefined" : _type_of(value)) === "object") {
|
|
1524
|
-
// @ts-ignore
|
|
1525
|
-
if (ReflectionParser._isAssetRef(value)) {
|
|
1526
|
-
var context = this.context;
|
|
1527
|
-
// @ts-ignore
|
|
1528
|
-
context._addDependentAsset(value.url, context.resourceManager.getResourceByRef(value));
|
|
1529
|
-
} else {
|
|
1530
|
-
for(var key in value){
|
|
1531
|
-
this._searchDependentAssets(value[key]);
|
|
1532
|
-
}
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
};
|
|
1536
1546
|
return SceneParser;
|
|
1537
1547
|
}(HierarchyParser);
|
|
1538
1548
|
|
|
1549
|
+
var SpecularMode = /*#__PURE__*/ function(SpecularMode) {
|
|
1550
|
+
SpecularMode[SpecularMode["Sky"] = 0] = "Sky";
|
|
1551
|
+
SpecularMode[SpecularMode["Custom"] = 1] = "Custom";
|
|
1552
|
+
return SpecularMode;
|
|
1553
|
+
}({});
|
|
1554
|
+
|
|
1555
|
+
var MaterialLoaderType = /*#__PURE__*/ function(MaterialLoaderType) {
|
|
1556
|
+
MaterialLoaderType["Vector2"] = "Vector2";
|
|
1557
|
+
MaterialLoaderType["Vector3"] = "Vector3";
|
|
1558
|
+
MaterialLoaderType["Vector4"] = "Vector4";
|
|
1559
|
+
MaterialLoaderType["Color"] = "Color";
|
|
1560
|
+
MaterialLoaderType["Float"] = "Float";
|
|
1561
|
+
MaterialLoaderType["Texture"] = "Texture";
|
|
1562
|
+
MaterialLoaderType["Boolean"] = "Boolean";
|
|
1563
|
+
MaterialLoaderType["Integer"] = "Integer";
|
|
1564
|
+
return MaterialLoaderType;
|
|
1565
|
+
}({});
|
|
1566
|
+
|
|
1539
1567
|
/**
|
|
1540
1568
|
* Decode engine binary resource.
|
|
1541
1569
|
* @param arrayBuffer - array buffer of decode binary file
|
|
@@ -3017,6 +3045,45 @@ function getMeshoptDecoder() {
|
|
|
3017
3045
|
return GLTFResource;
|
|
3018
3046
|
}(engineCore.ReferResource);
|
|
3019
3047
|
|
|
3048
|
+
function _array_like_to_array(arr, len) {
|
|
3049
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3050
|
+
|
|
3051
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
3052
|
+
|
|
3053
|
+
return arr2;
|
|
3054
|
+
}
|
|
3055
|
+
|
|
3056
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
3057
|
+
if (!o) return;
|
|
3058
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
3059
|
+
|
|
3060
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
3061
|
+
|
|
3062
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
3063
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
3064
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
3068
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
3069
|
+
|
|
3070
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
3071
|
+
// Fallback for engines without symbol support
|
|
3072
|
+
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
3073
|
+
if (it) o = it;
|
|
3074
|
+
|
|
3075
|
+
var i = 0;
|
|
3076
|
+
|
|
3077
|
+
return function() {
|
|
3078
|
+
if (i >= o.length) return { done: true };
|
|
3079
|
+
|
|
3080
|
+
return { done: false, value: o[i++] };
|
|
3081
|
+
};
|
|
3082
|
+
}
|
|
3083
|
+
|
|
3084
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
3085
|
+
}
|
|
3086
|
+
|
|
3020
3087
|
/**
|
|
3021
3088
|
* Module for glTF 2.0 Interface
|
|
3022
3089
|
*/ /**
|
|
@@ -3638,11 +3705,13 @@ function registerGLTFParser(pipeline) {
|
|
|
3638
3705
|
});
|
|
3639
3706
|
var img = new Image();
|
|
3640
3707
|
img.onerror = function() {
|
|
3708
|
+
URL.revokeObjectURL(img.src);
|
|
3641
3709
|
reject(new Error("Failed to load image buffer"));
|
|
3642
3710
|
};
|
|
3643
3711
|
img.onload = function() {
|
|
3644
3712
|
// Call requestAnimationFrame to avoid iOS's bug.
|
|
3645
3713
|
requestAnimationFrame(function() {
|
|
3714
|
+
URL.revokeObjectURL(img.src);
|
|
3646
3715
|
resolve(img);
|
|
3647
3716
|
img.onload = null;
|
|
3648
3717
|
img.onerror = null;
|
|
@@ -4763,7 +4832,6 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
4763
4832
|
}
|
|
4764
4833
|
var _proto = GLTFSceneParser.prototype;
|
|
4765
4834
|
_proto.parse = function parse(context, index) {
|
|
4766
|
-
var _glTFResource;
|
|
4767
4835
|
var _context_glTF = context.glTF, scenes = _context_glTF.scenes, _context_glTF_scene = _context_glTF.scene, scene = _context_glTF_scene === void 0 ? 0 : _context_glTF_scene, glTFResource = context.glTFResource;
|
|
4768
4836
|
var sceneInfo = scenes[index];
|
|
4769
4837
|
var sceneExtensions = sceneInfo.extensions;
|
|
@@ -4777,7 +4845,6 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
4777
4845
|
for(var i = 0; i < sceneNodes.length; i++){
|
|
4778
4846
|
sceneRoot.addChild(context.get(GLTFParserType.Entity, sceneNodes[i]));
|
|
4779
4847
|
}
|
|
4780
|
-
((_glTFResource = glTFResource)._sceneRoots || (_glTFResource._sceneRoots = []))[index] = sceneRoot;
|
|
4781
4848
|
if (isDefaultScene) {
|
|
4782
4849
|
glTFResource._defaultSceneRoot = sceneRoot;
|
|
4783
4850
|
}
|
|
@@ -4907,13 +4974,15 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
4907
4974
|
if (rootBoneIndex !== -1) {
|
|
4908
4975
|
engineMath.BoundingBox.transform(mesh.bounds, inverseBindMatrices[rootBoneIndex], skinnedMeshRenderer.localBounds);
|
|
4909
4976
|
} else {
|
|
4910
|
-
|
|
4977
|
+
// rootBone can be outside skin.joints, so it has no inverse bind matrix
|
|
4978
|
+
var inverseRootBoneWorld = GLTFSceneParser._tempMatrix;
|
|
4911
4979
|
engineMath.Matrix.invert(rootBone.transform.worldMatrix, inverseRootBoneWorld);
|
|
4912
4980
|
engineMath.BoundingBox.transform(mesh.bounds, inverseRootBoneWorld, skinnedMeshRenderer.localBounds);
|
|
4913
4981
|
}
|
|
4914
4982
|
};
|
|
4915
4983
|
return GLTFSceneParser;
|
|
4916
4984
|
}(GLTFParser);
|
|
4985
|
+
exports.GLTFSceneParser._tempMatrix = new engineMath.Matrix();
|
|
4917
4986
|
exports.GLTFSceneParser = __decorate([
|
|
4918
4987
|
registerGLTFParser(GLTFParserType.Scene)
|
|
4919
4988
|
], exports.GLTFSceneParser);
|
|
@@ -4948,36 +5017,31 @@ exports.GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
4948
5017
|
skin.joints[i] = bone.name;
|
|
4949
5018
|
}
|
|
4950
5019
|
skin.bones = bones;
|
|
4951
|
-
// Get skeleton
|
|
5020
|
+
// Get skeleton — when `skin.skeleton` is absent, resolve via joints' LCA
|
|
5021
|
+
// LCA falls back to the GLTF_ROOT wrapper only when joints span multiple top-level scene nodes
|
|
4952
5022
|
if (skeleton !== undefined) {
|
|
4953
5023
|
var rootBone = entities[skeleton];
|
|
5024
|
+
if (!rootBone) {
|
|
5025
|
+
throw "Skin skeleton index " + skeleton + " is out of range.";
|
|
5026
|
+
}
|
|
4954
5027
|
skin.rootBone = rootBone;
|
|
4955
5028
|
} else {
|
|
4956
|
-
var rootBone1 = _this.
|
|
4957
|
-
if (rootBone1) {
|
|
4958
|
-
skin.rootBone = rootBone1;
|
|
4959
|
-
} else {
|
|
5029
|
+
var rootBone1 = _this._findSkeletonRootBone(joints, entities);
|
|
5030
|
+
if (!rootBone1) {
|
|
4960
5031
|
throw "Failed to find skeleton root bone.";
|
|
4961
5032
|
}
|
|
5033
|
+
skin.rootBone = rootBone1;
|
|
4962
5034
|
}
|
|
4963
5035
|
return skin;
|
|
4964
5036
|
});
|
|
4965
5037
|
return engineCore.AssetPromise.resolve(skinPromise);
|
|
4966
5038
|
};
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
nodeIndices.push(i);
|
|
4974
|
-
}
|
|
4975
|
-
}
|
|
4976
|
-
return this._findRootBoneByLCA(nodeIndices, entities);
|
|
4977
|
-
};
|
|
4978
|
-
_proto._findRootBoneByLCA = function _findRootBoneByLCA(nodeIndices, entities) {
|
|
4979
|
-
var paths = [];
|
|
4980
|
-
for(var _iterator = _create_for_of_iterator_helper_loose(nodeIndices), _step; !(_step = _iterator()).done;){
|
|
5039
|
+
/**
|
|
5040
|
+
* Resolve the skeleton rootBone as the lowest common ancestor of the joints' parent chains.
|
|
5041
|
+
* Returns null when joints share no common ancestor.
|
|
5042
|
+
*/ _proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
|
|
5043
|
+
var paths = {};
|
|
5044
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(joints), _step; !(_step = _iterator()).done;){
|
|
4981
5045
|
var index = _step.value;
|
|
4982
5046
|
var path = new Array();
|
|
4983
5047
|
var entity = entities[index];
|
|
@@ -4985,22 +5049,17 @@ exports.GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
4985
5049
|
path.unshift(entity);
|
|
4986
5050
|
entity = entity.parent;
|
|
4987
5051
|
}
|
|
4988
|
-
|
|
4989
|
-
paths.push(path);
|
|
4990
|
-
}
|
|
4991
|
-
}
|
|
4992
|
-
if (!paths.length) {
|
|
4993
|
-
return null;
|
|
5052
|
+
paths[index] = path;
|
|
4994
5053
|
}
|
|
4995
5054
|
var rootNode = null;
|
|
4996
5055
|
for(var i = 0;; i++){
|
|
4997
|
-
var path1 = paths[0];
|
|
5056
|
+
var path1 = paths[joints[0]];
|
|
4998
5057
|
if (i >= path1.length) {
|
|
4999
5058
|
return rootNode;
|
|
5000
5059
|
}
|
|
5001
5060
|
var entity1 = path1[i];
|
|
5002
|
-
for(var j = 1, m =
|
|
5003
|
-
path1 = paths[j];
|
|
5061
|
+
for(var j = 1, m = joints.length; j < m; j++){
|
|
5062
|
+
path1 = paths[joints[j]];
|
|
5004
5063
|
if (i >= path1.length || entity1 !== path1[i]) {
|
|
5005
5064
|
return rootNode;
|
|
5006
5065
|
}
|
|
@@ -5063,7 +5122,7 @@ exports.GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
5063
5122
|
if (uri) {
|
|
5064
5123
|
var extIndex = uri.lastIndexOf(".");
|
|
5065
5124
|
var ext = uri.substring(extIndex + 1);
|
|
5066
|
-
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.
|
|
5125
|
+
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.Texture;
|
|
5067
5126
|
texture = engine.resourceManager.load({
|
|
5068
5127
|
url: engineCore.Utils.resolveAbsoluteUrl(url, uri),
|
|
5069
5128
|
type: type,
|
|
@@ -5280,15 +5339,17 @@ var PrefabParser = /*#__PURE__*/ function(HierarchyParser) {
|
|
|
5280
5339
|
return _this;
|
|
5281
5340
|
}
|
|
5282
5341
|
var _proto = PrefabParser.prototype;
|
|
5283
|
-
_proto.
|
|
5284
|
-
if (entityConfig === void 0) entityConfig = {};
|
|
5285
|
-
HierarchyParser.prototype._applyEntityData.call(this, entity, entityConfig);
|
|
5342
|
+
_proto._onEntityCreated = function _onEntityCreated(entity) {
|
|
5286
5343
|
// @ts-ignore
|
|
5287
5344
|
entity._markAsTemplate(this.context.resource);
|
|
5288
|
-
return entity;
|
|
5289
5345
|
};
|
|
5290
|
-
_proto.
|
|
5291
|
-
|
|
5346
|
+
_proto._getRootIndices = function _getRootIndices() {
|
|
5347
|
+
return [
|
|
5348
|
+
this.data.root
|
|
5349
|
+
];
|
|
5350
|
+
};
|
|
5351
|
+
_proto._handleRootEntity = function _handleRootEntity(index) {
|
|
5352
|
+
this.prefabResource._root = this.context.entityInstances[index];
|
|
5292
5353
|
};
|
|
5293
5354
|
_proto._clearAndResolve = function _clearAndResolve() {
|
|
5294
5355
|
this.context.clear();
|
|
@@ -5299,9 +5360,7 @@ var PrefabParser = /*#__PURE__*/ function(HierarchyParser) {
|
|
|
5299
5360
|
var context = new ParserContext(engine, ParserType.Prefab, prefabResource);
|
|
5300
5361
|
var parser = new PrefabParser(data, context, prefabResource);
|
|
5301
5362
|
parser.start();
|
|
5302
|
-
return parser.promise
|
|
5303
|
-
return prefabResource;
|
|
5304
|
-
});
|
|
5363
|
+
return parser.promise;
|
|
5305
5364
|
};
|
|
5306
5365
|
return PrefabParser;
|
|
5307
5366
|
}(HierarchyParser);
|
|
@@ -5641,15 +5700,6 @@ var KTXContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
|
5641
5700
|
return KTXContentRestorer;
|
|
5642
5701
|
}(engineCore.ContentRestorer);
|
|
5643
5702
|
|
|
5644
|
-
function parseProperty(object, key, value) {
|
|
5645
|
-
if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object") {
|
|
5646
|
-
for(var subKey in value){
|
|
5647
|
-
parseProperty(object[key], subKey, value[subKey]);
|
|
5648
|
-
}
|
|
5649
|
-
} else {
|
|
5650
|
-
object[key] = value;
|
|
5651
|
-
}
|
|
5652
|
-
}
|
|
5653
5703
|
var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
5654
5704
|
_inherits(MaterialLoader, Loader);
|
|
5655
5705
|
function MaterialLoader() {
|
|
@@ -5710,7 +5760,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5710
5760
|
break;
|
|
5711
5761
|
}
|
|
5712
5762
|
};
|
|
5713
|
-
var name = materialSchema.name, shaderData = materialSchema.shaderData, macros = materialSchema.macros
|
|
5763
|
+
var name = materialSchema.name, shaderData = materialSchema.shaderData, macros = materialSchema.macros;
|
|
5714
5764
|
var material = new engineCore.Material(engine, shader);
|
|
5715
5765
|
material.name = name;
|
|
5716
5766
|
var texturePromises = new Array();
|
|
@@ -5724,7 +5774,6 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5724
5774
|
materialShaderData.enableMacro(name1, value);
|
|
5725
5775
|
}
|
|
5726
5776
|
}
|
|
5727
|
-
parseProperty(material, "renderState", renderState);
|
|
5728
5777
|
return Promise.all(texturePromises).then(function() {
|
|
5729
5778
|
return material;
|
|
5730
5779
|
});
|
|
@@ -5939,7 +5988,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5939
5988
|
var _atlasItem_type;
|
|
5940
5989
|
chainPromises.push(resourceManager.load({
|
|
5941
5990
|
url: engineCore.Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
|
|
5942
|
-
type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : engineCore.AssetType.
|
|
5991
|
+
type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : engineCore.AssetType.Texture,
|
|
5943
5992
|
params: {
|
|
5944
5993
|
format: format,
|
|
5945
5994
|
mipmap: mipmap
|
|
@@ -5989,8 +6038,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5989
6038
|
var offsetLeft = atlasRegionOffset.x, offsetTop = atlasRegionOffset.y, offsetRight = atlasRegionOffset.z, offsetBottom = atlasRegionOffset.w;
|
|
5990
6039
|
sprite.atlasRegionOffset.set(offsetLeft * invW, offsetTop * invH, offsetRight * invW, offsetBottom * invH);
|
|
5991
6040
|
}
|
|
5992
|
-
|
|
5993
|
-
sprite.atlasRotated = (_config_atlasRotated = config.atlasRotated) != null ? _config_atlasRotated : false;
|
|
6041
|
+
config.atlasRotated && (sprite.atlasRotated = true);
|
|
5994
6042
|
}
|
|
5995
6043
|
width === undefined || (sprite.width = width);
|
|
5996
6044
|
height === undefined || (sprite.height = height);
|
|
@@ -6019,517 +6067,210 @@ var SpriteLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6019
6067
|
return data.belongToAtlas ? _this._loadFromAtlas(resourceManager, data) : _this._loadFromTexture(resourceManager, data);
|
|
6020
6068
|
});
|
|
6021
6069
|
};
|
|
6022
|
-
_proto._loadFromAtlas = function _loadFromAtlas(resourceManager, data) {
|
|
6023
|
-
var _this = this;
|
|
6024
|
-
return resourceManager// @ts-ignore
|
|
6025
|
-
.getResourceByRef(data.belongToAtlas).then(function(atlas) {
|
|
6026
|
-
return atlas.getSprite(data.fullPath) || _this._loadFromTexture(resourceManager, data);
|
|
6027
|
-
});
|
|
6028
|
-
};
|
|
6029
|
-
_proto._loadFromTexture = function _loadFromTexture(resourceManager, data) {
|
|
6030
|
-
if (data.texture) {
|
|
6031
|
-
return resourceManager// @ts-ignore
|
|
6032
|
-
.getResourceByRef(data.texture).then(function(texture) {
|
|
6033
|
-
var sprite = new engineCore.Sprite(resourceManager.engine, texture, data.region, data.pivot, data.border);
|
|
6034
|
-
var width = data.width, height = data.height;
|
|
6035
|
-
width === undefined || (sprite.width = width);
|
|
6036
|
-
height === undefined || (sprite.height = height);
|
|
6037
|
-
return sprite;
|
|
6038
|
-
});
|
|
6039
|
-
} else {
|
|
6040
|
-
return new engineCore.AssetPromise(function(resolve) {
|
|
6041
|
-
var sprite = new engineCore.Sprite(resourceManager.engine, null, data.region, data.pivot, data.border);
|
|
6042
|
-
var width = data.width, height = data.height;
|
|
6043
|
-
width === undefined || (sprite.width = width);
|
|
6044
|
-
height === undefined || (sprite.height = height);
|
|
6045
|
-
resolve(sprite);
|
|
6046
|
-
});
|
|
6047
|
-
}
|
|
6048
|
-
};
|
|
6049
|
-
return SpriteLoader;
|
|
6050
|
-
}(engineCore.Loader);
|
|
6051
|
-
SpriteLoader = __decorate([
|
|
6052
|
-
engineCore.resourceLoader(engineCore.AssetType.Sprite, [
|
|
6053
|
-
"sprite"
|
|
6054
|
-
])
|
|
6055
|
-
], SpriteLoader);
|
|
6056
|
-
|
|
6057
|
-
var TextLoader = /*#__PURE__*/ function(Loader) {
|
|
6058
|
-
_inherits(TextLoader, Loader);
|
|
6059
|
-
function TextLoader() {
|
|
6060
|
-
return Loader.apply(this, arguments) || this;
|
|
6061
|
-
}
|
|
6062
|
-
var _proto = TextLoader.prototype;
|
|
6063
|
-
_proto.load = function load(item, resourceManager) {
|
|
6064
|
-
// @ts-ignore
|
|
6065
|
-
return resourceManager._request(item.url, _extends({}, item, {
|
|
6066
|
-
type: "text"
|
|
6067
|
-
})).then(function(text) {
|
|
6068
|
-
var asset = new engineCore.TextAsset(resourceManager.engine);
|
|
6069
|
-
asset.text = text;
|
|
6070
|
-
return asset;
|
|
6071
|
-
});
|
|
6072
|
-
};
|
|
6073
|
-
return TextLoader;
|
|
6074
|
-
}(engineCore.Loader);
|
|
6075
|
-
TextLoader = __decorate([
|
|
6076
|
-
engineCore.resourceLoader(engineCore.AssetType.Text, [
|
|
6077
|
-
"txt"
|
|
6078
|
-
])
|
|
6079
|
-
], TextLoader);
|
|
6080
|
-
|
|
6081
|
-
function loadImageFromBuffer(buffer) {
|
|
6082
|
-
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6083
|
-
var blob = new Blob([
|
|
6084
|
-
buffer
|
|
6085
|
-
]);
|
|
6086
|
-
var img = new Image();
|
|
6087
|
-
img.onload = function() {
|
|
6088
|
-
URL.revokeObjectURL(img.src);
|
|
6089
|
-
resolve(img);
|
|
6090
|
-
};
|
|
6091
|
-
img.onerror = reject;
|
|
6092
|
-
img.src = URL.createObjectURL(blob);
|
|
6093
|
-
});
|
|
6094
|
-
}
|
|
6095
|
-
var Texture2DLoader = /*#__PURE__*/ function(Loader) {
|
|
6096
|
-
_inherits(Texture2DLoader, Loader);
|
|
6097
|
-
function Texture2DLoader() {
|
|
6098
|
-
return Loader.apply(this, arguments) || this;
|
|
6099
|
-
}
|
|
6100
|
-
var _proto = Texture2DLoader.prototype;
|
|
6101
|
-
_proto.load = function load(item, resourceManager) {
|
|
6102
|
-
var _this = this;
|
|
6103
|
-
var url = item.url;
|
|
6104
|
-
var requestConfig = _extends({}, item, {
|
|
6105
|
-
type: "arraybuffer"
|
|
6106
|
-
});
|
|
6107
|
-
return new engineCore.AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
|
|
6108
|
-
resourceManager// @ts-ignore
|
|
6109
|
-
._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
|
|
6110
|
-
if (FileHeader.checkMagic(buffer)) {
|
|
6111
|
-
decode(buffer, resourceManager.engine).then(function(texture) {
|
|
6112
|
-
resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
|
|
6113
|
-
resolve(texture);
|
|
6114
|
-
}, reject);
|
|
6115
|
-
} else {
|
|
6116
|
-
loadImageFromBuffer(buffer).then(function(img) {
|
|
6117
|
-
var texture = _this._createTexture(img, item, resourceManager);
|
|
6118
|
-
resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
|
|
6119
|
-
resolve(texture);
|
|
6120
|
-
}, reject);
|
|
6121
|
-
}
|
|
6122
|
-
}).catch(reject);
|
|
6123
|
-
});
|
|
6124
|
-
};
|
|
6125
|
-
_proto._createTexture = function _createTexture(img, item, resourceManager) {
|
|
6126
|
-
var _item_params;
|
|
6127
|
-
var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? engineCore.TextureFormat.R8G8B8A8 : _ref_format, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode, _ref_isSRGBColorSpace = _ref.isSRGBColorSpace, isSRGBColorSpace = _ref_isSRGBColorSpace === void 0 ? true : _ref_isSRGBColorSpace, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
|
|
6128
|
-
var width = img.width, height = img.height;
|
|
6129
|
-
var engine = resourceManager.engine;
|
|
6130
|
-
var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
|
|
6131
|
-
var texture = new engineCore.Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
|
|
6132
|
-
texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
|
|
6133
|
-
texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
|
|
6134
|
-
texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
|
|
6135
|
-
texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
|
|
6136
|
-
texture.setImageSource(img);
|
|
6137
|
-
generateMipmap && texture.generateMipmaps();
|
|
6138
|
-
var url = item.url;
|
|
6139
|
-
if (url.indexOf("data:") !== 0) {
|
|
6140
|
-
texture.name = url.substring(url.lastIndexOf("/") + 1);
|
|
6141
|
-
}
|
|
6142
|
-
return texture;
|
|
6143
|
-
};
|
|
6144
|
-
return Texture2DLoader;
|
|
6145
|
-
}(engineCore.Loader);
|
|
6146
|
-
Texture2DLoader = __decorate([
|
|
6147
|
-
engineCore.resourceLoader(engineCore.AssetType.Texture2D, [
|
|
6148
|
-
"png",
|
|
6149
|
-
"jpg",
|
|
6150
|
-
"webp",
|
|
6151
|
-
"jpeg",
|
|
6152
|
-
"tex"
|
|
6153
|
-
])
|
|
6154
|
-
], Texture2DLoader);
|
|
6155
|
-
var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
6156
|
-
_inherits(Texture2DContentRestorer, ContentRestorer);
|
|
6157
|
-
function Texture2DContentRestorer(resource, url, requestConfig) {
|
|
6158
|
-
var _this;
|
|
6159
|
-
_this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
|
|
6160
|
-
return _this;
|
|
6161
|
-
}
|
|
6162
|
-
var _proto = Texture2DContentRestorer.prototype;
|
|
6163
|
-
_proto.restoreContent = function restoreContent() {
|
|
6164
|
-
var texture = this.resource;
|
|
6165
|
-
var engine = texture.engine;
|
|
6166
|
-
return engine.resourceManager// @ts-ignore
|
|
6167
|
-
._request(this.url, this.requestConfig).then(function(buffer) {
|
|
6168
|
-
if (FileHeader.checkMagic(buffer)) {
|
|
6169
|
-
return decode(buffer, engine, texture);
|
|
6170
|
-
} else {
|
|
6171
|
-
return loadImageFromBuffer(buffer).then(function(img) {
|
|
6172
|
-
texture.setImageSource(img);
|
|
6173
|
-
texture.generateMipmaps();
|
|
6174
|
-
return texture;
|
|
6175
|
-
});
|
|
6176
|
-
}
|
|
6177
|
-
});
|
|
6178
|
-
};
|
|
6179
|
-
return Texture2DContentRestorer;
|
|
6180
|
-
}(engineCore.ContentRestorer);
|
|
6181
|
-
|
|
6182
|
-
/**
|
|
6183
|
-
* HDR panorama to cubemap decoder.
|
|
6184
|
-
*/ var HDRDecoder = /*#__PURE__*/ function() {
|
|
6185
|
-
function HDRDecoder() {}
|
|
6186
|
-
HDRDecoder.parseHeader = function parseHeader(uint8array) {
|
|
6187
|
-
var line = this._readStringLine(uint8array, 0);
|
|
6188
|
-
if (line[0] !== "#" || line[1] !== "?") {
|
|
6189
|
-
throw "HDRDecoder: invalid file header";
|
|
6190
|
-
}
|
|
6191
|
-
var endOfHeader = false;
|
|
6192
|
-
var findFormat = false;
|
|
6193
|
-
var lineIndex = 0;
|
|
6194
|
-
do {
|
|
6195
|
-
lineIndex += line.length + 1;
|
|
6196
|
-
line = this._readStringLine(uint8array, lineIndex);
|
|
6197
|
-
if (line === "FORMAT=32-bit_rle_rgbe") findFormat = true;
|
|
6198
|
-
else if (line.length === 0) endOfHeader = true;
|
|
6199
|
-
}while (!endOfHeader);
|
|
6200
|
-
if (!findFormat) {
|
|
6201
|
-
throw "HDRDecoder: unsupported format, expected 32-bit_rle_rgbe";
|
|
6202
|
-
}
|
|
6203
|
-
lineIndex += line.length + 1;
|
|
6204
|
-
line = this._readStringLine(uint8array, lineIndex);
|
|
6205
|
-
var match = /^\-Y (.*) \+X (.*)$/g.exec(line);
|
|
6206
|
-
if (!match || match.length < 3) {
|
|
6207
|
-
throw "HDRDecoder: missing image size, only -Y +X layout is supported";
|
|
6208
|
-
}
|
|
6209
|
-
var width = parseInt(match[2]);
|
|
6210
|
-
var height = parseInt(match[1]);
|
|
6211
|
-
if (width < 8 || width > 0x7fff) {
|
|
6212
|
-
throw "HDRDecoder: unsupported image width, must be between 8 and 32767";
|
|
6213
|
-
}
|
|
6214
|
-
return {
|
|
6215
|
-
height: height,
|
|
6216
|
-
width: width,
|
|
6217
|
-
dataPosition: lineIndex + line.length + 1
|
|
6218
|
-
};
|
|
6219
|
-
};
|
|
6220
|
-
HDRDecoder.decodeFaces = function decodeFaces(bufferArray, header, onFace) {
|
|
6221
|
-
var width = header.width, height = header.height, dataPosition = header.dataPosition;
|
|
6222
|
-
var cubeSize = height >> 1;
|
|
6223
|
-
var pixels = HDRDecoder._readPixels(bufferArray.subarray(dataPosition), width, height);
|
|
6224
|
-
var faces = HDRDecoder._faces;
|
|
6225
|
-
var faceBuffer = new Uint16Array(cubeSize * cubeSize * 4);
|
|
6226
|
-
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
6227
|
-
HDRDecoder._createCubemapData(cubeSize, faces[faceIndex], pixels, width, height, faceBuffer);
|
|
6228
|
-
onFace(faceIndex, faceBuffer);
|
|
6229
|
-
}
|
|
6230
|
-
};
|
|
6231
|
-
HDRDecoder._generateFloat2HalfTables = function _generateFloat2HalfTables() {
|
|
6232
|
-
var baseTable = new Uint32Array(512);
|
|
6233
|
-
var shiftTable = new Uint32Array(512);
|
|
6234
|
-
for(var i = 0; i < 256; ++i){
|
|
6235
|
-
var e = i - 127;
|
|
6236
|
-
if (e < -27) {
|
|
6237
|
-
baseTable[i] = 0x0000;
|
|
6238
|
-
baseTable[i | 0x100] = 0x8000;
|
|
6239
|
-
shiftTable[i] = 24;
|
|
6240
|
-
shiftTable[i | 0x100] = 24;
|
|
6241
|
-
} else if (e < -14) {
|
|
6242
|
-
baseTable[i] = 0x0400 >> -e - 14;
|
|
6243
|
-
baseTable[i | 0x100] = 0x0400 >> -e - 14 | 0x8000;
|
|
6244
|
-
shiftTable[i] = -e - 1;
|
|
6245
|
-
shiftTable[i | 0x100] = -e - 1;
|
|
6246
|
-
} else if (e <= 15) {
|
|
6247
|
-
baseTable[i] = e + 15 << 10;
|
|
6248
|
-
baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
|
|
6249
|
-
shiftTable[i] = 13;
|
|
6250
|
-
shiftTable[i | 0x100] = 13;
|
|
6251
|
-
} else if (e < 128) {
|
|
6252
|
-
baseTable[i] = 0x7c00;
|
|
6253
|
-
baseTable[i | 0x100] = 0xfc00;
|
|
6254
|
-
shiftTable[i] = 24;
|
|
6255
|
-
shiftTable[i | 0x100] = 24;
|
|
6256
|
-
} else {
|
|
6257
|
-
baseTable[i] = 0x7c00;
|
|
6258
|
-
baseTable[i | 0x100] = 0xfc00;
|
|
6259
|
-
shiftTable[i] = 13;
|
|
6260
|
-
shiftTable[i | 0x100] = 13;
|
|
6261
|
-
}
|
|
6262
|
-
}
|
|
6263
|
-
return {
|
|
6264
|
-
baseTable: baseTable,
|
|
6265
|
-
shiftTable: shiftTable
|
|
6266
|
-
};
|
|
6267
|
-
};
|
|
6268
|
-
HDRDecoder._createCubemapData = function _createCubemapData(texSize, face, pixels, inputWidth, inputHeight, facePixels) {
|
|
6269
|
-
var invSize = 1 / texSize;
|
|
6270
|
-
var rotDX1X = (face[3] - face[0]) * invSize;
|
|
6271
|
-
var rotDX1Y = (face[4] - face[1]) * invSize;
|
|
6272
|
-
var rotDX1Z = (face[5] - face[2]) * invSize;
|
|
6273
|
-
var rotDX2X = (face[9] - face[6]) * invSize;
|
|
6274
|
-
var rotDX2Y = (face[10] - face[7]) * invSize;
|
|
6275
|
-
var rotDX2Z = (face[11] - face[8]) * invSize;
|
|
6276
|
-
var floatView = HDRDecoder._floatView;
|
|
6277
|
-
var uint32View = HDRDecoder._uint32View;
|
|
6278
|
-
var _HDRDecoder__float2HalfTables = HDRDecoder._float2HalfTables, baseTable = _HDRDecoder__float2HalfTables.baseTable, shiftTable = _HDRDecoder__float2HalfTables.shiftTable;
|
|
6279
|
-
var one = HDRDecoder._one;
|
|
6280
|
-
var fy = 0;
|
|
6281
|
-
for(var y = 0; y < texSize; y++){
|
|
6282
|
-
var xv1X = face[0], xv1Y = face[1], xv1Z = face[2];
|
|
6283
|
-
var xv2X = face[6], xv2Y = face[7], xv2Z = face[8];
|
|
6284
|
-
for(var x = 0; x < texSize; x++){
|
|
6285
|
-
var dirX = xv1X + (xv2X - xv1X) * fy;
|
|
6286
|
-
var dirY = xv1Y + (xv2Y - xv1Y) * fy;
|
|
6287
|
-
var dirZ = xv1Z + (xv2Z - xv1Z) * fy;
|
|
6288
|
-
var invLen = 1 / Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);
|
|
6289
|
-
dirX *= invLen;
|
|
6290
|
-
dirY *= invLen;
|
|
6291
|
-
dirZ *= invLen;
|
|
6292
|
-
var px = Math.round((Math.atan2(dirZ, dirX) / Math.PI * 0.5 + 0.5) * inputWidth);
|
|
6293
|
-
if (px < 0) px = 0;
|
|
6294
|
-
else if (px >= inputWidth) px = inputWidth - 1;
|
|
6295
|
-
var py = Math.round(Math.acos(dirY) / Math.PI * inputHeight);
|
|
6296
|
-
if (py < 0) py = 0;
|
|
6297
|
-
else if (py >= inputHeight) py = inputHeight - 1;
|
|
6298
|
-
var srcIndex = (inputHeight - py - 1) * inputWidth * 4 + px * 4;
|
|
6299
|
-
var scaleFactor = Math.pow(2, pixels[srcIndex + 3] - 128) / 255;
|
|
6300
|
-
var dstIndex = y * texSize * 4 + x * 4;
|
|
6301
|
-
for(var c = 0; c < 3; c++){
|
|
6302
|
-
// Clamp to half-float max (65504) to prevent Infinity in R16G16B16A16
|
|
6303
|
-
floatView[0] = Math.min(pixels[srcIndex + c] * scaleFactor, 65504);
|
|
6304
|
-
var f = uint32View[0];
|
|
6305
|
-
var e = f >> 23 & 0x1ff;
|
|
6306
|
-
facePixels[dstIndex + c] = baseTable[e] + ((f & 0x007fffff) >> shiftTable[e]);
|
|
6307
|
-
}
|
|
6308
|
-
facePixels[dstIndex + 3] = one;
|
|
6309
|
-
xv1X += rotDX1X;
|
|
6310
|
-
xv1Y += rotDX1Y;
|
|
6311
|
-
xv1Z += rotDX1Z;
|
|
6312
|
-
xv2X += rotDX2X;
|
|
6313
|
-
xv2Y += rotDX2Y;
|
|
6314
|
-
xv2Z += rotDX2Z;
|
|
6315
|
-
}
|
|
6316
|
-
fy += invSize;
|
|
6317
|
-
}
|
|
6318
|
-
};
|
|
6319
|
-
HDRDecoder._readStringLine = function _readStringLine(uint8array, startIndex) {
|
|
6320
|
-
var line = "";
|
|
6321
|
-
for(var i = startIndex, n = uint8array.length; i < n; i++){
|
|
6322
|
-
var character = String.fromCharCode(uint8array[i]);
|
|
6323
|
-
if (character === "\n") break;
|
|
6324
|
-
line += character;
|
|
6325
|
-
}
|
|
6326
|
-
return line;
|
|
6327
|
-
};
|
|
6328
|
-
HDRDecoder._readPixels = function _readPixels(buffer, width, height) {
|
|
6329
|
-
var byteLength = buffer.byteLength;
|
|
6330
|
-
var dataRGBA = new Uint8Array(4 * width * height);
|
|
6331
|
-
var offset = 0;
|
|
6332
|
-
var pos = 0;
|
|
6333
|
-
var ptrEnd = 4 * width;
|
|
6334
|
-
var scanLineBuffer = new Uint8Array(ptrEnd);
|
|
6335
|
-
var numScanLines = height;
|
|
6336
|
-
while(numScanLines > 0 && pos < byteLength){
|
|
6337
|
-
var a = buffer[pos++];
|
|
6338
|
-
var b = buffer[pos++];
|
|
6339
|
-
var c = buffer[pos++];
|
|
6340
|
-
var d = buffer[pos++];
|
|
6341
|
-
if (a !== 2 || b !== 2 || c & 0x80 || width < 8 || width > 32767) return buffer;
|
|
6342
|
-
if ((c << 8 | d) !== width) throw "HDRDecoder: wrong scanline width";
|
|
6343
|
-
var ptr = 0;
|
|
6344
|
-
while(ptr < ptrEnd && pos < byteLength){
|
|
6345
|
-
var count = buffer[pos++];
|
|
6346
|
-
var isEncodedRun = count > 128;
|
|
6347
|
-
if (isEncodedRun) count -= 128;
|
|
6348
|
-
if (count === 0 || ptr + count > ptrEnd) throw "HDRDecoder: bad scanline data";
|
|
6349
|
-
if (isEncodedRun) {
|
|
6350
|
-
var byteValue = buffer[pos++];
|
|
6351
|
-
for(var i = 0; i < count; i++)scanLineBuffer[ptr++] = byteValue;
|
|
6352
|
-
} else {
|
|
6353
|
-
scanLineBuffer.set(buffer.subarray(pos, pos + count), ptr);
|
|
6354
|
-
ptr += count;
|
|
6355
|
-
pos += count;
|
|
6356
|
-
}
|
|
6357
|
-
}
|
|
6358
|
-
for(var i1 = 0; i1 < width; i1++, offset += 4){
|
|
6359
|
-
dataRGBA[offset] = scanLineBuffer[i1];
|
|
6360
|
-
dataRGBA[offset + 1] = scanLineBuffer[i1 + width];
|
|
6361
|
-
dataRGBA[offset + 2] = scanLineBuffer[i1 + width * 2];
|
|
6362
|
-
dataRGBA[offset + 3] = scanLineBuffer[i1 + width * 3];
|
|
6363
|
-
}
|
|
6364
|
-
numScanLines--;
|
|
6070
|
+
_proto._loadFromAtlas = function _loadFromAtlas(resourceManager, data) {
|
|
6071
|
+
var _this = this;
|
|
6072
|
+
return resourceManager// @ts-ignore
|
|
6073
|
+
.getResourceByRef(data.belongToAtlas).then(function(atlas) {
|
|
6074
|
+
return atlas.getSprite(data.fullPath) || _this._loadFromTexture(resourceManager, data);
|
|
6075
|
+
});
|
|
6076
|
+
};
|
|
6077
|
+
_proto._loadFromTexture = function _loadFromTexture(resourceManager, data) {
|
|
6078
|
+
if (data.texture) {
|
|
6079
|
+
return resourceManager// @ts-ignore
|
|
6080
|
+
.getResourceByRef(data.texture).then(function(texture) {
|
|
6081
|
+
var sprite = new engineCore.Sprite(resourceManager.engine, texture, data.region, data.pivot, data.border);
|
|
6082
|
+
var width = data.width, height = data.height;
|
|
6083
|
+
width === undefined || (sprite.width = width);
|
|
6084
|
+
height === undefined || (sprite.height = height);
|
|
6085
|
+
return sprite;
|
|
6086
|
+
});
|
|
6087
|
+
} else {
|
|
6088
|
+
return new engineCore.AssetPromise(function(resolve) {
|
|
6089
|
+
var sprite = new engineCore.Sprite(resourceManager.engine, null, data.region, data.pivot, data.border);
|
|
6090
|
+
var width = data.width, height = data.height;
|
|
6091
|
+
width === undefined || (sprite.width = width);
|
|
6092
|
+
height === undefined || (sprite.height = height);
|
|
6093
|
+
resolve(sprite);
|
|
6094
|
+
});
|
|
6365
6095
|
}
|
|
6366
|
-
return dataRGBA;
|
|
6367
6096
|
};
|
|
6368
|
-
return
|
|
6369
|
-
}();
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
-1,
|
|
6400
|
-
1,
|
|
6401
|
-
1,
|
|
6402
|
-
-1,
|
|
6403
|
-
1,
|
|
6404
|
-
-1
|
|
6405
|
-
],
|
|
6406
|
-
/* +Y */ [
|
|
6407
|
-
-1,
|
|
6408
|
-
-1,
|
|
6409
|
-
1,
|
|
6410
|
-
1,
|
|
6411
|
-
-1,
|
|
6412
|
-
1,
|
|
6413
|
-
-1,
|
|
6414
|
-
-1,
|
|
6415
|
-
-1,
|
|
6416
|
-
1,
|
|
6417
|
-
-1,
|
|
6418
|
-
-1
|
|
6419
|
-
],
|
|
6420
|
-
/* -Y */ [
|
|
6421
|
-
-1,
|
|
6422
|
-
1,
|
|
6423
|
-
-1,
|
|
6424
|
-
1,
|
|
6425
|
-
1,
|
|
6426
|
-
-1,
|
|
6427
|
-
-1,
|
|
6428
|
-
1,
|
|
6429
|
-
1,
|
|
6430
|
-
1,
|
|
6431
|
-
1,
|
|
6432
|
-
1
|
|
6433
|
-
],
|
|
6434
|
-
/* +Z */ [
|
|
6435
|
-
-1,
|
|
6436
|
-
-1,
|
|
6437
|
-
-1,
|
|
6438
|
-
1,
|
|
6439
|
-
-1,
|
|
6440
|
-
-1,
|
|
6441
|
-
-1,
|
|
6442
|
-
1,
|
|
6443
|
-
-1,
|
|
6444
|
-
1,
|
|
6445
|
-
1,
|
|
6446
|
-
-1
|
|
6447
|
-
],
|
|
6448
|
-
/* -Z */ [
|
|
6449
|
-
1,
|
|
6450
|
-
-1,
|
|
6451
|
-
1,
|
|
6452
|
-
-1,
|
|
6453
|
-
-1,
|
|
6454
|
-
1,
|
|
6455
|
-
1,
|
|
6456
|
-
1,
|
|
6457
|
-
1,
|
|
6458
|
-
-1,
|
|
6459
|
-
1,
|
|
6460
|
-
1
|
|
6461
|
-
]
|
|
6462
|
-
];
|
|
6097
|
+
return SpriteLoader;
|
|
6098
|
+
}(engineCore.Loader);
|
|
6099
|
+
SpriteLoader = __decorate([
|
|
6100
|
+
engineCore.resourceLoader(engineCore.AssetType.Sprite, [
|
|
6101
|
+
"sprite"
|
|
6102
|
+
])
|
|
6103
|
+
], SpriteLoader);
|
|
6104
|
+
|
|
6105
|
+
var TextLoader = /*#__PURE__*/ function(Loader) {
|
|
6106
|
+
_inherits(TextLoader, Loader);
|
|
6107
|
+
function TextLoader() {
|
|
6108
|
+
return Loader.apply(this, arguments) || this;
|
|
6109
|
+
}
|
|
6110
|
+
var _proto = TextLoader.prototype;
|
|
6111
|
+
_proto.load = function load(item, resourceManager) {
|
|
6112
|
+
// @ts-ignore
|
|
6113
|
+
return resourceManager._request(item.url, _extends({}, item, {
|
|
6114
|
+
type: "text"
|
|
6115
|
+
})).then(function(text) {
|
|
6116
|
+
var asset = new engineCore.TextAsset(resourceManager.engine);
|
|
6117
|
+
asset.text = text;
|
|
6118
|
+
return asset;
|
|
6119
|
+
});
|
|
6120
|
+
};
|
|
6121
|
+
return TextLoader;
|
|
6122
|
+
}(engineCore.Loader);
|
|
6123
|
+
TextLoader = __decorate([
|
|
6124
|
+
engineCore.resourceLoader(engineCore.AssetType.Text, [
|
|
6125
|
+
"txt"
|
|
6126
|
+
])
|
|
6127
|
+
], TextLoader);
|
|
6463
6128
|
|
|
6464
|
-
var
|
|
6465
|
-
_inherits(
|
|
6466
|
-
function
|
|
6129
|
+
var TextureLoader = /*#__PURE__*/ function(Loader) {
|
|
6130
|
+
_inherits(TextureLoader, Loader);
|
|
6131
|
+
function TextureLoader() {
|
|
6467
6132
|
return Loader.apply(this, arguments) || this;
|
|
6468
6133
|
}
|
|
6469
|
-
var _proto =
|
|
6134
|
+
var _proto = TextureLoader.prototype;
|
|
6470
6135
|
_proto.load = function load(item, resourceManager) {
|
|
6136
|
+
var _this = this;
|
|
6137
|
+
var url = item.url;
|
|
6138
|
+
var requestConfig = _extends({}, item, {
|
|
6139
|
+
type: "arraybuffer"
|
|
6140
|
+
});
|
|
6141
|
+
return new engineCore.AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
|
|
6142
|
+
resourceManager// @ts-ignore
|
|
6143
|
+
._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
|
|
6144
|
+
_this._decode(buffer, item, resourceManager).then(function(texture) {
|
|
6145
|
+
resourceManager.addContentRestorer(new TextureContentRestorer(texture, url, requestConfig));
|
|
6146
|
+
resolve(texture);
|
|
6147
|
+
}, reject);
|
|
6148
|
+
}).catch(reject);
|
|
6149
|
+
});
|
|
6150
|
+
};
|
|
6151
|
+
_proto._decode = function _decode(buffer, item, resourceManager) {
|
|
6152
|
+
if (FileHeader.checkMagic(buffer)) {
|
|
6153
|
+
return decode(buffer, resourceManager.engine);
|
|
6154
|
+
}
|
|
6155
|
+
var bufferView = new Uint8Array(buffer);
|
|
6156
|
+
var isHDR = bufferView[0] === 0x23 && bufferView[1] === 0x3f;
|
|
6157
|
+
if (isHDR) {
|
|
6158
|
+
return this._decodeHDR(bufferView, item, resourceManager);
|
|
6159
|
+
}
|
|
6160
|
+
return this._decodeImage(buffer, item, resourceManager);
|
|
6161
|
+
};
|
|
6162
|
+
_proto._decodeHDR = function _decodeHDR(buffer, item, resourceManager) {
|
|
6163
|
+
var _this = this;
|
|
6471
6164
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6472
6165
|
var engine = resourceManager.engine;
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
}
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6166
|
+
if (!engineCore.SystemInfo.supportsTextureFormat(engine, engineCore.TextureFormat.R16G16B16A16)) {
|
|
6167
|
+
reject(new Error("TextureLoader: HDR texture requires half float support."));
|
|
6168
|
+
return;
|
|
6169
|
+
}
|
|
6170
|
+
var _HDRDecoder_decode = HDRDecoder.decode(buffer), width = _HDRDecoder_decode.width, height = _HDRDecoder_decode.height, pixels = _HDRDecoder_decode.pixels;
|
|
6171
|
+
var _item_params;
|
|
6172
|
+
var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
|
|
6173
|
+
var texture = new engineCore.Texture2D(engine, width, height, engineCore.TextureFormat.R16G16B16A16, mipmap, false);
|
|
6174
|
+
texture.setPixelBuffer(pixels);
|
|
6175
|
+
mipmap && texture.generateMipmaps();
|
|
6176
|
+
_this._applyParams(texture, item);
|
|
6177
|
+
resolve(texture);
|
|
6178
|
+
});
|
|
6179
|
+
};
|
|
6180
|
+
_proto._decodeImage = function _decodeImage(buffer, item, resourceManager) {
|
|
6181
|
+
var _this = this;
|
|
6182
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6183
|
+
var blob = new Blob([
|
|
6184
|
+
buffer
|
|
6185
|
+
]);
|
|
6186
|
+
var img = new Image();
|
|
6187
|
+
img.onload = function() {
|
|
6188
|
+
URL.revokeObjectURL(img.src);
|
|
6483
6189
|
var _item_params;
|
|
6484
|
-
var _ref = (_item_params = item.params) != null ? _item_params : {},
|
|
6485
|
-
var
|
|
6486
|
-
var
|
|
6487
|
-
var
|
|
6488
|
-
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
|
|
6493
|
-
texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
|
|
6494
|
-
texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
|
|
6495
|
-
texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
|
|
6496
|
-
resourceManager.addContentRestorer(new HDRContentRestorer(texture, url, requestConfig));
|
|
6190
|
+
var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? engineCore.TextureFormat.R8G8B8A8 : _ref_format, _ref_isSRGBColorSpace = _ref.isSRGBColorSpace, isSRGBColorSpace = _ref_isSRGBColorSpace === void 0 ? true : _ref_isSRGBColorSpace, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
|
|
6191
|
+
var engine = resourceManager.engine;
|
|
6192
|
+
var width = img.width, height = img.height;
|
|
6193
|
+
var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
|
|
6194
|
+
var texture = new engineCore.Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
|
|
6195
|
+
texture.setImageSource(img);
|
|
6196
|
+
generateMipmap && texture.generateMipmaps();
|
|
6197
|
+
_this._applyParams(texture, item);
|
|
6497
6198
|
resolve(texture);
|
|
6498
|
-
}
|
|
6199
|
+
};
|
|
6200
|
+
img.onerror = function(e) {
|
|
6201
|
+
URL.revokeObjectURL(img.src);
|
|
6202
|
+
reject(e);
|
|
6203
|
+
};
|
|
6204
|
+
img.src = URL.createObjectURL(blob);
|
|
6499
6205
|
});
|
|
6500
6206
|
};
|
|
6501
|
-
|
|
6207
|
+
_proto._applyParams = function _applyParams(texture, item) {
|
|
6208
|
+
var _item_params;
|
|
6209
|
+
var _ref = (_item_params = item.params) != null ? _item_params : {}, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
|
|
6210
|
+
texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
|
|
6211
|
+
texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
|
|
6212
|
+
texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
|
|
6213
|
+
texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
|
|
6214
|
+
var url = item.url;
|
|
6215
|
+
if (url.indexOf("data:") !== 0) {
|
|
6216
|
+
texture.name = url.substring(url.lastIndexOf("/") + 1);
|
|
6217
|
+
}
|
|
6218
|
+
};
|
|
6219
|
+
return TextureLoader;
|
|
6502
6220
|
}(engineCore.Loader);
|
|
6503
|
-
|
|
6504
|
-
engineCore.resourceLoader(engineCore.AssetType.
|
|
6505
|
-
"
|
|
6221
|
+
TextureLoader = __decorate([
|
|
6222
|
+
engineCore.resourceLoader(engineCore.AssetType.Texture, [
|
|
6223
|
+
"tex",
|
|
6224
|
+
"png",
|
|
6225
|
+
"jpg",
|
|
6226
|
+
"webp",
|
|
6227
|
+
"jpeg",
|
|
6506
6228
|
"hdr"
|
|
6507
6229
|
])
|
|
6508
|
-
],
|
|
6509
|
-
var
|
|
6510
|
-
_inherits(
|
|
6511
|
-
function
|
|
6230
|
+
], TextureLoader);
|
|
6231
|
+
var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
6232
|
+
_inherits(TextureContentRestorer, ContentRestorer);
|
|
6233
|
+
function TextureContentRestorer(resource, url, requestConfig) {
|
|
6512
6234
|
var _this;
|
|
6513
6235
|
_this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
|
|
6514
6236
|
return _this;
|
|
6515
6237
|
}
|
|
6516
|
-
var _proto =
|
|
6238
|
+
var _proto = TextureContentRestorer.prototype;
|
|
6517
6239
|
_proto.restoreContent = function restoreContent() {
|
|
6518
6240
|
var _this = this;
|
|
6519
|
-
return
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6241
|
+
return this.resource.engine.resourceManager// @ts-ignore
|
|
6242
|
+
._request(this.url, this.requestConfig).then(function(buffer) {
|
|
6243
|
+
if (FileHeader.checkMagic(buffer)) {
|
|
6244
|
+
return decode(buffer, _this.resource.engine, _this.resource);
|
|
6245
|
+
}
|
|
6246
|
+
var bufferView = new Uint8Array(buffer);
|
|
6247
|
+
var texture = _this.resource;
|
|
6248
|
+
if (bufferView[0] === 0x23 && bufferView[1] === 0x3f) {
|
|
6249
|
+
var pixels = HDRDecoder.decode(bufferView).pixels;
|
|
6250
|
+
texture.setPixelBuffer(pixels);
|
|
6251
|
+
texture.mipmapCount > 1 && texture.generateMipmaps();
|
|
6252
|
+
return texture;
|
|
6253
|
+
}
|
|
6254
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6255
|
+
var blob = new Blob([
|
|
6256
|
+
buffer
|
|
6257
|
+
]);
|
|
6258
|
+
var img = new Image();
|
|
6259
|
+
img.onload = function() {
|
|
6260
|
+
URL.revokeObjectURL(img.src);
|
|
6261
|
+
texture.setImageSource(img);
|
|
6262
|
+
texture.mipmapCount > 1 && texture.generateMipmaps();
|
|
6263
|
+
resolve(texture);
|
|
6264
|
+
};
|
|
6265
|
+
img.onerror = function(e) {
|
|
6266
|
+
URL.revokeObjectURL(img.src);
|
|
6267
|
+
reject(e);
|
|
6268
|
+
};
|
|
6269
|
+
img.src = URL.createObjectURL(blob);
|
|
6270
|
+
});
|
|
6530
6271
|
});
|
|
6531
6272
|
};
|
|
6532
|
-
return
|
|
6273
|
+
return TextureContentRestorer;
|
|
6533
6274
|
}(engineCore.ContentRestorer);
|
|
6534
6275
|
|
|
6535
6276
|
var AudioLoader = /*#__PURE__*/ function(Loader) {
|
|
@@ -6547,8 +6288,7 @@ var AudioLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6547
6288
|
resourceManager// @ts-ignore
|
|
6548
6289
|
._request(url, requestConfig).then(function(arrayBuffer) {
|
|
6549
6290
|
var audioClip = new engineCore.AudioClip(resourceManager.engine);
|
|
6550
|
-
|
|
6551
|
-
engineCore.AudioManager.getContext().decodeAudioData(arrayBuffer).then(function(result) {
|
|
6291
|
+
AudioLoader._getDecodeContext().decodeAudioData(arrayBuffer).then(function(result) {
|
|
6552
6292
|
// @ts-ignore
|
|
6553
6293
|
audioClip._setAudioSource(result);
|
|
6554
6294
|
if (url.indexOf("data:") !== 0) {
|
|
@@ -6564,6 +6304,12 @@ var AudioLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6564
6304
|
});
|
|
6565
6305
|
});
|
|
6566
6306
|
};
|
|
6307
|
+
AudioLoader._getDecodeContext = function _getDecodeContext() {
|
|
6308
|
+
var _AudioLoader;
|
|
6309
|
+
// length/channels are decode-only placeholders; 44100 is the safest cross-browser rate.
|
|
6310
|
+
// decodeAudioData resamples once to this rate then again to the playback rate, so pitch/duration are unaffected
|
|
6311
|
+
return (_AudioLoader = AudioLoader)._decodeContext || (_AudioLoader._decodeContext = new OfflineAudioContext(1, 1, 44100));
|
|
6312
|
+
};
|
|
6567
6313
|
return AudioLoader;
|
|
6568
6314
|
}(engineCore.Loader);
|
|
6569
6315
|
AudioLoader = __decorate([
|
|
@@ -6571,58 +6317,12 @@ AudioLoader = __decorate([
|
|
|
6571
6317
|
"mp3",
|
|
6572
6318
|
"ogg",
|
|
6573
6319
|
"wav",
|
|
6574
|
-
"audio",
|
|
6575
6320
|
"m4a",
|
|
6576
6321
|
"aac",
|
|
6577
6322
|
"flac"
|
|
6578
6323
|
])
|
|
6579
6324
|
], AudioLoader);
|
|
6580
6325
|
|
|
6581
|
-
var ShaderChunkLoader = /*#__PURE__*/ function(Loader) {
|
|
6582
|
-
_inherits(ShaderChunkLoader, Loader);
|
|
6583
|
-
function ShaderChunkLoader() {
|
|
6584
|
-
return Loader.apply(this, arguments) || this;
|
|
6585
|
-
}
|
|
6586
|
-
var _proto = ShaderChunkLoader.prototype;
|
|
6587
|
-
_proto.load = function load(item, resourceManager) {
|
|
6588
|
-
var url = item.url;
|
|
6589
|
-
// @ts-ignore
|
|
6590
|
-
return resourceManager._request(url, _extends({}, item, {
|
|
6591
|
-
type: "text"
|
|
6592
|
-
})).then(function(code) {
|
|
6593
|
-
engineCore.ShaderFactory.registerInclude(url.substring(1), code);
|
|
6594
|
-
return ShaderChunkLoader._loadChunksInCode(code, url, resourceManager);
|
|
6595
|
-
});
|
|
6596
|
-
};
|
|
6597
|
-
/**
|
|
6598
|
-
* @internal
|
|
6599
|
-
*/ ShaderChunkLoader._loadChunksInCode = function _loadChunksInCode(code, basePath, resourceManager) {
|
|
6600
|
-
var shaderChunkPaths = new Array();
|
|
6601
|
-
var matches = code.matchAll(ShaderChunkLoader._shaderIncludeRegex);
|
|
6602
|
-
for(var _iterator = _create_for_of_iterator_helper_loose(matches), _step; !(_step = _iterator()).done;){
|
|
6603
|
-
var match = _step.value;
|
|
6604
|
-
var chunkPath = engineCore.Utils.resolveAbsoluteUrl(basePath, match[1]);
|
|
6605
|
-
if (!engineCore.ShaderLib[chunkPath.substring(1)]) {
|
|
6606
|
-
shaderChunkPaths.push(chunkPath);
|
|
6607
|
-
}
|
|
6608
|
-
}
|
|
6609
|
-
return Promise.all(shaderChunkPaths.map(function(chunkPath) {
|
|
6610
|
-
// @ts-ignore
|
|
6611
|
-
return resourceManager.load({
|
|
6612
|
-
type: "ShaderChunk",
|
|
6613
|
-
url: chunkPath
|
|
6614
|
-
});
|
|
6615
|
-
}));
|
|
6616
|
-
};
|
|
6617
|
-
return ShaderChunkLoader;
|
|
6618
|
-
}(engineCore.Loader);
|
|
6619
|
-
ShaderChunkLoader._shaderIncludeRegex = /#include\s+"([./][^\\"]+)"/gm;
|
|
6620
|
-
ShaderChunkLoader = __decorate([
|
|
6621
|
-
engineCore.resourceLoader("ShaderChunk", [
|
|
6622
|
-
"glsl"
|
|
6623
|
-
])
|
|
6624
|
-
], ShaderChunkLoader);
|
|
6625
|
-
|
|
6626
6326
|
var ShaderLoader = /*#__PURE__*/ function(Loader) {
|
|
6627
6327
|
_inherits(ShaderLoader, Loader);
|
|
6628
6328
|
function ShaderLoader() {
|
|
@@ -6630,32 +6330,29 @@ var ShaderLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6630
6330
|
}
|
|
6631
6331
|
var _proto = ShaderLoader.prototype;
|
|
6632
6332
|
_proto.load = function load(item, resourceManager) {
|
|
6633
|
-
var _this = this;
|
|
6634
6333
|
var url = item.url;
|
|
6334
|
+
if (url.endsWith(".shaderc")) {
|
|
6335
|
+
// @ts-ignore
|
|
6336
|
+
return resourceManager._request(url, _extends({}, item, {
|
|
6337
|
+
type: "json"
|
|
6338
|
+
})).then(function(data) {
|
|
6339
|
+
// @ts-ignore - _createFromPrecompiled is @internal
|
|
6340
|
+
return engineCore.Shader._createFromPrecompiled(data);
|
|
6341
|
+
});
|
|
6342
|
+
}
|
|
6635
6343
|
// @ts-ignore
|
|
6636
6344
|
return resourceManager._request(url, _extends({}, item, {
|
|
6637
6345
|
type: "text"
|
|
6638
6346
|
})).then(function(code) {
|
|
6639
|
-
|
|
6640
|
-
if (builtinShader) {
|
|
6641
|
-
return engineCore.Shader.find(builtinShader);
|
|
6642
|
-
}
|
|
6643
|
-
return ShaderChunkLoader._loadChunksInCode(code, url, resourceManager).then(function() {
|
|
6644
|
-
var shader = engineCore.Shader.create(code, undefined, url);
|
|
6645
|
-
return shader;
|
|
6646
|
-
});
|
|
6347
|
+
return engineCore.Shader.create(code, undefined, url);
|
|
6647
6348
|
});
|
|
6648
6349
|
};
|
|
6649
|
-
_proto._getBuiltinShader = function _getBuiltinShader(code) {
|
|
6650
|
-
var match = code.match(ShaderLoader._builtinRegex);
|
|
6651
|
-
if (match && match[1]) return match[1];
|
|
6652
|
-
};
|
|
6653
6350
|
return ShaderLoader;
|
|
6654
6351
|
}(engineCore.Loader);
|
|
6655
|
-
ShaderLoader._builtinRegex = /^\s*\/\/\s*@builtin\s+(\w+)/;
|
|
6656
6352
|
ShaderLoader = __decorate([
|
|
6657
6353
|
engineCore.resourceLoader(engineCore.AssetType.Shader, [
|
|
6658
|
-
"shader"
|
|
6354
|
+
"shader",
|
|
6355
|
+
"shaderc"
|
|
6659
6356
|
])
|
|
6660
6357
|
], ShaderLoader);
|
|
6661
6358
|
|
|
@@ -6735,6 +6432,122 @@ RenderTargetLoader = __decorate([
|
|
|
6735
6432
|
])
|
|
6736
6433
|
], RenderTargetLoader);
|
|
6737
6434
|
|
|
6435
|
+
function loadRef(refs, index, resourceManager, label) {
|
|
6436
|
+
var ref = resolveRefItem(refs, index, "SceneLoader", label);
|
|
6437
|
+
// @ts-ignore
|
|
6438
|
+
return resourceManager.getResourceByRef(ref);
|
|
6439
|
+
}
|
|
6440
|
+
/**
|
|
6441
|
+
* Apply scene-level data (ambient, background, shadow, fog, AO) to a Scene.
|
|
6442
|
+
* @internal
|
|
6443
|
+
*/ function applySceneData(scene, sceneData, resourceManager, refs) {
|
|
6444
|
+
var promises = [];
|
|
6445
|
+
try {
|
|
6446
|
+
// parse ambient light
|
|
6447
|
+
var ambient = sceneData.ambient;
|
|
6448
|
+
if (ambient) {
|
|
6449
|
+
var useCustomAmbient = ambient.specularMode === SpecularMode.Custom;
|
|
6450
|
+
var useSH = ambient.diffuseMode === engineCore.DiffuseMode.SphericalHarmonics;
|
|
6451
|
+
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
6452
|
+
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
6453
|
+
scene.ambientLight.diffuseMode = ambient.diffuseMode;
|
|
6454
|
+
var solidColor = ambient.diffuseSolidColor;
|
|
6455
|
+
if (solidColor) {
|
|
6456
|
+
scene.ambientLight.diffuseSolidColor.set(solidColor[0], solidColor[1], solidColor[2], solidColor[3]);
|
|
6457
|
+
}
|
|
6458
|
+
if (useCustomAmbient && ambient.customAmbientLight != null) {
|
|
6459
|
+
promises.push(loadRef(refs, ambient.customAmbientLight, resourceManager, "scene.ambient.customAmbientLight").then(function(ambientLight) {
|
|
6460
|
+
scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
|
|
6461
|
+
}));
|
|
6462
|
+
}
|
|
6463
|
+
if (ambient.ambientLight != null && (!useCustomAmbient || useSH)) {
|
|
6464
|
+
promises.push(loadRef(refs, ambient.ambientLight, resourceManager, "scene.ambient.ambientLight").then(function(ambientLight) {
|
|
6465
|
+
if (!useCustomAmbient) {
|
|
6466
|
+
scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
|
|
6467
|
+
}
|
|
6468
|
+
if (useSH) {
|
|
6469
|
+
scene.ambientLight.diffuseSphericalHarmonics = ambientLight == null ? void 0 : ambientLight.diffuseSphericalHarmonics;
|
|
6470
|
+
}
|
|
6471
|
+
}));
|
|
6472
|
+
}
|
|
6473
|
+
}
|
|
6474
|
+
// parse background
|
|
6475
|
+
var background = sceneData.background;
|
|
6476
|
+
scene.background.mode = background.mode;
|
|
6477
|
+
switch(scene.background.mode){
|
|
6478
|
+
case engineCore.BackgroundMode.SolidColor:
|
|
6479
|
+
{
|
|
6480
|
+
var color = background.color;
|
|
6481
|
+
scene.background.solidColor.set(color[0], color[1], color[2], color[3]);
|
|
6482
|
+
break;
|
|
6483
|
+
}
|
|
6484
|
+
case engineCore.BackgroundMode.Sky:
|
|
6485
|
+
if (background.skyMesh != null && background.skyMaterial != null) {
|
|
6486
|
+
promises.push(loadRef(refs, background.skyMesh, resourceManager, "scene.background.skyMesh").then(function(mesh) {
|
|
6487
|
+
scene.background.sky.mesh = mesh;
|
|
6488
|
+
}), loadRef(refs, background.skyMaterial, resourceManager, "scene.background.skyMaterial").then(function(material) {
|
|
6489
|
+
scene.background.sky.material = material;
|
|
6490
|
+
}));
|
|
6491
|
+
} else {
|
|
6492
|
+
engineCore.Logger.warn("Sky background mode requires skyMesh and skyMaterial");
|
|
6493
|
+
}
|
|
6494
|
+
break;
|
|
6495
|
+
case engineCore.BackgroundMode.Texture:
|
|
6496
|
+
if (background.texture != null) {
|
|
6497
|
+
promises.push(loadRef(refs, background.texture, resourceManager, "scene.background.texture").then(function(texture) {
|
|
6498
|
+
scene.background.texture = texture;
|
|
6499
|
+
}));
|
|
6500
|
+
var _background_textureFillMode;
|
|
6501
|
+
scene.background.textureFillMode = (_background_textureFillMode = background.textureFillMode) != null ? _background_textureFillMode : scene.background.textureFillMode;
|
|
6502
|
+
}
|
|
6503
|
+
break;
|
|
6504
|
+
}
|
|
6505
|
+
} catch (error) {
|
|
6506
|
+
return Promise.reject(error);
|
|
6507
|
+
}
|
|
6508
|
+
// parse shadow
|
|
6509
|
+
var shadow = sceneData.shadow;
|
|
6510
|
+
if (shadow) {
|
|
6511
|
+
if (shadow.castShadows != undefined) scene.castShadows = shadow.castShadows;
|
|
6512
|
+
if (shadow.shadowResolution != undefined) scene.shadowResolution = shadow.shadowResolution;
|
|
6513
|
+
if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
|
|
6514
|
+
if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
|
|
6515
|
+
if (shadow.enableTransparentShadow != undefined) scene.enableTransparentShadow = shadow.enableTransparentShadow;
|
|
6516
|
+
if (shadow.shadowTwoCascadeSplits != undefined) scene.shadowTwoCascadeSplits = shadow.shadowTwoCascadeSplits;
|
|
6517
|
+
if (shadow.shadowFourCascadeSplits) {
|
|
6518
|
+
var splits = shadow.shadowFourCascadeSplits;
|
|
6519
|
+
scene.shadowFourCascadeSplits.set(splits[0], splits[1], splits[2]);
|
|
6520
|
+
}
|
|
6521
|
+
if (shadow.shadowFadeBorder != undefined) scene.shadowFadeBorder = shadow.shadowFadeBorder;
|
|
6522
|
+
}
|
|
6523
|
+
// parse fog
|
|
6524
|
+
var fog = sceneData.fog;
|
|
6525
|
+
if (fog) {
|
|
6526
|
+
if (fog.fogMode != undefined) scene.fogMode = fog.fogMode;
|
|
6527
|
+
if (fog.fogStart != undefined) scene.fogStart = fog.fogStart;
|
|
6528
|
+
if (fog.fogEnd != undefined) scene.fogEnd = fog.fogEnd;
|
|
6529
|
+
if (fog.fogDensity != undefined) scene.fogDensity = fog.fogDensity;
|
|
6530
|
+
if (fog.fogColor) scene.fogColor.set(fog.fogColor[0], fog.fogColor[1], fog.fogColor[2], fog.fogColor[3]);
|
|
6531
|
+
}
|
|
6532
|
+
// Post Process
|
|
6533
|
+
if (sceneData.postProcess) {
|
|
6534
|
+
engineCore.Logger.warn("Post Process is not supported in scene yet, please add PostProcess component in entity instead.");
|
|
6535
|
+
}
|
|
6536
|
+
// Ambient Occlusion
|
|
6537
|
+
var ambientOcclusion = sceneData.ambientOcclusion;
|
|
6538
|
+
if (ambientOcclusion) {
|
|
6539
|
+
var sceneAO = scene.ambientOcclusion;
|
|
6540
|
+
if (ambientOcclusion.enabledAmbientOcclusion != undefined) sceneAO.enabled = ambientOcclusion.enabledAmbientOcclusion;
|
|
6541
|
+
if (ambientOcclusion.quality != undefined) sceneAO.quality = ambientOcclusion.quality;
|
|
6542
|
+
if (ambientOcclusion.intensity != undefined) sceneAO.intensity = ambientOcclusion.intensity;
|
|
6543
|
+
if (ambientOcclusion.radius != undefined) sceneAO.radius = ambientOcclusion.radius;
|
|
6544
|
+
if (ambientOcclusion.bias != undefined) sceneAO.bias = ambientOcclusion.bias;
|
|
6545
|
+
if (ambientOcclusion.power != undefined) sceneAO.power = ambientOcclusion.power;
|
|
6546
|
+
if (ambientOcclusion.bilateralThreshold != undefined) sceneAO.bilateralThreshold = ambientOcclusion.bilateralThreshold;
|
|
6547
|
+
if (ambientOcclusion.minHorizonAngle != undefined) sceneAO.minHorizonAngle = ambientOcclusion.minHorizonAngle;
|
|
6548
|
+
}
|
|
6549
|
+
return Promise.all(promises).then(function() {});
|
|
6550
|
+
}
|
|
6738
6551
|
var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
6739
6552
|
_inherits(SceneLoader, Loader);
|
|
6740
6553
|
function SceneLoader() {
|
|
@@ -6748,130 +6561,15 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6748
6561
|
._request(item.url, _extends({}, item, {
|
|
6749
6562
|
type: "json"
|
|
6750
6563
|
})).then(function(data) {
|
|
6751
|
-
var
|
|
6752
|
-
var scene = new engineCore.Scene(engine, (
|
|
6564
|
+
var _data_scene_name;
|
|
6565
|
+
var scene = new engineCore.Scene(engine, (_data_scene_name = data.scene.name) != null ? _data_scene_name : "");
|
|
6753
6566
|
var context = new ParserContext(engine, ParserType.Scene, scene);
|
|
6754
6567
|
var parser = new SceneParser(data, context, scene);
|
|
6755
6568
|
parser._collectDependentAssets(data);
|
|
6756
6569
|
context._setTaskCompleteProgress = setTaskCompleteProgress;
|
|
6757
6570
|
parser.start();
|
|
6758
6571
|
return parser.promise.then(function() {
|
|
6759
|
-
|
|
6760
|
-
// parse ambient light
|
|
6761
|
-
var ambient = data.scene.ambient;
|
|
6762
|
-
if (ambient) {
|
|
6763
|
-
var useCustomAmbient = ambient.specularMode === SpecularMode.Custom;
|
|
6764
|
-
var useSH = ambient.diffuseMode === engineCore.DiffuseMode.SphericalHarmonics;
|
|
6765
|
-
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
6766
|
-
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
6767
|
-
scene.ambientLight.diffuseMode = ambient.diffuseMode;
|
|
6768
|
-
scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
|
|
6769
|
-
if (useCustomAmbient && ambient.customAmbientLight) {
|
|
6770
|
-
promises.push(// @ts-ignore
|
|
6771
|
-
resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
|
|
6772
|
-
scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
|
|
6773
|
-
}));
|
|
6774
|
-
}
|
|
6775
|
-
if (ambient.ambientLight && (!useCustomAmbient || useSH)) {
|
|
6776
|
-
promises.push(// @ts-ignore
|
|
6777
|
-
resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
|
|
6778
|
-
if (!useCustomAmbient) {
|
|
6779
|
-
scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
|
|
6780
|
-
}
|
|
6781
|
-
if (useSH) {
|
|
6782
|
-
scene.ambientLight.diffuseSphericalHarmonics = ambientLight == null ? void 0 : ambientLight.diffuseSphericalHarmonics;
|
|
6783
|
-
}
|
|
6784
|
-
}));
|
|
6785
|
-
}
|
|
6786
|
-
}
|
|
6787
|
-
// parse background
|
|
6788
|
-
var background = data.scene.background;
|
|
6789
|
-
scene.background.mode = background.mode;
|
|
6790
|
-
switch(scene.background.mode){
|
|
6791
|
-
case engineCore.BackgroundMode.SolidColor:
|
|
6792
|
-
scene.background.solidColor.copyFrom(background.color);
|
|
6793
|
-
break;
|
|
6794
|
-
case engineCore.BackgroundMode.Sky:
|
|
6795
|
-
if (background.skyMesh && background.skyMaterial) {
|
|
6796
|
-
// @ts-ignore
|
|
6797
|
-
var skyMeshPromise = resourceManager.getResourceByRef(background.skyMesh).then(function(mesh) {
|
|
6798
|
-
scene.background.sky.mesh = mesh;
|
|
6799
|
-
});
|
|
6800
|
-
// @ts-ignore
|
|
6801
|
-
// prettier-ignore
|
|
6802
|
-
var skyMaterialPromise = resourceManager.getResourceByRef(background.skyMaterial).then(function(material) {
|
|
6803
|
-
scene.background.sky.material = material;
|
|
6804
|
-
});
|
|
6805
|
-
promises.push(skyMeshPromise, skyMaterialPromise);
|
|
6806
|
-
} else {
|
|
6807
|
-
engineCore.Logger.warn("Sky background mode requires skyMesh and skyMaterial");
|
|
6808
|
-
}
|
|
6809
|
-
break;
|
|
6810
|
-
case engineCore.BackgroundMode.Texture:
|
|
6811
|
-
if (background.texture) {
|
|
6812
|
-
// @ts-ignore
|
|
6813
|
-
// prettier-ignore
|
|
6814
|
-
var backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
|
|
6815
|
-
scene.background.texture = texture;
|
|
6816
|
-
});
|
|
6817
|
-
promises.push(backgroundPromise);
|
|
6818
|
-
var _background_textureFillMode;
|
|
6819
|
-
scene.background.textureFillMode = (_background_textureFillMode = background.textureFillMode) != null ? _background_textureFillMode : scene.background.textureFillMode;
|
|
6820
|
-
}
|
|
6821
|
-
break;
|
|
6822
|
-
}
|
|
6823
|
-
// parse shadow
|
|
6824
|
-
var shadow = data.scene.shadow;
|
|
6825
|
-
if (shadow) {
|
|
6826
|
-
if (shadow.castShadows != undefined) scene.castShadows = shadow.castShadows;
|
|
6827
|
-
if (shadow.shadowResolution != undefined) scene.shadowResolution = shadow.shadowResolution;
|
|
6828
|
-
if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
|
|
6829
|
-
if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
|
|
6830
|
-
if (shadow.enableTransparentShadow != undefined) {
|
|
6831
|
-
scene.enableTransparentShadow = shadow.enableTransparentShadow;
|
|
6832
|
-
}
|
|
6833
|
-
var _shadow_shadowTwoCascadeSplits;
|
|
6834
|
-
scene.shadowTwoCascadeSplits = (_shadow_shadowTwoCascadeSplits = shadow.shadowTwoCascadeSplits) != null ? _shadow_shadowTwoCascadeSplits : scene.shadowTwoCascadeSplits;
|
|
6835
|
-
shadow.shadowFourCascadeSplits && scene.shadowFourCascadeSplits.copyFrom(shadow.shadowFourCascadeSplits);
|
|
6836
|
-
var _shadow_shadowFadeBorder;
|
|
6837
|
-
scene.shadowFadeBorder = (_shadow_shadowFadeBorder = shadow.shadowFadeBorder) != null ? _shadow_shadowFadeBorder : scene.shadowFadeBorder;
|
|
6838
|
-
}
|
|
6839
|
-
// parse fog
|
|
6840
|
-
var fog = data.scene.fog;
|
|
6841
|
-
if (fog) {
|
|
6842
|
-
if (fog.fogMode != undefined) scene.fogMode = fog.fogMode;
|
|
6843
|
-
if (fog.fogStart != undefined) scene.fogStart = fog.fogStart;
|
|
6844
|
-
if (fog.fogEnd != undefined) scene.fogEnd = fog.fogEnd;
|
|
6845
|
-
if (fog.fogDensity != undefined) scene.fogDensity = fog.fogDensity;
|
|
6846
|
-
if (fog.fogColor != undefined) scene.fogColor.copyFrom(fog.fogColor);
|
|
6847
|
-
}
|
|
6848
|
-
// parse physics
|
|
6849
|
-
var physics = data.scene.physics;
|
|
6850
|
-
// PhysicsScene has a native backing only when the engine was created with a physics backend.
|
|
6851
|
-
// Keep scene files loadable for render-only engines by ignoring serialized physics settings there.
|
|
6852
|
-
if (physics && engine._physicsInitialized) {
|
|
6853
|
-
if (physics.gravity != undefined) scene.physics.gravity.copyFrom(physics.gravity);
|
|
6854
|
-
if (physics.fixedTimeStep != undefined) scene.physics.fixedTimeStep = physics.fixedTimeStep;
|
|
6855
|
-
}
|
|
6856
|
-
// Post Process
|
|
6857
|
-
var postProcessData = data.scene.postProcess;
|
|
6858
|
-
if (postProcessData) {
|
|
6859
|
-
engineCore.Logger.warn("Post Process is not supported in scene yet, please add PostProcess component in entity instead.");
|
|
6860
|
-
}
|
|
6861
|
-
// Ambient Occlusion
|
|
6862
|
-
var ambientOcclusion = data.scene.ambientOcclusion;
|
|
6863
|
-
if (ambientOcclusion) {
|
|
6864
|
-
var sceneAmbientOcclusion = scene.ambientOcclusion;
|
|
6865
|
-
sceneAmbientOcclusion.enabled = ambientOcclusion.enabledAmbientOcclusion;
|
|
6866
|
-
sceneAmbientOcclusion.intensity = ambientOcclusion.intensity;
|
|
6867
|
-
sceneAmbientOcclusion.radius = ambientOcclusion.radius;
|
|
6868
|
-
sceneAmbientOcclusion.bias = ambientOcclusion.bias;
|
|
6869
|
-
sceneAmbientOcclusion.power = ambientOcclusion.power;
|
|
6870
|
-
sceneAmbientOcclusion.quality = ambientOcclusion.quality;
|
|
6871
|
-
sceneAmbientOcclusion.bilateralThreshold = ambientOcclusion.bilateralThreshold;
|
|
6872
|
-
sceneAmbientOcclusion.minHorizonAngle = ambientOcclusion.minHorizonAngle;
|
|
6873
|
-
}
|
|
6874
|
-
return Promise.all(promises).then(function() {
|
|
6572
|
+
return applySceneData(scene, data.scene, resourceManager, data.refs).then(function() {
|
|
6875
6573
|
resolve(scene);
|
|
6876
6574
|
});
|
|
6877
6575
|
});
|