@galacean/engine-loader 0.0.0-experimental-2.0-spine.0 → 0.0.0-experimental-2.0-game.19
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 +1383 -1081
- package/dist/main.js.map +1 -1
- package/dist/module.js +1384 -1082
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/HDRDecoder.d.ts +8 -27
- package/types/SceneLoader.d.ts +1 -8
- package/types/ShaderChunkLoader.d.ts +9 -0
- package/types/{TextureLoader.d.ts → Texture2DLoader.d.ts} +4 -4
- package/types/gltf/extensions/GLTFExtensionSchema.d.ts +3 -2
- package/types/gltf/parser/GLTFSceneParser.d.ts +0 -1
- package/types/gltf/parser/GLTFSkinParser.d.ts +2 -5
- package/types/index.d.ts +5 -3
- package/types/prefab/PrefabParser.d.ts +6 -9
- package/types/resource-deserialize/index.d.ts +2 -3
- package/types/resource-deserialize/resources/parser/HierarchyParser.d.ts +27 -22
- package/types/resource-deserialize/resources/parser/ParserContext.d.ts +11 -11
- package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +18 -41
- package/types/resource-deserialize/resources/scene/SceneParser.d.ts +7 -6
- package/types/resource-deserialize/resources/schema/BasicSchema.d.ts +105 -0
- package/types/resource-deserialize/resources/schema/MaterialSchema.d.ts +102 -0
- package/types/resource-deserialize/resources/schema/SceneSchema.d.ts +84 -0
- package/types/{schema → resource-deserialize/resources/schema}/index.d.ts +1 -4
- package/types/resource-deserialize/resources/texture2D/TextureDecoder.d.ts +9 -0
- package/types/schema/BasicSchema.d.ts +0 -21
- package/types/schema/CommonSchema.d.ts +0 -33
- package/types/schema/HierarchySchema.d.ts +0 -71
- package/types/schema/MaterialSchema.d.ts +0 -27
- package/types/schema/PrefabSchema.d.ts +0 -4
- package/types/schema/SceneSchema.d.ts +0 -59
- package/types/schema/refs.d.ts +0 -2
- /package/types/{resource-deserialize/resources/texture2D/Texture2DDecoder.d.ts → TextureCubeLoader.d.ts} +0 -0
- /package/types/{resource-deserialize/resources/textureCube/TextureCubeDecoder.d.ts → gltf/parser/GLTFSkinParser.test.d.ts} +0 -0
- /package/types/{schema → resource-deserialize/resources/schema}/ProjectSchema.d.ts +0 -0
package/dist/main.js
CHANGED
|
@@ -643,27 +643,37 @@ function float32ArrayToVector2(float32Array, vertexCount) {
|
|
|
643
643
|
return array;
|
|
644
644
|
}
|
|
645
645
|
|
|
646
|
-
function
|
|
647
|
-
|
|
646
|
+
function _is_native_reflect_construct() {
|
|
647
|
+
// Since Reflect.construct can't be properly polyfilled, some
|
|
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
|
+
}
|
|
648
660
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
661
|
+
function _construct(Parent, args, Class) {
|
|
662
|
+
if (_is_native_reflect_construct()) _construct = Reflect.construct;
|
|
663
|
+
else {
|
|
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();
|
|
652
669
|
|
|
653
|
-
|
|
654
|
-
key = sourceKeys[i];
|
|
655
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
656
|
-
target[key] = source[key];
|
|
657
|
-
}
|
|
670
|
+
if (Class) _set_prototype_of(instance, Class.prototype);
|
|
658
671
|
|
|
659
|
-
|
|
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);
|
|
672
|
+
return instance;
|
|
673
|
+
};
|
|
665
674
|
}
|
|
666
|
-
|
|
675
|
+
|
|
676
|
+
return _construct.apply(null, arguments);
|
|
667
677
|
}
|
|
668
678
|
|
|
669
679
|
var ParserType = /*#__PURE__*/ function(ParserType) {
|
|
@@ -679,20 +689,32 @@ var ParserType = /*#__PURE__*/ function(ParserType) {
|
|
|
679
689
|
this.engine = engine;
|
|
680
690
|
this.type = type;
|
|
681
691
|
this.resource = resource;
|
|
682
|
-
this
|
|
683
|
-
this
|
|
692
|
+
this.entityMap = new Map();
|
|
693
|
+
this.entityConfigMap = new Map();
|
|
694
|
+
this.components = new Map();
|
|
695
|
+
this.componentConfigMap = new Map();
|
|
696
|
+
this.rootIds = [];
|
|
697
|
+
this.strippedIds = [];
|
|
698
|
+
this._tasks = new Set();
|
|
684
699
|
this._loaded = 0;
|
|
685
700
|
this._total = 0;
|
|
686
701
|
this.resourceManager = engine.resourceManager;
|
|
687
702
|
}
|
|
688
703
|
var _proto = ParserContext.prototype;
|
|
689
704
|
_proto.clear = function clear() {
|
|
690
|
-
this.
|
|
691
|
-
this.
|
|
692
|
-
|
|
693
|
-
|
|
705
|
+
this.entityMap.clear();
|
|
706
|
+
this.components.clear();
|
|
707
|
+
this.componentConfigMap.clear();
|
|
708
|
+
this.entityConfigMap.clear();
|
|
709
|
+
this.rootIds.length = 0;
|
|
710
|
+
this.strippedIds.length = 0;
|
|
711
|
+
};
|
|
712
|
+
/** @internal */ _proto._addDependentAsset = function _addDependentAsset(url, promise) {
|
|
694
713
|
var _this = this;
|
|
714
|
+
var tasks = this._tasks;
|
|
715
|
+
if (tasks.has(url)) return;
|
|
695
716
|
++this._total;
|
|
717
|
+
tasks.add(url);
|
|
696
718
|
promise.finally(function() {
|
|
697
719
|
++_this._loaded;
|
|
698
720
|
_this._setTaskCompleteProgress(_this._loaded, _this._total);
|
|
@@ -702,399 +724,243 @@ var ParserType = /*#__PURE__*/ function(ParserType) {
|
|
|
702
724
|
}();
|
|
703
725
|
|
|
704
726
|
var ReflectionParser = /*#__PURE__*/ function() {
|
|
705
|
-
function ReflectionParser(_context
|
|
727
|
+
function ReflectionParser(_context) {
|
|
706
728
|
this._context = _context;
|
|
707
|
-
this._refs = _refs;
|
|
708
729
|
}
|
|
709
730
|
var _proto = ReflectionParser.prototype;
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
731
|
+
_proto.parseEntity = function parseEntity(entityConfig) {
|
|
732
|
+
var _this = this;
|
|
733
|
+
return this._getEntityByConfig(entityConfig).then(function(entity) {
|
|
734
|
+
var _entityConfig_isActive;
|
|
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) {
|
|
714
767
|
var promises = [];
|
|
715
|
-
if (
|
|
768
|
+
if (item.methods) {
|
|
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) {
|
|
716
777
|
var _this, _loop = function(key) {
|
|
717
|
-
var
|
|
718
|
-
|
|
778
|
+
var value = item.props[key];
|
|
779
|
+
var promise = _this.parseBasicType(value, instance[key]).then(function(v) {
|
|
780
|
+
return instance[key] = v;
|
|
719
781
|
});
|
|
720
782
|
promises.push(promise);
|
|
721
783
|
};
|
|
722
|
-
for(var key in props)_this = this, _loop(key);
|
|
784
|
+
for(var key in item.props)_this = this, _loop(key);
|
|
723
785
|
}
|
|
724
786
|
return Promise.all(promises).then(function() {
|
|
725
787
|
return instance;
|
|
726
788
|
});
|
|
727
789
|
};
|
|
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
|
-
};
|
|
790
|
+
_proto.parseMethod = function parseMethod(instance, methodName, methodParams) {
|
|
753
791
|
var _this = this;
|
|
754
|
-
|
|
755
|
-
var
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
this.parseProps(target, block.props),
|
|
767
|
-
this.parseCalls(target, block.calls)
|
|
768
|
-
]).then(function() {
|
|
769
|
-
return target;
|
|
792
|
+
var isMethodObject = ReflectionParser._isMethodObject(methodParams);
|
|
793
|
+
var params = isMethodObject ? methodParams.params : methodParams;
|
|
794
|
+
return Promise.all(params.map(function(param) {
|
|
795
|
+
return _this.parseBasicType(param);
|
|
796
|
+
})).then(function(result) {
|
|
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
|
+
}
|
|
770
804
|
});
|
|
771
805
|
};
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
}));
|
|
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);
|
|
805
|
-
}
|
|
806
|
-
// @ts-ignore
|
|
807
|
-
return context.resourceManager.getResourceByRef(refItem).then(function(resource) {
|
|
808
|
-
if (resource && context.type === ParserType.Prefab) {
|
|
809
|
-
// @ts-ignore
|
|
810
|
-
context.resource._addDependenceAsset(resource);
|
|
806
|
+
_proto.parseSignal = function parseSignal(signalRef) {
|
|
807
|
+
var _this = this;
|
|
808
|
+
var signal = new engineCore.Signal();
|
|
809
|
+
return Promise.all(signalRef.listeners.map(function(listener) {
|
|
810
|
+
return Promise.all([
|
|
811
|
+
_this.parseBasicType(listener.target),
|
|
812
|
+
listener.arguments ? Promise.all(listener.arguments.map(function(a) {
|
|
813
|
+
return _this.parseBasicType(a);
|
|
814
|
+
})) : Promise.resolve([])
|
|
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));
|
|
811
823
|
}
|
|
812
|
-
return resource;
|
|
813
|
-
});
|
|
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
|
});
|
|
824
|
-
}
|
|
825
|
-
|
|
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;
|
|
825
|
+
})).then(function() {
|
|
826
|
+
return signal;
|
|
847
827
|
});
|
|
848
828
|
};
|
|
849
|
-
_proto.
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
829
|
+
_proto.parseBasicType = function parseBasicType(value, originValue) {
|
|
830
|
+
var _this = this;
|
|
831
|
+
if (Array.isArray(value)) {
|
|
832
|
+
return Promise.all(value.map(function(item) {
|
|
833
|
+
return _this.parseBasicType(item);
|
|
834
|
+
}));
|
|
835
|
+
} else if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object" && value != null) {
|
|
836
|
+
if (ReflectionParser._isClassType(value)) {
|
|
837
|
+
return Promise.resolve(engineCore.Loader.getClass(value["classType"]));
|
|
838
|
+
} else if (ReflectionParser._isClass(value)) {
|
|
839
|
+
// class object
|
|
840
|
+
return this.parseClassObject(value);
|
|
841
|
+
} else if (ReflectionParser._isAssetRef(value)) {
|
|
842
|
+
var _this1 = this, context = _this1._context;
|
|
843
|
+
// reference object
|
|
844
|
+
// @ts-ignore
|
|
845
|
+
return context.resourceManager.getResourceByRef(value).then(function(resource) {
|
|
846
|
+
if (resource && context.type === ParserType.Prefab) {
|
|
847
|
+
// @ts-ignore
|
|
848
|
+
context.resource._addDependenceAsset(resource);
|
|
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
|
+
});
|
|
893
|
+
}
|
|
862
894
|
}
|
|
895
|
+
// primitive type
|
|
896
|
+
return Promise.resolve(value);
|
|
863
897
|
};
|
|
864
|
-
_proto.
|
|
898
|
+
_proto._getEntityByConfig = function _getEntityByConfig(entityConfig) {
|
|
865
899
|
var _this = this;
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
})
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
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) {
|
|
913
|
+
// @ts-ignore
|
|
914
|
+
_this._context.resource._addDependenceAsset(resource);
|
|
915
|
+
}
|
|
916
|
+
entity.name = entityConfig.name;
|
|
917
|
+
return entity;
|
|
881
918
|
});
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
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;
|
|
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
|
+
}
|
|
899
924
|
};
|
|
900
|
-
_proto.
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
var entity = (
|
|
904
|
-
for(var i = 1
|
|
905
|
-
|
|
906
|
-
entity =
|
|
925
|
+
_proto._resolveEntityByPath = function _resolveEntityByPath(entityPath) {
|
|
926
|
+
var _this__context = this._context, rootIds = _this__context.rootIds, entityMap = _this__context.entityMap;
|
|
927
|
+
if (!entityPath.length || entityPath[0] >= rootIds.length) return null;
|
|
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]];
|
|
907
932
|
}
|
|
908
933
|
return entity;
|
|
909
934
|
};
|
|
910
|
-
|
|
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
|
-
};
|
|
935
|
+
ReflectionParser._isClass = function _isClass(value) {
|
|
936
|
+
return value["class"] !== undefined;
|
|
957
937
|
};
|
|
958
|
-
|
|
959
|
-
|
|
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
|
-
};
|
|
938
|
+
ReflectionParser._isClassType = function _isClassType(value) {
|
|
939
|
+
return value["classType"] !== undefined;
|
|
972
940
|
};
|
|
973
|
-
|
|
974
|
-
|
|
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;
|
|
941
|
+
ReflectionParser._isAssetRef = function _isAssetRef(value) {
|
|
942
|
+
return value["url"] !== undefined;
|
|
995
943
|
};
|
|
996
|
-
|
|
997
|
-
|
|
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;
|
|
944
|
+
ReflectionParser._isEntityRef = function _isEntityRef(value) {
|
|
945
|
+
return Array.isArray(value["entityPath"]) && value["componentType"] === undefined;
|
|
1037
946
|
};
|
|
1038
|
-
|
|
1039
|
-
|
|
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
|
-
};
|
|
947
|
+
ReflectionParser._isComponentRef = function _isComponentRef(value) {
|
|
948
|
+
return Array.isArray(value["entityPath"]) && value["componentType"] !== undefined;
|
|
1074
949
|
};
|
|
1075
|
-
|
|
1076
|
-
|
|
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;
|
|
950
|
+
ReflectionParser._isSignalRef = function _isSignalRef(value) {
|
|
951
|
+
return value["listeners"] !== undefined;
|
|
1083
952
|
};
|
|
1084
|
-
|
|
953
|
+
ReflectionParser._isMethodObject = function _isMethodObject(value) {
|
|
954
|
+
return Array.isArray(value == null ? void 0 : value.params);
|
|
955
|
+
};
|
|
956
|
+
return ReflectionParser;
|
|
1085
957
|
}();
|
|
1086
|
-
HDRDecoder._float2HalfTables = HDRDecoder._generateFloat2HalfTables();
|
|
1087
|
-
HDRDecoder._floatView = new Float32Array(1);
|
|
1088
|
-
HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
|
|
1089
958
|
|
|
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() {
|
|
959
|
+
exports.Texture2DDecoder = /*#__PURE__*/ function() {
|
|
1094
960
|
function Texture2DDecoder() {}
|
|
1095
961
|
Texture2DDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
|
|
1096
962
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
1097
|
-
bufferReader.nextStr();
|
|
963
|
+
var url = bufferReader.nextStr();
|
|
1098
964
|
var mipmap = !!bufferReader.nextUint8();
|
|
1099
965
|
var filterMode = bufferReader.nextUint8();
|
|
1100
966
|
var anisoLevel = bufferReader.nextUint8();
|
|
@@ -1103,34 +969,58 @@ HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
|
|
|
1103
969
|
var format = bufferReader.nextUint8();
|
|
1104
970
|
var width = bufferReader.nextUint16();
|
|
1105
971
|
var height = bufferReader.nextUint16();
|
|
972
|
+
var isPixelBuffer = bufferReader.nextUint8();
|
|
1106
973
|
var isSRGBColorSpace = !!bufferReader.nextUint8();
|
|
1107
|
-
var
|
|
1108
|
-
var
|
|
1109
|
-
var
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
974
|
+
var mipCount = bufferReader.nextUint8();
|
|
975
|
+
var imagesData = bufferReader.nextImagesData(mipCount);
|
|
976
|
+
var texture2D = restoredTexture || new engineCore.Texture2D(engine, width, height, format, mipmap, isSRGBColorSpace);
|
|
977
|
+
texture2D.filterMode = filterMode;
|
|
978
|
+
texture2D.anisoLevel = anisoLevel;
|
|
979
|
+
texture2D.wrapModeU = wrapModeU;
|
|
980
|
+
texture2D.wrapModeV = wrapModeV;
|
|
981
|
+
if (isPixelBuffer) {
|
|
982
|
+
var pixelBuffer = imagesData[0];
|
|
983
|
+
texture2D.setPixelBuffer(pixelBuffer);
|
|
984
|
+
if (mipmap) {
|
|
985
|
+
texture2D.generateMipmaps();
|
|
986
|
+
for(var i = 1; i < mipCount; i++){
|
|
987
|
+
var pixelBuffer1 = imagesData[i];
|
|
988
|
+
texture2D.setPixelBuffer(pixelBuffer1, i);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
// @ts-ignore
|
|
992
|
+
engine.resourceManager._objectPool[url] = texture2D;
|
|
993
|
+
resolve(texture2D);
|
|
1120
994
|
} else {
|
|
1121
|
-
var blob = new Blob([
|
|
1122
|
-
|
|
995
|
+
var blob = new window.Blob([
|
|
996
|
+
imagesData[0]
|
|
1123
997
|
]);
|
|
1124
998
|
var img = new Image();
|
|
1125
999
|
img.onload = function() {
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1000
|
+
texture2D.setImageSource(img);
|
|
1001
|
+
var completedCount = 0;
|
|
1002
|
+
var onComplete = function() {
|
|
1003
|
+
completedCount++;
|
|
1004
|
+
if (completedCount >= mipCount) {
|
|
1005
|
+
resolve(texture2D);
|
|
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
|
+
}
|
|
1134
1024
|
};
|
|
1135
1025
|
img.src = URL.createObjectURL(blob);
|
|
1136
1026
|
}
|
|
@@ -1138,72 +1028,9 @@ HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
|
|
|
1138
1028
|
};
|
|
1139
1029
|
return Texture2DDecoder;
|
|
1140
1030
|
}();
|
|
1141
|
-
Texture2DDecoder = __decorate([
|
|
1031
|
+
exports.Texture2DDecoder = __decorate([
|
|
1142
1032
|
decoder("Texture2D")
|
|
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);
|
|
1033
|
+
], exports.Texture2DDecoder);
|
|
1207
1034
|
|
|
1208
1035
|
function _instanceof(left, right) {
|
|
1209
1036
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
@@ -1211,6 +1038,45 @@ function _instanceof(left, right) {
|
|
|
1211
1038
|
} else return left instanceof right;
|
|
1212
1039
|
}
|
|
1213
1040
|
|
|
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
|
+
|
|
1214
1080
|
/**
|
|
1215
1081
|
* The Prefab resource.
|
|
1216
1082
|
*/ var PrefabResource = /*#__PURE__*/ function(ReferResource1) {
|
|
@@ -1242,9 +1108,8 @@ function _instanceof(left, right) {
|
|
|
1242
1108
|
};
|
|
1243
1109
|
_proto._onDestroy = function _onDestroy() {
|
|
1244
1110
|
var _this = this;
|
|
1245
|
-
var _this__root;
|
|
1246
1111
|
ReferResource1.prototype._onDestroy.call(this);
|
|
1247
|
-
|
|
1112
|
+
this._root.destroy();
|
|
1248
1113
|
this._dependenceAssets.forEach(function(asset) {
|
|
1249
1114
|
if (_instanceof(asset, engineCore.ReferResource)) {
|
|
1250
1115
|
// @ts-ignore
|
|
@@ -1260,260 +1125,319 @@ function _instanceof(left, right) {
|
|
|
1260
1125
|
var _this = this;
|
|
1261
1126
|
this.data = data;
|
|
1262
1127
|
this.context = context;
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
throw new Error("Unsupported " + resourceType + ' format version "' + data.version + '". Expected "2.0".');
|
|
1266
|
-
}
|
|
1128
|
+
this._prefabContextMap = new WeakMap();
|
|
1129
|
+
this._prefabPromiseMap = new Map();
|
|
1267
1130
|
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);
|
|
1268
1139
|
this.promise = new Promise(function(resolve, reject) {
|
|
1269
1140
|
_this._reject = reject;
|
|
1270
1141
|
_this._resolve = resolve;
|
|
1271
1142
|
});
|
|
1272
|
-
this._reflectionParser = new ReflectionParser(context
|
|
1143
|
+
this._reflectionParser = new ReflectionParser(context);
|
|
1273
1144
|
}
|
|
1274
1145
|
var _proto = HierarchyParser.prototype;
|
|
1275
|
-
_proto.start = function start() {
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1146
|
+
/** start parse the scene or prefab or others */ _proto.start = function start() {
|
|
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
|
+
};
|
|
1293
1168
|
_proto._parseEntities = function _parseEntities() {
|
|
1294
|
-
var _this
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
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;
|
|
1305
|
-
}
|
|
1306
|
-
};
|
|
1307
|
-
var entities = this.data.entities;
|
|
1308
|
-
var entityInstances = this.context.entityInstances;
|
|
1169
|
+
var _this = this;
|
|
1170
|
+
var entitiesConfig = this.data.entities;
|
|
1171
|
+
var entityConfigMap = this.context.entityConfigMap;
|
|
1172
|
+
var entityMap = this.context.entityMap;
|
|
1309
1173
|
var engine = this._engine;
|
|
1310
|
-
var promises =
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
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]]);
|
|
1174
|
+
var promises = entitiesConfig.map(function(entityConfig) {
|
|
1175
|
+
var _entityConfig_strippedId;
|
|
1176
|
+
var id = (_entityConfig_strippedId = entityConfig.strippedId) != null ? _entityConfig_strippedId : entityConfig.id;
|
|
1177
|
+
entityConfig.id = id;
|
|
1178
|
+
entityConfigMap.set(id, entityConfig);
|
|
1179
|
+
return _this._getEntityByConfig(entityConfig, engine);
|
|
1180
|
+
});
|
|
1181
|
+
return Promise.all(promises).then(function(entities) {
|
|
1182
|
+
for(var i = 0, l = entities.length; i < l; i++){
|
|
1183
|
+
entityMap.set(entitiesConfig[i].id, entities[i]);
|
|
1329
1184
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1185
|
+
// Build rootIds in serialization order (not async completion order)
|
|
1186
|
+
var rootIds = _this.context.rootIds;
|
|
1187
|
+
for(var i1 = 0, l1 = entitiesConfig.length; i1 < l1; i1++){
|
|
1188
|
+
if (!entitiesConfig[i1].parent && !entitiesConfig[i1].strippedId) {
|
|
1189
|
+
rootIds.push(entitiesConfig[i1].id);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
return entities;
|
|
1193
|
+
});
|
|
1335
1194
|
};
|
|
1336
|
-
// ---------------------------------------------------------------------------
|
|
1337
|
-
// Stage 3: Add components to entities
|
|
1338
|
-
// ---------------------------------------------------------------------------
|
|
1339
1195
|
_proto._parseComponents = function _parseComponents() {
|
|
1340
|
-
var
|
|
1341
|
-
var
|
|
1342
|
-
var
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
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
|
-
});
|
|
1196
|
+
var entitiesConfig = this.data.entities;
|
|
1197
|
+
var entityMap = this.context.entityMap;
|
|
1198
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++){
|
|
1199
|
+
var entityConfig = entitiesConfig[i];
|
|
1200
|
+
if (entityConfig.strippedId) {
|
|
1201
|
+
continue;
|
|
1358
1202
|
}
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
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
|
+
})));
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
var _this = this;
|
|
1232
|
+
var entitiesConfig = this.data.entities;
|
|
1233
|
+
var entityMap = this.context.entityMap;
|
|
1380
1234
|
var promises = [];
|
|
1381
|
-
for(var i = 0,
|
|
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);
|
|
1387
|
-
}
|
|
1235
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
|
|
1388
1236
|
return Promise.all(promises);
|
|
1389
1237
|
};
|
|
1390
|
-
_proto.
|
|
1391
|
-
var
|
|
1392
|
-
var
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1238
|
+
_proto._parseAddedComponents = function _parseAddedComponents() {
|
|
1239
|
+
var entityMap = this.context.entityMap;
|
|
1240
|
+
var entityConfigMap = this.context.entityConfigMap;
|
|
1241
|
+
var strippedIds = this.context.strippedIds;
|
|
1242
|
+
for(var i = 0, n = strippedIds.length; i < n; i++){
|
|
1243
|
+
var entityConfig = entityConfigMap.get(strippedIds[i]);
|
|
1244
|
+
var prefabContext = this._prefabContextMap.get(entityMap.get(entityConfig.prefabInstanceId));
|
|
1245
|
+
var entity = prefabContext.entityMap.get(entityConfig.prefabSource.entityId);
|
|
1246
|
+
this._addComponents(entity, entityConfig.components);
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
1249
|
+
_proto._parsePrefabRemovedEntities = function _parsePrefabRemovedEntities() {
|
|
1250
|
+
var entitiesConfig = this.data.entities;
|
|
1251
|
+
var entityMap = this.context.entityMap;
|
|
1252
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++){
|
|
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
|
+
}
|
|
1418
1266
|
}
|
|
1419
1267
|
}
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1268
|
+
};
|
|
1269
|
+
_proto._parsePrefabRemovedComponents = function _parsePrefabRemovedComponents() {
|
|
1270
|
+
var entitiesConfig = this.data.entities;
|
|
1271
|
+
var entityMap = this.context.entityMap;
|
|
1272
|
+
var prefabContextMap = this._prefabContextMap;
|
|
1273
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++){
|
|
1274
|
+
var entityConfig = entitiesConfig[i];
|
|
1275
|
+
var id = entityConfig.id, removedComponents = entityConfig.removedComponents;
|
|
1276
|
+
if (removedComponents == null ? void 0 : removedComponents.length) {
|
|
1277
|
+
var rootEntity = entityMap.get(id);
|
|
1278
|
+
for(var j = 0, m = removedComponents.length; j < m; j++){
|
|
1279
|
+
var target = removedComponents[j];
|
|
1280
|
+
var componentId = target.componentId;
|
|
1281
|
+
var context = prefabContextMap.get(rootEntity);
|
|
1282
|
+
var targetComponent = context.components.get(componentId);
|
|
1283
|
+
if (targetComponent) {
|
|
1284
|
+
targetComponent.destroy();
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1427
1287
|
}
|
|
1428
1288
|
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
}
|
|
1436
|
-
for(var j5 = 0, m5 = targets.length; j5 < m5; j5++){
|
|
1437
|
-
targets[j5].destroy();
|
|
1438
|
-
}
|
|
1289
|
+
};
|
|
1290
|
+
_proto._organizeEntities = function _organizeEntities() {
|
|
1291
|
+
var _this_context = this.context, rootIds = _this_context.rootIds, strippedIds = _this_context.strippedIds;
|
|
1292
|
+
var parentIds = rootIds.concat(strippedIds);
|
|
1293
|
+
for(var i = 0, l = parentIds.length; i < l; i++){
|
|
1294
|
+
this._parseChildren(parentIds[i]);
|
|
1439
1295
|
}
|
|
1440
|
-
|
|
1441
|
-
|
|
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
|
-
}
|
|
1296
|
+
for(var i1 = 0; i1 < rootIds.length; i1++){
|
|
1297
|
+
this._handleRootEntity(rootIds[i1]);
|
|
1454
1298
|
}
|
|
1455
1299
|
};
|
|
1456
|
-
|
|
1457
|
-
// Prefab instance loading
|
|
1458
|
-
// ---------------------------------------------------------------------------
|
|
1459
|
-
_proto._loadPrefabInstance = function _loadPrefabInstance(entityConfig, engine) {
|
|
1300
|
+
_proto._getEntityByConfig = function _getEntityByConfig(entityConfig, engine) {
|
|
1460
1301
|
var _this = this;
|
|
1461
|
-
var
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1302
|
+
var entityPromise;
|
|
1303
|
+
if (entityConfig.assetUrl) {
|
|
1304
|
+
entityPromise = this._parsePrefab(entityConfig, engine);
|
|
1305
|
+
} else if (entityConfig.strippedId) {
|
|
1306
|
+
entityPromise = this._parseStrippedEntity(entityConfig);
|
|
1307
|
+
} else {
|
|
1308
|
+
entityPromise = this._parseEntity(entityConfig, engine);
|
|
1467
1309
|
}
|
|
1310
|
+
return entityPromise.then(function(entity) {
|
|
1311
|
+
return _this._applyEntityData(entity, entityConfig);
|
|
1312
|
+
});
|
|
1313
|
+
};
|
|
1314
|
+
_proto._parseEntity = function _parseEntity(entityConfig, engine) {
|
|
1315
|
+
var transform = entityConfig.transform;
|
|
1316
|
+
var entity = new engineCore.Entity(engine, entityConfig.name, transform ? engineCore.Loader.getClass(transform.class) : engineCore.Transform);
|
|
1317
|
+
this._addEntityPlugin(entityConfig.id, entity);
|
|
1318
|
+
return Promise.resolve(entity);
|
|
1319
|
+
};
|
|
1320
|
+
_proto._parsePrefab = function _parsePrefab(entityConfig, engine) {
|
|
1321
|
+
var _this = this;
|
|
1322
|
+
var assetUrl = entityConfig.assetUrl;
|
|
1468
1323
|
return engine.resourceManager// @ts-ignore
|
|
1469
|
-
.getResourceByRef(
|
|
1324
|
+
.getResourceByRef({
|
|
1325
|
+
url: assetUrl
|
|
1326
|
+
}).then(function(prefabResource) {
|
|
1470
1327
|
var entity = _instanceof(prefabResource, PrefabResource) ? prefabResource.instantiate() : prefabResource.instantiateSceneRoot();
|
|
1471
|
-
|
|
1328
|
+
var instanceContext = new ParserContext(engine, ParserType.Prefab, null);
|
|
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
|
+
}
|
|
1472
1337
|
return entity;
|
|
1473
1338
|
});
|
|
1474
1339
|
};
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
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;
|
|
1340
|
+
_proto._parseStrippedEntity = function _parseStrippedEntity(entityConfig) {
|
|
1341
|
+
var _this = this;
|
|
1342
|
+
this.context.strippedIds.push(entityConfig.id);
|
|
1343
|
+
return new Promise(function(resolve, reject) {
|
|
1344
|
+
var _this__prefabPromiseMap_get;
|
|
1345
|
+
var cbArray = (_this__prefabPromiseMap_get = _this._prefabPromiseMap.get(entityConfig.prefabInstanceId)) != null ? _this__prefabPromiseMap_get : [];
|
|
1346
|
+
cbArray.push({
|
|
1347
|
+
resolve: resolve,
|
|
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
|
+
});
|
|
1496
1355
|
};
|
|
1497
|
-
|
|
1498
|
-
var
|
|
1499
|
-
var
|
|
1500
|
-
if (
|
|
1501
|
-
|
|
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
|
+
}
|
|
1367
|
+
}
|
|
1502
1368
|
};
|
|
1503
|
-
|
|
1504
|
-
|
|
1369
|
+
_proto._addComponents = function _addComponents(entity, components) {
|
|
1370
|
+
var context = this.context;
|
|
1371
|
+
var componentMap = context.components;
|
|
1372
|
+
var componentConfigMap = context.componentConfigMap;
|
|
1373
|
+
for(var i = 0, n = components.length; i < n; i++){
|
|
1374
|
+
var componentConfig = components[i];
|
|
1375
|
+
var key = !componentConfig.url ? componentConfig.class : componentConfig.url;
|
|
1376
|
+
var componentId = componentConfig.id;
|
|
1377
|
+
var component = entity.addComponent(engineCore.Loader.getClass(key));
|
|
1378
|
+
componentMap.set(componentId, component);
|
|
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
|
+
}
|
|
1505
1403
|
};
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1404
|
+
_proto._parseComponentsPropsAndMethods = function _parseComponentsPropsAndMethods() {
|
|
1405
|
+
var context = this.context;
|
|
1406
|
+
var componentConfigMap = context.componentConfigMap;
|
|
1407
|
+
var reflectionParser = this._reflectionParser;
|
|
1408
|
+
var promises = [];
|
|
1409
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(context.components), _step; !(_step = _iterator()).done;){
|
|
1410
|
+
var _step_value = _step.value, componentId = _step_value[0], component = _step_value[1];
|
|
1411
|
+
var componentConfig = componentConfigMap.get(componentId);
|
|
1412
|
+
if (componentConfig) {
|
|
1413
|
+
promises.push(reflectionParser.parsePropsAndMethods(component, componentConfig));
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
return Promise.all(promises);
|
|
1513
1417
|
};
|
|
1418
|
+
_proto._addComponentPlugin = function _addComponentPlugin(componentId, component) {};
|
|
1419
|
+
_proto._addEntityPlugin = function _addEntityPlugin(entityId, entity) {};
|
|
1514
1420
|
return HierarchyParser;
|
|
1515
1421
|
}();
|
|
1516
1422
|
|
|
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
|
+
|
|
1517
1441
|
/** @Internal */ var SceneParser = /*#__PURE__*/ function(HierarchyParser) {
|
|
1518
1442
|
_inherits(SceneParser, HierarchyParser);
|
|
1519
1443
|
function SceneParser(data, context, scene) {
|
|
@@ -1527,42 +1451,90 @@ function _instanceof(left, right) {
|
|
|
1527
1451
|
*/ _proto._collectDependentAssets = function _collectDependentAssets(data) {
|
|
1528
1452
|
var context = this.context;
|
|
1529
1453
|
var resourceManager = context.resourceManager;
|
|
1530
|
-
|
|
1531
|
-
|
|
1454
|
+
this._parseDependentAssets(data);
|
|
1455
|
+
var scene = data.scene;
|
|
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;
|
|
1532
1474
|
// @ts-ignore
|
|
1533
|
-
context._addDependentAsset(resourceManager.getResourceByRef(
|
|
1475
|
+
texture && context._addDependentAsset(texture.url, resourceManager.getResourceByRef(texture));
|
|
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
|
+
}
|
|
1534
1484
|
}
|
|
1535
1485
|
};
|
|
1536
|
-
_proto.
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
_proto._handleRootEntity = function _handleRootEntity(index) {
|
|
1540
|
-
this.scene.addRootEntity(this.context.entityInstances[index]);
|
|
1486
|
+
_proto._handleRootEntity = function _handleRootEntity(id) {
|
|
1487
|
+
var entityMap = this.context.entityMap;
|
|
1488
|
+
this.scene.addRootEntity(entityMap.get(id));
|
|
1541
1489
|
};
|
|
1542
1490
|
_proto._clearAndResolve = function _clearAndResolve() {
|
|
1543
1491
|
this.context.clear();
|
|
1544
1492
|
return this.scene;
|
|
1545
1493
|
};
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
var
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
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
|
+
return SceneParser;
|
|
1537
|
+
}(HierarchyParser);
|
|
1566
1538
|
|
|
1567
1539
|
/**
|
|
1568
1540
|
* Decode engine binary resource.
|
|
@@ -3045,45 +3017,6 @@ function getMeshoptDecoder() {
|
|
|
3045
3017
|
return GLTFResource;
|
|
3046
3018
|
}(engineCore.ReferResource);
|
|
3047
3019
|
|
|
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
|
-
|
|
3087
3020
|
/**
|
|
3088
3021
|
* Module for glTF 2.0 Interface
|
|
3089
3022
|
*/ /**
|
|
@@ -3705,13 +3638,11 @@ function registerGLTFParser(pipeline) {
|
|
|
3705
3638
|
});
|
|
3706
3639
|
var img = new Image();
|
|
3707
3640
|
img.onerror = function() {
|
|
3708
|
-
URL.revokeObjectURL(img.src);
|
|
3709
3641
|
reject(new Error("Failed to load image buffer"));
|
|
3710
3642
|
};
|
|
3711
3643
|
img.onload = function() {
|
|
3712
3644
|
// Call requestAnimationFrame to avoid iOS's bug.
|
|
3713
3645
|
requestAnimationFrame(function() {
|
|
3714
|
-
URL.revokeObjectURL(img.src);
|
|
3715
3646
|
resolve(img);
|
|
3716
3647
|
img.onload = null;
|
|
3717
3648
|
img.onerror = null;
|
|
@@ -4832,6 +4763,7 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
4832
4763
|
}
|
|
4833
4764
|
var _proto = GLTFSceneParser.prototype;
|
|
4834
4765
|
_proto.parse = function parse(context, index) {
|
|
4766
|
+
var _glTFResource;
|
|
4835
4767
|
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;
|
|
4836
4768
|
var sceneInfo = scenes[index];
|
|
4837
4769
|
var sceneExtensions = sceneInfo.extensions;
|
|
@@ -4845,6 +4777,7 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
4845
4777
|
for(var i = 0; i < sceneNodes.length; i++){
|
|
4846
4778
|
sceneRoot.addChild(context.get(GLTFParserType.Entity, sceneNodes[i]));
|
|
4847
4779
|
}
|
|
4780
|
+
((_glTFResource = glTFResource)._sceneRoots || (_glTFResource._sceneRoots = []))[index] = sceneRoot;
|
|
4848
4781
|
if (isDefaultScene) {
|
|
4849
4782
|
glTFResource._defaultSceneRoot = sceneRoot;
|
|
4850
4783
|
}
|
|
@@ -4974,15 +4907,13 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
4974
4907
|
if (rootBoneIndex !== -1) {
|
|
4975
4908
|
engineMath.BoundingBox.transform(mesh.bounds, inverseBindMatrices[rootBoneIndex], skinnedMeshRenderer.localBounds);
|
|
4976
4909
|
} else {
|
|
4977
|
-
|
|
4978
|
-
var inverseRootBoneWorld = GLTFSceneParser._tempMatrix;
|
|
4910
|
+
var inverseRootBoneWorld = new engineMath.Matrix();
|
|
4979
4911
|
engineMath.Matrix.invert(rootBone.transform.worldMatrix, inverseRootBoneWorld);
|
|
4980
4912
|
engineMath.BoundingBox.transform(mesh.bounds, inverseRootBoneWorld, skinnedMeshRenderer.localBounds);
|
|
4981
4913
|
}
|
|
4982
4914
|
};
|
|
4983
4915
|
return GLTFSceneParser;
|
|
4984
4916
|
}(GLTFParser);
|
|
4985
|
-
exports.GLTFSceneParser._tempMatrix = new engineMath.Matrix();
|
|
4986
4917
|
exports.GLTFSceneParser = __decorate([
|
|
4987
4918
|
registerGLTFParser(GLTFParserType.Scene)
|
|
4988
4919
|
], exports.GLTFSceneParser);
|
|
@@ -5017,31 +4948,36 @@ exports.GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
5017
4948
|
skin.joints[i] = bone.name;
|
|
5018
4949
|
}
|
|
5019
4950
|
skin.bones = bones;
|
|
5020
|
-
// Get skeleton
|
|
5021
|
-
// LCA falls back to the GLTF_ROOT wrapper only when joints span multiple top-level scene nodes
|
|
4951
|
+
// Get skeleton
|
|
5022
4952
|
if (skeleton !== undefined) {
|
|
5023
4953
|
var rootBone = entities[skeleton];
|
|
5024
|
-
if (!rootBone) {
|
|
5025
|
-
throw "Skin skeleton index " + skeleton + " is out of range.";
|
|
5026
|
-
}
|
|
5027
4954
|
skin.rootBone = rootBone;
|
|
5028
4955
|
} else {
|
|
5029
|
-
var rootBone1 = _this.
|
|
5030
|
-
if (
|
|
4956
|
+
var rootBone1 = _this._findSkinRootBoneByLCA(index, joints, entities, glTF.nodes);
|
|
4957
|
+
if (rootBone1) {
|
|
4958
|
+
skin.rootBone = rootBone1;
|
|
4959
|
+
} else {
|
|
5031
4960
|
throw "Failed to find skeleton root bone.";
|
|
5032
4961
|
}
|
|
5033
|
-
skin.rootBone = rootBone1;
|
|
5034
4962
|
}
|
|
5035
4963
|
return skin;
|
|
5036
4964
|
});
|
|
5037
4965
|
return engineCore.AssetPromise.resolve(skinPromise);
|
|
5038
4966
|
};
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
4967
|
+
_proto._findSkinRootBoneByLCA = function _findSkinRootBoneByLCA(skinIndex, joints, entities, nodes) {
|
|
4968
|
+
if (nodes === void 0) nodes = [];
|
|
4969
|
+
var nodeIndices = joints.slice();
|
|
4970
|
+
for(var i = 0, n = nodes.length; i < n; i++){
|
|
4971
|
+
var _nodes_i;
|
|
4972
|
+
if (((_nodes_i = nodes[i]) == null ? void 0 : _nodes_i.skin) === skinIndex) {
|
|
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;){
|
|
5045
4981
|
var index = _step.value;
|
|
5046
4982
|
var path = new Array();
|
|
5047
4983
|
var entity = entities[index];
|
|
@@ -5049,17 +4985,22 @@ exports.GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
|
|
|
5049
4985
|
path.unshift(entity);
|
|
5050
4986
|
entity = entity.parent;
|
|
5051
4987
|
}
|
|
5052
|
-
|
|
4988
|
+
if (path.length) {
|
|
4989
|
+
paths.push(path);
|
|
4990
|
+
}
|
|
4991
|
+
}
|
|
4992
|
+
if (!paths.length) {
|
|
4993
|
+
return null;
|
|
5053
4994
|
}
|
|
5054
4995
|
var rootNode = null;
|
|
5055
4996
|
for(var i = 0;; i++){
|
|
5056
|
-
var path1 = paths[
|
|
4997
|
+
var path1 = paths[0];
|
|
5057
4998
|
if (i >= path1.length) {
|
|
5058
4999
|
return rootNode;
|
|
5059
5000
|
}
|
|
5060
5001
|
var entity1 = path1[i];
|
|
5061
|
-
for(var j = 1, m =
|
|
5062
|
-
path1 = paths[
|
|
5002
|
+
for(var j = 1, m = paths.length; j < m; j++){
|
|
5003
|
+
path1 = paths[j];
|
|
5063
5004
|
if (i >= path1.length || entity1 !== path1[i]) {
|
|
5064
5005
|
return rootNode;
|
|
5065
5006
|
}
|
|
@@ -5122,7 +5063,7 @@ exports.GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
5122
5063
|
if (uri) {
|
|
5123
5064
|
var extIndex = uri.lastIndexOf(".");
|
|
5124
5065
|
var ext = uri.substring(extIndex + 1);
|
|
5125
|
-
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.
|
|
5066
|
+
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.Texture2D;
|
|
5126
5067
|
texture = engine.resourceManager.load({
|
|
5127
5068
|
url: engineCore.Utils.resolveAbsoluteUrl(url, uri),
|
|
5128
5069
|
type: type,
|
|
@@ -5339,17 +5280,15 @@ var PrefabParser = /*#__PURE__*/ function(HierarchyParser) {
|
|
|
5339
5280
|
return _this;
|
|
5340
5281
|
}
|
|
5341
5282
|
var _proto = PrefabParser.prototype;
|
|
5342
|
-
_proto.
|
|
5283
|
+
_proto._applyEntityData = function _applyEntityData(entity, entityConfig) {
|
|
5284
|
+
if (entityConfig === void 0) entityConfig = {};
|
|
5285
|
+
HierarchyParser.prototype._applyEntityData.call(this, entity, entityConfig);
|
|
5343
5286
|
// @ts-ignore
|
|
5344
5287
|
entity._markAsTemplate(this.context.resource);
|
|
5288
|
+
return entity;
|
|
5345
5289
|
};
|
|
5346
|
-
_proto.
|
|
5347
|
-
|
|
5348
|
-
this.data.root
|
|
5349
|
-
];
|
|
5350
|
-
};
|
|
5351
|
-
_proto._handleRootEntity = function _handleRootEntity(index) {
|
|
5352
|
-
this.prefabResource._root = this.context.entityInstances[index];
|
|
5290
|
+
_proto._handleRootEntity = function _handleRootEntity(id) {
|
|
5291
|
+
this.prefabResource._root = this.context.entityMap.get(id);
|
|
5353
5292
|
};
|
|
5354
5293
|
_proto._clearAndResolve = function _clearAndResolve() {
|
|
5355
5294
|
this.context.clear();
|
|
@@ -5360,7 +5299,9 @@ var PrefabParser = /*#__PURE__*/ function(HierarchyParser) {
|
|
|
5360
5299
|
var context = new ParserContext(engine, ParserType.Prefab, prefabResource);
|
|
5361
5300
|
var parser = new PrefabParser(data, context, prefabResource);
|
|
5362
5301
|
parser.start();
|
|
5363
|
-
return parser.promise
|
|
5302
|
+
return parser.promise.then(function() {
|
|
5303
|
+
return prefabResource;
|
|
5304
|
+
});
|
|
5364
5305
|
};
|
|
5365
5306
|
return PrefabParser;
|
|
5366
5307
|
}(HierarchyParser);
|
|
@@ -5700,6 +5641,15 @@ var KTXContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
|
5700
5641
|
return KTXContentRestorer;
|
|
5701
5642
|
}(engineCore.ContentRestorer);
|
|
5702
5643
|
|
|
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
|
+
}
|
|
5703
5653
|
var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
5704
5654
|
_inherits(MaterialLoader, Loader);
|
|
5705
5655
|
function MaterialLoader() {
|
|
@@ -5760,7 +5710,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5760
5710
|
break;
|
|
5761
5711
|
}
|
|
5762
5712
|
};
|
|
5763
|
-
var name = materialSchema.name, shaderData = materialSchema.shaderData, macros = materialSchema.macros;
|
|
5713
|
+
var name = materialSchema.name, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
|
|
5764
5714
|
var material = new engineCore.Material(engine, shader);
|
|
5765
5715
|
material.name = name;
|
|
5766
5716
|
var texturePromises = new Array();
|
|
@@ -5774,6 +5724,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5774
5724
|
materialShaderData.enableMacro(name1, value);
|
|
5775
5725
|
}
|
|
5776
5726
|
}
|
|
5727
|
+
parseProperty(material, "renderState", renderState);
|
|
5777
5728
|
return Promise.all(texturePromises).then(function() {
|
|
5778
5729
|
return material;
|
|
5779
5730
|
});
|
|
@@ -5988,7 +5939,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5988
5939
|
var _atlasItem_type;
|
|
5989
5940
|
chainPromises.push(resourceManager.load({
|
|
5990
5941
|
url: engineCore.Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
|
|
5991
|
-
type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : engineCore.AssetType.
|
|
5942
|
+
type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : engineCore.AssetType.Texture2D,
|
|
5992
5943
|
params: {
|
|
5993
5944
|
format: format,
|
|
5994
5945
|
mipmap: mipmap
|
|
@@ -6038,7 +5989,8 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6038
5989
|
var offsetLeft = atlasRegionOffset.x, offsetTop = atlasRegionOffset.y, offsetRight = atlasRegionOffset.z, offsetBottom = atlasRegionOffset.w;
|
|
6039
5990
|
sprite.atlasRegionOffset.set(offsetLeft * invW, offsetTop * invH, offsetRight * invW, offsetBottom * invH);
|
|
6040
5991
|
}
|
|
6041
|
-
|
|
5992
|
+
var _config_atlasRotated;
|
|
5993
|
+
sprite.atlasRotated = (_config_atlasRotated = config.atlasRotated) != null ? _config_atlasRotated : false;
|
|
6042
5994
|
}
|
|
6043
5995
|
width === undefined || (sprite.width = width);
|
|
6044
5996
|
height === undefined || (sprite.height = height);
|
|
@@ -6094,183 +6046,490 @@ var SpriteLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6094
6046
|
});
|
|
6095
6047
|
}
|
|
6096
6048
|
};
|
|
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);
|
|
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--;
|
|
6365
|
+
}
|
|
6366
|
+
return dataRGBA;
|
|
6367
|
+
};
|
|
6368
|
+
return HDRDecoder;
|
|
6369
|
+
}();
|
|
6370
|
+
// Float32 to Float16 lookup tables (http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf)
|
|
6371
|
+
HDRDecoder._float2HalfTables = HDRDecoder._generateFloat2HalfTables();
|
|
6372
|
+
HDRDecoder._floatView = new Float32Array(1);
|
|
6373
|
+
HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
|
|
6374
|
+
HDRDecoder._one = 0x3c00 // Half float for 1.0
|
|
6375
|
+
;
|
|
6376
|
+
// prettier-ignore
|
|
6377
|
+
HDRDecoder._faces = [
|
|
6378
|
+
/* +X */ [
|
|
6379
|
+
1,
|
|
6380
|
+
-1,
|
|
6381
|
+
-1,
|
|
6382
|
+
1,
|
|
6383
|
+
-1,
|
|
6384
|
+
1,
|
|
6385
|
+
1,
|
|
6386
|
+
1,
|
|
6387
|
+
-1,
|
|
6388
|
+
1,
|
|
6389
|
+
1,
|
|
6390
|
+
1
|
|
6391
|
+
],
|
|
6392
|
+
/* -X */ [
|
|
6393
|
+
-1,
|
|
6394
|
+
-1,
|
|
6395
|
+
1,
|
|
6396
|
+
-1,
|
|
6397
|
+
-1,
|
|
6398
|
+
-1,
|
|
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
|
+
];
|
|
6128
6463
|
|
|
6129
|
-
var
|
|
6130
|
-
_inherits(
|
|
6131
|
-
function
|
|
6464
|
+
var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
|
|
6465
|
+
_inherits(TextureCubeLoader, Loader);
|
|
6466
|
+
function TextureCubeLoader() {
|
|
6132
6467
|
return Loader.apply(this, arguments) || this;
|
|
6133
6468
|
}
|
|
6134
|
-
var _proto =
|
|
6469
|
+
var _proto = TextureCubeLoader.prototype;
|
|
6135
6470
|
_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;
|
|
6164
6471
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6165
6472
|
var engine = resourceManager.engine;
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
}
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
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);
|
|
6473
|
+
var url = item.url;
|
|
6474
|
+
var requestConfig = _extends({}, item, {
|
|
6475
|
+
type: "arraybuffer"
|
|
6476
|
+
});
|
|
6477
|
+
resourceManager// @ts-ignore
|
|
6478
|
+
._request(url, requestConfig).then(function(buffer) {
|
|
6479
|
+
if (!engineCore.SystemInfo.supportsTextureFormat(engine, engineCore.TextureFormat.R16G16B16A16)) {
|
|
6480
|
+
reject(new Error("TextureCubeLoader: HDR texture requires half float support."));
|
|
6481
|
+
return;
|
|
6482
|
+
}
|
|
6189
6483
|
var _item_params;
|
|
6190
|
-
var _ref = (_item_params = item.params) != null ? _item_params : {},
|
|
6191
|
-
var
|
|
6192
|
-
var
|
|
6193
|
-
var
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6484
|
+
var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
|
|
6485
|
+
var bufferArray = new Uint8Array(buffer);
|
|
6486
|
+
var header = HDRDecoder.parseHeader(bufferArray);
|
|
6487
|
+
var texture = new engineCore.TextureCube(engine, header.height >> 1, engineCore.TextureFormat.R16G16B16A16, mipmap, false);
|
|
6488
|
+
HDRDecoder.decodeFaces(bufferArray, header, function(faceIndex, data) {
|
|
6489
|
+
texture.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + faceIndex, data, 0);
|
|
6490
|
+
});
|
|
6491
|
+
texture.generateMipmaps();
|
|
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));
|
|
6198
6497
|
resolve(texture);
|
|
6199
|
-
};
|
|
6200
|
-
img.onerror = function(e) {
|
|
6201
|
-
URL.revokeObjectURL(img.src);
|
|
6202
|
-
reject(e);
|
|
6203
|
-
};
|
|
6204
|
-
img.src = URL.createObjectURL(blob);
|
|
6498
|
+
}).catch(reject);
|
|
6205
6499
|
});
|
|
6206
6500
|
};
|
|
6207
|
-
|
|
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;
|
|
6501
|
+
return TextureCubeLoader;
|
|
6220
6502
|
}(engineCore.Loader);
|
|
6221
|
-
|
|
6222
|
-
engineCore.resourceLoader(engineCore.AssetType.
|
|
6223
|
-
"
|
|
6224
|
-
"png",
|
|
6225
|
-
"jpg",
|
|
6226
|
-
"webp",
|
|
6227
|
-
"jpeg",
|
|
6503
|
+
TextureCubeLoader = __decorate([
|
|
6504
|
+
engineCore.resourceLoader(engineCore.AssetType.TextureCube, [
|
|
6505
|
+
"texCube",
|
|
6228
6506
|
"hdr"
|
|
6229
6507
|
])
|
|
6230
|
-
],
|
|
6231
|
-
var
|
|
6232
|
-
_inherits(
|
|
6233
|
-
function
|
|
6508
|
+
], TextureCubeLoader);
|
|
6509
|
+
var HDRContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
6510
|
+
_inherits(HDRContentRestorer, ContentRestorer);
|
|
6511
|
+
function HDRContentRestorer(resource, url, requestConfig) {
|
|
6234
6512
|
var _this;
|
|
6235
6513
|
_this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
|
|
6236
6514
|
return _this;
|
|
6237
6515
|
}
|
|
6238
|
-
var _proto =
|
|
6516
|
+
var _proto = HDRContentRestorer.prototype;
|
|
6239
6517
|
_proto.restoreContent = function restoreContent() {
|
|
6240
6518
|
var _this = this;
|
|
6241
|
-
return
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
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
|
-
});
|
|
6519
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6520
|
+
var resource = _this.resource;
|
|
6521
|
+
resource.engine.resourceManager// @ts-ignore
|
|
6522
|
+
._request(_this.url, _this.requestConfig).then(function(buffer) {
|
|
6523
|
+
var bufferArray = new Uint8Array(buffer);
|
|
6524
|
+
HDRDecoder.decodeFaces(bufferArray, HDRDecoder.parseHeader(bufferArray), function(faceIndex, data) {
|
|
6525
|
+
resource.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + faceIndex, data, 0);
|
|
6526
|
+
});
|
|
6527
|
+
resource.generateMipmaps();
|
|
6528
|
+
resolve(resource);
|
|
6529
|
+
}).catch(reject);
|
|
6271
6530
|
});
|
|
6272
6531
|
};
|
|
6273
|
-
return
|
|
6532
|
+
return HDRContentRestorer;
|
|
6274
6533
|
}(engineCore.ContentRestorer);
|
|
6275
6534
|
|
|
6276
6535
|
var AudioLoader = /*#__PURE__*/ function(Loader) {
|
|
@@ -6288,7 +6547,8 @@ var AudioLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6288
6547
|
resourceManager// @ts-ignore
|
|
6289
6548
|
._request(url, requestConfig).then(function(arrayBuffer) {
|
|
6290
6549
|
var audioClip = new engineCore.AudioClip(resourceManager.engine);
|
|
6291
|
-
|
|
6550
|
+
// @ts-ignore
|
|
6551
|
+
engineCore.AudioManager.getContext().decodeAudioData(arrayBuffer).then(function(result) {
|
|
6292
6552
|
// @ts-ignore
|
|
6293
6553
|
audioClip._setAudioSource(result);
|
|
6294
6554
|
if (url.indexOf("data:") !== 0) {
|
|
@@ -6304,12 +6564,6 @@ var AudioLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6304
6564
|
});
|
|
6305
6565
|
});
|
|
6306
6566
|
};
|
|
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
|
-
};
|
|
6313
6567
|
return AudioLoader;
|
|
6314
6568
|
}(engineCore.Loader);
|
|
6315
6569
|
AudioLoader = __decorate([
|
|
@@ -6317,12 +6571,58 @@ AudioLoader = __decorate([
|
|
|
6317
6571
|
"mp3",
|
|
6318
6572
|
"ogg",
|
|
6319
6573
|
"wav",
|
|
6574
|
+
"audio",
|
|
6320
6575
|
"m4a",
|
|
6321
6576
|
"aac",
|
|
6322
6577
|
"flac"
|
|
6323
6578
|
])
|
|
6324
6579
|
], AudioLoader);
|
|
6325
6580
|
|
|
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
|
+
|
|
6326
6626
|
var ShaderLoader = /*#__PURE__*/ function(Loader) {
|
|
6327
6627
|
_inherits(ShaderLoader, Loader);
|
|
6328
6628
|
function ShaderLoader() {
|
|
@@ -6330,29 +6630,32 @@ var ShaderLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6330
6630
|
}
|
|
6331
6631
|
var _proto = ShaderLoader.prototype;
|
|
6332
6632
|
_proto.load = function load(item, resourceManager) {
|
|
6633
|
+
var _this = this;
|
|
6333
6634
|
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
|
-
}
|
|
6343
6635
|
// @ts-ignore
|
|
6344
6636
|
return resourceManager._request(url, _extends({}, item, {
|
|
6345
6637
|
type: "text"
|
|
6346
6638
|
})).then(function(code) {
|
|
6347
|
-
|
|
6639
|
+
var builtinShader = _this._getBuiltinShader(code);
|
|
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
|
+
});
|
|
6348
6647
|
});
|
|
6349
6648
|
};
|
|
6649
|
+
_proto._getBuiltinShader = function _getBuiltinShader(code) {
|
|
6650
|
+
var match = code.match(ShaderLoader._builtinRegex);
|
|
6651
|
+
if (match && match[1]) return match[1];
|
|
6652
|
+
};
|
|
6350
6653
|
return ShaderLoader;
|
|
6351
6654
|
}(engineCore.Loader);
|
|
6655
|
+
ShaderLoader._builtinRegex = /^\s*\/\/\s*@builtin\s+(\w+)/;
|
|
6352
6656
|
ShaderLoader = __decorate([
|
|
6353
6657
|
engineCore.resourceLoader(engineCore.AssetType.Shader, [
|
|
6354
|
-
"shader"
|
|
6355
|
-
"shaderc"
|
|
6658
|
+
"shader"
|
|
6356
6659
|
])
|
|
6357
6660
|
], ShaderLoader);
|
|
6358
6661
|
|
|
@@ -6432,122 +6735,6 @@ RenderTargetLoader = __decorate([
|
|
|
6432
6735
|
])
|
|
6433
6736
|
], RenderTargetLoader);
|
|
6434
6737
|
|
|
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
|
-
}
|
|
6551
6738
|
var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
6552
6739
|
_inherits(SceneLoader, Loader);
|
|
6553
6740
|
function SceneLoader() {
|
|
@@ -6561,15 +6748,130 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6561
6748
|
._request(item.url, _extends({}, item, {
|
|
6562
6749
|
type: "json"
|
|
6563
6750
|
})).then(function(data) {
|
|
6564
|
-
var
|
|
6565
|
-
var scene = new engineCore.Scene(engine, (
|
|
6751
|
+
var _data_name;
|
|
6752
|
+
var scene = new engineCore.Scene(engine, (_data_name = data.name) != null ? _data_name : "");
|
|
6566
6753
|
var context = new ParserContext(engine, ParserType.Scene, scene);
|
|
6567
6754
|
var parser = new SceneParser(data, context, scene);
|
|
6568
6755
|
parser._collectDependentAssets(data);
|
|
6569
6756
|
context._setTaskCompleteProgress = setTaskCompleteProgress;
|
|
6570
6757
|
parser.start();
|
|
6571
6758
|
return parser.promise.then(function() {
|
|
6572
|
-
|
|
6759
|
+
var promises = [];
|
|
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() {
|
|
6573
6875
|
resolve(scene);
|
|
6574
6876
|
});
|
|
6575
6877
|
});
|