@galacean/effects-threejs 2.6.0-beta.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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.6.0-beta.1
6
+ * Version: v2.6.0
7
7
  */
8
8
 
9
9
  'use strict';
@@ -488,6 +488,8 @@ function getPixelRatio() {
488
488
  }
489
489
  return 1;
490
490
  }
491
+ // window 对象不存在时需要判断
492
+ var canUseBOM = typeof window !== "undefined";
491
493
  function isIOS() {
492
494
  // real ios device not in simulator
493
495
  return !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
@@ -8312,6 +8314,8 @@ function gpuTimer(gl) {
8312
8314
 
8313
8315
  var initErrors = [];
8314
8316
  var glContext = {};
8317
+ var IOS16_LOCKDOWN_MODE = "iOS16 lockdown mode, WebGL Constants not in global";
8318
+ var WEBGL_CONSTANTS_NOT_IN_GLOBAL = "WebGL Constants not in global, please check your environment";
8315
8319
  if (!initErrors.length) {
8316
8320
  initGLContext();
8317
8321
  }
@@ -8323,8 +8327,12 @@ function initGLContext() {
8323
8327
  copy(WebGLRenderingContext);
8324
8328
  copy(WebGLRenderingContext.prototype);
8325
8329
  } else {
8326
- initErrors.push(isIOS() ? // iOS 16 lockdown mode
8327
- "iOS16 lockdown mode, WebGL Constants not in global" : "WebGL Constants not in global, please check your environment");
8330
+ if (canUseBOM) {
8331
+ initErrors.push(// iOS 16 lockdown mode
8332
+ isIOS() ? IOS16_LOCKDOWN_MODE : WEBGL_CONSTANTS_NOT_IN_GLOBAL);
8333
+ } else {
8334
+ initErrors.push(WEBGL_CONSTANTS_NOT_IN_GLOBAL);
8335
+ }
8328
8336
  }
8329
8337
  if (!initErrors.length && !("HALF_FLOAT" in glContext)) {
8330
8338
  // @ts-expect-error set default value
@@ -10034,18 +10042,15 @@ var MaskProcessor = /*#__PURE__*/ function() {
10034
10042
  _proto.getRefValue = function getRefValue() {
10035
10043
  return 1;
10036
10044
  };
10037
- _proto.getMaskMode = function getMaskMode(data) {
10045
+ _proto.setMaskOptions = function setMaskOptions(data) {
10038
10046
  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;
10039
10047
  this.alphaMaskEnabled = alphaMaskEnabled;
10040
10048
  if (isMask) {
10041
10049
  this.maskMode = exports.MaskMode.MASK;
10042
10050
  } else {
10043
10051
  this.maskMode = inverted ? exports.MaskMode.REVERSE_OBSCURED : exports.MaskMode.OBSCURED;
10044
- if (reference) {
10045
- this.maskable = this.engine.findObject(reference);
10046
- }
10052
+ this.maskable = this.engine.findObject(reference);
10047
10053
  }
10048
- return this.maskMode;
10049
10054
  };
10050
10055
  _proto.drawStencilMask = function drawStencilMask(renderer) {
10051
10056
  if (this.maskable) {
@@ -15232,7 +15237,7 @@ var singleSplits = [
15232
15237
  var textureSheetAnimation = baseRenderComponentData.textureSheetAnimation;
15233
15238
  var maskOptions = baseRenderComponentData.mask;
15234
15239
  if (maskOptions) {
15235
- this.maskManager.getMaskMode(maskOptions);
15240
+ this.maskManager.setMaskOptions(maskOptions);
15236
15241
  }
15237
15242
  // TODO 新蒙板上线后移除
15238
15243
  //-------------------------------------------------------------------------
@@ -15638,7 +15643,7 @@ exports.ShapeComponent = /*#__PURE__*/ function(BaseRenderComponent) {
15638
15643
  }
15639
15644
  }
15640
15645
  if (data.mask) {
15641
- this.maskManager.getMaskMode(data.mask);
15646
+ this.maskManager.setMaskOptions(data.mask);
15642
15647
  }
15643
15648
  var maskRef = this.maskManager.getRefValue();
15644
15649
  this.material.stencilRef = maskRef !== undefined ? [
@@ -15865,6 +15870,7 @@ var EventSystem = /*#__PURE__*/ function() {
15865
15870
  var touchstart = "mousedown";
15866
15871
  var touchmove = "mousemove";
15867
15872
  var touchend = "mouseup";
15873
+ var touchcancel = "mouseleave";
15868
15874
  var getTouchEventValue = function(event, x, y, dx, dy) {
15869
15875
  if (dx === void 0) dx = 0;
15870
15876
  if (dy === void 0) dy = 0;
@@ -15918,6 +15924,7 @@ var EventSystem = /*#__PURE__*/ function() {
15918
15924
  touchstart = "touchstart";
15919
15925
  touchmove = "touchmove";
15920
15926
  touchend = "touchend";
15927
+ touchcancel = "touchcancel";
15921
15928
  }
15922
15929
  var _obj;
15923
15930
  this.nativeHandlers = (_obj = {}, _obj[touchstart] = function(event) {
@@ -15960,6 +15967,7 @@ var EventSystem = /*#__PURE__*/ function() {
15960
15967
  }
15961
15968
  currentTouch = 0;
15962
15969
  }, _obj);
15970
+ this.nativeHandlers[touchcancel] = this.nativeHandlers[touchend];
15963
15971
  Object.keys(this.nativeHandlers).forEach(function(name) {
15964
15972
  var _this_target;
15965
15973
  (_this_target = _this.target) == null ? void 0 : _this_target.addEventListener(String(name), _this.nativeHandlers[name]);
@@ -18093,16 +18101,23 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
18093
18101
  var _this;
18094
18102
  _this = RendererComponent.apply(this, arguments) || this;
18095
18103
  /**
18096
- * 拖拽的惯性衰减系数,范围[0, 1], 越大惯性越强
18104
+ * 拖拽后的惯性衰减系数,范围[0, 1], 越大惯性越强
18105
+ * @default 0.95
18097
18106
  */ _this.downgrade = 0.95;
18098
18107
  /**
18099
- * 拖拽的距离映射系数,越大越容易拖动
18108
+ * 拖拽后的惯性速度,范围[0, +∞), 越大惯性越强
18109
+ * @default 25
18110
+ * @since 2.6.0
18111
+ */ _this.speed = 25;
18112
+ /**
18113
+ * 拖拽时的距离映射系数,越大越容易拖动
18114
+ * @default [1, 1]
18100
18115
  */ _this.dragRatio = [
18101
18116
  1,
18102
18117
  1
18103
18118
  ];
18104
18119
  /**
18105
- * 拖拽X范围
18120
+ * 拖拽范围(编辑器制作时已经设置好,特殊情况可运行时修改)
18106
18121
  */ _this.dragRange = {
18107
18122
  dxRange: [
18108
18123
  0,
@@ -18113,6 +18128,13 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
18113
18128
  0
18114
18129
  ]
18115
18130
  };
18131
+ /**
18132
+ * 滑动失效区域,范围[0, 1],单位 %,避免滑动触控冲突(如 iOS 右滑退出时不执行)
18133
+ * > 若是数组形式,格式为:[top、right、bottom、left]
18134
+ * @since 2.6.0
18135
+ * @default 0
18136
+ */ _this.invalidBorderRange = 0;
18137
+ _this.invalidByBorderRange = false;
18116
18138
  _this.duringPlay = false;
18117
18139
  /** 是否响应点击和拖拽交互事件 */ _this._interactive = true;
18118
18140
  _this.lastTime = -1;
@@ -18152,7 +18174,6 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
18152
18174
  ];
18153
18175
  };
18154
18176
  _proto.onStart = function onStart() {
18155
- var options = this.item.props.content.options;
18156
18177
  var env = this.item.engine.renderer.env;
18157
18178
  var composition = this.item.composition;
18158
18179
  var _this_interactData_options = this.interactData.options, type = _this_interactData_options.type, showPreview = _this_interactData_options.showPreview;
@@ -18165,11 +18186,6 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
18165
18186
  }
18166
18187
  }
18167
18188
  }
18168
- if (options.type === InteractType.DRAG) {
18169
- if (env !== PLAYER_OPTIONS_ENV_EDITOR || options.enableInEditor) {
18170
- (composition == null ? void 0 : composition.event) && this.beginDragTarget(options, composition.event);
18171
- }
18172
- }
18173
18189
  if (this.previewContent) {
18174
18190
  this.previewContent.mesh.item = this.item;
18175
18191
  this.materials = this.previewContent.mesh.materials;
@@ -18179,7 +18195,8 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
18179
18195
  _proto.onDisable = function onDisable() {
18180
18196
  RendererComponent.prototype.onDisable.call(this);
18181
18197
  if (this.item && this.item.composition) {
18182
- if (this.duringPlay && !this.item.transform.getValid()) {
18198
+ // Triggers the Message end event, do not trigger when reverse playback
18199
+ if (this.duringPlay && !this.item.transform.getValid() && this.item.composition.getSpeed() > 0) {
18183
18200
  this.item.composition.removeInteractiveItem(this.item, this.item.props.content.options.type);
18184
18201
  this.duringPlay = false;
18185
18202
  }
@@ -18198,14 +18215,17 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
18198
18215
  var enableInEditor = options.enableInEditor;
18199
18216
  if (env !== PLAYER_OPTIONS_ENV_EDITOR || enableInEditor) {
18200
18217
  var _this_item_composition;
18201
- ((_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.event) && this.beginDragTarget(options, this.item.composition.event);
18218
+ var event = ((_this_item_composition = this.item.composition) != null ? _this_item_composition : {}).event;
18219
+ if (event) {
18220
+ this.beginDragTarget(options, event);
18221
+ }
18202
18222
  }
18203
18223
  }
18204
18224
  };
18205
18225
  _proto.onUpdate = function onUpdate(dt) {
18206
18226
  var _this_previewContent;
18207
18227
  this.duringPlay = true;
18208
- // trigger messageBegin when item enter
18228
+ // Trigger messageBegin when item enter
18209
18229
  if (this.lastTime <= this.item.time) {
18210
18230
  if (this.item.time >= 0 && this.lastTime < 0) {
18211
18231
  var _this_item_composition;
@@ -18213,8 +18233,8 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
18213
18233
  (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.addInteractiveItem(this.item, options.type);
18214
18234
  }
18215
18235
  } else {
18216
- // loop trigger
18217
- if (this.item.time >= 0) {
18236
+ // Loop trigger, do not trigger when reverse playback
18237
+ if (this.item.time >= 0 && dt > 0) {
18218
18238
  var _this_item_composition1;
18219
18239
  var options1 = this.item.props.content.options;
18220
18240
  (_this_item_composition1 = this.item.composition) == null ? void 0 : _this_item_composition1.addInteractiveItem(this.item, options1.type);
@@ -18288,6 +18308,13 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
18288
18308
  if (!_this.canInteract()) {
18289
18309
  return;
18290
18310
  }
18311
+ _this.invalidByBorderRange = _this.checkInvalidBorderRange({
18312
+ x: event.x,
18313
+ y: event.y
18314
+ });
18315
+ if (_this.invalidByBorderRange) {
18316
+ return;
18317
+ }
18291
18318
  _this.dragEvent = null;
18292
18319
  _this.bouncingArg = null;
18293
18320
  var camera = (_this_item_composition = _this.item.composition) == null ? void 0 : _this_item_composition.camera;
@@ -18305,6 +18332,9 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
18305
18332
  };
18306
18333
  },
18307
18334
  touchmove: function(event) {
18335
+ if (_this.invalidByBorderRange) {
18336
+ return;
18337
+ }
18308
18338
  _this.handleDragMove(dragEvent, event);
18309
18339
  _this.bouncingArg = event;
18310
18340
  },
@@ -18314,9 +18344,8 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
18314
18344
  }
18315
18345
  var bouncingArg = _this.bouncingArg;
18316
18346
  if (!shouldIgnoreBouncing(bouncingArg, 3) && bouncingArg) {
18317
- var speed = 5;
18318
- bouncingArg.vx *= speed;
18319
- bouncingArg.vy *= speed;
18347
+ bouncingArg.vx *= _this.speed;
18348
+ bouncingArg.vy *= _this.speed;
18320
18349
  _this.dragEvent = _extends({}, dragEvent);
18321
18350
  }
18322
18351
  dragEvent = null;
@@ -18367,6 +18396,31 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
18367
18396
  var _this_item_composition;
18368
18397
  return Boolean((_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.interactive) && this._interactive;
18369
18398
  };
18399
+ /**
18400
+ * 检查滑动手势边界
18401
+ * @param position
18402
+ */ _proto.checkInvalidBorderRange = function checkInvalidBorderRange(position) {
18403
+ var invalidBorderRange = this.invalidBorderRange;
18404
+ if (invalidBorderRange) {
18405
+ var top = 0;
18406
+ var right = 0;
18407
+ var bottom = 0;
18408
+ var left = 0;
18409
+ if (typeof invalidBorderRange === "number") {
18410
+ top = invalidBorderRange;
18411
+ right = invalidBorderRange;
18412
+ bottom = invalidBorderRange;
18413
+ left = invalidBorderRange;
18414
+ } else if (isArray(invalidBorderRange)) {
18415
+ var ref, ref1, ref2, ref3, ref4;
18416
+ ref = invalidBorderRange, ref1 = ref[0], top = ref1 === void 0 ? 0 : ref1, ref2 = ref[1], right = ref2 === void 0 ? 0 : ref2, ref3 = ref[2], bottom = ref3 === void 0 ? 0 : ref3, ref4 = ref[3], left = ref4 === void 0 ? 0 : ref4;
18417
+ }
18418
+ if (position.x < left - 1 || position.x > 1 - right || position.y < top - 1 || position.y > 1 - bottom) {
18419
+ return true;
18420
+ }
18421
+ }
18422
+ return false;
18423
+ };
18370
18424
  _create_class(InteractComponent, [
18371
18425
  {
18372
18426
  key: "interactive",
@@ -22161,7 +22215,9 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
22161
22215
  this.options.startSize = createValueGetter(options.startSize);
22162
22216
  this.options.sizeAspect = createValueGetter(options.sizeAspect || 1);
22163
22217
  }
22164
- var maskProps = this.getMaskOptions(props);
22218
+ if (props.mask) {
22219
+ this.maskManager.setMaskOptions(props.mask);
22220
+ }
22165
22221
  var particleMeshProps = {
22166
22222
  // listIndex: vfxItem.listIndex,
22167
22223
  meshSlots: options.meshSlots,
@@ -22182,8 +22238,8 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
22182
22238
  occlusion: !!renderer.occlusion,
22183
22239
  transparentOcclusion: !!renderer.transparentOcclusion,
22184
22240
  maxCount: options.maxCount,
22185
- mask: maskProps.maskRef,
22186
- maskMode: maskProps.maskMode,
22241
+ mask: this.maskManager.getRefValue(),
22242
+ maskMode: this.maskManager.maskMode,
22187
22243
  forceTarget: forceTarget,
22188
22244
  diffuse: renderer.texture ? this.engine.findObject(renderer.texture) : undefined,
22189
22245
  sizeOverLifetime: sizeOverLifetimeGetter,
@@ -22264,7 +22320,9 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
22264
22320
  inheritParticleColor: !!trails.inheritParticleColor,
22265
22321
  parentAffectsPosition: !!trails.parentAffectsPosition
22266
22322
  };
22267
- maskProps = this.getMaskOptions(trails);
22323
+ if (trails.mask) {
22324
+ this.maskManager.setMaskOptions(trails.mask);
22325
+ }
22268
22326
  trailMeshProps = {
22269
22327
  name: "Trail",
22270
22328
  matrix: Matrix4.IDENTITY,
@@ -22281,8 +22339,8 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
22281
22339
  occlusion: !!trails.occlusion,
22282
22340
  transparentOcclusion: !!trails.transparentOcclusion,
22283
22341
  textureMap: trails.textureMap,
22284
- mask: maskProps.maskRef,
22285
- maskMode: maskProps.maskMode
22342
+ mask: this.maskManager.getRefValue(),
22343
+ maskMode: this.maskManager.maskMode
22286
22344
  };
22287
22345
  if (trails.colorOverLifetime && trails.colorOverLifetime[0] === ValueType.GRADIENT_COLOR) {
22288
22346
  trailMeshProps.colorOverLifetime = trails.colorOverLifetime[1];
@@ -22307,18 +22365,6 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
22307
22365
  this.item.getHitTestParams = this.getHitTestParams;
22308
22366
  this.item._content = this;
22309
22367
  };
22310
- _proto.getMaskOptions = function getMaskOptions(data) {
22311
- var maskMode = exports.MaskMode.NONE;
22312
- var maskRef = 0;
22313
- if (data.mask) {
22314
- maskMode = this.maskManager.getMaskMode(data.mask);
22315
- maskRef = this.maskManager.getRefValue();
22316
- }
22317
- return {
22318
- maskMode: maskMode,
22319
- maskRef: maskRef
22320
- };
22321
- };
22322
22368
  _create_class(ParticleSystem, [
22323
22369
  {
22324
22370
  key: "timePassed",
@@ -30131,6 +30177,7 @@ var itemMap = new Map();
30131
30177
  }
30132
30178
  }
30133
30179
  }
30180
+ json.version = JSONSceneVersion["3_2"];
30134
30181
  return json;
30135
30182
  }
30136
30183
  function version32Migration(json) {
@@ -30150,6 +30197,7 @@ function version32Migration(json) {
30150
30197
  var comp = _step2.value;
30151
30198
  processContent(comp);
30152
30199
  }
30200
+ json.version = JSONSceneVersion["3_3"];
30153
30201
  return json;
30154
30202
  }
30155
30203
  function version33Migration(json) {
@@ -30217,6 +30265,7 @@ function version33Migration(json) {
30217
30265
  }
30218
30266
  }
30219
30267
  }
30268
+ json.version = JSONSceneVersion["3_4"];
30220
30269
  return json;
30221
30270
  }
30222
30271
  function processContent(composition) {
@@ -31072,7 +31121,7 @@ function getStandardSpriteContent(sprite, transform) {
31072
31121
  return ret;
31073
31122
  }
31074
31123
 
31075
- var version$2 = "2.6.0-beta.1";
31124
+ var version$2 = "2.6.0";
31076
31125
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
31077
31126
  var standardVersion = /^(\d+)\.(\d+)$/;
31078
31127
  var reverseParticle = false;
@@ -34322,7 +34371,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem);
34322
34371
  registerPlugin("particle", ParticleLoader, exports.VFXItem);
34323
34372
  registerPlugin("cal", CalculateLoader, exports.VFXItem);
34324
34373
  registerPlugin("interact", InteractLoader, exports.VFXItem);
34325
- var version$1 = "2.6.0-beta.1";
34374
+ var version$1 = "2.6.0";
34326
34375
  logger.info("Core version: " + version$1 + ".");
34327
34376
 
34328
34377
  var _obj;
@@ -35927,7 +35976,7 @@ setMaxSpriteMeshItemCount(8);
35927
35976
  */ Mesh.create = function(engine, props) {
35928
35977
  return new ThreeMesh(engine, props);
35929
35978
  };
35930
- var version = "2.6.0-beta.1";
35979
+ var version = "2.6.0";
35931
35980
  logger.info("THREEJS plugin version: " + version + ".");
35932
35981
 
35933
35982
  exports.AbstractPlugin = AbstractPlugin;
@@ -36095,6 +36144,7 @@ exports.base64ToFile = base64ToFile;
36095
36144
  exports.blend = blend;
36096
36145
  exports.buildLine = buildLine;
36097
36146
  exports.calculateTranslation = calculateTranslation;
36147
+ exports.canUseBOM = canUseBOM;
36098
36148
  exports.canvasPool = canvasPool;
36099
36149
  exports.closePointEps = closePointEps;
36100
36150
  exports.colorGradingFrag = colorGradingFrag;