@galacean/effects-threejs 2.1.0-alpha.1 → 2.1.0-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/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.1.0-alpha.1
6
+ * Version: v2.1.0-alpha.2
7
7
  */
8
8
 
9
9
  'use strict';
@@ -8374,7 +8374,7 @@ var seed$9 = 1;
8374
8374
  * 通过 URL 创建 Texture 对象。
8375
8375
  * @param url - 要创建的 Texture URL
8376
8376
  * @since 2.0.0
8377
- */ Texture.fromImage = function fromImage(url, engine) {
8377
+ */ Texture.fromImage = function fromImage(url, engine, options) {
8378
8378
  return _async_to_generator(function() {
8379
8379
  var image, texture;
8380
8380
  return __generator(this, function(_state) {
@@ -8386,12 +8386,13 @@ var seed$9 = 1;
8386
8386
  ];
8387
8387
  case 1:
8388
8388
  image = _state.sent();
8389
- texture = Texture.create(engine, {
8389
+ texture = Texture.create(engine, _extends({
8390
8390
  sourceType: exports.TextureSourceType.image,
8391
8391
  image: image,
8392
+ target: glContext.TEXTURE_2D,
8392
8393
  id: generateGUID(),
8393
8394
  flipY: true
8394
- });
8395
+ }, options));
8395
8396
  texture.initialize();
8396
8397
  return [
8397
8398
  2,
@@ -10323,15 +10324,19 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
10323
10324
  points: points,
10324
10325
  timeInterval: timeInterval,
10325
10326
  valueInterval: valueInterval,
10326
- curve: curve
10327
+ curve: curve,
10328
+ timeStart: Number(s.x),
10329
+ timeEnd: Number(e.x)
10327
10330
  };
10328
10331
  }
10329
10332
  };
10330
10333
  _proto.getValue = function getValue(time) {
10331
10334
  var result = 0;
10332
10335
  var keyTimeData = Object.keys(this.curveMap);
10333
- var keyTimeStart = Number(keyTimeData[0].split("&")[0]);
10334
- var keyTimeEnd = Number(keyTimeData[keyTimeData.length - 1].split("&")[1]);
10336
+ var keyTimeStart = this.curveMap[keyTimeData[0]].timeStart;
10337
+ var keyTimeEnd = this.curveMap[keyTimeData[keyTimeData.length - 1]].timeEnd;
10338
+ // const keyTimeStart = Number(keyTimeData[0].split('&')[0]);
10339
+ // const keyTimeEnd = Number(keyTimeData[keyTimeData.length - 1].split('&')[1]);
10335
10340
  if (time <= keyTimeStart) {
10336
10341
  return this.getCurveValue(keyTimeData[0], keyTimeStart);
10337
10342
  }
@@ -10339,7 +10344,9 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
10339
10344
  return this.getCurveValue(keyTimeData[keyTimeData.length - 1], keyTimeEnd);
10340
10345
  }
10341
10346
  for(var i = 0; i < keyTimeData.length; i++){
10342
- var _keyTimeData_i_split = keyTimeData[i].split("&"), xMin = _keyTimeData_i_split[0], xMax = _keyTimeData_i_split[1];
10347
+ var xMin = this.curveMap[keyTimeData[i]].timeStart;
10348
+ var xMax = this.curveMap[keyTimeData[i]].timeEnd;
10349
+ // const [xMin, xMax] = keyTimeData[i].split('&');
10343
10350
  if (time >= Number(xMin) && time < Number(xMax)) {
10344
10351
  result = this.getCurveValue(keyTimeData[i], time);
10345
10352
  break;
@@ -10352,12 +10359,13 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
10352
10359
  var time = (t1 - t0) / ts;
10353
10360
  var result = 0;
10354
10361
  var keyTimeData = Object.keys(this.curveMap);
10355
- var keyTimeStart = Number(keyTimeData[0].split("&")[0]);
10362
+ var keyTimeStart = this.curveMap[keyTimeData[0]].timeStart;
10356
10363
  if (time <= keyTimeStart) {
10357
10364
  return 0;
10358
10365
  }
10359
10366
  for(var i = 0; i < keyTimeData.length; i++){
10360
- var _keyTimeData_i_split = keyTimeData[i].split("&"), xMin = _keyTimeData_i_split[0], xMax = _keyTimeData_i_split[1];
10367
+ var xMin = this.curveMap[keyTimeData[i]].timeStart;
10368
+ var xMax = this.curveMap[keyTimeData[i]].timeEnd;
10361
10369
  if (time >= Number(xMax)) {
10362
10370
  result += ts * this.getCurveIntegrateValue(keyTimeData[i], Number(xMax));
10363
10371
  }
@@ -17691,6 +17699,12 @@ var particleUniformTypeMap = {
17691
17699
  var ParticleMesh = /*#__PURE__*/ function() {
17692
17700
  function ParticleMesh(engine, props) {
17693
17701
  this.particleCount = 0;
17702
+ this.cachedVelocity = new Vector3();
17703
+ this.cachedRotationVector3 = new Vector3();
17704
+ this.cachedRotationMatrix = new Matrix3();
17705
+ this.cachedLinearMove = new Vector3();
17706
+ this.tempMatrix3 = new Matrix3();
17707
+ this.tempVector3 = new Vector3();
17694
17708
  this.VERT_MAX_KEY_FRAME_COUNT = 0;
17695
17709
  var _engine_renderer;
17696
17710
  var env = ((_engine_renderer = engine.renderer) != null ? _engine_renderer : {}).env;
@@ -18094,39 +18108,40 @@ var ParticleMesh = /*#__PURE__*/ function() {
18094
18108
  // if (!uParams) {
18095
18109
  // return;
18096
18110
  // }
18097
- var localTime = new Float32Array([
18098
- this.time
18099
- ])[0];
18111
+ var localTime = this.time;
18100
18112
  var particleCount = Math.ceil(aPosArray.length / 12);
18101
18113
  // calculate particle translation
18102
18114
  var aTranslationArray = this.geometry.getAttributeData("aTranslation");
18103
18115
  if (aTranslationArray.length < particleCount * 3) {
18104
- aTranslationArray = new Float32Array(particleCount * 3);
18116
+ aTranslationArray = this.expandArray(aTranslationArray, particleCount * 3);
18105
18117
  }
18106
- var velocity = new Vector3(0, 0, 0);
18118
+ var velocity = this.cachedVelocity;
18107
18119
  for(var i = 0; i < particleCount; i++){
18108
18120
  var velOffset = i * 12 + 3;
18109
18121
  velocity.set(aVelArray[velOffset], aVelArray[velOffset + 1], aVelArray[velOffset + 2]);
18110
- var trans = this.calculateTranslation(velocity, aOffsetArray[i * 4 + 2], localTime, aOffsetArray[i * 4 + 3]);
18122
+ this.calculateTranslation(velocity, aOffsetArray[i * 4 + 2], localTime, aOffsetArray[i * 4 + 3]);
18111
18123
  var aTranslationOffset = i * 3;
18112
- aTranslationArray[aTranslationOffset] = trans.x;
18113
- aTranslationArray[aTranslationOffset + 1] = trans.y;
18114
- aTranslationArray[aTranslationOffset + 2] = trans.z;
18124
+ if (aOffsetArray[i * 4 + 2] < localTime) {
18125
+ var translation = velocity.multiply(dt / 1000);
18126
+ aTranslationArray[aTranslationOffset] += translation.x;
18127
+ aTranslationArray[aTranslationOffset + 1] += translation.y;
18128
+ aTranslationArray[aTranslationOffset + 2] += translation.z;
18129
+ }
18115
18130
  }
18116
18131
  this.geometry.setAttributeData("aTranslation", aTranslationArray);
18117
18132
  // calculate particle rotation
18118
18133
  var aRotationArray = this.geometry.getAttributeData("aRotation0");
18119
18134
  if (aRotationArray.length < particleCount * 9) {
18120
- aRotationArray = new Float32Array(particleCount * 9);
18135
+ aRotationArray = this.expandArray(aRotationArray, particleCount * 9);
18121
18136
  }
18122
18137
  for(var i1 = 0; i1 < particleCount; i1++){
18123
18138
  var time = localTime - aOffsetArray[i1 * 4 + 2];
18124
18139
  var duration = aOffsetArray[i1 * 4 + 3];
18125
18140
  var life = clamp$1(time / duration, 0.0, 1.0);
18126
18141
  var aRotOffset = i1 * 8;
18127
- var aRot = new Vector3(aRotArray[aRotOffset], aRotArray[aRotOffset + 1], aRotArray[aRotOffset + 2]);
18142
+ var aRot = this.cachedRotationVector3.set(aRotArray[aRotOffset], aRotArray[aRotOffset + 1], aRotArray[aRotOffset + 2]);
18128
18143
  var aSeed = aSeedArray[i1 * 8 + 3];
18129
- var aRotation = this.transformFromRotation(aRot, life, duration, aSeed);
18144
+ var aRotation = this.transformFromRotation(aRot, life, duration, aSeed, this.cachedRotationMatrix);
18130
18145
  var aRotationOffset = i1 * 9;
18131
18146
  var matrixArray = aRotation.toArray();
18132
18147
  aRotationArray.set(matrixArray, aRotationOffset);
@@ -18135,14 +18150,16 @@ var ParticleMesh = /*#__PURE__*/ function() {
18135
18150
  // calculate linear movement
18136
18151
  var aLinearMoveArray = this.geometry.getAttributeData("aLinearMove");
18137
18152
  if (aLinearMoveArray.length < particleCount * 3) {
18138
- aLinearMoveArray = new Float32Array(particleCount * 3);
18153
+ aLinearMoveArray = this.expandArray(aLinearMoveArray, particleCount * 3);
18139
18154
  }
18155
+ var linearMove = this.cachedLinearMove;
18140
18156
  for(var i2 = 0; i2 < particleCount; i2++){
18141
18157
  var time1 = localTime - aOffsetArray[i2 * 4 + 2];
18142
18158
  var duration1 = aOffsetArray[i2 * 4 + 3];
18143
18159
  // const life = math.clamp(time / duration, 0.0, 1.0);
18144
18160
  var aSeed1 = aSeedArray[i2 * 8 + 3];
18145
- var linearMove = this.calLinearMov(time1, duration1, aSeed1);
18161
+ linearMove.setZero();
18162
+ this.calLinearMov(time1, duration1, aSeed1, linearMove);
18146
18163
  var aLinearMoveOffset = i2 * 3;
18147
18164
  aLinearMoveArray[aLinearMoveOffset] = linearMove.x;
18148
18165
  aLinearMoveArray[aLinearMoveOffset + 1] = linearMove.y;
@@ -18162,29 +18179,23 @@ var ParticleMesh = /*#__PURE__*/ function() {
18162
18179
  var uAcceleration = this.mesh.material.getVector4("uAcceleration");
18163
18180
  var uGravityModifierValue = this.mesh.material.getVector4("uGravityModifierValue");
18164
18181
  if (!uAcceleration || !uGravityModifierValue) {
18165
- return new Vector3();
18182
+ return velocity;
18166
18183
  }
18167
18184
  var dt = t1 - t0; // 相对delay的时间
18168
- var d = this.gravityModifier.getIntegrateByTime(0, dt);
18169
- var acc = [
18170
- uAcceleration.x * d,
18171
- uAcceleration.y * d,
18172
- uAcceleration.z * d
18173
- ];
18174
- // ret.addScaledVector(velData, speedIntegrate);
18175
- // ret.addScaledVector(acc, d);
18185
+ var d = this.gravityModifier.getIntegrateValue(0, dt, duration);
18186
+ var acc = this.tempVector3.set(uAcceleration.x * d, uAcceleration.y * d, uAcceleration.z * d);
18176
18187
  // speedIntegrate = speedOverLifetime.getIntegrateValue(0, time, duration);
18177
18188
  if (this.speedOverLifetime) {
18178
18189
  // dt / dur 归一化
18179
- var speed = this.speedOverLifetime.getIntegrateValue(0, dt, duration);
18180
- return velocity.clone().multiply(speed).add(acc);
18190
+ var speed = this.speedOverLifetime.getValue(dt / duration);
18191
+ return velocity.multiply(speed).add(acc);
18181
18192
  }
18182
- return velocity.clone().multiply(dt).add(acc);
18193
+ return velocity.add(acc);
18183
18194
  };
18184
- _proto.transformFromRotation = function transformFromRotation(rot, life, dur, aSeed) {
18185
- var rotation = rot.clone();
18195
+ _proto.transformFromRotation = function transformFromRotation(rot, life, dur, aSeed, result) {
18196
+ var rotation = rot;
18186
18197
  if (!this.rotationOverLifetime) {
18187
- return new Matrix3();
18198
+ return result.setZero();
18188
18199
  }
18189
18200
  if (this.rotationOverLifetime.asRotation) {
18190
18201
  // Adjust rotation based on the specified lifetime components
@@ -18235,32 +18246,33 @@ var ParticleMesh = /*#__PURE__*/ function() {
18235
18246
  }
18236
18247
  // If the rotation vector is zero, return the identity matrix
18237
18248
  if (rotation.dot(rotation) === 0.0) {
18238
- return new Matrix3().identity();
18249
+ return result.identity();
18239
18250
  }
18240
18251
  // Return the rotation matrix derived from the rotation vector
18241
- return this.mat3FromRotation(rotation);
18252
+ return this.mat3FromRotation(rotation, result);
18242
18253
  };
18243
- _proto.mat3FromRotation = function mat3FromRotation(rotation) {
18254
+ _proto.mat3FromRotation = function mat3FromRotation(rotation, result) {
18244
18255
  var d2r = Math.PI / 180;
18245
- var sinR = rotation.clone().multiply(d2r);
18246
- sinR.x = Math.sin(sinR.x);
18247
- sinR.y = Math.sin(sinR.y);
18248
- sinR.z = Math.sin(sinR.z);
18249
- var cosR = rotation.clone().multiply(d2r);
18250
- cosR.x = Math.cos(cosR.x);
18251
- cosR.y = Math.cos(cosR.y);
18252
- cosR.z = Math.cos(cosR.z);
18253
- var rotZ = new Matrix3(cosR.z, -sinR.z, 0., sinR.z, cosR.z, 0., 0., 0., 1.);
18254
- var rotY = new Matrix3(cosR.y, 0., sinR.y, 0., 1., 0., -sinR.y, 0, cosR.y);
18255
- var rotX = new Matrix3(1., 0., 0., 0, cosR.x, -sinR.x, 0., sinR.x, cosR.x);
18256
- var result = rotZ.multiply(rotY).multiply(rotX);
18256
+ var rotationXD2r = rotation.x * d2r;
18257
+ var rotationYD2r = rotation.y * d2r;
18258
+ var rotationZD2r = rotation.z * d2r;
18259
+ var sinRX = Math.sin(rotationXD2r);
18260
+ var sinRY = Math.sin(rotationYD2r);
18261
+ var sinRZ = Math.sin(rotationZD2r);
18262
+ var cosRX = Math.cos(rotationXD2r);
18263
+ var cosRY = Math.cos(rotationYD2r);
18264
+ var cosRZ = Math.cos(rotationZD2r);
18265
+ // rotZ * rotY * rotX
18266
+ result.set(cosRZ, -sinRZ, 0., sinRZ, cosRZ, 0., 0., 0., 1.); //rotZ
18267
+ result.multiply(this.tempMatrix3.set(cosRY, 0., sinRY, 0., 1., 0., -sinRY, 0, cosRY)); //rotY
18268
+ result.multiply(this.tempMatrix3.set(1., 0., 0., 0, cosRX, -sinRX, 0., sinRX, cosRX)); //rotX
18257
18269
  return result;
18258
18270
  };
18259
- _proto.calLinearMov = function calLinearMov(time, duration, aSeed) {
18260
- var mov = new Vector3();
18271
+ _proto.calLinearMov = function calLinearMov(time, duration, aSeed, result) {
18272
+ var mov = result;
18261
18273
  var lifetime = time / duration;
18262
18274
  if (!this.linearVelOverLifetime || !this.linearVelOverLifetime.enabled) {
18263
- return new Vector3();
18275
+ return mov;
18264
18276
  }
18265
18277
  if (this.linearVelOverLifetime.asMovement) {
18266
18278
  if (this.linearVelOverLifetime.x) {
@@ -18333,7 +18345,8 @@ var ParticleMesh = /*#__PURE__*/ function() {
18333
18345
  var pointData = {
18334
18346
  aPos: new Float32Array(48),
18335
18347
  aRot: new Float32Array(32),
18336
- aOffset: new Float32Array(16)
18348
+ aOffset: new Float32Array(16),
18349
+ aTranslation: new Float32Array(12)
18337
18350
  };
18338
18351
  var useSprite = this.useSprite;
18339
18352
  if (useSprite) {
@@ -18442,6 +18455,11 @@ var ParticleMesh = /*#__PURE__*/ function() {
18442
18455
  geometry.setDrawCount(this.particleCount * 6);
18443
18456
  }
18444
18457
  };
18458
+ _proto.expandArray = function expandArray(array, newSize) {
18459
+ var newArr = new Float32Array(newSize);
18460
+ newArr.set(array);
18461
+ return newArr;
18462
+ };
18445
18463
  return ParticleMesh;
18446
18464
  }();
18447
18465
  var gl2UniformSlots = [
@@ -28092,7 +28110,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem, true);
28092
28110
  registerPlugin("particle", ParticleLoader, exports.VFXItem, true);
28093
28111
  registerPlugin("cal", CalculateLoader, exports.VFXItem, true);
28094
28112
  registerPlugin("interact", InteractLoader, exports.VFXItem, true);
28095
- var version$1 = "2.1.0-alpha.1";
28113
+ var version$1 = "2.1.0-alpha.2";
28096
28114
  logger.info("Core version: " + version$1 + ".");
28097
28115
 
28098
28116
  var _obj;
@@ -29773,7 +29791,7 @@ setMaxSpriteMeshItemCount(8);
29773
29791
  */ Mesh.create = function(engine, props) {
29774
29792
  return new ThreeMesh(engine, props);
29775
29793
  };
29776
- var version = "2.1.0-alpha.1";
29794
+ var version = "2.1.0-alpha.2";
29777
29795
  logger.info("THREEJS plugin version: " + version + ".");
29778
29796
 
29779
29797
  exports.AbstractPlugin = AbstractPlugin;