@galacean/effects-threejs 0.0.1-alpha.1 → 0.0.1-alpha.3

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.mjs 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: v0.0.1-alpha.1
6
+ * Version: v0.0.1-alpha.3
7
7
  */
8
8
 
9
9
  import * as THREE from 'three';
@@ -6121,8 +6121,8 @@ var PLAYER_OPTIONS_ENV_EDITOR = 'editor';
6121
6121
  var FILTER_NAME_NONE = 'none';
6122
6122
  var DEG2RAD = 0.017453292519943295;
6123
6123
  var HELP_LINK = {
6124
- 'Filter not imported': 'https://yuque.antfin.com/huoxing/knaszl/qtnsf2g9ofigggor#n4Y1K',
6125
- 'Item duration can\'t be less than 0': 'https://yuque.antfin.com/huoxing/knaszl/wozlz0#vFPqF',
6124
+ 'Filter not imported': 'https://galacean.antgroup.com/effects/#/user/gasrv4ka5sacrwpg',
6125
+ 'Item duration can\'t be less than 0': 'https://galacean.antgroup.com/effects/#/user/gasrv4ka5sacrwpg',
6126
6126
  };
6127
6127
 
6128
6128
  /**
@@ -6665,7 +6665,7 @@ function asserts(condition, msg) {
6665
6665
  * Name: @galacean/effects-specification
6666
6666
  * Description: Galacean Effects JSON Specification
6667
6667
  * Author: Ant Group CO., Ltd.
6668
- * Version: v0.0.2
6668
+ * Version: v1.0.0
6669
6669
  */
6670
6670
 
6671
6671
  /*********************************************/
@@ -9750,6 +9750,7 @@ var VFXItem = /** @class */ (function () {
9750
9750
  this.endBehavior = endBehavior;
9751
9751
  this.lifetime = -(this.delayInms / this.durInms);
9752
9752
  this.listIndex = listIndex;
9753
+ this.speed = 1;
9753
9754
  this.onConstructed(props);
9754
9755
  if (duration <= 0) {
9755
9756
  throw Error("Item duration can't be less than 0, see ".concat(HELP_LINK['Item duration can\'t be less than 0']));
@@ -9828,6 +9829,20 @@ var VFXItem = /** @class */ (function () {
9828
9829
  enumerable: false,
9829
9830
  configurable: true
9830
9831
  });
9832
+ /**
9833
+ * 设置元素的动画速度
9834
+ * @param speed - 速度
9835
+ */
9836
+ VFXItem.prototype.setSpeed = function (speed) {
9837
+ this.speed = speed;
9838
+ };
9839
+ /**
9840
+ * 获取元素的动画速度
9841
+ * @returns
9842
+ */
9843
+ VFXItem.prototype.getSpeed = function () {
9844
+ return this.speed;
9845
+ };
9831
9846
  /**
9832
9847
  * 重置元素状态属性
9833
9848
  */
@@ -9883,11 +9898,12 @@ var VFXItem = /** @class */ (function () {
9883
9898
  };
9884
9899
  /**
9885
9900
  * 内部使用的更新回调,请不要重写此方法,重写 `onItemUpdate` 方法
9886
- * @param dt
9901
+ * @param deltaTime
9887
9902
  */
9888
- VFXItem.prototype.onUpdate = function (dt) {
9903
+ VFXItem.prototype.onUpdate = function (deltaTime) {
9889
9904
  var _a, _b;
9890
9905
  if (this.started && !this.frozen && this.composition) {
9906
+ var dt = deltaTime * this.speed;
9891
9907
  var time = (this.timeInms += dt);
9892
9908
  this.time += dt / 1000;
9893
9909
  var now = time - this.delayInms;
@@ -9899,7 +9915,6 @@ var VFXItem = /** @class */ (function () {
9899
9915
  this.composition.itemLifetimeEvent(this, true);
9900
9916
  }
9901
9917
  if (!this.delaying) {
9902
- var endBehavior = this.endBehavior;
9903
9918
  var lifetime = now / this.durInms;
9904
9919
  var ended = this.isEnded(now);
9905
9920
  var shouldUpdate = true;
@@ -9911,36 +9926,37 @@ var VFXItem = /** @class */ (function () {
9911
9926
  this.composition.itemLifetimeEvent(this, false);
9912
9927
  this.onEnd();
9913
9928
  }
9914
- if (endBehavior !== END_BEHAVIOR_FORWARD$1 && endBehavior !== END_BEHAVIOR_RESTART$1) {
9929
+ // 注意:不要定义私有变量替换 this.endBehavior,直接使用 this 上的!!!(Chrome 下会出现 endBehavior 5 时,能进入以下判断)
9930
+ if (this.endBehavior !== END_BEHAVIOR_FORWARD$1 && this.endBehavior !== END_BEHAVIOR_RESTART$1) {
9915
9931
  this.ended = true;
9916
9932
  this.transform.setValid(false);
9917
- if (endBehavior === END_BEHAVIOR_PAUSE$1 ||
9918
- endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY$1) {
9933
+ if (this.endBehavior === END_BEHAVIOR_PAUSE$1 ||
9934
+ this.endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY$1) {
9919
9935
  (_b = (_a = this.composition).handlePlayerPause) === null || _b === void 0 ? void 0 : _b.call(_a, this);
9920
9936
  }
9921
- else if (endBehavior === END_BEHAVIOR_FREEZE$1) {
9937
+ else if (this.endBehavior === END_BEHAVIOR_FREEZE$1) {
9922
9938
  this.transform.setValid(true);
9923
9939
  shouldUpdate = true;
9924
9940
  lifetime = 1;
9925
9941
  }
9926
9942
  if (!this.reusable) {
9927
- if (endBehavior === END_BEHAVIOR_DESTROY$1 ||
9928
- endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY$1 ||
9929
- endBehavior === END_BEHAVIOR_DESTROY_CHILDREN$1) {
9943
+ if (this.endBehavior === END_BEHAVIOR_DESTROY$1 ||
9944
+ this.endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY$1 ||
9945
+ this.endBehavior === END_BEHAVIOR_DESTROY_CHILDREN$1) {
9930
9946
  return this.dispose();
9931
9947
  }
9932
- else if (endBehavior === END_BEHAVIOR_PAUSE$1) {
9948
+ else if (this.endBehavior === END_BEHAVIOR_PAUSE$1) {
9933
9949
  this.endBehavior = END_BEHAVIOR_FORWARD$1;
9934
9950
  }
9935
9951
  }
9936
- else if (endBehavior === END_BEHAVIOR_DESTROY$1) {
9952
+ else if (this.endBehavior === END_BEHAVIOR_DESTROY$1) {
9937
9953
  this.setVisible(false);
9938
9954
  }
9939
9955
  lifetime = Math.min(lifetime, 1);
9940
9956
  }
9941
9957
  else {
9942
9958
  shouldUpdate = true;
9943
- if (endBehavior === END_BEHAVIOR_RESTART$1) {
9959
+ if (this.endBehavior === END_BEHAVIOR_RESTART$1) {
9944
9960
  this.ended = true;
9945
9961
  lifetime = lifetime % 1;
9946
9962
  }
@@ -9989,8 +10005,20 @@ var VFXItem = /** @class */ (function () {
9989
10005
  VFXItem.prototype.onEnd = function () {
9990
10006
  // OVERRIDE
9991
10007
  };
10008
+ /**
10009
+ * 通过指定 r、g、b、a 值设置元素的颜色
10010
+ * @param {number} r
10011
+ * @param {number} g
10012
+ * @param {number} b
10013
+ * @param {number} a
10014
+ * @internal
10015
+ */
9992
10016
  VFXItem.prototype.setColor = function (r, g, b, a) {
9993
10017
  };
10018
+ /**
10019
+ * 设置元素的透明度
10020
+ * @param opacity - 透明度值,范围 [0,1]
10021
+ */
9994
10022
  VFXItem.prototype.setOpacity = function (opacity) {
9995
10023
  };
9996
10024
  /**
@@ -10066,9 +10094,16 @@ var VFXItem = /** @class */ (function () {
10066
10094
  this.transform.scaleBy(x, y, z);
10067
10095
  };
10068
10096
  /**
10069
- * 元素的在画布上的像素位置
10097
+ * 设置元素的在画布上的像素位置
10070
10098
  */
10071
10099
  VFXItem.prototype.setPositionByPixel = function (x, y) {
10100
+ if (this.composition) {
10101
+ var z = this.transform.getWorldPosition()[2];
10102
+ var _a = __read$1(this.composition.camera.getInverseVPRatio(z), 2), rx = _a[0], ry = _a[1];
10103
+ var width = this.composition.renderer.getWidth() / 2;
10104
+ var height = this.composition.renderer.getHeight() / 2;
10105
+ this.transform.setPosition(2 * x * rx / width, -2 * y * ry / height, z);
10106
+ }
10072
10107
  };
10073
10108
  /**
10074
10109
  * 设置元素在 3D 坐标轴的位置
@@ -10144,9 +10179,11 @@ var VFXItem = /** @class */ (function () {
10144
10179
  };
10145
10180
  VFXItem.prototype.translateByPixel = function (x, y) {
10146
10181
  if (this.composition) {
10147
- var camera = this.composition.camera;
10148
- camera.getViewProjectionMatrix();
10149
- camera.getInverseViewProjectionMatrix();
10182
+ var z = this.transform.getWorldPosition()[2];
10183
+ var _a = __read$1(this.composition.camera.getInverseVPRatio(z), 2), rx = _a[0], ry = _a[1];
10184
+ var width = this.composition.renderer.getWidth() / 2;
10185
+ var height = this.composition.renderer.getHeight() / 2;
10186
+ this.transform.translate(2 * x * rx / width, -2 * y * ry / height, 0);
10150
10187
  }
10151
10188
  };
10152
10189
  /**
@@ -11209,7 +11246,7 @@ function generateHalfFloatTexture(engine, data, width, height) {
11209
11246
  }
11210
11247
 
11211
11248
  var RUNTIME_ENV = 'runtime_env';
11212
- var LOG_TYPE = 'mars';
11249
+ var LOG_TYPE = 'galacean-effects';
11213
11250
  var RENDER_PREFER_LOOKUP_TEXTURE = 'lookup_texture';
11214
11251
  // 数据模板使用 offscreen canvas 绘制
11215
11252
  var TEMPLATE_USE_OFFSCREEN_CANVAS = 'offscreen_canvas';
@@ -14311,14 +14348,10 @@ var SpriteMesh = /** @class */ (function () {
14311
14348
  var uSize = [1, 1, 1, 0];
14312
14349
  var uQuat = [0, 0, 1, 1];
14313
14350
  var uColor = selfData.color || [mainDataArray[uColorStart], mainDataArray[uColorStart + 1], mainDataArray[uColorStart + 2], mainDataArray[uColorStart + 3]];
14314
- // if (selfData.startSize) {
14315
- // selfData.transform.scaleBy(1 / selfData.startSize[0], 1 / selfData.startSize[1], 1);
14316
- // }
14351
+ if (!isNaN(item.getCustomOpacity())) {
14352
+ uColor[3] = item.getCustomOpacity();
14353
+ }
14317
14354
  selfData.transform.assignWorldTRS(uPos, uQuat, uSize);
14318
- // TODO 兼容改变锚点,位置不移动
14319
- // if (selfData.startSize) {
14320
- // selfData.transform.scaleBy(selfData.startSize[0], selfData.startSize[1], 1);
14321
- // }
14322
14355
  /* 要过包含父节点颜色/透明度变化的动画的帧对比 打开这段兼容代码 */
14323
14356
  // vecMulCombine(uColor, selfData.color, parentData.color);
14324
14357
  /***********************/
@@ -15225,7 +15258,7 @@ var SpriteGroup = /** @class */ (function () {
15225
15258
  for (var i = startIndex; i <= endIndex; i++) {
15226
15259
  var item = items[i];
15227
15260
  // 不可见的元素跳过 不参与合并
15228
- if (!init && (!item.contentVisible || item.lifetime < 0)) {
15261
+ if (!init && (!item.started || item.lifetime < 0)) {
15229
15262
  continue;
15230
15263
  }
15231
15264
  if (!isSprite(item)) {
@@ -15499,6 +15532,9 @@ var CalculateItem = /** @class */ (function () {
15499
15532
  get: function () {
15500
15533
  return this.basicTransform.scale;
15501
15534
  },
15535
+ set: function (scale) {
15536
+ this.basicTransform.scale = scale;
15537
+ },
15502
15538
  enumerable: false,
15503
15539
  configurable: true
15504
15540
  });
@@ -15697,11 +15733,20 @@ var SpriteItem = /** @class */ (function (_super) {
15697
15733
  }
15698
15734
  return ret;
15699
15735
  };
15736
+ /**
15737
+ * @internal
15738
+ */
15700
15739
  SpriteItem.prototype.setColor = function (r, g, b, a) {
15701
- this.options.startColor = [r, g, b, a];
15740
+ this.customColor = [r, g, b, a];
15702
15741
  };
15703
15742
  SpriteItem.prototype.setOpacity = function (opacity) {
15704
- this.options.startColor[3] = opacity;
15743
+ this.customOpacity = opacity;
15744
+ };
15745
+ /**
15746
+ * @internal
15747
+ */
15748
+ SpriteItem.prototype.getCustomOpacity = function () {
15749
+ return this.customOpacity;
15705
15750
  };
15706
15751
  SpriteItem.prototype.getRenderData = function (_time, init) {
15707
15752
  var ret = _super.prototype.getRenderData.call(this, _time, init);
@@ -15710,18 +15755,23 @@ var SpriteItem = /** @class */ (function (_super) {
15710
15755
  var time = _time < 0 ? _time : Math.max(_time, 0.);
15711
15756
  var duration = this.options.duration;
15712
15757
  var life = time / duration < 0 ? 0 : (time / duration > 1 ? 1 : time / duration);
15713
- var opacityOverLifetime = this.opacityOverLifetime;
15714
- var colorOverLifetime = this.colorOverLifetime;
15715
- if (colorOverLifetime) {
15716
- colorInc = getColorFromGradientStops(colorOverLifetime, life, true);
15717
- colorChanged = true;
15758
+ if (this.customColor) {
15759
+ ret.color = this.customColor;
15718
15760
  }
15719
- if (opacityOverLifetime) {
15720
- colorInc[3] *= opacityOverLifetime.getValue(life);
15721
- colorChanged = true;
15722
- }
15723
- if (colorChanged || init) {
15724
- ret.color = vecMulCombine(this.startColor, colorInc, this.options.startColor);
15761
+ else {
15762
+ var opacityOverLifetime = this.opacityOverLifetime;
15763
+ var colorOverLifetime = this.colorOverLifetime;
15764
+ if (colorOverLifetime) {
15765
+ colorInc = getColorFromGradientStops(colorOverLifetime, life, true);
15766
+ colorChanged = true;
15767
+ }
15768
+ if (opacityOverLifetime) {
15769
+ colorInc[3] *= opacityOverLifetime.getValue(life);
15770
+ colorChanged = true;
15771
+ }
15772
+ if (colorChanged || init) {
15773
+ ret.color = vecMulCombine(this.startColor, colorInc, this.options.startColor);
15774
+ }
15725
15775
  }
15726
15776
  var ta = this.textureSheetAnimation;
15727
15777
  if (ta) {
@@ -15826,6 +15876,9 @@ var SpriteVFXItem = /** @class */ (function (_super) {
15826
15876
  this.transform.assignWorldTRS(pos);
15827
15877
  return pos;
15828
15878
  };
15879
+ /**
15880
+ * @internal
15881
+ */
15829
15882
  SpriteVFXItem.prototype.setColor = function (r, g, b, a) {
15830
15883
  this.content.setColor(r, g, b, a);
15831
15884
  };
@@ -18516,19 +18569,29 @@ var ParticleSystem = /** @class */ (function () {
18516
18569
  };
18517
18570
  ParticleSystem.prototype.setOpacity = function (opacity) {
18518
18571
  var material = this.particleMesh.mesh.material;
18519
- material.setVector4('uOpacityOverLifetimeValue', [1, 1, 1, opacity]);
18572
+ var geometry = this.particleMesh.mesh.geometry;
18573
+ var originalColor = material.getVector4('uOpacityOverLifetimeValue') || [1, 1, 1, 1];
18574
+ material.setVector4('uOpacityOverLifetimeValue', [originalColor[0], originalColor[1], originalColor[2], opacity]);
18575
+ var data = geometry.getAttributeData('aColor') || [];
18576
+ for (var i = 0; i < data.length; i += 32) {
18577
+ data[i * 8 + 7] = opacity;
18578
+ }
18520
18579
  };
18580
+ /**
18581
+ * @internal
18582
+ */
18521
18583
  ParticleSystem.prototype.setColor = function (r, g, b, a) {
18522
18584
  var material = this.particleMesh.mesh.material;
18523
18585
  var geometry = this.particleMesh.mesh.geometry;
18524
- var data = geometry.getAttributeData('aRot') || [];
18525
- for (var i = 0; i < data.length; i += 4) {
18526
- data[0] = r;
18527
- data[1] = g;
18528
- data[2] = b;
18529
- data[3] = a;
18586
+ var originalColor = material.getVector4('uOpacityOverLifetimeValue') || [1, 1, 1, 1];
18587
+ material.setVector4('uOpacityOverLifetimeValue', [originalColor[0], originalColor[1], originalColor[2], a]);
18588
+ var data = geometry.getAttributeData('aColor') || [];
18589
+ for (var i = 0; i < data.length; i += 32) {
18590
+ data[i * 8 + 4] = r;
18591
+ data[i * 8 + 5] = g;
18592
+ data[i * 8 + 6] = b;
18593
+ data[i * 8 + 7] = a;
18530
18594
  }
18531
- material.setVector4('uOpacityOverLifetimeValue', [r, g, b, a]);
18532
18595
  };
18533
18596
  ParticleSystem.prototype.setParentTransform = function (transform) {
18534
18597
  this.parentTransform = transform;
@@ -19080,6 +19143,9 @@ var ParticleVFXItem = /** @class */ (function (_super) {
19080
19143
  content.meshes.forEach(function (mesh) { return mesh.dispose({ material: { textures: DestroyOptions.keep } }); });
19081
19144
  }
19082
19145
  };
19146
+ /**
19147
+ * @internal
19148
+ */
19083
19149
  ParticleVFXItem.prototype.setColor = function (r, g, b, a) {
19084
19150
  this.content.setColor(r, g, b, a);
19085
19151
  };
@@ -19394,6 +19460,13 @@ var CalculateVFXItem = /** @class */ (function (_super) {
19394
19460
  /********************/
19395
19461
  }
19396
19462
  };
19463
+ CalculateVFXItem.prototype.setScale = function (x, y, z) {
19464
+ this.content.startSize = [x, y, z];
19465
+ };
19466
+ CalculateVFXItem.prototype.scale = function (x, y, z) {
19467
+ var startSize = this.content.startSize.slice();
19468
+ this.content.startSize = [x * startSize[0], y * startSize[1], z * startSize[2]];
19469
+ };
19397
19470
  CalculateVFXItem.prototype.getHitTestParams = function (force) {
19398
19471
  };
19399
19472
  CalculateVFXItem.prototype.getRenderData = function () {
@@ -22156,12 +22229,13 @@ var Camera = /** @class */ (function () {
22156
22229
  };
22157
22230
  /**
22158
22231
  * 获取归一化坐标和 3D 世界坐标的换算比例
22232
+ * @param z - 当前的位置 z
22159
22233
  */
22160
- Camera.prototype.getInverseVPRatio = function () {
22234
+ Camera.prototype.getInverseVPRatio = function (z) {
22161
22235
  var pos = [0, 0, 0];
22162
- var nz = vec3MulMat4(pos, [0, 0, 0], this.getViewProjectionMatrix())[2];
22236
+ var nz = vec3MulMat4(pos, [0, 0, z], this.getViewProjectionMatrix())[2];
22163
22237
  vec3MulMat4(pos, [1, 1, nz], this.getInverseViewProjectionMatrix());
22164
- return [pos[0], pos[1]];
22238
+ return pos;
22165
22239
  };
22166
22240
  /**
22167
22241
  * 设置相机的旋转四元数
@@ -22353,7 +22427,7 @@ var filters = {
22353
22427
  * Name: @galacean/effects-specification
22354
22428
  * Description: Galacean Effects JSON Specification
22355
22429
  * Author: Ant Group CO., Ltd.
22356
- * Version: v0.0.2
22430
+ * Version: v1.0.0
22357
22431
  */
22358
22432
 
22359
22433
  /*********************************************/
@@ -23070,7 +23144,12 @@ function __read(o, n) {
23070
23144
  finally { if (e) throw e.error; }
23071
23145
  }
23072
23146
  return ar;
23073
- }
23147
+ }
23148
+
23149
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
23150
+ var e = new Error(message);
23151
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
23152
+ };
23074
23153
 
23075
23154
  function arrAdd(arr, item) {
23076
23155
  if (!arr.includes(item)) {
@@ -25128,6 +25207,12 @@ var Composition = /** @class */ (function () {
25128
25207
  enumerable: false,
25129
25208
  configurable: true
25130
25209
  });
25210
+ /**
25211
+ * 获取合成的时长
25212
+ */
25213
+ Composition.prototype.getDuration = function () {
25214
+ return this.content.duration;
25215
+ };
25131
25216
  Object.defineProperty(Composition.prototype, "isDestroyed", {
25132
25217
  /**
25133
25218
  * 获取销毁状态
@@ -25165,6 +25250,20 @@ var Composition = /** @class */ (function () {
25165
25250
  Composition.prototype.getIndex = function () {
25166
25251
  return this.renderOrder;
25167
25252
  };
25253
+ /**
25254
+ * 设置合成的动画速度
25255
+ * @param speed - 速度
25256
+ */
25257
+ Composition.prototype.setSpeed = function (speed) {
25258
+ this.speed = speed;
25259
+ };
25260
+ /**
25261
+ * 获取合成的动画速度
25262
+ * @returns
25263
+ */
25264
+ Composition.prototype.getSpeed = function () {
25265
+ return this.speed;
25266
+ };
25168
25267
  Composition.prototype.play = function () {
25169
25268
  if (this.content.ended && this.reusable) {
25170
25269
  this.restart();
@@ -25623,10 +25722,7 @@ var Composition = /** @class */ (function () {
25623
25722
  console.warn('Can not translate position when container not assigned');
25624
25723
  return;
25625
25724
  }
25626
- var _a = __read$1(this.camera.getInverseVPRatio(), 2), rx = _a[0], ry = _a[1];
25627
- var width = this.renderer.getWidth();
25628
- var height = this.renderer.getHeight();
25629
- this.content.translate(2 * x * rx / width, -2 * y * ry / height, 0);
25725
+ this.content.translateByPixel(x, y);
25630
25726
  };
25631
25727
  /**
25632
25728
  * 设置合成在 3D 坐标轴上相对移动
@@ -27434,9 +27530,9 @@ Geometry.create = function (engine, options) {
27434
27530
  Mesh.create = function (engine, props) {
27435
27531
  return new ThreeMesh(engine, props);
27436
27532
  };
27437
- var version = "0.0.1-alpha.1";
27533
+ var version = "0.0.1-alpha.3";
27438
27534
  console.info({
27439
- content: '[Galacean Effects THREEJS] version: ' + "0.0.1-alpha.1",
27535
+ content: '[Galacean Effects THREEJS] version: ' + "0.0.1-alpha.3",
27440
27536
  type: LOG_TYPE,
27441
27537
  });
27442
27538