@galacean/effects-threejs 2.0.0-alpha.18 → 2.0.0-alpha.19

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.0.0-alpha.18
6
+ * Version: v2.0.0-alpha.19
7
7
  */
8
8
 
9
9
  'use strict';
@@ -288,12 +288,12 @@ function addItem(arr, value) {
288
288
  arr[index] = currentItem;
289
289
  }
290
290
  }
291
- function enlargeBuffer(typeArray, length, increase, maxSize) {
291
+ function enlargeBuffer(typeArray, length, maxSize, increase) {
292
292
  if (increase === void 0) increase = 1;
293
293
  var buffer = typeArray.buffer;
294
294
  if (buffer.byteLength < typeArray.BYTES_PER_ELEMENT * length) {
295
295
  var size = Math.ceil(length * increase);
296
- if (!isNaN(maxSize)) {
296
+ if (!Number.isNaN(maxSize)) {
297
297
  size = Math.min(size, maxSize);
298
298
  }
299
299
  var nbuffer = new ArrayBuffer(typeArray.BYTES_PER_ELEMENT * size);
@@ -814,6 +814,17 @@ function base64ToFile(base64, filename, contentType) {
814
814
  });
815
815
  return file;
816
816
  }
817
+ function applyMixins(derivedCtrl, baseCtrls) {
818
+ baseCtrls.forEach(function(baseCtrl) {
819
+ Object.getOwnPropertyNames(baseCtrl.prototype).forEach(function(name) {
820
+ var propertyDescriptor = Object.getOwnPropertyDescriptor(baseCtrl.prototype, name);
821
+ if (!propertyDescriptor) {
822
+ throw new Error("Cannot find property descriptor of class " + baseCtrl);
823
+ }
824
+ Object.defineProperty(derivedCtrl.prototype, name, propertyDescriptor);
825
+ });
826
+ });
827
+ }
817
828
 
818
829
  function _defineProperties(target, props) {
819
830
  for(var i = 0; i < props.length; i++){
@@ -9963,6 +9974,9 @@ var StaticValue = /*#__PURE__*/ function(ValueGetter) {
9963
9974
  this.value = func(val);
9964
9975
  return this;
9965
9976
  };
9977
+ _proto.getMaxTime = function getMaxTime() {
9978
+ return 0;
9979
+ };
9966
9980
  return StaticValue;
9967
9981
  }(ValueGetter);
9968
9982
  var RandomSetValue = /*#__PURE__*/ function(ValueGetter) {
@@ -17267,7 +17281,10 @@ function randomArrItem(arr, keepArr) {
17267
17281
  */ var ParticleBehaviourPlayable = /*#__PURE__*/ function(Playable) {
17268
17282
  _inherits(ParticleBehaviourPlayable, Playable);
17269
17283
  function ParticleBehaviourPlayable() {
17270
- return Playable.apply(this, arguments);
17284
+ var _this;
17285
+ _this = Playable.apply(this, arguments) || this;
17286
+ _this.lastTime = 0;
17287
+ return _this;
17271
17288
  }
17272
17289
  var _proto = ParticleBehaviourPlayable.prototype;
17273
17290
  _proto.start = function start(context) {
@@ -17291,8 +17308,14 @@ function randomArrItem(arr, keepArr) {
17291
17308
  // TODO: [1.31] @十弦 验证 https://github.com/galacean/effects-runtime/commit/3e7d73d37b7d98c2a25e4544e80e928b17801ccd#diff-fae062f28caf3771cfedd3a20dc22f9749bd054c7541bf2fd50a9a5e413153d4
17292
17309
  // particleSystem.setParentTransform(parentItem.transform);
17293
17310
  particleSystem.setVisible(true);
17294
- particleSystem.onUpdate(context.deltaTime);
17311
+ var deltaTime = context.deltaTime;
17312
+ // 直接用 this.lastTime - this.time 获取 deltaTime 会有精度问题
17313
+ if (this.lastTime === this.time) {
17314
+ deltaTime = 0;
17315
+ }
17316
+ particleSystem.onUpdate(deltaTime);
17295
17317
  }
17318
+ this.lastTime = this.time;
17296
17319
  };
17297
17320
  return ParticleBehaviourPlayable;
17298
17321
  }(Playable);
@@ -17873,7 +17896,7 @@ var ParticleMesh = /*#__PURE__*/ function() {
17873
17896
  }));
17874
17897
  if (increaseBuffer) {
17875
17898
  var baseIndexData = geometry.getIndexData();
17876
- var idx = enlargeBuffer(baseIndexData, particleCount * 6, inc, maxCount * 6);
17899
+ var idx = enlargeBuffer(baseIndexData, particleCount * 6, maxCount * 6, inc);
17877
17900
  idx.set(indexData, index * 6);
17878
17901
  geometry.setIndexData(idx);
17879
17902
  this.maxParticleBufferCount = idx.length / 6;
@@ -17885,7 +17908,7 @@ var ParticleMesh = /*#__PURE__*/ function() {
17885
17908
  var attrSize = geometry.getAttributeStride(name) / Float32Array.BYTES_PER_ELEMENT;
17886
17909
  if (increaseBuffer) {
17887
17910
  var baseData = geometry.getAttributeData(name);
17888
- var geoData = enlargeBuffer(baseData, vertexCount * attrSize, inc, maxCount * 4 * attrSize);
17911
+ var geoData = enlargeBuffer(baseData, vertexCount * attrSize, maxCount * 4 * attrSize, inc);
17889
17912
  geoData.set(data, data.length * index);
17890
17913
  geometry.setAttributeData(name, geoData);
17891
17914
  } else {
@@ -18539,6 +18562,7 @@ exports.AnimationClip = /*#__PURE__*/ function(EffectsObject) {
18539
18562
  function AnimationClip() {
18540
18563
  var _this;
18541
18564
  _this = EffectsObject.apply(this, arguments) || this;
18565
+ _this.duration = 0;
18542
18566
  _this.positionCurves = [];
18543
18567
  _this.rotationCurves = [];
18544
18568
  _this.scaleCurves = [];
@@ -18583,6 +18607,7 @@ exports.AnimationClip = /*#__PURE__*/ function(EffectsObject) {
18583
18607
  path: positionCurveData.path,
18584
18608
  keyFrames: createValueGetter(positionCurveData.keyFrames)
18585
18609
  };
18610
+ this.duration = Math.max(this.duration, curve.keyFrames.getMaxTime());
18586
18611
  this.positionCurves.push(curve);
18587
18612
  }
18588
18613
  for(var _iterator1 = _create_for_of_iterator_helper_loose(data.rotationCurves), _step1; !(_step1 = _iterator1()).done;){
@@ -18591,6 +18616,7 @@ exports.AnimationClip = /*#__PURE__*/ function(EffectsObject) {
18591
18616
  path: rotationCurveData.path,
18592
18617
  keyFrames: createValueGetter(rotationCurveData.keyFrames)
18593
18618
  };
18619
+ this.duration = Math.max(this.duration, curve1.keyFrames.getMaxTime());
18594
18620
  this.rotationCurves.push(curve1);
18595
18621
  }
18596
18622
  for(var _iterator2 = _create_for_of_iterator_helper_loose(data.scaleCurves), _step2; !(_step2 = _iterator2()).done;){
@@ -18599,6 +18625,7 @@ exports.AnimationClip = /*#__PURE__*/ function(EffectsObject) {
18599
18625
  path: scaleCurvesData.path,
18600
18626
  keyFrames: createValueGetter(scaleCurvesData.keyFrames)
18601
18627
  };
18628
+ this.duration = Math.max(this.duration, curve2.keyFrames.getMaxTime());
18602
18629
  this.scaleCurves.push(curve2);
18603
18630
  }
18604
18631
  for(var _iterator3 = _create_for_of_iterator_helper_loose(data.floatCurves), _step3; !(_step3 = _iterator3()).done;){
@@ -18609,6 +18636,7 @@ exports.AnimationClip = /*#__PURE__*/ function(EffectsObject) {
18609
18636
  property: floatCurveData.property,
18610
18637
  className: floatCurveData.className
18611
18638
  };
18639
+ this.duration = Math.max(this.duration, curve3.keyFrames.getMaxTime());
18612
18640
  this.floatCurves.push(curve3);
18613
18641
  }
18614
18642
  };
@@ -18784,6 +18812,9 @@ var RuntimeClip = /*#__PURE__*/ function() {
18784
18812
  this.playable = clipPlayable;
18785
18813
  this.parentMixer = parentMixer;
18786
18814
  this.track = track;
18815
+ if (_instanceof1(this.track.binding, exports.VFXItem)) {
18816
+ this.particleSystem = this.track.binding.getComponent(exports.ParticleSystem);
18817
+ }
18787
18818
  }
18788
18819
  var _proto = RuntimeClip.prototype;
18789
18820
  _proto.evaluateAt = function evaluateAt(localTime) {
@@ -18793,8 +18824,7 @@ var RuntimeClip = /*#__PURE__*/ function() {
18793
18824
  var started = false;
18794
18825
  var boundItem = this.track.binding;
18795
18826
  if (localTime > clip.start + clip.duration + 0.001 && clip.endBehaviour === ItemEndBehavior.destroy) {
18796
- var _boundItem_getComponent;
18797
- if (exports.VFXItem.isParticle(boundItem) && !((_boundItem_getComponent = boundItem.getComponent(exports.ParticleSystem)) == null ? void 0 : _boundItem_getComponent.destroyed)) {
18827
+ if (exports.VFXItem.isParticle(boundItem) && this.particleSystem && !this.particleSystem.destroyed) {
18798
18828
  weight = 1.0;
18799
18829
  } else {
18800
18830
  weight = 0.0;
@@ -19568,14 +19598,41 @@ exports.TextComponent = /*#__PURE__*/ function(SpriteComponent) {
19568
19598
  return _possible_constructor_return(_this);
19569
19599
  }
19570
19600
  var options = props.options;
19571
- _this.textStyle = new TextStyle(options);
19572
- _this.textLayout = new TextLayout(options);
19573
- _this.text = options.text;
19574
- // Text
19601
+ _this.updateWithOptions(options);
19575
19602
  _this.updateTexture();
19576
19603
  return _this;
19577
19604
  }
19578
19605
  var _proto = TextComponent.prototype;
19606
+ _proto.update = function update(dt) {
19607
+ SpriteComponent.prototype.update.call(this, dt);
19608
+ this.updateTexture();
19609
+ };
19610
+ _proto.fromData = function fromData(data) {
19611
+ SpriteComponent.prototype.fromData.call(this, data);
19612
+ var options = data.options;
19613
+ this.updateWithOptions(options);
19614
+ // Text
19615
+ this.updateTexture();
19616
+ };
19617
+ _proto.updateWithOptions = function updateWithOptions(options) {
19618
+ // OVERRIDE by mixins
19619
+ };
19620
+ _proto.updateTexture = function updateTexture(flipY) {
19621
+ // OVERRIDE by mixins
19622
+ };
19623
+ return TextComponent;
19624
+ }(exports.SpriteComponent);
19625
+ exports.TextComponent = __decorate([
19626
+ effectsClass(DataType.TextComponent)
19627
+ ], exports.TextComponent);
19628
+ var TextComponentBase = /*#__PURE__*/ function() {
19629
+ function TextComponentBase() {}
19630
+ var _proto = TextComponentBase.prototype;
19631
+ _proto.updateWithOptions = function updateWithOptions(options) {
19632
+ this.textStyle = new TextStyle(options);
19633
+ this.textLayout = new TextLayout(options);
19634
+ this.text = options.text;
19635
+ };
19579
19636
  /**
19580
19637
  * 设置字号大小
19581
19638
  * @param value - 字号
@@ -19745,14 +19802,11 @@ exports.TextComponent = /*#__PURE__*/ function(SpriteComponent) {
19745
19802
  this.textStyle.fontScale = value;
19746
19803
  this.isDirty = true;
19747
19804
  };
19748
- _proto.update = function update(dt) {
19749
- SpriteComponent.prototype.update.call(this, dt);
19750
- this.updateTexture();
19751
- };
19752
19805
  /**
19753
19806
  * 更新文本
19754
19807
  * @returns
19755
- */ _proto.updateTexture = function updateTexture() {
19808
+ */ _proto.updateTexture = function updateTexture(flipY) {
19809
+ if (flipY === void 0) flipY = true;
19756
19810
  if (!this.isDirty || !this.context || !this.canvas) {
19757
19811
  return;
19758
19812
  }
@@ -19770,6 +19824,10 @@ exports.TextComponent = /*#__PURE__*/ function(SpriteComponent) {
19770
19824
  context.clearRect(0, 0, width, this.canvas.height);
19771
19825
  // fix bug 1/255
19772
19826
  context.fillStyle = "rgba(255, 255, 255, 0.0039)";
19827
+ if (!flipY) {
19828
+ context.translate(0, height);
19829
+ context.scale(1, -1);
19830
+ }
19773
19831
  context.fillRect(0, 0, width, this.canvas.height);
19774
19832
  style.fontDesc = this.getFontDesc();
19775
19833
  context.font = style.fontDesc;
@@ -19782,7 +19840,7 @@ exports.TextComponent = /*#__PURE__*/ function(SpriteComponent) {
19782
19840
  // 文本颜色
19783
19841
  context.fillStyle = "rgba(" + style.textColor[0] + ", " + style.textColor[1] + ", " + style.textColor[2] + ", " + style.textColor[3] + ")";
19784
19842
  var charsInfo = [];
19785
- // /3 为了和编辑器行为保持一致
19843
+ // /3 是为了和编辑器行为保持一致
19786
19844
  var offsetY = (lineHeight - fontSize) / 3;
19787
19845
  var x = 0;
19788
19846
  var y = layout.getOffsetY(style) + offsetY;
@@ -19836,7 +19894,7 @@ exports.TextComponent = /*#__PURE__*/ function(SpriteComponent) {
19836
19894
  width: imageData.width,
19837
19895
  height: imageData.height
19838
19896
  }, {
19839
- flipY: true,
19897
+ flipY: flipY,
19840
19898
  magFilter: glContext.LINEAR,
19841
19899
  minFilter: glContext.LINEAR,
19842
19900
  wrapS: glContext.CLAMP_TO_EDGE,
@@ -19844,50 +19902,47 @@ exports.TextComponent = /*#__PURE__*/ function(SpriteComponent) {
19844
19902
  }));
19845
19903
  this.isDirty = false;
19846
19904
  };
19847
- _proto.fromData = function fromData(data) {
19848
- SpriteComponent.prototype.fromData.call(this, data);
19849
- var options = data.options;
19850
- this.textStyle = new TextStyle(options);
19851
- this.textLayout = new TextLayout(options);
19852
- this.text = options.text;
19853
- // Text
19854
- this.updateTexture();
19855
- };
19856
19905
  _proto.getFontDesc = function getFontDesc() {
19857
- var textStyle = this.textStyle;
19858
- var fontDesc = "" + (textStyle.fontSize * textStyle.fontScale).toString() + "px ";
19859
- if (!DEFAULT_FONTS.includes(textStyle.fontFamily)) {
19860
- fontDesc += '"' + textStyle.fontFamily + '"';
19906
+ var _this_textStyle = this.textStyle, fontSize = _this_textStyle.fontSize, fontScale = _this_textStyle.fontScale, fontFamily = _this_textStyle.fontFamily, textWeight = _this_textStyle.textWeight, fontStyle = _this_textStyle.fontStyle;
19907
+ var fontDesc = "" + (fontSize * fontScale).toString() + "px ";
19908
+ if (!DEFAULT_FONTS.includes(fontFamily)) {
19909
+ fontDesc += '"' + fontFamily + '"';
19861
19910
  } else {
19862
- fontDesc += textStyle.fontFamily;
19911
+ fontDesc += fontFamily;
19863
19912
  }
19864
- if (textStyle.textWeight !== TextWeight.normal) {
19865
- fontDesc = textStyle.textWeight + " " + fontDesc;
19913
+ if (textWeight !== TextWeight.normal) {
19914
+ fontDesc = textWeight + " " + fontDesc;
19866
19915
  }
19867
- if (textStyle.fontStyle !== FontStyle.normal) {
19868
- fontDesc = textStyle.fontStyle + " " + fontDesc;
19916
+ if (fontStyle !== FontStyle.normal) {
19917
+ fontDesc = fontStyle + " " + fontDesc;
19869
19918
  }
19870
19919
  return fontDesc;
19871
19920
  };
19872
19921
  _proto.setupOutline = function setupOutline() {
19873
19922
  var context = this.context;
19874
- var style = this.textStyle;
19875
- context.strokeStyle = "rgba(" + style.outlineColor[0] * 255 + ", " + style.outlineColor[1] * 255 + ", " + style.outlineColor[2] * 255 + ", " + style.outlineColor[3] + ")";
19876
- context.lineWidth = style.outlineWidth * 2;
19923
+ var _this_textStyle = this.textStyle, outlineColor = _this_textStyle.outlineColor, outlineWidth = _this_textStyle.outlineWidth;
19924
+ var r = outlineColor[0], g = outlineColor[1], b = outlineColor[2], a = outlineColor[3];
19925
+ if (context) {
19926
+ context.strokeStyle = "rgba(" + r * 255 + ", " + g * 255 + ", " + b * 255 + ", " + a + ")";
19927
+ context.lineWidth = outlineWidth * 2;
19928
+ }
19877
19929
  };
19878
19930
  _proto.setupShadow = function setupShadow() {
19879
19931
  var context = this.context;
19880
- var style = this.textStyle;
19881
- context.shadowColor = "rgba(" + style.shadowColor[0] * 255 + ", " + style.shadowColor[1] * 255 + ", " + style.shadowColor[2] * 255 + ", " + style.shadowColor[3] + ")";
19882
- context.shadowBlur = style.shadowBlur;
19883
- context.shadowOffsetX = style.shadowOffsetX;
19884
- context.shadowOffsetY = -style.shadowOffsetY;
19932
+ var _this_textStyle = this.textStyle, outlineColor = _this_textStyle.outlineColor, shadowBlur = _this_textStyle.shadowBlur, shadowOffsetX = _this_textStyle.shadowOffsetX, shadowOffsetY = _this_textStyle.shadowOffsetY;
19933
+ var r = outlineColor[0], g = outlineColor[1], b = outlineColor[2], a = outlineColor[3];
19934
+ if (context) {
19935
+ context.shadowColor = "rgba(" + r * 255 + ", " + g * 255 + ", " + b * 255 + ", " + a + ")";
19936
+ context.shadowBlur = shadowBlur;
19937
+ context.shadowOffsetX = shadowOffsetX;
19938
+ context.shadowOffsetY = -shadowOffsetY;
19939
+ }
19885
19940
  };
19886
- return TextComponent;
19887
- }(exports.SpriteComponent);
19888
- exports.TextComponent = __decorate([
19889
- effectsClass(DataType.TextComponent)
19890
- ], exports.TextComponent);
19941
+ return TextComponentBase;
19942
+ }();
19943
+ applyMixins(exports.TextComponent, [
19944
+ TextComponentBase
19945
+ ]);
19891
19946
 
19892
19947
  // TODO: 注册必须用
19893
19948
  var TextLoader = /*#__PURE__*/ function(AbstractPlugin) {
@@ -20116,8 +20171,8 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20116
20171
  * @param classConstructor - 要添加的组件类型
20117
20172
  */ _proto.addComponent = function addComponent(classConstructor) {
20118
20173
  var newComponent = new classConstructor(this.engine);
20119
- newComponent.item = this;
20120
20174
  this.components.push(newComponent);
20175
+ newComponent.item = this;
20121
20176
  newComponent.onAttached();
20122
20177
  return newComponent;
20123
20178
  };
@@ -20372,6 +20427,7 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20372
20427
  }
20373
20428
  for(var _iterator = _create_for_of_iterator_helper_loose(this.components), _step; !(_step = _iterator()).done;){
20374
20429
  var component = _step.value;
20430
+ component.item = this;
20375
20431
  component.onAttached();
20376
20432
  }
20377
20433
  // renderOrder 在 component 初始化后设置。确保能拿到 rendererComponent。
@@ -23325,12 +23381,13 @@ var seed$1 = 1;
23325
23381
  ];
23326
23382
  case 8:
23327
23383
  _ref1 = _state.sent(), loadedBins = _ref1[0], loadedImages = _ref1[1];
23328
- for(i2 = 0; i2 < images1.length; i2++){
23329
- // FIXME: 2024.05.29 如果 renderer 为空,这里会抛异常
23330
- imageAsset = new ImageAsset(renderer.engine);
23331
- imageAsset.data = loadedImages[i2];
23332
- imageAsset.setInstanceId(images1[i2].id);
23333
- renderer == null ? void 0 : renderer.engine.addInstance(imageAsset);
23384
+ if (renderer) {
23385
+ for(i2 = 0; i2 < images1.length; i2++){
23386
+ imageAsset = new ImageAsset(renderer.engine);
23387
+ imageAsset.data = loadedImages[i2];
23388
+ imageAsset.setInstanceId(images1[i2].id);
23389
+ renderer.engine.addInstance(imageAsset);
23390
+ }
23334
23391
  }
23335
23392
  return [
23336
23393
  4,
@@ -25580,6 +25637,8 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem, true);
25580
25637
  registerPlugin("particle", ParticleLoader, exports.VFXItem, true);
25581
25638
  registerPlugin("cal", CalculateLoader, exports.VFXItem, true);
25582
25639
  registerPlugin("interact", InteractLoader, exports.VFXItem, true);
25640
+ var version$1 = "2.0.0-alpha.19";
25641
+ logger.info("Core version: " + version$1 + ".");
25583
25642
 
25584
25643
  var _obj;
25585
25644
  /**
@@ -27166,7 +27225,7 @@ setMaxSpriteMeshItemCount(8);
27166
27225
  */ Mesh.create = function(engine, props) {
27167
27226
  return new ThreeMesh(engine, props);
27168
27227
  };
27169
- var version = "2.0.0-alpha.18";
27228
+ var version = "2.0.0-alpha.19";
27170
27229
  logger.info("THREEJS plugin version: " + version + ".");
27171
27230
 
27172
27231
  exports.AbstractPlugin = AbstractPlugin;
@@ -27259,6 +27318,7 @@ exports.SpriteLoader = SpriteLoader;
27259
27318
  exports.StaticValue = StaticValue;
27260
27319
  exports.TEMPLATE_USE_OFFSCREEN_CANVAS = TEMPLATE_USE_OFFSCREEN_CANVAS;
27261
27320
  exports.TEXTURE_UNIFORM_MAP = TEXTURE_UNIFORM_MAP;
27321
+ exports.TextComponentBase = TextComponentBase;
27262
27322
  exports.TextLayout = TextLayout;
27263
27323
  exports.TextLoader = TextLoader;
27264
27324
  exports.TextStyle = TextStyle;
@@ -27279,6 +27339,7 @@ exports.ValueGetter = ValueGetter;
27279
27339
  exports.addByOrder = addByOrder;
27280
27340
  exports.addItem = addItem;
27281
27341
  exports.addItemWithOrder = addItemWithOrder;
27342
+ exports.applyMixins = applyMixins;
27282
27343
  exports.assertExist = assertExist;
27283
27344
  exports.asserts = asserts;
27284
27345
  exports.base64ToFile = base64ToFile;