@galacean/effects-threejs 2.8.0-alpha.2 → 2.8.0-alpha.4

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.2
6
+ * Version: v2.8.0-alpha.4
7
7
  */
8
8
 
9
9
  'use strict';
@@ -2905,7 +2905,6 @@ var plugins = [];
2905
2905
  pluginLoaderMap[name] = pluginClass;
2906
2906
  var pluginInstance = new pluginClass();
2907
2907
  pluginInstance.name = name;
2908
- pluginInstance.initialize();
2909
2908
  plugins.push(pluginInstance);
2910
2909
  plugins.sort(function(a, b) {
2911
2910
  return a.order - b.order;
@@ -2929,29 +2928,29 @@ var PluginSystem = /*#__PURE__*/ function() {
2929
2928
  };
2930
2929
  PluginSystem.initializeComposition = function initializeComposition(composition, scene) {
2931
2930
  plugins.forEach(function(loader) {
2932
- return loader.onCompositionConstructed(composition, scene);
2931
+ return loader.onCompositionCreated(composition, scene);
2933
2932
  });
2934
2933
  };
2935
2934
  PluginSystem.destroyComposition = function destroyComposition(comp) {
2936
2935
  plugins.forEach(function(loader) {
2937
- return loader.onCompositionDestroyed(comp);
2936
+ return loader.onCompositionDestroy(comp);
2938
2937
  });
2939
2938
  };
2940
- PluginSystem.processAssets = function processAssets(scene, options) {
2939
+ PluginSystem.onAssetsLoadStart = function onAssetsLoadStart(scene, options) {
2941
2940
  return _async_to_generator(function() {
2942
2941
  return __generator(this, function(_state) {
2943
2942
  return [
2944
2943
  2,
2945
2944
  Promise.all(plugins.map(function(plugin) {
2946
- return plugin.processAssets(scene, options);
2945
+ return plugin.onAssetsLoadStart(scene, options);
2947
2946
  }))
2948
2947
  ];
2949
2948
  });
2950
2949
  })();
2951
2950
  };
2952
- PluginSystem.loadResources = function loadResources(scene, options, engine) {
2951
+ PluginSystem.onAssetsLoadFinish = function onAssetsLoadFinish(scene, options, engine) {
2953
2952
  plugins.forEach(function(loader) {
2954
- return loader.prepareResource(scene, options, engine);
2953
+ return loader.onAssetsLoadFinish(scene, options, engine);
2955
2954
  });
2956
2955
  };
2957
2956
  return PluginSystem;
@@ -2981,20 +2980,18 @@ function getPluginUsageInfo(name) {
2981
2980
  /**
2982
2981
  * 抽象插件类
2983
2982
  * 注册合成不同生命周期的回调函数
2984
- */ var AbstractPlugin = /*#__PURE__*/ function() {
2985
- function AbstractPlugin() {
2983
+ */ var Plugin = /*#__PURE__*/ function() {
2984
+ function Plugin() {
2986
2985
  this.order = 100;
2987
- this.name = "";
2986
+ this.name = "Plugin";
2988
2987
  }
2989
- var _proto = AbstractPlugin.prototype;
2990
- _proto.initialize = function initialize() {};
2988
+ var _proto = Plugin.prototype;
2991
2989
  /**
2992
- * loadScene 函数调用的时候会触发此函数,
2993
- * 此阶段可以加载插件所需类型资源,并返回原始资源和加载后的资源。
2994
- * @param scene
2995
- * @param options
2996
- * @returns
2997
- */ _proto.processAssets = function processAssets(scene, options) {
2990
+ * 场景加载时触发,用于加载插件所需的自定义资源。
2991
+ * 此阶段适合发起异步资源请求。
2992
+ * @param scene - 场景对象
2993
+ * @param options - 场景加载选项
2994
+ */ _proto.onAssetsLoadStart = function onAssetsLoadStart(scene, options) {
2998
2995
  return _async_to_generator(function() {
2999
2996
  return __generator(this, function(_state) {
3000
2997
  return [
@@ -3004,17 +3001,22 @@ function getPluginUsageInfo(name) {
3004
3001
  })();
3005
3002
  };
3006
3003
  /**
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) {};
3015
- _proto.onCompositionConstructed = function onCompositionConstructed(composition, scene) {};
3016
- _proto.onCompositionDestroyed = function onCompositionDestroyed(composition) {};
3017
- return AbstractPlugin;
3004
+ * 场景资源加载完成后触发。
3005
+ * 此时 JSON 中的图片和二进制已加载完成,可对资源做进一步处理。
3006
+ * @param scene - 场景对象
3007
+ * @param options - 场景加载选项
3008
+ * @param engine - 引擎实例
3009
+ */ _proto.onAssetsLoadFinish = function onAssetsLoadFinish(scene, options, engine) {};
3010
+ /**
3011
+ * 合成创建完成后触发。
3012
+ * @param composition - 合成对象
3013
+ * @param scene - 场景对象
3014
+ */ _proto.onCompositionCreated = function onCompositionCreated(composition, scene) {};
3015
+ /**
3016
+ * 合成销毁时触发。
3017
+ * @param composition - 合成对象
3018
+ */ _proto.onCompositionDestroy = function onCompositionDestroy(composition) {};
3019
+ return Plugin;
3018
3020
  }();
3019
3021
 
3020
3022
  function _set_prototype_of(o, p) {
@@ -7252,13 +7254,388 @@ __decorate([
7252
7254
  serialize()
7253
7255
  ], RendererComponent.prototype, "_priority", void 0);
7254
7256
 
7257
+ exports.ShaderType = void 0;
7258
+ (function(ShaderType) {
7259
+ ShaderType[ShaderType["vertex"] = 0] = "vertex";
7260
+ ShaderType[ShaderType["fragment"] = 1] = "fragment";
7261
+ })(exports.ShaderType || (exports.ShaderType = {}));
7262
+ exports.MaskMode = void 0;
7263
+ (function(MaskMode) {
7264
+ /**
7265
+ * 无
7266
+ */ MaskMode[MaskMode["NONE"] = 0] = "NONE";
7267
+ /**
7268
+ * 蒙版
7269
+ */ MaskMode[MaskMode["MASK"] = 1] = "MASK";
7270
+ /**
7271
+ * 被遮挡
7272
+ */ MaskMode[MaskMode["OBSCURED"] = 2] = "OBSCURED";
7273
+ /**
7274
+ * 被反向遮挡
7275
+ */ MaskMode[MaskMode["REVERSE_OBSCURED"] = 3] = "REVERSE_OBSCURED";
7276
+ })(exports.MaskMode || (exports.MaskMode = {}));
7277
+
7278
+ exports.TextureLoadAction = void 0;
7279
+ (function(TextureLoadAction) {
7280
+ TextureLoadAction[TextureLoadAction["whatever"] = 0] = "whatever";
7281
+ //preserve previous attachment
7282
+ //load = 1,
7283
+ //clear attachment
7284
+ TextureLoadAction[TextureLoadAction["clear"] = 2] = "clear";
7285
+ })(exports.TextureLoadAction || (exports.TextureLoadAction = {}));
7286
+ exports.TextureSourceType = void 0;
7287
+ (function(TextureSourceType) {
7288
+ TextureSourceType[TextureSourceType["none"] = 0] = "none";
7289
+ TextureSourceType[TextureSourceType["data"] = 1] = "data";
7290
+ TextureSourceType[TextureSourceType["image"] = 2] = "image";
7291
+ TextureSourceType[TextureSourceType["compressed"] = 3] = "compressed";
7292
+ TextureSourceType[TextureSourceType["video"] = 4] = "video";
7293
+ TextureSourceType[TextureSourceType["canvas"] = 5] = "canvas";
7294
+ TextureSourceType[TextureSourceType["framebuffer"] = 6] = "framebuffer";
7295
+ TextureSourceType[TextureSourceType["mipmaps"] = 7] = "mipmaps";
7296
+ })(exports.TextureSourceType || (exports.TextureSourceType = {}));
7297
+
7298
+ var MaskProcessor = /*#__PURE__*/ function() {
7299
+ function MaskProcessor(engine) {
7300
+ this.engine = engine;
7301
+ this.alphaMaskEnabled = false;
7302
+ this.maskMode = exports.MaskMode.NONE;
7303
+ this.maskable = null;
7304
+ this.stencilClearAction = {
7305
+ stencilAction: exports.TextureLoadAction.clear
7306
+ };
7307
+ }
7308
+ var _proto = MaskProcessor.prototype;
7309
+ _proto.getRefValue = function getRefValue() {
7310
+ return 1;
7311
+ };
7312
+ _proto.setMaskOptions = function setMaskOptions(data) {
7313
+ var _data_isMask = data.isMask, isMask = _data_isMask === void 0 ? false : _data_isMask, _data_inverted = data.inverted, inverted = _data_inverted === void 0 ? false : _data_inverted, reference = data.reference, _data_alphaMaskEnabled = data.alphaMaskEnabled, alphaMaskEnabled = _data_alphaMaskEnabled === void 0 ? false : _data_alphaMaskEnabled;
7314
+ this.alphaMaskEnabled = alphaMaskEnabled;
7315
+ if (isMask) {
7316
+ this.maskMode = exports.MaskMode.MASK;
7317
+ } else {
7318
+ this.maskMode = inverted ? exports.MaskMode.REVERSE_OBSCURED : exports.MaskMode.OBSCURED;
7319
+ this.maskable = this.engine.findObject(reference);
7320
+ }
7321
+ };
7322
+ _proto.drawStencilMask = function drawStencilMask(renderer) {
7323
+ if (this.maskable) {
7324
+ renderer.clear(this.stencilClearAction);
7325
+ this.maskable.drawStencilMask(renderer);
7326
+ }
7327
+ };
7328
+ return MaskProcessor;
7329
+ }();
7330
+
7331
+ /**
7332
+ * Helper class to create a WebGL Context
7333
+ *
7334
+ * @param canvas
7335
+ * @param glType
7336
+ * @param options
7337
+ * @returns
7338
+ */ function createGLContext(canvas, glType, options) {
7339
+ if (glType === void 0) glType = "webgl";
7340
+ var context;
7341
+ if (glType === "webgl2") {
7342
+ context = canvas.getContext("webgl2", options);
7343
+ if (!context) {
7344
+ console.debug("WebGL2 context retrieval failed, falling back to WebGL context.");
7345
+ }
7346
+ }
7347
+ if (!context || glType === "webgl") {
7348
+ context = canvas.getContext("webgl", options);
7349
+ }
7350
+ if (!context) {
7351
+ throw new Error("This browser does not support WebGL or the WebGL version is incorrect. Please check your WebGL version.");
7352
+ }
7353
+ return context;
7354
+ }
7355
+
7356
+ function gpuTimer(gl) {
7357
+ var ext = gl.getExtension("EXT_disjoint_timer_query_webgl2");
7358
+ if (ext) {
7359
+ var query = gl.createQuery();
7360
+ var getTime = /*#__PURE__*/ _async_to_generator(function() {
7361
+ return __generator(this, function(_state) {
7362
+ return [
7363
+ 2,
7364
+ new Promise(function(resolve, reject) {
7365
+ if (query) {
7366
+ var available = gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE);
7367
+ var disjoint = gl.getParameter(ext.GPU_DISJOINT_EXT);
7368
+ if (available && !disjoint) {
7369
+ // See how much time the rendering of the object took in nanoseconds.
7370
+ var timeElapsed = gl.getQueryParameter(query, gl.QUERY_RESULT); // Do something useful with the time. Note that care should be
7371
+ // taken to use all significant bits of the result, not just the
7372
+ // least significant 32 bits.
7373
+ resolve(timeElapsed / 1000 / 1000);
7374
+ }
7375
+ if (available || disjoint) {
7376
+ // Clean up the query object.
7377
+ gl.deleteQuery(query); // Don't re-enter this polling loop.
7378
+ query = null;
7379
+ }
7380
+ available !== null && query && window.setTimeout(function() {
7381
+ getTime().then(resolve).catch;
7382
+ }, 1);
7383
+ }
7384
+ })
7385
+ ];
7386
+ });
7387
+ });
7388
+ if (!query) {
7389
+ return;
7390
+ }
7391
+ return {
7392
+ begin: function() {
7393
+ query && gl.beginQuery(ext.TIME_ELAPSED_EXT, query);
7394
+ },
7395
+ end: function() {
7396
+ gl.endQuery(ext.TIME_ELAPSED_EXT);
7397
+ },
7398
+ getTime: getTime
7399
+ };
7400
+ }
7401
+ }
7402
+
7403
+ var initErrors = [];
7404
+ var glContext = {};
7405
+ var IOS16_LOCKDOWN_MODE = "iOS16 lockdown mode, WebGL Constants not in global";
7406
+ var WEBGL_CONSTANTS_NOT_IN_GLOBAL = "WebGL Constants not in global, please check your environment";
7407
+ if (!initErrors.length) {
7408
+ initGLContext();
7409
+ }
7410
+ function initGLContext() {
7411
+ // 重要:iOS 9/10 低版本需要拷贝 gl context 的 prototype,要不然会有属性值的缺失
7412
+ if (typeof WebGL2RenderingContext === "function") {
7413
+ copy(WebGL2RenderingContext);
7414
+ } else if (typeof WebGLRenderingContext !== "undefined") {
7415
+ copy(WebGLRenderingContext);
7416
+ copy(WebGLRenderingContext.prototype);
7417
+ } else {
7418
+ if (canUseBOM) {
7419
+ initErrors.push(// iOS 16 lockdown mode
7420
+ isIOS() ? IOS16_LOCKDOWN_MODE : WEBGL_CONSTANTS_NOT_IN_GLOBAL);
7421
+ } else {
7422
+ initErrors.push(WEBGL_CONSTANTS_NOT_IN_GLOBAL);
7423
+ }
7424
+ }
7425
+ if (!initErrors.length && !("HALF_FLOAT" in glContext)) {
7426
+ // @ts-expect-error set default value
7427
+ glContext["HALF_FLOAT"] = 5131;
7428
+ }
7429
+ }
7430
+ function isWebGL2(gl) {
7431
+ return typeof WebGL2RenderingContext !== "undefined" && gl.constructor.name === "WebGL2RenderingContext";
7432
+ }
7433
+ function copy(target) {
7434
+ for(var name in target){
7435
+ if (/^[A-Z_]/.test(name)) {
7436
+ // @ts-expect-error safe to assign
7437
+ glContext[name] = target[name];
7438
+ }
7439
+ }
7440
+ }
7441
+ function vertexFormatType2GLType(formatType) {
7442
+ switch(formatType){
7443
+ case VertexFormatType.Float32:
7444
+ return WebGLRenderingContext["FLOAT"];
7445
+ case VertexFormatType.Int16:
7446
+ return WebGLRenderingContext["SHORT"];
7447
+ case VertexFormatType.Int8:
7448
+ return WebGLRenderingContext["BYTE"];
7449
+ case VertexFormatType.UInt16:
7450
+ return WebGLRenderingContext["UNSIGNED_SHORT"];
7451
+ case VertexFormatType.UInt8:
7452
+ return WebGLRenderingContext["UNSIGNED_BYTE"];
7453
+ default:
7454
+ return WebGLRenderingContext["FLOAT"];
7455
+ }
7456
+ }
7457
+ function glType2VertexFormatType(webglType) {
7458
+ switch(webglType){
7459
+ case WebGLRenderingContext["FLOAT"]:
7460
+ return VertexFormatType.Float32;
7461
+ case WebGLRenderingContext["SHORT"]:
7462
+ return VertexFormatType.Int16;
7463
+ case WebGLRenderingContext["BYTE"]:
7464
+ return VertexFormatType.Int8;
7465
+ case WebGLRenderingContext["UNSIGNED_SHORT"]:
7466
+ return VertexFormatType.UInt16;
7467
+ case WebGLRenderingContext["UNSIGNED_BYTE"]:
7468
+ return VertexFormatType.UInt8;
7469
+ default:
7470
+ return VertexFormatType.Float32;
7471
+ }
7472
+ }
7473
+
7474
+ function valIfUndefined(val, def) {
7475
+ if (val === undefined || val === null) {
7476
+ return def;
7477
+ }
7478
+ return val;
7479
+ }
7480
+ function getPreMultiAlpha(blending) {
7481
+ switch(blending){
7482
+ case BlendingMode.ALPHA:
7483
+ return 1;
7484
+ case BlendingMode.ADD:
7485
+ return 1;
7486
+ case BlendingMode.SUBTRACTION:
7487
+ return 1;
7488
+ case BlendingMode.STRONG_LIGHT:
7489
+ return 1;
7490
+ case BlendingMode.WEAK_LIGHT:
7491
+ return 1;
7492
+ case BlendingMode.SUPERPOSITION:
7493
+ return 2;
7494
+ case BlendingMode.BRIGHTNESS:
7495
+ return 3;
7496
+ case BlendingMode.MULTIPLY:
7497
+ return 0;
7498
+ default:
7499
+ // 处理undefined
7500
+ return 1;
7501
+ }
7502
+ }
7503
+ function setBlendMode(material, blendMode) {
7504
+ switch(blendMode){
7505
+ case undefined:
7506
+ material.blendFunction = [
7507
+ glContext.ONE,
7508
+ glContext.ONE_MINUS_SRC_ALPHA,
7509
+ glContext.ONE,
7510
+ glContext.ONE_MINUS_SRC_ALPHA
7511
+ ];
7512
+ break;
7513
+ case BlendingMode.ALPHA:
7514
+ material.blendFunction = [
7515
+ glContext.ONE,
7516
+ glContext.ONE_MINUS_SRC_ALPHA,
7517
+ glContext.ONE,
7518
+ glContext.ONE_MINUS_SRC_ALPHA
7519
+ ];
7520
+ break;
7521
+ case BlendingMode.ADD:
7522
+ material.blendFunction = [
7523
+ glContext.ONE,
7524
+ glContext.ONE,
7525
+ glContext.ONE,
7526
+ glContext.ONE
7527
+ ];
7528
+ break;
7529
+ case BlendingMode.SUBTRACTION:
7530
+ material.blendFunction = [
7531
+ glContext.ONE,
7532
+ glContext.ONE,
7533
+ glContext.ZERO,
7534
+ glContext.ONE
7535
+ ];
7536
+ material.blendEquation = [
7537
+ glContext.FUNC_REVERSE_SUBTRACT,
7538
+ glContext.FUNC_REVERSE_SUBTRACT
7539
+ ];
7540
+ break;
7541
+ case BlendingMode.SUPERPOSITION:
7542
+ material.blendFunction = [
7543
+ glContext.ONE,
7544
+ glContext.ONE,
7545
+ glContext.ONE,
7546
+ glContext.ONE
7547
+ ];
7548
+ break;
7549
+ case BlendingMode.MULTIPLY:
7550
+ material.blendFunction = [
7551
+ glContext.DST_COLOR,
7552
+ glContext.ONE_MINUS_SRC_ALPHA,
7553
+ glContext.DST_COLOR,
7554
+ glContext.ONE_MINUS_SRC_ALPHA
7555
+ ];
7556
+ break;
7557
+ case BlendingMode.BRIGHTNESS:
7558
+ material.blendFunction = [
7559
+ glContext.ONE,
7560
+ glContext.ONE_MINUS_SRC_ALPHA,
7561
+ glContext.ONE,
7562
+ glContext.ONE_MINUS_SRC_ALPHA
7563
+ ];
7564
+ break;
7565
+ case BlendingMode.STRONG_LIGHT:
7566
+ material.blendFunction = [
7567
+ glContext.DST_COLOR,
7568
+ glContext.DST_ALPHA,
7569
+ glContext.ZERO,
7570
+ glContext.ONE
7571
+ ];
7572
+ break;
7573
+ case BlendingMode.WEAK_LIGHT:
7574
+ material.blendFunction = [
7575
+ glContext.DST_COLOR,
7576
+ glContext.ZERO,
7577
+ glContext.ZERO,
7578
+ glContext.ONE
7579
+ ];
7580
+ break;
7581
+ default:
7582
+ console.warn("BlendMode " + blendMode + " not in specification, please set blend params separately.");
7583
+ }
7584
+ }
7585
+ function setSideMode(material, side) {
7586
+ if (side === SideMode.DOUBLE) {
7587
+ material.culling = false;
7588
+ } else {
7589
+ material.culling = true;
7590
+ material.frontFace = glContext.CW;
7591
+ material.cullFace = side === SideMode.BACK ? glContext.BACK : glContext.FRONT;
7592
+ }
7593
+ }
7594
+ function setMaskMode(material, maskMode) {
7595
+ switch(maskMode){
7596
+ case undefined:
7597
+ material.stencilTest = false;
7598
+ break;
7599
+ case exports.MaskMode.MASK:
7600
+ material.stencilTest = true;
7601
+ material.stencilFunc = [
7602
+ glContext.ALWAYS,
7603
+ glContext.ALWAYS
7604
+ ];
7605
+ material.stencilOpZPass = [
7606
+ glContext.REPLACE,
7607
+ glContext.REPLACE
7608
+ ];
7609
+ break;
7610
+ case exports.MaskMode.OBSCURED:
7611
+ material.stencilTest = true;
7612
+ material.stencilFunc = [
7613
+ glContext.EQUAL,
7614
+ glContext.EQUAL
7615
+ ];
7616
+ break;
7617
+ case exports.MaskMode.REVERSE_OBSCURED:
7618
+ material.stencilTest = true;
7619
+ material.stencilFunc = [
7620
+ glContext.NOTEQUAL,
7621
+ glContext.NOTEQUAL
7622
+ ];
7623
+ break;
7624
+ case exports.MaskMode.NONE:
7625
+ material.stencilTest = false;
7626
+ break;
7627
+ default:
7628
+ console.warn("MaskMode " + maskMode + " not in specification, please set stencil params seperately.");
7629
+ }
7630
+ }
7631
+
7255
7632
  /**
7256
7633
  * Mesh 组件
7257
7634
  */ var MeshComponent = /*#__PURE__*/ function(RendererComponent) {
7258
7635
  _inherits(MeshComponent, RendererComponent);
7259
- function MeshComponent() {
7636
+ function MeshComponent(engine) {
7260
7637
  var _this;
7261
- _this = RendererComponent.apply(this, arguments) || this;
7638
+ _this = RendererComponent.call(this, engine) || this;
7262
7639
  /**
7263
7640
  * 用于点击测试的碰撞器
7264
7641
  */ _this.meshCollider = new MeshCollider();
@@ -7274,6 +7651,7 @@ __decorate([
7274
7651
  };
7275
7652
  }
7276
7653
  };
7654
+ _this.maskManager = new MaskProcessor(engine);
7277
7655
  return _this;
7278
7656
  }
7279
7657
  var _proto = MeshComponent.prototype;
@@ -7283,12 +7661,42 @@ __decorate([
7283
7661
  renderer.drawGeometry(this.geometry, this.transform.getWorldMatrix(), material, i);
7284
7662
  }
7285
7663
  };
7664
+ _proto.drawStencilMask = function drawStencilMask(renderer) {
7665
+ if (!this.isActiveAndEnabled) {
7666
+ return;
7667
+ }
7668
+ for(var i = 0; i < this.materials.length; i++){
7669
+ var material = this.materials[i];
7670
+ var previousColorMask = material.colorMask;
7671
+ material.colorMask = false;
7672
+ renderer.drawGeometry(this.geometry, this.transform.getWorldMatrix(), material, i);
7673
+ material.colorMask = previousColorMask;
7674
+ }
7675
+ };
7286
7676
  _proto.getBoundingBox = function getBoundingBox() {
7287
7677
  var worldMatrix = this.transform.getWorldMatrix();
7288
7678
  this.meshCollider.setGeometry(this.geometry, worldMatrix);
7289
7679
  var boundingBox = this.meshCollider.getBoundingBox();
7290
7680
  return boundingBox;
7291
7681
  };
7682
+ // TODO: Update data spec
7683
+ _proto.fromData = function fromData(data) {
7684
+ RendererComponent.prototype.fromData.call(this, data);
7685
+ var maskableRendererData = data;
7686
+ var maskOptions = maskableRendererData.mask;
7687
+ if (maskOptions) {
7688
+ this.maskManager.setMaskOptions(maskOptions);
7689
+ }
7690
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.materials), _step; !(_step = _iterator()).done;){
7691
+ var material = _step.value;
7692
+ var stencilRef = this.maskManager.getRefValue();
7693
+ material.stencilRef = [
7694
+ stencilRef,
7695
+ stencilRef
7696
+ ];
7697
+ setMaskMode(material, this.maskManager.maskMode);
7698
+ }
7699
+ };
7292
7700
  return MeshComponent;
7293
7701
  }(RendererComponent);
7294
7702
  __decorate([
@@ -8478,348 +8886,6 @@ Matrix4.tempVec1 = new Vector3();
8478
8886
  Matrix4.tempVec2 = new Vector3();
8479
8887
  Matrix4.tempMat0 = new Matrix4();
8480
8888
 
8481
- /**
8482
- * Helper class to create a WebGL Context
8483
- *
8484
- * @param canvas
8485
- * @param glType
8486
- * @param options
8487
- * @returns
8488
- */ function createGLContext(canvas, glType, options) {
8489
- if (glType === void 0) glType = "webgl";
8490
- var context;
8491
- if (glType === "webgl2") {
8492
- context = canvas.getContext("webgl2", options);
8493
- if (!context) {
8494
- console.debug("WebGL2 context retrieval failed, falling back to WebGL context.");
8495
- }
8496
- }
8497
- if (!context || glType === "webgl") {
8498
- context = canvas.getContext("webgl", options);
8499
- }
8500
- if (!context) {
8501
- throw new Error("This browser does not support WebGL or the WebGL version is incorrect. Please check your WebGL version.");
8502
- }
8503
- return context;
8504
- }
8505
-
8506
- function gpuTimer(gl) {
8507
- var ext = gl.getExtension("EXT_disjoint_timer_query_webgl2");
8508
- if (ext) {
8509
- var query = gl.createQuery();
8510
- var getTime = /*#__PURE__*/ _async_to_generator(function() {
8511
- return __generator(this, function(_state) {
8512
- return [
8513
- 2,
8514
- new Promise(function(resolve, reject) {
8515
- if (query) {
8516
- var available = gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE);
8517
- var disjoint = gl.getParameter(ext.GPU_DISJOINT_EXT);
8518
- if (available && !disjoint) {
8519
- // See how much time the rendering of the object took in nanoseconds.
8520
- var timeElapsed = gl.getQueryParameter(query, gl.QUERY_RESULT); // Do something useful with the time. Note that care should be
8521
- // taken to use all significant bits of the result, not just the
8522
- // least significant 32 bits.
8523
- resolve(timeElapsed / 1000 / 1000);
8524
- }
8525
- if (available || disjoint) {
8526
- // Clean up the query object.
8527
- gl.deleteQuery(query); // Don't re-enter this polling loop.
8528
- query = null;
8529
- }
8530
- available !== null && query && window.setTimeout(function() {
8531
- getTime().then(resolve).catch;
8532
- }, 1);
8533
- }
8534
- })
8535
- ];
8536
- });
8537
- });
8538
- if (!query) {
8539
- return;
8540
- }
8541
- return {
8542
- begin: function() {
8543
- query && gl.beginQuery(ext.TIME_ELAPSED_EXT, query);
8544
- },
8545
- end: function() {
8546
- gl.endQuery(ext.TIME_ELAPSED_EXT);
8547
- },
8548
- getTime: getTime
8549
- };
8550
- }
8551
- }
8552
-
8553
- var initErrors = [];
8554
- var glContext = {};
8555
- var IOS16_LOCKDOWN_MODE = "iOS16 lockdown mode, WebGL Constants not in global";
8556
- var WEBGL_CONSTANTS_NOT_IN_GLOBAL = "WebGL Constants not in global, please check your environment";
8557
- if (!initErrors.length) {
8558
- initGLContext();
8559
- }
8560
- function initGLContext() {
8561
- // 重要:iOS 9/10 低版本需要拷贝 gl context 的 prototype,要不然会有属性值的缺失
8562
- if (typeof WebGL2RenderingContext === "function") {
8563
- copy(WebGL2RenderingContext);
8564
- } else if (typeof WebGLRenderingContext !== "undefined") {
8565
- copy(WebGLRenderingContext);
8566
- copy(WebGLRenderingContext.prototype);
8567
- } else {
8568
- if (canUseBOM) {
8569
- initErrors.push(// iOS 16 lockdown mode
8570
- isIOS() ? IOS16_LOCKDOWN_MODE : WEBGL_CONSTANTS_NOT_IN_GLOBAL);
8571
- } else {
8572
- initErrors.push(WEBGL_CONSTANTS_NOT_IN_GLOBAL);
8573
- }
8574
- }
8575
- if (!initErrors.length && !("HALF_FLOAT" in glContext)) {
8576
- // @ts-expect-error set default value
8577
- glContext["HALF_FLOAT"] = 5131;
8578
- }
8579
- }
8580
- function isWebGL2(gl) {
8581
- return typeof WebGL2RenderingContext !== "undefined" && gl.constructor.name === "WebGL2RenderingContext";
8582
- }
8583
- function copy(target) {
8584
- for(var name in target){
8585
- if (/^[A-Z_]/.test(name)) {
8586
- // @ts-expect-error safe to assign
8587
- glContext[name] = target[name];
8588
- }
8589
- }
8590
- }
8591
- function vertexFormatType2GLType(formatType) {
8592
- switch(formatType){
8593
- case VertexFormatType.Float32:
8594
- return WebGLRenderingContext["FLOAT"];
8595
- case VertexFormatType.Int16:
8596
- return WebGLRenderingContext["SHORT"];
8597
- case VertexFormatType.Int8:
8598
- return WebGLRenderingContext["BYTE"];
8599
- case VertexFormatType.UInt16:
8600
- return WebGLRenderingContext["UNSIGNED_SHORT"];
8601
- case VertexFormatType.UInt8:
8602
- return WebGLRenderingContext["UNSIGNED_BYTE"];
8603
- default:
8604
- return WebGLRenderingContext["FLOAT"];
8605
- }
8606
- }
8607
- function glType2VertexFormatType(webglType) {
8608
- switch(webglType){
8609
- case WebGLRenderingContext["FLOAT"]:
8610
- return VertexFormatType.Float32;
8611
- case WebGLRenderingContext["SHORT"]:
8612
- return VertexFormatType.Int16;
8613
- case WebGLRenderingContext["BYTE"]:
8614
- return VertexFormatType.Int8;
8615
- case WebGLRenderingContext["UNSIGNED_SHORT"]:
8616
- return VertexFormatType.UInt16;
8617
- case WebGLRenderingContext["UNSIGNED_BYTE"]:
8618
- return VertexFormatType.UInt8;
8619
- default:
8620
- return VertexFormatType.Float32;
8621
- }
8622
- }
8623
-
8624
- exports.ShaderType = void 0;
8625
- (function(ShaderType) {
8626
- ShaderType[ShaderType["vertex"] = 0] = "vertex";
8627
- ShaderType[ShaderType["fragment"] = 1] = "fragment";
8628
- })(exports.ShaderType || (exports.ShaderType = {}));
8629
- exports.MaskMode = void 0;
8630
- (function(MaskMode) {
8631
- /**
8632
- * 无
8633
- */ MaskMode[MaskMode["NONE"] = 0] = "NONE";
8634
- /**
8635
- * 蒙版
8636
- */ MaskMode[MaskMode["MASK"] = 1] = "MASK";
8637
- /**
8638
- * 被遮挡
8639
- */ MaskMode[MaskMode["OBSCURED"] = 2] = "OBSCURED";
8640
- /**
8641
- * 被反向遮挡
8642
- */ MaskMode[MaskMode["REVERSE_OBSCURED"] = 3] = "REVERSE_OBSCURED";
8643
- })(exports.MaskMode || (exports.MaskMode = {}));
8644
-
8645
- function valIfUndefined(val, def) {
8646
- if (val === undefined || val === null) {
8647
- return def;
8648
- }
8649
- return val;
8650
- }
8651
- function getPreMultiAlpha(blending) {
8652
- switch(blending){
8653
- case BlendingMode.ALPHA:
8654
- return 1;
8655
- case BlendingMode.ADD:
8656
- return 1;
8657
- case BlendingMode.SUBTRACTION:
8658
- return 1;
8659
- case BlendingMode.STRONG_LIGHT:
8660
- return 1;
8661
- case BlendingMode.WEAK_LIGHT:
8662
- return 1;
8663
- case BlendingMode.SUPERPOSITION:
8664
- return 2;
8665
- case BlendingMode.BRIGHTNESS:
8666
- return 3;
8667
- case BlendingMode.MULTIPLY:
8668
- return 0;
8669
- default:
8670
- // 处理undefined
8671
- return 1;
8672
- }
8673
- }
8674
- function setBlendMode(material, blendMode) {
8675
- switch(blendMode){
8676
- case undefined:
8677
- material.blendFunction = [
8678
- glContext.ONE,
8679
- glContext.ONE_MINUS_SRC_ALPHA,
8680
- glContext.ONE,
8681
- glContext.ONE_MINUS_SRC_ALPHA
8682
- ];
8683
- break;
8684
- case BlendingMode.ALPHA:
8685
- material.blendFunction = [
8686
- glContext.ONE,
8687
- glContext.ONE_MINUS_SRC_ALPHA,
8688
- glContext.ONE,
8689
- glContext.ONE_MINUS_SRC_ALPHA
8690
- ];
8691
- break;
8692
- case BlendingMode.ADD:
8693
- material.blendFunction = [
8694
- glContext.ONE,
8695
- glContext.ONE,
8696
- glContext.ONE,
8697
- glContext.ONE
8698
- ];
8699
- break;
8700
- case BlendingMode.SUBTRACTION:
8701
- material.blendFunction = [
8702
- glContext.ONE,
8703
- glContext.ONE,
8704
- glContext.ZERO,
8705
- glContext.ONE
8706
- ];
8707
- material.blendEquation = [
8708
- glContext.FUNC_REVERSE_SUBTRACT,
8709
- glContext.FUNC_REVERSE_SUBTRACT
8710
- ];
8711
- break;
8712
- case BlendingMode.SUPERPOSITION:
8713
- material.blendFunction = [
8714
- glContext.ONE,
8715
- glContext.ONE,
8716
- glContext.ONE,
8717
- glContext.ONE
8718
- ];
8719
- break;
8720
- case BlendingMode.MULTIPLY:
8721
- material.blendFunction = [
8722
- glContext.DST_COLOR,
8723
- glContext.ONE_MINUS_SRC_ALPHA,
8724
- glContext.DST_COLOR,
8725
- glContext.ONE_MINUS_SRC_ALPHA
8726
- ];
8727
- break;
8728
- case BlendingMode.BRIGHTNESS:
8729
- material.blendFunction = [
8730
- glContext.ONE,
8731
- glContext.ONE_MINUS_SRC_ALPHA,
8732
- glContext.ONE,
8733
- glContext.ONE_MINUS_SRC_ALPHA
8734
- ];
8735
- break;
8736
- case BlendingMode.STRONG_LIGHT:
8737
- material.blendFunction = [
8738
- glContext.DST_COLOR,
8739
- glContext.DST_ALPHA,
8740
- glContext.ZERO,
8741
- glContext.ONE
8742
- ];
8743
- break;
8744
- case BlendingMode.WEAK_LIGHT:
8745
- material.blendFunction = [
8746
- glContext.DST_COLOR,
8747
- glContext.ZERO,
8748
- glContext.ZERO,
8749
- glContext.ONE
8750
- ];
8751
- break;
8752
- default:
8753
- console.warn("BlendMode " + blendMode + " not in specification, please set blend params separately.");
8754
- }
8755
- }
8756
- function setSideMode(material, side) {
8757
- if (side === SideMode.DOUBLE) {
8758
- material.culling = false;
8759
- } else {
8760
- material.culling = true;
8761
- material.frontFace = glContext.CW;
8762
- material.cullFace = side === SideMode.BACK ? glContext.BACK : glContext.FRONT;
8763
- }
8764
- }
8765
- function setMaskMode(material, maskMode) {
8766
- switch(maskMode){
8767
- case undefined:
8768
- material.stencilTest = false;
8769
- break;
8770
- case exports.MaskMode.MASK:
8771
- material.stencilTest = true;
8772
- material.stencilFunc = [
8773
- glContext.ALWAYS,
8774
- glContext.ALWAYS
8775
- ];
8776
- material.stencilOpZPass = [
8777
- glContext.REPLACE,
8778
- glContext.REPLACE
8779
- ];
8780
- break;
8781
- case exports.MaskMode.OBSCURED:
8782
- material.stencilTest = true;
8783
- material.stencilFunc = [
8784
- glContext.EQUAL,
8785
- glContext.EQUAL
8786
- ];
8787
- break;
8788
- case exports.MaskMode.REVERSE_OBSCURED:
8789
- material.stencilTest = true;
8790
- material.stencilFunc = [
8791
- glContext.NOTEQUAL,
8792
- glContext.NOTEQUAL
8793
- ];
8794
- break;
8795
- case exports.MaskMode.NONE:
8796
- material.stencilTest = false;
8797
- break;
8798
- default:
8799
- console.warn("MaskMode " + maskMode + " not in specification, please set stencil params seperately.");
8800
- }
8801
- }
8802
-
8803
- exports.TextureLoadAction = void 0;
8804
- (function(TextureLoadAction) {
8805
- TextureLoadAction[TextureLoadAction["whatever"] = 0] = "whatever";
8806
- //preserve previous attachment
8807
- //load = 1,
8808
- //clear attachment
8809
- TextureLoadAction[TextureLoadAction["clear"] = 2] = "clear";
8810
- })(exports.TextureLoadAction || (exports.TextureLoadAction = {}));
8811
- exports.TextureSourceType = void 0;
8812
- (function(TextureSourceType) {
8813
- TextureSourceType[TextureSourceType["none"] = 0] = "none";
8814
- TextureSourceType[TextureSourceType["data"] = 1] = "data";
8815
- TextureSourceType[TextureSourceType["image"] = 2] = "image";
8816
- TextureSourceType[TextureSourceType["compressed"] = 3] = "compressed";
8817
- TextureSourceType[TextureSourceType["video"] = 4] = "video";
8818
- TextureSourceType[TextureSourceType["canvas"] = 5] = "canvas";
8819
- TextureSourceType[TextureSourceType["framebuffer"] = 6] = "framebuffer";
8820
- TextureSourceType[TextureSourceType["mipmaps"] = 7] = "mipmaps";
8821
- })(exports.TextureSourceType || (exports.TextureSourceType = {}));
8822
-
8823
8889
  /**
8824
8890
  * 负责下载各种资源,并提供了一些异步加载和缓存管理的功能
8825
8891
  */ var Downloader = /*#__PURE__*/ function() {
@@ -10298,39 +10364,6 @@ exports.MaterialRenderType = void 0;
10298
10364
  return Material;
10299
10365
  }(EffectsObject);
10300
10366
 
10301
- var MaskProcessor = /*#__PURE__*/ function() {
10302
- function MaskProcessor(engine) {
10303
- this.engine = engine;
10304
- this.alphaMaskEnabled = false;
10305
- this.maskMode = exports.MaskMode.NONE;
10306
- this.maskable = null;
10307
- this.stencilClearAction = {
10308
- stencilAction: exports.TextureLoadAction.clear
10309
- };
10310
- }
10311
- var _proto = MaskProcessor.prototype;
10312
- _proto.getRefValue = function getRefValue() {
10313
- return 1;
10314
- };
10315
- _proto.setMaskOptions = function setMaskOptions(data) {
10316
- var _data_isMask = data.isMask, isMask = _data_isMask === void 0 ? false : _data_isMask, _data_inverted = data.inverted, inverted = _data_inverted === void 0 ? false : _data_inverted, reference = data.reference, _data_alphaMaskEnabled = data.alphaMaskEnabled, alphaMaskEnabled = _data_alphaMaskEnabled === void 0 ? false : _data_alphaMaskEnabled;
10317
- this.alphaMaskEnabled = alphaMaskEnabled;
10318
- if (isMask) {
10319
- this.maskMode = exports.MaskMode.MASK;
10320
- } else {
10321
- this.maskMode = inverted ? exports.MaskMode.REVERSE_OBSCURED : exports.MaskMode.OBSCURED;
10322
- this.maskable = this.engine.findObject(reference);
10323
- }
10324
- };
10325
- _proto.drawStencilMask = function drawStencilMask(renderer) {
10326
- if (this.maskable) {
10327
- renderer.clear(this.stencilClearAction);
10328
- this.maskable.drawStencilMask(renderer);
10329
- }
10330
- };
10331
- return MaskProcessor;
10332
- }();
10333
-
10334
10367
  var EFFECTS_COPY_MESH_NAME = "effects-internal-copy";
10335
10368
  var COPY_MESH_SHADER_ID = "effects-internal-copy-mesh";
10336
10369
  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}";
@@ -10643,6 +10676,9 @@ var DrawObjectPass = /*#__PURE__*/ function(RenderPass) {
10643
10676
  stencilAction: exports.TextureLoadAction.clear
10644
10677
  });
10645
10678
  }
10679
+ this.meshes.sort(function(a, b) {
10680
+ return a.priority - b.priority;
10681
+ });
10646
10682
  renderer.renderMeshes(this.meshes);
10647
10683
  };
10648
10684
  _proto.onCameraCleanup = function onCameraCleanup(renderer) {
@@ -12744,244 +12780,131 @@ var ShaderFactory = /*#__PURE__*/ function() {
12744
12780
  return ShaderFactory;
12745
12781
  }();
12746
12782
 
12747
- // Bloom 阈值 Pass
12748
- var BloomThresholdPass = /*#__PURE__*/ function(RenderPass) {
12749
- _inherits(BloomThresholdPass, RenderPass);
12750
- function BloomThresholdPass(renderer) {
12783
+ // Bloom Pass - 包含阈值提取、高斯模糊(Down Sample 和 Up Sample)
12784
+ var BloomPass = /*#__PURE__*/ function(RenderPass) {
12785
+ _inherits(BloomPass, RenderPass);
12786
+ function BloomPass(renderer, iterationCount) {
12787
+ if (iterationCount === void 0) iterationCount = 4;
12751
12788
  var _this;
12752
12789
  _this = RenderPass.call(this, renderer) || this;
12790
+ _this.tempRTs = [];
12791
+ _this.iterationCount = iterationCount;
12753
12792
  var engine = _this.renderer.engine;
12754
- var geometry = Geometry.create(engine, {
12755
- mode: glContext.TRIANGLE_STRIP,
12756
- attributes: {
12757
- aPos: {
12758
- type: glContext.FLOAT,
12759
- size: 2,
12760
- data: new Float32Array([
12761
- -1,
12762
- 1,
12763
- -1,
12764
- -1,
12765
- 1,
12766
- 1,
12767
- 1,
12768
- -1
12769
- ])
12770
- }
12771
- },
12772
- drawCount: 4
12773
- });
12774
- var material = Material.create(engine, {
12793
+ // Threshold material
12794
+ _this.thresholdMaterial = Material.create(engine, {
12775
12795
  shader: {
12776
12796
  vertex: screenMeshVert,
12777
12797
  fragment: thresholdFrag,
12778
12798
  glslVersion: exports.GLSLVersion.GLSL1
12779
12799
  }
12780
12800
  });
12781
- material.blending = false;
12782
- material.depthTest = false;
12783
- material.culling = false;
12784
- _this.screenMesh = Mesh.create(engine, {
12785
- geometry: geometry,
12786
- material: material,
12787
- priority: 0
12801
+ _this.thresholdMaterial.blending = false;
12802
+ _this.thresholdMaterial.depthTest = false;
12803
+ _this.thresholdMaterial.culling = false;
12804
+ // Down sample H material
12805
+ _this.downSampleHMaterial = Material.create(engine, {
12806
+ shader: {
12807
+ vertex: screenMeshVert,
12808
+ fragment: gaussianDownHFrag,
12809
+ glslVersion: exports.GLSLVersion.GLSL1
12810
+ }
12788
12811
  });
12812
+ _this.downSampleHMaterial.blending = false;
12813
+ _this.downSampleHMaterial.depthTest = false;
12814
+ _this.downSampleHMaterial.culling = false;
12815
+ // Down sample V material
12816
+ _this.downSampleVMaterial = Material.create(engine, {
12817
+ shader: {
12818
+ vertex: screenMeshVert,
12819
+ fragment: gaussianDownVFrag,
12820
+ glslVersion: exports.GLSLVersion.GLSL1
12821
+ }
12822
+ });
12823
+ _this.downSampleVMaterial.blending = false;
12824
+ _this.downSampleVMaterial.depthTest = false;
12825
+ _this.downSampleVMaterial.culling = false;
12826
+ // Up sample material
12827
+ _this.upSampleMaterial = Material.create(engine, {
12828
+ shader: {
12829
+ vertex: screenMeshVert,
12830
+ fragment: gaussianUpFrag,
12831
+ glslVersion: exports.GLSLVersion.GLSL1
12832
+ }
12833
+ });
12834
+ _this.upSampleMaterial.blending = false;
12835
+ _this.upSampleMaterial.depthTest = false;
12836
+ _this.upSampleMaterial.culling = false;
12789
12837
  _this.priority = 5000;
12790
- _this.name = "BloomThresholdPass";
12838
+ _this.name = "BloomPass";
12791
12839
  return _this;
12792
12840
  }
12793
- var _proto = BloomThresholdPass.prototype;
12841
+ var _proto = BloomPass.prototype;
12794
12842
  _proto.configure = function configure(renderer) {
12795
- this.framebuffer = renderer.getTemporaryRT(this.name, renderer.getWidth(), renderer.getHeight(), 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
12843
+ // 获取场景纹理用于 ToneMappingPass
12796
12844
  this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
12797
12845
  this.sceneTextureHandle.texture = this.mainTexture;
12798
- renderer.setFramebuffer(this.framebuffer);
12799
12846
  };
12800
12847
  _proto.execute = function execute(renderer) {
12801
12848
  var _renderer_renderingData_currentFrame_globalVolume_bloom, _renderer_renderingData_currentFrame_globalVolume;
12802
- renderer.clear({
12803
- colorAction: exports.TextureLoadAction.clear,
12804
- depthAction: exports.TextureLoadAction.clear,
12805
- stencilAction: exports.TextureLoadAction.clear
12806
- });
12807
- this.screenMesh.material.setTexture("_MainTex", this.mainTexture);
12849
+ var baseWidth = renderer.getWidth();
12850
+ var baseHeight = renderer.getHeight();
12808
12851
  var _renderer_renderingData_currentFrame_globalVolume_bloom_threshold;
12852
+ // 1. Threshold pass - 提取高亮区域
12809
12853
  var threshold = (_renderer_renderingData_currentFrame_globalVolume_bloom_threshold = (_renderer_renderingData_currentFrame_globalVolume = renderer.renderingData.currentFrame.globalVolume) == null ? void 0 : (_renderer_renderingData_currentFrame_globalVolume_bloom = _renderer_renderingData_currentFrame_globalVolume.bloom) == null ? void 0 : _renderer_renderingData_currentFrame_globalVolume_bloom.threshold) != null ? _renderer_renderingData_currentFrame_globalVolume_bloom_threshold : 1.0;
12810
- this.screenMesh.material.setFloat("_Threshold", threshold);
12811
- renderer.renderMeshes([
12812
- this.screenMesh
12813
- ]);
12854
+ this.thresholdRT = renderer.getTemporaryRT("_BloomThreshold", baseWidth, baseHeight, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
12855
+ this.thresholdMaterial.setFloat("_Threshold", threshold);
12856
+ renderer.blit(this.mainTexture, this.thresholdRT, this.thresholdMaterial);
12857
+ var currentTexture = this.thresholdRT.getColorTextures()[0];
12858
+ // 2. Down sample passes
12859
+ for(var i = 0; i < this.iterationCount; i++){
12860
+ var downWidth = Math.floor(baseWidth / Math.pow(2, i + 1));
12861
+ var downHeight = Math.floor(baseHeight / Math.pow(2, i + 1));
12862
+ // Horizontal pass
12863
+ var tempH = renderer.getTemporaryRT("_BloomDownH" + i, downWidth, downHeight, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
12864
+ this.downSampleHMaterial.setVector2("_TextureSize", getTextureSize(currentTexture));
12865
+ renderer.blit(currentTexture, tempH, this.downSampleHMaterial);
12866
+ // Vertical pass
12867
+ var tempV = renderer.getTemporaryRT("_BloomDownV" + i, downWidth, downHeight, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
12868
+ this.downSampleVMaterial.setVector2("_TextureSize", getTextureSize(tempH.getColorTextures()[0]));
12869
+ renderer.blit(tempH.getColorTextures()[0], tempV, this.downSampleVMaterial);
12870
+ // 释放 H pass RT,保留 V pass RT 用于 up sample
12871
+ renderer.releaseTemporaryRT(tempH);
12872
+ this.tempRTs.push(tempV);
12873
+ currentTexture = tempV.getColorTextures()[0];
12874
+ }
12875
+ // 释放 threshold RT
12876
+ renderer.releaseTemporaryRT(this.thresholdRT);
12877
+ // 3. Up sample passes
12878
+ for(var i1 = this.iterationCount - 1; i1 > 0; i1--){
12879
+ var upWidth = Math.floor(baseWidth / Math.pow(2, i1 - 1));
12880
+ var upHeight = Math.floor(baseHeight / Math.pow(2, i1 - 1));
12881
+ var tempUp = renderer.getTemporaryRT("_BloomUp" + i1, upWidth, upHeight, 0, exports.FilterMode.Linear, exports.RenderTextureFormat.RGBAHalf);
12882
+ // 获取下一层的 down sample 结果
12883
+ var downSampleTexture = this.tempRTs[i1 - 1].getColorTextures()[0];
12884
+ this.upSampleMaterial.setTexture("_GaussianDownTex", downSampleTexture);
12885
+ this.upSampleMaterial.setVector2("_GaussianDownTextureSize", getTextureSize(downSampleTexture));
12886
+ renderer.blit(currentTexture, tempUp, this.upSampleMaterial);
12887
+ currentTexture = tempUp.getColorTextures()[0];
12888
+ this.tempRTs.push(tempUp);
12889
+ }
12890
+ // 设置最终输出到当前 framebuffer
12891
+ renderer.setFramebuffer(this.tempRTs[this.tempRTs.length - 1]);
12814
12892
  };
12815
12893
  _proto.onCameraCleanup = function onCameraCleanup(renderer) {
12816
- if (this.framebuffer) {
12817
- renderer.releaseTemporaryRT(this.framebuffer);
12894
+ // 释放所有临时 RT
12895
+ for(var i = 0; i < this.tempRTs.length; i++){
12896
+ renderer.releaseTemporaryRT(this.tempRTs[i]);
12818
12897
  }
12898
+ this.tempRTs = [];
12819
12899
  };
12820
12900
  _proto.dispose = function dispose(options) {
12901
+ this.thresholdMaterial.dispose();
12902
+ this.downSampleHMaterial.dispose();
12903
+ this.downSampleVMaterial.dispose();
12904
+ this.upSampleMaterial.dispose();
12821
12905
  RenderPass.prototype.dispose.call(this, options);
12822
12906
  };
12823
- return BloomThresholdPass;
12824
- }(RenderPass);
12825
- var HQGaussianDownSamplePass = /*#__PURE__*/ function(RenderPass) {
12826
- _inherits(HQGaussianDownSamplePass, RenderPass);
12827
- function HQGaussianDownSamplePass(renderer, type, level) {
12828
- var _this;
12829
- _this = RenderPass.call(this, renderer) || this;
12830
- _this.type = type;
12831
- _this.level = level;
12832
- var engine = _this.renderer.engine;
12833
- var name = "PostProcess";
12834
- var geometry = Geometry.create(engine, {
12835
- name: name,
12836
- mode: glContext.TRIANGLE_STRIP,
12837
- attributes: {
12838
- aPos: {
12839
- type: glContext.FLOAT,
12840
- size: 2,
12841
- data: new Float32Array([
12842
- -1,
12843
- 1,
12844
- -1,
12845
- -1,
12846
- 1,
12847
- 1,
12848
- 1,
12849
- -1
12850
- ])
12851
- }
12852
- },
12853
- drawCount: 4
12854
- });
12855
- var fragment = type === "H" ? gaussianDownHFrag : gaussianDownVFrag;
12856
- var shader = {
12857
- vertex: screenMeshVert,
12858
- fragment: fragment,
12859
- glslVersion: exports.GLSLVersion.GLSL1
12860
- };
12861
- var material = Material.create(engine, {
12862
- name: name,
12863
- shader: shader
12864
- });
12865
- material.blending = false;
12866
- material.depthTest = false;
12867
- material.culling = false;
12868
- _this.screenMesh = Mesh.create(engine, {
12869
- name: name,
12870
- geometry: geometry,
12871
- material: material,
12872
- priority: 0
12873
- });
12874
- _this.priority = 5000;
12875
- _this.name = "GaussianDownPass" + type + level;
12876
- return _this;
12877
- }
12878
- var _proto = HQGaussianDownSamplePass.prototype;
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);
12883
- this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
12884
- renderer.setFramebuffer(this.framebuffer);
12885
- };
12886
- _proto.execute = function execute(renderer) {
12887
- renderer.clear({
12888
- colorAction: exports.TextureLoadAction.clear,
12889
- depthAction: exports.TextureLoadAction.clear,
12890
- stencilAction: exports.TextureLoadAction.clear
12891
- });
12892
- this.screenMesh.material.setTexture("_MainTex", this.mainTexture);
12893
- this.screenMesh.material.setVector2("_TextureSize", getTextureSize(this.mainTexture));
12894
- renderer.renderMeshes([
12895
- this.screenMesh
12896
- ]);
12897
- if (this.type === "V") {
12898
- this.gaussianResult.texture = renderer.getFramebuffer().getColorTextures()[0];
12899
- }
12900
- };
12901
- _proto.onCameraCleanup = function onCameraCleanup(renderer) {
12902
- if (this.framebuffer) {
12903
- renderer.releaseTemporaryRT(this.framebuffer);
12904
- }
12905
- };
12906
- return HQGaussianDownSamplePass;
12907
- }(RenderPass);
12908
- var HQGaussianUpSamplePass = /*#__PURE__*/ function(RenderPass) {
12909
- _inherits(HQGaussianUpSamplePass, RenderPass);
12910
- function HQGaussianUpSamplePass(renderer, level) {
12911
- var _this;
12912
- _this = RenderPass.call(this, renderer) || this;
12913
- _this.level = level;
12914
- var name = "PostProcess";
12915
- var engine = _this.renderer.engine;
12916
- var geometry = Geometry.create(engine, {
12917
- name: name,
12918
- mode: glContext.TRIANGLE_STRIP,
12919
- attributes: {
12920
- aPos: {
12921
- type: glContext.FLOAT,
12922
- size: 2,
12923
- data: new Float32Array([
12924
- -1,
12925
- 1,
12926
- -1,
12927
- -1,
12928
- 1,
12929
- 1,
12930
- 1,
12931
- -1
12932
- ])
12933
- }
12934
- },
12935
- drawCount: 4
12936
- });
12937
- var shader = {
12938
- vertex: screenMeshVert,
12939
- fragment: gaussianUpFrag
12940
- };
12941
- var material = Material.create(engine, {
12942
- name: name,
12943
- shader: shader
12944
- });
12945
- material.blending = false;
12946
- material.depthTest = false;
12947
- material.culling = false;
12948
- _this.screenMesh = Mesh.create(engine, {
12949
- name: name,
12950
- geometry: geometry,
12951
- material: material,
12952
- priority: 0
12953
- });
12954
- _this.priority = 5000;
12955
- _this.name = "GaussianUpPass" + level;
12956
- return _this;
12957
- }
12958
- var _proto = HQGaussianUpSamplePass.prototype;
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);
12963
- this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
12964
- renderer.setFramebuffer(this.framebuffer);
12965
- };
12966
- _proto.execute = function execute(renderer) {
12967
- renderer.clear({
12968
- colorAction: exports.TextureLoadAction.clear,
12969
- depthAction: exports.TextureLoadAction.clear,
12970
- stencilAction: exports.TextureLoadAction.clear
12971
- });
12972
- this.screenMesh.material.setTexture("_MainTex", this.mainTexture);
12973
- this.screenMesh.material.setTexture("_GaussianDownTex", this.gaussianDownSampleResult.texture);
12974
- this.screenMesh.material.setVector2("_GaussianDownTextureSize", getTextureSize(this.gaussianDownSampleResult.texture));
12975
- renderer.renderMeshes([
12976
- this.screenMesh
12977
- ]);
12978
- };
12979
- _proto.onCameraCleanup = function onCameraCleanup(renderer) {
12980
- if (this.framebuffer) {
12981
- renderer.releaseTemporaryRT(this.framebuffer);
12982
- }
12983
- };
12984
- return HQGaussianUpSamplePass;
12907
+ return BloomPass;
12985
12908
  }(RenderPass);
12986
12909
  // 合并Bloom的高斯模糊结果,并应用ACES Tonemapping
12987
12910
  var ToneMappingPass = /*#__PURE__*/ function(RenderPass) {
@@ -13125,36 +13048,11 @@ var seed$6 = 1;
13125
13048
  if (postProcessingEnabled) {
13126
13049
  var sceneTextureHandle = new RenderTargetHandle(engine); //保存后处理前的屏幕图像
13127
13050
  var gaussianStep = 7; // 高斯模糊的迭代次数,次数越高模糊范围越大
13128
- var viewport = [
13129
- 0,
13130
- 0,
13131
- this.renderer.getWidth() / 2,
13132
- this.renderer.getHeight() / 2
13133
- ];
13134
- var gaussianDownResults = new Array(gaussianStep); //存放多个高斯Pass的模糊结果,用于Bloom
13135
- var bloomThresholdPass = new BloomThresholdPass(renderer);
13136
- bloomThresholdPass.sceneTextureHandle = sceneTextureHandle;
13137
- this.addRenderPass(bloomThresholdPass);
13138
- for(var i = 0; i < gaussianStep; i++){
13139
- gaussianDownResults[i] = new RenderTargetHandle(engine);
13140
- var gaussianDownHPass = new HQGaussianDownSamplePass(renderer, "H", i);
13141
- var gaussianDownVPass = new HQGaussianDownSamplePass(renderer, "V", i);
13142
- gaussianDownVPass.gaussianResult = gaussianDownResults[i];
13143
- this.addRenderPass(gaussianDownHPass);
13144
- this.addRenderPass(gaussianDownVPass);
13145
- viewport[2] /= 2;
13146
- viewport[3] /= 2;
13147
- // TODO 限制最大迭代
13148
- }
13149
- viewport[2] *= 4;
13150
- viewport[3] *= 4;
13151
- for(var i1 = 0; i1 < gaussianStep - 1; i1++){
13152
- var gaussianUpPass = new HQGaussianUpSamplePass(renderer, gaussianStep - i1);
13153
- gaussianUpPass.gaussianDownSampleResult = gaussianDownResults[gaussianStep - 2 - i1];
13154
- this.addRenderPass(gaussianUpPass);
13155
- viewport[2] *= 2;
13156
- viewport[3] *= 2;
13157
- }
13051
+ // Bloom Pass(包含阈值提取、高斯模糊)
13052
+ var bloomPass = new BloomPass(renderer, gaussianStep);
13053
+ bloomPass.sceneTextureHandle = sceneTextureHandle;
13054
+ this.addRenderPass(bloomPass);
13055
+ // Tone Mapping Pass
13158
13056
  var postProcessPass = new ToneMappingPass(renderer, sceneTextureHandle);
13159
13057
  this.addRenderPass(postProcessPass);
13160
13058
  }
@@ -13648,6 +13546,14 @@ var Renderer = /*#__PURE__*/ function() {
13648
13546
  _proto.releaseTemporaryRT = function releaseTemporaryRT(rt) {
13649
13547
  this.renderTargetPool.release(rt);
13650
13548
  };
13549
+ /**
13550
+ * 将源纹理复制到目标 Framebuffer,可使用自定义材质进行处理
13551
+ * @param source - 源纹理
13552
+ * @param destination - 目标 Framebuffer,如果为 null 则渲染到屏幕
13553
+ * @param material - 可选的自定义材质,不传则使用默认复制材质
13554
+ */ _proto.blit = function blit(source, destination, material) {
13555
+ // OVERRIDE
13556
+ };
13651
13557
  _proto.dispose = function dispose() {
13652
13558
  // OVERRIDE
13653
13559
  };
@@ -16710,13 +16616,49 @@ exports.CameraController = __decorate([
16710
16616
  effectsClass(DataType.CameraController)
16711
16617
  ], exports.CameraController);
16712
16618
 
16713
- var CameraVFXItemLoader = /*#__PURE__*/ function(AbstractPlugin) {
16714
- _inherits(CameraVFXItemLoader, AbstractPlugin);
16619
+ function _get_prototype_of(o) {
16620
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
16621
+ return o.__proto__ || Object.getPrototypeOf(o);
16622
+ };
16623
+ return _get_prototype_of(o);
16624
+ }
16625
+
16626
+ function _is_native_function(fn) {
16627
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
16628
+ }
16629
+
16630
+ function _wrap_native_super(Class) {
16631
+ var _cache = typeof Map === "function" ? new Map() : undefined;
16632
+ _wrap_native_super = function _wrap_native_super(Class) {
16633
+ if (Class === null || !_is_native_function(Class)) return Class;
16634
+ if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
16635
+ if (typeof _cache !== "undefined") {
16636
+ if (_cache.has(Class)) return _cache.get(Class);
16637
+ _cache.set(Class, Wrapper);
16638
+ }
16639
+ function Wrapper() {
16640
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
16641
+ }
16642
+ Wrapper.prototype = Object.create(Class.prototype, {
16643
+ constructor: {
16644
+ value: Wrapper,
16645
+ enumerable: false,
16646
+ writable: true,
16647
+ configurable: true
16648
+ }
16649
+ });
16650
+ return _set_prototype_of(Wrapper, Class);
16651
+ };
16652
+ return _wrap_native_super(Class);
16653
+ }
16654
+
16655
+ var CameraVFXItemLoader = /*#__PURE__*/ function(Plugin) {
16656
+ _inherits(CameraVFXItemLoader, Plugin);
16715
16657
  function CameraVFXItemLoader() {
16716
- return AbstractPlugin.apply(this, arguments);
16658
+ return Plugin.apply(this, arguments);
16717
16659
  }
16718
16660
  return CameraVFXItemLoader;
16719
- }(AbstractPlugin);
16661
+ }(_wrap_native_super(Plugin));
16720
16662
 
16721
16663
  exports.HitTestType = void 0;
16722
16664
  (function(HitTestType) {
@@ -17000,13 +16942,13 @@ function getCoord(event) {
17000
16942
  };
17001
16943
  }
17002
16944
 
17003
- var InteractLoader = /*#__PURE__*/ function(AbstractPlugin) {
17004
- _inherits(InteractLoader, AbstractPlugin);
16945
+ var InteractLoader = /*#__PURE__*/ function(Plugin) {
16946
+ _inherits(InteractLoader, Plugin);
17005
16947
  function InteractLoader() {
17006
- return AbstractPlugin.apply(this, arguments);
16948
+ return Plugin.apply(this, arguments);
17007
16949
  }
17008
16950
  return InteractLoader;
17009
- }(AbstractPlugin);
16951
+ }(_wrap_native_super(Plugin));
17010
16952
 
17011
16953
  var vertex = "\nprecision highp float;\n\nattribute vec2 aPoint;\nuniform vec4 uPos;\nuniform vec2 uSize;\nuniform vec4 uQuat;\nuniform vec4 uColor;\nuniform mat4 effects_ObjectToWorld;\nuniform mat4 effects_MatrixInvV;\nuniform mat4 effects_MatrixVP;\nvarying vec4 vColor;\n\nvec3 rotateByQuat(vec3 a, vec4 quat){\n vec3 qvec = quat.xyz;\n vec3 uv = cross(qvec, a);\n vec3 uuv = cross(qvec, uv) * 2.;\n return a +(uv * 2. * quat.w + uuv);\n}\n\nvoid main() {\n vec4 _pos = uPos;\n vec3 point = rotateByQuat(vec3(aPoint.xy * uSize, 0.),uQuat);\n vec4 pos = vec4(_pos.xyz, 1.0);\n pos = effects_ObjectToWorld * pos;\n pos.xyz += effects_MatrixInvV[0].xyz * point.x+ effects_MatrixInvV[1].xyz * point.y;\n gl_Position = effects_MatrixVP * pos;\n vColor = uColor;\n}\n";
17012
16954
  var fragment = "\nprecision highp float;\n\n#define fragColor gl_FragColor\n\nvarying vec4 vColor;\nvoid main() {\n gl_FragColor = vColor*vColor.a;\n}\n";
@@ -17605,16 +17547,16 @@ function shouldIgnoreBouncing(arg, mul) {
17605
17547
  return MeshCollider;
17606
17548
  }();
17607
17549
 
17608
- var SpriteLoader = /*#__PURE__*/ function(AbstractPlugin) {
17609
- _inherits(SpriteLoader, AbstractPlugin);
17550
+ var SpriteLoader = /*#__PURE__*/ function(Plugin) {
17551
+ _inherits(SpriteLoader, Plugin);
17610
17552
  function SpriteLoader() {
17611
17553
  var _this;
17612
- _this = AbstractPlugin.apply(this, arguments) || this;
17554
+ _this = Plugin.apply(this, arguments) || this;
17613
17555
  _this.name = "sprite";
17614
17556
  return _this;
17615
17557
  }
17616
17558
  return SpriteLoader;
17617
- }(AbstractPlugin);
17559
+ }(_wrap_native_super(Plugin));
17618
17560
 
17619
17561
  /**
17620
17562
  * 动画图可播放节点对象
@@ -20105,7 +20047,7 @@ function calculateDirection(prePoint, point, nextPoint) {
20105
20047
  if (this.time >= 0 && this.time < particleSystem.item.duration && particleSystem.isEnded()) {
20106
20048
  particleSystem.reset();
20107
20049
  }
20108
- particleSystem.update(this.time - particleSystem.time);
20050
+ particleSystem.simulate(this.time - particleSystem.time);
20109
20051
  }
20110
20052
  this.lastTime = this.time;
20111
20053
  };
@@ -21556,126 +21498,133 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
21556
21498
  this.initEmitterTransform();
21557
21499
  };
21558
21500
  _proto.onUpdate = function onUpdate(dt) {
21559
- this.update(dt);
21501
+ if (!this.frozen) {
21502
+ this.update(dt);
21503
+ }
21504
+ };
21505
+ _proto.simulate = function simulate(time) {
21506
+ this.update(time * 1000);
21507
+ this.frozen = true;
21560
21508
  };
21561
21509
  _proto.update = function update(delta) {
21562
21510
  var _this = this;
21563
- if (this.started && !this.frozen) {
21564
- var now = this.time + delta / 1000;
21565
- var options = this.options;
21566
- var loopStartTime = this.loopStartTime;
21567
- var emission = this.emission;
21568
- this.time = now;
21569
- this.upDirectionWorld = null;
21570
- this.renderer.updateTime(now, delta);
21571
- var link = this.particleLink;
21572
- var emitterLifetime = (now - loopStartTime) / this.item.duration;
21573
- var timePassed = this.timePassed;
21574
- var trailUpdated = false;
21575
- var updateTrail = function() {
21576
- if (_this.trails && !trailUpdated) {
21577
- trailUpdated = true;
21578
- link.forEach(function(param) {
21579
- var time = param[0], pointIndex = param[1], delay = param[2], point = param[3];
21580
- if (time < timePassed) {
21581
- _this.clearPointTrail(pointIndex);
21582
- } else if (timePassed > delay) {
21583
- _this.updatePointTrail(pointIndex, emitterLifetime, point, delay);
21584
- }
21585
- });
21511
+ if (!this.started) {
21512
+ return;
21513
+ }
21514
+ var now = this.time + delta / 1000;
21515
+ var options = this.options;
21516
+ var loopStartTime = this.loopStartTime;
21517
+ var emission = this.emission;
21518
+ this.time = now;
21519
+ this.upDirectionWorld = null;
21520
+ this.renderer.updateTime(now, delta);
21521
+ var link = this.particleLink;
21522
+ var emitterLifetime = (now - loopStartTime) / this.item.duration;
21523
+ var timePassed = this.timePassed;
21524
+ var trailUpdated = false;
21525
+ var updateTrail = function() {
21526
+ if (_this.trails && !trailUpdated) {
21527
+ trailUpdated = true;
21528
+ link.forEach(function(param) {
21529
+ var time = param[0], pointIndex = param[1], delay = param[2], point = param[3];
21530
+ if (time < timePassed) {
21531
+ _this.clearPointTrail(pointIndex);
21532
+ } else if (timePassed > delay) {
21533
+ _this.updatePointTrail(pointIndex, emitterLifetime, point, delay);
21534
+ }
21535
+ });
21536
+ }
21537
+ };
21538
+ if (!this.ended) {
21539
+ var duration = this.item.duration;
21540
+ var lifetime = this.lifetime;
21541
+ if (timePassed < duration) {
21542
+ var interval = 1 / emission.rateOverTime.getValue(lifetime);
21543
+ var pointCount = Math.floor((timePassed - this.lastEmitTime) / interval);
21544
+ var maxEmissionCount = pointCount;
21545
+ var timeDelta = interval / pointCount;
21546
+ var meshTime = now;
21547
+ var maxCount = options.maxCount;
21548
+ this.updateEmitterTransform(timePassed);
21549
+ var shouldSkipGenerate = function() {
21550
+ var first = link.first;
21551
+ return _this.emissionStopped || link.length === maxCount && first && first.content[0] - loopStartTime > timePassed;
21552
+ };
21553
+ for(var i = 0; i < maxEmissionCount && i < maxCount; i++){
21554
+ if (shouldSkipGenerate()) {
21555
+ break;
21556
+ }
21557
+ var p = this.createPoint(lifetime);
21558
+ p.delay += meshTime + i * timeDelta;
21559
+ this.addParticle(p, maxCount);
21560
+ this.lastEmitTime = timePassed;
21586
21561
  }
21587
- };
21588
- if (!this.ended) {
21589
- var duration = this.item.duration;
21590
- var lifetime = this.lifetime;
21591
- if (timePassed < duration) {
21592
- var interval = 1 / emission.rateOverTime.getValue(lifetime);
21593
- var pointCount = Math.floor((timePassed - this.lastEmitTime) / interval);
21594
- var maxEmissionCount = pointCount;
21595
- var timeDelta = interval / pointCount;
21596
- var meshTime = now;
21597
- var maxCount = options.maxCount;
21598
- this.updateEmitterTransform(timePassed);
21599
- var shouldSkipGenerate = function() {
21600
- var first = link.first;
21601
- return _this.emissionStopped || link.length === maxCount && first && first.content[0] - loopStartTime > timePassed;
21602
- };
21603
- for(var i = 0; i < maxEmissionCount && i < maxCount; i++){
21604
- if (shouldSkipGenerate()) {
21605
- break;
21606
- }
21607
- var p = this.createPoint(lifetime);
21608
- p.delay += meshTime + i * timeDelta;
21609
- this.addParticle(p, maxCount);
21610
- this.lastEmitTime = timePassed;
21562
+ var bursts = emission.bursts;
21563
+ for(var j = (bursts == null ? void 0 : bursts.length) - 1, cursor = 0; j >= 0 && cursor < maxCount; j--){
21564
+ if (shouldSkipGenerate()) {
21565
+ break;
21611
21566
  }
21612
- var bursts = emission.bursts;
21613
- for(var j = (bursts == null ? void 0 : bursts.length) - 1, cursor = 0; j >= 0 && cursor < maxCount; j--){
21614
- if (shouldSkipGenerate()) {
21615
- break;
21567
+ var burst = bursts[j];
21568
+ var opts = !burst.disabled && burst.getGeneratorOptions(timePassed, lifetime);
21569
+ if (opts) {
21570
+ var originVec = [
21571
+ 0,
21572
+ 0,
21573
+ 0
21574
+ ];
21575
+ var offsets = emission.burstOffsets[j];
21576
+ var burstOffset = offsets && offsets[opts.cycleIndex] || originVec;
21577
+ if (burst.once) {
21578
+ this.removeBurst(j);
21616
21579
  }
21617
- var burst = bursts[j];
21618
- var opts = !burst.disabled && burst.getGeneratorOptions(timePassed, lifetime);
21619
- if (opts) {
21620
- var originVec = [
21621
- 0,
21622
- 0,
21623
- 0
21624
- ];
21625
- var offsets = emission.burstOffsets[j];
21626
- var burstOffset = offsets && offsets[opts.cycleIndex] || originVec;
21627
- if (burst.once) {
21628
- this.removeBurst(j);
21629
- }
21630
- for(var i1 = 0; i1 < opts.count && cursor < maxCount; i1++){
21631
- var _p_transform;
21632
- if (shouldSkipGenerate()) {
21633
- break;
21634
- }
21635
- var p1 = this.initPoint(this.shape.generate({
21636
- total: opts.total,
21637
- index: opts.index,
21638
- burstIndex: i1,
21639
- burstCount: opts.count
21640
- }));
21641
- p1.delay += meshTime;
21642
- cursor++;
21643
- (_p_transform = p1.transform).translate.apply(_p_transform, [].concat(burstOffset));
21644
- this.addParticle(p1, maxCount);
21580
+ for(var i1 = 0; i1 < opts.count && cursor < maxCount; i1++){
21581
+ var _p_transform;
21582
+ if (shouldSkipGenerate()) {
21583
+ break;
21645
21584
  }
21585
+ var p1 = this.initPoint(this.shape.generate({
21586
+ total: opts.total,
21587
+ index: opts.index,
21588
+ burstIndex: i1,
21589
+ burstCount: opts.count
21590
+ }));
21591
+ p1.delay += meshTime;
21592
+ cursor++;
21593
+ (_p_transform = p1.transform).translate.apply(_p_transform, [].concat(burstOffset));
21594
+ this.addParticle(p1, maxCount);
21646
21595
  }
21647
21596
  }
21648
- } else if (this.item.endBehavior === EndBehavior.restart) {
21649
- updateTrail();
21650
- this.loopStartTime = now - duration;
21651
- this.lastEmitTime -= duration;
21652
- this.time -= duration;
21653
- emission.bursts.forEach(function(b) {
21654
- return b.reset();
21655
- });
21656
- this.particleLink.forEach(function(content) {
21657
- content[0] -= duration;
21658
- content[2] -= duration;
21659
- content[3].delay -= duration;
21660
- });
21661
- this.renderer.minusTimeForLoop(duration);
21662
- } else {
21663
- this.ended = true;
21664
- var endBehavior = this.item.endBehavior;
21665
- if (endBehavior === EndBehavior.freeze) {
21666
- this.frozen = true;
21667
- }
21668
21597
  }
21669
- } else if (this.item.endBehavior !== EndBehavior.restart) {
21670
- if (EndBehavior.destroy === this.item.endBehavior) {
21671
- var node = link.last;
21672
- if (node && node.content[0] < this.time) {
21673
- this.destroyed = true;
21674
- }
21598
+ } else if (this.item.endBehavior === EndBehavior.restart) {
21599
+ updateTrail();
21600
+ this.loopStartTime = now - duration;
21601
+ this.lastEmitTime -= duration;
21602
+ this.time -= duration;
21603
+ emission.bursts.forEach(function(b) {
21604
+ return b.reset();
21605
+ });
21606
+ this.particleLink.forEach(function(content) {
21607
+ content[0] -= duration;
21608
+ content[2] -= duration;
21609
+ content[3].delay -= duration;
21610
+ });
21611
+ this.renderer.minusTimeForLoop(duration);
21612
+ } else {
21613
+ this.ended = true;
21614
+ var endBehavior = this.item.endBehavior;
21615
+ if (endBehavior === EndBehavior.freeze) {
21616
+ this.frozen = true;
21617
+ }
21618
+ }
21619
+ } else if (this.item.endBehavior !== EndBehavior.restart) {
21620
+ if (EndBehavior.destroy === this.item.endBehavior) {
21621
+ var node = link.last;
21622
+ if (node && node.content[0] < this.time) {
21623
+ this.destroyed = true;
21675
21624
  }
21676
21625
  }
21677
- updateTrail();
21678
21626
  }
21627
+ updateTrail();
21679
21628
  };
21680
21629
  _proto.drawStencilMask = function drawStencilMask(renderer) {
21681
21630
  if (!this.isActiveAndEnabled) {
@@ -25715,7 +25664,6 @@ exports.SpriteComponent = /*#__PURE__*/ function(MaskableGraphic) {
25715
25664
  _this = MaskableGraphic.call(this, engine) || this;
25716
25665
  _this.time = 0;
25717
25666
  _this.duration = 1;
25718
- _this.loop = true;
25719
25667
  /**
25720
25668
  * @internal
25721
25669
  */ _this.splits = singleSplits;
@@ -25730,11 +25678,15 @@ exports.SpriteComponent = /*#__PURE__*/ function(MaskableGraphic) {
25730
25678
  var _this = this;
25731
25679
  var time = this.time;
25732
25680
  var duration = this.duration;
25733
- if (time > duration && this.loop) {
25681
+ var textureAnimation = this.textureSheetAnimation;
25682
+ var _textureAnimation_loop;
25683
+ // TODO: Update textureAnimation spec.
25684
+ // @ts-expect-error
25685
+ var loop = (_textureAnimation_loop = textureAnimation == null ? void 0 : textureAnimation.loop) != null ? _textureAnimation_loop : true;
25686
+ if (time > duration && loop) {
25734
25687
  time = time % duration;
25735
25688
  }
25736
25689
  var life = Math.min(Math.max(time / duration, 0.0), 1.0);
25737
- var ta = this.textureSheetAnimation;
25738
25690
  var video = this.renderer.texture.source.video;
25739
25691
  if (video) {
25740
25692
  if (time === 0) {
@@ -25746,9 +25698,9 @@ exports.SpriteComponent = /*#__PURE__*/ function(MaskableGraphic) {
25746
25698
  }
25747
25699
  this.renderer.texture.uploadCurrentVideoFrame();
25748
25700
  }
25749
- if (ta) {
25701
+ if (textureAnimation) {
25750
25702
  var _this_material_getVector4;
25751
- var total = ta.total || ta.row * ta.col;
25703
+ var total = textureAnimation.total || textureAnimation.row * textureAnimation.col;
25752
25704
  var texRectX = 0;
25753
25705
  var texRectY = 0;
25754
25706
  var texRectW = 1;
@@ -25769,20 +25721,20 @@ exports.SpriteComponent = /*#__PURE__*/ function(MaskableGraphic) {
25769
25721
  }
25770
25722
  var dx, dy;
25771
25723
  if (flip) {
25772
- dx = 1 / ta.row * texRectW;
25773
- dy = 1 / ta.col * texRectH;
25724
+ dx = 1 / textureAnimation.row * texRectW;
25725
+ dy = 1 / textureAnimation.col * texRectH;
25774
25726
  } else {
25775
- dx = 1 / ta.col * texRectW;
25776
- dy = 1 / ta.row * texRectH;
25727
+ dx = 1 / textureAnimation.col * texRectW;
25728
+ dy = 1 / textureAnimation.row * texRectH;
25777
25729
  }
25778
25730
  var texOffset;
25779
- if (ta.animate) {
25731
+ if (textureAnimation.animate) {
25780
25732
  var frameIndex = Math.round(life * (total - 1));
25781
- var yIndex = Math.floor(frameIndex / ta.col);
25782
- var xIndex = frameIndex - yIndex * ta.col;
25733
+ var yIndex = Math.floor(frameIndex / textureAnimation.col);
25734
+ var xIndex = frameIndex - yIndex * textureAnimation.col;
25783
25735
  texOffset = flip ? [
25784
25736
  dx * yIndex,
25785
- dy * (ta.col - xIndex)
25737
+ dy * (textureAnimation.col - xIndex)
25786
25738
  ] : [
25787
25739
  dx * xIndex,
25788
25740
  dy * (1 + yIndex)
@@ -25970,8 +25922,6 @@ exports.SpriteComponent = /*#__PURE__*/ function(MaskableGraphic) {
25970
25922
  var _data_duration;
25971
25923
  //@ts-expect-error
25972
25924
  this.duration = (_data_duration = data.duration) != null ? _data_duration : this.item.duration;
25973
- var _data_loop;
25974
- this.loop = (_data_loop = data.loop) != null ? _data_loop : true;
25975
25925
  };
25976
25926
  return SpriteComponent;
25977
25927
  }(MaskableGraphic);
@@ -25979,21 +25929,21 @@ exports.SpriteComponent = __decorate([
25979
25929
  effectsClass(DataType.SpriteComponent)
25980
25930
  ], exports.SpriteComponent);
25981
25931
 
25982
- var ParticleLoader = /*#__PURE__*/ function(AbstractPlugin) {
25983
- _inherits(ParticleLoader, AbstractPlugin);
25932
+ var ParticleLoader = /*#__PURE__*/ function(Plugin) {
25933
+ _inherits(ParticleLoader, Plugin);
25984
25934
  function ParticleLoader() {
25985
- return AbstractPlugin.apply(this, arguments);
25935
+ return Plugin.apply(this, arguments);
25986
25936
  }
25987
25937
  return ParticleLoader;
25988
- }(AbstractPlugin);
25938
+ }(_wrap_native_super(Plugin));
25989
25939
 
25990
- var CalculateLoader = /*#__PURE__*/ function(AbstractPlugin) {
25991
- _inherits(CalculateLoader, AbstractPlugin);
25940
+ var CalculateLoader = /*#__PURE__*/ function(Plugin) {
25941
+ _inherits(CalculateLoader, Plugin);
25992
25942
  function CalculateLoader() {
25993
- return AbstractPlugin.apply(this, arguments);
25943
+ return Plugin.apply(this, arguments);
25994
25944
  }
25995
25945
  return CalculateLoader;
25996
- }(AbstractPlugin);
25946
+ }(_wrap_native_super(Plugin));
25997
25947
 
25998
25948
  // Based on:
25999
25949
  /**
@@ -29095,6 +29045,12 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29095
29045
  /**
29096
29046
  * 每一行文本的最大宽度
29097
29047
  */ _this.maxLineWidth = 0;
29048
+ /**
29049
+ * 初始文本宽度,用于计算缩放比例
29050
+ */ _this.baseTextWidth = 0;
29051
+ /**
29052
+ * 初始 `transform.size.x`,用于按比例更新显示宽度
29053
+ */ _this.baseScaleX = 1;
29098
29054
  _this.name = "MText" + seed$2++;
29099
29055
  // 初始化canvas资源
29100
29056
  _this.canvas = canvasPool.getCanvas();
@@ -29120,10 +29076,11 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29120
29076
  text: "默认文本",
29121
29077
  fontFamily: "AlibabaSans-BoldItalic",
29122
29078
  fontSize: 40,
29079
+ // 统一使用 0-1 颜色值
29123
29080
  textColor: [
29124
- 255,
29125
- 255,
29126
- 255,
29081
+ 1,
29082
+ 1,
29083
+ 1,
29127
29084
  1
29128
29085
  ],
29129
29086
  fontWeight: TextWeight.normal,
@@ -29160,6 +29117,10 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29160
29117
  // TextComponentBase
29161
29118
  this.updateWithOptions(options);
29162
29119
  this.renderText(options);
29120
+ // 记录初始的 textWidth 和 x 缩放,用于后续按比例更新显示宽度
29121
+ // 添加兜底值 1 防止除 0
29122
+ this.baseTextWidth = options.textWidth || this.textLayout.width || 1;
29123
+ this.baseScaleX = this.item.transform.size.x;
29163
29124
  // 恢复默认颜色
29164
29125
  this.material.setColor("_Color", new Color(1, 1, 1, 1));
29165
29126
  };
@@ -29358,9 +29319,9 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29358
29319
  if (style.isOutlined) {
29359
29320
  _this.setupOutline();
29360
29321
  }
29361
- // 文本颜色 - 直接使用 vec4 原值,不乘以 255
29322
+ // textColor 统一是 0-1,写入 canvas 时乘 255
29362
29323
  var _style_textColor = style.textColor, r = _style_textColor[0], g = _style_textColor[1], b = _style_textColor[2], a = _style_textColor[3];
29363
- context.fillStyle = "rgba(" + r + ", " + g + ", " + b + ", " + a + ")";
29324
+ context.fillStyle = "rgba(" + r * 255 + ", " + g * 255 + ", " + b * 255 + ", " + a + ")";
29364
29325
  var charsInfo = [];
29365
29326
  var x = 0;
29366
29327
  var y = layout.getOffsetY(style, _this.lineCount, lineHeight, fontSize);
@@ -29422,6 +29383,46 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29422
29383
  layout.autoWidth = normalizedValue;
29423
29384
  this.isDirty = true;
29424
29385
  };
29386
+ /**
29387
+ * 设置文本框宽度
29388
+ * 手动设置宽度时会自动关闭 `autoWidth`
29389
+ * 同时会按比例更新 `transform.size.x`,让 UI 框宽度也跟着变化
29390
+ * @param value - 文本框宽度
29391
+ */ _proto.setTextWidth = function setTextWidth(value) {
29392
+ var width = Math.max(0, Number(value) || 0);
29393
+ var layout = this.textLayout;
29394
+ // 宽度没变且已是非 autoWidth 模式,直接返回
29395
+ if (layout.width === width && layout.autoWidth === false) {
29396
+ return;
29397
+ }
29398
+ // 手动设置宽度时关闭 autoWidth
29399
+ layout.autoWidth = false;
29400
+ layout.width = width;
29401
+ // 按当前 overflow 模式重新计算行数和 maxLineWidth
29402
+ this.lineCount = this.getLineCount(this.text || "");
29403
+ this.isDirty = true;
29404
+ // 同步更新外层显示宽度(按比例缩放 transform)
29405
+ // 这样 UI 框的视觉宽度也会跟着文本宽度变化
29406
+ if (this.baseTextWidth > 0) {
29407
+ var scale = width / this.baseTextWidth;
29408
+ this.item.transform.size.x = this.baseScaleX * scale;
29409
+ }
29410
+ };
29411
+ /**
29412
+ * 设置文本框高度
29413
+ * @param value - 文本框高度
29414
+ */ _proto.setTextHeight = function setTextHeight(value) {
29415
+ var height = Math.max(0, Number(value) || 0);
29416
+ if (height === 0) {
29417
+ return;
29418
+ }
29419
+ var layout = this.textLayout;
29420
+ if (layout.height === height) {
29421
+ return;
29422
+ }
29423
+ layout.height = height;
29424
+ this.isDirty = true;
29425
+ };
29425
29426
  _proto.setFontSize = function setFontSize(value) {
29426
29427
  if (this.textStyle.fontSize === value) {
29427
29428
  return;
@@ -29489,13 +29490,13 @@ applyMixins(exports.TextComponent, [
29489
29490
  ]);
29490
29491
 
29491
29492
  // TODO: 注册必须用
29492
- var TextLoader = /*#__PURE__*/ function(AbstractPlugin) {
29493
- _inherits(TextLoader, AbstractPlugin);
29493
+ var TextLoader = /*#__PURE__*/ function(Plugin) {
29494
+ _inherits(TextLoader, Plugin);
29494
29495
  function TextLoader() {
29495
- return AbstractPlugin.apply(this, arguments);
29496
+ return Plugin.apply(this, arguments);
29496
29497
  }
29497
29498
  return TextLoader;
29498
- }(AbstractPlugin);
29499
+ }(_wrap_native_super(Plugin));
29499
29500
 
29500
29501
  var Asset = /*#__PURE__*/ function(EffectsObject) {
29501
29502
  _inherits(Asset, EffectsObject);
@@ -30552,6 +30553,10 @@ function version35Migration(json) {
30552
30553
  if (component.dataType === DataType.TextComponent || component.dataType === DataType.RichTextComponent && component.options) {
30553
30554
  ensureTextVerticalAlign(component.options);
30554
30555
  }
30556
+ // 处理文本颜色从 0-255 到 0-1 的转换
30557
+ if (component.dataType === DataType.TextComponent) {
30558
+ convertTextColorTo01(component.options);
30559
+ }
30555
30560
  }
30556
30561
  }
30557
30562
  //@ts-expect-error
@@ -30571,6 +30576,22 @@ function version35Migration(json) {
30571
30576
  options.TextVerticalAlign = options.textBaseline;
30572
30577
  }
30573
30578
  }
30579
+ /**
30580
+ * 将文本颜色从 0-255 转换到 0-1
30581
+ */ function convertTextColorTo01(options) {
30582
+ if (!options || !options.textColor) {
30583
+ return;
30584
+ }
30585
+ var textColor = options.textColor;
30586
+ var _textColor_;
30587
+ // 将 RGB 从 0-255 转换到 0-1(alpha 通道已经是 0-1,不需要转换)
30588
+ options.textColor = [
30589
+ textColor[0] / 255.0,
30590
+ textColor[1] / 255.0,
30591
+ textColor[2] / 255.0,
30592
+ (_textColor_ = textColor[3]) != null ? _textColor_ : 1
30593
+ ];
30594
+ }
30574
30595
  /**
30575
30596
  * 根据形状获取形状几何体数据
30576
30597
  * @param shape - 形状
@@ -31493,7 +31514,7 @@ function getStandardSpriteContent(sprite, transform) {
31493
31514
  return ret;
31494
31515
  }
31495
31516
 
31496
- var version$2 = "2.8.0-alpha.2";
31517
+ var version$2 = "2.8.0-alpha.4";
31497
31518
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
31498
31519
  var standardVersion = /^(\d+)\.(\d+)$/;
31499
31520
  var reverseParticle = false;
@@ -32133,8 +32154,8 @@ var seed$1 = 1;
32133
32154
  };
32134
32155
  return [
32135
32156
  4,
32136
- hookTimeInfo("plugin:processAssets", function() {
32137
- return _this.processPluginAssets(scene);
32157
+ hookTimeInfo("plugin:onAssetsLoadStart", function() {
32158
+ return _this.onPluginSceneLoadStart(scene);
32138
32159
  })
32139
32160
  ];
32140
32161
  case 6:
@@ -32422,7 +32443,7 @@ var seed$1 = 1;
32422
32443
  });
32423
32444
  })();
32424
32445
  };
32425
- _proto.processPluginAssets = function processPluginAssets(scene) {
32446
+ _proto.onPluginSceneLoadStart = function onPluginSceneLoadStart(scene) {
32426
32447
  var _this = this;
32427
32448
  return _async_to_generator(function() {
32428
32449
  return __generator(this, function(_state) {
@@ -32430,7 +32451,7 @@ var seed$1 = 1;
32430
32451
  case 0:
32431
32452
  return [
32432
32453
  4,
32433
- PluginSystem.processAssets(scene, _this.options)
32454
+ PluginSystem.onAssetsLoadStart(scene, _this.options)
32434
32455
  ];
32435
32456
  case 1:
32436
32457
  _state.sent();
@@ -35131,8 +35152,8 @@ var SceneLoader = /*#__PURE__*/ function() {
35131
35152
  case 1:
35132
35153
  loadedScene = _state.sent();
35133
35154
  engine.clearResources();
35134
- // 触发插件系统 pluginSystem 的回调 prepareResource
35135
- PluginSystem.loadResources(loadedScene, assetManager.options, engine);
35155
+ // 触发插件系统 pluginSystem 的回调 onAssetsLoadFinish
35156
+ PluginSystem.onAssetsLoadFinish(loadedScene, assetManager.options, engine);
35136
35157
  engine.assetService.prepareAssets(loadedScene, loadedScene.assets);
35137
35158
  engine.assetService.updateTextVariables(loadedScene, options.variables);
35138
35159
  engine.assetService.initializeTexture(loadedScene);
@@ -35194,7 +35215,7 @@ registerPlugin("sprite", SpriteLoader);
35194
35215
  registerPlugin("particle", ParticleLoader);
35195
35216
  registerPlugin("cal", CalculateLoader);
35196
35217
  registerPlugin("interact", InteractLoader);
35197
- var version$1 = "2.8.0-alpha.2";
35218
+ var version$1 = "2.8.0-alpha.4";
35198
35219
  logger.info("Core version: " + version$1 + ".");
35199
35220
 
35200
35221
  var _obj;
@@ -36488,8 +36509,8 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
36488
36509
  _$scene = _state.sent();
36489
36510
  engine = _this.engine;
36490
36511
  engine.clearResources();
36491
- // 触发插件系统 pluginSystem 的回调 prepareResource
36492
- PluginSystem.loadResources(_$scene, assetManager.options, engine);
36512
+ // 触发插件系统 pluginSystem 的回调 onAssetsLoadFinish
36513
+ PluginSystem.onAssetsLoadFinish(_$scene, assetManager.options, engine);
36493
36514
  _this.assetService.prepareAssets(_$scene, assetManager.getAssets());
36494
36515
  _this.assetService.updateTextVariables(_$scene, assetManager.options.variables);
36495
36516
  _this.assetService.initializeTexture(_$scene);
@@ -36784,10 +36805,9 @@ applyMixins(exports.ThreeTextComponent, [
36784
36805
  */ Mesh.create = function(engine, props) {
36785
36806
  return new ThreeMesh(engine, props);
36786
36807
  };
36787
- var version = "2.8.0-alpha.2";
36808
+ var version = "2.8.0-alpha.4";
36788
36809
  logger.info("THREEJS plugin version: " + version + ".");
36789
36810
 
36790
- exports.AbstractPlugin = AbstractPlugin;
36791
36811
  exports.ActivationMixerPlayable = ActivationMixerPlayable;
36792
36812
  exports.ActivationPlayable = ActivationPlayable;
36793
36813
  exports.AndNode = AndNode;
@@ -36891,6 +36911,7 @@ exports.PathSegments = PathSegments;
36891
36911
  exports.Playable = Playable;
36892
36912
  exports.PlayableAsset = PlayableAsset;
36893
36913
  exports.PlayableOutput = PlayableOutput;
36914
+ exports.Plugin = Plugin;
36894
36915
  exports.PluginSystem = PluginSystem;
36895
36916
  exports.PointerEventData = PointerEventData;
36896
36917
  exports.PolyStar = PolyStar;