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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -74,4 +74,4 @@ render();
74
74
 
75
75
  ## API 文档
76
76
 
77
- TODO
77
+ [Galacean Effects THREE.JS API 文档](https://galacean.antgroup.com/effects/#/api/modules_galacean_effects_threejs)
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: v0.0.1-alpha.1
6
+ * Version: v0.0.1-alpha.2
7
7
  */
8
8
 
9
9
  'use strict';
@@ -6145,8 +6145,8 @@ var PLAYER_OPTIONS_ENV_EDITOR = 'editor';
6145
6145
  var FILTER_NAME_NONE = 'none';
6146
6146
  var DEG2RAD = 0.017453292519943295;
6147
6147
  var HELP_LINK = {
6148
- 'Filter not imported': 'https://yuque.antfin.com/huoxing/knaszl/qtnsf2g9ofigggor#n4Y1K',
6149
- 'Item duration can\'t be less than 0': 'https://yuque.antfin.com/huoxing/knaszl/wozlz0#vFPqF',
6148
+ 'Filter not imported': 'https://galacean.antgroup.com/effects/#/user/gasrv4ka5sacrwpg',
6149
+ 'Item duration can\'t be less than 0': 'https://galacean.antgroup.com/effects/#/user/gasrv4ka5sacrwpg',
6150
6150
  };
6151
6151
 
6152
6152
  /**
@@ -6689,7 +6689,7 @@ function asserts(condition, msg) {
6689
6689
  * Name: @galacean/effects-specification
6690
6690
  * Description: Galacean Effects JSON Specification
6691
6691
  * Author: Ant Group CO., Ltd.
6692
- * Version: v0.0.2
6692
+ * Version: v1.0.0
6693
6693
  */
6694
6694
 
6695
6695
  /*********************************************/
@@ -9774,6 +9774,7 @@ var VFXItem = /** @class */ (function () {
9774
9774
  this.endBehavior = endBehavior;
9775
9775
  this.lifetime = -(this.delayInms / this.durInms);
9776
9776
  this.listIndex = listIndex;
9777
+ this.speed = 1;
9777
9778
  this.onConstructed(props);
9778
9779
  if (duration <= 0) {
9779
9780
  throw Error("Item duration can't be less than 0, see ".concat(HELP_LINK['Item duration can\'t be less than 0']));
@@ -9852,6 +9853,20 @@ var VFXItem = /** @class */ (function () {
9852
9853
  enumerable: false,
9853
9854
  configurable: true
9854
9855
  });
9856
+ /**
9857
+ * 设置元素的动画速度
9858
+ * @param speed - 速度
9859
+ */
9860
+ VFXItem.prototype.setSpeed = function (speed) {
9861
+ this.speed = speed;
9862
+ };
9863
+ /**
9864
+ * 获取元素的动画速度
9865
+ * @returns
9866
+ */
9867
+ VFXItem.prototype.getSpeed = function () {
9868
+ return this.speed;
9869
+ };
9855
9870
  /**
9856
9871
  * 重置元素状态属性
9857
9872
  */
@@ -9907,11 +9922,12 @@ var VFXItem = /** @class */ (function () {
9907
9922
  };
9908
9923
  /**
9909
9924
  * 内部使用的更新回调,请不要重写此方法,重写 `onItemUpdate` 方法
9910
- * @param dt
9925
+ * @param deltaTime
9911
9926
  */
9912
- VFXItem.prototype.onUpdate = function (dt) {
9927
+ VFXItem.prototype.onUpdate = function (deltaTime) {
9913
9928
  var _a, _b;
9914
9929
  if (this.started && !this.frozen && this.composition) {
9930
+ var dt = deltaTime * this.speed;
9915
9931
  var time = (this.timeInms += dt);
9916
9932
  this.time += dt / 1000;
9917
9933
  var now = time - this.delayInms;
@@ -9923,7 +9939,6 @@ var VFXItem = /** @class */ (function () {
9923
9939
  this.composition.itemLifetimeEvent(this, true);
9924
9940
  }
9925
9941
  if (!this.delaying) {
9926
- var endBehavior = this.endBehavior;
9927
9942
  var lifetime = now / this.durInms;
9928
9943
  var ended = this.isEnded(now);
9929
9944
  var shouldUpdate = true;
@@ -9935,36 +9950,37 @@ var VFXItem = /** @class */ (function () {
9935
9950
  this.composition.itemLifetimeEvent(this, false);
9936
9951
  this.onEnd();
9937
9952
  }
9938
- if (endBehavior !== END_BEHAVIOR_FORWARD$1 && endBehavior !== END_BEHAVIOR_RESTART$1) {
9953
+ // 注意:不要定义私有变量替换 this.endBehavior,直接使用 this 上的!!!(Chrome 下会出现 endBehavior 5 时,能进入以下判断)
9954
+ if (this.endBehavior !== END_BEHAVIOR_FORWARD$1 && this.endBehavior !== END_BEHAVIOR_RESTART$1) {
9939
9955
  this.ended = true;
9940
9956
  this.transform.setValid(false);
9941
- if (endBehavior === END_BEHAVIOR_PAUSE$1 ||
9942
- endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY$1) {
9957
+ if (this.endBehavior === END_BEHAVIOR_PAUSE$1 ||
9958
+ this.endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY$1) {
9943
9959
  (_b = (_a = this.composition).handlePlayerPause) === null || _b === void 0 ? void 0 : _b.call(_a, this);
9944
9960
  }
9945
- else if (endBehavior === END_BEHAVIOR_FREEZE$1) {
9961
+ else if (this.endBehavior === END_BEHAVIOR_FREEZE$1) {
9946
9962
  this.transform.setValid(true);
9947
9963
  shouldUpdate = true;
9948
9964
  lifetime = 1;
9949
9965
  }
9950
9966
  if (!this.reusable) {
9951
- if (endBehavior === END_BEHAVIOR_DESTROY$1 ||
9952
- endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY$1 ||
9953
- endBehavior === END_BEHAVIOR_DESTROY_CHILDREN$1) {
9967
+ if (this.endBehavior === END_BEHAVIOR_DESTROY$1 ||
9968
+ this.endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY$1 ||
9969
+ this.endBehavior === END_BEHAVIOR_DESTROY_CHILDREN$1) {
9954
9970
  return this.dispose();
9955
9971
  }
9956
- else if (endBehavior === END_BEHAVIOR_PAUSE$1) {
9972
+ else if (this.endBehavior === END_BEHAVIOR_PAUSE$1) {
9957
9973
  this.endBehavior = END_BEHAVIOR_FORWARD$1;
9958
9974
  }
9959
9975
  }
9960
- else if (endBehavior === END_BEHAVIOR_DESTROY$1) {
9976
+ else if (this.endBehavior === END_BEHAVIOR_DESTROY$1) {
9961
9977
  this.setVisible(false);
9962
9978
  }
9963
9979
  lifetime = Math.min(lifetime, 1);
9964
9980
  }
9965
9981
  else {
9966
9982
  shouldUpdate = true;
9967
- if (endBehavior === END_BEHAVIOR_RESTART$1) {
9983
+ if (this.endBehavior === END_BEHAVIOR_RESTART$1) {
9968
9984
  this.ended = true;
9969
9985
  lifetime = lifetime % 1;
9970
9986
  }
@@ -10013,8 +10029,20 @@ var VFXItem = /** @class */ (function () {
10013
10029
  VFXItem.prototype.onEnd = function () {
10014
10030
  // OVERRIDE
10015
10031
  };
10032
+ /**
10033
+ * 通过指定 r、g、b、a 值设置元素的颜色
10034
+ * @param {number} r
10035
+ * @param {number} g
10036
+ * @param {number} b
10037
+ * @param {number} a
10038
+ * @internal
10039
+ */
10016
10040
  VFXItem.prototype.setColor = function (r, g, b, a) {
10017
10041
  };
10042
+ /**
10043
+ * 设置元素的透明度
10044
+ * @param opacity - 透明度值,范围 [0,1]
10045
+ */
10018
10046
  VFXItem.prototype.setOpacity = function (opacity) {
10019
10047
  };
10020
10048
  /**
@@ -10090,9 +10118,16 @@ var VFXItem = /** @class */ (function () {
10090
10118
  this.transform.scaleBy(x, y, z);
10091
10119
  };
10092
10120
  /**
10093
- * 元素的在画布上的像素位置
10121
+ * 设置元素的在画布上的像素位置
10094
10122
  */
10095
10123
  VFXItem.prototype.setPositionByPixel = function (x, y) {
10124
+ if (this.composition) {
10125
+ var z = this.transform.getWorldPosition()[2];
10126
+ var _a = __read$1(this.composition.camera.getInverseVPRatio(z), 2), rx = _a[0], ry = _a[1];
10127
+ var width = this.composition.renderer.getWidth() / 2;
10128
+ var height = this.composition.renderer.getHeight() / 2;
10129
+ this.transform.setPosition(2 * x * rx / width, -2 * y * ry / height, z);
10130
+ }
10096
10131
  };
10097
10132
  /**
10098
10133
  * 设置元素在 3D 坐标轴的位置
@@ -10168,9 +10203,11 @@ var VFXItem = /** @class */ (function () {
10168
10203
  };
10169
10204
  VFXItem.prototype.translateByPixel = function (x, y) {
10170
10205
  if (this.composition) {
10171
- var camera = this.composition.camera;
10172
- camera.getViewProjectionMatrix();
10173
- camera.getInverseViewProjectionMatrix();
10206
+ var z = this.transform.getWorldPosition()[2];
10207
+ var _a = __read$1(this.composition.camera.getInverseVPRatio(z), 2), rx = _a[0], ry = _a[1];
10208
+ var width = this.composition.renderer.getWidth() / 2;
10209
+ var height = this.composition.renderer.getHeight() / 2;
10210
+ this.transform.translate(2 * x * rx / width, -2 * y * ry / height, 0);
10174
10211
  }
10175
10212
  };
10176
10213
  /**
@@ -11233,7 +11270,7 @@ function generateHalfFloatTexture(engine, data, width, height) {
11233
11270
  }
11234
11271
 
11235
11272
  var RUNTIME_ENV = 'runtime_env';
11236
- var LOG_TYPE = 'mars';
11273
+ var LOG_TYPE = 'galacean-effects';
11237
11274
  var RENDER_PREFER_LOOKUP_TEXTURE = 'lookup_texture';
11238
11275
  // 数据模板使用 offscreen canvas 绘制
11239
11276
  var TEMPLATE_USE_OFFSCREEN_CANVAS = 'offscreen_canvas';
@@ -14335,14 +14372,10 @@ var SpriteMesh = /** @class */ (function () {
14335
14372
  var uSize = [1, 1, 1, 0];
14336
14373
  var uQuat = [0, 0, 1, 1];
14337
14374
  var uColor = selfData.color || [mainDataArray[uColorStart], mainDataArray[uColorStart + 1], mainDataArray[uColorStart + 2], mainDataArray[uColorStart + 3]];
14338
- // if (selfData.startSize) {
14339
- // selfData.transform.scaleBy(1 / selfData.startSize[0], 1 / selfData.startSize[1], 1);
14340
- // }
14375
+ if (!isNaN(item.getCustomOpacity())) {
14376
+ uColor[3] = item.getCustomOpacity();
14377
+ }
14341
14378
  selfData.transform.assignWorldTRS(uPos, uQuat, uSize);
14342
- // TODO 兼容改变锚点,位置不移动
14343
- // if (selfData.startSize) {
14344
- // selfData.transform.scaleBy(selfData.startSize[0], selfData.startSize[1], 1);
14345
- // }
14346
14379
  /* 要过包含父节点颜色/透明度变化的动画的帧对比 打开这段兼容代码 */
14347
14380
  // vecMulCombine(uColor, selfData.color, parentData.color);
14348
14381
  /***********************/
@@ -15523,6 +15556,9 @@ var CalculateItem = /** @class */ (function () {
15523
15556
  get: function () {
15524
15557
  return this.basicTransform.scale;
15525
15558
  },
15559
+ set: function (scale) {
15560
+ this.basicTransform.scale = scale;
15561
+ },
15526
15562
  enumerable: false,
15527
15563
  configurable: true
15528
15564
  });
@@ -15721,11 +15757,20 @@ var SpriteItem = /** @class */ (function (_super) {
15721
15757
  }
15722
15758
  return ret;
15723
15759
  };
15760
+ /**
15761
+ * @internal
15762
+ */
15724
15763
  SpriteItem.prototype.setColor = function (r, g, b, a) {
15725
- this.options.startColor = [r, g, b, a];
15764
+ this.customColor = [r, g, b, a];
15726
15765
  };
15727
15766
  SpriteItem.prototype.setOpacity = function (opacity) {
15728
- this.options.startColor[3] = opacity;
15767
+ this.customOpacity = opacity;
15768
+ };
15769
+ /**
15770
+ * @internal
15771
+ */
15772
+ SpriteItem.prototype.getCustomOpacity = function () {
15773
+ return this.customOpacity;
15729
15774
  };
15730
15775
  SpriteItem.prototype.getRenderData = function (_time, init) {
15731
15776
  var ret = _super.prototype.getRenderData.call(this, _time, init);
@@ -15734,18 +15779,23 @@ var SpriteItem = /** @class */ (function (_super) {
15734
15779
  var time = _time < 0 ? _time : Math.max(_time, 0.);
15735
15780
  var duration = this.options.duration;
15736
15781
  var life = time / duration < 0 ? 0 : (time / duration > 1 ? 1 : time / duration);
15737
- var opacityOverLifetime = this.opacityOverLifetime;
15738
- var colorOverLifetime = this.colorOverLifetime;
15739
- if (colorOverLifetime) {
15740
- colorInc = getColorFromGradientStops(colorOverLifetime, life, true);
15741
- colorChanged = true;
15782
+ if (this.customColor) {
15783
+ ret.color = this.customColor;
15742
15784
  }
15743
- if (opacityOverLifetime) {
15744
- colorInc[3] *= opacityOverLifetime.getValue(life);
15745
- colorChanged = true;
15746
- }
15747
- if (colorChanged || init) {
15748
- ret.color = vecMulCombine(this.startColor, colorInc, this.options.startColor);
15785
+ else {
15786
+ var opacityOverLifetime = this.opacityOverLifetime;
15787
+ var colorOverLifetime = this.colorOverLifetime;
15788
+ if (colorOverLifetime) {
15789
+ colorInc = getColorFromGradientStops(colorOverLifetime, life, true);
15790
+ colorChanged = true;
15791
+ }
15792
+ if (opacityOverLifetime) {
15793
+ colorInc[3] *= opacityOverLifetime.getValue(life);
15794
+ colorChanged = true;
15795
+ }
15796
+ if (colorChanged || init) {
15797
+ ret.color = vecMulCombine(this.startColor, colorInc, this.options.startColor);
15798
+ }
15749
15799
  }
15750
15800
  var ta = this.textureSheetAnimation;
15751
15801
  if (ta) {
@@ -15850,6 +15900,9 @@ var SpriteVFXItem = /** @class */ (function (_super) {
15850
15900
  this.transform.assignWorldTRS(pos);
15851
15901
  return pos;
15852
15902
  };
15903
+ /**
15904
+ * @internal
15905
+ */
15853
15906
  SpriteVFXItem.prototype.setColor = function (r, g, b, a) {
15854
15907
  this.content.setColor(r, g, b, a);
15855
15908
  };
@@ -18540,19 +18593,29 @@ var ParticleSystem = /** @class */ (function () {
18540
18593
  };
18541
18594
  ParticleSystem.prototype.setOpacity = function (opacity) {
18542
18595
  var material = this.particleMesh.mesh.material;
18543
- material.setVector4('uOpacityOverLifetimeValue', [1, 1, 1, opacity]);
18596
+ var geometry = this.particleMesh.mesh.geometry;
18597
+ var originalColor = material.getVector4('uOpacityOverLifetimeValue') || [1, 1, 1, 1];
18598
+ material.setVector4('uOpacityOverLifetimeValue', [originalColor[0], originalColor[1], originalColor[2], opacity]);
18599
+ var data = geometry.getAttributeData('aColor') || [];
18600
+ for (var i = 0; i < data.length; i += 32) {
18601
+ data[i * 8 + 7] = opacity;
18602
+ }
18544
18603
  };
18604
+ /**
18605
+ * @internal
18606
+ */
18545
18607
  ParticleSystem.prototype.setColor = function (r, g, b, a) {
18546
18608
  var material = this.particleMesh.mesh.material;
18547
18609
  var geometry = this.particleMesh.mesh.geometry;
18548
- var data = geometry.getAttributeData('aRot') || [];
18549
- for (var i = 0; i < data.length; i += 4) {
18550
- data[0] = r;
18551
- data[1] = g;
18552
- data[2] = b;
18553
- data[3] = a;
18610
+ var originalColor = material.getVector4('uOpacityOverLifetimeValue') || [1, 1, 1, 1];
18611
+ material.setVector4('uOpacityOverLifetimeValue', [originalColor[0], originalColor[1], originalColor[2], a]);
18612
+ var data = geometry.getAttributeData('aColor') || [];
18613
+ for (var i = 0; i < data.length; i += 32) {
18614
+ data[i * 8 + 4] = r;
18615
+ data[i * 8 + 5] = g;
18616
+ data[i * 8 + 6] = b;
18617
+ data[i * 8 + 7] = a;
18554
18618
  }
18555
- material.setVector4('uOpacityOverLifetimeValue', [r, g, b, a]);
18556
18619
  };
18557
18620
  ParticleSystem.prototype.setParentTransform = function (transform) {
18558
18621
  this.parentTransform = transform;
@@ -19104,6 +19167,9 @@ var ParticleVFXItem = /** @class */ (function (_super) {
19104
19167
  content.meshes.forEach(function (mesh) { return mesh.dispose({ material: { textures: exports.DestroyOptions.keep } }); });
19105
19168
  }
19106
19169
  };
19170
+ /**
19171
+ * @internal
19172
+ */
19107
19173
  ParticleVFXItem.prototype.setColor = function (r, g, b, a) {
19108
19174
  this.content.setColor(r, g, b, a);
19109
19175
  };
@@ -19418,6 +19484,9 @@ var CalculateVFXItem = /** @class */ (function (_super) {
19418
19484
  /********************/
19419
19485
  }
19420
19486
  };
19487
+ CalculateVFXItem.prototype.setScale = function (x, y, z) {
19488
+ this.content.startSize = [x, y, z];
19489
+ };
19421
19490
  CalculateVFXItem.prototype.getHitTestParams = function (force) {
19422
19491
  };
19423
19492
  CalculateVFXItem.prototype.getRenderData = function () {
@@ -22180,12 +22249,13 @@ var Camera = /** @class */ (function () {
22180
22249
  };
22181
22250
  /**
22182
22251
  * 获取归一化坐标和 3D 世界坐标的换算比例
22252
+ * @param z - 当前的位置 z
22183
22253
  */
22184
- Camera.prototype.getInverseVPRatio = function () {
22254
+ Camera.prototype.getInverseVPRatio = function (z) {
22185
22255
  var pos = [0, 0, 0];
22186
- var nz = vec3MulMat4(pos, [0, 0, 0], this.getViewProjectionMatrix())[2];
22256
+ var nz = vec3MulMat4(pos, [0, 0, z], this.getViewProjectionMatrix())[2];
22187
22257
  vec3MulMat4(pos, [1, 1, nz], this.getInverseViewProjectionMatrix());
22188
- return [pos[0], pos[1]];
22258
+ return pos;
22189
22259
  };
22190
22260
  /**
22191
22261
  * 设置相机的旋转四元数
@@ -22377,7 +22447,7 @@ var filters = {
22377
22447
  * Name: @galacean/effects-specification
22378
22448
  * Description: Galacean Effects JSON Specification
22379
22449
  * Author: Ant Group CO., Ltd.
22380
- * Version: v0.0.2
22450
+ * Version: v1.0.0
22381
22451
  */
22382
22452
 
22383
22453
  /*********************************************/
@@ -23094,7 +23164,12 @@ function __read(o, n) {
23094
23164
  finally { if (e) throw e.error; }
23095
23165
  }
23096
23166
  return ar;
23097
- }
23167
+ }
23168
+
23169
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
23170
+ var e = new Error(message);
23171
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
23172
+ };
23098
23173
 
23099
23174
  function arrAdd(arr, item) {
23100
23175
  if (!arr.includes(item)) {
@@ -25152,6 +25227,12 @@ var Composition = /** @class */ (function () {
25152
25227
  enumerable: false,
25153
25228
  configurable: true
25154
25229
  });
25230
+ /**
25231
+ * 获取合成的时长
25232
+ */
25233
+ Composition.prototype.getDuration = function () {
25234
+ return this.content.duration;
25235
+ };
25155
25236
  Object.defineProperty(Composition.prototype, "isDestroyed", {
25156
25237
  /**
25157
25238
  * 获取销毁状态
@@ -25189,6 +25270,20 @@ var Composition = /** @class */ (function () {
25189
25270
  Composition.prototype.getIndex = function () {
25190
25271
  return this.renderOrder;
25191
25272
  };
25273
+ /**
25274
+ * 设置合成的动画速度
25275
+ * @param speed - 速度
25276
+ */
25277
+ Composition.prototype.setSpeed = function (speed) {
25278
+ this.speed = speed;
25279
+ };
25280
+ /**
25281
+ * 获取合成的动画速度
25282
+ * @returns
25283
+ */
25284
+ Composition.prototype.getSpeed = function () {
25285
+ return this.speed;
25286
+ };
25192
25287
  Composition.prototype.play = function () {
25193
25288
  if (this.content.ended && this.reusable) {
25194
25289
  this.restart();
@@ -25647,10 +25742,7 @@ var Composition = /** @class */ (function () {
25647
25742
  console.warn('Can not translate position when container not assigned');
25648
25743
  return;
25649
25744
  }
25650
- var _a = __read$1(this.camera.getInverseVPRatio(), 2), rx = _a[0], ry = _a[1];
25651
- var width = this.renderer.getWidth();
25652
- var height = this.renderer.getHeight();
25653
- this.content.translate(2 * x * rx / width, -2 * y * ry / height, 0);
25745
+ this.content.translateByPixel(x, y);
25654
25746
  };
25655
25747
  /**
25656
25748
  * 设置合成在 3D 坐标轴上相对移动
@@ -27458,9 +27550,9 @@ Geometry.create = function (engine, options) {
27458
27550
  Mesh.create = function (engine, props) {
27459
27551
  return new ThreeMesh(engine, props);
27460
27552
  };
27461
- var version = "0.0.1-alpha.1";
27553
+ var version = "0.0.1-alpha.2";
27462
27554
  console.info({
27463
- content: '[Galacean Effects THREEJS] version: ' + "0.0.1-alpha.1",
27555
+ content: '[Galacean Effects THREEJS] version: ' + "0.0.1-alpha.2",
27464
27556
  type: LOG_TYPE,
27465
27557
  });
27466
27558