@galacean/effects-threejs 2.8.0-alpha.1 → 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 threejs plugin for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.8.0-alpha.1
6
+ * Version: v2.8.0-alpha.2
7
7
  */
8
8
 
9
9
  'use strict';
@@ -59,41 +59,6 @@ function _async_to_generator(fn) {
59
59
  };
60
60
  }
61
61
 
62
- function _array_like_to_array(arr, len) {
63
- if (len == null || len > arr.length) len = arr.length;
64
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
65
- return arr2;
66
- }
67
-
68
- function _unsupported_iterable_to_array(o, minLen) {
69
- if (!o) return;
70
- if (typeof o === "string") return _array_like_to_array(o, minLen);
71
- var n = Object.prototype.toString.call(o).slice(8, -1);
72
- if (n === "Object" && o.constructor) n = o.constructor.name;
73
- if (n === "Map" || n === "Set") return Array.from(n);
74
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
75
- }
76
-
77
- function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
78
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
79
- if (it) return (it = it.call(o)).next.bind(it);
80
- // Fallback for engines without symbol support
81
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
82
- if (it) o = it;
83
- var i = 0;
84
- return function() {
85
- if (i >= o.length) return {
86
- done: true
87
- };
88
- return {
89
- done: false,
90
- value: o[i++]
91
- };
92
- };
93
- }
94
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
95
- }
96
-
97
62
  function _instanceof1(left, right) {
98
63
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
99
64
  return !!right[Symbol.hasInstance](left);
@@ -2926,134 +2891,68 @@ function applyMixins(derivedCtrl, baseCtrls) {
2926
2891
  }
2927
2892
 
2928
2893
  var pluginLoaderMap = {};
2929
- var defaultPlugins = [];
2930
- var pluginCtrlMap = {};
2894
+ var plugins = [];
2931
2895
  /**
2932
2896
  * 注册 plugin
2933
2897
  * @param name
2934
2898
  * @param pluginClass class of plugin
2935
2899
  * @param itemClass class of item
2936
2900
  * @param isDefault load
2937
- */ function registerPlugin(name, pluginClass, itemClass) {
2938
- if (pluginCtrlMap[name]) {
2901
+ */ function registerPlugin(name, pluginClass) {
2902
+ if (pluginLoaderMap[name]) {
2939
2903
  logger.error("Duplicate registration for plugin " + name + ".");
2940
2904
  }
2941
- pluginCtrlMap[name] = itemClass;
2942
2905
  pluginLoaderMap[name] = pluginClass;
2943
- addItem(defaultPlugins, name);
2906
+ var pluginInstance = new pluginClass();
2907
+ pluginInstance.name = name;
2908
+ pluginInstance.initialize();
2909
+ plugins.push(pluginInstance);
2910
+ plugins.sort(function(a, b) {
2911
+ return a.order - b.order;
2912
+ });
2944
2913
  }
2945
- function unregisterPlugin(name) {
2946
- delete pluginCtrlMap[name];
2914
+ /**
2915
+ * 注销 plugin
2916
+ */ function unregisterPlugin(name) {
2947
2917
  delete pluginLoaderMap[name];
2948
- removeItem(defaultPlugins, name);
2918
+ var pluginIndex = plugins.findIndex(function(plugin) {
2919
+ return plugin.name === name;
2920
+ });
2921
+ if (pluginIndex !== -1) {
2922
+ plugins.splice(pluginIndex, 1);
2923
+ }
2949
2924
  }
2950
2925
  var PluginSystem = /*#__PURE__*/ function() {
2951
- function PluginSystem(pluginNames) {
2952
- var loaders = {};
2953
- var loaded = [];
2954
- var addLoader = function(name) {
2955
- var loader = pluginLoaderMap[name];
2956
- if (!loaded.includes(loader)) {
2957
- loaded.push(loader);
2958
- loaders[name] = loader;
2959
- }
2960
- };
2961
- defaultPlugins.forEach(addLoader);
2962
- for(var _iterator = _create_for_of_iterator_helper_loose(pluginNames), _step; !(_step = _iterator()).done;){
2963
- var customPluginName = _step.value;
2964
- if (!pluginLoaderMap[customPluginName]) {
2965
- throw new Error("The plugin '" + customPluginName + "' not found." + getPluginUsageInfo(customPluginName));
2966
- }
2967
- }
2968
- this.plugins = Object.keys(loaders).map(function(name) {
2969
- var pluginConstructor = pluginLoaderMap[name];
2970
- var loader = new pluginConstructor();
2971
- loader.name = name;
2972
- return loader;
2973
- }).sort(function(a, b) {
2974
- return a.order - b.order;
2975
- });
2976
- }
2977
- var _proto = PluginSystem.prototype;
2978
- _proto.initializeComposition = function initializeComposition(composition, scene) {
2979
- this.plugins.forEach(function(loader) {
2926
+ function PluginSystem() {}
2927
+ PluginSystem.getPlugins = function getPlugins() {
2928
+ return plugins;
2929
+ };
2930
+ PluginSystem.initializeComposition = function initializeComposition(composition, scene) {
2931
+ plugins.forEach(function(loader) {
2980
2932
  return loader.onCompositionConstructed(composition, scene);
2981
2933
  });
2982
2934
  };
2983
- _proto.destroyComposition = function destroyComposition(comp) {
2984
- this.plugins.forEach(function(loader) {
2935
+ PluginSystem.destroyComposition = function destroyComposition(comp) {
2936
+ plugins.forEach(function(loader) {
2985
2937
  return loader.onCompositionDestroyed(comp);
2986
2938
  });
2987
2939
  };
2988
- _proto.resetComposition = function resetComposition(comp, renderFrame) {
2989
- this.plugins.forEach(function(loader) {
2990
- return loader.onCompositionReset(comp, renderFrame);
2991
- });
2992
- };
2993
- _proto.processRawJSON = function processRawJSON(json, options) {
2994
- var _this = this;
2940
+ PluginSystem.processAssets = function processAssets(scene, options) {
2995
2941
  return _async_to_generator(function() {
2996
2942
  return __generator(this, function(_state) {
2997
2943
  return [
2998
2944
  2,
2999
- _this.callStatic("processRawJSON", json, options)
3000
- ];
3001
- });
3002
- })();
3003
- };
3004
- _proto.processAssets = function processAssets(json, options) {
3005
- var _this = this;
3006
- return _async_to_generator(function() {
3007
- return __generator(this, function(_state) {
3008
- return [
3009
- 2,
3010
- _this.callStatic("processAssets", json, options)
3011
- ];
3012
- });
3013
- })();
3014
- };
3015
- _proto.precompile = function precompile(compositions, renderer) {
3016
- for(var _iterator = _create_for_of_iterator_helper_loose(this.plugins), _step; !(_step = _iterator()).done;){
3017
- var plugin = _step.value;
3018
- plugin.precompile(compositions, renderer);
3019
- }
3020
- };
3021
- _proto.loadResources = function loadResources(scene, options) {
3022
- var _this = this;
3023
- return _async_to_generator(function() {
3024
- return __generator(this, function(_state) {
3025
- return [
3026
- 2,
3027
- _this.callStatic("prepareResource", scene, options)
2945
+ Promise.all(plugins.map(function(plugin) {
2946
+ return plugin.processAssets(scene, options);
2947
+ }))
3028
2948
  ];
3029
2949
  });
3030
2950
  })();
3031
2951
  };
3032
- _proto.callStatic = function callStatic(name) {
3033
- for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
3034
- args[_key - 1] = arguments[_key];
3035
- }
3036
- var _this = this;
3037
- return _async_to_generator(function() {
3038
- var pendings, plugins, i, plugin, ctrl, _ctrl_name, _ctrl_name1;
3039
- return __generator(this, function(_state) {
3040
- pendings = [];
3041
- plugins = _this.plugins;
3042
- for(i = 0; i < plugins.length; i++){
3043
- plugin = plugins[i];
3044
- ctrl = pluginLoaderMap[plugin.name];
3045
- if (name in ctrl) {
3046
- pendings.push(Promise.resolve((_ctrl_name1 = ctrl[name]) == null ? void 0 : (_ctrl_name = _ctrl_name1).call.apply(_ctrl_name, [].concat([
3047
- ctrl
3048
- ], args))));
3049
- }
3050
- }
3051
- return [
3052
- 2,
3053
- Promise.all(pendings)
3054
- ];
3055
- });
3056
- })();
2952
+ PluginSystem.loadResources = function loadResources(scene, options, engine) {
2953
+ plugins.forEach(function(loader) {
2954
+ return loader.prepareResource(scene, options, engine);
2955
+ });
3057
2956
  };
3058
2957
  return PluginSystem;
3059
2958
  }();
@@ -3061,6 +2960,8 @@ var pluginInfoMap = {
3061
2960
  "alipay-downgrade": "@galacean/effects-plugin-alipay-downgrade",
3062
2961
  "downgrade": "@galacean/effects-plugin-downgrade",
3063
2962
  "editor-gizmo": "@galacean/effects-plugin-editor-gizmo",
2963
+ "ffd": "@galacean/effects-plugin-ffd",
2964
+ "ktx2": "@galacean/effects-plugin-ktx2",
3064
2965
  "model": "@galacean/effects-plugin-model",
3065
2966
  "video": "@galacean/effects-plugin-multimedia",
3066
2967
  "audio": "@galacean/effects-plugin-multimedia",
@@ -3086,15 +2987,33 @@ function getPluginUsageInfo(name) {
3086
2987
  this.name = "";
3087
2988
  }
3088
2989
  var _proto = AbstractPlugin.prototype;
2990
+ _proto.initialize = function initialize() {};
3089
2991
  /**
3090
- * 在加载到 JSON 后,就可以进行提前编译
3091
- * @param json
3092
- * @param player
3093
- */ _proto.precompile = function precompile(compositions, renderer) {};
2992
+ * loadScene 函数调用的时候会触发此函数,
2993
+ * 此阶段可以加载插件所需类型资源,并返回原始资源和加载后的资源。
2994
+ * @param scene
2995
+ * @param options
2996
+ * @returns
2997
+ */ _proto.processAssets = function processAssets(scene, options) {
2998
+ return _async_to_generator(function() {
2999
+ return __generator(this, function(_state) {
3000
+ return [
3001
+ 2
3002
+ ];
3003
+ });
3004
+ })();
3005
+ };
3006
+ /**
3007
+ * loadScene 函数调用的时候会触发此函数,
3008
+ * 此阶段时,json 中的图片和二进制已经被加载完成,可以对加载好的资源做进一步处理,
3009
+ * 如果 promise 被 reject, loadScene 函数同样会被 reject,表示场景加载失败。
3010
+ * 请记住,整个 load 阶段都不要创建 GL 相关的对象,只创建 JS 对象
3011
+ * 此阶段晚于 processAssets
3012
+ * @param {Scene} scene
3013
+ * @param {SceneLoadOptions} options
3014
+ */ _proto.prepareResource = function prepareResource(scene, options, engine) {};
3094
3015
  _proto.onCompositionConstructed = function onCompositionConstructed(composition, scene) {};
3095
- _proto.onCompositionReset = function onCompositionReset(composition, frame) {};
3096
3016
  _proto.onCompositionDestroyed = function onCompositionDestroyed(composition) {};
3097
- _proto.onCompositionUpdate = function onCompositionUpdate(composition, dt) {};
3098
3017
  return AbstractPlugin;
3099
3018
  }();
3100
3019
 
@@ -4079,6 +3998,41 @@ var index$1 = /*#__PURE__*/Object.freeze({
4079
3998
  get VertexBufferSemantic () { return VertexBufferSemantic; }
4080
3999
  });
4081
4000
 
4001
+ function _array_like_to_array(arr, len) {
4002
+ if (len == null || len > arr.length) len = arr.length;
4003
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4004
+ return arr2;
4005
+ }
4006
+
4007
+ function _unsupported_iterable_to_array(o, minLen) {
4008
+ if (!o) return;
4009
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
4010
+ var n = Object.prototype.toString.call(o).slice(8, -1);
4011
+ if (n === "Object" && o.constructor) n = o.constructor.name;
4012
+ if (n === "Map" || n === "Set") return Array.from(n);
4013
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
4014
+ }
4015
+
4016
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
4017
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
4018
+ if (it) return (it = it.call(o)).next.bind(it);
4019
+ // Fallback for engines without symbol support
4020
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
4021
+ if (it) o = it;
4022
+ var i = 0;
4023
+ return function() {
4024
+ if (i >= o.length) return {
4025
+ done: true
4026
+ };
4027
+ return {
4028
+ done: false,
4029
+ value: o[i++]
4030
+ };
4031
+ };
4032
+ }
4033
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4034
+ }
4035
+
4082
4036
  var decoratorInitialStore = new Map();
4083
4037
  var mergedStore = new Map();
4084
4038
  var effectsClassStore = {};
@@ -10377,175 +10331,72 @@ var MaskProcessor = /*#__PURE__*/ function() {
10377
10331
  return MaskProcessor;
10378
10332
  }();
10379
10333
 
10380
- exports.ShaderCompileResultStatus = void 0;
10381
- (function(ShaderCompileResultStatus) {
10382
- ShaderCompileResultStatus[ShaderCompileResultStatus["noShader"] = 0] = "noShader";
10383
- ShaderCompileResultStatus[ShaderCompileResultStatus["success"] = 1] = "success";
10384
- ShaderCompileResultStatus[ShaderCompileResultStatus["fail"] = 2] = "fail";
10385
- ShaderCompileResultStatus[ShaderCompileResultStatus["compiling"] = 3] = "compiling";
10386
- })(exports.ShaderCompileResultStatus || (exports.ShaderCompileResultStatus = {}));
10387
- exports.GLSLVersion = void 0;
10388
- (function(GLSLVersion) {
10389
- GLSLVersion["GLSL1"] = "100";
10390
- GLSLVersion["GLSL3"] = "300 es";
10391
- })(exports.GLSLVersion || (exports.GLSLVersion = {}));
10392
- var ShaderVariant = /*#__PURE__*/ function(EffectsObject) {
10393
- _inherits(ShaderVariant, EffectsObject);
10394
- function ShaderVariant(engine, source) {
10395
- var _this;
10396
- _this = EffectsObject.call(this, engine) || this;
10397
- _this.source = source;
10398
- return _this;
10399
- }
10400
- return ShaderVariant;
10401
- }(EffectsObject);
10402
- exports.Shader = /*#__PURE__*/ function(EffectsObject) {
10403
- _inherits(Shader, EffectsObject);
10404
- function Shader() {
10405
- return EffectsObject.apply(this, arguments);
10406
- }
10407
- var _proto = Shader.prototype;
10408
- _proto.createVariant = function createVariant(macros) {
10409
- var shaderMacros = [];
10410
- if (macros) {
10411
- for(var _iterator = _create_for_of_iterator_helper_loose(Object.keys(macros)), _step; !(_step = _iterator()).done;){
10412
- var key = _step.value;
10413
- shaderMacros.push([
10414
- key,
10415
- macros[key]
10416
- ]);
10417
- }
10418
- }
10419
- var shaderVariant = this.engine.getShaderLibrary().createShader(this.shaderData, shaderMacros);
10420
- shaderVariant.shader = this;
10421
- return shaderVariant;
10422
- };
10423
- _proto.fromData = function fromData(data) {
10424
- EffectsObject.prototype.fromData.call(this, data);
10425
- this.shaderData = data;
10426
- };
10427
- return Shader;
10428
- }(EffectsObject);
10429
- exports.Shader = __decorate([
10430
- effectsClass(DataType.Shader)
10431
- ], exports.Shader);
10432
-
10433
10334
  var EFFECTS_COPY_MESH_NAME = "effects-internal-copy";
10434
10335
  var COPY_MESH_SHADER_ID = "effects-internal-copy-mesh";
10435
10336
  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}";
10436
10337
  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";
10437
- function createCopyShader(level, writeDepth) {
10438
- var webgl2 = level === 2;
10439
- return {
10440
- name: EFFECTS_COPY_MESH_NAME,
10441
- vertex: COPY_VERTEX_SHADER,
10442
- fragment: COPY_FRAGMENT_SHADER,
10443
- glslVersion: webgl2 ? exports.GLSLVersion.GLSL3 : exports.GLSLVersion.GLSL1,
10444
- macros: [
10445
- [
10446
- "DEPTH_TEXTURE",
10447
- !!writeDepth
10448
- ]
10449
- ],
10450
- // @ts-expect-error
10451
- cacheId: COPY_MESH_SHADER_ID + +writeDepth
10452
- };
10453
- }
10454
10338
 
10455
- var def = {
10456
- format: glContext.RGBA,
10457
- type: glContext.UNSIGNED_BYTE,
10458
- minFilter: glContext.LINEAR,
10459
- magFilter: glContext.LINEAR,
10460
- wrapS: glContext.CLAMP_TO_EDGE,
10461
- wrapT: glContext.CLAMP_TO_EDGE
10462
- };
10463
- var disposeSymbol = Symbol("dispose");
10464
- var PassTextureCache = /*#__PURE__*/ function() {
10465
- function PassTextureCache(engine) {
10466
- this.textureCache = {};
10467
- this.textureRef = {};
10468
- this.engine = engine;
10469
- }
10470
- var _proto = PassTextureCache.prototype;
10471
- _proto.requestColorAttachmentTexture = function requestColorAttachmentTexture(request) {
10472
- var _this = this;
10473
- var width = request.width, height = request.height, name = request.name;
10474
- var options = {
10475
- sourceType: exports.TextureSourceType.framebuffer,
10476
- data: {
10477
- width: width,
10478
- height: height
10479
- },
10480
- name: name
10481
- };
10482
- var keys = [
10483
- name
10484
- ];
10485
- Object.getOwnPropertyNames(def).forEach(function(name) {
10486
- var _request_name;
10487
- var value = (_request_name = request[name]) != null ? _request_name : def[name];
10488
- options[name] = value;
10489
- keys.push(name, value);
10490
- });
10491
- var cacheId = keys.join(":");
10492
- var tex = this.textureCache[cacheId];
10493
- if (tex) {
10494
- this.textureRef[cacheId]++;
10495
- } else {
10496
- var engine = this.engine;
10497
- assertExist(engine);
10498
- tex = Texture.create(engine, options);
10499
- this.textureCache[cacheId] = tex;
10500
- this.textureRef[cacheId] = 1;
10501
- // @ts-expect-error
10502
- tex[disposeSymbol] = tex.dispose;
10503
- tex.dispose = function() {
10504
- return _this.removeTexture(cacheId);
10505
- };
10506
- }
10507
- return tex;
10339
+ exports.FilterMode = void 0;
10340
+ (function(FilterMode) {
10341
+ FilterMode[FilterMode["Nearest"] = 0] = "Nearest";
10342
+ FilterMode[FilterMode["Linear"] = 1] = "Linear";
10343
+ })(exports.FilterMode || (exports.FilterMode = {}));
10344
+ exports.RenderTextureFormat = void 0;
10345
+ (function(RenderTextureFormat) {
10346
+ RenderTextureFormat[RenderTextureFormat["RGBA32"] = 0] = "RGBA32";
10347
+ RenderTextureFormat[RenderTextureFormat["RGBAHalf"] = 1] = "RGBAHalf";
10348
+ })(exports.RenderTextureFormat || (exports.RenderTextureFormat = {}));
10349
+ /**
10350
+ *
10351
+ */ var Framebuffer = /*#__PURE__*/ function() {
10352
+ function Framebuffer() {}
10353
+ var _proto = Framebuffer.prototype;
10354
+ _proto.resize = function resize(x, y, width, height) {
10355
+ // OVERRIDE
10508
10356
  };
10509
- _proto.removeTexture = function removeTexture(id) {
10510
- var refCount = this.textureRef[id];
10511
- if (refCount <= 1) {
10512
- if (refCount < 0) {
10513
- console.error("Ref count < 0.");
10357
+ _proto.resetColorTextures = function resetColorTextures(textures) {
10358
+ // OVERRIDE
10359
+ };
10360
+ _proto.unbind = function unbind() {
10361
+ // OVERRIDE
10362
+ };
10363
+ _proto.bind = function bind() {
10364
+ // OVERRIDE
10365
+ };
10366
+ _proto.getDepthTexture = function getDepthTexture() {
10367
+ // OVERRIDE
10368
+ return undefined;
10369
+ };
10370
+ _proto.getStencilTexture = function getStencilTexture() {
10371
+ // OVERRIDE
10372
+ return undefined;
10373
+ };
10374
+ _proto.getColorTextures = function getColorTextures() {
10375
+ // OVERRIDE
10376
+ return [];
10377
+ };
10378
+ _proto.dispose = function dispose(options) {
10379
+ // OVERRIDE
10380
+ };
10381
+ _create_class(Framebuffer, [
10382
+ {
10383
+ key: "stencilStorage",
10384
+ get: function get() {
10385
+ // OVERRIDE
10386
+ return undefined;
10514
10387
  }
10515
- var tex = this.textureCache[id];
10516
- if (tex) {
10517
- // @ts-expect-error
10518
- tex[disposeSymbol]();
10519
- // @ts-expect-error
10520
- tex.dispose = tex[disposeSymbol];
10388
+ },
10389
+ {
10390
+ key: "depthStorage",
10391
+ get: function get() {
10392
+ // OVERRIDE
10393
+ return undefined;
10521
10394
  }
10522
- delete this.textureCache[id];
10523
- delete this.textureRef[id];
10524
- } else {
10525
- this.textureRef[id] = refCount - 1;
10526
10395
  }
10527
- };
10528
- _proto.dispose = function dispose() {
10529
- var _this = this;
10530
- Object.keys(this.textureCache).forEach(function(key) {
10531
- var texture = _this.textureCache[key];
10532
- // @ts-expect-error
10533
- texture[disposeSymbol]();
10534
- // @ts-expect-error
10535
- texture.dispose = texture[disposeSymbol];
10536
- });
10537
- this.textureCache = {};
10538
- this.textureRef = {};
10539
- this.engine = undefined;
10540
- };
10541
- return PassTextureCache;
10396
+ ]);
10397
+ return Framebuffer;
10542
10398
  }();
10543
10399
 
10544
- function _assert_this_initialized(self) {
10545
- if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
10546
- return self;
10547
- }
10548
-
10549
10400
  var RenderPassPriorityPrepare = 0;
10550
10401
  var RenderPassPriorityNormal = 1000;
10551
10402
  var RenderPassPriorityPostprocess = 3000;
@@ -10555,7 +10406,7 @@ exports.RenderPassAttachmentStorageType = void 0;
10555
10406
  RenderPassAttachmentStorageType[RenderPassAttachmentStorageType["color"] = 1] = "color";
10556
10407
  //stencil 8 render buffer
10557
10408
  RenderPassAttachmentStorageType[RenderPassAttachmentStorageType["stencil_8_opaque"] = 2] = "stencil_8_opaque";
10558
- //stencil 16 render buffer
10409
+ //depth 16 render buffer
10559
10410
  RenderPassAttachmentStorageType[RenderPassAttachmentStorageType["depth_16_opaque"] = 3] = "depth_16_opaque";
10560
10411
  //depth 16 & stencil 8 render buffer
10561
10412
  RenderPassAttachmentStorageType[RenderPassAttachmentStorageType["depth_stencil_opaque"] = 4] = "depth_stencil_opaque";
@@ -10674,61 +10525,31 @@ var seed$8 = 1;
10674
10525
  /**
10675
10526
  * RenderPass 抽象类
10676
10527
  */ var RenderPass = /*#__PURE__*/ function() {
10677
- function RenderPass(renderer, options) {
10528
+ function RenderPass(renderer) {
10678
10529
  /**
10679
10530
  * 优先级
10680
10531
  */ this.priority = 0;
10681
10532
  /**
10682
- * ColorAttachment 数组
10683
- */ this.attachments = [];
10684
- /**
10685
10533
  * 名称
10686
10534
  */ this.name = "RenderPass" + seed$8++;
10687
10535
  /**
10688
10536
  * 包含的 Mesh 列表
10689
10537
  */ this.meshes = [];
10690
- /**
10691
- * Mesh 渲染顺序,按照优先级升序或降序
10692
- */ this.meshOrder = exports.OrderType.ascending;
10693
10538
  this.disposed = false;
10694
- this.initialized = false;
10695
- var depthStencilAttachment = options.depthStencilAttachment;
10539
+ this.framebuffer = null;
10696
10540
  this.renderer = renderer;
10697
- this.depthStencilType = (depthStencilAttachment == null ? void 0 : depthStencilAttachment.storageType) || 0;
10698
- this.storeAction = {
10699
- colorAction: 0,
10700
- depthAction: 0,
10701
- stencilAction: 0
10702
- };
10703
- this.options = options;
10704
10541
  }
10705
10542
  var _proto = RenderPass.prototype;
10706
10543
  _proto.addMesh = function addMesh(mesh) {
10707
- addByOrder(this.meshes, mesh, this.meshOrder);
10544
+ addByOrder(this.meshes, mesh);
10708
10545
  };
10709
10546
  _proto.removeMesh = function removeMesh(mesh) {
10710
10547
  removeItem(this.meshes, mesh);
10711
10548
  };
10712
- _proto.setMeshes = function setMeshes(meshes) {
10713
- var _this_meshes;
10714
- this.meshes.length = 0;
10715
- (_this_meshes = this.meshes).splice.apply(_this_meshes, [].concat([
10716
- 0,
10717
- 0
10718
- ], meshes));
10719
- sortByOrder(this.meshes, this.meshOrder);
10720
- return this.meshes;
10721
- };
10722
- // TODO 所有pass在子类配置
10723
10549
  /**
10724
10550
  * 配置当前pass的RT,在每帧渲染前调用
10725
10551
  */ _proto.configure = function configure(renderer) {
10726
- if (this.framebuffer) {
10727
- renderer.setFramebuffer(this.framebuffer);
10728
- } else {
10729
- var _this_getViewport = this.getViewport(), x = _this_getViewport[0], y = _this_getViewport[1], width = _this_getViewport[2], height = _this_getViewport[3];
10730
- renderer.setViewport(x, y, width, height);
10731
- }
10552
+ // OVERRIDE
10732
10553
  };
10733
10554
  /**
10734
10555
  * 执行当前pass,每帧调用一次
@@ -10736,66 +10557,10 @@ var seed$8 = 1;
10736
10557
  // OVERRIDE
10737
10558
  };
10738
10559
  /**
10739
- * 每帧所有的pass渲染完后调用,通常用于清空临时的RT资源
10740
- */ _proto.frameCleanup = function frameCleanup(renderer) {
10560
+ * 每帧所有的pass渲染完后调用,用于清空临时的RT资源
10561
+ */ _proto.onCameraCleanup = function onCameraCleanup(renderer) {
10741
10562
  // OVERRIDE
10742
10563
  };
10743
- _proto._resetAttachments = function _resetAttachments() {
10744
- var _this = this;
10745
- var _options_attachments;
10746
- var renderer = this.renderer;
10747
- var options = this.options;
10748
- if (this.attachments.length) {
10749
- var _this_framebuffer;
10750
- this.attachments.forEach(function(att) {
10751
- return !att.externalTexture && att.dispose();
10752
- });
10753
- this.attachments.length = 0;
10754
- (_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.dispose({
10755
- depthStencilAttachment: 2
10756
- });
10757
- this.framebuffer = null;
10758
- }
10759
- // renderpass 的 viewport 相关参数都需要动态的修改
10760
- var viewport = [
10761
- 0,
10762
- 0,
10763
- renderer.getWidth(),
10764
- renderer.getHeight()
10765
- ];
10766
- var size = [
10767
- viewport[2],
10768
- viewport[3]
10769
- ];
10770
- var name = this.name;
10771
- if ((_options_attachments = options.attachments) == null ? void 0 : _options_attachments.length) {
10772
- var attachments = options.attachments.map(function(attr, index) {
10773
- var _attr_texture;
10774
- var attachment = new RenderTargetHandle(_this.renderer.engine, _extends({
10775
- size: size,
10776
- name: ((_attr_texture = attr.texture) == null ? void 0 : _attr_texture.name) || name + "##color_" + index
10777
- }, attr));
10778
- return attachment;
10779
- });
10780
- this.attachments = attachments;
10781
- var framebuffer = Framebuffer.create({
10782
- storeAction: this.storeAction,
10783
- name: name,
10784
- viewport: viewport,
10785
- attachments: attachments.map(function(att) {
10786
- return att.texture;
10787
- }),
10788
- depthStencilAttachment: options.depthStencilAttachment || {
10789
- storageType: 0
10790
- }
10791
- }, renderer);
10792
- framebuffer.bind();
10793
- framebuffer.unbind();
10794
- this.framebuffer = framebuffer;
10795
- } else {
10796
- this.attachments.length = 0;
10797
- }
10798
- };
10799
10564
  /**
10800
10565
  * 获取当前视口大小,格式:[x偏移,y偏移,宽度,高度]
10801
10566
  */ _proto.getViewport = function getViewport() {
@@ -10818,68 +10583,6 @@ var seed$8 = 1;
10818
10583
  ];
10819
10584
  };
10820
10585
  /**
10821
- * 获取深度 Attachment,可能没有
10822
- */ _proto.getDepthAttachment = function getDepthAttachment() {
10823
- var framebuffer = this.framebuffer;
10824
- if (framebuffer) {
10825
- var depthTexture = framebuffer.getDepthTexture();
10826
- var texture = depthTexture ? this.getDepthTexture(depthTexture, framebuffer.externalStorage) : undefined;
10827
- return {
10828
- storageType: framebuffer.depthStencilStorageType,
10829
- storage: framebuffer.depthStorage,
10830
- texture: texture
10831
- };
10832
- }
10833
- };
10834
- /**
10835
- * 获取蒙版 Attachment,可能没有
10836
- */ _proto.getStencilAttachment = function getStencilAttachment() {
10837
- var framebuffer = this.framebuffer;
10838
- if (framebuffer) {
10839
- var stencilTexture = framebuffer.getStencilTexture();
10840
- var texture = stencilTexture ? this.getDepthTexture(stencilTexture, framebuffer.externalStorage) : undefined;
10841
- return {
10842
- storageType: framebuffer.depthStencilStorageType,
10843
- storage: framebuffer.stencilStorage,
10844
- texture: texture
10845
- };
10846
- }
10847
- };
10848
- _proto.getDepthTexture = function getDepthTexture(texture, external) {
10849
- if (!this.depthTexture) {
10850
- var _this_options_depthStencilAttachment;
10851
- var outTex = (_this_options_depthStencilAttachment = this.options.depthStencilAttachment) == null ? void 0 : _this_options_depthStencilAttachment.texture;
10852
- var tex = texture === outTex ? outTex : texture;
10853
- // TODO 为什么要initialize?
10854
- //tex.initialize(this.renderer.engine);
10855
- if (!external) {
10856
- this.depthTexture = tex;
10857
- }
10858
- return tex;
10859
- }
10860
- return this.depthTexture;
10861
- };
10862
- _proto.getStencilTexture = function getStencilTexture(texture, external) {
10863
- if (!this.stencilTexture) {
10864
- var _this_options_depthStencilAttachment;
10865
- var outTex = (_this_options_depthStencilAttachment = this.options.depthStencilAttachment) == null ? void 0 : _this_options_depthStencilAttachment.texture;
10866
- var tex = texture === outTex ? outTex : texture;
10867
- if (!external) {
10868
- this.stencilTexture = tex;
10869
- }
10870
- return tex;
10871
- }
10872
- return this.stencilTexture;
10873
- };
10874
- // 生成并初始化帧缓冲
10875
- _proto.initialize = function initialize(renderer) {
10876
- if (!this.initialized) {
10877
- this._resetAttachments();
10878
- this.initialized = true;
10879
- }
10880
- return this;
10881
- };
10882
- /**
10883
10586
  * 销毁 RenderPass
10884
10587
  * @param options - 有选择销毁内部对象
10885
10588
  */ _proto.dispose = function dispose(options) {
@@ -10893,35 +10596,11 @@ var seed$8 = 1;
10893
10596
  });
10894
10597
  }
10895
10598
  this.meshes.length = 0;
10896
- var colorOpt = (options == null ? void 0 : options.colorAttachment) ? options.colorAttachment : 0;
10897
- this.attachments.forEach(function(att) {
10898
- var keep = att.externalTexture && colorOpt === 2 || colorOpt === 1;
10899
- if (!keep) {
10900
- att.dispose();
10901
- }
10902
- });
10903
- this.attachments.length = 0;
10904
10599
  this.disposed = true;
10905
- var depthStencilOpt = (options == null ? void 0 : options.depthStencilAttachment) ? options.depthStencilAttachment : 0;
10906
- var fbo = this.framebuffer;
10907
- if (fbo) {
10908
- fbo.dispose({
10909
- depthStencilAttachment: depthStencilOpt
10910
- });
10911
- var keep = fbo.externalStorage && depthStencilOpt === 2 || depthStencilOpt === 1;
10912
- if (!keep) {
10913
- var _this_stencilTexture, _this_depthTexture;
10914
- (_this_stencilTexture = this.stencilTexture) == null ? void 0 : _this_stencilTexture.dispose();
10915
- (_this_depthTexture = this.depthTexture) == null ? void 0 : _this_depthTexture.dispose();
10916
- }
10917
- }
10918
- // @ts-expect-error safe to assign
10919
- this.options = null;
10920
- this.initialize = throwDestroyedError;
10921
10600
  };
10922
10601
  _create_class(RenderPass, [
10923
10602
  {
10924
- key: "isDestroyed",
10603
+ key: "isDisposed",
10925
10604
  get: function get() {
10926
10605
  return this.disposed;
10927
10606
  }
@@ -10931,18 +10610,6 @@ var seed$8 = 1;
10931
10610
  get: function get() {
10932
10611
  return this.getViewport();
10933
10612
  }
10934
- },
10935
- {
10936
- key: "stencilAttachment",
10937
- get: function get() {
10938
- return this.getStencilAttachment();
10939
- }
10940
- },
10941
- {
10942
- key: "depthAttachment",
10943
- get: function get() {
10944
- return this.getDepthAttachment();
10945
- }
10946
10613
  }
10947
10614
  ]);
10948
10615
  return RenderPass;
@@ -10950,38 +10617,95 @@ var seed$8 = 1;
10950
10617
 
10951
10618
  var DrawObjectPass = /*#__PURE__*/ function(RenderPass) {
10952
10619
  _inherits(DrawObjectPass, RenderPass);
10953
- function DrawObjectPass(renderer, options) {
10620
+ function DrawObjectPass(renderer) {
10954
10621
  var _this;
10955
- _this = RenderPass.call(this, renderer, options) || this;
10622
+ _this = RenderPass.call(this, renderer) || this;
10623
+ _this.useRenderTarget = false;
10956
10624
  _this.priority = RenderPassPriorityNormal;
10957
10625
  _this.name = "DrawObjectPass";
10958
- _this.onResize = _this.onResize.bind(_assert_this_initialized(_this));
10959
- _this.renderer.engine.on("resize", _this.onResize);
10960
10626
  return _this;
10961
10627
  }
10962
10628
  var _proto = DrawObjectPass.prototype;
10629
+ _proto.setup = function setup(useRenderTarget) {
10630
+ this.useRenderTarget = useRenderTarget;
10631
+ };
10632
+ _proto.configure = function configure(renderer) {
10633
+ if (this.useRenderTarget) {
10634
+ this.framebuffer = renderer.getTemporaryRT("DrawObjectPass", renderer.getWidth(), renderer.getHeight(), 16, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
10635
+ renderer.setFramebuffer(this.framebuffer);
10636
+ }
10637
+ };
10963
10638
  _proto.execute = function execute(renderer) {
10964
- renderer.clear({
10965
- colorAction: exports.TextureLoadAction.clear,
10966
- depthAction: exports.TextureLoadAction.clear,
10967
- stencilAction: exports.TextureLoadAction.clear
10968
- });
10639
+ if (this.useRenderTarget) {
10640
+ renderer.clear({
10641
+ colorAction: exports.TextureLoadAction.clear,
10642
+ depthAction: exports.TextureLoadAction.clear,
10643
+ stencilAction: exports.TextureLoadAction.clear
10644
+ });
10645
+ }
10969
10646
  renderer.renderMeshes(this.meshes);
10970
- renderer.clear(this.storeAction);
10971
- };
10972
- _proto.onResize = function onResize() {
10973
- var _this_framebuffer;
10974
- var width = this.renderer.getWidth();
10975
- var height = this.renderer.getHeight();
10976
- (_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.resize(0, 0, width, height);
10977
10647
  };
10978
- _proto.dispose = function dispose(options) {
10979
- this.renderer.engine.off("resize", this.onResize);
10980
- RenderPass.prototype.dispose.call(this, options);
10648
+ _proto.onCameraCleanup = function onCameraCleanup(renderer) {
10649
+ if (this.useRenderTarget && this.framebuffer) {
10650
+ renderer.releaseTemporaryRT(this.framebuffer);
10651
+ }
10981
10652
  };
10982
10653
  return DrawObjectPass;
10983
10654
  }(RenderPass);
10984
10655
 
10656
+ exports.ShaderCompileResultStatus = void 0;
10657
+ (function(ShaderCompileResultStatus) {
10658
+ ShaderCompileResultStatus[ShaderCompileResultStatus["noShader"] = 0] = "noShader";
10659
+ ShaderCompileResultStatus[ShaderCompileResultStatus["success"] = 1] = "success";
10660
+ ShaderCompileResultStatus[ShaderCompileResultStatus["fail"] = 2] = "fail";
10661
+ ShaderCompileResultStatus[ShaderCompileResultStatus["compiling"] = 3] = "compiling";
10662
+ })(exports.ShaderCompileResultStatus || (exports.ShaderCompileResultStatus = {}));
10663
+ exports.GLSLVersion = void 0;
10664
+ (function(GLSLVersion) {
10665
+ GLSLVersion["GLSL1"] = "100";
10666
+ GLSLVersion["GLSL3"] = "300 es";
10667
+ })(exports.GLSLVersion || (exports.GLSLVersion = {}));
10668
+ var ShaderVariant = /*#__PURE__*/ function(EffectsObject) {
10669
+ _inherits(ShaderVariant, EffectsObject);
10670
+ function ShaderVariant(engine, source) {
10671
+ var _this;
10672
+ _this = EffectsObject.call(this, engine) || this;
10673
+ _this.source = source;
10674
+ return _this;
10675
+ }
10676
+ return ShaderVariant;
10677
+ }(EffectsObject);
10678
+ exports.Shader = /*#__PURE__*/ function(EffectsObject) {
10679
+ _inherits(Shader, EffectsObject);
10680
+ function Shader() {
10681
+ return EffectsObject.apply(this, arguments);
10682
+ }
10683
+ var _proto = Shader.prototype;
10684
+ _proto.createVariant = function createVariant(macros) {
10685
+ var shaderMacros = [];
10686
+ if (macros) {
10687
+ for(var _iterator = _create_for_of_iterator_helper_loose(Object.keys(macros)), _step; !(_step = _iterator()).done;){
10688
+ var key = _step.value;
10689
+ shaderMacros.push([
10690
+ key,
10691
+ macros[key]
10692
+ ]);
10693
+ }
10694
+ }
10695
+ var shaderVariant = this.engine.getShaderLibrary().createShader(this.shaderData, shaderMacros);
10696
+ shaderVariant.shader = this;
10697
+ return shaderVariant;
10698
+ };
10699
+ _proto.fromData = function fromData(data) {
10700
+ EffectsObject.prototype.fromData.call(this, data);
10701
+ this.shaderData = data;
10702
+ };
10703
+ return Shader;
10704
+ }(EffectsObject);
10705
+ exports.Shader = __decorate([
10706
+ effectsClass(DataType.Shader)
10707
+ ], exports.Shader);
10708
+
10985
10709
  var _obj$6;
10986
10710
  var BYTES_TYPE_MAP = (_obj$6 = {}, _obj$6[glContext.FLOAT] = Float32Array.BYTES_PER_ELEMENT, _obj$6[glContext.INT] = Int32Array.BYTES_PER_ELEMENT, _obj$6[glContext.SHORT] = Int16Array.BYTES_PER_ELEMENT, _obj$6[glContext.BYTE] = Int8Array.BYTES_PER_ELEMENT, _obj$6);
10987
10711
  /**
@@ -13023,9 +12747,9 @@ var ShaderFactory = /*#__PURE__*/ function() {
13023
12747
  // Bloom 阈值 Pass
13024
12748
  var BloomThresholdPass = /*#__PURE__*/ function(RenderPass) {
13025
12749
  _inherits(BloomThresholdPass, RenderPass);
13026
- function BloomThresholdPass(renderer, option) {
12750
+ function BloomThresholdPass(renderer) {
13027
12751
  var _this;
13028
- _this = RenderPass.call(this, renderer, option) || this;
12752
+ _this = RenderPass.call(this, renderer) || this;
13029
12753
  var engine = _this.renderer.engine;
13030
12754
  var geometry = Geometry.create(engine, {
13031
12755
  mode: glContext.TRIANGLE_STRIP,
@@ -13064,12 +12788,11 @@ var BloomThresholdPass = /*#__PURE__*/ function(RenderPass) {
13064
12788
  });
13065
12789
  _this.priority = 5000;
13066
12790
  _this.name = "BloomThresholdPass";
13067
- _this.onResize = _this.onResize.bind(_assert_this_initialized(_this));
13068
- _this.renderer.engine.on("resize", _this.onResize);
13069
12791
  return _this;
13070
12792
  }
13071
12793
  var _proto = BloomThresholdPass.prototype;
13072
12794
  _proto.configure = function configure(renderer) {
12795
+ this.framebuffer = renderer.getTemporaryRT(this.name, renderer.getWidth(), renderer.getHeight(), 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
13073
12796
  this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
13074
12797
  this.sceneTextureHandle.texture = this.mainTexture;
13075
12798
  renderer.setFramebuffer(this.framebuffer);
@@ -13077,9 +12800,9 @@ var BloomThresholdPass = /*#__PURE__*/ function(RenderPass) {
13077
12800
  _proto.execute = function execute(renderer) {
13078
12801
  var _renderer_renderingData_currentFrame_globalVolume_bloom, _renderer_renderingData_currentFrame_globalVolume;
13079
12802
  renderer.clear({
13080
- colorAction: exports.TextureStoreAction.clear,
13081
- depthAction: exports.TextureStoreAction.clear,
13082
- stencilAction: exports.TextureStoreAction.clear
12803
+ colorAction: exports.TextureLoadAction.clear,
12804
+ depthAction: exports.TextureLoadAction.clear,
12805
+ stencilAction: exports.TextureLoadAction.clear
13083
12806
  });
13084
12807
  this.screenMesh.material.setTexture("_MainTex", this.mainTexture);
13085
12808
  var _renderer_renderingData_currentFrame_globalVolume_bloom_threshold;
@@ -13089,23 +12812,21 @@ var BloomThresholdPass = /*#__PURE__*/ function(RenderPass) {
13089
12812
  this.screenMesh
13090
12813
  ]);
13091
12814
  };
13092
- _proto.onResize = function onResize() {
13093
- var _this_framebuffer;
13094
- var width = this.renderer.getWidth();
13095
- var height = this.renderer.getHeight();
13096
- (_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.resize(0, 0, width, height);
12815
+ _proto.onCameraCleanup = function onCameraCleanup(renderer) {
12816
+ if (this.framebuffer) {
12817
+ renderer.releaseTemporaryRT(this.framebuffer);
12818
+ }
13097
12819
  };
13098
12820
  _proto.dispose = function dispose(options) {
13099
- this.renderer.engine.off("resize", this.onResize);
13100
12821
  RenderPass.prototype.dispose.call(this, options);
13101
12822
  };
13102
12823
  return BloomThresholdPass;
13103
12824
  }(RenderPass);
13104
12825
  var HQGaussianDownSamplePass = /*#__PURE__*/ function(RenderPass) {
13105
12826
  _inherits(HQGaussianDownSamplePass, RenderPass);
13106
- function HQGaussianDownSamplePass(renderer, type, level, options) {
12827
+ function HQGaussianDownSamplePass(renderer, type, level) {
13107
12828
  var _this;
13108
- _this = RenderPass.call(this, renderer, options) || this;
12829
+ _this = RenderPass.call(this, renderer) || this;
13109
12830
  _this.type = type;
13110
12831
  _this.level = level;
13111
12832
  var engine = _this.renderer.engine;
@@ -13152,25 +12873,21 @@ var HQGaussianDownSamplePass = /*#__PURE__*/ function(RenderPass) {
13152
12873
  });
13153
12874
  _this.priority = 5000;
13154
12875
  _this.name = "GaussianDownPass" + type + level;
13155
- _this.onResize = _this.onResize.bind(_assert_this_initialized(_this));
13156
- _this.renderer.engine.on("resize", _this.onResize);
13157
12876
  return _this;
13158
12877
  }
13159
12878
  var _proto = HQGaussianDownSamplePass.prototype;
13160
- _proto.initialize = function initialize(renderer) {
13161
- RenderPass.prototype.initialize.call(this, renderer);
13162
- this.onResize();
13163
- return this;
13164
- };
13165
12879
  _proto.configure = function configure(renderer) {
12880
+ var width = Math.floor(this.renderer.getWidth() / Math.pow(2, this.level + 1));
12881
+ var height = Math.floor(this.renderer.getHeight() / Math.pow(2, this.level + 1));
12882
+ this.framebuffer = renderer.getTemporaryRT(this.name, width, height, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
13166
12883
  this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
13167
12884
  renderer.setFramebuffer(this.framebuffer);
13168
12885
  };
13169
12886
  _proto.execute = function execute(renderer) {
13170
12887
  renderer.clear({
13171
- colorAction: exports.TextureStoreAction.clear,
13172
- depthAction: exports.TextureStoreAction.clear,
13173
- stencilAction: exports.TextureStoreAction.clear
12888
+ colorAction: exports.TextureLoadAction.clear,
12889
+ depthAction: exports.TextureLoadAction.clear,
12890
+ stencilAction: exports.TextureLoadAction.clear
13174
12891
  });
13175
12892
  this.screenMesh.material.setTexture("_MainTex", this.mainTexture);
13176
12893
  this.screenMesh.material.setVector2("_TextureSize", getTextureSize(this.mainTexture));
@@ -13181,23 +12898,18 @@ var HQGaussianDownSamplePass = /*#__PURE__*/ function(RenderPass) {
13181
12898
  this.gaussianResult.texture = renderer.getFramebuffer().getColorTextures()[0];
13182
12899
  }
13183
12900
  };
13184
- _proto.onResize = function onResize() {
13185
- var _this_framebuffer;
13186
- var width = Math.floor(this.renderer.getWidth() / Math.pow(2, this.level + 1));
13187
- var height = Math.floor(this.renderer.getHeight() / Math.pow(2, this.level + 1));
13188
- (_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.resize(0, 0, width, height);
13189
- };
13190
- _proto.dispose = function dispose(options) {
13191
- this.renderer.engine.off("resize", this.onResize);
13192
- RenderPass.prototype.dispose.call(this, options);
12901
+ _proto.onCameraCleanup = function onCameraCleanup(renderer) {
12902
+ if (this.framebuffer) {
12903
+ renderer.releaseTemporaryRT(this.framebuffer);
12904
+ }
13193
12905
  };
13194
12906
  return HQGaussianDownSamplePass;
13195
12907
  }(RenderPass);
13196
12908
  var HQGaussianUpSamplePass = /*#__PURE__*/ function(RenderPass) {
13197
12909
  _inherits(HQGaussianUpSamplePass, RenderPass);
13198
- function HQGaussianUpSamplePass(renderer, level, options) {
12910
+ function HQGaussianUpSamplePass(renderer, level) {
13199
12911
  var _this;
13200
- _this = RenderPass.call(this, renderer, options) || this;
12912
+ _this = RenderPass.call(this, renderer) || this;
13201
12913
  _this.level = level;
13202
12914
  var name = "PostProcess";
13203
12915
  var engine = _this.renderer.engine;
@@ -13241,25 +12953,21 @@ var HQGaussianUpSamplePass = /*#__PURE__*/ function(RenderPass) {
13241
12953
  });
13242
12954
  _this.priority = 5000;
13243
12955
  _this.name = "GaussianUpPass" + level;
13244
- _this.onResize = _this.onResize.bind(_assert_this_initialized(_this));
13245
- _this.renderer.engine.on("resize", _this.onResize);
13246
12956
  return _this;
13247
12957
  }
13248
12958
  var _proto = HQGaussianUpSamplePass.prototype;
13249
- _proto.initialize = function initialize(renderer) {
13250
- RenderPass.prototype.initialize.call(this, renderer);
13251
- this.onResize();
13252
- return this;
13253
- };
13254
12959
  _proto.configure = function configure(renderer) {
12960
+ var width = Math.floor(this.renderer.getWidth() / Math.pow(2, this.level - 1));
12961
+ var height = Math.floor(this.renderer.getHeight() / Math.pow(2, this.level - 1));
12962
+ this.framebuffer = renderer.getTemporaryRT(this.name, width, height, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
13255
12963
  this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
13256
12964
  renderer.setFramebuffer(this.framebuffer);
13257
12965
  };
13258
12966
  _proto.execute = function execute(renderer) {
13259
12967
  renderer.clear({
13260
- colorAction: exports.TextureStoreAction.clear,
13261
- depthAction: exports.TextureStoreAction.clear,
13262
- stencilAction: exports.TextureStoreAction.clear
12968
+ colorAction: exports.TextureLoadAction.clear,
12969
+ depthAction: exports.TextureLoadAction.clear,
12970
+ stencilAction: exports.TextureLoadAction.clear
13263
12971
  });
13264
12972
  this.screenMesh.material.setTexture("_MainTex", this.mainTexture);
13265
12973
  this.screenMesh.material.setTexture("_GaussianDownTex", this.gaussianDownSampleResult.texture);
@@ -13268,15 +12976,10 @@ var HQGaussianUpSamplePass = /*#__PURE__*/ function(RenderPass) {
13268
12976
  this.screenMesh
13269
12977
  ]);
13270
12978
  };
13271
- _proto.onResize = function onResize() {
13272
- var _this_framebuffer;
13273
- var width = Math.floor(this.renderer.getWidth() / Math.pow(2, this.level - 1));
13274
- var height = Math.floor(this.renderer.getHeight() / Math.pow(2, this.level - 1));
13275
- (_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.resize(0, 0, width, height);
13276
- };
13277
- _proto.dispose = function dispose(options) {
13278
- this.renderer.engine.off("resize", this.onResize);
13279
- RenderPass.prototype.dispose.call(this, options);
12979
+ _proto.onCameraCleanup = function onCameraCleanup(renderer) {
12980
+ if (this.framebuffer) {
12981
+ renderer.releaseTemporaryRT(this.framebuffer);
12982
+ }
13280
12983
  };
13281
12984
  return HQGaussianUpSamplePass;
13282
12985
  }(RenderPass);
@@ -13285,7 +12988,7 @@ var ToneMappingPass = /*#__PURE__*/ function(RenderPass) {
13285
12988
  _inherits(ToneMappingPass, RenderPass);
13286
12989
  function ToneMappingPass(renderer, sceneTextureHandle) {
13287
12990
  var _this;
13288
- _this = RenderPass.call(this, renderer, {}) || this;
12991
+ _this = RenderPass.call(this, renderer) || this;
13289
12992
  var name = "PostProcess";
13290
12993
  var engine = _this.renderer.engine;
13291
12994
  _this.sceneTextureHandle = sceneTextureHandle ? sceneTextureHandle : new RenderTargetHandle(engine);
@@ -13341,9 +13044,9 @@ var ToneMappingPass = /*#__PURE__*/ function(RenderPass) {
13341
13044
  };
13342
13045
  _proto.execute = function execute(renderer) {
13343
13046
  renderer.clear({
13344
- colorAction: exports.TextureStoreAction.clear,
13345
- depthAction: exports.TextureStoreAction.clear,
13346
- stencilAction: exports.TextureStoreAction.clear
13047
+ colorAction: exports.TextureLoadAction.clear,
13048
+ depthAction: exports.TextureLoadAction.clear,
13049
+ stencilAction: exports.TextureLoadAction.clear
13347
13050
  });
13348
13051
  var globalVolume = renderer.renderingData.currentFrame.globalVolume;
13349
13052
  var bloom = _extends({
@@ -13390,95 +13093,31 @@ var ToneMappingPass = /*#__PURE__*/ function(RenderPass) {
13390
13093
  return ToneMappingPass;
13391
13094
  }(RenderPass);
13392
13095
 
13393
- var SemanticMap = /*#__PURE__*/ function() {
13394
- function SemanticMap(semantics) {
13395
- if (semantics === void 0) semantics = {};
13396
- this.semantics = _extends({}, semantics);
13397
- }
13398
- var _proto = SemanticMap.prototype;
13399
- _proto.toObject = function toObject() {
13400
- return _extends({}, this.semantics);
13401
- };
13402
- _proto.setSemantic = function setSemantic(name, value) {
13403
- if (value === undefined) {
13404
- delete this.semantics[name];
13405
- } else {
13406
- this.semantics[name] = value;
13407
- }
13408
- };
13409
- _proto.getSemanticValue = function getSemanticValue(name, state) {
13410
- var ret = this.semantics[name];
13411
- if (isFunction(ret)) {
13412
- return ret(state);
13413
- }
13414
- return ret;
13415
- };
13416
- _proto.hasSemanticValue = function hasSemanticValue(name) {
13417
- return name in this.semantics;
13418
- };
13419
- _proto.dispose = function dispose() {
13420
- var _this = this;
13421
- Object.keys(this.semantics).forEach(function(name) {
13422
- delete _this.semantics[name];
13423
- });
13424
- };
13425
- return SemanticMap;
13426
- }();
13427
-
13428
- var RENDER_PASS_NAME_PREFIX = "_effects_default_";
13429
13096
  var seed$6 = 1;
13430
13097
  /**
13431
13098
  * RenderFrame 抽象类
13432
13099
  */ var RenderFrame = /*#__PURE__*/ function() {
13433
13100
  function RenderFrame(options) {
13434
- var _this_renderer_getShaderLibrary;
13435
- // TODO: 是否有用
13436
- this.renderQueue = [];
13437
- this.destroyed = false;
13438
- this.renderPassInfoMap = new WeakMap();
13439
- var camera = options.camera, keepColorBuffer = options.keepColorBuffer, renderer = options.renderer, _options_editorTransform = options.editorTransform, editorTransform = _options_editorTransform === void 0 ? [
13101
+ this.disposed = false;
13102
+ this.postProcessingEnabled = false;
13103
+ this.enableHDR = true;
13104
+ var camera = options.camera, renderer = options.renderer, _options_editorTransform = options.editorTransform, editorTransform = _options_editorTransform === void 0 ? [
13440
13105
  1,
13441
13106
  1,
13442
13107
  0,
13443
13108
  0
13444
- ] : _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 ? {
13445
- colorAction: exports.TextureLoadAction.whatever,
13446
- stencilAction: exports.TextureLoadAction.clear,
13447
- depthAction: exports.TextureLoadAction.whatever
13448
- } : _options_clearAction;
13109
+ ] : _options_editorTransform, globalVolume = options.globalVolume, _options_postProcessingEnabled = options.postProcessingEnabled, postProcessingEnabled = _options_postProcessingEnabled === void 0 ? false : _options_postProcessingEnabled;
13449
13110
  var engine = renderer.engine;
13450
13111
  if (globalVolume) {
13451
13112
  this.globalVolume = globalVolume;
13452
13113
  }
13114
+ this.postProcessingEnabled = postProcessingEnabled;
13453
13115
  this.globalUniforms = new GlobalUniforms();
13454
- var attachments = []; //渲染场景物体Pass的RT
13455
- var depthStencilAttachment;
13456
13116
  this.renderer = renderer;
13457
- if (postProcessingEnabled) {
13458
- var enableHDR = true;
13459
- if (!this.renderer.engine.gpuCapability.detail.halfFloatTexture) {
13460
- throw new Error("Half float texture is not supported.");
13461
- }
13462
- // 使用HDR浮点纹理,FLOAT在IOS上报错,使用HALF_FLOAT
13463
- var textureType = enableHDR ? glContext.HALF_FLOAT : glContext.UNSIGNED_BYTE;
13464
- attachments = [
13465
- {
13466
- texture: {
13467
- format: glContext.RGBA,
13468
- type: textureType,
13469
- magFilter: glContext.LINEAR,
13470
- minFilter: glContext.LINEAR
13471
- }
13472
- }
13473
- ];
13474
- depthStencilAttachment = {
13475
- storageType: exports.RenderPassAttachmentStorageType.depth_stencil_opaque
13476
- };
13117
+ if (postProcessingEnabled && this.enableHDR && !this.renderer.engine.gpuCapability.detail.halfFloatTexture) {
13118
+ throw new Error("Half float texture is not supported.");
13477
13119
  }
13478
- this.drawObjectPass = new DrawObjectPass(renderer, {
13479
- depthStencilAttachment: depthStencilAttachment,
13480
- attachments: attachments
13481
- });
13120
+ this.drawObjectPass = new DrawObjectPass(renderer);
13482
13121
  var renderPasses = [
13483
13122
  this.drawObjectPass
13484
13123
  ];
@@ -13493,48 +13132,13 @@ var seed$6 = 1;
13493
13132
  this.renderer.getHeight() / 2
13494
13133
  ];
13495
13134
  var gaussianDownResults = new Array(gaussianStep); //存放多个高斯Pass的模糊结果,用于Bloom
13496
- var enableHDR1 = true;
13497
- var textureType1 = enableHDR1 ? glContext.HALF_FLOAT : glContext.UNSIGNED_BYTE;
13498
- var bloomThresholdPass = new BloomThresholdPass(renderer, {
13499
- attachments: [
13500
- {
13501
- texture: {
13502
- format: glContext.RGBA,
13503
- type: textureType1,
13504
- minFilter: glContext.LINEAR,
13505
- magFilter: glContext.LINEAR
13506
- }
13507
- }
13508
- ]
13509
- });
13135
+ var bloomThresholdPass = new BloomThresholdPass(renderer);
13510
13136
  bloomThresholdPass.sceneTextureHandle = sceneTextureHandle;
13511
13137
  this.addRenderPass(bloomThresholdPass);
13512
13138
  for(var i = 0; i < gaussianStep; i++){
13513
13139
  gaussianDownResults[i] = new RenderTargetHandle(engine);
13514
- var gaussianDownHPass = new HQGaussianDownSamplePass(renderer, "H", i, {
13515
- attachments: [
13516
- {
13517
- texture: {
13518
- format: glContext.RGBA,
13519
- type: textureType1,
13520
- minFilter: glContext.LINEAR,
13521
- magFilter: glContext.LINEAR
13522
- }
13523
- }
13524
- ]
13525
- });
13526
- var gaussianDownVPass = new HQGaussianDownSamplePass(renderer, "V", i, {
13527
- attachments: [
13528
- {
13529
- texture: {
13530
- format: glContext.RGBA,
13531
- type: textureType1,
13532
- minFilter: glContext.LINEAR,
13533
- magFilter: glContext.LINEAR
13534
- }
13535
- }
13536
- ]
13537
- });
13140
+ var gaussianDownHPass = new HQGaussianDownSamplePass(renderer, "H", i);
13141
+ var gaussianDownVPass = new HQGaussianDownSamplePass(renderer, "V", i);
13538
13142
  gaussianDownVPass.gaussianResult = gaussianDownResults[i];
13539
13143
  this.addRenderPass(gaussianDownHPass);
13540
13144
  this.addRenderPass(gaussianDownVPass);
@@ -13545,18 +13149,7 @@ var seed$6 = 1;
13545
13149
  viewport[2] *= 4;
13546
13150
  viewport[3] *= 4;
13547
13151
  for(var i1 = 0; i1 < gaussianStep - 1; i1++){
13548
- var gaussianUpPass = new HQGaussianUpSamplePass(renderer, gaussianStep - i1, {
13549
- attachments: [
13550
- {
13551
- texture: {
13552
- format: glContext.RGBA,
13553
- type: textureType1,
13554
- minFilter: glContext.LINEAR,
13555
- magFilter: glContext.LINEAR
13556
- }
13557
- }
13558
- ]
13559
- });
13152
+ var gaussianUpPass = new HQGaussianUpSamplePass(renderer, gaussianStep - i1);
13560
13153
  gaussianUpPass.gaussianDownSampleResult = gaussianDownResults[gaussianStep - 2 - i1];
13561
13154
  this.addRenderPass(gaussianUpPass);
13562
13155
  viewport[2] *= 2;
@@ -13565,31 +13158,17 @@ var seed$6 = 1;
13565
13158
  var postProcessPass = new ToneMappingPass(renderer, sceneTextureHandle);
13566
13159
  this.addRenderPass(postProcessPass);
13567
13160
  }
13568
- this.semantics = new SemanticMap(options.semantics);
13569
- this.clearAction = clearAction;
13570
13161
  this.name = "RenderFrame" + seed$6++;
13571
- var firstRP = renderPasses[0];
13572
13162
  this.camera = camera;
13573
- this.keepColorBuffer = keepColorBuffer;
13574
- this.renderPassInfoMap.set(firstRP, {
13575
- listStart: 0,
13576
- listEnd: 0,
13577
- renderPass: firstRP,
13578
- intermedia: false
13579
- });
13580
13163
  this.editorTransform = Vector4.fromArray(editorTransform);
13581
- if (!options.clearAction) {
13582
- this.resetClearActions();
13583
- }
13584
- this.passTextureCache = new PassTextureCache(engine);
13585
- // FIXME: addShader是为了性能考虑,如果影响不大,下面代码可以删除
13586
- var _engine_gpuCapability = engine.gpuCapability, detail = _engine_gpuCapability.detail, level = _engine_gpuCapability.level;
13587
- var writeDepth = detail.readableDepthStencilTextures && detail.writableFragDepth;
13588
- var shader = createCopyShader(level, writeDepth);
13589
- (_this_renderer_getShaderLibrary = this.renderer.getShaderLibrary()) == null ? void 0 : _this_renderer_getShaderLibrary.addShader(shader);
13590
13164
  }
13591
13165
  var _proto = RenderFrame.prototype;
13592
13166
  /**
13167
+ * 设置 RenderPasses 参数,此函数每帧调用一次
13168
+ */ _proto.setup = function setup() {
13169
+ this.drawObjectPass.setup(this.postProcessingEnabled);
13170
+ };
13171
+ /**
13593
13172
  * 根据 Mesh 优先级添加到 RenderPass
13594
13173
  * @param mesh - 要添加的 Mesh 对象
13595
13174
  */ _proto.addMeshToDefaultRenderPass = function addMeshToDefaultRenderPass(mesh) {
@@ -13606,78 +13185,25 @@ var seed$6 = 1;
13606
13185
  * 销毁 RenderFrame
13607
13186
  * @param options - 可以有选择销毁一些对象
13608
13187
  */ _proto.dispose = function dispose(options) {
13609
- if ((options == null ? void 0 : options.semantics) !== exports.DestroyOptions.keep) {
13610
- this.semantics.dispose();
13611
- }
13612
13188
  var pass = (options == null ? void 0 : options.passes) ? options.passes : undefined;
13613
13189
  if (pass !== exports.DestroyOptions.keep) {
13614
13190
  this._renderPasses.forEach(function(renderPass) {
13615
13191
  renderPass.dispose(pass);
13616
13192
  });
13617
13193
  }
13618
- this.passTextureCache.dispose();
13619
13194
  this._renderPasses.length = 0;
13620
- this.destroyed = true;
13621
- };
13622
- /**
13623
- * 查找 Mesh 所在的 RenderPass 索引,没找到是-1
13624
- * @param mesh - 需要查找的 Mesh
13625
- */ _proto.findMeshRenderPassIndex = function findMeshRenderPassIndex(mesh) {
13626
- var index = -1;
13627
- this.renderPasses.every(function(rp, idx) {
13628
- if (rp.name.startsWith(RENDER_PASS_NAME_PREFIX) && rp.meshes.includes(mesh)) {
13629
- index = idx;
13630
- return false;
13631
- }
13632
- return true;
13633
- });
13634
- return index;
13635
- };
13636
- _proto.addToRenderPass = function addToRenderPass(renderPass, mesh) {
13637
- var info = this.renderPassInfoMap.get(renderPass);
13638
- var priority = mesh.priority;
13639
- if (!info) {
13640
- return;
13641
- }
13642
- if (renderPass.meshes.length === 0) {
13643
- info.listStart = info.listEnd = priority;
13644
- } else {
13645
- if (priority < info.listStart) {
13646
- info.listStart = priority;
13647
- } else if (priority > info.listEnd) {
13648
- info.listEnd = priority;
13649
- }
13650
- }
13651
- renderPass.addMesh(mesh);
13652
- };
13653
- _proto.resetClearActions = function resetClearActions() {
13654
- var action = this.renderPasses.length > 1 ? exports.TextureLoadAction.clear : exports.TextureLoadAction.whatever;
13655
- this.clearAction.stencilAction = action;
13656
- this.clearAction.depthAction = action;
13657
- this.clearAction.colorAction = action;
13658
- if (this.keepColorBuffer) {
13659
- this.clearAction.colorAction = exports.TextureLoadAction.whatever;
13660
- }
13195
+ this.disposed = true;
13661
13196
  };
13662
13197
  /**
13663
13198
  * 设置 RenderPass 数组,直接修改内部的 RenderPass 数组
13664
13199
  * @param passes - RenderPass 数组
13665
13200
  */ _proto.setRenderPasses = function setRenderPasses(passes) {
13666
- var _this = this;
13667
- if (this.renderer !== undefined) {
13668
- passes.forEach(function(pass) {
13669
- return pass.initialize(_this.renderer);
13670
- });
13671
- }
13672
13201
  this._renderPasses = passes.slice();
13673
13202
  };
13674
13203
  /**
13675
13204
  * 添加 RenderPass
13676
13205
  * @param pass - 需要添加的 RenderPass
13677
13206
  */ _proto.addRenderPass = function addRenderPass(pass) {
13678
- if (this.renderer !== undefined) {
13679
- pass.initialize(this.renderer);
13680
- }
13681
13207
  this._renderPasses.push(pass);
13682
13208
  };
13683
13209
  /**
@@ -13694,9 +13220,9 @@ var seed$6 = 1;
13694
13220
  }
13695
13221
  },
13696
13222
  {
13697
- key: "isDestroyed",
13223
+ key: "isDisposed",
13698
13224
  get: function get() {
13699
- return this.destroyed;
13225
+ return this.disposed;
13700
13226
  }
13701
13227
  }
13702
13228
  ]);
@@ -13705,10 +13231,6 @@ var seed$6 = 1;
13705
13231
  function getTextureSize(tex) {
13706
13232
  return tex ? new Vector2(tex.getWidth(), tex.getHeight()) : new Vector2();
13707
13233
  }
13708
- function findPreviousRenderPass(renderPasses, renderPass) {
13709
- var index = renderPasses.indexOf(renderPass);
13710
- return renderPasses[index - 1];
13711
- }
13712
13234
  var GlobalUniforms = function GlobalUniforms() {
13713
13235
  this.floats = {};
13714
13236
  this.ints = {};
@@ -13746,6 +13268,122 @@ var Renderbuffer = /*#__PURE__*/ function() {
13746
13268
  return Renderbuffer;
13747
13269
  }();
13748
13270
 
13271
+ var RenderTargetPool = /*#__PURE__*/ function() {
13272
+ function RenderTargetPool(engine) {
13273
+ this.engine = engine;
13274
+ this.temporaryRTs = [];
13275
+ this.currentFrame = 0;
13276
+ this.maxUnusedFrames = 4;
13277
+ }
13278
+ var _proto = RenderTargetPool.prototype;
13279
+ /**
13280
+ * 清理 RenderTarget 池
13281
+ * @param force - 是否强制清理所有未占用的 RT
13282
+ * @param framesOffset - 自定义未使用帧数阈值,-1 表示使用默认值
13283
+ */ _proto.flush = function flush(force, framesOffset) {
13284
+ if (force === void 0) force = false;
13285
+ if (framesOffset === void 0) framesOffset = -1;
13286
+ this.currentFrame++;
13287
+ var threshold = framesOffset >= 0 ? framesOffset : this.maxUnusedFrames;
13288
+ for(var i = 0; i < this.temporaryRTs.length; i++){
13289
+ var entry = this.temporaryRTs[i];
13290
+ // 强制清理所有未占用的 RT,或清理超过阈值帧数未使用的 RT
13291
+ if (!entry.isOccupied && (force || this.currentFrame - entry.lastFrameReleased > threshold)) {
13292
+ entry.RT.dispose();
13293
+ this.temporaryRTs.splice(i--, 1);
13294
+ }
13295
+ }
13296
+ };
13297
+ _proto.get = function get(name, width, height, depthBuffer, filter, format) {
13298
+ if (depthBuffer === void 0) depthBuffer = 0;
13299
+ if (filter === void 0) filter = exports.FilterMode.Linear;
13300
+ if (format === void 0) format = exports.RenderTextureFormat.RGBA32;
13301
+ // 使用参数计算 hash 值作为缓存 key
13302
+ var hash = width + "_" + height + "_" + depthBuffer + "_" + filter + "_" + format;
13303
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.temporaryRTs), _step; !(_step = _iterator()).done;){
13304
+ var entry = _step.value;
13305
+ if (!entry.isOccupied && entry.descriptionHash === hash) {
13306
+ entry.isOccupied = true;
13307
+ entry.RT.name = name;
13308
+ return entry.RT;
13309
+ }
13310
+ }
13311
+ var textureFilter;
13312
+ var textureType;
13313
+ var depthType = exports.RenderPassAttachmentStorageType.none;
13314
+ // TODO 建立Map映射
13315
+ if (filter === exports.FilterMode.Linear) {
13316
+ textureFilter = glContext.LINEAR;
13317
+ } else if (filter === exports.FilterMode.Nearest) {
13318
+ textureFilter = glContext.NEAREST;
13319
+ }
13320
+ if (format === exports.RenderTextureFormat.RGBA32) {
13321
+ textureType = glContext.UNSIGNED_BYTE;
13322
+ } else if (format === exports.RenderTextureFormat.RGBAHalf) {
13323
+ textureType = glContext.HALF_FLOAT;
13324
+ }
13325
+ if (depthBuffer === 0) {
13326
+ depthType = exports.RenderPassAttachmentStorageType.none;
13327
+ } else if (depthBuffer === 16) {
13328
+ depthType = exports.RenderPassAttachmentStorageType.depth_stencil_opaque;
13329
+ } else if (depthBuffer === 24) {
13330
+ depthType = exports.RenderPassAttachmentStorageType.depth_24_stencil_8_texture;
13331
+ }
13332
+ var colorAttachment = Texture.create(this.engine, {
13333
+ sourceType: exports.TextureSourceType.framebuffer,
13334
+ minFilter: textureFilter,
13335
+ magFilter: textureFilter,
13336
+ internalFormat: glContext.RGBA,
13337
+ format: glContext.RGBA,
13338
+ type: textureType
13339
+ });
13340
+ var newFramebuffer = Framebuffer.create({
13341
+ name: name,
13342
+ storeAction: {},
13343
+ viewport: [
13344
+ 0,
13345
+ 0,
13346
+ width,
13347
+ height
13348
+ ],
13349
+ attachments: [
13350
+ colorAttachment
13351
+ ],
13352
+ depthStencilAttachment: {
13353
+ storageType: depthType
13354
+ }
13355
+ }, this.engine.renderer);
13356
+ var entry1 = {
13357
+ RT: newFramebuffer,
13358
+ lastFrameReleased: 0,
13359
+ descriptionHash: hash,
13360
+ isOccupied: true
13361
+ };
13362
+ this.temporaryRTs.push(entry1);
13363
+ return entry1.RT;
13364
+ };
13365
+ /**
13366
+ * 释放 RenderTarget,使其可以被复用
13367
+ * @param rt - 要释放的 Framebuffer
13368
+ */ _proto.release = function release(rt) {
13369
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.temporaryRTs), _step; !(_step = _iterator()).done;){
13370
+ var entry = _step.value;
13371
+ if (entry.RT === rt) {
13372
+ entry.isOccupied = false;
13373
+ entry.lastFrameReleased = this.currentFrame;
13374
+ break;
13375
+ }
13376
+ }
13377
+ };
13378
+ _proto.dispose = function dispose() {
13379
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.temporaryRTs), _step; !(_step = _iterator()).done;){
13380
+ var entry = _step.value;
13381
+ entry.RT.dispose();
13382
+ }
13383
+ };
13384
+ return RenderTargetPool;
13385
+ }();
13386
+
13749
13387
  var isWebGL2Available = typeof WebGL2RenderingContext === "function";
13750
13388
  var GPUCapability = /*#__PURE__*/ function() {
13751
13389
  function GPUCapability(gl) {
@@ -13931,70 +13569,11 @@ exports.CompressTextureCapabilityType = void 0;
13931
13569
  return !!hasCompressedTextureSupport;
13932
13570
  }
13933
13571
 
13934
- exports.FilterMode = void 0;
13935
- (function(FilterMode) {
13936
- FilterMode[FilterMode["Nearest"] = 0] = "Nearest";
13937
- FilterMode[FilterMode["Linear"] = 1] = "Linear";
13938
- })(exports.FilterMode || (exports.FilterMode = {}));
13939
- exports.RenderTextureFormat = void 0;
13940
- (function(RenderTextureFormat) {
13941
- RenderTextureFormat[RenderTextureFormat["RGBA32"] = 0] = "RGBA32";
13942
- RenderTextureFormat[RenderTextureFormat["RGBAHalf"] = 1] = "RGBAHalf";
13943
- })(exports.RenderTextureFormat || (exports.RenderTextureFormat = {}));
13944
- /**
13945
- *
13946
- */ var Framebuffer = /*#__PURE__*/ function() {
13947
- function Framebuffer() {}
13948
- var _proto = Framebuffer.prototype;
13949
- _proto.resize = function resize(x, y, width, height) {
13950
- // OVERRIDE
13951
- };
13952
- _proto.resetColorTextures = function resetColorTextures(textures) {
13953
- // OVERRIDE
13954
- };
13955
- _proto.unbind = function unbind() {
13956
- // OVERRIDE
13957
- };
13958
- _proto.bind = function bind() {
13959
- // OVERRIDE
13960
- };
13961
- _proto.getDepthTexture = function getDepthTexture() {
13962
- // OVERRIDE
13963
- return undefined;
13964
- };
13965
- _proto.getStencilTexture = function getStencilTexture() {
13966
- // OVERRIDE
13967
- return undefined;
13968
- };
13969
- _proto.getColorTextures = function getColorTextures() {
13970
- // OVERRIDE
13971
- return [];
13972
- };
13973
- _proto.dispose = function dispose(options) {
13974
- // OVERRIDE
13975
- };
13976
- _create_class(Framebuffer, [
13977
- {
13978
- key: "stencilStorage",
13979
- get: function get() {
13980
- // OVERRIDE
13981
- return undefined;
13982
- }
13983
- },
13984
- {
13985
- key: "depthStorage",
13986
- get: function get() {
13987
- // OVERRIDE
13988
- return undefined;
13989
- }
13990
- }
13991
- ]);
13992
- return Framebuffer;
13993
- }();
13994
-
13995
13572
  var Renderer = /*#__PURE__*/ function() {
13996
13573
  function Renderer(engine) {
13997
13574
  this.engine = engine;
13575
+ this.currentFramebuffer = null;
13576
+ this.renderTargetPool = new RenderTargetPool(engine);
13998
13577
  }
13999
13578
  var _proto = Renderer.prototype;
14000
13579
  _proto.setGlobalFloat = function setGlobalFloat(name, value) {
@@ -14064,8 +13643,10 @@ var Renderer = /*#__PURE__*/ function() {
14064
13643
  // OVERRIDE
14065
13644
  };
14066
13645
  _proto.getTemporaryRT = function getTemporaryRT(name, width, height, depthBuffer, filter, format) {
14067
- // OVERRIDE
14068
- return null;
13646
+ return this.renderTargetPool.get(name, width, height, depthBuffer, filter, format);
13647
+ };
13648
+ _proto.releaseTemporaryRT = function releaseTemporaryRT(rt) {
13649
+ this.renderTargetPool.release(rt);
14069
13650
  };
14070
13651
  _proto.dispose = function dispose() {
14071
13652
  // OVERRIDE
@@ -14073,6 +13654,41 @@ var Renderer = /*#__PURE__*/ function() {
14073
13654
  return Renderer;
14074
13655
  }();
14075
13656
 
13657
+ var SemanticMap = /*#__PURE__*/ function() {
13658
+ function SemanticMap(semantics) {
13659
+ if (semantics === void 0) semantics = {};
13660
+ this.semantics = _extends({}, semantics);
13661
+ }
13662
+ var _proto = SemanticMap.prototype;
13663
+ _proto.toObject = function toObject() {
13664
+ return _extends({}, this.semantics);
13665
+ };
13666
+ _proto.setSemantic = function setSemantic(name, value) {
13667
+ if (value === undefined) {
13668
+ delete this.semantics[name];
13669
+ } else {
13670
+ this.semantics[name] = value;
13671
+ }
13672
+ };
13673
+ _proto.getSemanticValue = function getSemanticValue(name, state) {
13674
+ var ret = this.semantics[name];
13675
+ if (isFunction(ret)) {
13676
+ return ret(state);
13677
+ }
13678
+ return ret;
13679
+ };
13680
+ _proto.hasSemanticValue = function hasSemanticValue(name) {
13681
+ return name in this.semantics;
13682
+ };
13683
+ _proto.dispose = function dispose() {
13684
+ var _this = this;
13685
+ Object.keys(this.semantics).forEach(function(name) {
13686
+ delete _this.semantics[name];
13687
+ });
13688
+ };
13689
+ return SemanticMap;
13690
+ }();
13691
+
14076
13692
  /**
14077
13693
  * @since 2.7.0
14078
13694
  */ var MaskableGraphic = /*#__PURE__*/ function(RendererComponent) {
@@ -18103,6 +17719,11 @@ exports.PlayState = void 0;
18103
17719
  PlayState[PlayState["Paused"] = 1] = "Paused";
18104
17720
  })(exports.PlayState || (exports.PlayState = {}));
18105
17721
 
17722
+ function _assert_this_initialized(self) {
17723
+ if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
17724
+ return self;
17725
+ }
17726
+
18106
17727
  var tempQuat$1 = new Quaternion();
18107
17728
  var tempVector3 = new Vector3();
18108
17729
  var tempVector3Second = new Vector3();
@@ -24480,8 +24101,7 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24480
24101
  _this.reusable = reusable;
24481
24102
  _this.speed = speed;
24482
24103
  _this.name = sourceContent.name;
24483
- _this.pluginSystem = scene.pluginSystem;
24484
- _this.pluginSystem.initializeComposition(_assert_this_initialized(_this), scene);
24104
+ PluginSystem.initializeComposition(_assert_this_initialized(_this), scene);
24485
24105
  _this.camera = new Camera(_this.name, _extends({}, sourceContent == null ? void 0 : sourceContent.camera, {
24486
24106
  aspect: width / height,
24487
24107
  pixelWidth: width,
@@ -24495,7 +24115,6 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24495
24115
  _this.createRenderFrame();
24496
24116
  Composition.buildItemTree(_this.rootItem);
24497
24117
  _this.rootComposition.setChildrenRenderOrder(0);
24498
- _this.pluginSystem.resetComposition(_assert_this_initialized(_this), _this.renderFrame);
24499
24118
  return _this;
24500
24119
  }
24501
24120
  var _proto = Composition.prototype;
@@ -24605,12 +24224,9 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24605
24224
  this.renderFrame = new RenderFrame({
24606
24225
  camera: this.camera,
24607
24226
  renderer: this.renderer,
24608
- keepColorBuffer: this.keepColorBuffer,
24609
24227
  globalVolume: this.globalVolume,
24610
24228
  postProcessingEnabled: this.postProcessingEnabled
24611
24229
  });
24612
- // TODO 考虑放到构造函数
24613
- this.renderFrame.cachedTextures = this.textures;
24614
24230
  };
24615
24231
  /**
24616
24232
  * 跳到指定时间点(不做任何播放行为)
@@ -24661,7 +24277,6 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24661
24277
  this.isEnded = false;
24662
24278
  this.isEndCalled = false;
24663
24279
  this.rootComposition.time = 0;
24664
- this.pluginSystem.resetComposition(this, this.renderFrame);
24665
24280
  };
24666
24281
  _proto.prepareRender = function prepareRender() {};
24667
24282
  /**
@@ -24679,8 +24294,6 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24679
24294
  var previousCompositionTime = this.time;
24680
24295
  this.updateCompositionTime(deltaTime * this.speed / 1000);
24681
24296
  var deltaTimeInMs = (this.time - previousCompositionTime) * 1000;
24682
- // 更新 model-tree-plugin
24683
- this.updatePluginLoaders(deltaTimeInMs);
24684
24297
  this.sceneTicking.update.tick(deltaTimeInMs);
24685
24298
  this.sceneTicking.lateUpdate.tick(deltaTimeInMs);
24686
24299
  this.updateCamera();
@@ -24705,15 +24318,6 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24705
24318
  this.camera.updateMatrix();
24706
24319
  };
24707
24320
  /**
24708
- * 插件更新,来自 CompVFXItem 的更新调用
24709
- * @param deltaTime - 更新的时间步长
24710
- */ _proto.updatePluginLoaders = function updatePluginLoaders(deltaTime) {
24711
- var _this = this;
24712
- this.pluginSystem.plugins.forEach(function(loader) {
24713
- return loader.onCompositionUpdate(_this, deltaTime);
24714
- });
24715
- };
24716
- /**
24717
24321
  * 更新主合成组件
24718
24322
  */ _proto.updateCompositionTime = function updateCompositionTime(deltaTime) {
24719
24323
  if (this.rootComposition.state === exports.PlayState.Paused || !this.rootComposition.isActiveAndEnabled) {
@@ -24872,7 +24476,6 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24872
24476
  * 合成对象销毁
24873
24477
  */ _proto.dispose = function dispose() {
24874
24478
  var _this = this;
24875
- var _this_pluginSystem;
24876
24479
  if (this.destroyed) {
24877
24480
  return;
24878
24481
  }
@@ -24892,13 +24495,14 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24892
24495
  this.rootItem.dispose();
24893
24496
  // FIXME: 注意这里增加了renderFrame销毁
24894
24497
  this.renderFrame.dispose();
24895
- (_this_pluginSystem = this.pluginSystem) == null ? void 0 : _this_pluginSystem.destroyComposition(this);
24498
+ PluginSystem.destroyComposition(this);
24896
24499
  this.update = function() {
24897
24500
  {
24898
24501
  logger.error("Update disposed composition: " + _this.name + ".");
24899
24502
  }
24900
24503
  };
24901
24504
  this.dispose = noop;
24505
+ this.renderer.engine.removeComposition(this);
24902
24506
  if (this.getEngine().env === PLAYER_OPTIONS_ENV_EDITOR) {
24903
24507
  return;
24904
24508
  }
@@ -24915,7 +24519,6 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24915
24519
  0
24916
24520
  ]
24917
24521
  });
24918
- this.renderer.engine.removeComposition(this);
24919
24522
  };
24920
24523
  /**
24921
24524
  * 编辑器使用的 transform 修改方法
@@ -31890,7 +31493,7 @@ function getStandardSpriteContent(sprite, transform) {
31890
31493
  return ret;
31891
31494
  }
31892
31495
 
31893
- var version$2 = "2.8.0-alpha.1";
31496
+ var version$2 = "2.8.0-alpha.2";
31894
31497
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
31895
31498
  var standardVersion = /^(\d+)\.(\d+)$/;
31896
31499
  var reverseParticle = false;
@@ -32405,7 +32008,7 @@ var seed$1 = 1;
32405
32008
  * @param renderer - renderer 对象,用于获取管理、编译 shader 及 GPU 上下文的参数
32406
32009
  * @param options - 扩展参数
32407
32010
  * @returns
32408
- */ _proto.loadScene = function loadScene(url, renderer, options) {
32011
+ */ _proto.loadScene = function loadScene(url, renderer) {
32409
32012
  var _this = this;
32410
32013
  return _async_to_generator(function() {
32411
32014
  var rawJSON, assetUrl, startTime, timeInfoMessages, gpuInstance, _gpuInstance_detail_ktx2Support, isKTX2Supported, timeInfos, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
@@ -32466,7 +32069,7 @@ var seed$1 = 1;
32466
32069
  });
32467
32070
  });
32468
32071
  loadResourcePromise = /*#__PURE__*/ _async_to_generator(function() {
32469
- var scene, link, _ref, jsonScene, pluginSystem, _jsonScene_bins, bins, images, fonts, _ref1, loadedBins, loadedImages, loadedTextures, totalTime;
32072
+ var scene, link, _scene_bins, _scene_textureOptions, _scene_images, jsonScene, _jsonScene_bins, bins, images, fonts, _ref, loadedBins, loadedImages, loadedTextures, totalTime;
32470
32073
  return __generator(this, function(_state) {
32471
32074
  switch(_state.label){
32472
32075
  case 0:
@@ -32516,7 +32119,26 @@ var seed$1 = 1;
32516
32119
  })
32517
32120
  ];
32518
32121
  case 5:
32519
- _ref = _state.sent(), jsonScene = _ref.jsonScene, pluginSystem = _ref.pluginSystem;
32122
+ jsonScene = _state.sent().jsonScene;
32123
+ scene = {
32124
+ timeInfos: timeInfos,
32125
+ url: url,
32126
+ storage: {},
32127
+ jsonScene: jsonScene,
32128
+ bins: [],
32129
+ textureOptions: [],
32130
+ textures: [],
32131
+ images: [],
32132
+ assets: _this.assets
32133
+ };
32134
+ return [
32135
+ 4,
32136
+ hookTimeInfo("plugin:processAssets", function() {
32137
+ return _this.processPluginAssets(scene);
32138
+ })
32139
+ ];
32140
+ case 6:
32141
+ _state.sent();
32520
32142
  _jsonScene_bins = jsonScene.bins, bins = _jsonScene_bins === void 0 ? [] : _jsonScene_bins, images = jsonScene.images, fonts = jsonScene.fonts;
32521
32143
  return [
32522
32144
  4,
@@ -32527,46 +32149,26 @@ var seed$1 = 1;
32527
32149
  hookTimeInfo("processImages", function() {
32528
32150
  return _this.processImages(images, isKTX2Supported);
32529
32151
  }),
32530
- hookTimeInfo("plugin:processAssets", function() {
32531
- return _this.processPluginAssets(jsonScene, pluginSystem, options);
32532
- }),
32533
32152
  hookTimeInfo("processFontURL", function() {
32534
32153
  return _this.processFontURL(fonts);
32535
32154
  })
32536
32155
  ])
32537
32156
  ];
32538
- case 6:
32539
- _ref1 = _state.sent(), loadedBins = _ref1[0], loadedImages = _ref1[1];
32157
+ case 7:
32158
+ _ref = _state.sent(), loadedBins = _ref[0], loadedImages = _ref[1];
32540
32159
  return [
32541
32160
  4,
32542
32161
  hookTimeInfo("processTextures", function() {
32543
32162
  return _this.processTextures(loadedImages, loadedBins, jsonScene);
32544
32163
  })
32545
32164
  ];
32546
- case 7:
32547
- loadedTextures = _state.sent();
32548
- scene = {
32549
- timeInfos: timeInfos,
32550
- url: url,
32551
- renderLevel: _this.options.renderLevel,
32552
- storage: {},
32553
- pluginSystem: pluginSystem,
32554
- jsonScene: jsonScene,
32555
- bins: loadedBins,
32556
- textureOptions: loadedTextures,
32557
- textures: [],
32558
- images: loadedImages,
32559
- assets: _this.assets
32560
- };
32561
- // 触发插件系统 pluginSystem 的回调 prepareResource
32562
- return [
32563
- 4,
32564
- hookTimeInfo("plugin:prepareResource", function() {
32565
- return pluginSystem.loadResources(scene, _this.options);
32566
- })
32567
- ];
32568
32165
  case 8:
32569
- _state.sent();
32166
+ loadedTextures = _state.sent();
32167
+ (_scene_bins = scene.bins).push.apply(_scene_bins, [].concat(loadedBins));
32168
+ (_scene_textureOptions = scene.textureOptions).push.apply(_scene_textureOptions, [].concat(loadedTextures));
32169
+ (_scene_images = scene.images).push.apply(_scene_images, [].concat(loadedImages));
32170
+ // 降级插件会修改 this.options.renderLevel, 在 processPluginAssets 后赋值
32171
+ scene.renderLevel = _this.options.renderLevel;
32570
32172
  _state.label = 9;
32571
32173
  case 9:
32572
32174
  totalTime = performance.now() - startTime;
@@ -32598,29 +32200,23 @@ var seed$1 = 1;
32598
32200
  return this.assets;
32599
32201
  };
32600
32202
  _proto.processJSON = function processJSON(json) {
32601
- var _this = this;
32602
32203
  return _async_to_generator(function() {
32603
- var jsonScene, _jsonScene_plugins, plugins, pluginSystem;
32204
+ var jsonScene, _jsonScene_plugins, plugins, _iterator, _step, customPluginName;
32604
32205
  return __generator(this, function(_state) {
32605
- switch(_state.label){
32606
- case 0:
32607
- jsonScene = getStandardJSON(json);
32608
- _jsonScene_plugins = jsonScene.plugins, plugins = _jsonScene_plugins === void 0 ? [] : _jsonScene_plugins;
32609
- pluginSystem = new PluginSystem(plugins);
32610
- return [
32611
- 4,
32612
- pluginSystem.processRawJSON(jsonScene, _this.options)
32613
- ];
32614
- case 1:
32615
- _state.sent();
32616
- return [
32617
- 2,
32618
- {
32619
- jsonScene: jsonScene,
32620
- pluginSystem: pluginSystem
32621
- }
32622
- ];
32206
+ jsonScene = getStandardJSON(json);
32207
+ _jsonScene_plugins = jsonScene.plugins, plugins = _jsonScene_plugins === void 0 ? [] : _jsonScene_plugins;
32208
+ for(_iterator = _create_for_of_iterator_helper_loose(plugins); !(_step = _iterator()).done;){
32209
+ customPluginName = _step.value;
32210
+ if (!pluginLoaderMap[customPluginName]) {
32211
+ throw new Error("The plugin '" + customPluginName + "' not found." + getPluginUsageInfo(customPluginName));
32212
+ }
32623
32213
  }
32214
+ return [
32215
+ 2,
32216
+ {
32217
+ jsonScene: jsonScene
32218
+ }
32219
+ ];
32624
32220
  });
32625
32221
  })();
32626
32222
  };
@@ -32826,30 +32422,18 @@ var seed$1 = 1;
32826
32422
  });
32827
32423
  })();
32828
32424
  };
32829
- _proto.processPluginAssets = function processPluginAssets(jsonScene, pluginSystem, options) {
32425
+ _proto.processPluginAssets = function processPluginAssets(scene) {
32830
32426
  var _this = this;
32831
32427
  return _async_to_generator(function() {
32832
- var pluginResult, _pluginResult_reduce, assets, loadedAssets, i;
32833
32428
  return __generator(this, function(_state) {
32834
32429
  switch(_state.label){
32835
32430
  case 0:
32836
32431
  return [
32837
32432
  4,
32838
- pluginSystem.processAssets(jsonScene, options)
32433
+ PluginSystem.processAssets(scene, _this.options)
32839
32434
  ];
32840
32435
  case 1:
32841
- pluginResult = _state.sent();
32842
- _pluginResult_reduce = pluginResult.reduce(function(acc, cur) {
32843
- acc.assets = acc.assets.concat(cur.assets);
32844
- acc.loadedAssets = acc.loadedAssets.concat(cur.loadedAssets);
32845
- return acc;
32846
- }, {
32847
- assets: [],
32848
- loadedAssets: []
32849
- }), assets = _pluginResult_reduce.assets, loadedAssets = _pluginResult_reduce.loadedAssets;
32850
- for(i = 0; i < assets.length; i++){
32851
- _this.assets[assets[i].id] = loadedAssets[i];
32852
- }
32436
+ _state.sent();
32853
32437
  return [
32854
32438
  2
32855
32439
  ];
@@ -33276,7 +32860,6 @@ function _createTextureOptionsBySource() {
33276
32860
  }
33277
32861
  };
33278
32862
  _proto.prepareAssets = function prepareAssets(scene, assets) {
33279
- this.engine.clearResources();
33280
32863
  for(var _iterator = _create_for_of_iterator_helper_loose(Object.keys(assets)), _step; !(_step = _iterator()).done;){
33281
32864
  var assetId = _step.value;
33282
32865
  var asset = assets[assetId];
@@ -35188,8 +34771,9 @@ var DEFAULT_FPS = 60;
35188
34771
  ]
35189
34772
  });
35190
34773
  for(var i1 = 0; i1 < comps.length; i1++){
35191
- !comps[i1].renderFrame.isDestroyed && this.renderer.renderRenderFrame(comps[i1].renderFrame);
34774
+ !comps[i1].renderFrame.isDisposed && this.renderer.renderRenderFrame(comps[i1].renderFrame);
35192
34775
  }
34776
+ this.renderer.renderTargetPool.flush();
35193
34777
  };
35194
34778
  /**
35195
34779
  * 将渲染器重新和父容器大小对齐
@@ -35435,6 +35019,95 @@ var DEFAULT_FPS = 60;
35435
35019
  return Engine;
35436
35020
  }(EventEmitter);
35437
35021
 
35022
+ var def = {
35023
+ format: glContext.RGBA,
35024
+ type: glContext.UNSIGNED_BYTE,
35025
+ minFilter: glContext.LINEAR,
35026
+ magFilter: glContext.LINEAR,
35027
+ wrapS: glContext.CLAMP_TO_EDGE,
35028
+ wrapT: glContext.CLAMP_TO_EDGE
35029
+ };
35030
+ var disposeSymbol = Symbol("dispose");
35031
+ var PassTextureCache = /*#__PURE__*/ function() {
35032
+ function PassTextureCache(engine) {
35033
+ this.textureCache = {};
35034
+ this.textureRef = {};
35035
+ this.engine = engine;
35036
+ }
35037
+ var _proto = PassTextureCache.prototype;
35038
+ _proto.requestColorAttachmentTexture = function requestColorAttachmentTexture(request) {
35039
+ var _this = this;
35040
+ var width = request.width, height = request.height, name = request.name;
35041
+ var options = {
35042
+ sourceType: exports.TextureSourceType.framebuffer,
35043
+ data: {
35044
+ width: width,
35045
+ height: height
35046
+ },
35047
+ name: name
35048
+ };
35049
+ var keys = [
35050
+ name
35051
+ ];
35052
+ Object.getOwnPropertyNames(def).forEach(function(name) {
35053
+ var _request_name;
35054
+ var value = (_request_name = request[name]) != null ? _request_name : def[name];
35055
+ options[name] = value;
35056
+ keys.push(name, value);
35057
+ });
35058
+ var cacheId = keys.join(":");
35059
+ var tex = this.textureCache[cacheId];
35060
+ if (tex) {
35061
+ this.textureRef[cacheId]++;
35062
+ } else {
35063
+ var engine = this.engine;
35064
+ assertExist(engine);
35065
+ tex = Texture.create(engine, options);
35066
+ this.textureCache[cacheId] = tex;
35067
+ this.textureRef[cacheId] = 1;
35068
+ // @ts-expect-error
35069
+ tex[disposeSymbol] = tex.dispose;
35070
+ tex.dispose = function() {
35071
+ return _this.removeTexture(cacheId);
35072
+ };
35073
+ }
35074
+ return tex;
35075
+ };
35076
+ _proto.removeTexture = function removeTexture(id) {
35077
+ var refCount = this.textureRef[id];
35078
+ if (refCount <= 1) {
35079
+ if (refCount < 0) {
35080
+ console.error("Ref count < 0.");
35081
+ }
35082
+ var tex = this.textureCache[id];
35083
+ if (tex) {
35084
+ // @ts-expect-error
35085
+ tex[disposeSymbol]();
35086
+ // @ts-expect-error
35087
+ tex.dispose = tex[disposeSymbol];
35088
+ }
35089
+ delete this.textureCache[id];
35090
+ delete this.textureRef[id];
35091
+ } else {
35092
+ this.textureRef[id] = refCount - 1;
35093
+ }
35094
+ };
35095
+ _proto.dispose = function dispose() {
35096
+ var _this = this;
35097
+ Object.keys(this.textureCache).forEach(function(key) {
35098
+ var texture = _this.textureCache[key];
35099
+ // @ts-expect-error
35100
+ texture[disposeSymbol]();
35101
+ // @ts-expect-error
35102
+ texture.dispose = texture[disposeSymbol];
35103
+ });
35104
+ this.textureCache = {};
35105
+ this.textureRef = {};
35106
+ this.engine = undefined;
35107
+ };
35108
+ return PassTextureCache;
35109
+ }();
35110
+
35438
35111
  var SceneLoader = /*#__PURE__*/ function() {
35439
35112
  function SceneLoader() {}
35440
35113
  SceneLoader.load = function load(scene, engine, options) {
@@ -35453,16 +35126,16 @@ var SceneLoader = /*#__PURE__*/ function() {
35453
35126
  engine.assetManagers.push(assetManager);
35454
35127
  return [
35455
35128
  4,
35456
- assetManager.loadScene(scene, engine.renderer, {
35457
- env: engine.env
35458
- })
35129
+ assetManager.loadScene(scene, engine.renderer)
35459
35130
  ];
35460
35131
  case 1:
35461
35132
  loadedScene = _state.sent();
35133
+ engine.clearResources();
35134
+ // 触发插件系统 pluginSystem 的回调 prepareResource
35135
+ PluginSystem.loadResources(loadedScene, assetManager.options, engine);
35462
35136
  engine.assetService.prepareAssets(loadedScene, loadedScene.assets);
35463
35137
  engine.assetService.updateTextVariables(loadedScene, options.variables);
35464
35138
  engine.assetService.initializeTexture(loadedScene);
35465
- loadedScene.pluginSystem.precompile(loadedScene.jsonScene.compositions, engine.renderer);
35466
35139
  composition = _this.createComposition(loadedScene, engine, options);
35467
35140
  composition.setIndex(compositionIndex);
35468
35141
  compileStart = performance.now();
@@ -35515,13 +35188,13 @@ var SceneLoader = /*#__PURE__*/ function() {
35515
35188
  return SceneLoader;
35516
35189
  }();
35517
35190
 
35518
- registerPlugin("camera", CameraVFXItemLoader, exports.VFXItem);
35519
- registerPlugin("text", TextLoader, exports.VFXItem);
35520
- registerPlugin("sprite", SpriteLoader, exports.VFXItem);
35521
- registerPlugin("particle", ParticleLoader, exports.VFXItem);
35522
- registerPlugin("cal", CalculateLoader, exports.VFXItem);
35523
- registerPlugin("interact", InteractLoader, exports.VFXItem);
35524
- var version$1 = "2.8.0-alpha.1";
35191
+ registerPlugin("camera", CameraVFXItemLoader);
35192
+ registerPlugin("text", TextLoader);
35193
+ registerPlugin("sprite", SpriteLoader);
35194
+ registerPlugin("particle", ParticleLoader);
35195
+ registerPlugin("cal", CalculateLoader);
35196
+ registerPlugin("interact", InteractLoader);
35197
+ var version$1 = "2.8.0-alpha.2";
35525
35198
  logger.info("Core version: " + version$1 + ".");
35526
35199
 
35527
35200
  var _obj;
@@ -36799,7 +36472,7 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
36799
36472
  return [
36800
36473
  4,
36801
36474
  Promise.all(scenes.map(/*#__PURE__*/ _async_to_generator(function(url, index) {
36802
- var _this_assetService_assembleSceneLoadOptions, source, opts, assetManager, _$scene, composition;
36475
+ var _this_assetService_assembleSceneLoadOptions, source, opts, assetManager, _$scene, engine, composition;
36803
36476
  return __generator(this, function(_state) {
36804
36477
  switch(_state.label){
36805
36478
  case 0:
@@ -36809,16 +36482,17 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
36809
36482
  assetManager = new AssetManager(opts);
36810
36483
  return [
36811
36484
  4,
36812
- assetManager.loadScene(source, _this.renderer, {
36813
- env: _this.env
36814
- })
36485
+ assetManager.loadScene(source, _this.renderer)
36815
36486
  ];
36816
36487
  case 1:
36817
36488
  _$scene = _state.sent();
36489
+ engine = _this.engine;
36490
+ engine.clearResources();
36491
+ // 触发插件系统 pluginSystem 的回调 prepareResource
36492
+ PluginSystem.loadResources(_$scene, assetManager.options, engine);
36818
36493
  _this.assetService.prepareAssets(_$scene, assetManager.getAssets());
36819
36494
  _this.assetService.updateTextVariables(_$scene, assetManager.options.variables);
36820
36495
  _this.assetService.initializeTexture(_$scene);
36821
- _$scene.pluginSystem.precompile(_$scene.jsonScene.compositions, _this.renderer);
36822
36496
  composition = _this.createComposition(_$scene, opts);
36823
36497
  _this.baseCompositionIndex += 1;
36824
36498
  composition.setIndex(baseOrder + index);
@@ -37110,7 +36784,7 @@ applyMixins(exports.ThreeTextComponent, [
37110
36784
  */ Mesh.create = function(engine, props) {
37111
36785
  return new ThreeMesh(engine, props);
37112
36786
  };
37113
- var version = "2.8.0-alpha.1";
36787
+ var version = "2.8.0-alpha.2";
37114
36788
  logger.info("THREEJS plugin version: " + version + ".");
37115
36789
 
37116
36790
  exports.AbstractPlugin = AbstractPlugin;
@@ -37225,7 +36899,6 @@ exports.Pose = Pose;
37225
36899
  exports.PoseNode = PoseNode;
37226
36900
  exports.PropertyClipPlayable = PropertyClipPlayable;
37227
36901
  exports.PropertyTrack = PropertyTrack;
37228
- exports.RENDER_PASS_NAME_PREFIX = RENDER_PASS_NAME_PREFIX;
37229
36902
  exports.RENDER_PREFER_LOOKUP_TEXTURE = RENDER_PREFER_LOOKUP_TEXTURE;
37230
36903
  exports.RUNTIME_ENV = RUNTIME_ENV;
37231
36904
  exports.RandomSetValue = RandomSetValue;
@@ -37238,6 +36911,7 @@ exports.RenderPassPriorityNormal = RenderPassPriorityNormal;
37238
36911
  exports.RenderPassPriorityPostprocess = RenderPassPriorityPostprocess;
37239
36912
  exports.RenderPassPriorityPrepare = RenderPassPriorityPrepare;
37240
36913
  exports.RenderTargetHandle = RenderTargetHandle;
36914
+ exports.RenderTargetPool = RenderTargetPool;
37241
36915
  exports.Renderbuffer = Renderbuffer;
37242
36916
  exports.Renderer = Renderer;
37243
36917
  exports.RendererComponent = RendererComponent;
@@ -37306,14 +36980,12 @@ exports.colorGradingFrag = colorGradingFrag;
37306
36980
  exports.colorStopsFromGradient = colorStopsFromGradient;
37307
36981
  exports.colorToArr = colorToArr$1;
37308
36982
  exports.combineImageTemplate = combineImageTemplate;
37309
- exports.createCopyShader = createCopyShader;
37310
36983
  exports.createGLContext = createGLContext;
37311
36984
  exports.createKeyFrameMeta = createKeyFrameMeta;
37312
36985
  exports.createShape = createShape;
37313
36986
  exports.createValueGetter = createValueGetter;
37314
36987
  exports.curveEps = curveEps;
37315
36988
  exports.decimalEqual = decimalEqual;
37316
- exports.defaultPlugins = defaultPlugins;
37317
36989
  exports.deserializeMipmapTexture = deserializeMipmapTexture;
37318
36990
  exports.earcut = earcut;
37319
36991
  exports.effectsClass = effectsClass;
@@ -37321,7 +36993,6 @@ exports.effectsClassStore = effectsClassStore;
37321
36993
  exports.enlargeBuffer = enlargeBuffer;
37322
36994
  exports.ensureFixedNumber = ensureFixedNumber;
37323
36995
  exports.ensureVec3 = ensureVec3;
37324
- exports.findPreviousRenderPass = findPreviousRenderPass;
37325
36996
  exports.gaussianDownHFrag = gaussianDownHFrag;
37326
36997
  exports.gaussianDownVFrag = gaussianDownVFrag;
37327
36998
  exports.gaussianUpFrag = gaussianUpFrag;
@@ -37342,6 +37013,7 @@ exports.getMergedStore = getMergedStore;
37342
37013
  exports.getNodeDataClass = getNodeDataClass;
37343
37014
  exports.getParticleMeshShader = getParticleMeshShader;
37344
37015
  exports.getPixelRatio = getPixelRatio;
37016
+ exports.getPluginUsageInfo = getPluginUsageInfo;
37345
37017
  exports.getPreMultiAlpha = getPreMultiAlpha;
37346
37018
  exports.getStandardComposition = getStandardComposition;
37347
37019
  exports.getStandardImage = getStandardImage;