@galacean/effects-core 2.8.0-alpha.0 → 2.8.0-alpha.2

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/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.8.0-alpha.0
6
+ * Version: v2.8.0-alpha.2
7
7
  */
8
8
 
9
9
  'use strict';
@@ -37,41 +37,6 @@ function _async_to_generator(fn) {
37
37
  };
38
38
  }
39
39
 
40
- function _array_like_to_array(arr, len) {
41
- if (len == null || len > arr.length) len = arr.length;
42
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
43
- return arr2;
44
- }
45
-
46
- function _unsupported_iterable_to_array(o, minLen) {
47
- if (!o) return;
48
- if (typeof o === "string") return _array_like_to_array(o, minLen);
49
- var n = Object.prototype.toString.call(o).slice(8, -1);
50
- if (n === "Object" && o.constructor) n = o.constructor.name;
51
- if (n === "Map" || n === "Set") return Array.from(n);
52
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
53
- }
54
-
55
- function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
56
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
57
- if (it) return (it = it.call(o)).next.bind(it);
58
- // Fallback for engines without symbol support
59
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
60
- if (it) o = it;
61
- var i = 0;
62
- return function() {
63
- if (i >= o.length) return {
64
- done: true
65
- };
66
- return {
67
- done: false,
68
- value: o[i++]
69
- };
70
- };
71
- }
72
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
73
- }
74
-
75
40
  function _instanceof1(left, right) {
76
41
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
77
42
  return !!right[Symbol.hasInstance](left);
@@ -2904,134 +2869,68 @@ function applyMixins(derivedCtrl, baseCtrls) {
2904
2869
  }
2905
2870
 
2906
2871
  var pluginLoaderMap = {};
2907
- var defaultPlugins = [];
2908
- var pluginCtrlMap = {};
2872
+ var plugins = [];
2909
2873
  /**
2910
2874
  * 注册 plugin
2911
2875
  * @param name
2912
2876
  * @param pluginClass class of plugin
2913
2877
  * @param itemClass class of item
2914
2878
  * @param isDefault load
2915
- */ function registerPlugin(name, pluginClass, itemClass) {
2916
- if (pluginCtrlMap[name]) {
2879
+ */ function registerPlugin(name, pluginClass) {
2880
+ if (pluginLoaderMap[name]) {
2917
2881
  logger.error("Duplicate registration for plugin " + name + ".");
2918
2882
  }
2919
- pluginCtrlMap[name] = itemClass;
2920
2883
  pluginLoaderMap[name] = pluginClass;
2921
- addItem(defaultPlugins, name);
2884
+ var pluginInstance = new pluginClass();
2885
+ pluginInstance.name = name;
2886
+ pluginInstance.initialize();
2887
+ plugins.push(pluginInstance);
2888
+ plugins.sort(function(a, b) {
2889
+ return a.order - b.order;
2890
+ });
2922
2891
  }
2923
- function unregisterPlugin(name) {
2924
- delete pluginCtrlMap[name];
2892
+ /**
2893
+ * 注销 plugin
2894
+ */ function unregisterPlugin(name) {
2925
2895
  delete pluginLoaderMap[name];
2926
- removeItem(defaultPlugins, name);
2896
+ var pluginIndex = plugins.findIndex(function(plugin) {
2897
+ return plugin.name === name;
2898
+ });
2899
+ if (pluginIndex !== -1) {
2900
+ plugins.splice(pluginIndex, 1);
2901
+ }
2927
2902
  }
2928
2903
  var PluginSystem = /*#__PURE__*/ function() {
2929
- function PluginSystem(pluginNames) {
2930
- var loaders = {};
2931
- var loaded = [];
2932
- var addLoader = function(name) {
2933
- var loader = pluginLoaderMap[name];
2934
- if (!loaded.includes(loader)) {
2935
- loaded.push(loader);
2936
- loaders[name] = loader;
2937
- }
2938
- };
2939
- defaultPlugins.forEach(addLoader);
2940
- for(var _iterator = _create_for_of_iterator_helper_loose(pluginNames), _step; !(_step = _iterator()).done;){
2941
- var customPluginName = _step.value;
2942
- if (!pluginLoaderMap[customPluginName]) {
2943
- throw new Error("The plugin '" + customPluginName + "' not found." + getPluginUsageInfo(customPluginName));
2944
- }
2945
- }
2946
- this.plugins = Object.keys(loaders).map(function(name) {
2947
- var pluginConstructor = pluginLoaderMap[name];
2948
- var loader = new pluginConstructor();
2949
- loader.name = name;
2950
- return loader;
2951
- }).sort(function(a, b) {
2952
- return a.order - b.order;
2953
- });
2954
- }
2955
- var _proto = PluginSystem.prototype;
2956
- _proto.initializeComposition = function initializeComposition(composition, scene) {
2957
- this.plugins.forEach(function(loader) {
2904
+ function PluginSystem() {}
2905
+ PluginSystem.getPlugins = function getPlugins() {
2906
+ return plugins;
2907
+ };
2908
+ PluginSystem.initializeComposition = function initializeComposition(composition, scene) {
2909
+ plugins.forEach(function(loader) {
2958
2910
  return loader.onCompositionConstructed(composition, scene);
2959
2911
  });
2960
2912
  };
2961
- _proto.destroyComposition = function destroyComposition(comp) {
2962
- this.plugins.forEach(function(loader) {
2913
+ PluginSystem.destroyComposition = function destroyComposition(comp) {
2914
+ plugins.forEach(function(loader) {
2963
2915
  return loader.onCompositionDestroyed(comp);
2964
2916
  });
2965
2917
  };
2966
- _proto.resetComposition = function resetComposition(comp, renderFrame) {
2967
- this.plugins.forEach(function(loader) {
2968
- return loader.onCompositionReset(comp, renderFrame);
2969
- });
2970
- };
2971
- _proto.processRawJSON = function processRawJSON(json, options) {
2972
- var _this = this;
2973
- return _async_to_generator(function() {
2974
- return __generator(this, function(_state) {
2975
- return [
2976
- 2,
2977
- _this.callStatic("processRawJSON", json, options)
2978
- ];
2979
- });
2980
- })();
2981
- };
2982
- _proto.processAssets = function processAssets(json, options) {
2983
- var _this = this;
2918
+ PluginSystem.processAssets = function processAssets(scene, options) {
2984
2919
  return _async_to_generator(function() {
2985
2920
  return __generator(this, function(_state) {
2986
2921
  return [
2987
2922
  2,
2988
- _this.callStatic("processAssets", json, options)
2989
- ];
2990
- });
2991
- })();
2992
- };
2993
- _proto.precompile = function precompile(compositions, renderer) {
2994
- for(var _iterator = _create_for_of_iterator_helper_loose(this.plugins), _step; !(_step = _iterator()).done;){
2995
- var plugin = _step.value;
2996
- plugin.precompile(compositions, renderer);
2997
- }
2998
- };
2999
- _proto.loadResources = function loadResources(scene, options) {
3000
- var _this = this;
3001
- return _async_to_generator(function() {
3002
- return __generator(this, function(_state) {
3003
- return [
3004
- 2,
3005
- _this.callStatic("prepareResource", scene, options)
2923
+ Promise.all(plugins.map(function(plugin) {
2924
+ return plugin.processAssets(scene, options);
2925
+ }))
3006
2926
  ];
3007
2927
  });
3008
2928
  })();
3009
2929
  };
3010
- _proto.callStatic = function callStatic(name) {
3011
- for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
3012
- args[_key - 1] = arguments[_key];
3013
- }
3014
- var _this = this;
3015
- return _async_to_generator(function() {
3016
- var pendings, plugins, i, plugin, ctrl, _ctrl_name, _ctrl_name1;
3017
- return __generator(this, function(_state) {
3018
- pendings = [];
3019
- plugins = _this.plugins;
3020
- for(i = 0; i < plugins.length; i++){
3021
- plugin = plugins[i];
3022
- ctrl = pluginLoaderMap[plugin.name];
3023
- if (name in ctrl) {
3024
- pendings.push(Promise.resolve((_ctrl_name1 = ctrl[name]) == null ? void 0 : (_ctrl_name = _ctrl_name1).call.apply(_ctrl_name, [].concat([
3025
- ctrl
3026
- ], args))));
3027
- }
3028
- }
3029
- return [
3030
- 2,
3031
- Promise.all(pendings)
3032
- ];
3033
- });
3034
- })();
2930
+ PluginSystem.loadResources = function loadResources(scene, options, engine) {
2931
+ plugins.forEach(function(loader) {
2932
+ return loader.prepareResource(scene, options, engine);
2933
+ });
3035
2934
  };
3036
2935
  return PluginSystem;
3037
2936
  }();
@@ -3039,6 +2938,8 @@ var pluginInfoMap = {
3039
2938
  "alipay-downgrade": "@galacean/effects-plugin-alipay-downgrade",
3040
2939
  "downgrade": "@galacean/effects-plugin-downgrade",
3041
2940
  "editor-gizmo": "@galacean/effects-plugin-editor-gizmo",
2941
+ "ffd": "@galacean/effects-plugin-ffd",
2942
+ "ktx2": "@galacean/effects-plugin-ktx2",
3042
2943
  "model": "@galacean/effects-plugin-model",
3043
2944
  "video": "@galacean/effects-plugin-multimedia",
3044
2945
  "audio": "@galacean/effects-plugin-multimedia",
@@ -3064,15 +2965,33 @@ function getPluginUsageInfo(name) {
3064
2965
  this.name = "";
3065
2966
  }
3066
2967
  var _proto = AbstractPlugin.prototype;
2968
+ _proto.initialize = function initialize() {};
2969
+ /**
2970
+ * loadScene 函数调用的时候会触发此函数,
2971
+ * 此阶段可以加载插件所需类型资源,并返回原始资源和加载后的资源。
2972
+ * @param scene
2973
+ * @param options
2974
+ * @returns
2975
+ */ _proto.processAssets = function processAssets(scene, options) {
2976
+ return _async_to_generator(function() {
2977
+ return __generator(this, function(_state) {
2978
+ return [
2979
+ 2
2980
+ ];
2981
+ });
2982
+ })();
2983
+ };
3067
2984
  /**
3068
- * 在加载到 JSON 后,就可以进行提前编译
3069
- * @param json
3070
- * @param player
3071
- */ _proto.precompile = function precompile(compositions, renderer) {};
2985
+ * loadScene 函数调用的时候会触发此函数,
2986
+ * 此阶段时,json 中的图片和二进制已经被加载完成,可以对加载好的资源做进一步处理,
2987
+ * 如果 promise 被 reject, loadScene 函数同样会被 reject,表示场景加载失败。
2988
+ * 请记住,整个 load 阶段都不要创建 GL 相关的对象,只创建 JS 对象
2989
+ * 此阶段晚于 processAssets
2990
+ * @param {Scene} scene
2991
+ * @param {SceneLoadOptions} options
2992
+ */ _proto.prepareResource = function prepareResource(scene, options, engine) {};
3072
2993
  _proto.onCompositionConstructed = function onCompositionConstructed(composition, scene) {};
3073
- _proto.onCompositionReset = function onCompositionReset(composition, frame) {};
3074
2994
  _proto.onCompositionDestroyed = function onCompositionDestroyed(composition) {};
3075
- _proto.onCompositionUpdate = function onCompositionUpdate(composition, dt) {};
3076
2995
  return AbstractPlugin;
3077
2996
  }();
3078
2997
 
@@ -4057,6 +3976,41 @@ var index$1 = /*#__PURE__*/Object.freeze({
4057
3976
  get VertexBufferSemantic () { return VertexBufferSemantic; }
4058
3977
  });
4059
3978
 
3979
+ function _array_like_to_array(arr, len) {
3980
+ if (len == null || len > arr.length) len = arr.length;
3981
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
3982
+ return arr2;
3983
+ }
3984
+
3985
+ function _unsupported_iterable_to_array(o, minLen) {
3986
+ if (!o) return;
3987
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
3988
+ var n = Object.prototype.toString.call(o).slice(8, -1);
3989
+ if (n === "Object" && o.constructor) n = o.constructor.name;
3990
+ if (n === "Map" || n === "Set") return Array.from(n);
3991
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
3992
+ }
3993
+
3994
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
3995
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
3996
+ if (it) return (it = it.call(o)).next.bind(it);
3997
+ // Fallback for engines without symbol support
3998
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
3999
+ if (it) o = it;
4000
+ var i = 0;
4001
+ return function() {
4002
+ if (i >= o.length) return {
4003
+ done: true
4004
+ };
4005
+ return {
4006
+ done: false,
4007
+ value: o[i++]
4008
+ };
4009
+ };
4010
+ }
4011
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4012
+ }
4013
+
4060
4014
  var decoratorInitialStore = new Map();
4061
4015
  var mergedStore = new Map();
4062
4016
  var effectsClassStore = {};
@@ -9881,6 +9835,8 @@ var TextureFactory = /*#__PURE__*/ function() {
9881
9835
  internalFormat: textureData.internalFormat,
9882
9836
  format: textureData.format,
9883
9837
  mipmaps: textureData.mipmaps,
9838
+ minFilter: glContext.LINEAR,
9839
+ magFilter: glContext.LINEAR,
9884
9840
  sourceFrom: sourceFrom
9885
9841
  }, config)
9886
9842
  ];
@@ -10353,208 +10309,70 @@ var MaskProcessor = /*#__PURE__*/ function() {
10353
10309
  return MaskProcessor;
10354
10310
  }();
10355
10311
 
10356
- exports.ShaderCompileResultStatus = void 0;
10357
- (function(ShaderCompileResultStatus) {
10358
- ShaderCompileResultStatus[ShaderCompileResultStatus["noShader"] = 0] = "noShader";
10359
- ShaderCompileResultStatus[ShaderCompileResultStatus["success"] = 1] = "success";
10360
- ShaderCompileResultStatus[ShaderCompileResultStatus["fail"] = 2] = "fail";
10361
- ShaderCompileResultStatus[ShaderCompileResultStatus["compiling"] = 3] = "compiling";
10362
- })(exports.ShaderCompileResultStatus || (exports.ShaderCompileResultStatus = {}));
10363
- exports.GLSLVersion = void 0;
10364
- (function(GLSLVersion) {
10365
- GLSLVersion["GLSL1"] = "100";
10366
- GLSLVersion["GLSL3"] = "300 es";
10367
- })(exports.GLSLVersion || (exports.GLSLVersion = {}));
10368
- var ShaderVariant = /*#__PURE__*/ function(EffectsObject) {
10369
- _inherits(ShaderVariant, EffectsObject);
10370
- function ShaderVariant(engine, source) {
10371
- var _this;
10372
- _this = EffectsObject.call(this, engine) || this;
10373
- _this.source = source;
10374
- return _this;
10375
- }
10376
- return ShaderVariant;
10377
- }(EffectsObject);
10378
- exports.Shader = /*#__PURE__*/ function(EffectsObject) {
10379
- _inherits(Shader, EffectsObject);
10380
- function Shader() {
10381
- return EffectsObject.apply(this, arguments);
10382
- }
10383
- var _proto = Shader.prototype;
10384
- _proto.createVariant = function createVariant(macros) {
10385
- var shaderMacros = [];
10386
- if (macros) {
10387
- for(var _iterator = _create_for_of_iterator_helper_loose(Object.keys(macros)), _step; !(_step = _iterator()).done;){
10388
- var key = _step.value;
10389
- shaderMacros.push([
10390
- key,
10391
- macros[key]
10392
- ]);
10393
- }
10394
- }
10395
- var shaderVariant = this.engine.getShaderLibrary().createShader(this.shaderData, shaderMacros);
10396
- shaderVariant.shader = this;
10397
- return shaderVariant;
10398
- };
10399
- _proto.fromData = function fromData(data) {
10400
- EffectsObject.prototype.fromData.call(this, data);
10401
- this.shaderData = data;
10402
- };
10403
- return Shader;
10404
- }(EffectsObject);
10405
- exports.Shader = __decorate([
10406
- effectsClass(DataType.Shader)
10407
- ], exports.Shader);
10408
-
10409
10312
  var EFFECTS_COPY_MESH_NAME = "effects-internal-copy";
10410
10313
  var COPY_MESH_SHADER_ID = "effects-internal-copy-mesh";
10411
10314
  var COPY_VERTEX_SHADER = "\nprecision highp float;\nattribute vec2 aPos;\nvarying vec2 vTex;\nvoid main(){\n gl_Position = vec4(aPos,0.,1.0);\n vTex = (aPos + vec2(1.0))/2.;\n}";
10412
10315
  var COPY_FRAGMENT_SHADER = "precision mediump float;\nvarying vec2 vTex;\n\n#ifdef DEPTH_TEXTURE\nuniform sampler2D uDepth;\n#extension GL_EXT_frag_depth : enable\n#endif\nvoid main(){\n #ifdef DEPTH_TEXTURE\n gl_FragDepthEXT = texture2D(uDepth,vTex).r;\n #endif\n}\n";
10413
- function createCopyShader(level, writeDepth) {
10414
- var webgl2 = level === 2;
10415
- return {
10416
- name: EFFECTS_COPY_MESH_NAME,
10417
- vertex: COPY_VERTEX_SHADER,
10418
- fragment: COPY_FRAGMENT_SHADER,
10419
- glslVersion: webgl2 ? exports.GLSLVersion.GLSL3 : exports.GLSLVersion.GLSL1,
10420
- macros: [
10421
- [
10422
- "DEPTH_TEXTURE",
10423
- !!writeDepth
10424
- ]
10425
- ],
10426
- // @ts-expect-error
10427
- cacheId: COPY_MESH_SHADER_ID + +writeDepth
10428
- };
10429
- }
10430
10316
 
10431
- var def = {
10432
- format: glContext.RGBA,
10433
- type: glContext.UNSIGNED_BYTE,
10434
- minFilter: glContext.LINEAR,
10435
- magFilter: glContext.LINEAR,
10436
- wrapS: glContext.CLAMP_TO_EDGE,
10437
- wrapT: glContext.CLAMP_TO_EDGE
10438
- };
10439
- var disposeSymbol = Symbol("dispose");
10440
- var PassTextureCache = /*#__PURE__*/ function() {
10441
- function PassTextureCache(engine) {
10442
- this.textureCache = {};
10443
- this.textureRef = {};
10444
- this.engine = engine;
10445
- }
10446
- var _proto = PassTextureCache.prototype;
10447
- _proto.requestColorAttachmentTexture = function requestColorAttachmentTexture(request) {
10448
- var _this = this;
10449
- var width = request.width, height = request.height, name = request.name;
10450
- var options = {
10451
- sourceType: exports.TextureSourceType.framebuffer,
10452
- data: {
10453
- width: width,
10454
- height: height
10455
- },
10456
- name: name
10457
- };
10458
- var keys = [
10459
- name
10460
- ];
10461
- Object.getOwnPropertyNames(def).forEach(function(name) {
10462
- var _request_name;
10463
- var value = (_request_name = request[name]) != null ? _request_name : def[name];
10464
- options[name] = value;
10465
- keys.push(name, value);
10466
- });
10467
- var cacheId = keys.join(":");
10468
- var tex = this.textureCache[cacheId];
10469
- if (tex) {
10470
- this.textureRef[cacheId]++;
10471
- } else {
10472
- var engine = this.engine;
10473
- assertExist(engine);
10474
- tex = Texture.create(engine, options);
10475
- this.textureCache[cacheId] = tex;
10476
- this.textureRef[cacheId] = 1;
10477
- // @ts-expect-error
10478
- tex[disposeSymbol] = tex.dispose;
10479
- tex.dispose = function() {
10480
- return _this.removeTexture(cacheId);
10481
- };
10482
- }
10483
- return tex;
10317
+ exports.FilterMode = void 0;
10318
+ (function(FilterMode) {
10319
+ FilterMode[FilterMode["Nearest"] = 0] = "Nearest";
10320
+ FilterMode[FilterMode["Linear"] = 1] = "Linear";
10321
+ })(exports.FilterMode || (exports.FilterMode = {}));
10322
+ exports.RenderTextureFormat = void 0;
10323
+ (function(RenderTextureFormat) {
10324
+ RenderTextureFormat[RenderTextureFormat["RGBA32"] = 0] = "RGBA32";
10325
+ RenderTextureFormat[RenderTextureFormat["RGBAHalf"] = 1] = "RGBAHalf";
10326
+ })(exports.RenderTextureFormat || (exports.RenderTextureFormat = {}));
10327
+ /**
10328
+ *
10329
+ */ var Framebuffer = /*#__PURE__*/ function() {
10330
+ function Framebuffer() {}
10331
+ var _proto = Framebuffer.prototype;
10332
+ _proto.resize = function resize(x, y, width, height) {
10333
+ // OVERRIDE
10484
10334
  };
10485
- _proto.removeTexture = function removeTexture(id) {
10486
- var refCount = this.textureRef[id];
10487
- if (refCount <= 1) {
10488
- if (refCount < 0) {
10489
- console.error("Ref count < 0.");
10490
- }
10491
- var tex = this.textureCache[id];
10492
- if (tex) {
10493
- // @ts-expect-error
10494
- tex[disposeSymbol]();
10495
- // @ts-expect-error
10496
- tex.dispose = tex[disposeSymbol];
10497
- }
10498
- delete this.textureCache[id];
10499
- delete this.textureRef[id];
10500
- } else {
10501
- this.textureRef[id] = refCount - 1;
10502
- }
10335
+ _proto.resetColorTextures = function resetColorTextures(textures) {
10336
+ // OVERRIDE
10503
10337
  };
10504
- _proto.dispose = function dispose() {
10505
- var _this = this;
10506
- Object.keys(this.textureCache).forEach(function(key) {
10507
- var texture = _this.textureCache[key];
10508
- // @ts-expect-error
10509
- texture[disposeSymbol]();
10510
- // @ts-expect-error
10511
- texture.dispose = texture[disposeSymbol];
10512
- });
10513
- this.textureCache = {};
10514
- this.textureRef = {};
10515
- this.engine = undefined;
10338
+ _proto.unbind = function unbind() {
10339
+ // OVERRIDE
10516
10340
  };
10517
- return PassTextureCache;
10518
- }();
10519
-
10520
- function _assert_this_initialized(self) {
10521
- if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
10522
- return self;
10523
- }
10524
-
10525
- var SemanticMap = /*#__PURE__*/ function() {
10526
- function SemanticMap(semantics) {
10527
- if (semantics === void 0) semantics = {};
10528
- this.semantics = _extends({}, semantics);
10529
- }
10530
- var _proto = SemanticMap.prototype;
10531
- _proto.toObject = function toObject() {
10532
- return _extends({}, this.semantics);
10341
+ _proto.bind = function bind() {
10342
+ // OVERRIDE
10533
10343
  };
10534
- _proto.setSemantic = function setSemantic(name, value) {
10535
- if (value === undefined) {
10536
- delete this.semantics[name];
10537
- } else {
10538
- this.semantics[name] = value;
10539
- }
10344
+ _proto.getDepthTexture = function getDepthTexture() {
10345
+ // OVERRIDE
10346
+ return undefined;
10540
10347
  };
10541
- _proto.getSemanticValue = function getSemanticValue(name, state) {
10542
- var ret = this.semantics[name];
10543
- if (isFunction(ret)) {
10544
- return ret(state);
10545
- }
10546
- return ret;
10348
+ _proto.getStencilTexture = function getStencilTexture() {
10349
+ // OVERRIDE
10350
+ return undefined;
10547
10351
  };
10548
- _proto.hasSemanticValue = function hasSemanticValue(name) {
10549
- return name in this.semantics;
10352
+ _proto.getColorTextures = function getColorTextures() {
10353
+ // OVERRIDE
10354
+ return [];
10550
10355
  };
10551
- _proto.dispose = function dispose() {
10552
- var _this = this;
10553
- Object.keys(this.semantics).forEach(function(name) {
10554
- delete _this.semantics[name];
10555
- });
10356
+ _proto.dispose = function dispose(options) {
10357
+ // OVERRIDE
10556
10358
  };
10557
- return SemanticMap;
10359
+ _create_class(Framebuffer, [
10360
+ {
10361
+ key: "stencilStorage",
10362
+ get: function get() {
10363
+ // OVERRIDE
10364
+ return undefined;
10365
+ }
10366
+ },
10367
+ {
10368
+ key: "depthStorage",
10369
+ get: function get() {
10370
+ // OVERRIDE
10371
+ return undefined;
10372
+ }
10373
+ }
10374
+ ]);
10375
+ return Framebuffer;
10558
10376
  }();
10559
10377
 
10560
10378
  var RenderPassPriorityPrepare = 0;
@@ -10566,7 +10384,7 @@ exports.RenderPassAttachmentStorageType = void 0;
10566
10384
  RenderPassAttachmentStorageType[RenderPassAttachmentStorageType["color"] = 1] = "color";
10567
10385
  //stencil 8 render buffer
10568
10386
  RenderPassAttachmentStorageType[RenderPassAttachmentStorageType["stencil_8_opaque"] = 2] = "stencil_8_opaque";
10569
- //stencil 16 render buffer
10387
+ //depth 16 render buffer
10570
10388
  RenderPassAttachmentStorageType[RenderPassAttachmentStorageType["depth_16_opaque"] = 3] = "depth_16_opaque";
10571
10389
  //depth 16 & stencil 8 render buffer
10572
10390
  RenderPassAttachmentStorageType[RenderPassAttachmentStorageType["depth_stencil_opaque"] = 4] = "depth_stencil_opaque";
@@ -10685,128 +10503,47 @@ var seed$7 = 1;
10685
10503
  /**
10686
10504
  * RenderPass 抽象类
10687
10505
  */ var RenderPass = /*#__PURE__*/ function() {
10688
- function RenderPass(renderer, options) {
10506
+ function RenderPass(renderer) {
10689
10507
  /**
10690
- * ColorAttachment 数组
10691
- */ this.attachments = [];
10692
- this.destroyed = false;
10693
- this.initialized = false;
10694
- var _options_name = options.name, name = _options_name === void 0 ? "RenderPass_" + seed$7++ : _options_name, clearAction = options.clearAction, semantics = options.semantics, depthStencilAttachment = options.depthStencilAttachment, storeAction = options.storeAction, _options_priority = options.priority, priority = _options_priority === void 0 ? 0 : _options_priority, _options_meshOrder = options.meshOrder, meshOrder = _options_meshOrder === void 0 ? exports.OrderType.ascending : _options_meshOrder, _options_meshes = options.meshes, meshes = _options_meshes === void 0 ? [] : _options_meshes, _options_delegate = options.delegate, delegate = _options_delegate === void 0 ? {} : _options_delegate;
10695
- this.name = name;
10508
+ * 优先级
10509
+ */ this.priority = 0;
10510
+ /**
10511
+ * 名称
10512
+ */ this.name = "RenderPass" + seed$7++;
10513
+ /**
10514
+ * 包含的 Mesh 列表
10515
+ */ this.meshes = [];
10516
+ this.disposed = false;
10517
+ this.framebuffer = null;
10696
10518
  this.renderer = renderer;
10697
- this.priority = priority;
10698
- this.meshOrder = meshOrder;
10699
- this.meshes = sortByOrder(meshes.slice(), this.meshOrder);
10700
- this.depthStencilType = (depthStencilAttachment == null ? void 0 : depthStencilAttachment.storageType) || 0;
10701
- this.clearAction = _extends({}, clearAction);
10702
- this.storeAction = _extends({
10703
- colorAction: 0,
10704
- depthAction: 0,
10705
- stencilAction: 0
10706
- }, storeAction);
10707
- this.semantics = new SemanticMap(semantics);
10708
- this.options = options;
10709
- this.delegate = delegate;
10710
10519
  }
10711
10520
  var _proto = RenderPass.prototype;
10712
10521
  _proto.addMesh = function addMesh(mesh) {
10713
- addByOrder(this.meshes, mesh, this.meshOrder);
10522
+ addByOrder(this.meshes, mesh);
10714
10523
  };
10715
10524
  _proto.removeMesh = function removeMesh(mesh) {
10716
10525
  removeItem(this.meshes, mesh);
10717
10526
  };
10718
- _proto.setMeshes = function setMeshes(meshes) {
10719
- var _this_meshes;
10720
- this.meshes.length = 0;
10721
- (_this_meshes = this.meshes).splice.apply(_this_meshes, [].concat([
10722
- 0,
10723
- 0
10724
- ], meshes));
10725
- sortByOrder(this.meshes, this.meshOrder);
10726
- return this.meshes;
10727
- };
10728
- // TODO 所有pass在子类配置
10729
10527
  /**
10730
10528
  * 配置当前pass的RT,在每帧渲染前调用
10731
10529
  */ _proto.configure = function configure(renderer) {
10732
- if (this.framebuffer) {
10733
- renderer.setFramebuffer(this.framebuffer);
10734
- } else {
10735
- var _this_getViewport = this.getViewport(), x = _this_getViewport[0], y = _this_getViewport[1], width = _this_getViewport[2], height = _this_getViewport[3];
10736
- renderer.setViewport(x, y, width, height);
10737
- }
10530
+ // OVERRIDE
10738
10531
  };
10739
10532
  /**
10740
10533
  * 执行当前pass,每帧调用一次
10741
10534
  */ _proto.execute = function execute(renderer) {
10742
- renderer.clear(this.clearAction);
10743
- renderer.renderMeshes(this.meshes);
10744
- renderer.clear(this.storeAction);
10535
+ // OVERRIDE
10745
10536
  };
10746
10537
  /**
10747
- * 每帧所有的pass渲染完后调用,通常用于清空临时的RT资源
10748
- */ _proto.frameCleanup = function frameCleanup(renderer) {};
10749
- _proto._resetAttachments = function _resetAttachments() {
10750
- var _this = this;
10751
- var _options_attachments;
10752
- var renderer = this.renderer;
10753
- var options = this.options;
10754
- if (this.attachments.length) {
10755
- var _this_framebuffer;
10756
- this.attachments.forEach(function(att) {
10757
- return !att.externalTexture && att.dispose();
10758
- });
10759
- this.attachments.length = 0;
10760
- (_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.dispose({
10761
- depthStencilAttachment: 2
10762
- });
10763
- this.framebuffer = null;
10764
- }
10765
- // renderpass 的 viewport 相关参数都需要动态的修改
10766
- var viewport = [
10767
- 0,
10768
- 0,
10769
- renderer.getWidth(),
10770
- renderer.getHeight()
10771
- ];
10772
- var size = [
10773
- viewport[2],
10774
- viewport[3]
10775
- ];
10776
- var name = this.name;
10777
- if ((_options_attachments = options.attachments) == null ? void 0 : _options_attachments.length) {
10778
- var attachments = options.attachments.map(function(attr, index) {
10779
- var _attr_texture;
10780
- var attachment = new RenderTargetHandle(_this.renderer.engine, _extends({
10781
- size: size,
10782
- name: ((_attr_texture = attr.texture) == null ? void 0 : _attr_texture.name) || name + "##color_" + index
10783
- }, attr));
10784
- return attachment;
10785
- });
10786
- this.attachments = attachments;
10787
- var framebuffer = Framebuffer.create({
10788
- storeAction: this.storeAction,
10789
- name: name,
10790
- viewport: viewport,
10791
- attachments: attachments.map(function(att) {
10792
- return att.texture;
10793
- }),
10794
- depthStencilAttachment: options.depthStencilAttachment || {
10795
- storageType: 0
10796
- }
10797
- }, renderer);
10798
- framebuffer.bind();
10799
- framebuffer.unbind();
10800
- this.framebuffer = framebuffer;
10801
- } else {
10802
- this.attachments.length = 0;
10803
- }
10538
+ * 每帧所有的pass渲染完后调用,用于清空临时的RT资源
10539
+ */ _proto.onCameraCleanup = function onCameraCleanup(renderer) {
10540
+ // OVERRIDE
10804
10541
  };
10805
10542
  /**
10806
10543
  * 获取当前视口大小,格式:[x偏移,y偏移,宽度,高度]
10807
10544
  */ _proto.getViewport = function getViewport() {
10808
10545
  var _this_framebuffer;
10809
- var ret = ((_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.viewport) || this.customViewport;
10546
+ var ret = (_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.viewport;
10810
10547
  if (ret) {
10811
10548
  return ret;
10812
10549
  }
@@ -10824,72 +10561,10 @@ var seed$7 = 1;
10824
10561
  ];
10825
10562
  };
10826
10563
  /**
10827
- * 获取深度 Attachment,可能没有
10828
- */ _proto.getDepthAttachment = function getDepthAttachment() {
10829
- var framebuffer = this.framebuffer;
10830
- if (framebuffer) {
10831
- var depthTexture = framebuffer.getDepthTexture();
10832
- var texture = depthTexture ? this.getDepthTexture(depthTexture, framebuffer.externalStorage) : undefined;
10833
- return {
10834
- storageType: framebuffer.depthStencilStorageType,
10835
- storage: framebuffer.depthStorage,
10836
- texture: texture
10837
- };
10838
- }
10839
- };
10840
- /**
10841
- * 获取蒙版 Attachment,可能没有
10842
- */ _proto.getStencilAttachment = function getStencilAttachment() {
10843
- var framebuffer = this.framebuffer;
10844
- if (framebuffer) {
10845
- var stencilTexture = framebuffer.getStencilTexture();
10846
- var texture = stencilTexture ? this.getDepthTexture(stencilTexture, framebuffer.externalStorage) : undefined;
10847
- return {
10848
- storageType: framebuffer.depthStencilStorageType,
10849
- storage: framebuffer.stencilStorage,
10850
- texture: texture
10851
- };
10852
- }
10853
- };
10854
- _proto.getDepthTexture = function getDepthTexture(texture, external) {
10855
- if (!this.depthTexture) {
10856
- var _this_options_depthStencilAttachment;
10857
- var outTex = (_this_options_depthStencilAttachment = this.options.depthStencilAttachment) == null ? void 0 : _this_options_depthStencilAttachment.texture;
10858
- var tex = texture === outTex ? outTex : texture;
10859
- // TODO 为什么要initialize?
10860
- //tex.initialize(this.renderer.engine);
10861
- if (!external) {
10862
- this.depthTexture = tex;
10863
- }
10864
- return tex;
10865
- }
10866
- return this.depthTexture;
10867
- };
10868
- _proto.getStencilTexture = function getStencilTexture(texture, external) {
10869
- if (!this.stencilTexture) {
10870
- var _this_options_depthStencilAttachment;
10871
- var outTex = (_this_options_depthStencilAttachment = this.options.depthStencilAttachment) == null ? void 0 : _this_options_depthStencilAttachment.texture;
10872
- var tex = texture === outTex ? outTex : texture;
10873
- if (!external) {
10874
- this.stencilTexture = tex;
10875
- }
10876
- return tex;
10877
- }
10878
- return this.stencilTexture;
10879
- };
10880
- // 生成并初始化帧缓冲
10881
- _proto.initialize = function initialize(renderer) {
10882
- if (!this.initialized) {
10883
- this._resetAttachments();
10884
- this.initialized = true;
10885
- }
10886
- return this;
10887
- };
10888
- /**
10889
10564
  * 销毁 RenderPass
10890
10565
  * @param options - 有选择销毁内部对象
10891
10566
  */ _proto.dispose = function dispose(options) {
10892
- if (this.destroyed) {
10567
+ if (this.disposed) {
10893
10568
  return;
10894
10569
  }
10895
10570
  var destroyMeshOption = (options == null ? void 0 : options.meshes) || undefined;
@@ -10899,40 +10574,13 @@ var seed$7 = 1;
10899
10574
  });
10900
10575
  }
10901
10576
  this.meshes.length = 0;
10902
- var colorOpt = (options == null ? void 0 : options.colorAttachment) ? options.colorAttachment : 0;
10903
- this.attachments.forEach(function(att) {
10904
- var keep = att.externalTexture && colorOpt === 2 || colorOpt === 1;
10905
- if (!keep) {
10906
- att.dispose();
10907
- }
10908
- });
10909
- this.attachments.length = 0;
10910
- if ((options == null ? void 0 : options.semantics) !== exports.DestroyOptions.keep) {
10911
- this.semantics.dispose();
10912
- }
10913
- this.destroyed = true;
10914
- var depthStencilOpt = (options == null ? void 0 : options.depthStencilAttachment) ? options.depthStencilAttachment : 0;
10915
- var fbo = this.framebuffer;
10916
- if (fbo) {
10917
- fbo.dispose({
10918
- depthStencilAttachment: depthStencilOpt
10919
- });
10920
- var keep = fbo.externalStorage && depthStencilOpt === 2 || depthStencilOpt === 1;
10921
- if (!keep) {
10922
- var _this_stencilTexture, _this_depthTexture;
10923
- (_this_stencilTexture = this.stencilTexture) == null ? void 0 : _this_stencilTexture.dispose();
10924
- (_this_depthTexture = this.depthTexture) == null ? void 0 : _this_depthTexture.dispose();
10925
- }
10926
- }
10927
- // @ts-expect-error safe to assign
10928
- this.options = null;
10929
- this.initialize = throwDestroyedError;
10577
+ this.disposed = true;
10930
10578
  };
10931
10579
  _create_class(RenderPass, [
10932
10580
  {
10933
- key: "isDestroyed",
10581
+ key: "isDisposed",
10934
10582
  get: function get() {
10935
- return this.destroyed;
10583
+ return this.disposed;
10936
10584
  }
10937
10585
  },
10938
10586
  {
@@ -10940,18 +10588,6 @@ var seed$7 = 1;
10940
10588
  get: function get() {
10941
10589
  return this.getViewport();
10942
10590
  }
10943
- },
10944
- {
10945
- key: "stencilAttachment",
10946
- get: function get() {
10947
- return this.getStencilAttachment();
10948
- }
10949
- },
10950
- {
10951
- key: "depthAttachment",
10952
- get: function get() {
10953
- return this.getDepthAttachment();
10954
- }
10955
10591
  }
10956
10592
  ]);
10957
10593
  return RenderPass;
@@ -10959,27 +10595,95 @@ var seed$7 = 1;
10959
10595
 
10960
10596
  var DrawObjectPass = /*#__PURE__*/ function(RenderPass) {
10961
10597
  _inherits(DrawObjectPass, RenderPass);
10962
- function DrawObjectPass(renderer, options) {
10598
+ function DrawObjectPass(renderer) {
10963
10599
  var _this;
10964
- _this = RenderPass.call(this, renderer, options) || this;
10965
- _this.onResize = _this.onResize.bind(_assert_this_initialized(_this));
10966
- _this.renderer.engine.on("resize", _this.onResize);
10600
+ _this = RenderPass.call(this, renderer) || this;
10601
+ _this.useRenderTarget = false;
10602
+ _this.priority = RenderPassPriorityNormal;
10603
+ _this.name = "DrawObjectPass";
10967
10604
  return _this;
10968
10605
  }
10969
10606
  var _proto = DrawObjectPass.prototype;
10970
- _proto.onResize = function onResize() {
10971
- var _this_framebuffer;
10972
- var width = this.renderer.getWidth();
10973
- var height = this.renderer.getHeight();
10974
- (_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.resize(0, 0, width, height);
10607
+ _proto.setup = function setup(useRenderTarget) {
10608
+ this.useRenderTarget = useRenderTarget;
10975
10609
  };
10976
- _proto.dispose = function dispose(options) {
10977
- this.renderer.engine.off("resize", this.onResize);
10978
- RenderPass.prototype.dispose.call(this, options);
10610
+ _proto.configure = function configure(renderer) {
10611
+ if (this.useRenderTarget) {
10612
+ this.framebuffer = renderer.getTemporaryRT("DrawObjectPass", renderer.getWidth(), renderer.getHeight(), 16, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
10613
+ renderer.setFramebuffer(this.framebuffer);
10614
+ }
10615
+ };
10616
+ _proto.execute = function execute(renderer) {
10617
+ if (this.useRenderTarget) {
10618
+ renderer.clear({
10619
+ colorAction: exports.TextureLoadAction.clear,
10620
+ depthAction: exports.TextureLoadAction.clear,
10621
+ stencilAction: exports.TextureLoadAction.clear
10622
+ });
10623
+ }
10624
+ renderer.renderMeshes(this.meshes);
10625
+ };
10626
+ _proto.onCameraCleanup = function onCameraCleanup(renderer) {
10627
+ if (this.useRenderTarget && this.framebuffer) {
10628
+ renderer.releaseTemporaryRT(this.framebuffer);
10629
+ }
10979
10630
  };
10980
10631
  return DrawObjectPass;
10981
10632
  }(RenderPass);
10982
10633
 
10634
+ exports.ShaderCompileResultStatus = void 0;
10635
+ (function(ShaderCompileResultStatus) {
10636
+ ShaderCompileResultStatus[ShaderCompileResultStatus["noShader"] = 0] = "noShader";
10637
+ ShaderCompileResultStatus[ShaderCompileResultStatus["success"] = 1] = "success";
10638
+ ShaderCompileResultStatus[ShaderCompileResultStatus["fail"] = 2] = "fail";
10639
+ ShaderCompileResultStatus[ShaderCompileResultStatus["compiling"] = 3] = "compiling";
10640
+ })(exports.ShaderCompileResultStatus || (exports.ShaderCompileResultStatus = {}));
10641
+ exports.GLSLVersion = void 0;
10642
+ (function(GLSLVersion) {
10643
+ GLSLVersion["GLSL1"] = "100";
10644
+ GLSLVersion["GLSL3"] = "300 es";
10645
+ })(exports.GLSLVersion || (exports.GLSLVersion = {}));
10646
+ var ShaderVariant = /*#__PURE__*/ function(EffectsObject) {
10647
+ _inherits(ShaderVariant, EffectsObject);
10648
+ function ShaderVariant(engine, source) {
10649
+ var _this;
10650
+ _this = EffectsObject.call(this, engine) || this;
10651
+ _this.source = source;
10652
+ return _this;
10653
+ }
10654
+ return ShaderVariant;
10655
+ }(EffectsObject);
10656
+ exports.Shader = /*#__PURE__*/ function(EffectsObject) {
10657
+ _inherits(Shader, EffectsObject);
10658
+ function Shader() {
10659
+ return EffectsObject.apply(this, arguments);
10660
+ }
10661
+ var _proto = Shader.prototype;
10662
+ _proto.createVariant = function createVariant(macros) {
10663
+ var shaderMacros = [];
10664
+ if (macros) {
10665
+ for(var _iterator = _create_for_of_iterator_helper_loose(Object.keys(macros)), _step; !(_step = _iterator()).done;){
10666
+ var key = _step.value;
10667
+ shaderMacros.push([
10668
+ key,
10669
+ macros[key]
10670
+ ]);
10671
+ }
10672
+ }
10673
+ var shaderVariant = this.engine.getShaderLibrary().createShader(this.shaderData, shaderMacros);
10674
+ shaderVariant.shader = this;
10675
+ return shaderVariant;
10676
+ };
10677
+ _proto.fromData = function fromData(data) {
10678
+ EffectsObject.prototype.fromData.call(this, data);
10679
+ this.shaderData = data;
10680
+ };
10681
+ return Shader;
10682
+ }(EffectsObject);
10683
+ exports.Shader = __decorate([
10684
+ effectsClass(DataType.Shader)
10685
+ ], exports.Shader);
10686
+
10983
10687
  var _obj$5;
10984
10688
  var BYTES_TYPE_MAP = (_obj$5 = {}, _obj$5[glContext.FLOAT] = Float32Array.BYTES_PER_ELEMENT, _obj$5[glContext.INT] = Int32Array.BYTES_PER_ELEMENT, _obj$5[glContext.SHORT] = Int16Array.BYTES_PER_ELEMENT, _obj$5[glContext.BYTE] = Int8Array.BYTES_PER_ELEMENT, _obj$5);
10985
10689
  /**
@@ -13021,9 +12725,9 @@ var ShaderFactory = /*#__PURE__*/ function() {
13021
12725
  // Bloom 阈值 Pass
13022
12726
  var BloomThresholdPass = /*#__PURE__*/ function(RenderPass) {
13023
12727
  _inherits(BloomThresholdPass, RenderPass);
13024
- function BloomThresholdPass(renderer, option) {
12728
+ function BloomThresholdPass(renderer) {
13025
12729
  var _this;
13026
- _this = RenderPass.call(this, renderer, option) || this;
12730
+ _this = RenderPass.call(this, renderer) || this;
13027
12731
  var engine = _this.renderer.engine;
13028
12732
  var geometry = Geometry.create(engine, {
13029
12733
  mode: glContext.TRIANGLE_STRIP,
@@ -13061,12 +12765,12 @@ var BloomThresholdPass = /*#__PURE__*/ function(RenderPass) {
13061
12765
  priority: 0
13062
12766
  });
13063
12767
  _this.priority = 5000;
13064
- _this.onResize = _this.onResize.bind(_assert_this_initialized(_this));
13065
- _this.renderer.engine.on("resize", _this.onResize);
12768
+ _this.name = "BloomThresholdPass";
13066
12769
  return _this;
13067
12770
  }
13068
12771
  var _proto = BloomThresholdPass.prototype;
13069
12772
  _proto.configure = function configure(renderer) {
12773
+ this.framebuffer = renderer.getTemporaryRT(this.name, renderer.getWidth(), renderer.getHeight(), 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
13070
12774
  this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
13071
12775
  this.sceneTextureHandle.texture = this.mainTexture;
13072
12776
  renderer.setFramebuffer(this.framebuffer);
@@ -13074,9 +12778,9 @@ var BloomThresholdPass = /*#__PURE__*/ function(RenderPass) {
13074
12778
  _proto.execute = function execute(renderer) {
13075
12779
  var _renderer_renderingData_currentFrame_globalVolume_bloom, _renderer_renderingData_currentFrame_globalVolume;
13076
12780
  renderer.clear({
13077
- colorAction: exports.TextureStoreAction.clear,
13078
- depthAction: exports.TextureStoreAction.clear,
13079
- stencilAction: exports.TextureStoreAction.clear
12781
+ colorAction: exports.TextureLoadAction.clear,
12782
+ depthAction: exports.TextureLoadAction.clear,
12783
+ stencilAction: exports.TextureLoadAction.clear
13080
12784
  });
13081
12785
  this.screenMesh.material.setTexture("_MainTex", this.mainTexture);
13082
12786
  var _renderer_renderingData_currentFrame_globalVolume_bloom_threshold;
@@ -13086,23 +12790,21 @@ var BloomThresholdPass = /*#__PURE__*/ function(RenderPass) {
13086
12790
  this.screenMesh
13087
12791
  ]);
13088
12792
  };
13089
- _proto.onResize = function onResize() {
13090
- var _this_framebuffer;
13091
- var width = this.renderer.getWidth();
13092
- var height = this.renderer.getHeight();
13093
- (_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.resize(0, 0, width, height);
12793
+ _proto.onCameraCleanup = function onCameraCleanup(renderer) {
12794
+ if (this.framebuffer) {
12795
+ renderer.releaseTemporaryRT(this.framebuffer);
12796
+ }
13094
12797
  };
13095
12798
  _proto.dispose = function dispose(options) {
13096
- this.renderer.engine.off("resize", this.onResize);
13097
12799
  RenderPass.prototype.dispose.call(this, options);
13098
12800
  };
13099
12801
  return BloomThresholdPass;
13100
12802
  }(RenderPass);
13101
12803
  var HQGaussianDownSamplePass = /*#__PURE__*/ function(RenderPass) {
13102
12804
  _inherits(HQGaussianDownSamplePass, RenderPass);
13103
- function HQGaussianDownSamplePass(renderer, type, level, options) {
12805
+ function HQGaussianDownSamplePass(renderer, type, level) {
13104
12806
  var _this;
13105
- _this = RenderPass.call(this, renderer, options) || this;
12807
+ _this = RenderPass.call(this, renderer) || this;
13106
12808
  _this.type = type;
13107
12809
  _this.level = level;
13108
12810
  var engine = _this.renderer.engine;
@@ -13148,25 +12850,22 @@ var HQGaussianDownSamplePass = /*#__PURE__*/ function(RenderPass) {
13148
12850
  priority: 0
13149
12851
  });
13150
12852
  _this.priority = 5000;
13151
- _this.onResize = _this.onResize.bind(_assert_this_initialized(_this));
13152
- _this.renderer.engine.on("resize", _this.onResize);
12853
+ _this.name = "GaussianDownPass" + type + level;
13153
12854
  return _this;
13154
12855
  }
13155
12856
  var _proto = HQGaussianDownSamplePass.prototype;
13156
- _proto.initialize = function initialize(renderer) {
13157
- RenderPass.prototype.initialize.call(this, renderer);
13158
- this.onResize();
13159
- return this;
13160
- };
13161
12857
  _proto.configure = function configure(renderer) {
12858
+ var width = Math.floor(this.renderer.getWidth() / Math.pow(2, this.level + 1));
12859
+ var height = Math.floor(this.renderer.getHeight() / Math.pow(2, this.level + 1));
12860
+ this.framebuffer = renderer.getTemporaryRT(this.name, width, height, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
13162
12861
  this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
13163
12862
  renderer.setFramebuffer(this.framebuffer);
13164
12863
  };
13165
12864
  _proto.execute = function execute(renderer) {
13166
12865
  renderer.clear({
13167
- colorAction: exports.TextureStoreAction.clear,
13168
- depthAction: exports.TextureStoreAction.clear,
13169
- stencilAction: exports.TextureStoreAction.clear
12866
+ colorAction: exports.TextureLoadAction.clear,
12867
+ depthAction: exports.TextureLoadAction.clear,
12868
+ stencilAction: exports.TextureLoadAction.clear
13170
12869
  });
13171
12870
  this.screenMesh.material.setTexture("_MainTex", this.mainTexture);
13172
12871
  this.screenMesh.material.setVector2("_TextureSize", getTextureSize(this.mainTexture));
@@ -13177,23 +12876,18 @@ var HQGaussianDownSamplePass = /*#__PURE__*/ function(RenderPass) {
13177
12876
  this.gaussianResult.texture = renderer.getFramebuffer().getColorTextures()[0];
13178
12877
  }
13179
12878
  };
13180
- _proto.onResize = function onResize() {
13181
- var _this_framebuffer;
13182
- var width = Math.floor(this.renderer.getWidth() / Math.pow(2, this.level + 1));
13183
- var height = Math.floor(this.renderer.getHeight() / Math.pow(2, this.level + 1));
13184
- (_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.resize(0, 0, width, height);
13185
- };
13186
- _proto.dispose = function dispose(options) {
13187
- this.renderer.engine.off("resize", this.onResize);
13188
- RenderPass.prototype.dispose.call(this, options);
12879
+ _proto.onCameraCleanup = function onCameraCleanup(renderer) {
12880
+ if (this.framebuffer) {
12881
+ renderer.releaseTemporaryRT(this.framebuffer);
12882
+ }
13189
12883
  };
13190
12884
  return HQGaussianDownSamplePass;
13191
12885
  }(RenderPass);
13192
12886
  var HQGaussianUpSamplePass = /*#__PURE__*/ function(RenderPass) {
13193
12887
  _inherits(HQGaussianUpSamplePass, RenderPass);
13194
- function HQGaussianUpSamplePass(renderer, level, options) {
12888
+ function HQGaussianUpSamplePass(renderer, level) {
13195
12889
  var _this;
13196
- _this = RenderPass.call(this, renderer, options) || this;
12890
+ _this = RenderPass.call(this, renderer) || this;
13197
12891
  _this.level = level;
13198
12892
  var name = "PostProcess";
13199
12893
  var engine = _this.renderer.engine;
@@ -13236,25 +12930,22 @@ var HQGaussianUpSamplePass = /*#__PURE__*/ function(RenderPass) {
13236
12930
  priority: 0
13237
12931
  });
13238
12932
  _this.priority = 5000;
13239
- _this.onResize = _this.onResize.bind(_assert_this_initialized(_this));
13240
- _this.renderer.engine.on("resize", _this.onResize);
12933
+ _this.name = "GaussianUpPass" + level;
13241
12934
  return _this;
13242
12935
  }
13243
12936
  var _proto = HQGaussianUpSamplePass.prototype;
13244
- _proto.initialize = function initialize(renderer) {
13245
- RenderPass.prototype.initialize.call(this, renderer);
13246
- this.onResize();
13247
- return this;
13248
- };
13249
12937
  _proto.configure = function configure(renderer) {
12938
+ var width = Math.floor(this.renderer.getWidth() / Math.pow(2, this.level - 1));
12939
+ var height = Math.floor(this.renderer.getHeight() / Math.pow(2, this.level - 1));
12940
+ this.framebuffer = renderer.getTemporaryRT(this.name, width, height, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
13250
12941
  this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
13251
12942
  renderer.setFramebuffer(this.framebuffer);
13252
12943
  };
13253
12944
  _proto.execute = function execute(renderer) {
13254
12945
  renderer.clear({
13255
- colorAction: exports.TextureStoreAction.clear,
13256
- depthAction: exports.TextureStoreAction.clear,
13257
- stencilAction: exports.TextureStoreAction.clear
12946
+ colorAction: exports.TextureLoadAction.clear,
12947
+ depthAction: exports.TextureLoadAction.clear,
12948
+ stencilAction: exports.TextureLoadAction.clear
13258
12949
  });
13259
12950
  this.screenMesh.material.setTexture("_MainTex", this.mainTexture);
13260
12951
  this.screenMesh.material.setTexture("_GaussianDownTex", this.gaussianDownSampleResult.texture);
@@ -13263,15 +12954,10 @@ var HQGaussianUpSamplePass = /*#__PURE__*/ function(RenderPass) {
13263
12954
  this.screenMesh
13264
12955
  ]);
13265
12956
  };
13266
- _proto.onResize = function onResize() {
13267
- var _this_framebuffer;
13268
- var width = Math.floor(this.renderer.getWidth() / Math.pow(2, this.level - 1));
13269
- var height = Math.floor(this.renderer.getHeight() / Math.pow(2, this.level - 1));
13270
- (_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.resize(0, 0, width, height);
13271
- };
13272
- _proto.dispose = function dispose(options) {
13273
- this.renderer.engine.off("resize", this.onResize);
13274
- RenderPass.prototype.dispose.call(this, options);
12957
+ _proto.onCameraCleanup = function onCameraCleanup(renderer) {
12958
+ if (this.framebuffer) {
12959
+ renderer.releaseTemporaryRT(this.framebuffer);
12960
+ }
13275
12961
  };
13276
12962
  return HQGaussianUpSamplePass;
13277
12963
  }(RenderPass);
@@ -13280,7 +12966,7 @@ var ToneMappingPass = /*#__PURE__*/ function(RenderPass) {
13280
12966
  _inherits(ToneMappingPass, RenderPass);
13281
12967
  function ToneMappingPass(renderer, sceneTextureHandle) {
13282
12968
  var _this;
13283
- _this = RenderPass.call(this, renderer, {}) || this;
12969
+ _this = RenderPass.call(this, renderer) || this;
13284
12970
  var name = "PostProcess";
13285
12971
  var engine = _this.renderer.engine;
13286
12972
  _this.sceneTextureHandle = sceneTextureHandle ? sceneTextureHandle : new RenderTargetHandle(engine);
@@ -13323,6 +13009,7 @@ var ToneMappingPass = /*#__PURE__*/ function(RenderPass) {
13323
13009
  priority: 0
13324
13010
  });
13325
13011
  _this.priority = 5000;
13012
+ _this.name = "ToneMappingPass";
13326
13013
  return _this;
13327
13014
  }
13328
13015
  var _proto = ToneMappingPass.prototype;
@@ -13335,9 +13022,9 @@ var ToneMappingPass = /*#__PURE__*/ function(RenderPass) {
13335
13022
  };
13336
13023
  _proto.execute = function execute(renderer) {
13337
13024
  renderer.clear({
13338
- colorAction: exports.TextureStoreAction.clear,
13339
- depthAction: exports.TextureStoreAction.clear,
13340
- stencilAction: exports.TextureStoreAction.clear
13025
+ colorAction: exports.TextureLoadAction.clear,
13026
+ depthAction: exports.TextureLoadAction.clear,
13027
+ stencilAction: exports.TextureLoadAction.clear
13341
13028
  });
13342
13029
  var globalVolume = renderer.renderingData.currentFrame.globalVolume;
13343
13030
  var bloom = _extends({
@@ -13384,70 +13071,31 @@ var ToneMappingPass = /*#__PURE__*/ function(RenderPass) {
13384
13071
  return ToneMappingPass;
13385
13072
  }(RenderPass);
13386
13073
 
13387
- var RENDER_PASS_NAME_PREFIX = "_effects_default_";
13388
13074
  var seed$5 = 1;
13389
13075
  /**
13390
13076
  * RenderFrame 抽象类
13391
13077
  */ var RenderFrame = /*#__PURE__*/ function() {
13392
13078
  function RenderFrame(options) {
13393
- var _this_renderer_getShaderLibrary;
13394
- // TODO: 是否有用
13395
- this.renderQueue = [];
13396
- this.destroyed = false;
13397
- this.renderPassInfoMap = new WeakMap();
13398
- var camera = options.camera, keepColorBuffer = options.keepColorBuffer, renderer = options.renderer, _options_editorTransform = options.editorTransform, editorTransform = _options_editorTransform === void 0 ? [
13079
+ this.disposed = false;
13080
+ this.postProcessingEnabled = false;
13081
+ this.enableHDR = true;
13082
+ var camera = options.camera, renderer = options.renderer, _options_editorTransform = options.editorTransform, editorTransform = _options_editorTransform === void 0 ? [
13399
13083
  1,
13400
13084
  1,
13401
13085
  0,
13402
13086
  0
13403
- ] : _options_editorTransform, globalVolume = options.globalVolume, _options_postProcessingEnabled = options.postProcessingEnabled, postProcessingEnabled = _options_postProcessingEnabled === void 0 ? false : _options_postProcessingEnabled, _options_clearAction = options.clearAction, clearAction = _options_clearAction === void 0 ? {
13404
- colorAction: exports.TextureLoadAction.whatever,
13405
- stencilAction: exports.TextureLoadAction.clear,
13406
- depthAction: exports.TextureLoadAction.whatever
13407
- } : _options_clearAction;
13087
+ ] : _options_editorTransform, globalVolume = options.globalVolume, _options_postProcessingEnabled = options.postProcessingEnabled, postProcessingEnabled = _options_postProcessingEnabled === void 0 ? false : _options_postProcessingEnabled;
13408
13088
  var engine = renderer.engine;
13409
13089
  if (globalVolume) {
13410
13090
  this.globalVolume = globalVolume;
13411
13091
  }
13092
+ this.postProcessingEnabled = postProcessingEnabled;
13412
13093
  this.globalUniforms = new GlobalUniforms();
13413
- var attachments = []; //渲染场景物体Pass的RT
13414
- var depthStencilAttachment;
13415
- var drawObjectPassClearAction = {};
13416
13094
  this.renderer = renderer;
13417
- if (postProcessingEnabled) {
13418
- var enableHDR = true;
13419
- if (!this.renderer.engine.gpuCapability.detail.halfFloatTexture) {
13420
- throw new Error("Half float texture is not supported.");
13421
- }
13422
- // 使用HDR浮点纹理,FLOAT在IOS上报错,使用HALF_FLOAT
13423
- var textureType = enableHDR ? glContext.HALF_FLOAT : glContext.UNSIGNED_BYTE;
13424
- attachments = [
13425
- {
13426
- texture: {
13427
- format: glContext.RGBA,
13428
- type: textureType,
13429
- magFilter: glContext.LINEAR,
13430
- minFilter: glContext.LINEAR
13431
- }
13432
- }
13433
- ];
13434
- depthStencilAttachment = {
13435
- storageType: exports.RenderPassAttachmentStorageType.depth_stencil_opaque
13436
- };
13437
- drawObjectPassClearAction = {
13438
- colorAction: exports.TextureLoadAction.clear,
13439
- stencilAction: exports.TextureLoadAction.clear,
13440
- depthAction: exports.TextureLoadAction.clear
13441
- };
13095
+ if (postProcessingEnabled && this.enableHDR && !this.renderer.engine.gpuCapability.detail.halfFloatTexture) {
13096
+ throw new Error("Half float texture is not supported.");
13442
13097
  }
13443
- this.drawObjectPass = new DrawObjectPass(renderer, {
13444
- name: RENDER_PASS_NAME_PREFIX,
13445
- priority: RenderPassPriorityNormal,
13446
- meshOrder: exports.OrderType.ascending,
13447
- depthStencilAttachment: depthStencilAttachment,
13448
- attachments: attachments,
13449
- clearAction: drawObjectPassClearAction
13450
- });
13098
+ this.drawObjectPass = new DrawObjectPass(renderer);
13451
13099
  var renderPasses = [
13452
13100
  this.drawObjectPass
13453
13101
  ];
@@ -13462,51 +13110,13 @@ var seed$5 = 1;
13462
13110
  this.renderer.getHeight() / 2
13463
13111
  ];
13464
13112
  var gaussianDownResults = new Array(gaussianStep); //存放多个高斯Pass的模糊结果,用于Bloom
13465
- var enableHDR1 = true;
13466
- var textureType1 = enableHDR1 ? glContext.HALF_FLOAT : glContext.UNSIGNED_BYTE;
13467
- var bloomThresholdPass = new BloomThresholdPass(renderer, {
13468
- name: "BloomThresholdPass",
13469
- attachments: [
13470
- {
13471
- texture: {
13472
- format: glContext.RGBA,
13473
- type: textureType1,
13474
- minFilter: glContext.LINEAR,
13475
- magFilter: glContext.LINEAR
13476
- }
13477
- }
13478
- ]
13479
- });
13113
+ var bloomThresholdPass = new BloomThresholdPass(renderer);
13480
13114
  bloomThresholdPass.sceneTextureHandle = sceneTextureHandle;
13481
13115
  this.addRenderPass(bloomThresholdPass);
13482
13116
  for(var i = 0; i < gaussianStep; i++){
13483
13117
  gaussianDownResults[i] = new RenderTargetHandle(engine);
13484
- var gaussianDownHPass = new HQGaussianDownSamplePass(renderer, "H", i, {
13485
- name: "GaussianDownPassH" + i,
13486
- attachments: [
13487
- {
13488
- texture: {
13489
- format: glContext.RGBA,
13490
- type: textureType1,
13491
- minFilter: glContext.LINEAR,
13492
- magFilter: glContext.LINEAR
13493
- }
13494
- }
13495
- ]
13496
- });
13497
- var gaussianDownVPass = new HQGaussianDownSamplePass(renderer, "V", i, {
13498
- name: "GaussianDownPassV" + i,
13499
- attachments: [
13500
- {
13501
- texture: {
13502
- format: glContext.RGBA,
13503
- type: textureType1,
13504
- minFilter: glContext.LINEAR,
13505
- magFilter: glContext.LINEAR
13506
- }
13507
- }
13508
- ]
13509
- });
13118
+ var gaussianDownHPass = new HQGaussianDownSamplePass(renderer, "H", i);
13119
+ var gaussianDownVPass = new HQGaussianDownSamplePass(renderer, "V", i);
13510
13120
  gaussianDownVPass.gaussianResult = gaussianDownResults[i];
13511
13121
  this.addRenderPass(gaussianDownHPass);
13512
13122
  this.addRenderPass(gaussianDownVPass);
@@ -13517,19 +13127,7 @@ var seed$5 = 1;
13517
13127
  viewport[2] *= 4;
13518
13128
  viewport[3] *= 4;
13519
13129
  for(var i1 = 0; i1 < gaussianStep - 1; i1++){
13520
- var gaussianUpPass = new HQGaussianUpSamplePass(renderer, gaussianStep - i1, {
13521
- name: "GaussianUpPass" + i1,
13522
- attachments: [
13523
- {
13524
- texture: {
13525
- format: glContext.RGBA,
13526
- type: textureType1,
13527
- minFilter: glContext.LINEAR,
13528
- magFilter: glContext.LINEAR
13529
- }
13530
- }
13531
- ]
13532
- });
13130
+ var gaussianUpPass = new HQGaussianUpSamplePass(renderer, gaussianStep - i1);
13533
13131
  gaussianUpPass.gaussianDownSampleResult = gaussianDownResults[gaussianStep - 2 - i1];
13534
13132
  this.addRenderPass(gaussianUpPass);
13535
13133
  viewport[2] *= 2;
@@ -13538,31 +13136,17 @@ var seed$5 = 1;
13538
13136
  var postProcessPass = new ToneMappingPass(renderer, sceneTextureHandle);
13539
13137
  this.addRenderPass(postProcessPass);
13540
13138
  }
13541
- this.semantics = new SemanticMap(options.semantics);
13542
- this.clearAction = clearAction;
13543
13139
  this.name = "RenderFrame" + seed$5++;
13544
- var firstRP = renderPasses[0];
13545
13140
  this.camera = camera;
13546
- this.keepColorBuffer = keepColorBuffer;
13547
- this.renderPassInfoMap.set(firstRP, {
13548
- listStart: 0,
13549
- listEnd: 0,
13550
- renderPass: firstRP,
13551
- intermedia: false
13552
- });
13553
13141
  this.editorTransform = Vector4.fromArray(editorTransform);
13554
- if (!options.clearAction) {
13555
- this.resetClearActions();
13556
- }
13557
- this.passTextureCache = new PassTextureCache(engine);
13558
- // FIXME: addShader是为了性能考虑,如果影响不大,下面代码可以删除
13559
- var _engine_gpuCapability = engine.gpuCapability, detail = _engine_gpuCapability.detail, level = _engine_gpuCapability.level;
13560
- var writeDepth = detail.readableDepthStencilTextures && detail.writableFragDepth;
13561
- var shader = createCopyShader(level, writeDepth);
13562
- (_this_renderer_getShaderLibrary = this.renderer.getShaderLibrary()) == null ? void 0 : _this_renderer_getShaderLibrary.addShader(shader);
13563
13142
  }
13564
13143
  var _proto = RenderFrame.prototype;
13565
13144
  /**
13145
+ * 设置 RenderPasses 参数,此函数每帧调用一次
13146
+ */ _proto.setup = function setup() {
13147
+ this.drawObjectPass.setup(this.postProcessingEnabled);
13148
+ };
13149
+ /**
13566
13150
  * 根据 Mesh 优先级添加到 RenderPass
13567
13151
  * @param mesh - 要添加的 Mesh 对象
13568
13152
  */ _proto.addMeshToDefaultRenderPass = function addMeshToDefaultRenderPass(mesh) {
@@ -13579,78 +13163,25 @@ var seed$5 = 1;
13579
13163
  * 销毁 RenderFrame
13580
13164
  * @param options - 可以有选择销毁一些对象
13581
13165
  */ _proto.dispose = function dispose(options) {
13582
- if ((options == null ? void 0 : options.semantics) !== exports.DestroyOptions.keep) {
13583
- this.semantics.dispose();
13584
- }
13585
13166
  var pass = (options == null ? void 0 : options.passes) ? options.passes : undefined;
13586
13167
  if (pass !== exports.DestroyOptions.keep) {
13587
13168
  this._renderPasses.forEach(function(renderPass) {
13588
13169
  renderPass.dispose(pass);
13589
13170
  });
13590
13171
  }
13591
- this.passTextureCache.dispose();
13592
13172
  this._renderPasses.length = 0;
13593
- this.destroyed = true;
13594
- };
13595
- /**
13596
- * 查找 Mesh 所在的 RenderPass 索引,没找到是-1
13597
- * @param mesh - 需要查找的 Mesh
13598
- */ _proto.findMeshRenderPassIndex = function findMeshRenderPassIndex(mesh) {
13599
- var index = -1;
13600
- this.renderPasses.every(function(rp, idx) {
13601
- if (rp.name.startsWith(RENDER_PASS_NAME_PREFIX) && rp.meshes.includes(mesh)) {
13602
- index = idx;
13603
- return false;
13604
- }
13605
- return true;
13606
- });
13607
- return index;
13608
- };
13609
- _proto.addToRenderPass = function addToRenderPass(renderPass, mesh) {
13610
- var info = this.renderPassInfoMap.get(renderPass);
13611
- var priority = mesh.priority;
13612
- if (!info) {
13613
- return;
13614
- }
13615
- if (renderPass.meshes.length === 0) {
13616
- info.listStart = info.listEnd = priority;
13617
- } else {
13618
- if (priority < info.listStart) {
13619
- info.listStart = priority;
13620
- } else if (priority > info.listEnd) {
13621
- info.listEnd = priority;
13622
- }
13623
- }
13624
- renderPass.addMesh(mesh);
13625
- };
13626
- _proto.resetClearActions = function resetClearActions() {
13627
- var action = this.renderPasses.length > 1 ? exports.TextureLoadAction.clear : exports.TextureLoadAction.whatever;
13628
- this.clearAction.stencilAction = action;
13629
- this.clearAction.depthAction = action;
13630
- this.clearAction.colorAction = action;
13631
- if (this.keepColorBuffer) {
13632
- this.clearAction.colorAction = exports.TextureLoadAction.whatever;
13633
- }
13173
+ this.disposed = true;
13634
13174
  };
13635
13175
  /**
13636
13176
  * 设置 RenderPass 数组,直接修改内部的 RenderPass 数组
13637
13177
  * @param passes - RenderPass 数组
13638
13178
  */ _proto.setRenderPasses = function setRenderPasses(passes) {
13639
- var _this = this;
13640
- if (this.renderer !== undefined) {
13641
- passes.forEach(function(pass) {
13642
- return pass.initialize(_this.renderer);
13643
- });
13644
- }
13645
13179
  this._renderPasses = passes.slice();
13646
13180
  };
13647
13181
  /**
13648
13182
  * 添加 RenderPass
13649
13183
  * @param pass - 需要添加的 RenderPass
13650
13184
  */ _proto.addRenderPass = function addRenderPass(pass) {
13651
- if (this.renderer !== undefined) {
13652
- pass.initialize(this.renderer);
13653
- }
13654
13185
  this._renderPasses.push(pass);
13655
13186
  };
13656
13187
  /**
@@ -13667,9 +13198,9 @@ var seed$5 = 1;
13667
13198
  }
13668
13199
  },
13669
13200
  {
13670
- key: "isDestroyed",
13201
+ key: "isDisposed",
13671
13202
  get: function get() {
13672
- return this.destroyed;
13203
+ return this.disposed;
13673
13204
  }
13674
13205
  }
13675
13206
  ]);
@@ -13678,10 +13209,6 @@ var seed$5 = 1;
13678
13209
  function getTextureSize(tex) {
13679
13210
  return tex ? new Vector2(tex.getWidth(), tex.getHeight()) : new Vector2();
13680
13211
  }
13681
- function findPreviousRenderPass(renderPasses, renderPass) {
13682
- var index = renderPasses.indexOf(renderPass);
13683
- return renderPasses[index - 1];
13684
- }
13685
13212
  var GlobalUniforms = function GlobalUniforms() {
13686
13213
  this.floats = {};
13687
13214
  this.ints = {};
@@ -13719,6 +13246,122 @@ var Renderbuffer = /*#__PURE__*/ function() {
13719
13246
  return Renderbuffer;
13720
13247
  }();
13721
13248
 
13249
+ var RenderTargetPool = /*#__PURE__*/ function() {
13250
+ function RenderTargetPool(engine) {
13251
+ this.engine = engine;
13252
+ this.temporaryRTs = [];
13253
+ this.currentFrame = 0;
13254
+ this.maxUnusedFrames = 4;
13255
+ }
13256
+ var _proto = RenderTargetPool.prototype;
13257
+ /**
13258
+ * 清理 RenderTarget 池
13259
+ * @param force - 是否强制清理所有未占用的 RT
13260
+ * @param framesOffset - 自定义未使用帧数阈值,-1 表示使用默认值
13261
+ */ _proto.flush = function flush(force, framesOffset) {
13262
+ if (force === void 0) force = false;
13263
+ if (framesOffset === void 0) framesOffset = -1;
13264
+ this.currentFrame++;
13265
+ var threshold = framesOffset >= 0 ? framesOffset : this.maxUnusedFrames;
13266
+ for(var i = 0; i < this.temporaryRTs.length; i++){
13267
+ var entry = this.temporaryRTs[i];
13268
+ // 强制清理所有未占用的 RT,或清理超过阈值帧数未使用的 RT
13269
+ if (!entry.isOccupied && (force || this.currentFrame - entry.lastFrameReleased > threshold)) {
13270
+ entry.RT.dispose();
13271
+ this.temporaryRTs.splice(i--, 1);
13272
+ }
13273
+ }
13274
+ };
13275
+ _proto.get = function get(name, width, height, depthBuffer, filter, format) {
13276
+ if (depthBuffer === void 0) depthBuffer = 0;
13277
+ if (filter === void 0) filter = exports.FilterMode.Linear;
13278
+ if (format === void 0) format = exports.RenderTextureFormat.RGBA32;
13279
+ // 使用参数计算 hash 值作为缓存 key
13280
+ var hash = width + "_" + height + "_" + depthBuffer + "_" + filter + "_" + format;
13281
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.temporaryRTs), _step; !(_step = _iterator()).done;){
13282
+ var entry = _step.value;
13283
+ if (!entry.isOccupied && entry.descriptionHash === hash) {
13284
+ entry.isOccupied = true;
13285
+ entry.RT.name = name;
13286
+ return entry.RT;
13287
+ }
13288
+ }
13289
+ var textureFilter;
13290
+ var textureType;
13291
+ var depthType = exports.RenderPassAttachmentStorageType.none;
13292
+ // TODO 建立Map映射
13293
+ if (filter === exports.FilterMode.Linear) {
13294
+ textureFilter = glContext.LINEAR;
13295
+ } else if (filter === exports.FilterMode.Nearest) {
13296
+ textureFilter = glContext.NEAREST;
13297
+ }
13298
+ if (format === exports.RenderTextureFormat.RGBA32) {
13299
+ textureType = glContext.UNSIGNED_BYTE;
13300
+ } else if (format === exports.RenderTextureFormat.RGBAHalf) {
13301
+ textureType = glContext.HALF_FLOAT;
13302
+ }
13303
+ if (depthBuffer === 0) {
13304
+ depthType = exports.RenderPassAttachmentStorageType.none;
13305
+ } else if (depthBuffer === 16) {
13306
+ depthType = exports.RenderPassAttachmentStorageType.depth_stencil_opaque;
13307
+ } else if (depthBuffer === 24) {
13308
+ depthType = exports.RenderPassAttachmentStorageType.depth_24_stencil_8_texture;
13309
+ }
13310
+ var colorAttachment = Texture.create(this.engine, {
13311
+ sourceType: exports.TextureSourceType.framebuffer,
13312
+ minFilter: textureFilter,
13313
+ magFilter: textureFilter,
13314
+ internalFormat: glContext.RGBA,
13315
+ format: glContext.RGBA,
13316
+ type: textureType
13317
+ });
13318
+ var newFramebuffer = Framebuffer.create({
13319
+ name: name,
13320
+ storeAction: {},
13321
+ viewport: [
13322
+ 0,
13323
+ 0,
13324
+ width,
13325
+ height
13326
+ ],
13327
+ attachments: [
13328
+ colorAttachment
13329
+ ],
13330
+ depthStencilAttachment: {
13331
+ storageType: depthType
13332
+ }
13333
+ }, this.engine.renderer);
13334
+ var entry1 = {
13335
+ RT: newFramebuffer,
13336
+ lastFrameReleased: 0,
13337
+ descriptionHash: hash,
13338
+ isOccupied: true
13339
+ };
13340
+ this.temporaryRTs.push(entry1);
13341
+ return entry1.RT;
13342
+ };
13343
+ /**
13344
+ * 释放 RenderTarget,使其可以被复用
13345
+ * @param rt - 要释放的 Framebuffer
13346
+ */ _proto.release = function release(rt) {
13347
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.temporaryRTs), _step; !(_step = _iterator()).done;){
13348
+ var entry = _step.value;
13349
+ if (entry.RT === rt) {
13350
+ entry.isOccupied = false;
13351
+ entry.lastFrameReleased = this.currentFrame;
13352
+ break;
13353
+ }
13354
+ }
13355
+ };
13356
+ _proto.dispose = function dispose() {
13357
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.temporaryRTs), _step; !(_step = _iterator()).done;){
13358
+ var entry = _step.value;
13359
+ entry.RT.dispose();
13360
+ }
13361
+ };
13362
+ return RenderTargetPool;
13363
+ }();
13364
+
13722
13365
  var isWebGL2Available = typeof WebGL2RenderingContext === "function";
13723
13366
  var GPUCapability = /*#__PURE__*/ function() {
13724
13367
  function GPUCapability(gl) {
@@ -13904,70 +13547,11 @@ exports.CompressTextureCapabilityType = void 0;
13904
13547
  return !!hasCompressedTextureSupport;
13905
13548
  }
13906
13549
 
13907
- exports.FilterMode = void 0;
13908
- (function(FilterMode) {
13909
- FilterMode[FilterMode["Nearest"] = 0] = "Nearest";
13910
- FilterMode[FilterMode["Linear"] = 1] = "Linear";
13911
- })(exports.FilterMode || (exports.FilterMode = {}));
13912
- exports.RenderTextureFormat = void 0;
13913
- (function(RenderTextureFormat) {
13914
- RenderTextureFormat[RenderTextureFormat["RGBA32"] = 0] = "RGBA32";
13915
- RenderTextureFormat[RenderTextureFormat["RGBAHalf"] = 1] = "RGBAHalf";
13916
- })(exports.RenderTextureFormat || (exports.RenderTextureFormat = {}));
13917
- /**
13918
- *
13919
- */ var Framebuffer = /*#__PURE__*/ function() {
13920
- function Framebuffer() {}
13921
- var _proto = Framebuffer.prototype;
13922
- _proto.resize = function resize(x, y, width, height) {
13923
- // OVERRIDE
13924
- };
13925
- _proto.resetColorTextures = function resetColorTextures(textures) {
13926
- // OVERRIDE
13927
- };
13928
- _proto.unbind = function unbind() {
13929
- // OVERRIDE
13930
- };
13931
- _proto.bind = function bind() {
13932
- // OVERRIDE
13933
- };
13934
- _proto.getDepthTexture = function getDepthTexture() {
13935
- // OVERRIDE
13936
- return undefined;
13937
- };
13938
- _proto.getStencilTexture = function getStencilTexture() {
13939
- // OVERRIDE
13940
- return undefined;
13941
- };
13942
- _proto.getColorTextures = function getColorTextures() {
13943
- // OVERRIDE
13944
- return [];
13945
- };
13946
- _proto.dispose = function dispose(options) {
13947
- // OVERRIDE
13948
- };
13949
- _create_class(Framebuffer, [
13950
- {
13951
- key: "stencilStorage",
13952
- get: function get() {
13953
- // OVERRIDE
13954
- return undefined;
13955
- }
13956
- },
13957
- {
13958
- key: "depthStorage",
13959
- get: function get() {
13960
- // OVERRIDE
13961
- return undefined;
13962
- }
13963
- }
13964
- ]);
13965
- return Framebuffer;
13966
- }();
13967
-
13968
13550
  var Renderer = /*#__PURE__*/ function() {
13969
13551
  function Renderer(engine) {
13970
13552
  this.engine = engine;
13553
+ this.currentFramebuffer = null;
13554
+ this.renderTargetPool = new RenderTargetPool(engine);
13971
13555
  }
13972
13556
  var _proto = Renderer.prototype;
13973
13557
  _proto.setGlobalFloat = function setGlobalFloat(name, value) {
@@ -14037,8 +13621,10 @@ var Renderer = /*#__PURE__*/ function() {
14037
13621
  // OVERRIDE
14038
13622
  };
14039
13623
  _proto.getTemporaryRT = function getTemporaryRT(name, width, height, depthBuffer, filter, format) {
14040
- // OVERRIDE
14041
- return null;
13624
+ return this.renderTargetPool.get(name, width, height, depthBuffer, filter, format);
13625
+ };
13626
+ _proto.releaseTemporaryRT = function releaseTemporaryRT(rt) {
13627
+ this.renderTargetPool.release(rt);
14042
13628
  };
14043
13629
  _proto.dispose = function dispose() {
14044
13630
  // OVERRIDE
@@ -14046,6 +13632,41 @@ var Renderer = /*#__PURE__*/ function() {
14046
13632
  return Renderer;
14047
13633
  }();
14048
13634
 
13635
+ var SemanticMap = /*#__PURE__*/ function() {
13636
+ function SemanticMap(semantics) {
13637
+ if (semantics === void 0) semantics = {};
13638
+ this.semantics = _extends({}, semantics);
13639
+ }
13640
+ var _proto = SemanticMap.prototype;
13641
+ _proto.toObject = function toObject() {
13642
+ return _extends({}, this.semantics);
13643
+ };
13644
+ _proto.setSemantic = function setSemantic(name, value) {
13645
+ if (value === undefined) {
13646
+ delete this.semantics[name];
13647
+ } else {
13648
+ this.semantics[name] = value;
13649
+ }
13650
+ };
13651
+ _proto.getSemanticValue = function getSemanticValue(name, state) {
13652
+ var ret = this.semantics[name];
13653
+ if (isFunction(ret)) {
13654
+ return ret(state);
13655
+ }
13656
+ return ret;
13657
+ };
13658
+ _proto.hasSemanticValue = function hasSemanticValue(name) {
13659
+ return name in this.semantics;
13660
+ };
13661
+ _proto.dispose = function dispose() {
13662
+ var _this = this;
13663
+ Object.keys(this.semantics).forEach(function(name) {
13664
+ delete _this.semantics[name];
13665
+ });
13666
+ };
13667
+ return SemanticMap;
13668
+ }();
13669
+
14049
13670
  /**
14050
13671
  * @since 2.7.0
14051
13672
  */ var MaskableGraphic = /*#__PURE__*/ function(RendererComponent) {
@@ -18076,6 +17697,11 @@ exports.PlayState = void 0;
18076
17697
  PlayState[PlayState["Paused"] = 1] = "Paused";
18077
17698
  })(exports.PlayState || (exports.PlayState = {}));
18078
17699
 
17700
+ function _assert_this_initialized(self) {
17701
+ if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
17702
+ return self;
17703
+ }
17704
+
18079
17705
  var tempQuat$1 = new Quaternion();
18080
17706
  var tempVector3 = new Vector3();
18081
17707
  var tempVector3Second = new Vector3();
@@ -24453,8 +24079,7 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24453
24079
  _this.reusable = reusable;
24454
24080
  _this.speed = speed;
24455
24081
  _this.name = sourceContent.name;
24456
- _this.pluginSystem = scene.pluginSystem;
24457
- _this.pluginSystem.initializeComposition(_assert_this_initialized(_this), scene);
24082
+ PluginSystem.initializeComposition(_assert_this_initialized(_this), scene);
24458
24083
  _this.camera = new Camera(_this.name, _extends({}, sourceContent == null ? void 0 : sourceContent.camera, {
24459
24084
  aspect: width / height,
24460
24085
  pixelWidth: width,
@@ -24468,7 +24093,6 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24468
24093
  _this.createRenderFrame();
24469
24094
  Composition.buildItemTree(_this.rootItem);
24470
24095
  _this.rootComposition.setChildrenRenderOrder(0);
24471
- _this.pluginSystem.resetComposition(_assert_this_initialized(_this), _this.renderFrame);
24472
24096
  return _this;
24473
24097
  }
24474
24098
  var _proto = Composition.prototype;
@@ -24578,12 +24202,9 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24578
24202
  this.renderFrame = new RenderFrame({
24579
24203
  camera: this.camera,
24580
24204
  renderer: this.renderer,
24581
- keepColorBuffer: this.keepColorBuffer,
24582
24205
  globalVolume: this.globalVolume,
24583
24206
  postProcessingEnabled: this.postProcessingEnabled
24584
24207
  });
24585
- // TODO 考虑放到构造函数
24586
- this.renderFrame.cachedTextures = this.textures;
24587
24208
  };
24588
24209
  /**
24589
24210
  * 跳到指定时间点(不做任何播放行为)
@@ -24634,7 +24255,6 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24634
24255
  this.isEnded = false;
24635
24256
  this.isEndCalled = false;
24636
24257
  this.rootComposition.time = 0;
24637
- this.pluginSystem.resetComposition(this, this.renderFrame);
24638
24258
  };
24639
24259
  _proto.prepareRender = function prepareRender() {};
24640
24260
  /**
@@ -24652,8 +24272,6 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24652
24272
  var previousCompositionTime = this.time;
24653
24273
  this.updateCompositionTime(deltaTime * this.speed / 1000);
24654
24274
  var deltaTimeInMs = (this.time - previousCompositionTime) * 1000;
24655
- // 更新 model-tree-plugin
24656
- this.updatePluginLoaders(deltaTimeInMs);
24657
24275
  this.sceneTicking.update.tick(deltaTimeInMs);
24658
24276
  this.sceneTicking.lateUpdate.tick(deltaTimeInMs);
24659
24277
  this.updateCamera();
@@ -24678,15 +24296,6 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24678
24296
  this.camera.updateMatrix();
24679
24297
  };
24680
24298
  /**
24681
- * 插件更新,来自 CompVFXItem 的更新调用
24682
- * @param deltaTime - 更新的时间步长
24683
- */ _proto.updatePluginLoaders = function updatePluginLoaders(deltaTime) {
24684
- var _this = this;
24685
- this.pluginSystem.plugins.forEach(function(loader) {
24686
- return loader.onCompositionUpdate(_this, deltaTime);
24687
- });
24688
- };
24689
- /**
24690
24299
  * 更新主合成组件
24691
24300
  */ _proto.updateCompositionTime = function updateCompositionTime(deltaTime) {
24692
24301
  if (this.rootComposition.state === exports.PlayState.Paused || !this.rootComposition.isActiveAndEnabled) {
@@ -24845,7 +24454,6 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24845
24454
  * 合成对象销毁
24846
24455
  */ _proto.dispose = function dispose() {
24847
24456
  var _this = this;
24848
- var _this_pluginSystem;
24849
24457
  if (this.destroyed) {
24850
24458
  return;
24851
24459
  }
@@ -24865,13 +24473,14 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24865
24473
  this.rootItem.dispose();
24866
24474
  // FIXME: 注意这里增加了renderFrame销毁
24867
24475
  this.renderFrame.dispose();
24868
- (_this_pluginSystem = this.pluginSystem) == null ? void 0 : _this_pluginSystem.destroyComposition(this);
24476
+ PluginSystem.destroyComposition(this);
24869
24477
  this.update = function() {
24870
24478
  {
24871
24479
  logger.error("Update disposed composition: " + _this.name + ".");
24872
24480
  }
24873
24481
  };
24874
24482
  this.dispose = noop;
24483
+ this.renderer.engine.removeComposition(this);
24875
24484
  if (this.getEngine().env === PLAYER_OPTIONS_ENV_EDITOR) {
24876
24485
  return;
24877
24486
  }
@@ -24888,7 +24497,6 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24888
24497
  0
24889
24498
  ]
24890
24499
  });
24891
- this.renderer.engine.removeComposition(this);
24892
24500
  };
24893
24501
  /**
24894
24502
  * 编辑器使用的 transform 修改方法
@@ -29281,6 +28889,12 @@ var TextComponentBase = /*#__PURE__*/ function() {
29281
28889
  this.textLayout.textVerticalAlign = value;
29282
28890
  this.isDirty = true;
29283
28891
  };
28892
+ /**
28893
+ * @deprecated 2.8.0 本方法已废弃,请使用 setTextVerticalAlign 替代。
28894
+ */ _proto.setTextBaseline = function setTextBaseline(value) {
28895
+ console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。" + "本次调用将转调用 setTextVerticalAlign。");
28896
+ this.setTextVerticalAlign(value);
28897
+ };
29284
28898
  _proto.setTextColor = function setTextColor(value) {
29285
28899
  if (this.textStyle.textColor === value) {
29286
28900
  return;
@@ -29545,7 +29159,9 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29545
29159
  this.lineCount = this.getLineCount(this.text);
29546
29160
  this.isDirty = true;
29547
29161
  };
29548
- _proto.updateWithOptions = function updateWithOptions(options) {
29162
+ /**
29163
+ * 根据配置更新文本样式和布局
29164
+ */ _proto.updateWithOptions = function updateWithOptions(options) {
29549
29165
  // 初始化 textStyle 和 textLayout
29550
29166
  if (!this.textStyle) {
29551
29167
  this.textStyle = new TextStyle(options);
@@ -31855,7 +31471,7 @@ function getStandardSpriteContent(sprite, transform) {
31855
31471
  return ret;
31856
31472
  }
31857
31473
 
31858
- var version$1 = "2.8.0-alpha.0";
31474
+ var version$1 = "2.8.0-alpha.2";
31859
31475
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
31860
31476
  var standardVersion = /^(\d+)\.(\d+)$/;
31861
31477
  var reverseParticle = false;
@@ -32370,7 +31986,7 @@ var seed = 1;
32370
31986
  * @param renderer - renderer 对象,用于获取管理、编译 shader 及 GPU 上下文的参数
32371
31987
  * @param options - 扩展参数
32372
31988
  * @returns
32373
- */ _proto.loadScene = function loadScene(url, renderer, options) {
31989
+ */ _proto.loadScene = function loadScene(url, renderer) {
32374
31990
  var _this = this;
32375
31991
  return _async_to_generator(function() {
32376
31992
  var rawJSON, assetUrl, startTime, timeInfoMessages, gpuInstance, _gpuInstance_detail_ktx2Support, isKTX2Supported, timeInfos, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
@@ -32431,7 +32047,7 @@ var seed = 1;
32431
32047
  });
32432
32048
  });
32433
32049
  loadResourcePromise = /*#__PURE__*/ _async_to_generator(function() {
32434
- var scene, link, _ref, jsonScene, pluginSystem, _jsonScene_bins, bins, images, fonts, _ref1, loadedBins, loadedImages, loadedTextures, totalTime;
32050
+ var scene, link, _scene_bins, _scene_textureOptions, _scene_images, jsonScene, _jsonScene_bins, bins, images, fonts, _ref, loadedBins, loadedImages, loadedTextures, totalTime;
32435
32051
  return __generator(this, function(_state) {
32436
32052
  switch(_state.label){
32437
32053
  case 0:
@@ -32481,7 +32097,26 @@ var seed = 1;
32481
32097
  })
32482
32098
  ];
32483
32099
  case 5:
32484
- _ref = _state.sent(), jsonScene = _ref.jsonScene, pluginSystem = _ref.pluginSystem;
32100
+ jsonScene = _state.sent().jsonScene;
32101
+ scene = {
32102
+ timeInfos: timeInfos,
32103
+ url: url,
32104
+ storage: {},
32105
+ jsonScene: jsonScene,
32106
+ bins: [],
32107
+ textureOptions: [],
32108
+ textures: [],
32109
+ images: [],
32110
+ assets: _this.assets
32111
+ };
32112
+ return [
32113
+ 4,
32114
+ hookTimeInfo("plugin:processAssets", function() {
32115
+ return _this.processPluginAssets(scene);
32116
+ })
32117
+ ];
32118
+ case 6:
32119
+ _state.sent();
32485
32120
  _jsonScene_bins = jsonScene.bins, bins = _jsonScene_bins === void 0 ? [] : _jsonScene_bins, images = jsonScene.images, fonts = jsonScene.fonts;
32486
32121
  return [
32487
32122
  4,
@@ -32492,46 +32127,26 @@ var seed = 1;
32492
32127
  hookTimeInfo("processImages", function() {
32493
32128
  return _this.processImages(images, isKTX2Supported);
32494
32129
  }),
32495
- hookTimeInfo("plugin:processAssets", function() {
32496
- return _this.processPluginAssets(jsonScene, pluginSystem, options);
32497
- }),
32498
32130
  hookTimeInfo("processFontURL", function() {
32499
32131
  return _this.processFontURL(fonts);
32500
32132
  })
32501
32133
  ])
32502
32134
  ];
32503
- case 6:
32504
- _ref1 = _state.sent(), loadedBins = _ref1[0], loadedImages = _ref1[1];
32135
+ case 7:
32136
+ _ref = _state.sent(), loadedBins = _ref[0], loadedImages = _ref[1];
32505
32137
  return [
32506
32138
  4,
32507
32139
  hookTimeInfo("processTextures", function() {
32508
32140
  return _this.processTextures(loadedImages, loadedBins, jsonScene);
32509
32141
  })
32510
32142
  ];
32511
- case 7:
32512
- loadedTextures = _state.sent();
32513
- scene = {
32514
- timeInfos: timeInfos,
32515
- url: url,
32516
- renderLevel: _this.options.renderLevel,
32517
- storage: {},
32518
- pluginSystem: pluginSystem,
32519
- jsonScene: jsonScene,
32520
- bins: loadedBins,
32521
- textureOptions: loadedTextures,
32522
- textures: [],
32523
- images: loadedImages,
32524
- assets: _this.assets
32525
- };
32526
- // 触发插件系统 pluginSystem 的回调 prepareResource
32527
- return [
32528
- 4,
32529
- hookTimeInfo("plugin:prepareResource", function() {
32530
- return pluginSystem.loadResources(scene, _this.options);
32531
- })
32532
- ];
32533
32143
  case 8:
32534
- _state.sent();
32144
+ loadedTextures = _state.sent();
32145
+ (_scene_bins = scene.bins).push.apply(_scene_bins, [].concat(loadedBins));
32146
+ (_scene_textureOptions = scene.textureOptions).push.apply(_scene_textureOptions, [].concat(loadedTextures));
32147
+ (_scene_images = scene.images).push.apply(_scene_images, [].concat(loadedImages));
32148
+ // 降级插件会修改 this.options.renderLevel, 在 processPluginAssets 后赋值
32149
+ scene.renderLevel = _this.options.renderLevel;
32535
32150
  _state.label = 9;
32536
32151
  case 9:
32537
32152
  totalTime = performance.now() - startTime;
@@ -32563,29 +32178,23 @@ var seed = 1;
32563
32178
  return this.assets;
32564
32179
  };
32565
32180
  _proto.processJSON = function processJSON(json) {
32566
- var _this = this;
32567
32181
  return _async_to_generator(function() {
32568
- var jsonScene, _jsonScene_plugins, plugins, pluginSystem;
32182
+ var jsonScene, _jsonScene_plugins, plugins, _iterator, _step, customPluginName;
32569
32183
  return __generator(this, function(_state) {
32570
- switch(_state.label){
32571
- case 0:
32572
- jsonScene = getStandardJSON(json);
32573
- _jsonScene_plugins = jsonScene.plugins, plugins = _jsonScene_plugins === void 0 ? [] : _jsonScene_plugins;
32574
- pluginSystem = new PluginSystem(plugins);
32575
- return [
32576
- 4,
32577
- pluginSystem.processRawJSON(jsonScene, _this.options)
32578
- ];
32579
- case 1:
32580
- _state.sent();
32581
- return [
32582
- 2,
32583
- {
32584
- jsonScene: jsonScene,
32585
- pluginSystem: pluginSystem
32586
- }
32587
- ];
32184
+ jsonScene = getStandardJSON(json);
32185
+ _jsonScene_plugins = jsonScene.plugins, plugins = _jsonScene_plugins === void 0 ? [] : _jsonScene_plugins;
32186
+ for(_iterator = _create_for_of_iterator_helper_loose(plugins); !(_step = _iterator()).done;){
32187
+ customPluginName = _step.value;
32188
+ if (!pluginLoaderMap[customPluginName]) {
32189
+ throw new Error("The plugin '" + customPluginName + "' not found." + getPluginUsageInfo(customPluginName));
32190
+ }
32588
32191
  }
32192
+ return [
32193
+ 2,
32194
+ {
32195
+ jsonScene: jsonScene
32196
+ }
32197
+ ];
32589
32198
  });
32590
32199
  })();
32591
32200
  };
@@ -32791,30 +32400,18 @@ var seed = 1;
32791
32400
  });
32792
32401
  })();
32793
32402
  };
32794
- _proto.processPluginAssets = function processPluginAssets(jsonScene, pluginSystem, options) {
32403
+ _proto.processPluginAssets = function processPluginAssets(scene) {
32795
32404
  var _this = this;
32796
32405
  return _async_to_generator(function() {
32797
- var pluginResult, _pluginResult_reduce, assets, loadedAssets, i;
32798
32406
  return __generator(this, function(_state) {
32799
32407
  switch(_state.label){
32800
32408
  case 0:
32801
32409
  return [
32802
32410
  4,
32803
- pluginSystem.processAssets(jsonScene, options)
32411
+ PluginSystem.processAssets(scene, _this.options)
32804
32412
  ];
32805
32413
  case 1:
32806
- pluginResult = _state.sent();
32807
- _pluginResult_reduce = pluginResult.reduce(function(acc, cur) {
32808
- acc.assets = acc.assets.concat(cur.assets);
32809
- acc.loadedAssets = acc.loadedAssets.concat(cur.loadedAssets);
32810
- return acc;
32811
- }, {
32812
- assets: [],
32813
- loadedAssets: []
32814
- }), assets = _pluginResult_reduce.assets, loadedAssets = _pluginResult_reduce.loadedAssets;
32815
- for(i = 0; i < assets.length; i++){
32816
- _this.assets[assets[i].id] = loadedAssets[i];
32817
- }
32414
+ _state.sent();
32818
32415
  return [
32819
32416
  2
32820
32417
  ];
@@ -33241,7 +32838,6 @@ function _createTextureOptionsBySource() {
33241
32838
  }
33242
32839
  };
33243
32840
  _proto.prepareAssets = function prepareAssets(scene, assets) {
33244
- this.engine.clearResources();
33245
32841
  for(var _iterator = _create_for_of_iterator_helper_loose(Object.keys(assets)), _step; !(_step = _iterator()).done;){
33246
32842
  var assetId = _step.value;
33247
32843
  var asset = assets[assetId];
@@ -35153,8 +34749,9 @@ var DEFAULT_FPS = 60;
35153
34749
  ]
35154
34750
  });
35155
34751
  for(var i1 = 0; i1 < comps.length; i1++){
35156
- !comps[i1].renderFrame.isDestroyed && this.renderer.renderRenderFrame(comps[i1].renderFrame);
34752
+ !comps[i1].renderFrame.isDisposed && this.renderer.renderRenderFrame(comps[i1].renderFrame);
35157
34753
  }
34754
+ this.renderer.renderTargetPool.flush();
35158
34755
  };
35159
34756
  /**
35160
34757
  * 将渲染器重新和父容器大小对齐
@@ -35400,6 +34997,95 @@ var DEFAULT_FPS = 60;
35400
34997
  return Engine;
35401
34998
  }(EventEmitter);
35402
34999
 
35000
+ var def = {
35001
+ format: glContext.RGBA,
35002
+ type: glContext.UNSIGNED_BYTE,
35003
+ minFilter: glContext.LINEAR,
35004
+ magFilter: glContext.LINEAR,
35005
+ wrapS: glContext.CLAMP_TO_EDGE,
35006
+ wrapT: glContext.CLAMP_TO_EDGE
35007
+ };
35008
+ var disposeSymbol = Symbol("dispose");
35009
+ var PassTextureCache = /*#__PURE__*/ function() {
35010
+ function PassTextureCache(engine) {
35011
+ this.textureCache = {};
35012
+ this.textureRef = {};
35013
+ this.engine = engine;
35014
+ }
35015
+ var _proto = PassTextureCache.prototype;
35016
+ _proto.requestColorAttachmentTexture = function requestColorAttachmentTexture(request) {
35017
+ var _this = this;
35018
+ var width = request.width, height = request.height, name = request.name;
35019
+ var options = {
35020
+ sourceType: exports.TextureSourceType.framebuffer,
35021
+ data: {
35022
+ width: width,
35023
+ height: height
35024
+ },
35025
+ name: name
35026
+ };
35027
+ var keys = [
35028
+ name
35029
+ ];
35030
+ Object.getOwnPropertyNames(def).forEach(function(name) {
35031
+ var _request_name;
35032
+ var value = (_request_name = request[name]) != null ? _request_name : def[name];
35033
+ options[name] = value;
35034
+ keys.push(name, value);
35035
+ });
35036
+ var cacheId = keys.join(":");
35037
+ var tex = this.textureCache[cacheId];
35038
+ if (tex) {
35039
+ this.textureRef[cacheId]++;
35040
+ } else {
35041
+ var engine = this.engine;
35042
+ assertExist(engine);
35043
+ tex = Texture.create(engine, options);
35044
+ this.textureCache[cacheId] = tex;
35045
+ this.textureRef[cacheId] = 1;
35046
+ // @ts-expect-error
35047
+ tex[disposeSymbol] = tex.dispose;
35048
+ tex.dispose = function() {
35049
+ return _this.removeTexture(cacheId);
35050
+ };
35051
+ }
35052
+ return tex;
35053
+ };
35054
+ _proto.removeTexture = function removeTexture(id) {
35055
+ var refCount = this.textureRef[id];
35056
+ if (refCount <= 1) {
35057
+ if (refCount < 0) {
35058
+ console.error("Ref count < 0.");
35059
+ }
35060
+ var tex = this.textureCache[id];
35061
+ if (tex) {
35062
+ // @ts-expect-error
35063
+ tex[disposeSymbol]();
35064
+ // @ts-expect-error
35065
+ tex.dispose = tex[disposeSymbol];
35066
+ }
35067
+ delete this.textureCache[id];
35068
+ delete this.textureRef[id];
35069
+ } else {
35070
+ this.textureRef[id] = refCount - 1;
35071
+ }
35072
+ };
35073
+ _proto.dispose = function dispose() {
35074
+ var _this = this;
35075
+ Object.keys(this.textureCache).forEach(function(key) {
35076
+ var texture = _this.textureCache[key];
35077
+ // @ts-expect-error
35078
+ texture[disposeSymbol]();
35079
+ // @ts-expect-error
35080
+ texture.dispose = texture[disposeSymbol];
35081
+ });
35082
+ this.textureCache = {};
35083
+ this.textureRef = {};
35084
+ this.engine = undefined;
35085
+ };
35086
+ return PassTextureCache;
35087
+ }();
35088
+
35403
35089
  var SceneLoader = /*#__PURE__*/ function() {
35404
35090
  function SceneLoader() {}
35405
35091
  SceneLoader.load = function load(scene, engine, options) {
@@ -35418,16 +35104,16 @@ var SceneLoader = /*#__PURE__*/ function() {
35418
35104
  engine.assetManagers.push(assetManager);
35419
35105
  return [
35420
35106
  4,
35421
- assetManager.loadScene(scene, engine.renderer, {
35422
- env: engine.env
35423
- })
35107
+ assetManager.loadScene(scene, engine.renderer)
35424
35108
  ];
35425
35109
  case 1:
35426
35110
  loadedScene = _state.sent();
35111
+ engine.clearResources();
35112
+ // 触发插件系统 pluginSystem 的回调 prepareResource
35113
+ PluginSystem.loadResources(loadedScene, assetManager.options, engine);
35427
35114
  engine.assetService.prepareAssets(loadedScene, loadedScene.assets);
35428
35115
  engine.assetService.updateTextVariables(loadedScene, options.variables);
35429
35116
  engine.assetService.initializeTexture(loadedScene);
35430
- loadedScene.pluginSystem.precompile(loadedScene.jsonScene.compositions, engine.renderer);
35431
35117
  composition = _this.createComposition(loadedScene, engine, options);
35432
35118
  composition.setIndex(compositionIndex);
35433
35119
  compileStart = performance.now();
@@ -35480,13 +35166,13 @@ var SceneLoader = /*#__PURE__*/ function() {
35480
35166
  return SceneLoader;
35481
35167
  }();
35482
35168
 
35483
- registerPlugin("camera", CameraVFXItemLoader, exports.VFXItem);
35484
- registerPlugin("text", TextLoader, exports.VFXItem);
35485
- registerPlugin("sprite", SpriteLoader, exports.VFXItem);
35486
- registerPlugin("particle", ParticleLoader, exports.VFXItem);
35487
- registerPlugin("cal", CalculateLoader, exports.VFXItem);
35488
- registerPlugin("interact", InteractLoader, exports.VFXItem);
35489
- var version = "2.8.0-alpha.0";
35169
+ registerPlugin("camera", CameraVFXItemLoader);
35170
+ registerPlugin("text", TextLoader);
35171
+ registerPlugin("sprite", SpriteLoader);
35172
+ registerPlugin("particle", ParticleLoader);
35173
+ registerPlugin("cal", CalculateLoader);
35174
+ registerPlugin("interact", InteractLoader);
35175
+ var version = "2.8.0-alpha.2";
35490
35176
  logger.info("Core version: " + version + ".");
35491
35177
 
35492
35178
  exports.AbstractPlugin = AbstractPlugin;
@@ -35597,7 +35283,6 @@ exports.Pose = Pose;
35597
35283
  exports.PoseNode = PoseNode;
35598
35284
  exports.PropertyClipPlayable = PropertyClipPlayable;
35599
35285
  exports.PropertyTrack = PropertyTrack;
35600
- exports.RENDER_PASS_NAME_PREFIX = RENDER_PASS_NAME_PREFIX;
35601
35286
  exports.RENDER_PREFER_LOOKUP_TEXTURE = RENDER_PREFER_LOOKUP_TEXTURE;
35602
35287
  exports.RUNTIME_ENV = RUNTIME_ENV;
35603
35288
  exports.RandomSetValue = RandomSetValue;
@@ -35610,6 +35295,7 @@ exports.RenderPassPriorityNormal = RenderPassPriorityNormal;
35610
35295
  exports.RenderPassPriorityPostprocess = RenderPassPriorityPostprocess;
35611
35296
  exports.RenderPassPriorityPrepare = RenderPassPriorityPrepare;
35612
35297
  exports.RenderTargetHandle = RenderTargetHandle;
35298
+ exports.RenderTargetPool = RenderTargetPool;
35613
35299
  exports.Renderbuffer = Renderbuffer;
35614
35300
  exports.Renderer = Renderer;
35615
35301
  exports.RendererComponent = RendererComponent;
@@ -35672,14 +35358,12 @@ exports.colorGradingFrag = colorGradingFrag;
35672
35358
  exports.colorStopsFromGradient = colorStopsFromGradient;
35673
35359
  exports.colorToArr = colorToArr$1;
35674
35360
  exports.combineImageTemplate = combineImageTemplate;
35675
- exports.createCopyShader = createCopyShader;
35676
35361
  exports.createGLContext = createGLContext;
35677
35362
  exports.createKeyFrameMeta = createKeyFrameMeta;
35678
35363
  exports.createShape = createShape;
35679
35364
  exports.createValueGetter = createValueGetter;
35680
35365
  exports.curveEps = curveEps;
35681
35366
  exports.decimalEqual = decimalEqual;
35682
- exports.defaultPlugins = defaultPlugins;
35683
35367
  exports.deserializeMipmapTexture = deserializeMipmapTexture;
35684
35368
  exports.earcut = earcut;
35685
35369
  exports.effectsClass = effectsClass;
@@ -35687,7 +35371,6 @@ exports.effectsClassStore = effectsClassStore;
35687
35371
  exports.enlargeBuffer = enlargeBuffer;
35688
35372
  exports.ensureFixedNumber = ensureFixedNumber;
35689
35373
  exports.ensureVec3 = ensureVec3;
35690
- exports.findPreviousRenderPass = findPreviousRenderPass;
35691
35374
  exports.gaussianDownHFrag = gaussianDownHFrag;
35692
35375
  exports.gaussianDownVFrag = gaussianDownVFrag;
35693
35376
  exports.gaussianUpFrag = gaussianUpFrag;
@@ -35708,6 +35391,7 @@ exports.getMergedStore = getMergedStore;
35708
35391
  exports.getNodeDataClass = getNodeDataClass;
35709
35392
  exports.getParticleMeshShader = getParticleMeshShader;
35710
35393
  exports.getPixelRatio = getPixelRatio;
35394
+ exports.getPluginUsageInfo = getPluginUsageInfo;
35711
35395
  exports.getPreMultiAlpha = getPreMultiAlpha;
35712
35396
  exports.getStandardComposition = getStandardComposition;
35713
35397
  exports.getStandardImage = getStandardImage;