@galacean/effects-threejs 1.3.1 → 1.4.0-beta.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: v1.3.1
6
+ * Version: v1.4.0-beta.0
7
7
  */
8
8
 
9
9
  'use strict';
@@ -708,7 +708,7 @@ function asserts(condition, msg) {
708
708
  * Name: @galacean/effects-specification
709
709
  * Description: Galacean Effects JSON Specification
710
710
  * Author: Ant Group CO., Ltd.
711
- * Version: v1.1.0
711
+ * Version: v1.2.0-beta.0
712
712
  */
713
713
 
714
714
  /*********************************************/
@@ -7325,6 +7325,448 @@ function trianglesFromRect(position, halfWidth, halfHeight) {
7325
7325
  { p0: p0.clone(), p1: p2.clone(), p2: p3 },
7326
7326
  ];
7327
7327
  }
7328
+ function decimalEqual(a, b, epsilon) {
7329
+ if (epsilon === void 0) { epsilon = 0.000001; }
7330
+ return Math.abs(a - b) < epsilon;
7331
+ }
7332
+ function numberToFix(a, fixed) {
7333
+ if (fixed === void 0) { fixed = 2; }
7334
+ var base = Math.pow(10, fixed);
7335
+ return Math.floor(a * base) / base;
7336
+ }
7337
+ function pointOnLine(x1, y1, x2, y2, x3, y3) {
7338
+ var det1 = (x1 * y2) + (y1 * x3) + (x2 * y3) - (x3 * y2) - (y3 * x1) - (x2 * y1);
7339
+ return det1 > -0.001 && det1 < 0.001;
7340
+ }
7341
+
7342
+ var keyframeInfo = {
7343
+ /**
7344
+ * 根据不同关键帧类型,获取位于曲线上的点
7345
+ */
7346
+ getPointInCurve: function (keyframe) {
7347
+ var _a = __read$3(keyframe, 2); _a[0]; var data = _a[1];
7348
+ var _b = this.getPointIndexInCurve(keyframe), xIndex = _b.xIndex, yIndex = _b.yIndex;
7349
+ var time = data[xIndex];
7350
+ var value = data[yIndex];
7351
+ return new Vector2(time, value);
7352
+ },
7353
+ /**
7354
+ * 根据不同关键帧类型,获取位于曲线上的点的索引
7355
+ */
7356
+ getPointIndexInCurve: function (keyframe) {
7357
+ var _a = __read$3(keyframe, 3), type = _a[0], markType = _a[2];
7358
+ // 不同类型,存放的时间不同
7359
+ var index = type === BezierKeyframeType$1.LINE ? 0
7360
+ : type === BezierKeyframeType$1.EASE_OUT ? 0
7361
+ : type === BezierKeyframeType$1.EASE_IN ? 2
7362
+ : type === BezierKeyframeType$1.EASE ? 2
7363
+ : type === BezierKeyframeType$1.HOLD ? (markType === BezierKeyframeType$1.EASE_IN ? 2 : 0)
7364
+ : 0;
7365
+ return { xIndex: index, yIndex: index + 1 };
7366
+ },
7367
+ /**
7368
+ * 关键帧左侧是否为缓动类型(否则为线段)
7369
+ */
7370
+ isLeftSideEase: function (keyframe) {
7371
+ var _a = __read$3(keyframe, 3), keyframeType = _a[0]; _a[1]; var markType = _a[2];
7372
+ // 定格关键帧的左侧类型,需要借助markType判断
7373
+ if (keyframeType === BezierKeyframeType$1.HOLD && this.isKeyframeTypeLeftSideEase(markType)) {
7374
+ return true;
7375
+ }
7376
+ return this.isKeyframeTypeLeftSideEase(keyframeType);
7377
+ },
7378
+ /**
7379
+ * 关键帧右侧是否为缓动类型(否则为线段)
7380
+ */
7381
+ isRightSideEase: function (keyframe) {
7382
+ var _a = __read$3(keyframe, 3), keyframeType = _a[0]; _a[1]; var markType = _a[2];
7383
+ // 定格关键帧的右侧类型,需要借助markType判断
7384
+ if (keyframeType === BezierKeyframeType$1.HOLD && this.isKeyframeTypeRightSideEase(markType)) {
7385
+ return true;
7386
+ }
7387
+ return this.isKeyframeTypeRightSideEase(keyframeType);
7388
+ },
7389
+ /**
7390
+ * 关键帧左侧是否为缓动类型(否则为线段)
7391
+ */
7392
+ isKeyframeTypeLeftSideEase: function (keyframeType) {
7393
+ return [BezierKeyframeType$1.EASE, BezierKeyframeType$1.EASE_IN, BezierKeyframeType$1.AUTO].includes(keyframeType);
7394
+ },
7395
+ /**
7396
+ * 关键帧右侧是否为缓动类型(否则为线段)
7397
+ */
7398
+ isKeyframeTypeRightSideEase: function (keyframeType) {
7399
+ return [BezierKeyframeType$1.EASE, BezierKeyframeType$1.EASE_OUT, BezierKeyframeType$1.AUTO].includes(keyframeType);
7400
+ },
7401
+ /**
7402
+ * 是否为定格进关键帧
7403
+ */
7404
+ isHoldInKeyframe: function (keyframe) {
7405
+ var _a = __read$3(keyframe, 3), keyframeType = _a[0]; _a[1]; var leftSubType = _a[2];
7406
+ return keyframeType === BezierKeyframeType$1.HOLD && [BezierKeyframeType$1.HOLD, BezierKeyframeType$1.LINE_OUT, BezierKeyframeType$1.EASE_OUT].includes(leftSubType);
7407
+ },
7408
+ /**
7409
+ * 是否为定格出关键帧
7410
+ */
7411
+ isHoldOutKeyframe: function (keyframe) {
7412
+ var _a = __read$3(keyframe, 3), keyframeType = _a[0]; _a[1]; var leftSubType = _a[2];
7413
+ return keyframeType === BezierKeyframeType$1.HOLD && [BezierKeyframeType$1.HOLD, BezierKeyframeType$1.LINE, BezierKeyframeType$1.EASE_IN].includes(leftSubType);
7414
+ },
7415
+ };
7416
+
7417
+ var BezierLengthData = /** @class */ (function () {
7418
+ function BezierLengthData(points, totalLength) {
7419
+ this.points = points;
7420
+ this.totalLength = totalLength;
7421
+ }
7422
+ return BezierLengthData;
7423
+ }());
7424
+ var BezierMap = {};
7425
+ var BezierDataMap = {};
7426
+ var NEWTON_ITERATIONS = 4;
7427
+ var NEWTON_MIN_SLOPE = 0.001;
7428
+ var SUBDIVISION_PRECISION = 0.0000001;
7429
+ var SUBDIVISION_MAX_ITERATIONS = 10;
7430
+ var CURVE_SEGMENTS = 300;
7431
+ var kSplineTableSize = 11;
7432
+ var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
7433
+ function A(a1, a2) { return 1.0 - 3.0 * a2 + 3.0 * a1; }
7434
+ function B(a1, a2) { return 3.0 * a2 - 6.0 * a1; }
7435
+ function C(a1) { return 3.0 * a1; }
7436
+ // A * t ^ 3 + B * t ^ 2 + C * t
7437
+ // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
7438
+ function calcBezier(t, a1, a2) {
7439
+ return ((A(a1, a2) * t + B(a1, a2)) * t + C(a1)) * t;
7440
+ }
7441
+ // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
7442
+ function getSlope(t, a1, a2) {
7443
+ return 3.0 * A(a1, a2) * t * t + 2.0 * B(a1, a2) * t + C(a1);
7444
+ }
7445
+ function binarySubdivide(aX, aA, aB, mX1, mX2) {
7446
+ var currentX, currentT, i = 0;
7447
+ do {
7448
+ currentT = aA + (aB - aA) / 2.0;
7449
+ currentX = calcBezier(currentT, mX1, mX2) - aX;
7450
+ if (currentX > 0.0) {
7451
+ aB = currentT;
7452
+ }
7453
+ else {
7454
+ aA = currentT;
7455
+ }
7456
+ } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
7457
+ return currentT;
7458
+ }
7459
+ function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
7460
+ for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
7461
+ var currentSlope = getSlope(aGuessT, mX1, mX2);
7462
+ if (currentSlope === 0.0) {
7463
+ return aGuessT;
7464
+ }
7465
+ var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
7466
+ aGuessT -= currentX / currentSlope;
7467
+ }
7468
+ return aGuessT;
7469
+ }
7470
+ // de Casteljau算法构建曲线
7471
+ /**
7472
+ * @param p1 起始点
7473
+ * @param p2 终点
7474
+ * @param p3 起始控制点
7475
+ * @param p4 终止控制点
7476
+ * @returns
7477
+ */
7478
+ function buildBezierData(p1, p2, p3, p4) {
7479
+ // 使用平移后的终点、控制点作为key
7480
+ var s1 = numberToFix(p2.x - p1.x, 3) + '_' + numberToFix(p2.y - p1.y, 3) + '_' + numberToFix(p2.z - p1.z, 3);
7481
+ var s2 = numberToFix(p3.x - p1.x, 3) + '_' + numberToFix(p3.y - p1.y, 3) + '_' + numberToFix(p3.z - p1.z, 3);
7482
+ var s3 = numberToFix(p4.x - p1.x, 3) + '_' + numberToFix(p4.y - p1.y, 3) + '_' + numberToFix(p4.z - p1.z, 3);
7483
+ var str = s1 + '&' + s2 + '&' + s3;
7484
+ if (BezierDataMap[str]) {
7485
+ return {
7486
+ data: BezierDataMap[str],
7487
+ interval: p1,
7488
+ };
7489
+ }
7490
+ else {
7491
+ var samples = [];
7492
+ var lastPoint = null, addedLength = 0, ptDistance = 0;
7493
+ var curveSegments = CURVE_SEGMENTS;
7494
+ for (var k = 0; k < curveSegments; k += 1) {
7495
+ var point = new Vector3();
7496
+ var perc = k / (curveSegments - 1);
7497
+ ptDistance = 0;
7498
+ point.x = 3 * Math.pow(1 - perc, 2) * perc * (p3.x - p1.x) + 3 * (1 - perc) * Math.pow(perc, 2) * (p4.x - p1.x) + Math.pow(perc, 3) * (p2.x - p1.x);
7499
+ point.y = 3 * Math.pow(1 - perc, 2) * perc * (p3.y - p1.y) + 3 * (1 - perc) * Math.pow(perc, 2) * (p4.y - p1.y) + Math.pow(perc, 3) * (p2.y - p1.y);
7500
+ point.z = 3 * Math.pow(1 - perc, 2) * perc * (p3.z - p1.z) + 3 * (1 - perc) * Math.pow(perc, 2) * (p4.z - p1.z) + Math.pow(perc, 3) * (p2.z - p1.z);
7501
+ if (lastPoint !== null) {
7502
+ ptDistance += Math.pow(point.x - lastPoint.x, 2);
7503
+ ptDistance += Math.pow(point.y - lastPoint.y, 2);
7504
+ ptDistance += Math.pow(point.z - lastPoint.z, 2);
7505
+ }
7506
+ lastPoint = point;
7507
+ ptDistance = Math.sqrt(ptDistance);
7508
+ addedLength += ptDistance;
7509
+ samples[k] = {
7510
+ partialLength: ptDistance,
7511
+ point: point,
7512
+ };
7513
+ }
7514
+ var data = new BezierLengthData(samples, addedLength);
7515
+ BezierDataMap[str] = data;
7516
+ return {
7517
+ data: data,
7518
+ interval: new Vector3(p1.x, p1.y, p1.z),
7519
+ };
7520
+ }
7521
+ }
7522
+ var BezierPath = /** @class */ (function () {
7523
+ function BezierPath(p1, p2, p3, p4) {
7524
+ this.p1 = p1;
7525
+ this.p2 = p2;
7526
+ this.p3 = p3;
7527
+ this.p4 = p4;
7528
+ this.catching = {
7529
+ lastPoint: 0,
7530
+ lastAddedLength: 0,
7531
+ };
7532
+ var _a = buildBezierData(p1, p2, p3, p4), data = _a.data, interval = _a.interval;
7533
+ this.lengthData = data;
7534
+ this.interval = interval;
7535
+ this.totalLength = data.totalLength;
7536
+ }
7537
+ /**
7538
+ * 获取路径在指定比例长度上点的坐标
7539
+ * @param percent 路径长度的比例
7540
+ */
7541
+ BezierPath.prototype.getPointInPercent = function (percent) {
7542
+ var bezierData = this.lengthData;
7543
+ if (percent === 0) {
7544
+ return bezierData.points[0].point.clone().add(this.interval);
7545
+ }
7546
+ if (decimalEqual(1 - percent, 0)) {
7547
+ return bezierData.points[CURVE_SEGMENTS - 1].point.clone().add(this.interval);
7548
+ }
7549
+ if (decimalEqual(bezierData.totalLength, 0)) {
7550
+ return this.p1.clone();
7551
+ }
7552
+ var point = new Vector3();
7553
+ var segmentLength = numberToFix(bezierData.totalLength * percent, 4);
7554
+ var addedLength = this.catching.lastAddedLength;
7555
+ var j = this.catching.lastPoint;
7556
+ if (decimalEqual(addedLength, segmentLength)) {
7557
+ return bezierData.points[j].point.clone().add(this.interval);
7558
+ }
7559
+ var flag = true;
7560
+ var dir = 1;
7561
+ if (segmentLength < addedLength) {
7562
+ dir = -1;
7563
+ }
7564
+ while (flag) {
7565
+ if (segmentLength >= addedLength) {
7566
+ if (j === CURVE_SEGMENTS - 1) {
7567
+ point.x = bezierData.points[j].point.x;
7568
+ point.y = bezierData.points[j].point.y;
7569
+ point.z = bezierData.points[j].point.z;
7570
+ break;
7571
+ }
7572
+ if (segmentLength < addedLength + bezierData.points[j + 1].partialLength) {
7573
+ var segmentPerc = (segmentLength - addedLength) / bezierData.points[j + 1].partialLength;
7574
+ point.x = bezierData.points[j].point.x + (bezierData.points[j + 1].point.x - bezierData.points[j].point.x) * segmentPerc;
7575
+ point.y = bezierData.points[j].point.y + (bezierData.points[j + 1].point.y - bezierData.points[j].point.y) * segmentPerc;
7576
+ point.z = bezierData.points[j].point.z + (bezierData.points[j + 1].point.z - bezierData.points[j].point.z) * segmentPerc;
7577
+ break;
7578
+ }
7579
+ }
7580
+ if (dir > 0 && j < (CURVE_SEGMENTS - 1)) {
7581
+ j += dir;
7582
+ addedLength += numberToFix(bezierData.points[j].partialLength, 5);
7583
+ }
7584
+ else if (dir < 0 && j > 0) {
7585
+ addedLength -= numberToFix(bezierData.points[j].partialLength, 5);
7586
+ j += dir;
7587
+ }
7588
+ else {
7589
+ flag = false;
7590
+ }
7591
+ }
7592
+ this.catching.lastPoint = j;
7593
+ this.catching.lastAddedLength = addedLength;
7594
+ point.add(this.interval);
7595
+ return point;
7596
+ };
7597
+ return BezierPath;
7598
+ }());
7599
+ var BezierEasing = /** @class */ (function () {
7600
+ function BezierEasing(mX1, mY1, mX2, mY2) {
7601
+ this.mX1 = mX1;
7602
+ this.mY1 = mY1;
7603
+ this.mX2 = mX2;
7604
+ this.mY2 = mY2;
7605
+ this.precomputed = false;
7606
+ this.mSampleValues = new Array(kSplineTableSize);
7607
+ this.cachingValue = {};
7608
+ }
7609
+ BezierEasing.prototype.precompute = function () {
7610
+ this.precomputed = true;
7611
+ if (this.mX1 !== this.mY1 || this.mX2 !== this.mY2) {
7612
+ this.calcSampleValues();
7613
+ }
7614
+ };
7615
+ BezierEasing.prototype.getValue = function (x) {
7616
+ if (this.mX1 === this.mY1 && this.mX2 === this.mY2) {
7617
+ return x;
7618
+ }
7619
+ if (isNaN(this.mY1) || isNaN(this.mY2)) {
7620
+ return 0;
7621
+ }
7622
+ if (x === 0 || x === 1) {
7623
+ return x;
7624
+ }
7625
+ if (!this.precomputed) {
7626
+ this.precompute();
7627
+ }
7628
+ var keys = Object.keys(this.cachingValue);
7629
+ var index = keys.findIndex(function (key) { return decimalEqual(Number(key), x, 0.005); });
7630
+ if (index !== -1) {
7631
+ return this.cachingValue[keys[index]];
7632
+ }
7633
+ var value = calcBezier(this.getTForX(x), this.mY1, this.mY2);
7634
+ if (keys.length < 300) {
7635
+ this.cachingValue[x] = value;
7636
+ }
7637
+ return value;
7638
+ };
7639
+ BezierEasing.prototype.calcSampleValues = function () {
7640
+ for (var i = 0; i < kSplineTableSize; ++i) {
7641
+ this.mSampleValues[i] = calcBezier(i * kSampleStepSize, this.mX1, this.mX2);
7642
+ }
7643
+ };
7644
+ BezierEasing.prototype.getTForX = function (aX) {
7645
+ var mSampleValues = this.mSampleValues, lastSample = kSplineTableSize - 1;
7646
+ var intervalStart = 0, currentSample = 1;
7647
+ for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
7648
+ intervalStart += kSampleStepSize;
7649
+ }
7650
+ --currentSample;
7651
+ // Interpolate to provide an initial guess for t
7652
+ var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]);
7653
+ var guessForT = intervalStart + dist * kSampleStepSize;
7654
+ var initialSlope = getSlope(guessForT, this.mX1, this.mX2);
7655
+ if (initialSlope >= NEWTON_MIN_SLOPE) {
7656
+ return newtonRaphsonIterate(aX, guessForT, this.mX1, this.mX2);
7657
+ }
7658
+ if (initialSlope === 0.0) {
7659
+ return guessForT;
7660
+ }
7661
+ return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, this.mX1, this.mX2);
7662
+ };
7663
+ return BezierEasing;
7664
+ }());
7665
+ function buildEasingCurve(leftKeyframe, rightKeyframe) {
7666
+ // 获取控制点和曲线类型
7667
+ var _a = getControlPoints(leftKeyframe, rightKeyframe, true), p0 = _a.p0, p1 = _a.p1, p2 = _a.p2, p3 = _a.p3;
7668
+ assertExist(p2);
7669
+ assertExist(p3);
7670
+ var timeInterval = p3.x - p0.x;
7671
+ var valueInterval = p3.y - p0.y;
7672
+ var y1, y2;
7673
+ var x1 = numberToFix((p1.x - p0.x) / timeInterval, 5);
7674
+ var x2 = numberToFix((p2.x - p0.x) / timeInterval, 5);
7675
+ if (decimalEqual(valueInterval, 0)) {
7676
+ y1 = y2 = NaN;
7677
+ }
7678
+ else {
7679
+ y1 = numberToFix((p1.y - p0.y) / valueInterval, 5);
7680
+ y2 = numberToFix((p2.y - p0.y) / valueInterval, 5);
7681
+ }
7682
+ if (x1 < 0) {
7683
+ console.error('invalid bezier points, x1 < 0', p0, p1, p2, p3);
7684
+ x1 = 0;
7685
+ }
7686
+ if (x2 < 0) {
7687
+ console.error('invalid bezier points, x2 < 0', p0, p1, p2, p3);
7688
+ x2 = 0;
7689
+ }
7690
+ if (x1 > 1) {
7691
+ console.error('invalid bezier points, x1 >= 1', p0, p1, p2, p3);
7692
+ x1 = 1;
7693
+ }
7694
+ if (x2 > 1) {
7695
+ console.error('invalid bezier points, x2 >= 1', p0, p1, p2, p3);
7696
+ x2 = 1;
7697
+ }
7698
+ var str = ('bez_' + x1 + '_' + y1 + '_' + x2 + '_' + y2).replace(/\./g, 'p');
7699
+ var bezEasing;
7700
+ if (BezierMap[str]) {
7701
+ bezEasing = BezierMap[str];
7702
+ }
7703
+ else {
7704
+ bezEasing = new BezierEasing(x1, y1, x2, y2);
7705
+ BezierMap[str] = bezEasing;
7706
+ }
7707
+ return {
7708
+ points: [p0, p1, p2, p3],
7709
+ timeInterval: timeInterval,
7710
+ valueInterval: valueInterval,
7711
+ curve: bezEasing,
7712
+ };
7713
+ }
7714
+ /**
7715
+ * 根据关键帧类型获取贝塞尔曲线上的关键点
7716
+ */
7717
+ function getControlPoints(leftKeyframe, rightKeyframe, lineToBezier) {
7718
+ var _a = __read$3(leftKeyframe, 2), leftValue = _a[1];
7719
+ var leftHoldLine = keyframeInfo.isHoldOutKeyframe(leftKeyframe);
7720
+ var rightHoldLine = keyframeInfo.isHoldInKeyframe(rightKeyframe);
7721
+ var leftEase = !rightHoldLine && keyframeInfo.isRightSideEase(leftKeyframe);
7722
+ var rightEase = !leftHoldLine && keyframeInfo.isLeftSideEase(rightKeyframe);
7723
+ // 1. 左边为ease,右边为line(补充右边的控制点,该点在曲线上的点的偏左边位置)
7724
+ if (leftEase && !rightEase && !rightHoldLine) {
7725
+ var p0_1 = new Vector2(leftValue[leftValue.length - 4], leftValue[leftValue.length - 3]);
7726
+ var p1_1 = new Vector2(leftValue[leftValue.length - 2], leftValue[leftValue.length - 1]);
7727
+ var rightPoint = keyframeInfo.getPointInCurve(rightKeyframe);
7728
+ var p3 = new Vector2(rightPoint.x, rightPoint.y);
7729
+ var p2 = new Vector2(p3.x - (p3.x - p0_1.x) / 10, p3.y);
7730
+ return { type: 'ease', p0: p0_1, p1: p1_1, p2: p2, p3: p3 };
7731
+ }
7732
+ // 2. 左边为line,右边为ease(补充左边的控制点,该点在曲线上的点的偏右边位置)
7733
+ if (!leftEase && rightEase && !leftHoldLine) {
7734
+ var _b = __read$3(rightKeyframe, 2), rightValue = _b[1];
7735
+ var leftPoint = keyframeInfo.getPointInCurve(leftKeyframe);
7736
+ var p0_2 = new Vector2(leftPoint.x, leftPoint.y);
7737
+ var p2 = new Vector2(rightValue[0], rightValue[1]);
7738
+ var p3 = new Vector2(rightValue[2], rightValue[3]);
7739
+ var p1_2 = new Vector2(p0_2.x + (p3.x - p0_2.x) / 10, p0_2.y);
7740
+ return { type: 'ease', p0: p0_2, p1: p1_2, p2: p2, p3: p3 };
7741
+ }
7742
+ // 3. 左边为ease,右边为ease
7743
+ if (leftEase && rightEase) {
7744
+ var _c = __read$3(rightKeyframe, 2), rightValue = _c[1];
7745
+ var p0_3 = new Vector2(leftValue[leftValue.length - 4], leftValue[leftValue.length - 3]);
7746
+ var p1_3 = new Vector2(leftValue[leftValue.length - 2], leftValue[leftValue.length - 1]);
7747
+ var p2 = new Vector2(rightValue[0], rightValue[1]);
7748
+ var p3 = new Vector2(rightValue[2], rightValue[3]);
7749
+ return { type: 'ease', p0: p0_3, p1: p1_3, p2: p2, p3: p3 };
7750
+ }
7751
+ // 4. 左边为line,右边为line
7752
+ var p0 = keyframeInfo.getPointInCurve(leftKeyframe);
7753
+ var p1 = keyframeInfo.getPointInCurve(rightKeyframe);
7754
+ if (leftHoldLine) {
7755
+ p1.y = p0.y; // 定格关键帧使用相同的点
7756
+ }
7757
+ else if (rightHoldLine) {
7758
+ p0.y = p1.y;
7759
+ }
7760
+ if (lineToBezier) {
7761
+ // 补上两个在直线上的控制点
7762
+ var p2 = new Vector2((p1.x - p0.x) / 3 + p0.x, (p1.y - p0.y) / 3 + p0.y);
7763
+ var p3 = new Vector2((p1.x - p0.x) / 3 * 2 + p0.x, (p1.y - p0.y) / 3 * 2 + p0.y);
7764
+ return { type: 'ease', p0: p0, p1: p2, p2: p3, p3: p1, isHold: leftHoldLine || rightHoldLine, leftHoldLine: leftHoldLine, rightHoldLine: rightHoldLine };
7765
+ }
7766
+ else {
7767
+ return { type: 'line', p0: p0, p1: p1, isHold: leftHoldLine || rightHoldLine, leftHoldLine: leftHoldLine, rightHoldLine: rightHoldLine };
7768
+ }
7769
+ }
7328
7770
 
7329
7771
  var _a$5;
7330
7772
  var NOT_IMPLEMENT = 'not_implement';
@@ -7332,6 +7774,15 @@ var ValueGetter = /** @class */ (function () {
7332
7774
  function ValueGetter(arg) {
7333
7775
  this.onCreate(arg);
7334
7776
  }
7777
+ ValueGetter.getAllData = function (meta, halfFloat) {
7778
+ var ret = new (halfFloat ? Float16ArrayWrapper : Float32Array)(meta.index * 4);
7779
+ for (var i = 0, cursor = 0, curves = meta.curves; i < curves.length; i++) {
7780
+ var data = curves[i].toData();
7781
+ ret.set(data, cursor);
7782
+ cursor += data.length;
7783
+ }
7784
+ return halfFloat ? ret.data : ret;
7785
+ };
7335
7786
  ValueGetter.prototype.onCreate = function (props) {
7336
7787
  throw Error(NOT_IMPLEMENT);
7337
7788
  };
@@ -7353,6 +7804,9 @@ var ValueGetter = /** @class */ (function () {
7353
7804
  ValueGetter.prototype.scaleXCoord = function (scale) {
7354
7805
  return this;
7355
7806
  };
7807
+ ValueGetter.prototype.toData = function () {
7808
+ throw Error(NOT_IMPLEMENT);
7809
+ };
7356
7810
  return ValueGetter;
7357
7811
  }());
7358
7812
  var StaticValue = /** @class */ (function (_super) {
@@ -7515,153 +7969,6 @@ var GradientValue = /** @class */ (function (_super) {
7515
7969
  };
7516
7970
  return GradientValue;
7517
7971
  }(ValueGetter));
7518
- var CURVE_PRO_TIME = 0;
7519
- var CURVE_PRO_VALUE = 1;
7520
- var CURVE_PRO_IN_TANGENT = 2;
7521
- var CURVE_PRO_OUT_TANGENT = 3;
7522
- var CurveValue = /** @class */ (function (_super) {
7523
- __extends(CurveValue, _super);
7524
- function CurveValue() {
7525
- return _super !== null && _super.apply(this, arguments) || this;
7526
- }
7527
- CurveValue.getAllData = function (meta, halfFloat) {
7528
- var ret = new (halfFloat ? Float16ArrayWrapper : Float32Array)(meta.index * 4);
7529
- for (var i = 0, cursor = 0, curves = meta.curves; i < curves.length; i++) {
7530
- var data = curves[i].toData();
7531
- ret.set(data, cursor);
7532
- cursor += data.length;
7533
- }
7534
- return halfFloat ? ret.data : ret;
7535
- };
7536
- CurveValue.prototype.onCreate = function (props) {
7537
- var min = Infinity;
7538
- var max = -Infinity;
7539
- //formatted number
7540
- if (Number.isFinite(props[0]) && Number.isFinite(props[1])) {
7541
- var keys = [];
7542
- for (var i = 2; i < props.length; i++) {
7543
- // FIXME
7544
- keys.push(props[i].slice(0, 4));
7545
- }
7546
- this.keys = keys;
7547
- this.min = props[0];
7548
- this.dist = props[1] - props[0];
7549
- }
7550
- else {
7551
- var keys = props.map(function (item) {
7552
- if (isArray(item)) {
7553
- min = Math.min(min, item[1]);
7554
- max = Math.max(max, item[1]);
7555
- return item.slice(0, 4);
7556
- }
7557
- else if (typeof item === 'object' && item) {
7558
- var _a = item, time = _a.time, value = _a.value, _b = _a.inTangent, inTangent = _b === void 0 ? 0 : _b, _c = _a.outTangent, outTangent = _c === void 0 ? 0 : _c;
7559
- min = Math.min(min, value);
7560
- max = Math.max(max, value);
7561
- return [time, value, inTangent, outTangent];
7562
- }
7563
- throw new Error('invalid keyframe');
7564
- });
7565
- var dist = max - min;
7566
- this.keys = keys;
7567
- if (dist !== 0) {
7568
- for (var i = 0; i < keys.length; i++) {
7569
- var key = keys[i];
7570
- key[1] = (key[1] - min) / dist;
7571
- }
7572
- }
7573
- var key0 = keys[0];
7574
- if (key0[0] > 0) {
7575
- key0[2] = 0;
7576
- keys.unshift([0, key0[1], 0, 0]);
7577
- }
7578
- var key1 = keys[keys.length - 1];
7579
- if (key1[0] < 1) {
7580
- key1[3] = 0;
7581
- keys.push([1, key1[1], 0, 0]);
7582
- }
7583
- this.min = min;
7584
- this.dist = dist;
7585
- }
7586
- this.isCurveValue = true;
7587
- };
7588
- CurveValue.prototype.getValue = function (time) {
7589
- var _a = this, keys = _a.keys, min = _a.min, dist = _a.dist;
7590
- var keysNumerArray = keys;
7591
- if (time <= keysNumerArray[0][CURVE_PRO_TIME]) {
7592
- return keysNumerArray[0][CURVE_PRO_VALUE] * dist + min;
7593
- }
7594
- var end = keysNumerArray.length - 1;
7595
- for (var i = 0; i < end; i++) {
7596
- var key = keysNumerArray[i];
7597
- var k2 = keysNumerArray[i + 1];
7598
- if (time > key[CURVE_PRO_TIME] && time <= k2[CURVE_PRO_TIME]) {
7599
- return curveValueEvaluate(time, key, k2) * dist + min;
7600
- }
7601
- }
7602
- return keysNumerArray[end][CURVE_PRO_VALUE] * dist + min;
7603
- };
7604
- CurveValue.prototype.getIntegrateByTime = function (t0, t1) {
7605
- var d = this.integrate(t1, true) - this.integrate(t0, true);
7606
- return this.min * 0.5 * (t1 - t0) * (t1 - t0) + d * this.dist;
7607
- };
7608
- CurveValue.prototype.getIntegrateValue = function (t0, t1, ts) {
7609
- ts = ts || 1;
7610
- var d = (this.integrate(t1 / ts, false) - this.integrate(t0 / ts, false)) * ts;
7611
- var dt = (t1 - t0) / ts;
7612
- return this.min * dt + d * this.dist;
7613
- };
7614
- CurveValue.prototype.integrate = function (time, byTime) {
7615
- var keys = this.keys;
7616
- if (time <= keys[0][CURVE_PRO_TIME]) {
7617
- return 0;
7618
- }
7619
- var ret = 0;
7620
- var end = keys.length - 1;
7621
- var func = byTime ? curveValueIntegrateByTime : curveValueIntegrate;
7622
- for (var i = 0; i < end; i++) {
7623
- var key = keys[i];
7624
- var k2 = keys[i + 1];
7625
- var t1 = key[CURVE_PRO_TIME];
7626
- var t2 = k2[CURVE_PRO_TIME];
7627
- if (time > t1 && time <= t2) {
7628
- return ret + func(time, key, k2);
7629
- }
7630
- else {
7631
- ret += func(t2, key, k2);
7632
- }
7633
- }
7634
- return ret;
7635
- };
7636
- CurveValue.prototype.toData = function () {
7637
- var keys = this.keys;
7638
- var data = new Float32Array(keys.length * 4);
7639
- for (var i = 0, cursor = 0; i < keys.length; i++, cursor += 4) {
7640
- data.set(keys[i], cursor);
7641
- }
7642
- return data;
7643
- };
7644
- CurveValue.prototype.toUniform = function (meta) {
7645
- var index = meta.index;
7646
- var keys = this.keys;
7647
- meta.curves.push(this);
7648
- meta.index += keys.length;
7649
- meta.max = Math.max(meta.max, keys.length);
7650
- meta.curveCount += keys.length;
7651
- return new Float32Array([2, index + 1 / keys.length, this.min, this.dist]);
7652
- };
7653
- CurveValue.prototype.map = function (func) {
7654
- this.keys.forEach(function (k) {
7655
- k[CURVE_PRO_VALUE] = func(k[CURVE_PRO_VALUE]);
7656
- });
7657
- return this;
7658
- };
7659
- CurveValue.prototype.scaleXCoord = function (scale) {
7660
- this.keys.forEach(function (k) { return k[CURVE_PRO_TIME] = scale * k[CURVE_PRO_TIME]; });
7661
- return this;
7662
- };
7663
- return CurveValue;
7664
- }(ValueGetter));
7665
7972
  var LineSegments = /** @class */ (function (_super) {
7666
7973
  __extends(LineSegments, _super);
7667
7974
  function LineSegments() {
@@ -7763,77 +8070,247 @@ var LineSegments = /** @class */ (function (_super) {
7763
8070
  };
7764
8071
  return LineSegments;
7765
8072
  }(ValueGetter));
7766
- var PathSegments = /** @class */ (function (_super) {
7767
- __extends(PathSegments, _super);
7768
- function PathSegments() {
8073
+ // export class PathSegments extends ValueGetter<number[]> {
8074
+ // keys: number[][];
8075
+ // values: number[][];
8076
+ //
8077
+ // override onCreate (props: number[][][]) {
8078
+ // this.keys = props[0];
8079
+ // this.values = props[1];
8080
+ // }
8081
+ //
8082
+ // override getValue (time: number) {
8083
+ // const keys = this.keys;
8084
+ // const values = this.values;
8085
+ //
8086
+ // for (let i = 0; i < keys.length - 1; i++) {
8087
+ // const k0 = keys[i];
8088
+ // const k1 = keys[i + 1];
8089
+ //
8090
+ // if (k0[0] <= time && k1[0] >= time) {
8091
+ // const dis = k1[1] - k0[1];
8092
+ // let dt;
8093
+ //
8094
+ // if (dis === 0) {
8095
+ // dt = (time - k0[0]) / (k1[0] - k0[0]);
8096
+ // } else {
8097
+ // const val = curveValueEvaluate(time, k0, k1);
8098
+ //
8099
+ // dt = (val - k0[1]) / dis;
8100
+ // }
8101
+ //
8102
+ // return this.calculateVec(i, dt);
8103
+ // }
8104
+ // }
8105
+ // if (time <= keys[0][0]) {
8106
+ // return values[0].slice();
8107
+ // }
8108
+ //
8109
+ // return values[values.length - 1].slice();
8110
+ // }
8111
+ //
8112
+ // calculateVec (i: number, dt: number) {
8113
+ // const vec0 = this.values[i];
8114
+ // const vec1 = this.values[i + 1];
8115
+ // const ret = [0, 0, 0];
8116
+ //
8117
+ // for (let j = 0; j < vec0.length; j++) {
8118
+ // ret[j] = vec0[j] * (1 - dt) + vec1[j] * dt;
8119
+ // }
8120
+ //
8121
+ // return ret;
8122
+ // }
8123
+ // }
8124
+ var BezierCurve = /** @class */ (function (_super) {
8125
+ __extends(BezierCurve, _super);
8126
+ function BezierCurve() {
7769
8127
  return _super !== null && _super.apply(this, arguments) || this;
7770
8128
  }
7771
- PathSegments.prototype.onCreate = function (props) {
7772
- this.keys = props[0];
7773
- this.values = props[1];
8129
+ BezierCurve.prototype.onCreate = function (props) {
8130
+ var keyframes = props;
8131
+ this.curveMap = {};
8132
+ this.keys = [];
8133
+ for (var i = 0; i < keyframes.length - 1; i++) {
8134
+ var leftKeyframe = keyframes[i];
8135
+ var rightKeyframe = keyframes[i + 1];
8136
+ var _a = buildEasingCurve(leftKeyframe, rightKeyframe), points = _a.points, curve = _a.curve, timeInterval = _a.timeInterval, valueInterval = _a.valueInterval;
8137
+ var s = points[0];
8138
+ var e = points[points.length - 1];
8139
+ this.keys.push(__spreadArray$2(__spreadArray$2([], __read$3(s.toArray()), false), __read$3(points[1].toArray()), false));
8140
+ this.keys.push(__spreadArray$2(__spreadArray$2([], __read$3(e.toArray()), false), __read$3(points[2].toArray()), false));
8141
+ this.curveMap["".concat(s.x, "&").concat(e.x)] = {
8142
+ points: points,
8143
+ timeInterval: timeInterval,
8144
+ valueInterval: valueInterval,
8145
+ curve: curve,
8146
+ };
8147
+ }
7774
8148
  };
7775
- PathSegments.prototype.getValue = function (time) {
7776
- var keys = this.keys;
7777
- var values = this.values;
7778
- for (var i = 0; i < keys.length - 1; i++) {
7779
- var k0 = keys[i];
7780
- var k1 = keys[i + 1];
7781
- if (k0[0] <= time && k1[0] >= time) {
7782
- var dis = k1[1] - k0[1];
7783
- var dt = void 0;
7784
- if (dis === 0) {
7785
- dt = (time - k0[0]) / (k1[0] - k0[0]);
7786
- }
7787
- else {
7788
- var val = curveValueEvaluate(time, k0, k1);
7789
- dt = (val - k0[1]) / dis;
7790
- }
7791
- return this.calculateVec(i, dt);
8149
+ BezierCurve.prototype.getValue = function (time) {
8150
+ var result = 0;
8151
+ var keyTimeData = Object.keys(this.curveMap);
8152
+ var keyTimeStart = Number(keyTimeData[0].split('&')[0]);
8153
+ var keyTimeEnd = Number(keyTimeData[keyTimeData.length - 1].split('&')[1]);
8154
+ if (time <= keyTimeStart) {
8155
+ return this.getCurveValue(keyTimeData[0], keyTimeStart);
8156
+ }
8157
+ if (time >= keyTimeEnd) {
8158
+ return this.getCurveValue(keyTimeData[keyTimeData.length - 1], keyTimeEnd);
8159
+ }
8160
+ for (var i = 0; i < keyTimeData.length; i++) {
8161
+ var _a = __read$3(keyTimeData[i].split('&'), 2), xMin = _a[0], xMax = _a[1];
8162
+ if (time >= Number(xMin) && time < Number(xMax)) {
8163
+ result = this.getCurveValue(keyTimeData[i], time);
8164
+ break;
7792
8165
  }
7793
8166
  }
7794
- if (time <= keys[0][0]) {
7795
- return values[0].slice();
8167
+ return result;
8168
+ };
8169
+ BezierCurve.prototype.getIntegrateValue = function (t0, t1, ts) {
8170
+ if (ts === void 0) { ts = 1; }
8171
+ var time = (t1 - t0);
8172
+ var result = 0;
8173
+ var keyTimeData = Object.keys(this.curveMap);
8174
+ var keyTimeStart = Number(keyTimeData[0].split('&')[0]);
8175
+ if (time <= keyTimeStart) {
8176
+ return 0;
8177
+ }
8178
+ for (var i = 0; i < keyTimeData.length; i++) {
8179
+ var _a = __read$3(keyTimeData[i].split('&'), 2), xMin = _a[0], xMax = _a[1];
8180
+ if (time >= Number(xMax)) {
8181
+ result += ts * this.getCurveIntegrateValue(keyTimeData[i], Number(xMax));
8182
+ }
8183
+ if (time >= Number(xMin) && time < Number(xMax)) {
8184
+ result += ts * this.getCurveIntegrateValue(keyTimeData[i], time);
8185
+ break;
8186
+ }
8187
+ }
8188
+ return result;
8189
+ };
8190
+ // 速度变化曲线面板移除后下线
8191
+ BezierCurve.prototype.getCurveIntegrateValue = function (curveKey, time) {
8192
+ var curveInfo = this.curveMap[curveKey];
8193
+ var _a = __read$3(curveInfo.points, 1), p0 = _a[0];
8194
+ var timeInterval = curveInfo.timeInterval;
8195
+ var valueInterval = curveInfo.valueInterval;
8196
+ var segments = 100;
8197
+ var total = 0;
8198
+ var h = (time - p0.x) / segments;
8199
+ for (var i = 0; i <= segments; i++) {
8200
+ var t = i * h;
8201
+ var normalizeTime = t / timeInterval;
8202
+ var y = p0.y + valueInterval * curveInfo.curve.getValue(normalizeTime);
8203
+ if (i === 0 || i === segments) {
8204
+ total += y;
8205
+ }
8206
+ else if (i % 2 === 1) {
8207
+ total += 4 * y;
8208
+ }
8209
+ else {
8210
+ total += 2 * y;
8211
+ }
7796
8212
  }
7797
- return values[values.length - 1].slice();
8213
+ total *= h / 3;
8214
+ return total;
8215
+ };
8216
+ BezierCurve.prototype.getCurveValue = function (curveKey, time) {
8217
+ var curveInfo = this.curveMap[curveKey];
8218
+ var _a = __read$3(curveInfo.points, 1), p0 = _a[0];
8219
+ var timeInterval = curveInfo.timeInterval;
8220
+ var valueInterval = curveInfo.valueInterval;
8221
+ var normalizeTime = (time - p0.x) / timeInterval;
8222
+ var value = curveInfo.curve.getValue(normalizeTime);
8223
+ return p0.y + valueInterval * value;
8224
+ };
8225
+ BezierCurve.prototype.toUniform = function (meta) {
8226
+ var index = meta.index;
8227
+ var count = this.keys.length;
8228
+ meta.curves.push(this);
8229
+ meta.index = index + count;
8230
+ // 兼容 WebGL1
8231
+ meta.max = Math.max(meta.max, count);
8232
+ meta.curveCount += count;
8233
+ return new Float32Array([5, index + 1 / count, index, count]);
7798
8234
  };
7799
- PathSegments.prototype.calculateVec = function (i, dt) {
7800
- var vec0 = this.values[i];
7801
- var vec1 = this.values[i + 1];
7802
- var ret = [0, 0, 0];
7803
- for (var j = 0; j < vec0.length; j++) {
7804
- ret[j] = vec0[j] * (1 - dt) + vec1[j] * dt;
8235
+ BezierCurve.prototype.toData = function () {
8236
+ var keys = this.keys;
8237
+ var data = new Float32Array(keys.length * 4);
8238
+ for (var i = 0, cursor = 0; i < keys.length; i++, cursor += 4) {
8239
+ data.set(keys[i], cursor);
7805
8240
  }
7806
- return ret;
8241
+ return data;
7807
8242
  };
7808
- return PathSegments;
8243
+ return BezierCurve;
7809
8244
  }(ValueGetter));
7810
- var BezierSegments = /** @class */ (function (_super) {
7811
- __extends(BezierSegments, _super);
7812
- function BezierSegments() {
8245
+ var BezierCurvePath = /** @class */ (function (_super) {
8246
+ __extends(BezierCurvePath, _super);
8247
+ function BezierCurvePath() {
7813
8248
  return _super !== null && _super.apply(this, arguments) || this;
7814
8249
  }
7815
- BezierSegments.prototype.onCreate = function (props) {
7816
- _super.prototype.onCreate.call(this, props);
7817
- this.cps = props[2];
7818
- };
7819
- BezierSegments.prototype.calculateVec = function (i, t) {
7820
- var vec0 = this.values[i];
7821
- var vec1 = this.values[i + 1];
7822
- var outCp = this.cps[i + i];
7823
- var inCp = this.cps[i + i + 1];
7824
- var ret = [0, 0, 0];
7825
- var ddt = 1 - t;
7826
- var a = ddt * ddt * ddt;
7827
- var b = 3 * t * ddt * ddt;
7828
- var c = 3 * t * t * ddt;
7829
- var d = t * t * t;
7830
- for (var j = 0; j < vec0.length; j++) {
7831
- ret[j] = a * vec0[j] + b * outCp[j] + c * inCp[j] + d * vec1[j];
8250
+ BezierCurvePath.prototype.onCreate = function (props) {
8251
+ var _a = __read$3(props, 3), keyframes = _a[0], points = _a[1], controlPoints = _a[2];
8252
+ this.curveSegments = {};
8253
+ if (!controlPoints.length) {
8254
+ return;
8255
+ }
8256
+ for (var i = 0; i < keyframes.length - 1; i++) {
8257
+ var leftKeyframe = keyframes[i];
8258
+ var rightKeyframe = keyframes[i + 1];
8259
+ var ps1 = new Vector3(points[i][0], points[i][1], points[i][2]), ps2 = new Vector3(points[i + 1][0], points[i + 1][1], points[i + 1][2]);
8260
+ var cp1 = new Vector3(controlPoints[2 * i][0], controlPoints[2 * i][1], controlPoints[2 * i][2]), cp2 = new Vector3(controlPoints[2 * i + 1][0], controlPoints[2 * i + 1][1], controlPoints[2 * i + 1][2]);
8261
+ var _b = buildEasingCurve(leftKeyframe, rightKeyframe), ps = _b.points, easingCurve = _b.curve, timeInterval = _b.timeInterval, valueInterval = _b.valueInterval;
8262
+ var s = ps[0];
8263
+ var e = ps[ps.length - 1];
8264
+ var pathCurve = new BezierPath(ps1, ps2, cp1, cp2);
8265
+ this.curveSegments["".concat(s.x, "&").concat(e.x)] = {
8266
+ points: ps,
8267
+ timeInterval: timeInterval,
8268
+ valueInterval: valueInterval,
8269
+ easingCurve: easingCurve,
8270
+ pathCurve: pathCurve,
8271
+ };
7832
8272
  }
7833
- return ret;
7834
8273
  };
7835
- return BezierSegments;
7836
- }(PathSegments));
8274
+ BezierCurvePath.prototype.getValue = function (time) {
8275
+ var t = numberToFix(time, 5);
8276
+ var perc = 0, point = new Vector3();
8277
+ var keyTimeData = Object.keys(this.curveSegments);
8278
+ if (!keyTimeData.length) {
8279
+ return point;
8280
+ }
8281
+ var keyTimeStart = Number(keyTimeData[0].split('&')[0]);
8282
+ var keyTimeEnd = Number(keyTimeData[keyTimeData.length - 1].split('&')[1]);
8283
+ if (t <= keyTimeStart) {
8284
+ var pathCurve = this.curveSegments[keyTimeData[0]].pathCurve;
8285
+ point = pathCurve.getPointInPercent(0);
8286
+ return point;
8287
+ }
8288
+ if (t >= keyTimeEnd) {
8289
+ var pathCurve = this.curveSegments[keyTimeData[keyTimeData.length - 1]].pathCurve;
8290
+ point = pathCurve.getPointInPercent(1);
8291
+ return point;
8292
+ }
8293
+ for (var i = 0; i < keyTimeData.length; i++) {
8294
+ var _a = __read$3(keyTimeData[i].split('&'), 2), xMin = _a[0], xMax = _a[1];
8295
+ if (t >= Number(xMin) && t < Number(xMax)) {
8296
+ var bezierPath = this.curveSegments[keyTimeData[i]].pathCurve;
8297
+ perc = this.getPercValue(keyTimeData[i], t);
8298
+ point = bezierPath.getPointInPercent(perc);
8299
+ }
8300
+ }
8301
+ return point;
8302
+ };
8303
+ BezierCurvePath.prototype.getPercValue = function (curveKey, time) {
8304
+ var curveInfo = this.curveSegments[curveKey];
8305
+ var _a = __read$3(curveInfo.points, 1), p0 = _a[0];
8306
+ var timeInterval = curveInfo.timeInterval;
8307
+ var normalizeTime = numberToFix((time - p0.x) / timeInterval, 4);
8308
+ var value = curveInfo.easingCurve.getValue(normalizeTime);
8309
+ // TODO 测试用 编辑器限制值域后移除clamp
8310
+ return clamp$1(value, 0, 1);
8311
+ };
8312
+ return BezierCurvePath;
8313
+ }(ValueGetter));
7837
8314
  var map$1 = (_a$5 = {},
7838
8315
  _a$5[ValueType$1.RANDOM] = function (props) {
7839
8316
  if (props[0] instanceof Array) {
@@ -7853,9 +8330,6 @@ var map$1 = (_a$5 = {},
7853
8330
  _a$5[ValueType$1.CONSTANT_VEC4] = function (props) {
7854
8331
  return new StaticValue(props);
7855
8332
  },
7856
- _a$5[ValueType$1.CURVE] = function (props) {
7857
- return new CurveValue(props);
7858
- },
7859
8333
  _a$5[ValueType$1.RGBA_COLOR] = function (props) {
7860
8334
  return new StaticValue(props);
7861
8335
  },
@@ -7871,11 +8345,20 @@ var map$1 = (_a$5 = {},
7871
8345
  _a$5[ValueType$1.GRADIENT_COLOR] = function (props) {
7872
8346
  return new GradientValue(props);
7873
8347
  },
7874
- _a$5[ValueType$1.LINEAR_PATH] = function (pros) {
7875
- return new PathSegments(pros);
8348
+ // [spec.ValueType.LINEAR_PATH] (pros: number[][][]) {
8349
+ // return new PathSegments(pros);
8350
+ // },
8351
+ _a$5[ValueType$1.BEZIER_CURVE] = function (props) {
8352
+ if (props.length === 1) {
8353
+ return new StaticValue(props[0][1][1]);
8354
+ }
8355
+ return new BezierCurve(props);
7876
8356
  },
7877
- _a$5[ValueType$1.BEZIER_PATH] = function (pros) {
7878
- return new BezierSegments(pros);
8357
+ _a$5[ValueType$1.BEZIER_CURVE_PATH] = function (props) {
8358
+ if (props[0].length === 1) {
8359
+ return new StaticValue(new Vector3(props[0][0][1][1], props[1][0][1][1], props[2][0][1][1]));
8360
+ }
8361
+ return new BezierCurvePath(props);
7879
8362
  },
7880
8363
  _a$5);
7881
8364
  function createValueGetter(args) {
@@ -7903,53 +8386,6 @@ function lineSegIntegrateByTime(t, t0, t1, y0, y1) {
7903
8386
  var t03 = t02 * t0;
7904
8387
  return (2 * t3 * (y0 - y1) + 3 * t2 * (t0 * y1 - t1 * y0) - t03 * (2 * y0 + y1) + 3 * t02 * t1 * y0) / (6 * (t0 - t1));
7905
8388
  }
7906
- function curveValueEvaluate(time, keyframe0, keyframe1) {
7907
- var dt = keyframe1[CURVE_PRO_TIME] - keyframe0[CURVE_PRO_TIME];
7908
- var m0 = keyframe0[CURVE_PRO_OUT_TANGENT] * dt;
7909
- var m1 = keyframe1[CURVE_PRO_IN_TANGENT] * dt;
7910
- var t = (time - keyframe0[CURVE_PRO_TIME]) / dt;
7911
- var t2 = t * t;
7912
- var t3 = t2 * t;
7913
- var a = 2 * t3 - 3 * t2 + 1;
7914
- var b = t3 - 2 * t2 + t;
7915
- var c = t3 - t2;
7916
- var d = -2 * t3 + 3 * t2;
7917
- //(2*v0+m0+m1-2*v1)*(t-t0)^3/k^3+(3*v1-3*v0-2*m0-m1)*(t-t0)^2/k^2+m0 *(t-t0)/k+v0
7918
- return a * keyframe0[CURVE_PRO_VALUE] + b * m0 + c * m1 + d * keyframe1[CURVE_PRO_VALUE];
7919
- }
7920
- function curveValueIntegrate(time, keyframe0, keyframe1) {
7921
- var k = keyframe1[CURVE_PRO_TIME] - keyframe0[CURVE_PRO_TIME];
7922
- var m0 = keyframe0[CURVE_PRO_OUT_TANGENT] * k;
7923
- var m1 = keyframe1[CURVE_PRO_IN_TANGENT] * k;
7924
- var t0 = keyframe0[CURVE_PRO_TIME];
7925
- var v0 = keyframe0[CURVE_PRO_VALUE];
7926
- var v1 = keyframe1[CURVE_PRO_VALUE];
7927
- var dt = t0 - time;
7928
- var dt2 = dt * dt;
7929
- var dt3 = dt2 * dt;
7930
- return (m0 + m1 + 2 * v0 - 2 * v1) * dt3 * dt / (4 * k * k * k) +
7931
- (2 * m0 + m1 + 3 * v0 - 3 * v1) * dt3 / (3 * k * k) +
7932
- m0 * dt2 / 2 / k - v0 * dt;
7933
- }
7934
- function curveValueIntegrateByTime(t1, keyframe0, keyframe1) {
7935
- var k = keyframe1[CURVE_PRO_TIME] - keyframe0[CURVE_PRO_TIME];
7936
- var m0 = keyframe0[CURVE_PRO_OUT_TANGENT] * k;
7937
- var m1 = keyframe1[CURVE_PRO_IN_TANGENT] * k;
7938
- var t0 = keyframe0[CURVE_PRO_TIME];
7939
- var v0 = keyframe0[CURVE_PRO_VALUE];
7940
- var v1 = keyframe1[CURVE_PRO_VALUE];
7941
- var dt = t0 - t1;
7942
- var dt2 = dt * dt;
7943
- var dt3 = dt2 * dt;
7944
- var k2 = k * k;
7945
- var k3 = k2 * k;
7946
- //(30 k^3 v0 (t1^2 - t0^2) + 10 k^2 m0 (t0 + 2 t1) (t0 - t1)^2 + 5 k (t0 + 3 t1) (t0 - t1)^3 (2 m0 + m1 + 3 v0 - 3 v1) + 3 (t0 + 4 t1) (t0 - t1)^4 (m0 + m1 + 2 v0 - 2 v1))/(60 k^3)
7947
- var ret = -30 * k3 * v0 * (t0 + t1) * dt +
7948
- 10 * k2 * m0 * (t0 + 2 * t1) * dt2 +
7949
- 5 * k * (t0 + 3 * t1) * (2 * m0 + m1 + 3 * v0 - 3 * v1) * dt3 +
7950
- 3 * (t0 + 4 * t1) * (m0 + m1 + 2 * v0 - 2 * v1) * dt3 * dt;
7951
- return ret / 60 / k3;
7952
- }
7953
8389
  function getKeyFrameMetaByRawValue(meta, value) {
7954
8390
  if (value) {
7955
8391
  var type = value[0];
@@ -7984,6 +8420,13 @@ function getKeyFrameMetaByRawValue(meta, value) {
7984
8420
  meta.index += uniformCount;
7985
8421
  meta.max = Math.max(meta.max, uniformCount);
7986
8422
  }
8423
+ else if (type === ValueType$1.BEZIER_CURVE) {
8424
+ var keyLen = keys.length - 1;
8425
+ meta.index += 2 * keyLen;
8426
+ meta.curves.push(keys);
8427
+ meta.max = Math.max(meta.max, 2 * keyLen);
8428
+ meta.curveCount += 2 * keyLen;
8429
+ }
7987
8430
  }
7988
8431
  }
7989
8432
  function createKeyFrameMeta() {
@@ -11714,21 +12157,19 @@ var compatible_vert = "#version 300 es\n#ifdef WEBGL2\n#define texture2D texture
11714
12157
 
11715
12158
  var itemFrameFrag = "#version 300 es\nprecision highp float;\n#version 300 es\n#ifdef WEBGL2\n#define texture2D texture\n#define textureCube texture\n#define textureCubeLodEXT textureLod\nlayout(location=0)out vec4 fragColor;\n#else\n#define fragColor gl_FragColor\n#endif\nvec4 blendColor(vec4 color,vec4 vc,float mode){vec4 ret=color*vc;\n#ifdef PRE_MULTIPLY_ALPHA\nfloat alpha=vc.a;\n#else\nfloat alpha=ret.a;\n#endif\nif(mode==1.){ret.rgb*=alpha;}else if(mode==2.){ret.rgb*=alpha;ret.a=dot(ret.rgb,vec3(0.33333333));}else if(mode==3.){alpha=color.r*alpha;ret=vec4(vc.rgb*alpha,alpha);}return ret;}in vec4 vColor;in vec4 vTexCoord;in highp vec2 vParams;uniform vec3 uFrameColor;void main(){fragColor=vec4(uFrameColor.xyz,1.0);}";
11716
12159
 
11717
- var integrate = "float integrateCurveFrames(float t1,vec4 k0,vec4 k1){float k=k1.x-k0.x;float m0=k0.w*k;float m1=k1.z*k;float t0=k0.x;float v0=k0.y;float v1=k1.y;float dt=t0-t1;float dt2=dt*dt;float dt3=dt2*dt;vec4 a=vec4(dt3*dt,dt3,dt2,dt)/vec4(4.*k*k*k,3.*k*k,2.*k,1.);vec4 b=vec4(m0+m1+2.*v0-2.*v1,2.*m0+m1+3.*v0-3.*v1,m0,-v0);return dot(a,b);}float integrateByTimeCurveFrames(float t1,vec4 k0,vec4 k1){float k=k1.x-k0.x;float m0=k0.w*k;float m1=k1.z*k;float t0=k0.x;float v0=k0.y;float v1=k1.y;float dt=t0-t1;float dt2=dt*dt;float dt3=dt2*dt;float k2=k*k;float k3=k2*k;vec4 a=vec4(-30.*k3,10.*k2,5.*k,3.)*vec4(dt,dt2,dt3,dt3*dt);vec4 b=vec4(v0,m0,2.*m0+m1+3.*v0-3.*v1,m0+m1+2.*v0-2.*v1)*vec4(t0+t1,t0+2.*t1,t0+3.*t1,t0+4.*t1);return dot(a,b)/60./k3;}float integrateByTimeFromCurveFrames(float t1,float frameStart,float frameCount){if(t1==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i==count){return ret;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(t1>k0.x&&t1<=k1.x){return ret+integrateByTimeCurveFrames(t1,k0,k1);}ret+=integrateByTimeCurveFrames(k1.x,k0,k1);}return ret;}float integrateFromCurveFrames(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i==count){return ret;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(time>k0.x&&time<=k1.x){return ret+integrateCurveFrames(time,k0,k1);}ret+=integrateCurveFrames(k1.x,k0,k1);}return ret;}float integrateByTimeLineSeg(float t,vec2 p0,vec2 p1){float t0=p0.x;float t1=p1.x;float y0=p0.y;float y1=p1.y;vec4 tSqr=vec4(t,t,t0,t0);tSqr=tSqr*tSqr;vec4 a=vec4(2.*t,3.,-t0,3.)*tSqr;float t1y0=t1*y0;vec4 b=vec4(y0-y1,t0*y1-t1y0,2.*y0+y1,t1y0);float r=dot(a,b);return r/(t0-t1)*0.16666667;}float integrateLineSeg(float time,vec2 p0,vec2 p1){float h=time-p0.x;float y0=p0.y;return(y0+y0+(p1.y-y0)*h/(p1.x-p0.x))*h/2.;}float integrateFromLineSeg(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i>count){return ret;}vec4 ks=lookup_curve(i+start);vec2 k0=ks.xy;vec2 k1=ks.zw;if(time>k0.x&&time<=k1.x){return ret+integrateLineSeg(time,k0,k1);}ret+=integrateLineSeg(k1.x,k0,k1);vec2 k2=lookup_curve(i+start+1).xy;if(time>k1.x&&time<=k2.x){return ret+integrateLineSeg(time,k1,k2);}ret+=integrateLineSeg(k2.x,k1,k2);}return ret;}float integrateByTimeFromLineSeg(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i>count){return ret;}vec4 ks=lookup_curve(i+start);vec2 k0=ks.xy;vec2 k1=ks.zw;if(time>k0.x&&time<=k1.x){return ret+integrateByTimeLineSeg(time,k0,k1);}ret+=integrateByTimeLineSeg(k1.x,k0,k1);vec2 k2=lookup_curve(i+start+1).xy;if(time>k1.x&&time<=k2.x){return ret+integrateByTimeLineSeg(time,k1,k2);}ret+=integrateByTimeLineSeg(k2.x,k1,k2);}return ret;}float getIntegrateFromTime0(float t1,vec4 value){float type=value.x;if(type==0.){return value.y*t1;}else if(type==1.){vec2 p0=vec2(0.,value.y);vec2 p1=vec2(value.w,value.z);return integrateLineSeg(t1,p0,p1);}if(type==3.){return integrateFromLineSeg(t1,value.y,value.z);}if(type==2.){float idx=floor(value.y);float ilen=floor(1./fract(value.y)+0.5);float d=integrateFromCurveFrames(t1,idx,ilen);return d*value.w+value.z*t1;}if(type==4.){return mix(value.y,value.z,aSeed)*t1;}return 0.;}float getIntegrateByTimeFromTime(float t0,float t1,vec4 value){float type=value.x;if(type==0.){return value.y*(t1*t1-t0*t0)/2.;}else if(type==1.){vec2 p0=vec2(0.,value.y);vec2 p1=vec2(value.w,value.z);return integrateByTimeLineSeg(t1,p0,p1)-integrateByTimeLineSeg(t0,p0,p1);}if(type==2.){float idx=floor(value.y);float ilen=floor(1./fract(value.y)+0.5);float d=integrateByTimeFromCurveFrames(t1,idx,ilen)-integrateByTimeFromCurveFrames(t0,idx,ilen);return d*value.w+value.z*pow(t1-t0,2.)*0.5;}if(type==3.){return integrateByTimeFromLineSeg(t1,value.y,value.z)-integrateByTimeFromLineSeg(t0,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed)*(t1*t1-t0*t0)/2.;}return 0.;}";
12160
+ var integrate = "float calculateMovement(float t,vec2 p1,vec2 p2,vec2 p3,vec2 p4){float movement=0.0;float h=(t-p1.x)*0.1;float delta=1./(p4.x-p1.x);for(int i=0;i<=10;i++){float t=float(i)*h*delta;float nt=binarySearchT(t,p1.x,p2.x,p3.x,p4.x);float y=cubicBezier(nt,p1.y,p2.y,p3.y,p4.y);float weight=(i==0||i==10)? 1.0 :(mod(float(i),2.)!=0.)? 4.0 : 2.0;movement+=weight*y;}movement*=h/3.;return movement;}float integrateFromBezierCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i+=2){vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(i==0&&time<k0.x){return ret;}vec2 p1=vec2(k0.x,k0.y);vec2 p2=vec2(k0.z,k0.w);vec2 p3=vec2(k1.z,k1.w);vec2 p4=vec2(k1.x,k1.y);if(time>=k1.x){ret+=calculateMovement(k1.x,p1,p2,p3,p4);}if(time>=k0.x&&time<k1.x){return ret+calculateMovement(time,p1,p2,p3,p4);}}return ret;}float integrateByTimeLineSeg(float t,vec2 p0,vec2 p1){float t0=p0.x;float t1=p1.x;float y0=p0.y;float y1=p1.y;vec4 tSqr=vec4(t,t,t0,t0);tSqr=tSqr*tSqr;vec4 a=vec4(2.*t,3.,-t0,3.)*tSqr;float t1y0=t1*y0;vec4 b=vec4(y0-y1,t0*y1-t1y0,2.*y0+y1,t1y0);float r=dot(a,b);return r/(t0-t1)*0.16666667;}float integrateLineSeg(float time,vec2 p0,vec2 p1){float h=time-p0.x;float y0=p0.y;return(y0+y0+(p1.y-y0)*h/(p1.x-p0.x))*h/2.;}float integrateFromLineSeg(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i>count){return ret;}vec4 ks=lookup_curve(i+start);vec2 k0=ks.xy;vec2 k1=ks.zw;if(time>k0.x&&time<=k1.x){return ret+integrateLineSeg(time,k0,k1);}ret+=integrateLineSeg(k1.x,k0,k1);vec2 k2=lookup_curve(i+start+1).xy;if(time>k1.x&&time<=k2.x){return ret+integrateLineSeg(time,k1,k2);}ret+=integrateLineSeg(k2.x,k1,k2);}return ret;}float integrateByTimeFromLineSeg(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i>count){return ret;}vec4 ks=lookup_curve(i+start);vec2 k0=ks.xy;vec2 k1=ks.zw;if(time>k0.x&&time<=k1.x){return ret+integrateByTimeLineSeg(time,k0,k1);}ret+=integrateByTimeLineSeg(k1.x,k0,k1);vec2 k2=lookup_curve(i+start+1).xy;if(time>k1.x&&time<=k2.x){return ret+integrateByTimeLineSeg(time,k1,k2);}ret+=integrateByTimeLineSeg(k2.x,k1,k2);}return ret;}float getIntegrateFromTime0(float t1,vec4 value){float type=value.x;if(type==0.){return value.y*t1;}else if(type==1.){vec2 p0=vec2(0.,value.y);vec2 p1=vec2(value.w,value.z);return integrateLineSeg(t1,p0,p1);}if(type==3.){return integrateFromLineSeg(t1,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed)*t1;}if(type==5.){return integrateFromBezierCurveFrames(t1,value.z,value.w);}return 0.;}float getIntegrateByTimeFromTime(float t0,float t1,vec4 value){float type=value.x;if(type==0.){return value.y*(t1*t1-t0*t0)/2.;}else if(type==1.){vec2 p0=vec2(0.,value.y);vec2 p1=vec2(value.w,value.z);return integrateByTimeLineSeg(t1,p0,p1)-integrateByTimeLineSeg(t0,p0,p1);}if(type==3.){return integrateByTimeFromLineSeg(t1,value.y,value.z)-integrateByTimeFromLineSeg(t0,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed)*(t1*t1-t0*t0)/2.;}if(type==5.){return integrateFromBezierCurveFrames(t1,value.z,value.w)-integrateFromBezierCurveFrames(t0,value.z,value.w);}return 0.;}";
11718
12161
 
11719
12162
  var itemVert = "#version 300 es\nprecision highp float;\n#define SHADER_VERTEX 1\n#define SPRITE_SHADER 1\nin vec4 aPoint;in vec2 aIndex;uniform mat4 uMainData[MAX_ITEM_COUNT];uniform vec4 uTexParams[MAX_ITEM_COUNT];uniform vec4 uTexOffset[MAX_ITEM_COUNT];uniform mat4 effects_ObjectToWorld;uniform mat4 effects_MatrixInvV;uniform mat4 effects_MatrixVP;out vec4 vColor;out vec4 vTexCoord;\n#ifdef ADJUST_LAYER\nout vec2 vFeatherCoord;\n#endif\nout highp vec3 vParams;const float d2r=3.141592653589793/180.;\n#ifdef ENV_EDITOR\nuniform vec4 uEditorTransform;\n#endif\nvec4 filterMain(float t,vec4 position);\n#pragma FILTER_VERT\nvec3 rotateByQuat(vec3 a,vec4 quat){vec3 qvec=quat.xyz;vec3 uv=cross(qvec,a);vec3 uuv=cross(qvec,uv)*2.;return a+(uv*2.*quat.w+uuv);}void main(){int index=int(aIndex.x);vec4 texParams=uTexParams[index];mat4 mainData=uMainData[index];float life=mainData[1].z;if(life<0.||life>1.){gl_Position=vec4(3.,3.,3.,1.);}else{vec4 _pos=mainData[0];vec2 size=mainData[1].xy;vec3 point=rotateByQuat(vec3(aPoint.xy*size,0.),mainData[2]);vec4 pos=vec4(_pos.xyz,1.0);float renderMode=texParams.z;if(renderMode==0.){pos=effects_ObjectToWorld*pos;pos.xyz+=effects_MatrixInvV[0].xyz*point.x+effects_MatrixInvV[1].xyz*point.y;}else if(renderMode==1.){pos.xyz+=point;pos=effects_ObjectToWorld*pos;}else if(renderMode==2.){pos=effects_ObjectToWorld*pos;pos.xy+=point.xy;}else if(renderMode==3.){pos=effects_ObjectToWorld*pos;pos.xyz+=effects_MatrixInvV[0].xyz*point.x+effects_MatrixInvV[2].xyz*point.y;}gl_Position=effects_MatrixVP*pos;\n#ifdef ADJUST_LAYER\nvec4 filter_Position=filterMain(life,pos);\n#endif\ngl_PointSize=6.0;\n#ifdef ENV_EDITOR\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#ifdef ADJUST_LAYER\nfilter_Position=vec4(filter_Position.xy*uEditorTransform.xy+uEditorTransform.zw*filter_Position.w,filter_Position.zw);\n#endif\n#endif\n#ifdef ADJUST_LAYER\nvTexCoord=vec4(filter_Position.xy/filter_Position.w+1.,gl_Position.xy/gl_Position.w+1.)/2.;vFeatherCoord=aPoint.zw;\n#else\nvec4 texOffset=uTexOffset[index];vTexCoord=vec4(aPoint.zw*texOffset.zw+texOffset.xy,texParams.xy);\n#endif\nvColor=mainData[3];vParams=vec3(aIndex.y,texParams.y,texParams.x);}}";
11720
12163
 
11721
- var item_define = "uniform mat4 uMainData[MAX_ITEM_COUNT];uniform vec4 uTexParams[MAX_ITEM_COUNT];uniform vec4 uTexOffset[MAX_ITEM_COUNT];";
11722
-
11723
12164
  var itemFrag = "#version 300 es\nprecision highp float;\n#version 300 es\n#ifdef WEBGL2\n#define texture2D texture\n#define textureCube texture\n#define textureCubeLodEXT textureLod\nlayout(location=0)out vec4 fragColor;\n#else\n#define fragColor gl_FragColor\n#endif\nvec4 blendColor(vec4 color,vec4 vc,float mode){vec4 ret=color*vc;\n#ifdef PRE_MULTIPLY_ALPHA\nfloat alpha=vc.a;\n#else\nfloat alpha=ret.a;\n#endif\nif(mode==1.){ret.rgb*=alpha;}else if(mode==2.){ret.rgb*=alpha;ret.a=dot(ret.rgb,vec3(0.33333333));}else if(mode==3.){alpha=color.r*alpha;ret=vec4(vc.rgb*alpha,alpha);}return ret;}\n#define SPRITE_SHADER 1\nin vec4 vColor;in vec4 vTexCoord;in highp vec3 vParams;\n#ifdef ADJUST_LAYER\nuniform sampler2D uSamplerPre;vec4 filterMain(vec2 coord,sampler2D tex);in vec2 vFeatherCoord;uniform sampler2D uFeatherSampler;\n#endif\nuniform sampler2D uSampler0;uniform sampler2D uSampler1;uniform sampler2D uSampler2;uniform sampler2D uSampler3;uniform sampler2D uSampler4;uniform sampler2D uSampler5;uniform sampler2D uSampler6;uniform sampler2D uSampler7;\n#if MAX_FRAG_TEX == 16\nuniform sampler2D uSampler8;uniform sampler2D uSampler9;uniform sampler2D uSampler10;uniform sampler2D uSampler11;uniform sampler2D uSampler12;uniform sampler2D uSampler13;uniform sampler2D uSampler14;uniform sampler2D uSampler15;\n#endif\nvec4 texture2DbyIndex(float index,vec2 coord);\n#pragma FILTER_FRAG\n#ifndef WEBGL2\n#define round(a) floor(0.5+a)\n#endif\nvoid main(){vec4 color=vec4(0.);\n#ifdef ADJUST_LAYER\nvec2 featherCoord=abs(vFeatherCoord-vec2(0.5))/0.5;float cc=sqrt(max(featherCoord.x,featherCoord.y));float blend=vColor.a*texture2D(uFeatherSampler,vec2(cc,0.)).r;if(blend>=1.){color=filterMain(vTexCoord.xy,uSamplerPre);}else if(blend<=0.){color=texture2D(uSamplerPre,vTexCoord.zw);}else{color=mix(texture2D(uSamplerPre,vTexCoord.zw),filterMain(vTexCoord.xy,uSamplerPre),blend);}\n#else\nvec4 texColor=texture2DbyIndex(round(vParams.x),vTexCoord.xy);color=blendColor(texColor,vColor,round(vParams.y));if(vParams.z==0.&&color.a<0.04){discard;}\n#endif\ncolor.a=clamp(color.a,0.0,1.0);fragColor=color;}vec4 texture2DbyIndex(float index,vec2 coord){\n#ifndef ADJUST_LAYER\nif(index==0.){return texture2D(uSampler0,coord);}if(index==1.){return texture2D(uSampler1,coord);}if(index==2.){return texture2D(uSampler2,coord);}if(index==3.){return texture2D(uSampler3,coord);}if(index==4.){return texture2D(uSampler4,coord);}if(index==5.){return texture2D(uSampler5,coord);}if(index==6.){return texture2D(uSampler6,coord);}if(index==7.){return texture2D(uSampler7,coord);}\n#if MAX_FRAG_TEX == 16\nif(index==8.){return texture2D(uSampler8,coord);}if(index==9.){return texture2D(uSampler9,coord);}if(index==10.){return texture2D(uSampler10,coord);}if(index==11.){return texture2D(uSampler11,coord);}if(index==12.){return texture2D(uSampler12,coord);}if(index==13.){return texture2D(uSampler13,coord);}if(index==14.){return texture2D(uSampler14,coord);}if(index==15.){return texture2D(uSampler15,coord);}\n#endif\nreturn texture2D(uSampler0,coord);\n#else\nreturn vec4(0.);\n#endif\n}";
11724
12165
 
11725
- var particleFrag = "#version 300 es\nprecision mediump float;\n#version 300 es\n#ifdef WEBGL2\n#define texture2D texture\n#define textureCube texture\n#define textureCubeLodEXT textureLod\nlayout(location=0)out vec4 fragColor;\n#else\n#define fragColor gl_FragColor\n#endif\nvec4 blendColor(vec4 color,vec4 vc,float mode){vec4 ret=color*vc;\n#ifdef PRE_MULTIPLY_ALPHA\nfloat alpha=vc.a;\n#else\nfloat alpha=ret.a;\n#endif\nif(mode==1.){ret.rgb*=alpha;}else if(mode==2.){ret.rgb*=alpha;ret.a=dot(ret.rgb,vec3(0.33333333));}else if(mode==3.){alpha=color.r*alpha;ret=vec4(vc.rgb*alpha,alpha);}return ret;}\n#define PATICLE_SHADER 1\nin float vLife;in vec2 vTexCoord;in vec4 vColor;uniform vec3 emissionColor;uniform float emissionIntensity;uniform sampler2D uMaskTex;uniform vec4 uColorParams;uniform vec2 uTexOffset;\n#ifdef COLOR_OVER_LIFETIME\nuniform sampler2D uColorOverLifetime;\n#endif\n#ifdef USE_SPRITE\nin vec4 vTexCoordBlend;\n#ifdef USE_FILTER\nuniform vec4 uFSprite;\n#endif\n#endif\nin float vSeed;\n#ifdef PREVIEW_BORDER\nuniform vec4 uPreviewColor;\n#endif\n#ifdef USE_SPRITE\nvec4 getTextureColor(sampler2D tex,vec2 texCoord){if(vTexCoordBlend.w>0.){return mix(texture2D(tex,texCoord),texture2D(tex,vTexCoordBlend.xy+texCoord),vTexCoordBlend.z);}return texture2D(tex,texCoord);}\n#else\n#define getTextureColor texture2D\n#endif\n#ifndef WEBGL2\n#define round(a) floor(0.5+a)\n#endif\n#ifdef PREVIEW_BORDER\nvoid main(){fragColor=uPreviewColor;}\n#else\n#pragma FILTER_FRAG\nvoid main(){vec4 color=vec4(1.0);vec4 tempColor=vColor;vec2 texOffset=uTexOffset;if(vLife<0.){discard;}\n#ifdef USE_FILTER\n#ifdef USE_SPRITE\ntexOffset=uTexOffset/uFSprite.xy;\n#endif\ncolor=filterMain(vTexCoord,uMaskTex);\n#else\nif(uColorParams.x>0.0){color=getTextureColor(uMaskTex,vTexCoord);}\n#endif\n#ifdef COLOR_OVER_LIFETIME\n#ifndef ENABLE_VERTEX_TEXTURE\ntempColor*=texture2D(uColorOverLifetime,vec2(vLife,0.));\n#endif\n#endif\ncolor=blendColor(color,tempColor,round(uColorParams.y));if(color.a<=0.01&&uColorParams.w>0.){float _at=texture2D(uMaskTex,vTexCoord+texOffset).a+texture2D(uMaskTex,vTexCoord+texOffset*-1.).a;if(_at<=0.02){discard;}}vec3 emission=emissionColor*pow(2.0,emissionIntensity);color=vec4(pow(pow(color.rgb,vec3(2.2))+emission,vec3(1.0/2.2)),color.a);fragColor=color;}\n#endif\n";
12166
+ var particleFrag = "#version 300 es\nprecision highp float;\n#version 300 es\n#ifdef WEBGL2\n#define texture2D texture\n#define textureCube texture\n#define textureCubeLodEXT textureLod\nlayout(location=0)out vec4 fragColor;\n#else\n#define fragColor gl_FragColor\n#endif\nvec4 blendColor(vec4 color,vec4 vc,float mode){vec4 ret=color*vc;\n#ifdef PRE_MULTIPLY_ALPHA\nfloat alpha=vc.a;\n#else\nfloat alpha=ret.a;\n#endif\nif(mode==1.){ret.rgb*=alpha;}else if(mode==2.){ret.rgb*=alpha;ret.a=dot(ret.rgb,vec3(0.33333333));}else if(mode==3.){alpha=color.r*alpha;ret=vec4(vc.rgb*alpha,alpha);}return ret;}\n#define PATICLE_SHADER 1\nin float vLife;in vec2 vTexCoord;in vec4 vColor;uniform vec3 emissionColor;uniform float emissionIntensity;uniform sampler2D uMaskTex;uniform vec4 uColorParams;uniform vec2 uTexOffset;\n#ifdef COLOR_OVER_LIFETIME\nuniform sampler2D uColorOverLifetime;\n#endif\n#ifdef USE_SPRITE\nin vec4 vTexCoordBlend;\n#ifdef USE_FILTER\nuniform vec4 uFSprite;\n#endif\n#endif\nin float vSeed;\n#ifdef PREVIEW_BORDER\nuniform vec4 uPreviewColor;\n#endif\n#ifdef USE_SPRITE\nvec4 getTextureColor(sampler2D tex,vec2 texCoord){if(vTexCoordBlend.w>0.){return mix(texture2D(tex,texCoord),texture2D(tex,vTexCoordBlend.xy+texCoord),vTexCoordBlend.z);}return texture2D(tex,texCoord);}\n#else\n#define getTextureColor texture2D\n#endif\n#ifndef WEBGL2\n#define round(a) floor(0.5+a)\n#endif\n#ifdef PREVIEW_BORDER\nvoid main(){fragColor=uPreviewColor;}\n#else\n#pragma FILTER_FRAG\nvoid main(){vec4 color=vec4(1.0);vec4 tempColor=vColor;vec2 texOffset=uTexOffset;if(vLife<0.){discard;}\n#ifdef USE_FILTER\n#ifdef USE_SPRITE\ntexOffset=uTexOffset/uFSprite.xy;\n#endif\ncolor=filterMain(vTexCoord,uMaskTex);\n#else\nif(uColorParams.x>0.0){color=getTextureColor(uMaskTex,vTexCoord);}\n#endif\n#ifdef COLOR_OVER_LIFETIME\n#ifndef ENABLE_VERTEX_TEXTURE\ntempColor*=texture2D(uColorOverLifetime,vec2(vLife,0.));\n#endif\n#endif\ncolor=blendColor(color,tempColor,round(uColorParams.y));if(color.a<=0.01&&uColorParams.w>0.){float _at=texture2D(uMaskTex,vTexCoord+texOffset).a+texture2D(uMaskTex,vTexCoord+texOffset*-1.).a;if(_at<=0.02){discard;}}vec3 emission=emissionColor*pow(2.0,emissionIntensity);color=vec4(pow(pow(color.rgb,vec3(2.2))+emission,vec3(1.0/2.2)),color.a);fragColor=color;}\n#endif\n";
11726
12167
 
11727
- var particleVert = "#version 300 es\nprecision highp float;\n#define SHADER_VERTEX 1\n#define PATICLE_SHADER 1\n#version 300 es\n#ifdef WEBGL2\n#define texture2D texture\n#else\n#endif\n#ifdef SHADER_VERTEX\n#define CURVE_VALUE_TEXTURE uVCurveValueTexture\n#define CURVE_VALUE_ARRAY uVCurveValues\n#define CURVE_VALUE_COUNT VERT_CURVE_VALUE_COUNT\n#define FRAG_CURVE_VALUE_COUNT 0\n#else\n#define CURVE_VALUE_TEXTURE uFCurveValueTexture\n#define CURVE_VALUE_ARRAY uFCurveValues\n#define CURVE_VALUE_COUNT FRAG_CURVE_VALUE_COUNT\n#define VERT_CURVE_VALUE_COUNT 0\n#endif\n#if CURVE_VALUE_COUNT > 0\n#if LOOKUP_TEXTURE_CURVE\nuniform sampler2D CURVE_VALUE_TEXTURE;const float uCurveCount=1./float(CURVE_VALUE_COUNT);\n#define lookup_curve(i) texture2D(CURVE_VALUE_TEXTURE,vec2(float(i) * uCurveCount,0.))\n#else\nuniform vec4 CURVE_VALUE_ARRAY[CURVE_VALUE_COUNT];\n#define lookup_curve(i) CURVE_VALUE_ARRAY[i]\n#endif\n#else\n#define lookup_curve(i) vec4(0.)\n#endif\n#ifdef WEBGL2\n#define ITR_END (count + 1)\n#else\n#define ITR_END MAX_C\n#endif\n#ifdef SHADER_VERTEX\nin float aSeed;out float vSeed;\n#define NONE_CONST_INDEX 1\n#else\n#if LOOKUP_TEXTURE_CURVE\n#define NONE_CONST_INDEX 1\n#endif\n#endif\n#ifdef NONE_CONST_INDEX\n#ifdef SHADER_VERTEX\n#define MAX_C VERT_MAX_KEY_FRAME_COUNT\n#else\n#define MAX_C FRAG_MAX_KEY_FRAME_COUNT\n#endif\n#else\n#define MAX_C CURVE_VALUE_COUNT\n#endif\nfloat evaluateCurveFrames(float time,vec4 keyframe0,vec4 keyframe1){float dt=keyframe1.x-keyframe0.x;float m0=keyframe0.w*dt;float m1=keyframe1.z*dt;float t=(time-keyframe0.x)/dt;float t2=t*t;float t3=t2*t;return dot(vec4(dot(vec3(2.,-3.,1.),vec3(t3,t2,1.)),dot(vec3(1,-2.,1),vec3(t3,t2,t)),t3-t2,dot(vec2(-2,3),vec2(t3,t2))),vec4(keyframe0.y,m0,m1,keyframe1.y));}float valueFromCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);int end=start+count;for(int i=0;i<ITR_END;i++){\n#ifdef NONE_CONST_INDEX\nif(i==count){return lookup_curve(count).y;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);\n#else\nif(i<start){continue;}vec4 k0=lookup_curve(i);vec4 k1=lookup_curve(i+1);if(i==end){return k0.y;}\n#endif\nif(time>=k0.x&&time<=k1.x){return evaluateCurveFrames(time,k0,k1);}}return lookup_curve(0).y;}float evaluteLineSeg(float t,vec2 p0,vec2 p1){return p0.y+(p1.y-p0.y)*(t-p0.x)/(p1.x-p0.x);}float valueFromLineSegs(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);int end=start+count;for(int i=0;i<ITR_END;i++){\n#ifdef NONE_CONST_INDEX\nif(i>count){return lookup_curve(i).w;}\n#else\nif(i<start){continue;}if(i>end){return lookup_curve(i-2).w;}\n#endif\n#ifdef NONE_CONST_INDEX\nvec4 seg=lookup_curve(i+start);\n#else\nvec4 seg=lookup_curve(i);\n#endif\nvec2 p0=seg.xy;vec2 p1=seg.zw;if(time>=p0.x&&time<=p1.x){return evaluteLineSeg(time,p0,p1);}\n#ifdef NONE_CONST_INDEX\nvec2 p2=lookup_curve(i+start+1).xy;\n#else\nvec2 p2=lookup_curve(i+1).xy;\n#endif\nif(time>p1.x&&time<=p2.x){return evaluteLineSeg(time,p1,p2);}}return lookup_curve(0).y;}float getValueFromTime(float time,vec4 value){float type=value.x;if(type==0.){return value.y;}else if(type==1.){return mix(value.y,value.z,time/value.w);}if(type==2.){return valueFromCurveFrames(time,floor(value.y),floor(1./fract(value.y)+0.5))*value.w+value.z;}if(type==3.){return valueFromLineSegs(time,value.y,value.z);}if(type==4.){\n#ifdef SHADER_VERTEX\nfloat seed=aSeed;\n#else\nfloat seed=vSeed;\n#endif\nreturn mix(value.y,value.z,seed);}return 0.;}float integrateCurveFrames(float t1,vec4 k0,vec4 k1){float k=k1.x-k0.x;float m0=k0.w*k;float m1=k1.z*k;float t0=k0.x;float v0=k0.y;float v1=k1.y;float dt=t0-t1;float dt2=dt*dt;float dt3=dt2*dt;vec4 a=vec4(dt3*dt,dt3,dt2,dt)/vec4(4.*k*k*k,3.*k*k,2.*k,1.);vec4 b=vec4(m0+m1+2.*v0-2.*v1,2.*m0+m1+3.*v0-3.*v1,m0,-v0);return dot(a,b);}float integrateByTimeCurveFrames(float t1,vec4 k0,vec4 k1){float k=k1.x-k0.x;float m0=k0.w*k;float m1=k1.z*k;float t0=k0.x;float v0=k0.y;float v1=k1.y;float dt=t0-t1;float dt2=dt*dt;float dt3=dt2*dt;float k2=k*k;float k3=k2*k;vec4 a=vec4(-30.*k3,10.*k2,5.*k,3.)*vec4(dt,dt2,dt3,dt3*dt);vec4 b=vec4(v0,m0,2.*m0+m1+3.*v0-3.*v1,m0+m1+2.*v0-2.*v1)*vec4(t0+t1,t0+2.*t1,t0+3.*t1,t0+4.*t1);return dot(a,b)/60./k3;}float integrateByTimeFromCurveFrames(float t1,float frameStart,float frameCount){if(t1==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i==count){return ret;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(t1>k0.x&&t1<=k1.x){return ret+integrateByTimeCurveFrames(t1,k0,k1);}ret+=integrateByTimeCurveFrames(k1.x,k0,k1);}return ret;}float integrateFromCurveFrames(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i==count){return ret;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(time>k0.x&&time<=k1.x){return ret+integrateCurveFrames(time,k0,k1);}ret+=integrateCurveFrames(k1.x,k0,k1);}return ret;}float integrateByTimeLineSeg(float t,vec2 p0,vec2 p1){float t0=p0.x;float t1=p1.x;float y0=p0.y;float y1=p1.y;vec4 tSqr=vec4(t,t,t0,t0);tSqr=tSqr*tSqr;vec4 a=vec4(2.*t,3.,-t0,3.)*tSqr;float t1y0=t1*y0;vec4 b=vec4(y0-y1,t0*y1-t1y0,2.*y0+y1,t1y0);float r=dot(a,b);return r/(t0-t1)*0.16666667;}float integrateLineSeg(float time,vec2 p0,vec2 p1){float h=time-p0.x;float y0=p0.y;return(y0+y0+(p1.y-y0)*h/(p1.x-p0.x))*h/2.;}float integrateFromLineSeg(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i>count){return ret;}vec4 ks=lookup_curve(i+start);vec2 k0=ks.xy;vec2 k1=ks.zw;if(time>k0.x&&time<=k1.x){return ret+integrateLineSeg(time,k0,k1);}ret+=integrateLineSeg(k1.x,k0,k1);vec2 k2=lookup_curve(i+start+1).xy;if(time>k1.x&&time<=k2.x){return ret+integrateLineSeg(time,k1,k2);}ret+=integrateLineSeg(k2.x,k1,k2);}return ret;}float integrateByTimeFromLineSeg(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i>count){return ret;}vec4 ks=lookup_curve(i+start);vec2 k0=ks.xy;vec2 k1=ks.zw;if(time>k0.x&&time<=k1.x){return ret+integrateByTimeLineSeg(time,k0,k1);}ret+=integrateByTimeLineSeg(k1.x,k0,k1);vec2 k2=lookup_curve(i+start+1).xy;if(time>k1.x&&time<=k2.x){return ret+integrateByTimeLineSeg(time,k1,k2);}ret+=integrateByTimeLineSeg(k2.x,k1,k2);}return ret;}float getIntegrateFromTime0(float t1,vec4 value){float type=value.x;if(type==0.){return value.y*t1;}else if(type==1.){vec2 p0=vec2(0.,value.y);vec2 p1=vec2(value.w,value.z);return integrateLineSeg(t1,p0,p1);}if(type==3.){return integrateFromLineSeg(t1,value.y,value.z);}if(type==2.){float idx=floor(value.y);float ilen=floor(1./fract(value.y)+0.5);float d=integrateFromCurveFrames(t1,idx,ilen);return d*value.w+value.z*t1;}if(type==4.){return mix(value.y,value.z,aSeed)*t1;}return 0.;}float getIntegrateByTimeFromTime(float t0,float t1,vec4 value){float type=value.x;if(type==0.){return value.y*(t1*t1-t0*t0)/2.;}else if(type==1.){vec2 p0=vec2(0.,value.y);vec2 p1=vec2(value.w,value.z);return integrateByTimeLineSeg(t1,p0,p1)-integrateByTimeLineSeg(t0,p0,p1);}if(type==2.){float idx=floor(value.y);float ilen=floor(1./fract(value.y)+0.5);float d=integrateByTimeFromCurveFrames(t1,idx,ilen)-integrateByTimeFromCurveFrames(t0,idx,ilen);return d*value.w+value.z*pow(t1-t0,2.)*0.5;}if(type==3.){return integrateByTimeFromLineSeg(t1,value.y,value.z)-integrateByTimeFromLineSeg(t0,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed)*(t1*t1-t0*t0)/2.;}return 0.;}const float d2r=3.141592653589793/180.;in vec3 aPos;in vec4 aOffset;in vec3 aVel;in vec3 aRot;in vec4 aColor;in vec3 aDirX;in vec3 aDirY;\n#ifdef USE_SPRITE\nin vec3 aSprite;uniform vec4 uSprite;struct UVDetail{vec2 uv0;vec3 uv1;};UVDetail getSpriteUV(vec2 uv,float lifeTime);out vec4 vTexCoordBlend;\n#endif\n#pragma EDITOR_VERT_DEFINE\n#ifdef FINAL_TARGET\nuniform vec3 uFinalTarget;uniform vec4 uForceCurve;\n#endif\nuniform mat4 effects_ObjectToWorld;uniform mat4 effects_MatrixV;uniform mat4 effects_MatrixVP;uniform vec4 uParams;uniform vec4 uAcceleration;uniform vec4 uGravityModifierValue;uniform vec4 uOpacityOverLifetimeValue;\n#ifdef ROT_X_LIFETIME\nuniform vec4 uRXByLifeTimeValue;\n#endif\n#ifdef ROT_Y_LIFETIME\nuniform vec4 uRYByLifeTimeValue;\n#endif\n#ifdef ROT_Z_LIFETIME\nuniform vec4 uRZByLifeTimeValue;\n#endif\n#ifdef COLOR_OVER_LIFETIME\nuniform sampler2D uColorOverLifetime;\n#endif\n#if LINEAR_VEL_X + LINEAR_VEL_Y + LINEAR_VEL_Z\n#if LINEAR_VEL_X\nuniform vec4 uLinearXByLifetimeValue;\n#endif\n#if LINEAR_VEL_Y\nuniform vec4 uLinearYByLifetimeValue;\n#endif\n#if LINEAR_VEL_Z\nuniform vec4 uLinearZByLifetimeValue;\n#endif\n#endif\n#ifdef SPEED_OVER_LIFETIME\nuniform vec4 uSpeedLifetimeValue;\n#endif\n#if ORB_VEL_X + ORB_VEL_Y + ORB_VEL_Z\n#if ORB_VEL_X\nuniform vec4 uOrbXByLifetimeValue;\n#endif\n#if ORB_VEL_Y\nuniform vec4 uOrbYByLifetimeValue;\n#endif\n#if ORB_VEL_Z\nuniform vec4 uOrbZByLifetimeValue;\n#endif\nuniform vec3 uOrbCenter;\n#endif\nuniform vec4 uSizeByLifetimeValue;\n#ifdef SIZE_Y_BY_LIFE\nuniform vec4 uSizeYByLifetimeValue;\n#endif\nout float vLife;out vec4 vColor;out vec2 vTexCoord;\n#ifdef USE_FILTER\n#pragma FILTER_VERT\n#endif\n#ifdef ENV_EDITOR\nuniform vec4 uEditorTransform;\n#endif\nvec3 calOrbitalMov(float _life,float _dur){vec3 orb=vec3(0.0);\n#ifdef AS_ORBITAL_MOVEMENT\n#define FUNC(a) getValueFromTime(_life,a)\n#else\n#define FUNC(a) getIntegrateFromTime0(_life,a) * _dur\n#endif\n#if ORB_VEL_X\norb.x=FUNC(uOrbXByLifetimeValue);\n#endif\n#if ORB_VEL_Y\norb.y=FUNC(uOrbYByLifetimeValue);\n#endif\n#if ORB_VEL_Z\norb.z=FUNC(uOrbZByLifetimeValue);\n#endif\n#undef FUNC\nreturn orb;}vec3 calLinearMov(float _life,float _dur){vec3 mov=vec3(0.0);\n#ifdef AS_LINEAR_MOVEMENT\n#define FUNC(a) getValueFromTime(_life,a)\n#else\n#define FUNC(a) getIntegrateFromTime0(_life,a) * _dur\n#endif\n#if LINEAR_VEL_X\nmov.x=FUNC(uLinearXByLifetimeValue);\n#endif\n#if LINEAR_VEL_Y\nmov.y=FUNC(uLinearYByLifetimeValue);\n#endif\n#if LINEAR_VEL_Z\nmov.z=FUNC(uLinearZByLifetimeValue);\n#endif\n#undef FUNC\nreturn mov;}mat3 mat3FromRotation(vec3 rotation){vec3 sinR=sin(rotation*d2r);vec3 cosR=cos(rotation*d2r);return mat3(cosR.z,-sinR.z,0.,sinR.z,cosR.z,0.,0.,0.,1.)*mat3(cosR.y,0.,sinR.y,0.,1.,0.,-sinR.y,0,cosR.y)*mat3(1.,0.,0.,0,cosR.x,-sinR.x,0.,sinR.x,cosR.x);}\n#ifdef USE_SPRITE\nUVDetail getSpriteUV(vec2 uv,float lifeTime){float t=fract(clamp((lifeTime-aSprite.x)/aSprite.y,0.0,1.)*aSprite.z);float frame=uSprite.z*t;float frameIndex=max(ceil(frame)-1.,0.);float row=floor((frameIndex+0.1)/uSprite.x);float col=frameIndex-row*uSprite.x;vec2 retUV=(vec2(col,row)+uv)/uSprite.xy;UVDetail ret;if(uSprite.w>0.){float blend=frame-frameIndex;float frameIndex1=min(ceil(frame),uSprite.z-1.);float row1=floor((frameIndex1+0.1)/uSprite.x);float col1=frameIndex1-row1*uSprite.x;vec2 coord=(vec2(col1,row1)+uv)/uSprite.xy-retUV;ret.uv1=vec3(coord.x,1.-coord.y,blend);}ret.uv0=vec2(retUV.x,1.-retUV.y);return ret;}\n#endif\nvec3 calculateTranslation(vec3 vel,float t0,float t1,float dur){float dt=t1-t0;float d=getIntegrateByTimeFromTime(0.,dt,uGravityModifierValue);vec3 acc=uAcceleration.xyz*d;\n#ifdef SPEED_OVER_LIFETIME\nreturn vel*getIntegrateFromTime0(dt/dur,uSpeedLifetimeValue)*dur+acc;\n#endif\nreturn vel*dt+acc;}mat3 transformFromRotation(vec3 rot,float _life,float _dur){vec3 rotation=rot;\n#ifdef ROT_LIFETIME_AS_MOVEMENT\n#define FUNC1(a) getValueFromTime(_life,a)\n#else\n#define FUNC1(a) getIntegrateFromTime0(_life,a) * _dur\n#endif\n#ifdef ROT_X_LIFETIME\nrotation.x+=FUNC1(uRXByLifeTimeValue);\n#endif\n#ifdef ROT_Y_LIFETIME\nrotation.y+=FUNC1(uRYByLifeTimeValue);\n#endif\n#ifdef ROT_Z_LIFETIME\nrotation.z+=FUNC1(uRZByLifeTimeValue);\n#endif\nif(dot(rotation,rotation)==0.0){return mat3(1.0);}\n#undef FUNC1\nreturn mat3FromRotation(rotation);}void main(){float time=uParams.x-aOffset.z;float dur=aOffset.w;if(time<0.||time>dur){gl_Position=vec4(-3.,-3.,-3.,1.);}else{float life=clamp(time/dur,0.0,1.0);vLife=life;\n#ifdef USE_SPRITE\nUVDetail uvD=getSpriteUV(aOffset.xy,time);vTexCoord=uvD.uv0;vTexCoordBlend=vec4(uvD.uv1,uSprite.w);\n#else\nvTexCoord=aOffset.xy;\n#endif\nvColor=aColor;\n#ifdef COLOR_OVER_LIFETIME\n#ifdef ENABLE_VERTEX_TEXTURE\nvColor*=texture2D(uColorOverLifetime,vec2(life,0.));\n#endif\n#endif\nvColor.a*=clamp(getValueFromTime(life,uOpacityOverLifetimeValue),0.,1.);vec3 size=vec3(vec2(getValueFromTime(life,uSizeByLifetimeValue)),1.0);\n#ifdef SIZE_Y_BY_LIFE\nsize.y=getValueFromTime(life,uSizeYByLifetimeValue);\n#endif\nvec3 point=transformFromRotation(aRot,life,dur)*(aDirX*size.x+aDirY*size.y);vec3 pt=calculateTranslation(aVel,aOffset.z,uParams.x,dur);vec3 _pos=aPos+pt;\n#if ORB_VEL_X + ORB_VEL_Y + ORB_VEL_Z\n_pos=mat3FromRotation(calOrbitalMov(life,dur))*(_pos-uOrbCenter);_pos+=uOrbCenter;\n#endif\n#if LINEAR_VEL_X + LINEAR_VEL_Y + LINEAR_VEL_Z\n_pos.xyz+=calLinearMov(life,dur);\n#endif\n#ifdef FINAL_TARGET\nfloat force=getValueFromTime(life,uForceCurve);vec4 pos=vec4(mix(_pos,uFinalTarget,force),1.);\n#else\nvec4 pos=vec4(_pos,1.0);\n#endif\n#if RENDER_MODE == 1\npos.xyz+=point;pos=effects_ObjectToWorld*pos;\n#elif RENDER_MODE == 3\npos=effects_ObjectToWorld*pos;pos.xyz+=effects_MatrixV[0].xyz*point.x+effects_MatrixV[2].xyz*point.y;\n#elif RENDER_MODE == 2\npos=effects_ObjectToWorld*pos;pos.xy+=point.xy;\n#elif RENDER_MODE == 0\npos=effects_ObjectToWorld*pos;pos.xyz+=effects_MatrixV[0].xyz*point.x+effects_MatrixV[1].xyz*point.y;\n#endif\ngl_Position=effects_MatrixVP*pos;vSeed=aSeed;gl_PointSize=6.0;\n#ifdef USE_FILTER\nfilterMain(life);\n#endif\n#ifdef ENV_EDITOR\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n#pragma EDITOR_VERT_TRANSFORM\n}}";
12168
+ var particleVert = "#version 300 es\nprecision mediump float;\n#define SHADER_VERTEX 1\n#define PATICLE_SHADER 1\n#version 300 es\n#ifdef WEBGL2\n#define texture2D texture\n#else\n#endif\n#ifdef SHADER_VERTEX\n#define CURVE_VALUE_TEXTURE uVCurveValueTexture\n#define CURVE_VALUE_ARRAY uVCurveValues\n#define CURVE_VALUE_COUNT VERT_CURVE_VALUE_COUNT\n#define FRAG_CURVE_VALUE_COUNT 0\n#else\n#define CURVE_VALUE_TEXTURE uFCurveValueTexture\n#define CURVE_VALUE_ARRAY uFCurveValues\n#define CURVE_VALUE_COUNT FRAG_CURVE_VALUE_COUNT\n#define VERT_CURVE_VALUE_COUNT 0\n#endif\n#if CURVE_VALUE_COUNT > 0\n#if LOOKUP_TEXTURE_CURVE\nuniform sampler2D CURVE_VALUE_TEXTURE;const float uCurveCount=1./float(CURVE_VALUE_COUNT);\n#define lookup_curve(i) texture2D(CURVE_VALUE_TEXTURE,vec2(float(i) * uCurveCount,0.))\n#else\nuniform vec4 CURVE_VALUE_ARRAY[CURVE_VALUE_COUNT];\n#define lookup_curve(i) CURVE_VALUE_ARRAY[i]\n#endif\n#else\n#define lookup_curve(i) vec4(0.)\n#endif\n#ifdef WEBGL2\n#define ITR_END (count + 1)\n#else\n#define ITR_END MAX_C\n#endif\n#define NONE_CONST_INDEX 1\n#ifdef SHADER_VERTEX\nin float aSeed;out float vSeed;\n#endif\n#ifdef SHADER_VERTEX\n#define MAX_C VERT_MAX_KEY_FRAME_COUNT\n#else\n#define MAX_C FRAG_MAX_KEY_FRAME_COUNT\n#endif\nmat4 cubicBezierMatrix=mat4(1.0,-3.0,3.0,-1.0,0.0,3.0,-6.0,3.0,0.0,0.0,3.0,-3.0,0.0,0.0,0.0,1.0);float cubicBezier(float t,float y1,float y2,float y3,float y4){vec4 tVec=vec4(1.0,t,t*t,t*t*t);vec4 yVec=vec4(y1,y2,y3,y4);vec4 result=tVec*cubicBezierMatrix*yVec;return result.x+result.y+result.z+result.w;}float binarySearchT(float x,float x1,float x2,float x3,float x4){float left=0.0;float right=1.0;float mid=0.0;float computedX;for(int i=0;i<12;i++){mid=(left+right)*0.5;computedX=cubicBezier(mid,x1,x2,x3,x4);if(abs(computedX-x)<0.0001){break;}else if(computedX>x){right=mid;}else{left=mid;}}return mid;}float valueFromBezierCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);for(int i=0;i<ITR_END;i+=2){if(i>=count){break;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(i==0&&time<k0.x){return k0.y;}if(i==int(frameCount-2.)&&time>=k1.x){return k1.y;}if(time>=k0.x&&time<=k1.x){float t=(time-k0.x)/(k1.x-k0.x);float nt=binarySearchT(time,k0.x,k0.z,k1.z,k1.x);return cubicBezier(nt,k0.y,k0.w,k1.w,k1.y);}}}float evaluteLineSeg(float t,vec2 p0,vec2 p1){return p0.y+(p1.y-p0.y)*(t-p0.x)/(p1.x-p0.x);}float valueFromLineSegs(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);int end=start+count;for(int i=0;i<ITR_END;i++){if(i>count){return lookup_curve(i).w;}vec4 seg=lookup_curve(i+start);vec2 p0=seg.xy;vec2 p1=seg.zw;if(time>=p0.x&&time<=p1.x){return evaluteLineSeg(time,p0,p1);}vec2 p2=lookup_curve(i+start+1).xy;if(time>p1.x&&time<=p2.x){return evaluteLineSeg(time,p1,p2);}}return lookup_curve(0).y;}float getValueFromTime(float time,vec4 value){float type=value.x;if(type==0.){return value.y;}if(type==1.){return mix(value.y,value.z,time/value.w);}if(type==3.){return valueFromLineSegs(time,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed);}if(type==5.){return valueFromBezierCurveFrames(time,value.z,value.w);}return 0.;}float calculateMovement(float t,vec2 p1,vec2 p2,vec2 p3,vec2 p4){float movement=0.0;float h=(t-p1.x)*0.1;float delta=1./(p4.x-p1.x);for(int i=0;i<=10;i++){float t=float(i)*h*delta;float nt=binarySearchT(t,p1.x,p2.x,p3.x,p4.x);float y=cubicBezier(nt,p1.y,p2.y,p3.y,p4.y);float weight=(i==0||i==10)? 1.0 :(mod(float(i),2.)!=0.)? 4.0 : 2.0;movement+=weight*y;}movement*=h/3.;return movement;}float integrateFromBezierCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i+=2){vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(i==0&&time<k0.x){return ret;}vec2 p1=vec2(k0.x,k0.y);vec2 p2=vec2(k0.z,k0.w);vec2 p3=vec2(k1.z,k1.w);vec2 p4=vec2(k1.x,k1.y);if(time>=k1.x){ret+=calculateMovement(k1.x,p1,p2,p3,p4);}if(time>=k0.x&&time<k1.x){return ret+calculateMovement(time,p1,p2,p3,p4);}}return ret;}float integrateByTimeLineSeg(float t,vec2 p0,vec2 p1){float t0=p0.x;float t1=p1.x;float y0=p0.y;float y1=p1.y;vec4 tSqr=vec4(t,t,t0,t0);tSqr=tSqr*tSqr;vec4 a=vec4(2.*t,3.,-t0,3.)*tSqr;float t1y0=t1*y0;vec4 b=vec4(y0-y1,t0*y1-t1y0,2.*y0+y1,t1y0);float r=dot(a,b);return r/(t0-t1)*0.16666667;}float integrateLineSeg(float time,vec2 p0,vec2 p1){float h=time-p0.x;float y0=p0.y;return(y0+y0+(p1.y-y0)*h/(p1.x-p0.x))*h/2.;}float integrateFromLineSeg(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i>count){return ret;}vec4 ks=lookup_curve(i+start);vec2 k0=ks.xy;vec2 k1=ks.zw;if(time>k0.x&&time<=k1.x){return ret+integrateLineSeg(time,k0,k1);}ret+=integrateLineSeg(k1.x,k0,k1);vec2 k2=lookup_curve(i+start+1).xy;if(time>k1.x&&time<=k2.x){return ret+integrateLineSeg(time,k1,k2);}ret+=integrateLineSeg(k2.x,k1,k2);}return ret;}float integrateByTimeFromLineSeg(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i>count){return ret;}vec4 ks=lookup_curve(i+start);vec2 k0=ks.xy;vec2 k1=ks.zw;if(time>k0.x&&time<=k1.x){return ret+integrateByTimeLineSeg(time,k0,k1);}ret+=integrateByTimeLineSeg(k1.x,k0,k1);vec2 k2=lookup_curve(i+start+1).xy;if(time>k1.x&&time<=k2.x){return ret+integrateByTimeLineSeg(time,k1,k2);}ret+=integrateByTimeLineSeg(k2.x,k1,k2);}return ret;}float getIntegrateFromTime0(float t1,vec4 value){float type=value.x;if(type==0.){return value.y*t1;}else if(type==1.){vec2 p0=vec2(0.,value.y);vec2 p1=vec2(value.w,value.z);return integrateLineSeg(t1,p0,p1);}if(type==3.){return integrateFromLineSeg(t1,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed)*t1;}if(type==5.){return integrateFromBezierCurveFrames(t1,value.z,value.w);}return 0.;}float getIntegrateByTimeFromTime(float t0,float t1,vec4 value){float type=value.x;if(type==0.){return value.y*(t1*t1-t0*t0)/2.;}else if(type==1.){vec2 p0=vec2(0.,value.y);vec2 p1=vec2(value.w,value.z);return integrateByTimeLineSeg(t1,p0,p1)-integrateByTimeLineSeg(t0,p0,p1);}if(type==3.){return integrateByTimeFromLineSeg(t1,value.y,value.z)-integrateByTimeFromLineSeg(t0,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed)*(t1*t1-t0*t0)/2.;}if(type==5.){return integrateFromBezierCurveFrames(t1,value.z,value.w)-integrateFromBezierCurveFrames(t0,value.z,value.w);}return 0.;}const float d2r=3.141592653589793/180.;in vec3 aPos;in vec4 aOffset;in vec3 aVel;in vec3 aRot;in vec4 aColor;in vec3 aDirX;in vec3 aDirY;\n#ifdef USE_SPRITE\nin vec3 aSprite;uniform vec4 uSprite;struct UVDetail{vec2 uv0;vec3 uv1;};UVDetail getSpriteUV(vec2 uv,float lifeTime);out vec4 vTexCoordBlend;\n#endif\n#ifdef FINAL_TARGET\nuniform vec3 uFinalTarget;uniform vec4 uForceCurve;\n#endif\nuniform mat4 effects_ObjectToWorld;uniform mat4 effects_MatrixV;uniform mat4 effects_MatrixVP;uniform vec4 uParams;uniform vec4 uAcceleration;uniform vec4 uGravityModifierValue;uniform vec4 uOpacityOverLifetimeValue;\n#ifdef ROT_X_LIFETIME\nuniform vec4 uRXByLifeTimeValue;\n#endif\n#ifdef ROT_Y_LIFETIME\nuniform vec4 uRYByLifeTimeValue;\n#endif\n#ifdef ROT_Z_LIFETIME\nuniform vec4 uRZByLifeTimeValue;\n#endif\n#ifdef COLOR_OVER_LIFETIME\nuniform sampler2D uColorOverLifetime;\n#endif\n#if LINEAR_VEL_X + LINEAR_VEL_Y + LINEAR_VEL_Z\n#if LINEAR_VEL_X\nuniform vec4 uLinearXByLifetimeValue;\n#endif\n#if LINEAR_VEL_Y\nuniform vec4 uLinearYByLifetimeValue;\n#endif\n#if LINEAR_VEL_Z\nuniform vec4 uLinearZByLifetimeValue;\n#endif\n#endif\n#ifdef SPEED_OVER_LIFETIME\nuniform vec4 uSpeedLifetimeValue;\n#endif\n#if ORB_VEL_X + ORB_VEL_Y + ORB_VEL_Z\n#if ORB_VEL_X\nuniform vec4 uOrbXByLifetimeValue;\n#endif\n#if ORB_VEL_Y\nuniform vec4 uOrbYByLifetimeValue;\n#endif\n#if ORB_VEL_Z\nuniform vec4 uOrbZByLifetimeValue;\n#endif\nuniform vec3 uOrbCenter;\n#endif\nuniform vec4 uSizeByLifetimeValue;\n#ifdef SIZE_Y_BY_LIFE\nuniform vec4 uSizeYByLifetimeValue;\n#endif\nout float vLife;out vec4 vColor;out vec2 vTexCoord;\n#ifdef USE_FILTER\n#pragma FILTER_VERT\n#endif\n#ifdef ENV_EDITOR\nuniform vec4 uEditorTransform;\n#endif\nvec3 calOrbitalMov(float _life,float _dur){vec3 orb=vec3(0.0);\n#ifdef AS_ORBITAL_MOVEMENT\n#define FUNC(a) getValueFromTime(_life,a)\n#else\n#define FUNC(a) getIntegrateFromTime0(_life,a) * _dur\n#endif\n#if ORB_VEL_X\norb.x=FUNC(uOrbXByLifetimeValue);\n#endif\n#if ORB_VEL_Y\norb.y=FUNC(uOrbYByLifetimeValue);\n#endif\n#if ORB_VEL_Z\norb.z=FUNC(uOrbZByLifetimeValue);\n#endif\n#undef FUNC\nreturn orb;}vec3 calLinearMov(float _life,float _dur){vec3 mov=vec3(0.0);\n#ifdef AS_LINEAR_MOVEMENT\n#define FUNC(a) getValueFromTime(_life,a)\n#else\n#define FUNC(a) getIntegrateFromTime0(_life,a) * _dur\n#endif\n#if LINEAR_VEL_X\nmov.x=FUNC(uLinearXByLifetimeValue);\n#endif\n#if LINEAR_VEL_Y\nmov.y=FUNC(uLinearYByLifetimeValue);\n#endif\n#if LINEAR_VEL_Z\nmov.z=FUNC(uLinearZByLifetimeValue);\n#endif\n#undef FUNC\nreturn mov;}mat3 mat3FromRotation(vec3 rotation){vec3 sinR=sin(rotation*d2r);vec3 cosR=cos(rotation*d2r);return mat3(cosR.z,-sinR.z,0.,sinR.z,cosR.z,0.,0.,0.,1.)*mat3(cosR.y,0.,sinR.y,0.,1.,0.,-sinR.y,0,cosR.y)*mat3(1.,0.,0.,0,cosR.x,-sinR.x,0.,sinR.x,cosR.x);}\n#ifdef USE_SPRITE\nUVDetail getSpriteUV(vec2 uv,float lifeTime){float t=fract(clamp((lifeTime-aSprite.x)/aSprite.y,0.0,1.)*aSprite.z);float frame=uSprite.z*t;float frameIndex=max(ceil(frame)-1.,0.);float row=floor((frameIndex+0.1f)/uSprite.x);float col=frameIndex-row*uSprite.x;vec2 retUV=(vec2(col,row)+uv)/uSprite.xy;UVDetail ret;if(uSprite.w>0.){float blend=frame-frameIndex;float frameIndex1=min(ceil(frame),uSprite.z-1.);float row1=floor((frameIndex1+0.1f)/uSprite.x);float col1=frameIndex1-row1*uSprite.x;vec2 coord=(vec2(col1,row1)+uv)/uSprite.xy-retUV;ret.uv1=vec3(coord.x,1.-coord.y,blend);}ret.uv0=vec2(retUV.x,1.-retUV.y);return ret;}\n#endif\nvec3 calculateTranslation(vec3 vel,float t0,float t1,float dur){float dt=t1-t0;float d=getIntegrateByTimeFromTime(0.,dt,uGravityModifierValue);vec3 acc=uAcceleration.xyz*d;\n#ifdef SPEED_OVER_LIFETIME\nreturn vel*getIntegrateFromTime0(dt/dur,uSpeedLifetimeValue)*dur+acc;\n#endif\nreturn vel*dt+acc;}mat3 transformFromRotation(vec3 rot,float _life,float _dur){vec3 rotation=rot;\n#ifdef ROT_LIFETIME_AS_MOVEMENT\n#define FUNC1(a) getValueFromTime(_life,a)\n#else\n#define FUNC1(a) getIntegrateFromTime0(_life,a) * _dur\n#endif\n#ifdef ROT_X_LIFETIME\nrotation.x+=FUNC1(uRXByLifeTimeValue);\n#endif\n#ifdef ROT_Y_LIFETIME\nrotation.y+=FUNC1(uRYByLifeTimeValue);\n#endif\n#ifdef ROT_Z_LIFETIME\nrotation.z+=FUNC1(uRZByLifeTimeValue);\n#endif\nif(dot(rotation,rotation)==0.0){return mat3(1.0);}\n#undef FUNC1\nreturn mat3FromRotation(rotation);}void main(){float time=uParams.x-aOffset.z;float dur=aOffset.w;if(time<0.||time>dur){gl_Position=vec4(-3.,-3.,-3.,1.);}else{float life=clamp(time/dur,0.0,1.0);vLife=life;\n#ifdef USE_SPRITE\nUVDetail uvD=getSpriteUV(aOffset.xy,time);vTexCoord=uvD.uv0;vTexCoordBlend=vec4(uvD.uv1,uSprite.w);\n#else\nvTexCoord=aOffset.xy;\n#endif\nvColor=aColor;\n#ifdef COLOR_OVER_LIFETIME\n#ifdef ENABLE_VERTEX_TEXTURE\nvColor*=texture2D(uColorOverLifetime,vec2(life,0.));\n#endif\n#endif\nvColor.a*=clamp(getValueFromTime(life,uOpacityOverLifetimeValue),0.,1.);vec3 size=vec3(vec2(getValueFromTime(life,uSizeByLifetimeValue)),1.0);\n#ifdef SIZE_Y_BY_LIFE\nsize.y=getValueFromTime(life,uSizeYByLifetimeValue);\n#endif\nvec3 point=transformFromRotation(aRot,life,dur)*(aDirX*size.x+aDirY*size.y);vec3 pt=calculateTranslation(aVel,aOffset.z,uParams.x,dur);vec3 _pos=aPos+pt;\n#if ORB_VEL_X + ORB_VEL_Y + ORB_VEL_Z\n_pos=mat3FromRotation(calOrbitalMov(life,dur))*(_pos-uOrbCenter);_pos+=uOrbCenter;\n#endif\n#if LINEAR_VEL_X + LINEAR_VEL_Y + LINEAR_VEL_Z\n_pos.xyz+=calLinearMov(life,dur);\n#endif\n#ifdef FINAL_TARGET\nfloat force=getValueFromTime(life,uForceCurve);vec4 pos=vec4(mix(_pos,uFinalTarget,force),1.);\n#else\nvec4 pos=vec4(_pos,1.0);\n#endif\n#if RENDER_MODE == 1\npos.xyz+=point;pos=effects_ObjectToWorld*pos;\n#elif RENDER_MODE == 3\npos=effects_ObjectToWorld*pos;pos.xyz+=effects_MatrixV[0].xyz*point.x+effects_MatrixV[2].xyz*point.y;\n#elif RENDER_MODE == 2\npos=effects_ObjectToWorld*pos;pos.xy+=point.xy;\n#elif RENDER_MODE == 0\npos=effects_ObjectToWorld*pos;pos.xyz+=effects_MatrixV[0].xyz*point.x+effects_MatrixV[1].xyz*point.y;\n#endif\ngl_Position=effects_MatrixVP*pos;vSeed=aSeed;gl_PointSize=6.0;\n#ifdef USE_FILTER\nfilterMain(life);\n#endif\n#ifdef ENV_EDITOR\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}}";
11728
12169
 
11729
- var trailVert = "#version 300 es\nprecision mediump float;\n#define SHADER_VERTEX 1\n#version 300 es\n#ifdef WEBGL2\n#define texture2D texture\n#else\n#endif\n#ifdef SHADER_VERTEX\n#define CURVE_VALUE_TEXTURE uVCurveValueTexture\n#define CURVE_VALUE_ARRAY uVCurveValues\n#define CURVE_VALUE_COUNT VERT_CURVE_VALUE_COUNT\n#define FRAG_CURVE_VALUE_COUNT 0\n#else\n#define CURVE_VALUE_TEXTURE uFCurveValueTexture\n#define CURVE_VALUE_ARRAY uFCurveValues\n#define CURVE_VALUE_COUNT FRAG_CURVE_VALUE_COUNT\n#define VERT_CURVE_VALUE_COUNT 0\n#endif\n#if CURVE_VALUE_COUNT > 0\n#if LOOKUP_TEXTURE_CURVE\nuniform sampler2D CURVE_VALUE_TEXTURE;const float uCurveCount=1./float(CURVE_VALUE_COUNT);\n#define lookup_curve(i) texture2D(CURVE_VALUE_TEXTURE,vec2(float(i) * uCurveCount,0.))\n#else\nuniform vec4 CURVE_VALUE_ARRAY[CURVE_VALUE_COUNT];\n#define lookup_curve(i) CURVE_VALUE_ARRAY[i]\n#endif\n#else\n#define lookup_curve(i) vec4(0.)\n#endif\n#ifdef WEBGL2\n#define ITR_END (count + 1)\n#else\n#define ITR_END MAX_C\n#endif\n#ifdef SHADER_VERTEX\nin float aSeed;out float vSeed;\n#define NONE_CONST_INDEX 1\n#else\n#if LOOKUP_TEXTURE_CURVE\n#define NONE_CONST_INDEX 1\n#endif\n#endif\n#ifdef NONE_CONST_INDEX\n#ifdef SHADER_VERTEX\n#define MAX_C VERT_MAX_KEY_FRAME_COUNT\n#else\n#define MAX_C FRAG_MAX_KEY_FRAME_COUNT\n#endif\n#else\n#define MAX_C CURVE_VALUE_COUNT\n#endif\nfloat evaluateCurveFrames(float time,vec4 keyframe0,vec4 keyframe1){float dt=keyframe1.x-keyframe0.x;float m0=keyframe0.w*dt;float m1=keyframe1.z*dt;float t=(time-keyframe0.x)/dt;float t2=t*t;float t3=t2*t;return dot(vec4(dot(vec3(2.,-3.,1.),vec3(t3,t2,1.)),dot(vec3(1,-2.,1),vec3(t3,t2,t)),t3-t2,dot(vec2(-2,3),vec2(t3,t2))),vec4(keyframe0.y,m0,m1,keyframe1.y));}float valueFromCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);int end=start+count;for(int i=0;i<ITR_END;i++){\n#ifdef NONE_CONST_INDEX\nif(i==count){return lookup_curve(count).y;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);\n#else\nif(i<start){continue;}vec4 k0=lookup_curve(i);vec4 k1=lookup_curve(i+1);if(i==end){return k0.y;}\n#endif\nif(time>=k0.x&&time<=k1.x){return evaluateCurveFrames(time,k0,k1);}}return lookup_curve(0).y;}float evaluteLineSeg(float t,vec2 p0,vec2 p1){return p0.y+(p1.y-p0.y)*(t-p0.x)/(p1.x-p0.x);}float valueFromLineSegs(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);int end=start+count;for(int i=0;i<ITR_END;i++){\n#ifdef NONE_CONST_INDEX\nif(i>count){return lookup_curve(i).w;}\n#else\nif(i<start){continue;}if(i>end){return lookup_curve(i-2).w;}\n#endif\n#ifdef NONE_CONST_INDEX\nvec4 seg=lookup_curve(i+start);\n#else\nvec4 seg=lookup_curve(i);\n#endif\nvec2 p0=seg.xy;vec2 p1=seg.zw;if(time>=p0.x&&time<=p1.x){return evaluteLineSeg(time,p0,p1);}\n#ifdef NONE_CONST_INDEX\nvec2 p2=lookup_curve(i+start+1).xy;\n#else\nvec2 p2=lookup_curve(i+1).xy;\n#endif\nif(time>p1.x&&time<=p2.x){return evaluteLineSeg(time,p1,p2);}}return lookup_curve(0).y;}float getValueFromTime(float time,vec4 value){float type=value.x;if(type==0.){return value.y;}else if(type==1.){return mix(value.y,value.z,time/value.w);}if(type==2.){return valueFromCurveFrames(time,floor(value.y),floor(1./fract(value.y)+0.5))*value.w+value.z;}if(type==3.){return valueFromLineSegs(time,value.y,value.z);}if(type==4.){\n#ifdef SHADER_VERTEX\nfloat seed=aSeed;\n#else\nfloat seed=vSeed;\n#endif\nreturn mix(value.y,value.z,seed);}return 0.;}in vec4 aPos;in vec3 aDir;in vec3 aInfo;in vec4 aColor;in float aTime;\n#ifdef ATTR_TRAIL_START\nin float aTrailStart;\n#else\nuniform float uTrailStart[64];in float aTrailStartIndex;\n#endif\nuniform mat4 effects_MatrixInvV;uniform mat4 effects_ObjectToWorld;uniform mat4 effects_MatrixVP;uniform vec4 uTextureMap;uniform float uTime;uniform vec4 uParams;uniform vec4 uColorParams;uniform vec4 uOpacityOverLifetimeValue;uniform vec4 uWidthOverTrail;\n#ifdef COLOR_OVER_TRAIL\nuniform sampler2D uColorOverTrail;\n#endif\n#ifdef COLOR_OVER_LIFETIME\nuniform sampler2D uColorOverLifetime;\n#endif\nout float vLife;out vec2 vTexCoord;out vec4 vColor;\n#ifdef ENV_EDITOR\nuniform vec4 uEditorTransform;\n#endif\nvoid main(){vec4 _pa=effects_MatrixVP*vec4(aPos.xyz,1.);vec4 _pb=effects_MatrixVP*vec4(aPos.xyz+aDir,1.);vec2 dir=normalize(_pb.xy/_pb.w-_pa.xy/_pa.w);vec2 screen_xy=vec2(-dir.y,dir.x);vec4 pos=effects_ObjectToWorld*vec4(aPos.xyz,1.);\n#ifdef ATTR_TRAIL_START\nfloat ts=aTrailStart;\n#else\nfloat ts=uTrailStart[int(aTrailStartIndex)];\n#endif\nfloat trail=(ts-aInfo.y)/uParams.y;float width=aPos.w*getValueFromTime(trail,uWidthOverTrail)/max(abs(screen_xy.x),abs(screen_xy.y));pos.xyz+=(effects_MatrixInvV[0].xyz*screen_xy.x+effects_MatrixInvV[1].xyz*screen_xy.y)*width;float time=min((uTime-aTime)/aInfo.x,1.0);gl_Position=effects_MatrixVP*pos;vColor=aColor;\n#ifdef COLOR_OVER_LIFETIME\n#ifdef ENABLE_VERTEX_TEXTURE\nvColor*=texture2D(uColorOverLifetime,vec2(time,0.));\n#endif\n#endif\n#ifdef COLOR_OVER_TRAIL\nvColor*=texture2D(uColorOverTrail,vec2(trail,0.));\n#endif\nvColor.a*=clamp(getValueFromTime(time,uOpacityOverLifetimeValue),0.,1.);vLife=time;vTexCoord=uTextureMap.xy+vec2(trail,aInfo.z)*uTextureMap.zw;vSeed=aSeed;\n#ifdef ENV_EDITOR\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}";
12170
+ var trailVert = "#version 300 es\nprecision mediump float;\n#define SHADER_VERTEX 1\n#version 300 es\n#ifdef WEBGL2\n#define texture2D texture\n#else\n#endif\n#ifdef SHADER_VERTEX\n#define CURVE_VALUE_TEXTURE uVCurveValueTexture\n#define CURVE_VALUE_ARRAY uVCurveValues\n#define CURVE_VALUE_COUNT VERT_CURVE_VALUE_COUNT\n#define FRAG_CURVE_VALUE_COUNT 0\n#else\n#define CURVE_VALUE_TEXTURE uFCurveValueTexture\n#define CURVE_VALUE_ARRAY uFCurveValues\n#define CURVE_VALUE_COUNT FRAG_CURVE_VALUE_COUNT\n#define VERT_CURVE_VALUE_COUNT 0\n#endif\n#if CURVE_VALUE_COUNT > 0\n#if LOOKUP_TEXTURE_CURVE\nuniform sampler2D CURVE_VALUE_TEXTURE;const float uCurveCount=1./float(CURVE_VALUE_COUNT);\n#define lookup_curve(i) texture2D(CURVE_VALUE_TEXTURE,vec2(float(i) * uCurveCount,0.))\n#else\nuniform vec4 CURVE_VALUE_ARRAY[CURVE_VALUE_COUNT];\n#define lookup_curve(i) CURVE_VALUE_ARRAY[i]\n#endif\n#else\n#define lookup_curve(i) vec4(0.)\n#endif\n#ifdef WEBGL2\n#define ITR_END (count + 1)\n#else\n#define ITR_END MAX_C\n#endif\n#define NONE_CONST_INDEX 1\n#ifdef SHADER_VERTEX\nin float aSeed;out float vSeed;\n#endif\n#ifdef SHADER_VERTEX\n#define MAX_C VERT_MAX_KEY_FRAME_COUNT\n#else\n#define MAX_C FRAG_MAX_KEY_FRAME_COUNT\n#endif\nmat4 cubicBezierMatrix=mat4(1.0,-3.0,3.0,-1.0,0.0,3.0,-6.0,3.0,0.0,0.0,3.0,-3.0,0.0,0.0,0.0,1.0);float cubicBezier(float t,float y1,float y2,float y3,float y4){vec4 tVec=vec4(1.0,t,t*t,t*t*t);vec4 yVec=vec4(y1,y2,y3,y4);vec4 result=tVec*cubicBezierMatrix*yVec;return result.x+result.y+result.z+result.w;}float binarySearchT(float x,float x1,float x2,float x3,float x4){float left=0.0;float right=1.0;float mid=0.0;float computedX;for(int i=0;i<12;i++){mid=(left+right)*0.5;computedX=cubicBezier(mid,x1,x2,x3,x4);if(abs(computedX-x)<0.0001){break;}else if(computedX>x){right=mid;}else{left=mid;}}return mid;}float valueFromBezierCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);for(int i=0;i<ITR_END;i+=2){if(i>=count){break;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(i==0&&time<k0.x){return k0.y;}if(i==int(frameCount-2.)&&time>=k1.x){return k1.y;}if(time>=k0.x&&time<=k1.x){float t=(time-k0.x)/(k1.x-k0.x);float nt=binarySearchT(time,k0.x,k0.z,k1.z,k1.x);return cubicBezier(nt,k0.y,k0.w,k1.w,k1.y);}}}float evaluteLineSeg(float t,vec2 p0,vec2 p1){return p0.y+(p1.y-p0.y)*(t-p0.x)/(p1.x-p0.x);}float valueFromLineSegs(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);int end=start+count;for(int i=0;i<ITR_END;i++){if(i>count){return lookup_curve(i).w;}vec4 seg=lookup_curve(i+start);vec2 p0=seg.xy;vec2 p1=seg.zw;if(time>=p0.x&&time<=p1.x){return evaluteLineSeg(time,p0,p1);}vec2 p2=lookup_curve(i+start+1).xy;if(time>p1.x&&time<=p2.x){return evaluteLineSeg(time,p1,p2);}}return lookup_curve(0).y;}float getValueFromTime(float time,vec4 value){float type=value.x;if(type==0.){return value.y;}if(type==1.){return mix(value.y,value.z,time/value.w);}if(type==3.){return valueFromLineSegs(time,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed);}if(type==5.){return valueFromBezierCurveFrames(time,value.z,value.w);}return 0.;}in vec4 aPos;in vec3 aDir;in vec3 aInfo;in vec4 aColor;in float aTime;\n#ifdef ATTR_TRAIL_START\nin float aTrailStart;\n#else\nuniform float uTrailStart[64];in float aTrailStartIndex;\n#endif\nuniform mat4 effects_MatrixInvV;uniform mat4 effects_ObjectToWorld;uniform mat4 effects_MatrixVP;uniform vec4 uTextureMap;uniform float uTime;uniform vec4 uParams;uniform vec4 uColorParams;uniform vec4 uOpacityOverLifetimeValue;uniform vec4 uWidthOverTrail;\n#ifdef COLOR_OVER_TRAIL\nuniform sampler2D uColorOverTrail;\n#endif\n#ifdef COLOR_OVER_LIFETIME\nuniform sampler2D uColorOverLifetime;\n#endif\nout float vLife;out vec2 vTexCoord;out vec4 vColor;\n#ifdef ENV_EDITOR\nuniform vec4 uEditorTransform;\n#endif\nvoid main(){vec4 _pa=effects_MatrixVP*vec4(aPos.xyz,1.);vec4 _pb=effects_MatrixVP*vec4(aPos.xyz+aDir,1.);vec2 dir=normalize(_pb.xy/_pb.w-_pa.xy/_pa.w);vec2 screen_xy=vec2(-dir.y,dir.x);vec4 pos=effects_ObjectToWorld*vec4(aPos.xyz,1.);\n#ifdef ATTR_TRAIL_START\nfloat ts=aTrailStart;\n#else\nfloat ts=uTrailStart[int(aTrailStartIndex)];\n#endif\nfloat trail=(ts-aInfo.y)/uParams.y;float width=aPos.w*getValueFromTime(trail,uWidthOverTrail)/max(abs(screen_xy.x),abs(screen_xy.y));pos.xyz+=(effects_MatrixInvV[0].xyz*screen_xy.x+effects_MatrixInvV[1].xyz*screen_xy.y)*width;float time=min((uTime-aTime)/aInfo.x,1.0);gl_Position=effects_MatrixVP*pos;vColor=aColor;\n#ifdef COLOR_OVER_LIFETIME\n#ifdef ENABLE_VERTEX_TEXTURE\nvColor*=texture2D(uColorOverLifetime,vec2(time,0.));\n#endif\n#endif\n#ifdef COLOR_OVER_TRAIL\nvColor*=texture2D(uColorOverTrail,vec2(trail,0.));\n#endif\nvColor.a*=clamp(getValueFromTime(time,uOpacityOverLifetimeValue),0.,1.);vLife=time;vTexCoord=uTextureMap.xy+vec2(trail,aInfo.z)*uTextureMap.zw;vSeed=aSeed;\n#ifdef ENV_EDITOR\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}";
11730
12171
 
11731
- var value = "#ifdef SHADER_VERTEX\n#define CURVE_VALUE_TEXTURE uVCurveValueTexture\n#define CURVE_VALUE_ARRAY uVCurveValues\n#define CURVE_VALUE_COUNT VERT_CURVE_VALUE_COUNT\n#define FRAG_CURVE_VALUE_COUNT 0\n#else\n#define CURVE_VALUE_TEXTURE uFCurveValueTexture\n#define CURVE_VALUE_ARRAY uFCurveValues\n#define CURVE_VALUE_COUNT FRAG_CURVE_VALUE_COUNT\n#define VERT_CURVE_VALUE_COUNT 0\n#endif\n#if CURVE_VALUE_COUNT > 0\n#if LOOKUP_TEXTURE_CURVE\nuniform sampler2D CURVE_VALUE_TEXTURE;const float uCurveCount=1./float(CURVE_VALUE_COUNT);\n#define lookup_curve(i) texture2D(CURVE_VALUE_TEXTURE,vec2(float(i) * uCurveCount,0.))\n#else\nuniform vec4 CURVE_VALUE_ARRAY[CURVE_VALUE_COUNT];\n#define lookup_curve(i) CURVE_VALUE_ARRAY[i]\n#endif\n#else\n#define lookup_curve(i) vec4(0.)\n#endif\n#ifdef WEBGL2\n#define ITR_END (count + 1)\n#else\n#define ITR_END MAX_C\n#endif\n#ifdef SHADER_VERTEX\nin float aSeed;out float vSeed;\n#define NONE_CONST_INDEX 1\n#else\n#if LOOKUP_TEXTURE_CURVE\n#define NONE_CONST_INDEX 1\n#endif\n#endif\n#ifdef NONE_CONST_INDEX\n#ifdef SHADER_VERTEX\n#define MAX_C VERT_MAX_KEY_FRAME_COUNT\n#else\n#define MAX_C FRAG_MAX_KEY_FRAME_COUNT\n#endif\n#else\n#define MAX_C CURVE_VALUE_COUNT\n#endif\nfloat evaluateCurveFrames(float time,vec4 keyframe0,vec4 keyframe1){float dt=keyframe1.x-keyframe0.x;float m0=keyframe0.w*dt;float m1=keyframe1.z*dt;float t=(time-keyframe0.x)/dt;float t2=t*t;float t3=t2*t;return dot(vec4(dot(vec3(2.,-3.,1.),vec3(t3,t2,1.)),dot(vec3(1,-2.,1),vec3(t3,t2,t)),t3-t2,dot(vec2(-2,3),vec2(t3,t2))),vec4(keyframe0.y,m0,m1,keyframe1.y));}float valueFromCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);int end=start+count;for(int i=0;i<ITR_END;i++){\n#ifdef NONE_CONST_INDEX\nif(i==count){return lookup_curve(count).y;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);\n#else\nif(i<start){continue;}vec4 k0=lookup_curve(i);vec4 k1=lookup_curve(i+1);if(i==end){return k0.y;}\n#endif\nif(time>=k0.x&&time<=k1.x){return evaluateCurveFrames(time,k0,k1);}}return lookup_curve(0).y;}float evaluteLineSeg(float t,vec2 p0,vec2 p1){return p0.y+(p1.y-p0.y)*(t-p0.x)/(p1.x-p0.x);}float valueFromLineSegs(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);int end=start+count;for(int i=0;i<ITR_END;i++){\n#ifdef NONE_CONST_INDEX\nif(i>count){return lookup_curve(i).w;}\n#else\nif(i<start){continue;}if(i>end){return lookup_curve(i-2).w;}\n#endif\n#ifdef NONE_CONST_INDEX\nvec4 seg=lookup_curve(i+start);\n#else\nvec4 seg=lookup_curve(i);\n#endif\nvec2 p0=seg.xy;vec2 p1=seg.zw;if(time>=p0.x&&time<=p1.x){return evaluteLineSeg(time,p0,p1);}\n#ifdef NONE_CONST_INDEX\nvec2 p2=lookup_curve(i+start+1).xy;\n#else\nvec2 p2=lookup_curve(i+1).xy;\n#endif\nif(time>p1.x&&time<=p2.x){return evaluteLineSeg(time,p1,p2);}}return lookup_curve(0).y;}float getValueFromTime(float time,vec4 value){float type=value.x;if(type==0.){return value.y;}else if(type==1.){return mix(value.y,value.z,time/value.w);}if(type==2.){return valueFromCurveFrames(time,floor(value.y),floor(1./fract(value.y)+0.5))*value.w+value.z;}if(type==3.){return valueFromLineSegs(time,value.y,value.z);}if(type==4.){\n#ifdef SHADER_VERTEX\nfloat seed=aSeed;\n#else\nfloat seed=vSeed;\n#endif\nreturn mix(value.y,value.z,seed);}return 0.;}";
12172
+ var value = "#ifdef SHADER_VERTEX\n#define CURVE_VALUE_TEXTURE uVCurveValueTexture\n#define CURVE_VALUE_ARRAY uVCurveValues\n#define CURVE_VALUE_COUNT VERT_CURVE_VALUE_COUNT\n#define FRAG_CURVE_VALUE_COUNT 0\n#else\n#define CURVE_VALUE_TEXTURE uFCurveValueTexture\n#define CURVE_VALUE_ARRAY uFCurveValues\n#define CURVE_VALUE_COUNT FRAG_CURVE_VALUE_COUNT\n#define VERT_CURVE_VALUE_COUNT 0\n#endif\n#if CURVE_VALUE_COUNT > 0\n#if LOOKUP_TEXTURE_CURVE\nuniform sampler2D CURVE_VALUE_TEXTURE;const float uCurveCount=1./float(CURVE_VALUE_COUNT);\n#define lookup_curve(i) texture2D(CURVE_VALUE_TEXTURE,vec2(float(i) * uCurveCount,0.))\n#else\nuniform vec4 CURVE_VALUE_ARRAY[CURVE_VALUE_COUNT];\n#define lookup_curve(i) CURVE_VALUE_ARRAY[i]\n#endif\n#else\n#define lookup_curve(i) vec4(0.)\n#endif\n#ifdef WEBGL2\n#define ITR_END (count + 1)\n#else\n#define ITR_END MAX_C\n#endif\n#define NONE_CONST_INDEX 1\n#ifdef SHADER_VERTEX\nin float aSeed;out float vSeed;\n#endif\n#ifdef SHADER_VERTEX\n#define MAX_C VERT_MAX_KEY_FRAME_COUNT\n#else\n#define MAX_C FRAG_MAX_KEY_FRAME_COUNT\n#endif\nmat4 cubicBezierMatrix=mat4(1.0,-3.0,3.0,-1.0,0.0,3.0,-6.0,3.0,0.0,0.0,3.0,-3.0,0.0,0.0,0.0,1.0);float cubicBezier(float t,float y1,float y2,float y3,float y4){vec4 tVec=vec4(1.0,t,t*t,t*t*t);vec4 yVec=vec4(y1,y2,y3,y4);vec4 result=tVec*cubicBezierMatrix*yVec;return result.x+result.y+result.z+result.w;}float binarySearchT(float x,float x1,float x2,float x3,float x4){float left=0.0;float right=1.0;float mid=0.0;float computedX;for(int i=0;i<12;i++){mid=(left+right)*0.5;computedX=cubicBezier(mid,x1,x2,x3,x4);if(abs(computedX-x)<0.0001){break;}else if(computedX>x){right=mid;}else{left=mid;}}return mid;}float valueFromBezierCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);for(int i=0;i<ITR_END;i+=2){if(i>=count){break;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(i==0&&time<k0.x){return k0.y;}if(i==int(frameCount-2.)&&time>=k1.x){return k1.y;}if(time>=k0.x&&time<=k1.x){float t=(time-k0.x)/(k1.x-k0.x);float nt=binarySearchT(time,k0.x,k0.z,k1.z,k1.x);return cubicBezier(nt,k0.y,k0.w,k1.w,k1.y);}}}float evaluteLineSeg(float t,vec2 p0,vec2 p1){return p0.y+(p1.y-p0.y)*(t-p0.x)/(p1.x-p0.x);}float valueFromLineSegs(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);int end=start+count;for(int i=0;i<ITR_END;i++){if(i>count){return lookup_curve(i).w;}vec4 seg=lookup_curve(i+start);vec2 p0=seg.xy;vec2 p1=seg.zw;if(time>=p0.x&&time<=p1.x){return evaluteLineSeg(time,p0,p1);}vec2 p2=lookup_curve(i+start+1).xy;if(time>p1.x&&time<=p2.x){return evaluteLineSeg(time,p1,p2);}}return lookup_curve(0).y;}float getValueFromTime(float time,vec4 value){float type=value.x;if(type==0.){return value.y;}if(type==1.){return mix(value.y,value.z,time/value.w);}if(type==3.){return valueFromLineSegs(time,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed);}if(type==5.){return valueFromBezierCurveFrames(time,value.z,value.w);}return 0.;}";
11732
12173
 
11733
12174
  var valueDefine = "#ifdef SHADER_VERTEX\n#define CURVE_VALUE_TEXTURE uVCurveValueTexture\n#define CURVE_VALUE_ARRAY uVCurveValues\n#define CURVE_VALUE_COUNT VERT_CURVE_VALUE_COUNT\n#define FRAG_CURVE_VALUE_COUNT 0\n#else\n#define CURVE_VALUE_TEXTURE uFCurveValueTexture\n#define CURVE_VALUE_ARRAY uFCurveValues\n#define CURVE_VALUE_COUNT FRAG_CURVE_VALUE_COUNT\n#define VERT_CURVE_VALUE_COUNT 0\n#endif\n#if CURVE_VALUE_COUNT > 0\n#if LOOKUP_TEXTURE_CURVE\nuniform sampler2D CURVE_VALUE_TEXTURE;const float uCurveCount=1./float(CURVE_VALUE_COUNT);\n#define lookup_curve(i) texture2D(CURVE_VALUE_TEXTURE,vec2(float(i) * uCurveCount,0.))\n#else\nuniform vec4 CURVE_VALUE_ARRAY[CURVE_VALUE_COUNT];\n#define lookup_curve(i) CURVE_VALUE_ARRAY[i]\n#endif\n#else\n#define lookup_curve(i) vec4(0.)\n#endif\n#ifdef WEBGL2\n#define ITR_END (count + 1)\n#else\n#define ITR_END MAX_C\n#endif\n";
11734
12175
 
@@ -15164,819 +15605,146 @@ var FilterSpriteVFXItem = /** @class */ (function (_super) {
15164
15605
  return FilterSpriteVFXItem;
15165
15606
  }(SpriteVFXItem));
15166
15607
 
15167
- var ParticleMesh = /** @class */ (function () {
15168
- function ParticleMesh(props, rendererOptions) {
15169
- var _a, _b, _c, _d;
15170
- this.particleCount = 0;
15171
- var engine = rendererOptions.composition.getEngine();
15172
- var env = ((_a = engine.renderer) !== null && _a !== void 0 ? _a : {}).env;
15173
- var speedOverLifetime = props.speedOverLifetime, colorOverLifetime = props.colorOverLifetime, linearVelOverLifetime = props.linearVelOverLifetime, orbitalVelOverLifetime = props.orbitalVelOverLifetime, sizeOverLifetime = props.sizeOverLifetime, rotationOverLifetime = props.rotationOverLifetime, sprite = props.sprite, gravityModifier = props.gravityModifier, maxCount = props.maxCount, duration = props.duration, textureFlip = props.textureFlip, useSprite = props.useSprite, name = props.name, filter = props.filter, gravity = props.gravity, forceTarget = props.forceTarget, side = props.side, occlusion = props.occlusion, anchor = props.anchor, blending = props.blending, maskMode = props.maskMode, mask = props.mask, transparentOcclusion = props.transparentOcclusion, listIndex = props.listIndex, meshSlots = props.meshSlots, _e = props.renderMode, renderMode = _e === void 0 ? 0 : _e, _f = props.diffuse, diffuse = _f === void 0 ? Texture.createWithData(engine) : _f;
15174
- var detail = engine.gpuCapability.detail;
15175
- var halfFloatTexture = detail.halfFloatTexture, maxVertexUniforms = detail.maxVertexUniforms;
15176
- var marcos = [
15177
- ['RENDER_MODE', +renderMode],
15178
- ['PRE_MULTIPLY_ALPHA', false],
15179
- ['ENV_EDITOR', env === PLAYER_OPTIONS_ENV_EDITOR],
15180
- ];
15181
- var level = engine.gpuCapability.level;
15182
- var vertexKeyFrameMeta = createKeyFrameMeta();
15183
- var fragmentKeyFrameMeta = createKeyFrameMeta();
15184
- var enableVertexTexture = maxVertexUniforms > 0;
15185
- var uniformValues = {};
15186
- var vertex_lookup_texture = 0;
15187
- var shaderCacheId = 0;
15188
- var particleDefine;
15189
- var useOrbitalVel;
15190
- this.useSprite = useSprite;
15191
- if (enableVertexTexture) {
15192
- marcos.push(['ENABLE_VERTEX_TEXTURE', true]);
15193
- }
15194
- if (speedOverLifetime) {
15195
- marcos.push(['SPEED_OVER_LIFETIME', true]);
15196
- shaderCacheId |= 1 << 1;
15197
- uniformValues.uSpeedLifetimeValue = speedOverLifetime.toUniform(vertexKeyFrameMeta);
15198
- }
15199
- if (sprite === null || sprite === void 0 ? void 0 : sprite.animate) {
15200
- marcos.push(['USE_SPRITE', true]);
15201
- shaderCacheId |= 1 << 2;
15202
- uniformValues.uFSprite = uniformValues.uSprite = new Float32Array([sprite.col, sprite.row, sprite.total, sprite.blend ? 1 : 0]);
15203
- this.useSprite = true;
15608
+ var LinkNode = /** @class */ (function () {
15609
+ function LinkNode(content) {
15610
+ this.content = content;
15611
+ }
15612
+ return LinkNode;
15613
+ }());
15614
+ var Link = /** @class */ (function () {
15615
+ function Link(sort) {
15616
+ this.sort = sort;
15617
+ this.length = 0;
15618
+ }
15619
+ Link.prototype.findNodeByContent = function (filter) {
15620
+ var node = this.first;
15621
+ if (node) {
15622
+ do {
15623
+ if (filter(node.content)) {
15624
+ return node;
15625
+ }
15626
+ // @ts-expect-error
15627
+ // eslint-disable-next-line no-cond-assign
15628
+ } while (node = node.next);
15204
15629
  }
15205
- if (filter && filter.name !== FILTER_NAME_NONE) {
15206
- marcos.push(['USE_FILTER', true]);
15207
- shaderCacheId |= 1 << 3;
15208
- var filterDefine = createFilter(filter, rendererOptions.composition);
15209
- if (!filterDefine.particle) {
15210
- throw new Error("particle filter ".concat(filter.name, " not implement"));
15630
+ };
15631
+ Link.prototype.insertNode = function (a, next) {
15632
+ var b = a.next;
15633
+ a.next = next;
15634
+ next.pre = a;
15635
+ next.next = b;
15636
+ if (b) {
15637
+ b.pre = next;
15638
+ }
15639
+ // a -> next -> b
15640
+ };
15641
+ Link.prototype.shiftNode = function (content) {
15642
+ var node = new LinkNode(content);
15643
+ this.length++;
15644
+ if (this.length === 1) {
15645
+ return this.first = this.last = node;
15646
+ }
15647
+ var current = this.first;
15648
+ while (current) {
15649
+ if (this.sort(current.content, node.content) <= 0) {
15650
+ if (current.next) {
15651
+ current = current.next;
15652
+ }
15653
+ else {
15654
+ this.insertNode(current, node);
15655
+ return this.last = node;
15656
+ }
15211
15657
  }
15212
- particleDefine = filterDefine.particle;
15213
- Object.keys((_b = particleDefine.uniforms) !== null && _b !== void 0 ? _b : {}).forEach(function (uName) {
15214
- var _a;
15215
- var getter = (_a = particleDefine.uniforms) === null || _a === void 0 ? void 0 : _a[uName];
15216
- if (uniformValues[uName]) {
15217
- throw new Error('conflict uniform name:' + uName);
15658
+ else {
15659
+ if (current.pre) {
15660
+ this.insertNode(current.pre, node);
15218
15661
  }
15219
- uniformValues[uName] = getter === null || getter === void 0 ? void 0 : getter.toUniform(vertexKeyFrameMeta);
15220
- });
15221
- Object.keys((_c = particleDefine.uniformValues) !== null && _c !== void 0 ? _c : {}).forEach(function (uName) {
15222
- var _a;
15223
- var val = (_a = particleDefine.uniformValues) === null || _a === void 0 ? void 0 : _a[uName];
15224
- if (uniformValues[uName]) {
15225
- throw new Error('conflict uniform name:' + uName);
15662
+ else {
15663
+ this.first = node;
15664
+ node.next = current;
15665
+ current.pre = node;
15226
15666
  }
15227
- uniformValues[uName] = val;
15228
- });
15229
- }
15230
- if (colorOverLifetime === null || colorOverLifetime === void 0 ? void 0 : colorOverLifetime.color) {
15231
- marcos.push(['COLOR_OVER_LIFETIME', true]);
15232
- shaderCacheId |= 1 << 4;
15233
- uniformValues.uColorOverLifetime = colorOverLifetime.color instanceof Texture ? colorOverLifetime.color : Texture.createWithData(engine, imageDataFromGradient(colorOverLifetime.color));
15234
- }
15235
- if (colorOverLifetime === null || colorOverLifetime === void 0 ? void 0 : colorOverLifetime.opacity) {
15236
- uniformValues.uOpacityOverLifetimeValue = colorOverLifetime.opacity.toUniform(vertexKeyFrameMeta);
15667
+ return node;
15668
+ }
15237
15669
  }
15238
- else {
15239
- uniformValues.uOpacityOverLifetimeValue = createValueGetter(1).toUniform(vertexKeyFrameMeta);
15670
+ };
15671
+ Link.prototype.pushNode = function (content) {
15672
+ var node = new LinkNode(content);
15673
+ this.length++;
15674
+ if (this.length === 1) {
15675
+ return this.last = this.first = node;
15240
15676
  }
15241
- ['x', 'y', 'z'].forEach(function (pro, i) {
15242
- var defL = 0;
15243
- var defO = 0;
15244
- if (linearVelOverLifetime === null || linearVelOverLifetime === void 0 ? void 0 : linearVelOverLifetime[pro]) {
15245
- uniformValues["uLinear".concat(pro.toUpperCase(), "ByLifetimeValue")] = linearVelOverLifetime[pro].toUniform(vertexKeyFrameMeta);
15246
- defL = 1;
15247
- shaderCacheId |= 1 << (7 + i);
15248
- linearVelOverLifetime.enabled = true;
15677
+ var current = this.last;
15678
+ while (current) {
15679
+ if (this.sort(node.content, current.content) <= 0) {
15680
+ if (this.first === current) {
15681
+ current.pre = node;
15682
+ node.next = current;
15683
+ return this.first = node;
15684
+ }
15685
+ else {
15686
+ // @ts-expect-error
15687
+ current = current.pre;
15688
+ }
15249
15689
  }
15250
- marcos.push(["LINEAR_VEL_".concat(pro.toUpperCase()), defL]);
15251
- if (orbitalVelOverLifetime === null || orbitalVelOverLifetime === void 0 ? void 0 : orbitalVelOverLifetime[pro]) {
15252
- uniformValues["uOrb".concat(pro.toUpperCase(), "ByLifetimeValue")] = orbitalVelOverLifetime[pro].toUniform(vertexKeyFrameMeta);
15253
- defO = 1;
15254
- shaderCacheId |= 1 << (10 + i);
15255
- useOrbitalVel = true;
15256
- orbitalVelOverLifetime.enabled = true;
15690
+ else {
15691
+ this.insertNode(current, node);
15692
+ if (current === this.last) {
15693
+ this.last = node;
15694
+ }
15695
+ return node;
15257
15696
  }
15258
- marcos.push(["ORB_VEL_".concat(pro.toUpperCase()), defO]);
15259
- });
15260
- if (linearVelOverLifetime === null || linearVelOverLifetime === void 0 ? void 0 : linearVelOverLifetime.asMovement) {
15261
- marcos.push(['AS_LINEAR_MOVEMENT', true]);
15262
- shaderCacheId |= 1 << 5;
15263
15697
  }
15264
- if (useOrbitalVel) {
15265
- if (orbitalVelOverLifetime === null || orbitalVelOverLifetime === void 0 ? void 0 : orbitalVelOverLifetime.asRotation) {
15266
- marcos.push(['AS_ORBITAL_MOVEMENT', true]);
15267
- shaderCacheId |= 1 << 6;
15698
+ };
15699
+ Link.prototype.removeNode = function (node) {
15700
+ var current = this.first;
15701
+ this.length--;
15702
+ if (current === node) {
15703
+ // @ts-expect-error
15704
+ var a = this.first = current.next;
15705
+ if (a) {
15706
+ a.pre = null;
15268
15707
  }
15269
- uniformValues.uOrbCenter = new Float32Array((orbitalVelOverLifetime === null || orbitalVelOverLifetime === void 0 ? void 0 : orbitalVelOverLifetime.center) || [0, 0, 0]);
15270
- }
15271
- uniformValues.uSizeByLifetimeValue = sizeOverLifetime === null || sizeOverLifetime === void 0 ? void 0 : sizeOverLifetime.x.toUniform(vertexKeyFrameMeta);
15272
- if (sizeOverLifetime === null || sizeOverLifetime === void 0 ? void 0 : sizeOverLifetime.separateAxes) {
15273
- marcos.push(['SIZE_Y_BY_LIFE', 1]);
15274
- shaderCacheId |= 1 << 14;
15275
- uniformValues.uSizeYByLifetimeValue = (_d = sizeOverLifetime === null || sizeOverLifetime === void 0 ? void 0 : sizeOverLifetime.y) === null || _d === void 0 ? void 0 : _d.toUniform(vertexKeyFrameMeta);
15276
- }
15277
- if (rotationOverLifetime === null || rotationOverLifetime === void 0 ? void 0 : rotationOverLifetime.z) {
15278
- uniformValues.uRZByLifeTimeValue = rotationOverLifetime.z.toUniform(vertexKeyFrameMeta);
15279
- shaderCacheId |= 1 << 15;
15280
- marcos.push(['ROT_Z_LIFETIME', 1]);
15281
15708
  }
15282
- if (rotationOverLifetime === null || rotationOverLifetime === void 0 ? void 0 : rotationOverLifetime.x) {
15283
- uniformValues.uRXByLifeTimeValue = rotationOverLifetime.x.toUniform(vertexKeyFrameMeta);
15284
- shaderCacheId |= 1 << 16;
15285
- marcos.push(['ROT_X_LIFETIME', 1]);
15286
- }
15287
- if (rotationOverLifetime === null || rotationOverLifetime === void 0 ? void 0 : rotationOverLifetime.y) {
15288
- uniformValues.uRYByLifeTimeValue = rotationOverLifetime.y.toUniform(vertexKeyFrameMeta);
15289
- shaderCacheId |= 1 << 17;
15290
- marcos.push(['ROT_Y_LIFETIME', 1]);
15291
- }
15292
- if (rotationOverLifetime === null || rotationOverLifetime === void 0 ? void 0 : rotationOverLifetime.asRotation) {
15293
- marcos.push(['ROT_LIFETIME_AS_MOVEMENT', 1]);
15294
- shaderCacheId |= 1 << 18;
15295
- }
15296
- uniformValues.uGravityModifierValue = gravityModifier.toUniform(vertexKeyFrameMeta);
15297
- if (forceTarget) {
15298
- marcos.push(['FINAL_TARGET', true]);
15299
- shaderCacheId |= 1 << 19;
15300
- uniformValues.uFinalTarget = new Float32Array(forceTarget.target || [0, 0, 0]);
15301
- uniformValues.uForceCurve = forceTarget.curve.toUniform(vertexKeyFrameMeta);
15302
- }
15303
- if (halfFloatTexture && fragmentKeyFrameMeta.max) {
15304
- shaderCacheId |= 1 << 20;
15305
- uniformValues.uFCurveValueTexture = generateHalfFloatTexture(engine, CurveValue.getAllData(fragmentKeyFrameMeta, true), fragmentKeyFrameMeta.index, 1);
15306
- }
15307
- else {
15308
- uniformValues.uFCurveValues = CurveValue.getAllData(fragmentKeyFrameMeta);
15309
- }
15310
- var vertexCurveTexture = vertexKeyFrameMeta.max + vertexKeyFrameMeta.curves.length - 32 > maxVertexUniforms;
15311
- // if (getConfig(RENDER_PREFER_LOOKUP_TEXTURE)) {
15312
- // vertexCurveTexture = true;
15313
- // }
15314
- if (level === 2) {
15315
- vertexKeyFrameMeta.max = -1;
15316
- vertexKeyFrameMeta.index = meshSlots ? meshSlots[0] : getSlot(vertexKeyFrameMeta.index);
15317
- if (fragmentKeyFrameMeta.index > 0) {
15318
- fragmentKeyFrameMeta.max = -1;
15319
- fragmentKeyFrameMeta.index = meshSlots ? meshSlots[1] : getSlot(fragmentKeyFrameMeta.index);
15709
+ else if ((current = this.last) === node) {
15710
+ // @ts-expect-error
15711
+ var a = this.last = current.pre;
15712
+ if (a) {
15713
+ a.next = null;
15320
15714
  }
15321
15715
  }
15322
- if (vertexCurveTexture && halfFloatTexture && enableVertexTexture) {
15323
- var tex = generateHalfFloatTexture(engine, CurveValue.getAllData(vertexKeyFrameMeta, true), vertexKeyFrameMeta.index, 1);
15324
- uniformValues.uVCurveValueTexture = tex;
15325
- vertex_lookup_texture = 1;
15716
+ else if (node) {
15717
+ var pre = node.pre;
15718
+ var next = node.next;
15719
+ // @ts-expect-error
15720
+ pre.next = next;
15721
+ if (next) {
15722
+ next.pre = pre;
15723
+ }
15326
15724
  }
15327
- else {
15328
- uniformValues.uVCurveValues = CurveValue.getAllData(vertexKeyFrameMeta);
15725
+ node.pre = null;
15726
+ node.next = null;
15727
+ };
15728
+ Link.prototype.forEach = function (func, thisObj) {
15729
+ var node = this.first;
15730
+ var i = 0;
15731
+ if (node) {
15732
+ do {
15733
+ func.call(thisObj || this, node.content, i++);
15734
+ // @ts-expect-error
15735
+ // eslint-disable-next-line no-cond-assign
15736
+ } while (node = node.next);
15329
15737
  }
15330
- var shaderCache = ['-p:', renderMode, shaderCacheId, vertexKeyFrameMeta.index, vertexKeyFrameMeta.max, fragmentKeyFrameMeta.index, fragmentKeyFrameMeta.max].join('+');
15331
- marcos.push(['VERT_CURVE_VALUE_COUNT', vertexKeyFrameMeta.index], ['FRAG_CURVE_VALUE_COUNT', fragmentKeyFrameMeta.index], ['VERT_MAX_KEY_FRAME_COUNT', vertexKeyFrameMeta.max], ['FRAG_MAX_KEY_FRAME_COUNT', fragmentKeyFrameMeta.max]);
15332
- var fragment = filter ? particleFrag.replace(/#pragma\s+FILTER_FRAG/, particleDefine.fragment) : particleFrag;
15333
- var originalVertex = "#define LOOKUP_TEXTURE_CURVE ".concat(vertex_lookup_texture, "\n").concat(particleVert);
15334
- var vertex = filter ? originalVertex.replace(/#pragma\s+FILTER_VERT/, particleDefine.vertex || 'void filterMain(float t){}\n') : originalVertex;
15335
- var shader = {
15336
- fragment: createShaderWithMarcos(marcos, fragment, exports.ShaderType.fragment, level),
15337
- vertex: createShaderWithMarcos(marcos, vertex, exports.ShaderType.vertex, level),
15338
- glslVersion: level === 1 ? exports.GLSLVersion.GLSL1 : exports.GLSLVersion.GLSL3,
15339
- shared: true,
15340
- cacheId: shaderCache,
15341
- marcos: marcos,
15342
- name: "particle#".concat(name),
15343
- };
15344
- if (filter) {
15345
- shader.cacheId += filter.name;
15346
- }
15347
- var mtlOptions = {
15348
- shader: shader,
15349
- uniformSemantics: {
15350
- effects_MatrixV: 'VIEW',
15351
- effects_MatrixVP: 'VIEWPROJECTION',
15352
- uEditorTransform: 'EDITOR_TRANSFORM',
15353
- effects_ObjectToWorld: 'MODEL',
15354
- },
15355
- };
15356
- var preMulAlpha = getPreMultiAlpha(blending);
15357
- uniformValues.uTexOffset = new Float32Array(diffuse ? [1 / diffuse.getWidth(), 1 / diffuse.getHeight()] : [0, 0]);
15358
- uniformValues.uMaskTex = diffuse;
15359
- uniformValues.uColorParams = new Float32Array([diffuse ? 1 : 0, +preMulAlpha, 0, +(!!occlusion && !transparentOcclusion)]);
15360
- uniformValues.uParams = [0, duration, 0, 0];
15361
- uniformValues.uAcceleration = [(gravity === null || gravity === void 0 ? void 0 : gravity[0]) || 0, (gravity === null || gravity === void 0 ? void 0 : gravity[1]) || 0, (gravity === null || gravity === void 0 ? void 0 : gravity[2]) || 0, 0];
15362
- // mtlOptions.uniformValues = uniformValues;
15363
- var material = Material.create(engine, mtlOptions);
15364
- material.blending = true;
15365
- material.depthTest = true;
15366
- material.depthMask = !!(occlusion);
15367
- material.stencilRef = mask ? [mask, mask] : undefined;
15368
- setMaskMode(material, maskMode);
15369
- setBlendMode(material, blending);
15370
- setSideMode(material, side);
15371
- var typeMap = {
15372
- 'uSprite': 'vec4',
15373
- 'uParams': 'vec4',
15374
- 'uAcceleration': 'vec4',
15375
- 'uGravityModifierValue': 'vec4',
15376
- 'uOpacityOverLifetimeValue': 'vec4',
15377
- 'uRXByLifeTimeValue': 'vec4',
15378
- 'uRYByLifeTimeValue': 'vec4',
15379
- 'uRZByLifeTimeValue': 'vec4',
15380
- 'uLinearXByLifetimeValue': 'vec4',
15381
- 'uLinearYByLifetimeValue': 'vec4',
15382
- 'uLinearZByLifetimeValue': 'vec4',
15383
- 'uSpeedLifetimeValue': 'vec4',
15384
- 'uOrbXByLifetimeValue': 'vec4',
15385
- 'uOrbYByLifetimeValue': 'vec4',
15386
- 'uOrbZByLifetimeValue': 'vec4',
15387
- 'uSizeByLifetimeValue': 'vec4',
15388
- 'uSizeYByLifetimeValue': 'vec4',
15389
- 'uColorParams': 'vec4',
15390
- 'uFSprite': 'vec4',
15391
- 'uPreviewColor': 'vec4',
15392
- 'uVCurveValues': 'vec4Array',
15393
- 'uFCurveValues': 'vec4',
15394
- 'uFinalTarget': 'vec3',
15395
- 'uForceCurve': 'vec4',
15396
- 'uOrbCenter': 'vec3',
15397
- 'uTexOffset': 'vec2',
15398
- 'uPeriodValue': 'vec4',
15399
- 'uMovementValue': 'vec4',
15400
- 'uStrengthValue': 'vec4',
15401
- 'uWaveParams': 'vec4',
15402
- };
15403
- Object.keys(uniformValues).map(function (name) {
15404
- var value = uniformValues[name];
15405
- if (value instanceof Texture) {
15406
- material.setTexture(name, value);
15407
- return;
15408
- }
15409
- var res = [];
15410
- switch (typeMap[name]) {
15411
- case 'vec4':
15412
- material.setVector4(name, Vector4.fromArray(value));
15413
- break;
15414
- case 'vec3':
15415
- material.setVector3(name, Vector3.fromArray(value));
15416
- break;
15417
- case 'vec2':
15418
- material.setVector2(name, Vector2.fromArray(value));
15419
- break;
15420
- case 'vec4Array':
15421
- for (var i = 0; i < value.length; i = i + 4) {
15422
- var v = new Vector4(value[i], value[i + 1], value[i + 2], value[i + 3]);
15423
- res.push(v);
15424
- }
15425
- material.setVector4Array(name, res);
15426
- res.length = 0;
15427
- break;
15428
- default:
15429
- console.warn("uniform ".concat(name, "'s type not in typeMap"));
15430
- }
15431
- });
15432
- material.setVector3('emissionColor', new Vector3(0, 0, 0));
15433
- material.setFloat('emissionIntensity', 0.0);
15434
- var geometry = Geometry.create(engine, generateGeometryProps(maxCount * 4, this.useSprite, "particle#".concat(name)));
15435
- var mesh = Mesh.create(engine, {
15436
- name: "MParticle_".concat(name),
15437
- priority: listIndex,
15438
- material: material,
15439
- geometry: geometry,
15440
- });
15441
- this.anchor = anchor;
15442
- this.mesh = mesh;
15443
- this.geometry = mesh.firstGeometry();
15444
- this.forceTarget = forceTarget;
15445
- this.sizeOverLifetime = sizeOverLifetime;
15446
- this.speedOverLifetime = speedOverLifetime;
15447
- this.linearVelOverLifetime = linearVelOverLifetime;
15448
- this.orbitalVelOverLifetime = orbitalVelOverLifetime;
15449
- this.orbitalVelOverLifetime = orbitalVelOverLifetime;
15450
- this.gravityModifier = gravityModifier;
15451
- this.maxCount = maxCount;
15452
- this.duration = duration;
15453
- this.textureOffsets = textureFlip ? [0, 0, 1, 0, 0, 1, 1, 1] : [0, 1, 0, 0, 1, 1, 1, 0];
15454
- }
15455
- Object.defineProperty(ParticleMesh.prototype, "time", {
15456
- get: function () {
15457
- var value = this.mesh.material.getVector4('uParams');
15458
- return value.x;
15459
- },
15460
- set: function (v) {
15461
- this.mesh.material.setVector4('uParams', new Vector4(+v, this.duration, 0, 0));
15462
- },
15463
- enumerable: false,
15464
- configurable: true
15465
- });
15466
- ParticleMesh.prototype.getPointColor = function (index) {
15467
- var data = this.geometry.getAttributeData('aRot');
15468
- var i = index * 32 + 4;
15469
- return [data[i], data[i + 1], data[i + 2], data[i + 3]];
15470
- };
15471
- /**
15472
- * 待废弃
15473
- * @deprecated - 使用 `particle-system.getPointPosition` 替代
15474
- */
15475
- ParticleMesh.prototype.getPointPosition = function (index) {
15476
- var geo = this.geometry;
15477
- var posIndex = index * 48;
15478
- var posData = geo.getAttributeData('aPos');
15479
- var offsetData = geo.getAttributeData('aOffset');
15480
- var time = this.time - offsetData[index * 16 + 2];
15481
- var pointDur = offsetData[index * 16 + 3];
15482
- var mtl = this.mesh.material;
15483
- var acc = mtl.getVector4('uAcceleration').toVector3();
15484
- var pos = Vector3.fromArray(posData, posIndex);
15485
- var vel = Vector3.fromArray(posData, posIndex + 3);
15486
- var ret = calculateTranslation(new Vector3(), this, acc, time, pointDur, pos, vel);
15487
- if (this.forceTarget) {
15488
- var target = mtl.getVector3('uFinalTarget');
15489
- var life = this.forceTarget.curve.getValue(time / pointDur);
15490
- var dl = 1 - life;
15491
- ret.x = ret.x * dl + target.x * life;
15492
- ret.y = ret.y * dl + target.y * life;
15493
- ret.z = ret.z * dl + target.z * life;
15494
- }
15495
- return ret;
15496
- };
15497
- ParticleMesh.prototype.clearPoints = function () {
15498
- this.resetGeometryData(this.geometry);
15499
- this.particleCount = 0;
15500
- this.geometry.setDrawCount(0);
15501
- this.maxParticleBufferCount = 0;
15502
- };
15503
- ParticleMesh.prototype.resetGeometryData = function (geometry) {
15504
- var names = geometry.getAttributeNames();
15505
- var index = geometry.getIndexData();
15506
- for (var i = 0; i < names.length; i++) {
15507
- var name_1 = names[i];
15508
- var data = geometry.getAttributeData(name_1);
15509
- if (data) {
15510
- // @ts-expect-error
15511
- geometry.setAttributeData(name_1, new data.constructor(0));
15512
- }
15513
- }
15514
- // @ts-expect-error
15515
- geometry.setIndexData(new index.constructor(0));
15516
- };
15517
- ParticleMesh.prototype.minusTime = function (time) {
15518
- var data = this.geometry.getAttributeData('aOffset');
15519
- for (var i = 0; i < data.length; i += 4) {
15520
- data[i + 2] -= time;
15521
- }
15522
- this.geometry.setAttributeData('aOffset', data);
15523
- this.time -= time;
15524
- };
15525
- ParticleMesh.prototype.removePoint = function (index) {
15526
- if (index < this.particleCount) {
15527
- this.geometry.setAttributeSubData('aOffset', index * 16, new Float32Array(16));
15528
- }
15529
- };
15530
- ParticleMesh.prototype.setPoint = function (point, index) {
15531
- var maxCount = this.maxCount;
15532
- if (index < maxCount) {
15533
- var particleCount = index + 1;
15534
- var vertexCount_1 = particleCount * 4;
15535
- var geometry_1 = this.geometry;
15536
- var increaseBuffer_1 = particleCount > this.maxParticleBufferCount;
15537
- var inc_1 = 1;
15538
- if (this.particleCount > 300) {
15539
- inc_1 = (this.particleCount + 100) / this.particleCount;
15540
- }
15541
- else if (this.particleCount > 100) {
15542
- inc_1 = 1.4;
15543
- }
15544
- else if (this.particleCount > 0) {
15545
- inc_1 = 2;
15546
- }
15547
- var pointData_1 = {
15548
- aPos: new Float32Array(48),
15549
- aRot: new Float32Array(32),
15550
- aOffset: new Float32Array(16),
15551
- };
15552
- var useSprite = this.useSprite;
15553
- if (useSprite) {
15554
- pointData_1.aSprite = new Float32Array(12);
15555
- }
15556
- var tempPos = new Vector3();
15557
- var tempQuat = new Quaternion();
15558
- var scale = new Vector3(1, 1, 1);
15559
- point.transform.assignWorldTRS(tempPos, tempQuat, scale);
15560
- var tempEuler = Transform.getRotation(tempQuat, new Euler());
15561
- var position = tempPos.toArray();
15562
- var rotation = tempEuler.toArray();
15563
- var offsets = this.textureOffsets;
15564
- var off = [0, 0, point.delay, point.lifetime];
15565
- var wholeUV = [0, 0, 1, 1];
15566
- var vel = point.vel;
15567
- var color = point.color;
15568
- var sizeOffsets = [-.5, .5, -.5, -.5, .5, .5, .5, -.5];
15569
- var seed = Math.random();
15570
- var sprite = void 0;
15571
- if (useSprite) {
15572
- sprite = point.sprite;
15573
- }
15574
- for (var j = 0; j < 4; j++) {
15575
- var offset = j * 2;
15576
- var j3 = j * 3;
15577
- var j4 = j * 4;
15578
- var j12 = j * 12;
15579
- var j8 = j * 8;
15580
- pointData_1.aPos.set(position, j12);
15581
- vel.fill(pointData_1.aPos, j12 + 3);
15582
- pointData_1.aRot.set(rotation, j8);
15583
- pointData_1.aRot[j8 + 3] = seed;
15584
- pointData_1.aRot.set(color, j8 + 4);
15585
- if (useSprite) {
15586
- // @ts-expect-error
15587
- pointData_1.aSprite.set(sprite, j3);
15588
- }
15589
- var uv = point.uv || wholeUV;
15590
- if (uv) {
15591
- var uvy = useSprite ? (1 - offsets[offset + 1]) : offsets[offset + 1];
15592
- off[0] = uv[0] + offsets[offset] * uv[2];
15593
- off[1] = uv[1] + uvy * uv[3];
15594
- }
15595
- pointData_1.aOffset.set(off, j4);
15596
- var ji = (j + j);
15597
- var sx = (sizeOffsets[ji] - this.anchor.x) * scale.x;
15598
- var sy = (sizeOffsets[ji + 1] - this.anchor.y) * scale.y;
15599
- for (var k = 0; k < 3; k++) {
15600
- pointData_1.aPos[j12 + 6 + k] = point.dirX.getElement(k) * sx;
15601
- pointData_1.aPos[j12 + 9 + k] = point.dirY.getElement(k) * sy;
15602
- }
15603
- }
15604
- var indexData = new Uint16Array([0, 1, 2, 2, 1, 3].map(function (x) { return x + index * 4; }));
15605
- if (increaseBuffer_1) {
15606
- var baseIndexData = geometry_1.getIndexData();
15607
- var idx = enlargeBuffer(baseIndexData, particleCount * 6, inc_1, maxCount * 6);
15608
- idx.set(indexData, index * 6);
15609
- geometry_1.setIndexData(idx);
15610
- this.maxParticleBufferCount = idx.length / 6;
15611
- }
15612
- else {
15613
- geometry_1.setIndexSubData(index * 6, indexData);
15614
- }
15615
- Object.keys(pointData_1).forEach(function (name) {
15616
- var data = pointData_1[name];
15617
- var attrSize = geometry_1.getAttributeStride(name) / Float32Array.BYTES_PER_ELEMENT;
15618
- if (increaseBuffer_1) {
15619
- var baseData = geometry_1.getAttributeData(name);
15620
- var geoData = enlargeBuffer(baseData, vertexCount_1 * attrSize, inc_1, maxCount * 4 * attrSize);
15621
- geoData.set(data, data.length * index);
15622
- geometry_1.setAttributeData(name, geoData);
15623
- }
15624
- else {
15625
- geometry_1.setAttributeSubData(name, data.length * index, data);
15626
- }
15627
- });
15628
- this.particleCount = Math.max(particleCount, this.particleCount);
15629
- geometry_1.setDrawCount(this.particleCount * 6);
15630
- }
15631
- };
15632
- return ParticleMesh;
15633
- }());
15634
- var gl2UniformSlots = [10, 32, 64, 160];
15635
- function getSlot(count) {
15636
- for (var w = 0; w < gl2UniformSlots.length; w++) {
15637
- var slot = gl2UniformSlots[w];
15638
- if (slot > count) {
15639
- return slot;
15640
- }
15641
- }
15642
- return count || gl2UniformSlots[0];
15643
- }
15644
- function generateGeometryProps(maxVertex, useSprite, name) {
15645
- var bpe = Float32Array.BYTES_PER_ELEMENT;
15646
- var j12 = bpe * 12;
15647
- var attributes = {
15648
- aPos: { size: 3, offset: 0, stride: j12, data: new Float32Array(0) },
15649
- aVel: { size: 3, offset: 3 * bpe, stride: j12, dataSource: 'aPos' },
15650
- aDirX: { size: 3, offset: 6 * bpe, stride: j12, dataSource: 'aPos' },
15651
- aDirY: { size: 3, offset: 9 * bpe, stride: j12, dataSource: 'aPos' },
15652
- //
15653
- aRot: { size: 3, offset: 0, stride: 8 * bpe, data: new Float32Array(0) },
15654
- aSeed: { size: 1, offset: 3 * bpe, stride: 8 * bpe, dataSource: 'aRot' },
15655
- aColor: { size: 4, offset: 4 * bpe, stride: 8 * bpe, dataSource: 'aRot' },
15656
- //
15657
- aOffset: { size: 4, stride: 4 * bpe, data: new Float32Array(0) },
15658
- };
15659
- if (useSprite) {
15660
- attributes['aSprite'] = { size: 3, data: new Float32Array(0) };
15661
- }
15662
- return { attributes: attributes, indices: { data: new Uint16Array(0) }, name: name, maxVertex: maxVertex };
15663
- }
15664
- function getParticleMeshShader(item, env, gpuCapability) {
15665
- var _a, _b, _c, _d, _e;
15666
- if (env === void 0) { env = ''; }
15667
- var props = item.content;
15668
- var renderMode = +(((_a = props.renderer) === null || _a === void 0 ? void 0 : _a.renderMode) || 0);
15669
- var marcos = [
15670
- ['RENDER_MODE', renderMode],
15671
- ['PRE_MULTIPLY_ALPHA', false],
15672
- ['ENV_EDITOR', env === PLAYER_OPTIONS_ENV_EDITOR],
15673
- ];
15674
- var level = gpuCapability.level, detail = gpuCapability.detail;
15675
- var vertexKeyFrameMeta = createKeyFrameMeta();
15676
- var fragmentKeyFrameMeta = createKeyFrameMeta();
15677
- var enableVertexTexture = detail.maxVertexUniforms > 0;
15678
- var speedOverLifetime = ((_b = props.positionOverLifetime) !== null && _b !== void 0 ? _b : {}).speedOverLifetime;
15679
- var vertex_lookup_texture = 0;
15680
- var shaderCacheId = 0;
15681
- if (enableVertexTexture) {
15682
- marcos.push(['ENABLE_VERTEX_TEXTURE', true]);
15683
- }
15684
- if (speedOverLifetime) {
15685
- marcos.push(['SPEED_OVER_LIFETIME', true]);
15686
- shaderCacheId |= 1 << 1;
15687
- getKeyFrameMetaByRawValue(vertexKeyFrameMeta, speedOverLifetime);
15688
- }
15689
- var sprite = props.textureSheetAnimation;
15690
- if (sprite && sprite.animate) {
15691
- marcos.push(['USE_SPRITE', true]);
15692
- shaderCacheId |= 1 << 2;
15693
- }
15694
- var filter = undefined;
15695
- if (props.filter && props.filter.name !== FILTER_NAME_NONE) {
15696
- marcos.push(['USE_FILTER', true]);
15697
- shaderCacheId |= 1 << 3;
15698
- var f = createFilterShaders(props.filter).find(function (f) { return f.isParticle; });
15699
- if (!f) {
15700
- throw Error("particle filter ".concat(props.filter.name, " not implement"));
15701
- }
15702
- filter = f;
15703
- (_c = f.uniforms) === null || _c === void 0 ? void 0 : _c.forEach(function (val) { return getKeyFrameMetaByRawValue(vertexKeyFrameMeta, val); });
15704
- // filter = processFilter(props.filter, fragmentKeyFrameMeta, vertexKeyFrameMeta, options);
15705
- }
15706
- var colorOverLifetime = props.colorOverLifetime;
15707
- if (colorOverLifetime && colorOverLifetime.color) {
15708
- marcos.push(['COLOR_OVER_LIFETIME', true]);
15709
- shaderCacheId |= 1 << 4;
15710
- }
15711
- var opacity = colorOverLifetime && colorOverLifetime.opacity;
15712
- if (opacity) {
15713
- getKeyFrameMetaByRawValue(vertexKeyFrameMeta, opacity);
15714
- }
15715
- var positionOverLifetime = props.positionOverLifetime;
15716
- var useOrbitalVel;
15717
- ['x', 'y', 'z'].forEach(function (pro, i) {
15718
- var defL = 0;
15719
- var linearPro = 'linear' + pro.toUpperCase();
15720
- var orbitalPro = 'orbital' + pro.toUpperCase();
15721
- if (positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime[linearPro]) {
15722
- getKeyFrameMetaByRawValue(vertexKeyFrameMeta, positionOverLifetime[linearPro]);
15723
- defL = 1;
15724
- shaderCacheId |= 1 << (7 + i);
15725
- }
15726
- marcos.push(["LINEAR_VEL_".concat(pro.toUpperCase()), defL]);
15727
- var defO = 0;
15728
- if (positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime[orbitalPro]) {
15729
- getKeyFrameMetaByRawValue(vertexKeyFrameMeta, positionOverLifetime[orbitalPro]);
15730
- defO = 1;
15731
- shaderCacheId |= 1 << (10 + i);
15732
- useOrbitalVel = true;
15733
- }
15734
- marcos.push(["ORB_VEL_".concat(pro.toUpperCase()), defO]);
15735
- });
15736
- if (positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.asMovement) {
15737
- marcos.push(['AS_LINEAR_MOVEMENT', true]);
15738
- shaderCacheId |= 1 << 5;
15739
- }
15740
- if (useOrbitalVel) {
15741
- if (positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.asRotation) {
15742
- marcos.push(['AS_ORBITAL_MOVEMENT', true]);
15743
- shaderCacheId |= 1 << 6;
15744
- }
15745
- }
15746
- var sizeOverLifetime = props.sizeOverLifetime;
15747
- getKeyFrameMetaByRawValue(vertexKeyFrameMeta, sizeOverLifetime === null || sizeOverLifetime === void 0 ? void 0 : sizeOverLifetime.x);
15748
- if (sizeOverLifetime === null || sizeOverLifetime === void 0 ? void 0 : sizeOverLifetime.separateAxes) {
15749
- marcos.push(['SIZE_Y_BY_LIFE', 1]);
15750
- shaderCacheId |= 1 << 14;
15751
- getKeyFrameMetaByRawValue(vertexKeyFrameMeta, sizeOverLifetime === null || sizeOverLifetime === void 0 ? void 0 : sizeOverLifetime.y);
15752
- }
15753
- var rot = props.rotationOverLifetime;
15754
- if (rot === null || rot === void 0 ? void 0 : rot.z) {
15755
- getKeyFrameMetaByRawValue(vertexKeyFrameMeta, rot === null || rot === void 0 ? void 0 : rot.z);
15756
- shaderCacheId |= 1 << 15;
15757
- marcos.push(['ROT_Z_LIFETIME', 1]);
15758
- }
15759
- if (rot === null || rot === void 0 ? void 0 : rot.separateAxes) {
15760
- if (rot.x) {
15761
- getKeyFrameMetaByRawValue(vertexKeyFrameMeta, rot.x);
15762
- shaderCacheId |= 1 << 16;
15763
- marcos.push(['ROT_X_LIFETIME', 1]);
15764
- }
15765
- if (rot.y) {
15766
- getKeyFrameMetaByRawValue(vertexKeyFrameMeta, rot.y);
15767
- shaderCacheId |= 1 << 17;
15768
- marcos.push(['ROT_Y_LIFETIME', 1]);
15769
- }
15770
- }
15771
- if (rot === null || rot === void 0 ? void 0 : rot.asRotation) {
15772
- marcos.push(['ROT_LIFETIME_AS_MOVEMENT', 1]);
15773
- shaderCacheId |= 1 << 18;
15774
- }
15775
- getKeyFrameMetaByRawValue(vertexKeyFrameMeta, positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.gravityOverLifetime);
15776
- var forceOpt = positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.forceTarget;
15777
- if (forceOpt) {
15778
- marcos.push(['FINAL_TARGET', true]);
15779
- shaderCacheId |= 1 << 19;
15780
- getKeyFrameMetaByRawValue(vertexKeyFrameMeta, positionOverLifetime.forceCurve);
15781
- }
15782
- var HALF_FLOAT = detail.halfFloatTexture;
15783
- if (HALF_FLOAT && fragmentKeyFrameMeta.max) {
15784
- shaderCacheId |= 1 << 20;
15785
- }
15786
- var maxVertexUniforms = detail.maxVertexUniforms;
15787
- var vertexCurveTexture = vertexKeyFrameMeta.max + vertexKeyFrameMeta.curves.length - 32 > maxVertexUniforms;
15788
- if (getConfig(RENDER_PREFER_LOOKUP_TEXTURE)) {
15789
- vertexCurveTexture = true;
15790
- }
15791
- if (level === 2) {
15792
- vertexKeyFrameMeta.max = -1;
15793
- // vertexKeyFrameMeta.index = getSlot(vertexKeyFrameMeta.index);
15794
- if (fragmentKeyFrameMeta.index > 0) {
15795
- fragmentKeyFrameMeta.max = -1;
15796
- // fragmentKeyFrameMeta.index = getSlot(fragmentKeyFrameMeta.index);
15797
- }
15798
- }
15799
- if (vertexCurveTexture && HALF_FLOAT && enableVertexTexture) {
15800
- vertex_lookup_texture = 1;
15801
- }
15802
- var shaderCache = ['-p:', renderMode, shaderCacheId, vertexKeyFrameMeta.index, vertexKeyFrameMeta.max, fragmentKeyFrameMeta.index, fragmentKeyFrameMeta.max].join('+');
15803
- var shader = {
15804
- fragment: particleFrag,
15805
- vertex: "#define LOOKUP_TEXTURE_CURVE ".concat(vertex_lookup_texture, "\n").concat(particleVert),
15806
- shared: true,
15807
- cacheId: shaderCache,
15808
- marcos: marcos,
15809
- name: "particle#".concat(item.name),
15810
- };
15811
- if (filter) {
15812
- shader.fragment = shader.fragment.replace(/#pragma\s+FILTER_FRAG/, (_d = filter.fragment) !== null && _d !== void 0 ? _d : '');
15813
- shader.vertex = shader.vertex.replace(/#pragma\s+FILTER_VERT/, filter.vertex || 'void filterMain(float t){}\n');
15814
- shader.cacheId += '+' + ((_e = props.filter) === null || _e === void 0 ? void 0 : _e.name);
15815
- }
15816
- marcos.push(['VERT_CURVE_VALUE_COUNT', vertexKeyFrameMeta.index], ['FRAG_CURVE_VALUE_COUNT', fragmentKeyFrameMeta.index], ['VERT_MAX_KEY_FRAME_COUNT', vertexKeyFrameMeta.max], ['FRAG_MAX_KEY_FRAME_COUNT', fragmentKeyFrameMeta.max]);
15817
- return { shader: shader, vertex: vertexKeyFrameMeta.index, fragment: fragmentKeyFrameMeta.index };
15818
- }
15819
- function modifyMaxKeyframeShader(shader, maxVertex, maxFrag) {
15820
- var _a;
15821
- var shaderIds = (_a = shader.cacheId) === null || _a === void 0 ? void 0 : _a.split('+');
15822
- shaderIds[3] = maxVertex;
15823
- shaderIds[5] = maxFrag;
15824
- shader.cacheId = shaderIds.join('+');
15825
- if (!shader.marcos) {
15826
- return;
15827
- }
15828
- for (var i = 0; i < shader.marcos.length; i++) {
15829
- var marco = shader.marcos[i];
15830
- if (marco[0] === 'VERT_CURVE_VALUE_COUNT') {
15831
- marco[1] = maxVertex;
15832
- }
15833
- else if (marco[0] === 'FRAG_CURVE_VALUE_COUNT') {
15834
- marco[1] = maxFrag;
15835
- break;
15836
- }
15837
- }
15838
- }
15839
-
15840
- var LinkNode = /** @class */ (function () {
15841
- function LinkNode(content) {
15842
- this.content = content;
15843
- }
15844
- return LinkNode;
15845
- }());
15846
- var Link = /** @class */ (function () {
15847
- function Link(sort) {
15848
- this.sort = sort;
15849
- this.length = 0;
15850
- }
15851
- Link.prototype.findNodeByContent = function (filter) {
15852
- var node = this.first;
15853
- if (node) {
15854
- do {
15855
- if (filter(node.content)) {
15856
- return node;
15857
- }
15858
- // @ts-expect-error
15859
- // eslint-disable-next-line no-cond-assign
15860
- } while (node = node.next);
15861
- }
15862
- };
15863
- Link.prototype.insertNode = function (a, next) {
15864
- var b = a.next;
15865
- a.next = next;
15866
- next.pre = a;
15867
- next.next = b;
15868
- if (b) {
15869
- b.pre = next;
15870
- }
15871
- // a -> next -> b
15872
- };
15873
- Link.prototype.shiftNode = function (content) {
15874
- var node = new LinkNode(content);
15875
- this.length++;
15876
- if (this.length === 1) {
15877
- return this.first = this.last = node;
15878
- }
15879
- var current = this.first;
15880
- while (current) {
15881
- if (this.sort(current.content, node.content) <= 0) {
15882
- if (current.next) {
15883
- current = current.next;
15884
- }
15885
- else {
15886
- this.insertNode(current, node);
15887
- return this.last = node;
15888
- }
15889
- }
15890
- else {
15891
- if (current.pre) {
15892
- this.insertNode(current.pre, node);
15893
- }
15894
- else {
15895
- this.first = node;
15896
- node.next = current;
15897
- current.pre = node;
15898
- }
15899
- return node;
15900
- }
15901
- }
15902
- };
15903
- Link.prototype.pushNode = function (content) {
15904
- var node = new LinkNode(content);
15905
- this.length++;
15906
- if (this.length === 1) {
15907
- return this.last = this.first = node;
15908
- }
15909
- var current = this.last;
15910
- while (current) {
15911
- if (this.sort(node.content, current.content) <= 0) {
15912
- if (this.first === current) {
15913
- current.pre = node;
15914
- node.next = current;
15915
- return this.first = node;
15916
- }
15917
- else {
15918
- // @ts-expect-error
15919
- current = current.pre;
15920
- }
15921
- }
15922
- else {
15923
- this.insertNode(current, node);
15924
- if (current === this.last) {
15925
- this.last = node;
15926
- }
15927
- return node;
15928
- }
15929
- }
15930
- };
15931
- Link.prototype.removeNode = function (node) {
15932
- var current = this.first;
15933
- this.length--;
15934
- if (current === node) {
15935
- // @ts-expect-error
15936
- var a = this.first = current.next;
15937
- if (a) {
15938
- a.pre = null;
15939
- }
15940
- }
15941
- else if ((current = this.last) === node) {
15942
- // @ts-expect-error
15943
- var a = this.last = current.pre;
15944
- if (a) {
15945
- a.next = null;
15946
- }
15947
- }
15948
- else if (node) {
15949
- var pre = node.pre;
15950
- var next = node.next;
15951
- // @ts-expect-error
15952
- pre.next = next;
15953
- if (next) {
15954
- next.pre = pre;
15955
- }
15956
- }
15957
- node.pre = null;
15958
- node.next = null;
15959
- };
15960
- Link.prototype.forEach = function (func, thisObj) {
15961
- var node = this.first;
15962
- var i = 0;
15963
- if (node) {
15964
- do {
15965
- func.call(thisObj || this, node.content, i++);
15966
- // @ts-expect-error
15967
- // eslint-disable-next-line no-cond-assign
15968
- } while (node = node.next);
15969
- }
15970
- };
15971
- Link.prototype.forEachReverse = function (func, thisObj) {
15972
- var node = this.last;
15973
- var i = this.length - 1;
15974
- if (node) {
15975
- do {
15976
- func.call(thisObj || this, node.content, i--);
15977
- // @ts-expect-error
15978
- // eslint-disable-next-line no-cond-assign
15979
- } while (node = node.pre);
15738
+ };
15739
+ Link.prototype.forEachReverse = function (func, thisObj) {
15740
+ var node = this.last;
15741
+ var i = this.length - 1;
15742
+ if (node) {
15743
+ do {
15744
+ func.call(thisObj || this, node.content, i--);
15745
+ // @ts-expect-error
15746
+ // eslint-disable-next-line no-cond-assign
15747
+ } while (node = node.pre);
15980
15748
  }
15981
15749
  };
15982
15750
  return Link;
@@ -17067,11 +16835,11 @@ var TrailMesh = /** @class */ (function () {
17067
16835
  var uWidthOverTrail = widthOverTrail.toUniform(keyFrameMeta);
17068
16836
  marcos.push(['VERT_CURVE_VALUE_COUNT', keyFrameMeta.index], ['VERT_MAX_KEY_FRAME_COUNT', keyFrameMeta.max]);
17069
16837
  if (enableVertexTexture && lookUpTexture) {
17070
- var tex = generateHalfFloatTexture(engine, CurveValue.getAllData(keyFrameMeta, true), keyFrameMeta.index, 1);
16838
+ var tex = generateHalfFloatTexture(engine, ValueGetter.getAllData(keyFrameMeta, true), keyFrameMeta.index, 1);
17071
16839
  uniformValues.uVCurveValueTexture = tex;
17072
16840
  }
17073
16841
  else {
17074
- uniformValues.uVCurveValues = CurveValue.getAllData(keyFrameMeta);
16842
+ uniformValues.uVCurveValues = ValueGetter.getAllData(keyFrameMeta);
17075
16843
  }
17076
16844
  var vertex = createShaderWithMarcos(marcos, trailVert, exports.ShaderType.vertex, level);
17077
16845
  var fragment = createShaderWithMarcos(marcos, particleFrag, exports.ShaderType.fragment, level);
@@ -17150,8 +16918,10 @@ var TrailMesh = /** @class */ (function () {
17150
16918
  }
17151
16919
  else if (name === 'uVCurveValues') {
17152
16920
  var array = [];
17153
- array.push(new Vector4(value[0], value[1], value[2], value[3]));
17154
- array.push(new Vector4(value[4], value[5], value[6], value[7]));
16921
+ for (var i = 0; i < value.length; i = i + 4) {
16922
+ var v = new Vector4(value[i], value[i + 1], value[i + 2], value[i + 3]);
16923
+ array.push(v);
16924
+ }
17155
16925
  material.setVector4Array(name, array);
17156
16926
  }
17157
16927
  else {
@@ -17899,456 +17669,1129 @@ var ParticleSystem = /** @class */ (function () {
17899
17669
  this.onIterate(this);
17900
17670
  }
17901
17671
  else {
17902
- this.ended = true;
17903
- this.onEnd(this);
17904
- var endBehavior = options.endBehavior;
17905
- if (endBehavior === END_BEHAVIOR_FREEZE$1) {
17906
- this.frozen = true;
17907
- }
17672
+ this.ended = true;
17673
+ this.onEnd(this);
17674
+ var endBehavior = options.endBehavior;
17675
+ if (endBehavior === END_BEHAVIOR_FREEZE$1) {
17676
+ this.frozen = true;
17677
+ }
17678
+ }
17679
+ }
17680
+ else if (!options.looping) {
17681
+ if (this.reusable) ;
17682
+ else if (END_BEHAVIOR_DESTROY$1 === options.endBehavior) {
17683
+ var node = link_1.last;
17684
+ if (node && (node.content[0] - loopStartTime_1) < timePassed_1) {
17685
+ this.onUpdate = function () { return _this.onDestroy(); };
17686
+ }
17687
+ }
17688
+ }
17689
+ updateTrail();
17690
+ }
17691
+ };
17692
+ ParticleSystem.prototype.onDestroy = function () {
17693
+ };
17694
+ ParticleSystem.prototype.getParticleBoxes = function () {
17695
+ var link = this.particleLink;
17696
+ var mesh = this.particleMesh;
17697
+ var res = [];
17698
+ var maxCount = this.particleCount;
17699
+ var counter = 0;
17700
+ if (!(link && mesh)) {
17701
+ return res;
17702
+ }
17703
+ var node = link.last;
17704
+ var finish = false;
17705
+ while (!finish) {
17706
+ var currentTime = node.content[0];
17707
+ var point = node.content[3];
17708
+ if (currentTime > this.timePassed) {
17709
+ var pos = this.getPointPosition(point);
17710
+ res.push({
17711
+ center: pos,
17712
+ size: point.transform.scale,
17713
+ });
17714
+ if (node.pre) {
17715
+ node = node.pre;
17716
+ }
17717
+ else {
17718
+ finish = true;
17719
+ }
17720
+ }
17721
+ counter++;
17722
+ if (counter > maxCount) {
17723
+ finish = true;
17724
+ }
17725
+ }
17726
+ return res;
17727
+ };
17728
+ ParticleSystem.prototype.raycast = function (options) {
17729
+ var link = this.particleLink;
17730
+ var mesh = this.particleMesh;
17731
+ if (!(link && mesh)) {
17732
+ return;
17733
+ }
17734
+ var node = link.last;
17735
+ var hitPositions = [];
17736
+ var temp = new Vector3();
17737
+ var finish = false;
17738
+ if (node && node.content) {
17739
+ do {
17740
+ var _a = __read$3(node.content, 4), currentTime = _a[0], pointIndex = _a[1]; _a[2]; var point = _a[3];
17741
+ if (currentTime > this.timePassed) {
17742
+ var pos = this.getPointPosition(point);
17743
+ var ray = options.ray;
17744
+ var pass = false;
17745
+ if (ray) {
17746
+ pass = !!ray.intersectSphere({
17747
+ center: pos,
17748
+ radius: options.radius,
17749
+ }, temp);
17750
+ }
17751
+ if (pass) {
17752
+ if (options.removeParticle) {
17753
+ mesh.removePoint(pointIndex);
17754
+ this.clearPointTrail(pointIndex);
17755
+ node.content[0] = 0;
17756
+ }
17757
+ hitPositions.push(pos);
17758
+ if (!options.multiple) {
17759
+ finish = true;
17760
+ }
17761
+ }
17762
+ }
17763
+ else {
17764
+ break;
17765
+ }
17766
+ // @ts-expect-error
17767
+ } while ((node = node.pre) && !finish);
17768
+ }
17769
+ return hitPositions;
17770
+ };
17771
+ ParticleSystem.prototype.clearPointTrail = function (pointIndex) {
17772
+ var _a;
17773
+ if (this.trails && this.trails.dieWithParticles) {
17774
+ (_a = this.trailMesh) === null || _a === void 0 ? void 0 : _a.clearTrail(pointIndex);
17775
+ }
17776
+ };
17777
+ ParticleSystem.prototype.updatePointTrail = function (pointIndex, emitterLifetime, point, startTime) {
17778
+ if (!this.trailMesh) {
17779
+ return;
17780
+ }
17781
+ var trails = this.trails;
17782
+ var particleMesh = this.particleMesh;
17783
+ var position = this.getPointPosition(point);
17784
+ var color = trails.inheritParticleColor ? particleMesh.getPointColor(pointIndex) : [1, 1, 1, 1];
17785
+ var size = point.transform.getWorldScale().toArray();
17786
+ var width = 1;
17787
+ var lifetime = trails.lifetime.getValue(emitterLifetime);
17788
+ if (trails.sizeAffectsWidth) {
17789
+ width *= size[0];
17790
+ }
17791
+ if (trails.sizeAffectsLifetime) {
17792
+ lifetime *= size[0];
17793
+ }
17794
+ if (trails.parentAffectsPosition && this.transform.parentTransform) {
17795
+ position.add(this.transform.parentTransform.position);
17796
+ var pos = this.trailMesh.getPointStartPos(pointIndex);
17797
+ if (pos) {
17798
+ position.subtract(pos);
17799
+ }
17800
+ }
17801
+ this.trailMesh.addPoint(pointIndex, position, {
17802
+ color: color,
17803
+ lifetime: lifetime,
17804
+ size: width,
17805
+ time: startTime,
17806
+ });
17807
+ };
17808
+ ParticleSystem.prototype.getPointPosition = function (point) {
17809
+ var transform = point.transform, vel = point.vel, lifetime = point.lifetime, delay = point.delay, _a = point.gravity, gravity = _a === void 0 ? [] : _a;
17810
+ var forceTarget = this.options.forceTarget;
17811
+ var time = this.lastUpdate - delay;
17812
+ var tempPos = new Vector3();
17813
+ var acc = Vector3.fromArray(gravity);
17814
+ transform.assignWorldTRS(tempPos);
17815
+ var ret = calculateTranslation(new Vector3(), this.options, acc, time, lifetime, tempPos, vel);
17816
+ if (forceTarget) {
17817
+ var target = forceTarget.target || [0, 0, 0];
17818
+ var life = forceTarget.curve.getValue(time / lifetime);
17819
+ var dl = 1 - life;
17820
+ ret.x = ret.x * dl + target[0] * life;
17821
+ ret.y = ret.y * dl + target[1] * life;
17822
+ ret.z = ret.z * dl + target[2] * life;
17823
+ }
17824
+ return ret;
17825
+ };
17826
+ ParticleSystem.prototype.onEnd = function (particle) {
17827
+ };
17828
+ ParticleSystem.prototype.onIterate = function (particle) {
17829
+ };
17830
+ ParticleSystem.prototype.initPoint = function (data) {
17831
+ var options = this.options;
17832
+ var lifetime = this.lifetime;
17833
+ var shape = this.shape;
17834
+ var speed = options.startSpeed.getValue(lifetime);
17835
+ var matrix4 = options.particleFollowParent ? this.transform.getMatrix() : this.transform.getWorldMatrix();
17836
+ // 粒子的位置受发射器的位置影响,自身的旋转和缩放不受影响
17837
+ var position = matrix4.transformPoint(data.position, new Vector3());
17838
+ var transform = new Transform({
17839
+ position: position,
17840
+ valid: true,
17841
+ });
17842
+ var direction = data.direction;
17843
+ direction = matrix4.transformNormal(direction, tempDir).normalize();
17844
+ if (options.startTurbulence && options.turbulence) {
17845
+ for (var i = 0; i < 3; i++) {
17846
+ tempVec3.setElement(i, options.turbulence[i].getValue(lifetime));
17847
+ }
17848
+ tempEuler.setFromVector3(tempVec3.negate());
17849
+ var mat4 = tempMat4.setFromEuler(tempEuler);
17850
+ mat4.transformNormal(direction).normalize();
17851
+ }
17852
+ var dirX = tmpDirX;
17853
+ var dirY = tmpDirY;
17854
+ if (shape.alignSpeedDirection) {
17855
+ dirY.copyFrom(direction);
17856
+ if (!this.upDirectionWorld) {
17857
+ if (shape.upDirection) {
17858
+ this.upDirectionWorld = shape.upDirection.clone();
17859
+ }
17860
+ else {
17861
+ this.upDirectionWorld = Vector3.Z.clone();
17908
17862
  }
17863
+ matrix4.transformNormal(this.upDirectionWorld);
17909
17864
  }
17910
- else if (!options.looping) {
17911
- if (this.reusable) ;
17912
- else if (END_BEHAVIOR_DESTROY$1 === options.endBehavior) {
17913
- var node = link_1.last;
17914
- if (node && (node.content[0] - loopStartTime_1) < timePassed_1) {
17915
- this.onUpdate = function () { return _this.onDestroy(); };
17916
- }
17917
- }
17865
+ dirX.crossVectors(dirY, this.upDirectionWorld).normalize();
17866
+ // FIXME: 原先因为有精度问题,这里dirX不是0向量
17867
+ if (dirX.isZero()) {
17868
+ dirX.set(1, 0, 0);
17918
17869
  }
17919
- updateTrail();
17920
17870
  }
17871
+ else {
17872
+ dirX.set(1, 0, 0);
17873
+ dirY.set(0, 1, 0);
17874
+ }
17875
+ var sprite;
17876
+ var tsa = this.textureSheetAnimation;
17877
+ if (tsa && tsa.animate) {
17878
+ sprite = tempSprite;
17879
+ sprite[0] = tsa.animationDelay.getValue(lifetime);
17880
+ sprite[1] = tsa.animationDuration.getValue(lifetime);
17881
+ sprite[2] = tsa.cycles.getValue(lifetime);
17882
+ }
17883
+ var rot = tempRot;
17884
+ if (options.start3DRotation) {
17885
+ // @ts-expect-error
17886
+ rot.set(options.startRotationX.getValue(lifetime), options.startRotationY.getValue(lifetime), options.startRotationZ.getValue(lifetime));
17887
+ }
17888
+ else if (options.startRotation) {
17889
+ rot.set(0, 0, options.startRotation.getValue(lifetime));
17890
+ }
17891
+ else {
17892
+ rot.set(0, 0, 0);
17893
+ }
17894
+ transform.setRotation(rot.x, rot.y, rot.z);
17895
+ var color = options.startColor.getValue(lifetime);
17896
+ if (color.length === 3) {
17897
+ color[3] = 1;
17898
+ }
17899
+ var size = tempSize;
17900
+ if (options.start3DSize) {
17901
+ size.x = options.startSizeX.getValue(lifetime);
17902
+ size.y = options.startSizeY.getValue(lifetime);
17903
+ }
17904
+ else {
17905
+ var n = options.startSize.getValue(lifetime);
17906
+ var aspect = options.sizeAspect.getValue(lifetime);
17907
+ size.x = n;
17908
+ // 兼容aspect为0的情况
17909
+ size.y = aspect === 0 ? 0 : n / aspect;
17910
+ // size[1] = n / aspect;
17911
+ }
17912
+ var vel = direction.clone();
17913
+ vel.multiply(speed);
17914
+ // 粒子的大小受发射器父节点的影响
17915
+ if (!options.particleFollowParent) {
17916
+ var tempScale = new Vector3();
17917
+ this.transform.assignWorldTRS(undefined, undefined, tempScale);
17918
+ size.x *= tempScale.x;
17919
+ size.y *= tempScale.y;
17920
+ }
17921
+ transform.setScale(size.x, size.y, 1);
17922
+ return {
17923
+ size: size,
17924
+ vel: vel,
17925
+ color: color,
17926
+ delay: options.startDelay.getValue(lifetime),
17927
+ lifetime: options.startLifetime.getValue(lifetime),
17928
+ uv: randomArrItem(this.uvs, true),
17929
+ gravity: options.gravity,
17930
+ sprite: sprite,
17931
+ dirY: dirY,
17932
+ dirX: dirX,
17933
+ transform: transform,
17934
+ };
17921
17935
  };
17922
- ParticleSystem.prototype.onDestroy = function () {
17936
+ ParticleSystem.prototype.addBurst = function (burst, offsets) {
17937
+ var willAdd = false;
17938
+ if (!this.emission.bursts.includes(burst)) {
17939
+ this.emission.bursts.push(burst);
17940
+ willAdd = true;
17941
+ }
17942
+ if (willAdd && offsets instanceof Array) {
17943
+ var index = this.emission.bursts.indexOf(burst);
17944
+ this.emission.burstOffsets[index] = offsets;
17945
+ return index;
17946
+ }
17947
+ return -1;
17923
17948
  };
17924
- ParticleSystem.prototype.getParticleBoxes = function () {
17925
- var link = this.particleLink;
17926
- var mesh = this.particleMesh;
17927
- var res = [];
17928
- var maxCount = this.particleCount;
17929
- var counter = 0;
17930
- if (!(link && mesh)) {
17931
- return res;
17949
+ ParticleSystem.prototype.removeBurst = function (index) {
17950
+ if (index < this.emission.bursts.length) {
17951
+ this.emission.burstOffsets[index] = null;
17952
+ this.emission.bursts.splice(index, 1);
17932
17953
  }
17933
- var node = link.last;
17934
- var finish = false;
17935
- while (!finish) {
17936
- var currentTime = node.content[0];
17937
- var point = node.content[3];
17938
- if (currentTime > this.timePassed) {
17939
- var pos = this.getPointPosition(point);
17940
- res.push({
17941
- center: pos,
17942
- size: point.transform.scale,
17943
- });
17944
- if (node.pre) {
17945
- node = node.pre;
17946
- }
17947
- else {
17948
- finish = true;
17949
- }
17954
+ };
17955
+ ParticleSystem.prototype.createPoint = function (lifetime) {
17956
+ var generator = {
17957
+ total: this.emission.rateOverTime.getValue(lifetime),
17958
+ index: this.generatedCount,
17959
+ burstIndex: 0,
17960
+ burstCount: 0,
17961
+ };
17962
+ this.generatedCount++;
17963
+ return this.initPoint(this.shape.generate(generator));
17964
+ };
17965
+ return ParticleSystem;
17966
+ }());
17967
+ // array performance better for small memory than Float32Array
17968
+ var tempDir = new Vector3();
17969
+ var tempSize = new Vector2();
17970
+ var tempRot = new Euler();
17971
+ var tmpDirX = new Vector3();
17972
+ var tmpDirY = new Vector3();
17973
+ var tempVec3 = new Vector3();
17974
+ var tempEuler = new Euler();
17975
+ var tempSprite = [0, 0, 0];
17976
+ var tempMat4 = new Matrix4();
17977
+ function getBurstOffsets(burstOffsets) {
17978
+ var ret = {};
17979
+ if (Array.isArray(burstOffsets)) {
17980
+ burstOffsets.forEach(function (arr) {
17981
+ var isArr = arr instanceof Array;
17982
+ var index = isArr ? arr[0] : arr.index;
17983
+ var offsets = ret[index];
17984
+ if (!offsets) {
17985
+ offsets = ret[index] = [];
17950
17986
  }
17951
- counter++;
17952
- if (counter > maxCount) {
17953
- finish = true;
17987
+ if (isArr) {
17988
+ offsets.push(arr.slice(1, 4));
17954
17989
  }
17955
- }
17956
- return res;
17990
+ else {
17991
+ offsets.push([+arr.x, +arr.y, +arr.z]);
17992
+ }
17993
+ });
17994
+ }
17995
+ return ret;
17996
+ }
17997
+ function randomArrItem(arr, keepArr) {
17998
+ var index = Math.floor(Math.random() * arr.length);
17999
+ var item = arr[index];
18000
+ if (!keepArr) {
18001
+ arr.splice(index, 1);
18002
+ }
18003
+ return item;
18004
+ }
18005
+
18006
+ var ParticleVFXItem = /** @class */ (function (_super) {
18007
+ __extends(ParticleVFXItem, _super);
18008
+ function ParticleVFXItem() {
18009
+ var _this = _super !== null && _super.apply(this, arguments) || this;
18010
+ _this.destroyed = false;
18011
+ return _this;
18012
+ }
18013
+ Object.defineProperty(ParticleVFXItem.prototype, "type", {
18014
+ get: function () {
18015
+ return ItemType$1.particle;
18016
+ },
18017
+ enumerable: false,
18018
+ configurable: true
18019
+ });
18020
+ ParticleVFXItem.prototype.onConstructed = function (props) {
18021
+ this.particle = props.content;
17957
18022
  };
17958
- ParticleSystem.prototype.raycast = function (options) {
17959
- var link = this.particleLink;
17960
- var mesh = this.particleMesh;
17961
- if (!(link && mesh)) {
17962
- return;
18023
+ ParticleVFXItem.prototype.onLifetimeBegin = function (composition, particleSystem) {
18024
+ var _this = this;
18025
+ if (particleSystem) {
18026
+ particleSystem.name = this.name;
18027
+ particleSystem.start();
18028
+ particleSystem.onDestroy = function () {
18029
+ _this.destroyed = true;
18030
+ };
17963
18031
  }
17964
- var node = link.last;
17965
- var hitPositions = [];
17966
- var temp = new Vector3();
17967
- var finish = false;
17968
- if (node && node.content) {
17969
- do {
17970
- var _a = __read$3(node.content, 4), currentTime = _a[0], pointIndex = _a[1]; _a[2]; var point = _a[3];
17971
- if (currentTime > this.timePassed) {
17972
- var pos = this.getPointPosition(point);
17973
- var ray = options.ray;
17974
- var pass = false;
17975
- if (ray) {
17976
- pass = !!ray.intersectSphere({
17977
- center: pos,
17978
- radius: options.radius,
17979
- }, temp);
17980
- }
17981
- if (pass) {
17982
- if (options.removeParticle) {
17983
- mesh.removePoint(pointIndex);
17984
- this.clearPointTrail(pointIndex);
17985
- node.content[0] = 0;
17986
- }
17987
- hitPositions.push(pos);
17988
- if (!options.multiple) {
17989
- finish = true;
17990
- }
18032
+ return particleSystem;
18033
+ };
18034
+ ParticleVFXItem.prototype.onItemUpdate = function (dt, lifetime) {
18035
+ var _a;
18036
+ if (this.content) {
18037
+ var hide = !this.visible;
18038
+ var parentItem = this.parentId && ((_a = this.composition) === null || _a === void 0 ? void 0 : _a.getItemByID(this.parentId));
18039
+ if (!hide && parentItem) {
18040
+ var parentData = parentItem.getRenderData();
18041
+ if (parentData) {
18042
+ if (!parentData.visible) {
18043
+ hide = false;
17991
18044
  }
17992
18045
  }
17993
- else {
17994
- break;
17995
- }
17996
- // @ts-expect-error
17997
- } while ((node = node.pre) && !finish);
18046
+ }
18047
+ if (hide) {
18048
+ this.content.setVisible(false);
18049
+ }
18050
+ else {
18051
+ this.content.setVisible(true);
18052
+ this.content.onUpdate(dt);
18053
+ }
17998
18054
  }
17999
- return hitPositions;
18000
18055
  };
18001
- ParticleSystem.prototype.clearPointTrail = function (pointIndex) {
18002
- var _a;
18003
- if (this.trails && this.trails.dieWithParticles) {
18004
- (_a = this.trailMesh) === null || _a === void 0 ? void 0 : _a.clearTrail(pointIndex);
18056
+ ParticleVFXItem.prototype.onItemRemoved = function (composition, content) {
18057
+ if (content) {
18058
+ composition.destroyTextures(content.getTextures());
18059
+ content.meshes.forEach(function (mesh) { return mesh.dispose({ material: { textures: exports.DestroyOptions.keep } }); });
18005
18060
  }
18006
18061
  };
18007
- ParticleSystem.prototype.updatePointTrail = function (pointIndex, emitterLifetime, point, startTime) {
18008
- if (!this.trailMesh) {
18009
- return;
18062
+ /**
18063
+ * @internal
18064
+ */
18065
+ ParticleVFXItem.prototype.setColor = function (r, g, b, a) {
18066
+ this.content.setColor(r, g, b, a);
18067
+ };
18068
+ ParticleVFXItem.prototype.setOpacity = function (opacity) {
18069
+ this.content.setOpacity(opacity);
18070
+ };
18071
+ ParticleVFXItem.prototype.stopParticleEmission = function () {
18072
+ if (this.content) {
18073
+ this.content.emissionStopped = true;
18010
18074
  }
18011
- var trails = this.trails;
18012
- var particleMesh = this.particleMesh;
18013
- var position = this.getPointPosition(point);
18014
- var color = trails.inheritParticleColor ? particleMesh.getPointColor(pointIndex) : [1, 1, 1, 1];
18015
- var size = point.transform.getWorldScale().toArray();
18016
- var width = 1;
18017
- var lifetime = trails.lifetime.getValue(emitterLifetime);
18018
- if (trails.sizeAffectsWidth) {
18019
- width *= size[0];
18075
+ };
18076
+ ParticleVFXItem.prototype.resumeParticleEmission = function () {
18077
+ if (this.content) {
18078
+ this.content.emissionStopped = false;
18020
18079
  }
18021
- if (trails.sizeAffectsLifetime) {
18022
- lifetime *= size[0];
18080
+ };
18081
+ ParticleVFXItem.prototype.doCreateContent = function (composition) {
18082
+ assertExist(this.particle);
18083
+ return new ParticleSystem(this.particle, composition.getRendererOptions(), this);
18084
+ };
18085
+ ParticleVFXItem.prototype.isEnded = function (now) {
18086
+ return _super.prototype.isEnded.call(this, now) && this.destroyed;
18087
+ };
18088
+ ParticleVFXItem.prototype.getBoundingBox = function () {
18089
+ var pt = this.content;
18090
+ if (!pt) {
18091
+ return;
18023
18092
  }
18024
- if (trails.parentAffectsPosition && this.transform.parentTransform) {
18025
- position.add(this.transform.parentTransform.position);
18026
- var pos = this.trailMesh.getPointStartPos(pointIndex);
18027
- if (pos) {
18028
- position.subtract(pos);
18029
- }
18093
+ else {
18094
+ var area = pt.getParticleBoxes();
18095
+ return {
18096
+ type: exports.HitTestType.sphere,
18097
+ area: area,
18098
+ };
18030
18099
  }
18031
- this.trailMesh.addPoint(pointIndex, position, {
18032
- color: color,
18033
- lifetime: lifetime,
18034
- size: width,
18035
- time: startTime,
18036
- });
18037
18100
  };
18038
- ParticleSystem.prototype.getPointPosition = function (point) {
18039
- var transform = point.transform, vel = point.vel, lifetime = point.lifetime, delay = point.delay, _a = point.gravity, gravity = _a === void 0 ? [] : _a;
18040
- var forceTarget = this.options.forceTarget;
18041
- var time = this.lastUpdate - delay;
18042
- var tempPos = new Vector3();
18043
- var acc = Vector3.fromArray(gravity);
18044
- transform.assignWorldTRS(tempPos);
18045
- var ret = calculateTranslation(new Vector3(), this.options, acc, time, lifetime, tempPos, vel);
18046
- if (forceTarget) {
18047
- var target = forceTarget.target || [0, 0, 0];
18048
- var life = forceTarget.curve.getValue(time / lifetime);
18049
- var dl = 1 - life;
18050
- ret.x = ret.x * dl + target[0] * life;
18051
- ret.y = ret.y * dl + target[1] * life;
18052
- ret.z = ret.z * dl + target[2] * life;
18101
+ ParticleVFXItem.prototype.getHitTestParams = function (force) {
18102
+ var _this = this;
18103
+ var _a;
18104
+ var interactParams = (_a = this.content) === null || _a === void 0 ? void 0 : _a.interaction;
18105
+ if (force || interactParams) {
18106
+ return {
18107
+ type: exports.HitTestType.custom,
18108
+ collect: function (ray) {
18109
+ var _a;
18110
+ return (_a = _this.content) === null || _a === void 0 ? void 0 : _a.raycast({
18111
+ radius: (interactParams === null || interactParams === void 0 ? void 0 : interactParams.radius) || 0.4,
18112
+ multiple: !!(interactParams === null || interactParams === void 0 ? void 0 : interactParams.multiple),
18113
+ removeParticle: (interactParams === null || interactParams === void 0 ? void 0 : interactParams.behavior) === ParticleInteractionBehavior$1.removeParticle,
18114
+ ray: ray,
18115
+ });
18116
+ },
18117
+ };
18053
18118
  }
18054
- return ret;
18055
18119
  };
18056
- ParticleSystem.prototype.onEnd = function (particle) {
18057
- };
18058
- ParticleSystem.prototype.onIterate = function (particle) {
18059
- };
18060
- ParticleSystem.prototype.initPoint = function (data) {
18061
- var options = this.options;
18062
- var lifetime = this.lifetime;
18063
- var shape = this.shape;
18064
- var speed = options.startSpeed.getValue(lifetime);
18065
- var matrix4 = options.particleFollowParent ? this.transform.getMatrix() : this.transform.getWorldMatrix();
18066
- // 粒子的位置受发射器的位置影响,自身的旋转和缩放不受影响
18067
- var position = matrix4.transformPoint(data.position, new Vector3());
18068
- var transform = new Transform({
18069
- position: position,
18070
- valid: true,
18071
- });
18072
- var direction = data.direction;
18073
- direction = matrix4.transformNormal(direction, tempDir).normalize();
18074
- if (options.startTurbulence && options.turbulence) {
18075
- for (var i = 0; i < 3; i++) {
18076
- tempVec3.setElement(i, options.turbulence[i].getValue(lifetime));
18077
- }
18078
- tempEuler.setFromVector3(tempVec3.negate());
18079
- var mat4 = tempMat4.setFromEuler(tempEuler);
18080
- mat4.transformNormal(direction).normalize();
18120
+ return ParticleVFXItem;
18121
+ }(VFXItem));
18122
+ var particleUniformTypeMap = {
18123
+ 'uSprite': 'vec4',
18124
+ 'uParams': 'vec4',
18125
+ 'uAcceleration': 'vec4',
18126
+ 'uGravityModifierValue': 'vec4',
18127
+ 'uOpacityOverLifetimeValue': 'vec4',
18128
+ 'uRXByLifeTimeValue': 'vec4',
18129
+ 'uRYByLifeTimeValue': 'vec4',
18130
+ 'uRZByLifeTimeValue': 'vec4',
18131
+ 'uLinearXByLifetimeValue': 'vec4',
18132
+ 'uLinearYByLifetimeValue': 'vec4',
18133
+ 'uLinearZByLifetimeValue': 'vec4',
18134
+ 'uSpeedLifetimeValue': 'vec4',
18135
+ 'uOrbXByLifetimeValue': 'vec4',
18136
+ 'uOrbYByLifetimeValue': 'vec4',
18137
+ 'uOrbZByLifetimeValue': 'vec4',
18138
+ 'uSizeByLifetimeValue': 'vec4',
18139
+ 'uSizeYByLifetimeValue': 'vec4',
18140
+ 'uColorParams': 'vec4',
18141
+ 'uFSprite': 'vec4',
18142
+ 'uPreviewColor': 'vec4',
18143
+ 'uVCurveValues': 'vec4Array',
18144
+ 'uFCurveValues': 'vec4',
18145
+ 'uFinalTarget': 'vec3',
18146
+ 'uForceCurve': 'vec4',
18147
+ 'uOrbCenter': 'vec3',
18148
+ 'uTexOffset': 'vec2',
18149
+ 'uPeriodValue': 'vec4',
18150
+ 'uMovementValue': 'vec4',
18151
+ 'uStrengthValue': 'vec4',
18152
+ 'uWaveParams': 'vec4',
18153
+ };
18154
+
18155
+ var ParticleMesh = /** @class */ (function () {
18156
+ function ParticleMesh(props, rendererOptions) {
18157
+ var _a, _b, _c, _d;
18158
+ this.particleCount = 0;
18159
+ var engine = rendererOptions.composition.getEngine();
18160
+ var env = ((_a = engine.renderer) !== null && _a !== void 0 ? _a : {}).env;
18161
+ var speedOverLifetime = props.speedOverLifetime, colorOverLifetime = props.colorOverLifetime, linearVelOverLifetime = props.linearVelOverLifetime, orbitalVelOverLifetime = props.orbitalVelOverLifetime, sizeOverLifetime = props.sizeOverLifetime, rotationOverLifetime = props.rotationOverLifetime, sprite = props.sprite, gravityModifier = props.gravityModifier, maxCount = props.maxCount, duration = props.duration, textureFlip = props.textureFlip, useSprite = props.useSprite, name = props.name, filter = props.filter, gravity = props.gravity, forceTarget = props.forceTarget, side = props.side, occlusion = props.occlusion, anchor = props.anchor, blending = props.blending, maskMode = props.maskMode, mask = props.mask, transparentOcclusion = props.transparentOcclusion, listIndex = props.listIndex, meshSlots = props.meshSlots, _e = props.renderMode, renderMode = _e === void 0 ? 0 : _e, _f = props.diffuse, diffuse = _f === void 0 ? Texture.createWithData(engine) : _f;
18162
+ var detail = engine.gpuCapability.detail;
18163
+ var halfFloatTexture = detail.halfFloatTexture, maxVertexUniforms = detail.maxVertexUniforms;
18164
+ var marcos = [
18165
+ ['RENDER_MODE', +renderMode],
18166
+ ['PRE_MULTIPLY_ALPHA', false],
18167
+ ['ENV_EDITOR', env === PLAYER_OPTIONS_ENV_EDITOR],
18168
+ ];
18169
+ var level = engine.gpuCapability.level;
18170
+ var vertexKeyFrameMeta = createKeyFrameMeta();
18171
+ var fragmentKeyFrameMeta = createKeyFrameMeta();
18172
+ var enableVertexTexture = maxVertexUniforms > 0;
18173
+ var uniformValues = {};
18174
+ var vertex_lookup_texture = 0;
18175
+ var shaderCacheId = 0;
18176
+ var particleDefine;
18177
+ var useOrbitalVel;
18178
+ this.useSprite = useSprite;
18179
+ if (enableVertexTexture) {
18180
+ marcos.push(['ENABLE_VERTEX_TEXTURE', true]);
18081
18181
  }
18082
- var dirX = tmpDirX;
18083
- var dirY = tmpDirY;
18084
- if (shape.alignSpeedDirection) {
18085
- dirY.copyFrom(direction);
18086
- if (!this.upDirectionWorld) {
18087
- if (shape.upDirection) {
18088
- this.upDirectionWorld = shape.upDirection.clone();
18182
+ if (speedOverLifetime) {
18183
+ marcos.push(['SPEED_OVER_LIFETIME', true]);
18184
+ shaderCacheId |= 1 << 1;
18185
+ uniformValues.uSpeedLifetimeValue = speedOverLifetime.toUniform(vertexKeyFrameMeta);
18186
+ }
18187
+ if (sprite === null || sprite === void 0 ? void 0 : sprite.animate) {
18188
+ marcos.push(['USE_SPRITE', true]);
18189
+ shaderCacheId |= 1 << 2;
18190
+ uniformValues.uFSprite = uniformValues.uSprite = new Float32Array([sprite.col, sprite.row, sprite.total, sprite.blend ? 1 : 0]);
18191
+ this.useSprite = true;
18192
+ }
18193
+ if (filter && filter.name !== FILTER_NAME_NONE) {
18194
+ marcos.push(['USE_FILTER', true]);
18195
+ shaderCacheId |= 1 << 3;
18196
+ var filterDefine = createFilter(filter, rendererOptions.composition);
18197
+ if (!filterDefine.particle) {
18198
+ throw new Error("particle filter ".concat(filter.name, " not implement"));
18199
+ }
18200
+ particleDefine = filterDefine.particle;
18201
+ Object.keys((_b = particleDefine.uniforms) !== null && _b !== void 0 ? _b : {}).forEach(function (uName) {
18202
+ var _a;
18203
+ var getter = (_a = particleDefine.uniforms) === null || _a === void 0 ? void 0 : _a[uName];
18204
+ if (uniformValues[uName]) {
18205
+ throw new Error('conflict uniform name:' + uName);
18089
18206
  }
18090
- else {
18091
- this.upDirectionWorld = Vector3.Z.clone();
18207
+ uniformValues[uName] = getter === null || getter === void 0 ? void 0 : getter.toUniform(vertexKeyFrameMeta);
18208
+ });
18209
+ Object.keys((_c = particleDefine.uniformValues) !== null && _c !== void 0 ? _c : {}).forEach(function (uName) {
18210
+ var _a;
18211
+ var val = (_a = particleDefine.uniformValues) === null || _a === void 0 ? void 0 : _a[uName];
18212
+ if (uniformValues[uName]) {
18213
+ throw new Error('conflict uniform name:' + uName);
18092
18214
  }
18093
- matrix4.transformNormal(this.upDirectionWorld);
18215
+ uniformValues[uName] = val;
18216
+ });
18217
+ }
18218
+ if (colorOverLifetime === null || colorOverLifetime === void 0 ? void 0 : colorOverLifetime.color) {
18219
+ marcos.push(['COLOR_OVER_LIFETIME', true]);
18220
+ shaderCacheId |= 1 << 4;
18221
+ uniformValues.uColorOverLifetime = colorOverLifetime.color instanceof Texture ? colorOverLifetime.color : Texture.createWithData(engine, imageDataFromGradient(colorOverLifetime.color));
18222
+ }
18223
+ if (colorOverLifetime === null || colorOverLifetime === void 0 ? void 0 : colorOverLifetime.opacity) {
18224
+ uniformValues.uOpacityOverLifetimeValue = colorOverLifetime.opacity.toUniform(vertexKeyFrameMeta);
18225
+ }
18226
+ else {
18227
+ uniformValues.uOpacityOverLifetimeValue = createValueGetter(1).toUniform(vertexKeyFrameMeta);
18228
+ }
18229
+ ['x', 'y', 'z'].forEach(function (pro, i) {
18230
+ var defL = 0;
18231
+ var defO = 0;
18232
+ if (linearVelOverLifetime === null || linearVelOverLifetime === void 0 ? void 0 : linearVelOverLifetime[pro]) {
18233
+ uniformValues["uLinear".concat(pro.toUpperCase(), "ByLifetimeValue")] = linearVelOverLifetime[pro].toUniform(vertexKeyFrameMeta);
18234
+ defL = 1;
18235
+ shaderCacheId |= 1 << (7 + i);
18236
+ linearVelOverLifetime.enabled = true;
18094
18237
  }
18095
- dirX.crossVectors(dirY, this.upDirectionWorld).normalize();
18096
- // FIXME: 原先因为有精度问题,这里dirX不是0向量
18097
- if (dirX.isZero()) {
18098
- dirX.set(1, 0, 0);
18238
+ marcos.push(["LINEAR_VEL_".concat(pro.toUpperCase()), defL]);
18239
+ if (orbitalVelOverLifetime === null || orbitalVelOverLifetime === void 0 ? void 0 : orbitalVelOverLifetime[pro]) {
18240
+ uniformValues["uOrb".concat(pro.toUpperCase(), "ByLifetimeValue")] = orbitalVelOverLifetime[pro].toUniform(vertexKeyFrameMeta);
18241
+ defO = 1;
18242
+ shaderCacheId |= 1 << (10 + i);
18243
+ useOrbitalVel = true;
18244
+ orbitalVelOverLifetime.enabled = true;
18245
+ }
18246
+ marcos.push(["ORB_VEL_".concat(pro.toUpperCase()), defO]);
18247
+ });
18248
+ if (linearVelOverLifetime === null || linearVelOverLifetime === void 0 ? void 0 : linearVelOverLifetime.asMovement) {
18249
+ marcos.push(['AS_LINEAR_MOVEMENT', true]);
18250
+ shaderCacheId |= 1 << 5;
18251
+ }
18252
+ if (useOrbitalVel) {
18253
+ if (orbitalVelOverLifetime === null || orbitalVelOverLifetime === void 0 ? void 0 : orbitalVelOverLifetime.asRotation) {
18254
+ marcos.push(['AS_ORBITAL_MOVEMENT', true]);
18255
+ shaderCacheId |= 1 << 6;
18099
18256
  }
18257
+ uniformValues.uOrbCenter = new Float32Array((orbitalVelOverLifetime === null || orbitalVelOverLifetime === void 0 ? void 0 : orbitalVelOverLifetime.center) || [0, 0, 0]);
18100
18258
  }
18101
- else {
18102
- dirX.set(1, 0, 0);
18103
- dirY.set(0, 1, 0);
18259
+ uniformValues.uSizeByLifetimeValue = sizeOverLifetime === null || sizeOverLifetime === void 0 ? void 0 : sizeOverLifetime.x.toUniform(vertexKeyFrameMeta);
18260
+ if (sizeOverLifetime === null || sizeOverLifetime === void 0 ? void 0 : sizeOverLifetime.separateAxes) {
18261
+ marcos.push(['SIZE_Y_BY_LIFE', 1]);
18262
+ shaderCacheId |= 1 << 14;
18263
+ uniformValues.uSizeYByLifetimeValue = (_d = sizeOverLifetime === null || sizeOverLifetime === void 0 ? void 0 : sizeOverLifetime.y) === null || _d === void 0 ? void 0 : _d.toUniform(vertexKeyFrameMeta);
18104
18264
  }
18105
- var sprite;
18106
- var tsa = this.textureSheetAnimation;
18107
- if (tsa && tsa.animate) {
18108
- sprite = tempSprite;
18109
- sprite[0] = tsa.animationDelay.getValue(lifetime);
18110
- sprite[1] = tsa.animationDuration.getValue(lifetime);
18111
- sprite[2] = tsa.cycles.getValue(lifetime);
18265
+ if (rotationOverLifetime === null || rotationOverLifetime === void 0 ? void 0 : rotationOverLifetime.z) {
18266
+ uniformValues.uRZByLifeTimeValue = rotationOverLifetime.z.toUniform(vertexKeyFrameMeta);
18267
+ shaderCacheId |= 1 << 15;
18268
+ marcos.push(['ROT_Z_LIFETIME', 1]);
18112
18269
  }
18113
- var rot = tempRot;
18114
- if (options.start3DRotation) {
18115
- // @ts-expect-error
18116
- rot.set(options.startRotationX.getValue(lifetime), options.startRotationY.getValue(lifetime), options.startRotationZ.getValue(lifetime));
18270
+ if (rotationOverLifetime === null || rotationOverLifetime === void 0 ? void 0 : rotationOverLifetime.x) {
18271
+ uniformValues.uRXByLifeTimeValue = rotationOverLifetime.x.toUniform(vertexKeyFrameMeta);
18272
+ shaderCacheId |= 1 << 16;
18273
+ marcos.push(['ROT_X_LIFETIME', 1]);
18117
18274
  }
18118
- else if (options.startRotation) {
18119
- rot.set(0, 0, options.startRotation.getValue(lifetime));
18275
+ if (rotationOverLifetime === null || rotationOverLifetime === void 0 ? void 0 : rotationOverLifetime.y) {
18276
+ uniformValues.uRYByLifeTimeValue = rotationOverLifetime.y.toUniform(vertexKeyFrameMeta);
18277
+ shaderCacheId |= 1 << 17;
18278
+ marcos.push(['ROT_Y_LIFETIME', 1]);
18120
18279
  }
18121
- else {
18122
- rot.set(0, 0, 0);
18280
+ if (rotationOverLifetime === null || rotationOverLifetime === void 0 ? void 0 : rotationOverLifetime.asRotation) {
18281
+ marcos.push(['ROT_LIFETIME_AS_MOVEMENT', 1]);
18282
+ shaderCacheId |= 1 << 18;
18123
18283
  }
18124
- transform.setRotation(rot.x, rot.y, rot.z);
18125
- var color = options.startColor.getValue(lifetime);
18126
- if (color.length === 3) {
18127
- color[3] = 1;
18284
+ uniformValues.uGravityModifierValue = gravityModifier.toUniform(vertexKeyFrameMeta);
18285
+ if (forceTarget) {
18286
+ marcos.push(['FINAL_TARGET', true]);
18287
+ shaderCacheId |= 1 << 19;
18288
+ uniformValues.uFinalTarget = new Float32Array(forceTarget.target || [0, 0, 0]);
18289
+ uniformValues.uForceCurve = forceTarget.curve.toUniform(vertexKeyFrameMeta);
18128
18290
  }
18129
- var size = tempSize;
18130
- if (options.start3DSize) {
18131
- size.x = options.startSizeX.getValue(lifetime);
18132
- size.y = options.startSizeY.getValue(lifetime);
18291
+ if (halfFloatTexture && fragmentKeyFrameMeta.max) {
18292
+ shaderCacheId |= 1 << 20;
18293
+ uniformValues.uFCurveValueTexture = generateHalfFloatTexture(engine, ValueGetter.getAllData(fragmentKeyFrameMeta, true), fragmentKeyFrameMeta.index, 1);
18133
18294
  }
18134
18295
  else {
18135
- var n = options.startSize.getValue(lifetime);
18136
- var aspect = options.sizeAspect.getValue(lifetime);
18137
- size.x = n;
18138
- // 兼容aspect为0的情况
18139
- size.y = aspect === 0 ? 0 : n / aspect;
18140
- // size[1] = n / aspect;
18296
+ uniformValues.uFCurveValues = ValueGetter.getAllData(fragmentKeyFrameMeta);
18141
18297
  }
18142
- var vel = direction.clone();
18143
- vel.multiply(speed);
18144
- // 粒子的大小受发射器父节点的影响
18145
- if (!options.particleFollowParent) {
18146
- var tempScale = new Vector3();
18147
- this.transform.assignWorldTRS(undefined, undefined, tempScale);
18148
- size.x *= tempScale.x;
18149
- size.y *= tempScale.y;
18298
+ var vertexCurveTexture = vertexKeyFrameMeta.max + vertexKeyFrameMeta.curves.length - 32 > maxVertexUniforms;
18299
+ // if (getConfig(RENDER_PREFER_LOOKUP_TEXTURE)) {
18300
+ // vertexCurveTexture = true;
18301
+ // }
18302
+ if (level === 2) {
18303
+ vertexKeyFrameMeta.max = -1;
18304
+ vertexKeyFrameMeta.index = meshSlots ? meshSlots[0] : getSlot(vertexKeyFrameMeta.index);
18305
+ if (fragmentKeyFrameMeta.index > 0) {
18306
+ fragmentKeyFrameMeta.max = -1;
18307
+ fragmentKeyFrameMeta.index = meshSlots ? meshSlots[1] : getSlot(fragmentKeyFrameMeta.index);
18308
+ }
18150
18309
  }
18151
- transform.setScale(size.x, size.y, 1);
18152
- return {
18153
- size: size,
18154
- vel: vel,
18155
- color: color,
18156
- delay: options.startDelay.getValue(lifetime),
18157
- lifetime: options.startLifetime.getValue(lifetime),
18158
- uv: randomArrItem(this.uvs, true),
18159
- gravity: options.gravity,
18160
- sprite: sprite,
18161
- dirY: dirY,
18162
- dirX: dirX,
18163
- transform: transform,
18164
- };
18165
- };
18166
- ParticleSystem.prototype.addBurst = function (burst, offsets) {
18167
- var willAdd = false;
18168
- if (!this.emission.bursts.includes(burst)) {
18169
- this.emission.bursts.push(burst);
18170
- willAdd = true;
18310
+ if (vertexCurveTexture && halfFloatTexture && enableVertexTexture) {
18311
+ var tex = generateHalfFloatTexture(engine, ValueGetter.getAllData(vertexKeyFrameMeta, true), vertexKeyFrameMeta.index, 1);
18312
+ uniformValues.uVCurveValueTexture = tex;
18313
+ vertex_lookup_texture = 1;
18171
18314
  }
18172
- if (willAdd && offsets instanceof Array) {
18173
- var index = this.emission.bursts.indexOf(burst);
18174
- this.emission.burstOffsets[index] = offsets;
18175
- return index;
18315
+ else {
18316
+ uniformValues.uVCurveValues = ValueGetter.getAllData(vertexKeyFrameMeta);
18176
18317
  }
18177
- return -1;
18178
- };
18179
- ParticleSystem.prototype.removeBurst = function (index) {
18180
- if (index < this.emission.bursts.length) {
18181
- this.emission.burstOffsets[index] = null;
18182
- this.emission.bursts.splice(index, 1);
18318
+ var shaderCache = ['-p:', renderMode, shaderCacheId, vertexKeyFrameMeta.index, vertexKeyFrameMeta.max, fragmentKeyFrameMeta.index, fragmentKeyFrameMeta.max].join('+');
18319
+ marcos.push(['VERT_CURVE_VALUE_COUNT', vertexKeyFrameMeta.index], ['FRAG_CURVE_VALUE_COUNT', fragmentKeyFrameMeta.index], ['VERT_MAX_KEY_FRAME_COUNT', vertexKeyFrameMeta.max], ['FRAG_MAX_KEY_FRAME_COUNT', fragmentKeyFrameMeta.max]);
18320
+ var fragment = filter ? particleFrag.replace(/#pragma\s+FILTER_FRAG/, particleDefine.fragment) : particleFrag;
18321
+ var originalVertex = "#define LOOKUP_TEXTURE_CURVE ".concat(vertex_lookup_texture, "\n").concat(particleVert);
18322
+ var vertex = filter ? originalVertex.replace(/#pragma\s+FILTER_VERT/, particleDefine.vertex || 'void filterMain(float t){}\n') : originalVertex;
18323
+ var shader = {
18324
+ fragment: createShaderWithMarcos(marcos, fragment, exports.ShaderType.fragment, level),
18325
+ vertex: createShaderWithMarcos(marcos, vertex, exports.ShaderType.vertex, level),
18326
+ glslVersion: level === 1 ? exports.GLSLVersion.GLSL1 : exports.GLSLVersion.GLSL3,
18327
+ shared: true,
18328
+ cacheId: shaderCache,
18329
+ marcos: marcos,
18330
+ name: "particle#".concat(name),
18331
+ };
18332
+ if (filter) {
18333
+ shader.cacheId += filter.name;
18183
18334
  }
18184
- };
18185
- ParticleSystem.prototype.createPoint = function (lifetime) {
18186
- var generator = {
18187
- total: this.emission.rateOverTime.getValue(lifetime),
18188
- index: this.generatedCount,
18189
- burstIndex: 0,
18190
- burstCount: 0,
18335
+ var mtlOptions = {
18336
+ shader: shader,
18337
+ uniformSemantics: {
18338
+ effects_MatrixV: 'VIEW',
18339
+ effects_MatrixVP: 'VIEWPROJECTION',
18340
+ uEditorTransform: 'EDITOR_TRANSFORM',
18341
+ effects_ObjectToWorld: 'MODEL',
18342
+ },
18191
18343
  };
18192
- this.generatedCount++;
18193
- return this.initPoint(this.shape.generate(generator));
18194
- };
18195
- return ParticleSystem;
18196
- }());
18197
- // array performance better for small memory than Float32Array
18198
- var tempDir = new Vector3();
18199
- var tempSize = new Vector2();
18200
- var tempRot = new Euler();
18201
- var tmpDirX = new Vector3();
18202
- var tmpDirY = new Vector3();
18203
- var tempVec3 = new Vector3();
18204
- var tempEuler = new Euler();
18205
- var tempSprite = [0, 0, 0];
18206
- var tempMat4 = new Matrix4();
18207
- function getBurstOffsets(burstOffsets) {
18208
- var ret = {};
18209
- if (Array.isArray(burstOffsets)) {
18210
- burstOffsets.forEach(function (arr) {
18211
- var isArr = arr instanceof Array;
18212
- var index = isArr ? arr[0] : arr.index;
18213
- var offsets = ret[index];
18214
- if (!offsets) {
18215
- offsets = ret[index] = [];
18216
- }
18217
- if (isArr) {
18218
- offsets.push(arr.slice(1, 4));
18344
+ var preMulAlpha = getPreMultiAlpha(blending);
18345
+ uniformValues.uTexOffset = new Float32Array(diffuse ? [1 / diffuse.getWidth(), 1 / diffuse.getHeight()] : [0, 0]);
18346
+ uniformValues.uMaskTex = diffuse;
18347
+ uniformValues.uColorParams = new Float32Array([diffuse ? 1 : 0, +preMulAlpha, 0, +(!!occlusion && !transparentOcclusion)]);
18348
+ uniformValues.uParams = [0, duration, 0, 0];
18349
+ uniformValues.uAcceleration = [(gravity === null || gravity === void 0 ? void 0 : gravity[0]) || 0, (gravity === null || gravity === void 0 ? void 0 : gravity[1]) || 0, (gravity === null || gravity === void 0 ? void 0 : gravity[2]) || 0, 0];
18350
+ // mtlOptions.uniformValues = uniformValues;
18351
+ var material = Material.create(engine, mtlOptions);
18352
+ material.blending = true;
18353
+ material.depthTest = true;
18354
+ material.depthMask = !!(occlusion);
18355
+ material.stencilRef = mask ? [mask, mask] : undefined;
18356
+ setMaskMode(material, maskMode);
18357
+ setBlendMode(material, blending);
18358
+ setSideMode(material, side);
18359
+ Object.keys(uniformValues).map(function (name) {
18360
+ var value = uniformValues[name];
18361
+ if (value instanceof Texture) {
18362
+ material.setTexture(name, value);
18363
+ return;
18219
18364
  }
18220
- else {
18221
- offsets.push([+arr.x, +arr.y, +arr.z]);
18365
+ var res = [];
18366
+ switch (particleUniformTypeMap[name]) {
18367
+ case 'vec4':
18368
+ material.setVector4(name, Vector4.fromArray(value));
18369
+ break;
18370
+ case 'vec3':
18371
+ material.setVector3(name, Vector3.fromArray(value));
18372
+ break;
18373
+ case 'vec2':
18374
+ material.setVector2(name, Vector2.fromArray(value));
18375
+ break;
18376
+ case 'vec4Array':
18377
+ for (var i = 0; i < value.length; i = i + 4) {
18378
+ var v = new Vector4(value[i], value[i + 1], value[i + 2], value[i + 3]);
18379
+ res.push(v);
18380
+ }
18381
+ material.setVector4Array(name, res);
18382
+ res.length = 0;
18383
+ break;
18384
+ default:
18385
+ console.warn("uniform ".concat(name, "'s type not in typeMap"));
18222
18386
  }
18223
18387
  });
18388
+ material.setVector3('emissionColor', new Vector3(0, 0, 0));
18389
+ material.setFloat('emissionIntensity', 0.0);
18390
+ var geometry = Geometry.create(engine, generateGeometryProps(maxCount * 4, this.useSprite, "particle#".concat(name)));
18391
+ var mesh = Mesh.create(engine, {
18392
+ name: "MParticle_".concat(name),
18393
+ priority: listIndex,
18394
+ material: material,
18395
+ geometry: geometry,
18396
+ });
18397
+ this.anchor = anchor;
18398
+ this.mesh = mesh;
18399
+ this.geometry = mesh.firstGeometry();
18400
+ this.forceTarget = forceTarget;
18401
+ this.sizeOverLifetime = sizeOverLifetime;
18402
+ this.speedOverLifetime = speedOverLifetime;
18403
+ this.linearVelOverLifetime = linearVelOverLifetime;
18404
+ this.orbitalVelOverLifetime = orbitalVelOverLifetime;
18405
+ this.orbitalVelOverLifetime = orbitalVelOverLifetime;
18406
+ this.gravityModifier = gravityModifier;
18407
+ this.maxCount = maxCount;
18408
+ this.duration = duration;
18409
+ this.textureOffsets = textureFlip ? [0, 0, 1, 0, 0, 1, 1, 1] : [0, 1, 0, 0, 1, 1, 1, 0];
18224
18410
  }
18225
- return ret;
18226
- }
18227
- function randomArrItem(arr, keepArr) {
18228
- var index = Math.floor(Math.random() * arr.length);
18229
- var item = arr[index];
18230
- if (!keepArr) {
18231
- arr.splice(index, 1);
18232
- }
18233
- return item;
18234
- }
18235
-
18236
- var ParticleVFXItem = /** @class */ (function (_super) {
18237
- __extends(ParticleVFXItem, _super);
18238
- function ParticleVFXItem() {
18239
- var _this = _super !== null && _super.apply(this, arguments) || this;
18240
- _this.destroyed = false;
18241
- return _this;
18242
- }
18243
- Object.defineProperty(ParticleVFXItem.prototype, "type", {
18411
+ Object.defineProperty(ParticleMesh.prototype, "time", {
18244
18412
  get: function () {
18245
- return ItemType$1.particle;
18413
+ var value = this.mesh.material.getVector4('uParams');
18414
+ return value.x;
18415
+ },
18416
+ set: function (v) {
18417
+ this.mesh.material.setVector4('uParams', new Vector4(+v, this.duration, 0, 0));
18246
18418
  },
18247
18419
  enumerable: false,
18248
18420
  configurable: true
18249
18421
  });
18250
- ParticleVFXItem.prototype.onConstructed = function (props) {
18251
- this.particle = props.content;
18422
+ ParticleMesh.prototype.getPointColor = function (index) {
18423
+ var data = this.geometry.getAttributeData('aRot');
18424
+ var i = index * 32 + 4;
18425
+ return [data[i], data[i + 1], data[i + 2], data[i + 3]];
18252
18426
  };
18253
- ParticleVFXItem.prototype.onLifetimeBegin = function (composition, particleSystem) {
18254
- var _this = this;
18255
- if (particleSystem) {
18256
- particleSystem.name = this.name;
18257
- particleSystem.start();
18258
- particleSystem.onDestroy = function () {
18259
- _this.destroyed = true;
18260
- };
18427
+ /**
18428
+ * 待废弃
18429
+ * @deprecated - 使用 `particle-system.getPointPosition` 替代
18430
+ */
18431
+ ParticleMesh.prototype.getPointPosition = function (index) {
18432
+ var geo = this.geometry;
18433
+ var posIndex = index * 48;
18434
+ var posData = geo.getAttributeData('aPos');
18435
+ var offsetData = geo.getAttributeData('aOffset');
18436
+ var time = this.time - offsetData[index * 16 + 2];
18437
+ var pointDur = offsetData[index * 16 + 3];
18438
+ var mtl = this.mesh.material;
18439
+ var acc = mtl.getVector4('uAcceleration').toVector3();
18440
+ var pos = Vector3.fromArray(posData, posIndex);
18441
+ var vel = Vector3.fromArray(posData, posIndex + 3);
18442
+ var ret = calculateTranslation(new Vector3(), this, acc, time, pointDur, pos, vel);
18443
+ if (this.forceTarget) {
18444
+ var target = mtl.getVector3('uFinalTarget');
18445
+ var life = this.forceTarget.curve.getValue(time / pointDur);
18446
+ var dl = 1 - life;
18447
+ ret.x = ret.x * dl + target.x * life;
18448
+ ret.y = ret.y * dl + target.y * life;
18449
+ ret.z = ret.z * dl + target.z * life;
18261
18450
  }
18262
- return particleSystem;
18451
+ return ret;
18263
18452
  };
18264
- ParticleVFXItem.prototype.onItemUpdate = function (dt, lifetime) {
18265
- var _a;
18266
- if (this.content) {
18267
- var hide = !this.visible;
18268
- var parentItem = this.parentId && ((_a = this.composition) === null || _a === void 0 ? void 0 : _a.getItemByID(this.parentId));
18269
- if (!hide && parentItem) {
18270
- var parentData = parentItem.getRenderData();
18271
- if (parentData) {
18272
- if (!parentData.visible) {
18273
- hide = false;
18274
- }
18453
+ ParticleMesh.prototype.clearPoints = function () {
18454
+ this.resetGeometryData(this.geometry);
18455
+ this.particleCount = 0;
18456
+ this.geometry.setDrawCount(0);
18457
+ this.maxParticleBufferCount = 0;
18458
+ };
18459
+ ParticleMesh.prototype.resetGeometryData = function (geometry) {
18460
+ var names = geometry.getAttributeNames();
18461
+ var index = geometry.getIndexData();
18462
+ for (var i = 0; i < names.length; i++) {
18463
+ var name_1 = names[i];
18464
+ var data = geometry.getAttributeData(name_1);
18465
+ if (data) {
18466
+ // @ts-expect-error
18467
+ geometry.setAttributeData(name_1, new data.constructor(0));
18468
+ }
18469
+ }
18470
+ // @ts-expect-error
18471
+ geometry.setIndexData(new index.constructor(0));
18472
+ };
18473
+ ParticleMesh.prototype.minusTime = function (time) {
18474
+ var data = this.geometry.getAttributeData('aOffset');
18475
+ for (var i = 0; i < data.length; i += 4) {
18476
+ data[i + 2] -= time;
18477
+ }
18478
+ this.geometry.setAttributeData('aOffset', data);
18479
+ this.time -= time;
18480
+ };
18481
+ ParticleMesh.prototype.removePoint = function (index) {
18482
+ if (index < this.particleCount) {
18483
+ this.geometry.setAttributeSubData('aOffset', index * 16, new Float32Array(16));
18484
+ }
18485
+ };
18486
+ ParticleMesh.prototype.setPoint = function (point, index) {
18487
+ var maxCount = this.maxCount;
18488
+ if (index < maxCount) {
18489
+ var particleCount = index + 1;
18490
+ var vertexCount_1 = particleCount * 4;
18491
+ var geometry_1 = this.geometry;
18492
+ var increaseBuffer_1 = particleCount > this.maxParticleBufferCount;
18493
+ var inc_1 = 1;
18494
+ if (this.particleCount > 300) {
18495
+ inc_1 = (this.particleCount + 100) / this.particleCount;
18496
+ }
18497
+ else if (this.particleCount > 100) {
18498
+ inc_1 = 1.4;
18499
+ }
18500
+ else if (this.particleCount > 0) {
18501
+ inc_1 = 2;
18502
+ }
18503
+ var pointData_1 = {
18504
+ aPos: new Float32Array(48),
18505
+ aRot: new Float32Array(32),
18506
+ aOffset: new Float32Array(16),
18507
+ };
18508
+ var useSprite = this.useSprite;
18509
+ if (useSprite) {
18510
+ pointData_1.aSprite = new Float32Array(12);
18511
+ }
18512
+ var tempPos = new Vector3();
18513
+ var tempQuat = new Quaternion();
18514
+ var scale = new Vector3(1, 1, 1);
18515
+ point.transform.assignWorldTRS(tempPos, tempQuat, scale);
18516
+ var tempEuler = Transform.getRotation(tempQuat, new Euler());
18517
+ var position = tempPos.toArray();
18518
+ var rotation = tempEuler.toArray();
18519
+ var offsets = this.textureOffsets;
18520
+ var off = [0, 0, point.delay, point.lifetime];
18521
+ var wholeUV = [0, 0, 1, 1];
18522
+ var vel = point.vel;
18523
+ var color = point.color;
18524
+ var sizeOffsets = [-.5, .5, -.5, -.5, .5, .5, .5, -.5];
18525
+ var seed = Math.random();
18526
+ var sprite = void 0;
18527
+ if (useSprite) {
18528
+ sprite = point.sprite;
18529
+ }
18530
+ for (var j = 0; j < 4; j++) {
18531
+ var offset = j * 2;
18532
+ var j3 = j * 3;
18533
+ var j4 = j * 4;
18534
+ var j12 = j * 12;
18535
+ var j8 = j * 8;
18536
+ pointData_1.aPos.set(position, j12);
18537
+ vel.fill(pointData_1.aPos, j12 + 3);
18538
+ pointData_1.aRot.set(rotation, j8);
18539
+ pointData_1.aRot[j8 + 3] = seed;
18540
+ pointData_1.aRot.set(color, j8 + 4);
18541
+ if (useSprite) {
18542
+ // @ts-expect-error
18543
+ pointData_1.aSprite.set(sprite, j3);
18544
+ }
18545
+ var uv = point.uv || wholeUV;
18546
+ if (uv) {
18547
+ var uvy = useSprite ? (1 - offsets[offset + 1]) : offsets[offset + 1];
18548
+ off[0] = uv[0] + offsets[offset] * uv[2];
18549
+ off[1] = uv[1] + uvy * uv[3];
18550
+ }
18551
+ pointData_1.aOffset.set(off, j4);
18552
+ var ji = (j + j);
18553
+ var sx = (sizeOffsets[ji] - this.anchor.x) * scale.x;
18554
+ var sy = (sizeOffsets[ji + 1] - this.anchor.y) * scale.y;
18555
+ for (var k = 0; k < 3; k++) {
18556
+ pointData_1.aPos[j12 + 6 + k] = point.dirX.getElement(k) * sx;
18557
+ pointData_1.aPos[j12 + 9 + k] = point.dirY.getElement(k) * sy;
18275
18558
  }
18276
18559
  }
18277
- if (hide) {
18278
- this.content.setVisible(false);
18560
+ var indexData = new Uint16Array([0, 1, 2, 2, 1, 3].map(function (x) { return x + index * 4; }));
18561
+ if (increaseBuffer_1) {
18562
+ var baseIndexData = geometry_1.getIndexData();
18563
+ var idx = enlargeBuffer(baseIndexData, particleCount * 6, inc_1, maxCount * 6);
18564
+ idx.set(indexData, index * 6);
18565
+ geometry_1.setIndexData(idx);
18566
+ this.maxParticleBufferCount = idx.length / 6;
18279
18567
  }
18280
18568
  else {
18281
- this.content.setVisible(true);
18282
- this.content.onUpdate(dt);
18569
+ geometry_1.setIndexSubData(index * 6, indexData);
18283
18570
  }
18571
+ Object.keys(pointData_1).forEach(function (name) {
18572
+ var data = pointData_1[name];
18573
+ var attrSize = geometry_1.getAttributeStride(name) / Float32Array.BYTES_PER_ELEMENT;
18574
+ if (increaseBuffer_1) {
18575
+ var baseData = geometry_1.getAttributeData(name);
18576
+ var geoData = enlargeBuffer(baseData, vertexCount_1 * attrSize, inc_1, maxCount * 4 * attrSize);
18577
+ geoData.set(data, data.length * index);
18578
+ geometry_1.setAttributeData(name, geoData);
18579
+ }
18580
+ else {
18581
+ geometry_1.setAttributeSubData(name, data.length * index, data);
18582
+ }
18583
+ });
18584
+ this.particleCount = Math.max(particleCount, this.particleCount);
18585
+ geometry_1.setDrawCount(this.particleCount * 6);
18586
+ }
18587
+ };
18588
+ return ParticleMesh;
18589
+ }());
18590
+ var gl2UniformSlots = [10, 32, 64, 160];
18591
+ function getSlot(count) {
18592
+ for (var w = 0; w < gl2UniformSlots.length; w++) {
18593
+ var slot = gl2UniformSlots[w];
18594
+ if (slot > count) {
18595
+ return slot;
18596
+ }
18597
+ }
18598
+ return count || gl2UniformSlots[0];
18599
+ }
18600
+ function generateGeometryProps(maxVertex, useSprite, name) {
18601
+ var bpe = Float32Array.BYTES_PER_ELEMENT;
18602
+ var j12 = bpe * 12;
18603
+ var attributes = {
18604
+ aPos: { size: 3, offset: 0, stride: j12, data: new Float32Array(0) },
18605
+ aVel: { size: 3, offset: 3 * bpe, stride: j12, dataSource: 'aPos' },
18606
+ aDirX: { size: 3, offset: 6 * bpe, stride: j12, dataSource: 'aPos' },
18607
+ aDirY: { size: 3, offset: 9 * bpe, stride: j12, dataSource: 'aPos' },
18608
+ //
18609
+ aRot: { size: 3, offset: 0, stride: 8 * bpe, data: new Float32Array(0) },
18610
+ aSeed: { size: 1, offset: 3 * bpe, stride: 8 * bpe, dataSource: 'aRot' },
18611
+ aColor: { size: 4, offset: 4 * bpe, stride: 8 * bpe, dataSource: 'aRot' },
18612
+ //
18613
+ aOffset: { size: 4, stride: 4 * bpe, data: new Float32Array(0) },
18614
+ };
18615
+ if (useSprite) {
18616
+ attributes['aSprite'] = { size: 3, data: new Float32Array(0) };
18617
+ }
18618
+ return { attributes: attributes, indices: { data: new Uint16Array(0) }, name: name, maxVertex: maxVertex };
18619
+ }
18620
+ function getParticleMeshShader(item, env, gpuCapability) {
18621
+ var _a, _b, _c, _d, _e;
18622
+ if (env === void 0) { env = ''; }
18623
+ var props = item.content;
18624
+ var renderMode = +(((_a = props.renderer) === null || _a === void 0 ? void 0 : _a.renderMode) || 0);
18625
+ var marcos = [
18626
+ ['RENDER_MODE', renderMode],
18627
+ ['PRE_MULTIPLY_ALPHA', false],
18628
+ ['ENV_EDITOR', env === PLAYER_OPTIONS_ENV_EDITOR],
18629
+ ];
18630
+ var level = gpuCapability.level, detail = gpuCapability.detail;
18631
+ var vertexKeyFrameMeta = createKeyFrameMeta();
18632
+ var fragmentKeyFrameMeta = createKeyFrameMeta();
18633
+ var enableVertexTexture = detail.maxVertexUniforms > 0;
18634
+ var speedOverLifetime = ((_b = props.positionOverLifetime) !== null && _b !== void 0 ? _b : {}).speedOverLifetime;
18635
+ var vertex_lookup_texture = 0;
18636
+ var shaderCacheId = 0;
18637
+ if (enableVertexTexture) {
18638
+ marcos.push(['ENABLE_VERTEX_TEXTURE', true]);
18639
+ }
18640
+ if (speedOverLifetime) {
18641
+ marcos.push(['SPEED_OVER_LIFETIME', true]);
18642
+ shaderCacheId |= 1 << 1;
18643
+ getKeyFrameMetaByRawValue(vertexKeyFrameMeta, speedOverLifetime);
18644
+ }
18645
+ var sprite = props.textureSheetAnimation;
18646
+ if (sprite && sprite.animate) {
18647
+ marcos.push(['USE_SPRITE', true]);
18648
+ shaderCacheId |= 1 << 2;
18649
+ }
18650
+ var filter = undefined;
18651
+ if (props.filter && props.filter.name !== FILTER_NAME_NONE) {
18652
+ marcos.push(['USE_FILTER', true]);
18653
+ shaderCacheId |= 1 << 3;
18654
+ var f = createFilterShaders(props.filter).find(function (f) { return f.isParticle; });
18655
+ if (!f) {
18656
+ throw Error("particle filter ".concat(props.filter.name, " not implement"));
18284
18657
  }
18285
- };
18286
- ParticleVFXItem.prototype.onItemRemoved = function (composition, content) {
18287
- if (content) {
18288
- composition.destroyTextures(content.getTextures());
18289
- content.meshes.forEach(function (mesh) { return mesh.dispose({ material: { textures: exports.DestroyOptions.keep } }); });
18658
+ filter = f;
18659
+ (_c = f.uniforms) === null || _c === void 0 ? void 0 : _c.forEach(function (val) { return getKeyFrameMetaByRawValue(vertexKeyFrameMeta, val); });
18660
+ // filter = processFilter(props.filter, fragmentKeyFrameMeta, vertexKeyFrameMeta, options);
18661
+ }
18662
+ var colorOverLifetime = props.colorOverLifetime;
18663
+ if (colorOverLifetime && colorOverLifetime.color) {
18664
+ marcos.push(['COLOR_OVER_LIFETIME', true]);
18665
+ shaderCacheId |= 1 << 4;
18666
+ }
18667
+ var opacity = colorOverLifetime && colorOverLifetime.opacity;
18668
+ if (opacity) {
18669
+ getKeyFrameMetaByRawValue(vertexKeyFrameMeta, opacity);
18670
+ }
18671
+ var positionOverLifetime = props.positionOverLifetime;
18672
+ var useOrbitalVel;
18673
+ ['x', 'y', 'z'].forEach(function (pro, i) {
18674
+ var defL = 0;
18675
+ var linearPro = 'linear' + pro.toUpperCase();
18676
+ var orbitalPro = 'orbital' + pro.toUpperCase();
18677
+ if (positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime[linearPro]) {
18678
+ getKeyFrameMetaByRawValue(vertexKeyFrameMeta, positionOverLifetime[linearPro]);
18679
+ defL = 1;
18680
+ shaderCacheId |= 1 << (7 + i);
18290
18681
  }
18291
- };
18292
- /**
18293
- * @internal
18294
- */
18295
- ParticleVFXItem.prototype.setColor = function (r, g, b, a) {
18296
- this.content.setColor(r, g, b, a);
18297
- };
18298
- ParticleVFXItem.prototype.setOpacity = function (opacity) {
18299
- this.content.setOpacity(opacity);
18300
- };
18301
- ParticleVFXItem.prototype.stopParticleEmission = function () {
18302
- if (this.content) {
18303
- this.content.emissionStopped = true;
18682
+ marcos.push(["LINEAR_VEL_".concat(pro.toUpperCase()), defL]);
18683
+ var defO = 0;
18684
+ if (positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime[orbitalPro]) {
18685
+ getKeyFrameMetaByRawValue(vertexKeyFrameMeta, positionOverLifetime[orbitalPro]);
18686
+ defO = 1;
18687
+ shaderCacheId |= 1 << (10 + i);
18688
+ useOrbitalVel = true;
18304
18689
  }
18305
- };
18306
- ParticleVFXItem.prototype.resumeParticleEmission = function () {
18307
- if (this.content) {
18308
- this.content.emissionStopped = false;
18690
+ marcos.push(["ORB_VEL_".concat(pro.toUpperCase()), defO]);
18691
+ });
18692
+ if (positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.asMovement) {
18693
+ marcos.push(['AS_LINEAR_MOVEMENT', true]);
18694
+ shaderCacheId |= 1 << 5;
18695
+ }
18696
+ if (useOrbitalVel) {
18697
+ if (positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.asRotation) {
18698
+ marcos.push(['AS_ORBITAL_MOVEMENT', true]);
18699
+ shaderCacheId |= 1 << 6;
18309
18700
  }
18310
- };
18311
- ParticleVFXItem.prototype.doCreateContent = function (composition) {
18312
- assertExist(this.particle);
18313
- return new ParticleSystem(this.particle, composition.getRendererOptions(), this);
18314
- };
18315
- ParticleVFXItem.prototype.isEnded = function (now) {
18316
- return _super.prototype.isEnded.call(this, now) && this.destroyed;
18317
- };
18318
- ParticleVFXItem.prototype.getBoundingBox = function () {
18319
- var pt = this.content;
18320
- if (!pt) {
18321
- return;
18701
+ }
18702
+ var sizeOverLifetime = props.sizeOverLifetime;
18703
+ getKeyFrameMetaByRawValue(vertexKeyFrameMeta, sizeOverLifetime === null || sizeOverLifetime === void 0 ? void 0 : sizeOverLifetime.x);
18704
+ if (sizeOverLifetime === null || sizeOverLifetime === void 0 ? void 0 : sizeOverLifetime.separateAxes) {
18705
+ marcos.push(['SIZE_Y_BY_LIFE', 1]);
18706
+ shaderCacheId |= 1 << 14;
18707
+ getKeyFrameMetaByRawValue(vertexKeyFrameMeta, sizeOverLifetime === null || sizeOverLifetime === void 0 ? void 0 : sizeOverLifetime.y);
18708
+ }
18709
+ var rot = props.rotationOverLifetime;
18710
+ if (rot === null || rot === void 0 ? void 0 : rot.z) {
18711
+ getKeyFrameMetaByRawValue(vertexKeyFrameMeta, rot === null || rot === void 0 ? void 0 : rot.z);
18712
+ shaderCacheId |= 1 << 15;
18713
+ marcos.push(['ROT_Z_LIFETIME', 1]);
18714
+ }
18715
+ if (rot === null || rot === void 0 ? void 0 : rot.separateAxes) {
18716
+ if (rot.x) {
18717
+ getKeyFrameMetaByRawValue(vertexKeyFrameMeta, rot.x);
18718
+ shaderCacheId |= 1 << 16;
18719
+ marcos.push(['ROT_X_LIFETIME', 1]);
18322
18720
  }
18323
- else {
18324
- var area = pt.getParticleBoxes();
18325
- return {
18326
- type: exports.HitTestType.sphere,
18327
- area: area,
18328
- };
18721
+ if (rot.y) {
18722
+ getKeyFrameMetaByRawValue(vertexKeyFrameMeta, rot.y);
18723
+ shaderCacheId |= 1 << 17;
18724
+ marcos.push(['ROT_Y_LIFETIME', 1]);
18329
18725
  }
18330
- };
18331
- ParticleVFXItem.prototype.getHitTestParams = function (force) {
18332
- var _this = this;
18333
- var _a;
18334
- var interactParams = (_a = this.content) === null || _a === void 0 ? void 0 : _a.interaction;
18335
- if (force || interactParams) {
18336
- return {
18337
- type: exports.HitTestType.custom,
18338
- collect: function (ray) {
18339
- var _a;
18340
- return (_a = _this.content) === null || _a === void 0 ? void 0 : _a.raycast({
18341
- radius: (interactParams === null || interactParams === void 0 ? void 0 : interactParams.radius) || 0.4,
18342
- multiple: !!(interactParams === null || interactParams === void 0 ? void 0 : interactParams.multiple),
18343
- removeParticle: (interactParams === null || interactParams === void 0 ? void 0 : interactParams.behavior) === ParticleInteractionBehavior$1.removeParticle,
18344
- ray: ray,
18345
- });
18346
- },
18347
- };
18726
+ }
18727
+ if (rot === null || rot === void 0 ? void 0 : rot.asRotation) {
18728
+ marcos.push(['ROT_LIFETIME_AS_MOVEMENT', 1]);
18729
+ shaderCacheId |= 1 << 18;
18730
+ }
18731
+ getKeyFrameMetaByRawValue(vertexKeyFrameMeta, positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.gravityOverLifetime);
18732
+ var forceOpt = positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.forceTarget;
18733
+ if (forceOpt) {
18734
+ marcos.push(['FINAL_TARGET', true]);
18735
+ shaderCacheId |= 1 << 19;
18736
+ getKeyFrameMetaByRawValue(vertexKeyFrameMeta, positionOverLifetime.forceCurve);
18737
+ }
18738
+ var HALF_FLOAT = detail.halfFloatTexture;
18739
+ if (HALF_FLOAT && fragmentKeyFrameMeta.max) {
18740
+ shaderCacheId |= 1 << 20;
18741
+ }
18742
+ var maxVertexUniforms = detail.maxVertexUniforms;
18743
+ var vertexCurveTexture = vertexKeyFrameMeta.max + vertexKeyFrameMeta.curves.length - 32 > maxVertexUniforms;
18744
+ if (getConfig(RENDER_PREFER_LOOKUP_TEXTURE)) {
18745
+ vertexCurveTexture = true;
18746
+ }
18747
+ if (level === 2) {
18748
+ vertexKeyFrameMeta.max = -1;
18749
+ // vertexKeyFrameMeta.index = getSlot(vertexKeyFrameMeta.index);
18750
+ if (fragmentKeyFrameMeta.index > 0) {
18751
+ fragmentKeyFrameMeta.max = -1;
18752
+ // fragmentKeyFrameMeta.index = getSlot(fragmentKeyFrameMeta.index);
18348
18753
  }
18754
+ }
18755
+ if (vertexCurveTexture && HALF_FLOAT && enableVertexTexture) {
18756
+ vertex_lookup_texture = 1;
18757
+ }
18758
+ var shaderCache = ['-p:', renderMode, shaderCacheId, vertexKeyFrameMeta.index, vertexKeyFrameMeta.max, fragmentKeyFrameMeta.index, fragmentKeyFrameMeta.max].join('+');
18759
+ var shader = {
18760
+ fragment: particleFrag,
18761
+ vertex: "#define LOOKUP_TEXTURE_CURVE ".concat(vertex_lookup_texture, "\n").concat(particleVert),
18762
+ shared: true,
18763
+ cacheId: shaderCache,
18764
+ marcos: marcos,
18765
+ name: "particle#".concat(item.name),
18349
18766
  };
18350
- return ParticleVFXItem;
18351
- }(VFXItem));
18767
+ if (filter) {
18768
+ shader.fragment = shader.fragment.replace(/#pragma\s+FILTER_FRAG/, (_d = filter.fragment) !== null && _d !== void 0 ? _d : '');
18769
+ shader.vertex = shader.vertex.replace(/#pragma\s+FILTER_VERT/, filter.vertex || 'void filterMain(float t){}\n');
18770
+ shader.cacheId += '+' + ((_e = props.filter) === null || _e === void 0 ? void 0 : _e.name);
18771
+ }
18772
+ marcos.push(['VERT_CURVE_VALUE_COUNT', vertexKeyFrameMeta.index], ['FRAG_CURVE_VALUE_COUNT', fragmentKeyFrameMeta.index], ['VERT_MAX_KEY_FRAME_COUNT', vertexKeyFrameMeta.max], ['FRAG_MAX_KEY_FRAME_COUNT', fragmentKeyFrameMeta.max]);
18773
+ return { shader: shader, vertex: vertexKeyFrameMeta.index, fragment: fragmentKeyFrameMeta.index };
18774
+ }
18775
+ function modifyMaxKeyframeShader(shader, maxVertex, maxFrag) {
18776
+ var _a;
18777
+ var shaderIds = (_a = shader.cacheId) === null || _a === void 0 ? void 0 : _a.split('+');
18778
+ shaderIds[3] = maxVertex;
18779
+ shaderIds[5] = maxFrag;
18780
+ shader.cacheId = shaderIds.join('+');
18781
+ if (!shader.marcos) {
18782
+ return;
18783
+ }
18784
+ for (var i = 0; i < shader.marcos.length; i++) {
18785
+ var marco = shader.marcos[i];
18786
+ if (marco[0] === 'VERT_CURVE_VALUE_COUNT') {
18787
+ marco[1] = maxVertex;
18788
+ }
18789
+ else if (marco[0] === 'FRAG_CURVE_VALUE_COUNT') {
18790
+ marco[1] = maxFrag;
18791
+ break;
18792
+ }
18793
+ }
18794
+ }
18352
18795
 
18353
18796
  var ParticleLoader = /** @class */ (function (_super) {
18354
18797
  __extends(ParticleLoader, _super);
@@ -21599,7 +22042,7 @@ var filters = {
21599
22042
  * Name: @galacean/effects-specification
21600
22043
  * Description: Galacean Effects JSON Specification
21601
22044
  * Author: Ant Group CO., Ltd.
21602
- * Version: v1.1.0
22045
+ * Version: v1.2.0-beta.0
21603
22046
  */
21604
22047
 
21605
22048
  /*********************************************/
@@ -22360,15 +22803,27 @@ function ensureFixedNumber(a) {
22360
22803
  return [ValueType.CONSTANT, a];
22361
22804
  }
22362
22805
  if (a) {
22363
- if (a[0] === 'lines') {
22806
+ var valueType = a[0];
22807
+ var valueData = a[1];
22808
+ if (Array.isArray(valueType)) {
22809
+ // 没有数据类型的数据
22810
+ return;
22811
+ }
22812
+ if (valueType === 'static' || valueType === ValueType.CONSTANT) {
22813
+ return [ValueType.CONSTANT, a[1]];
22814
+ }
22815
+ if (valueType === 'lines') {
22364
22816
  return [ValueType.LINE, a[1]];
22365
22817
  }
22366
- if (a[0] === 'curve') {
22367
- return [ValueType.CURVE, a[1]];
22818
+ if (valueType === ValueType.LINE) {
22819
+ // @ts-expect-error
22820
+ var keyframes = valueData.map(function (data) { return [BezierKeyframeType.LINE, data]; });
22821
+ return [ValueType.BEZIER_CURVE, keyframes];
22368
22822
  }
22369
- if (a[0] === 'static') {
22370
- return [ValueType.CONSTANT, a[1]];
22823
+ if (valueType === 'curve' || valueType === ValueType.CURVE) {
22824
+ return [ValueType.BEZIER_CURVE, getBezierCurveFromHermiteInGE(valueData)];
22371
22825
  }
22826
+ return a;
22372
22827
  }
22373
22828
  }
22374
22829
  function ensureFixedNumberWithRandom(a, p) {
@@ -22394,6 +22849,7 @@ function ensureColorExpression(a, normalized) {
22394
22849
  else if (a[0] === 'color') {
22395
22850
  return [ValueType.RGBA_COLOR, colorToArr(a[1], normalized)];
22396
22851
  }
22852
+ return a;
22397
22853
  }
22398
22854
  }
22399
22855
  function ensureNumberExpression(a) {
@@ -22461,6 +22917,9 @@ function parsePercent(c) {
22461
22917
  }
22462
22918
  function getGradientColor(color, normalized) {
22463
22919
  if (Array.isArray(color)) {
22920
+ if (color[0] === ValueType.GRADIENT_COLOR) {
22921
+ return color;
22922
+ }
22464
22923
  // @ts-expect-error
22465
22924
  return (color[0] === 'gradient' || color[0] === 'color') && ensureGradient(color[1], normalized);
22466
22925
  }
@@ -22473,12 +22932,36 @@ function ensureFixedVec3(a) {
22473
22932
  if (a.length === 3) {
22474
22933
  return [ValueType.CONSTANT_VEC3, a];
22475
22934
  }
22476
- if (a[0] === 'path') {
22477
- return [ValueType.LINEAR_PATH, a[1]];
22478
- }
22479
- if (a[0] === 'bezier') {
22480
- return [ValueType.BEZIER_PATH, a[1]];
22935
+ var valueType = a[0];
22936
+ if (valueType === 'path' ||
22937
+ valueType === 'bezier' ||
22938
+ valueType === ValueType.BEZIER_PATH ||
22939
+ valueType === ValueType.LINEAR_PATH) {
22940
+ var valueData = a[1];
22941
+ var easing = valueData[0];
22942
+ var points = valueData[1];
22943
+ var controlPoints = valueData[2];
22944
+ var bezierEasing = getBezierCurveFromHermiteInGE(easing);
22945
+ // linear path没有controlPoints
22946
+ if (!controlPoints) {
22947
+ controlPoints = [];
22948
+ for (var keyframeIndex = 0; keyframeIndex < points.length; keyframeIndex++) {
22949
+ var point = points[keyframeIndex].slice();
22950
+ if (keyframeIndex === 0) {
22951
+ controlPoints.push(point);
22952
+ }
22953
+ else if (keyframeIndex < points.length - 1) {
22954
+ controlPoints.push(point);
22955
+ controlPoints.push(point);
22956
+ }
22957
+ else {
22958
+ controlPoints.push(point);
22959
+ }
22960
+ }
22961
+ }
22962
+ return [ValueType.BEZIER_CURVE_PATH, [bezierEasing, points, controlPoints]];
22481
22963
  }
22964
+ return a;
22482
22965
  }
22483
22966
  }
22484
22967
  function objectValueToNumber(o) {
@@ -22568,6 +23051,50 @@ function rotationZYXFromQuat(out, quat) {
22568
23051
  }
22569
23052
  return out;
22570
23053
  }
23054
+ function getBezierCurveFromHermite(m0, m1, p0, p3) {
23055
+ var xStart = p0[0];
23056
+ var yStart = p0[1];
23057
+ var xEnd = p3[0];
23058
+ var yEnd = p3[1];
23059
+ var dt = xEnd - xStart;
23060
+ m0 = m0 * dt;
23061
+ m1 = m1 * dt;
23062
+ var bezierControlPoints = [[xStart + (xEnd - xStart) / 3, yStart + m0 / 3], [xEnd - (xEnd - xStart) / 3, yEnd - m1 / 3]];
23063
+ return bezierControlPoints;
23064
+ }
23065
+ function getBezierCurveFromHermiteInGE(geHermiteCurves) {
23066
+ var ymax = -1000000;
23067
+ var ymin = 1000000;
23068
+ for (var i = 0; i < geHermiteCurves.length; i++) {
23069
+ ymax = Math.max(ymax, geHermiteCurves[i][1]);
23070
+ ymin = Math.min(ymin, geHermiteCurves[i][1]);
23071
+ }
23072
+ var geBezierCurves = [[geHermiteCurves[0][0], geHermiteCurves[0][1]]];
23073
+ for (var i = 0; i < geHermiteCurves.length - 1; i++) {
23074
+ var m0 = geHermiteCurves[i][3] * (ymax - ymin);
23075
+ var m1 = geHermiteCurves[i + 1][2] * (ymax - ymin);
23076
+ var p0 = [geHermiteCurves[i][0], geHermiteCurves[i][1]];
23077
+ var p3 = [geHermiteCurves[i + 1][0], geHermiteCurves[i + 1][1]];
23078
+ if (p0[0] != p3[0]) {
23079
+ var bezierControlPoints = getBezierCurveFromHermite(m0, m1, p0, p3);
23080
+ var p1 = bezierControlPoints[0];
23081
+ var p2 = bezierControlPoints[1];
23082
+ geBezierCurves[geBezierCurves.length - 1].push(p1[0]);
23083
+ geBezierCurves[geBezierCurves.length - 1].push(p1[1]);
23084
+ geBezierCurves.push([p2[0], p2[1], p3[0], p3[1]]);
23085
+ }
23086
+ else {
23087
+ geBezierCurves[geBezierCurves.length - 1].push(p3[0]);
23088
+ geBezierCurves[geBezierCurves.length - 1].push(p3[1]);
23089
+ }
23090
+ }
23091
+ // 添加关键帧类型
23092
+ return geBezierCurves.map(function (curve, index) {
23093
+ return index === 0 ? [BezierKeyframeType.EASE_OUT, curve]
23094
+ : index === geBezierCurves.length - 1 ? [BezierKeyframeType.EASE_IN, curve]
23095
+ : [BezierKeyframeType.EASE, curve];
23096
+ });
23097
+ }
22571
23098
 
22572
23099
  function getStandardParticleContent(particle) {
22573
23100
  var _a;
@@ -22979,12 +23506,63 @@ function version22Migration(json) {
22979
23506
  });
22980
23507
  return json;
22981
23508
  }
23509
+ /**
23510
+ * 2.5 以下版本 赫尔米特数据转换成贝塞尔数据
23511
+ */
23512
+ function version24Migration(json) {
23513
+ // 曲线转换成贝塞尔
23514
+ json.compositions.map(function (comp) {
23515
+ var e_1, _a;
23516
+ try {
23517
+ for (var _b = __values(comp.items), _c = _b.next(); !_c.done; _c = _b.next()) {
23518
+ var item = _c.value;
23519
+ convertParam(item.content);
23520
+ }
23521
+ }
23522
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
23523
+ finally {
23524
+ try {
23525
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
23526
+ }
23527
+ finally { if (e_1) throw e_1.error; }
23528
+ }
23529
+ });
23530
+ return json;
23531
+ }
23532
+ function convertParam(content) {
23533
+ var e_2, _a;
23534
+ try {
23535
+ for (var _b = __values(Object.keys(content)), _c = _b.next(); !_c.done; _c = _b.next()) {
23536
+ var key = _c.value;
23537
+ var value = content[key];
23538
+ var isArray = Array.isArray(value);
23539
+ if (isArray && value.length === 2 && Array.isArray(value[1])) {
23540
+ if (key === 'path') {
23541
+ content[key] = ensureFixedVec3(value);
23542
+ }
23543
+ else {
23544
+ content[key] = ensureFixedNumber(value);
23545
+ }
23546
+ }
23547
+ else if (!isArray && typeof value === 'object') {
23548
+ convertParam(value);
23549
+ }
23550
+ }
23551
+ }
23552
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
23553
+ finally {
23554
+ try {
23555
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
23556
+ }
23557
+ finally { if (e_2) throw e_2.error; }
23558
+ }
23559
+ }
22982
23560
 
22983
23561
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
22984
23562
  var standardVersion = /^(\d+)\.(\d+)$/;
22985
23563
  var reverseParticle = false;
22986
23564
  function getStandardJSON(json) {
22987
- var _a, _b;
23565
+ var _a;
22988
23566
  if (!json || typeof json !== 'object') {
22989
23567
  throw Error('expect a json object');
22990
23568
  }
@@ -22994,9 +23572,14 @@ function getStandardJSON(json) {
22994
23572
  reverseParticle = ((_a = (/^(\d+)/).exec(json.version)) === null || _a === void 0 ? void 0 : _a[0]) === '0';
22995
23573
  return version21Migration(getStandardJSONFromV0(json));
22996
23574
  }
22997
- var mainVersion = (_b = standardVersion.exec(json.version)) === null || _b === void 0 ? void 0 : _b[1];
23575
+ var vs = standardVersion.exec(json.version) || [];
23576
+ var mainVersion = Number(vs[1]);
23577
+ var minorVersion = Number(vs[2]);
22998
23578
  if (mainVersion) {
22999
- if (Number(mainVersion) < 2) {
23579
+ if (mainVersion < 2 || (mainVersion === 2 && minorVersion < 4)) {
23580
+ version24Migration(json);
23581
+ }
23582
+ if (mainVersion < 2) {
23000
23583
  return version21Migration(json);
23001
23584
  }
23002
23585
  return json;
@@ -26962,13 +27545,14 @@ Geometry.create = function (engine, options) {
26962
27545
  Mesh.create = function (engine, props) {
26963
27546
  return new ThreeMesh(engine, props);
26964
27547
  };
26965
- var version = "1.3.1";
27548
+ var version = "1.4.0-beta.0";
26966
27549
  logger.info('THREEJS plugin version: ' + version);
26967
27550
 
26968
27551
  exports.AbstractPlugin = AbstractPlugin;
26969
27552
  exports.AssetManager = AssetManager;
26970
27553
  exports.BYTES_TYPE_MAP = BYTES_TYPE_MAP;
26971
- exports.BezierSegments = BezierSegments;
27554
+ exports.BezierCurve = BezierCurve;
27555
+ exports.BezierCurvePath = BezierCurvePath;
26972
27556
  exports.COMPRESSED_TEXTURE = COMPRESSED_TEXTURE;
26973
27557
  exports.CONSTANT_MAP_BLEND = CONSTANT_MAP_BLEND;
26974
27558
  exports.CONSTANT_MAP_DEPTH = CONSTANT_MAP_DEPTH;
@@ -26986,7 +27570,6 @@ exports.CameraVFXItem = CameraVFXItem;
26986
27570
  exports.CameraVFXItemLoader = CameraVFXItemLoader;
26987
27571
  exports.Composition = Composition;
26988
27572
  exports.CompositionSourceManager = CompositionSourceManager;
26989
- exports.CurveValue = CurveValue;
26990
27573
  exports.DEFAULT_FONTS = DEFAULT_FONTS;
26991
27574
  exports.Downloader = Downloader;
26992
27575
  exports.EFFECTS_COPY_MESH_NAME = EFFECTS_COPY_MESH_NAME;
@@ -27023,7 +27606,6 @@ exports.ParticleMesh = ParticleMesh;
27023
27606
  exports.ParticleSystem = ParticleSystem;
27024
27607
  exports.ParticleVFXItem = ParticleVFXItem;
27025
27608
  exports.PassTextureCache = PassTextureCache;
27026
- exports.PathSegments = PathSegments;
27027
27609
  exports.PluginSystem = PluginSystem;
27028
27610
  exports.QCanvasViewer = QCanvasViewer;
27029
27611
  exports.QText = QText;
@@ -27106,6 +27688,7 @@ exports.createShaderWithMarcos = createShaderWithMarcos;
27106
27688
  exports.createShape = createShape;
27107
27689
  exports.createVFXItem = createVFXItem;
27108
27690
  exports.createValueGetter = createValueGetter;
27691
+ exports.decimalEqual = decimalEqual;
27109
27692
  exports.deepClone = deepClone;
27110
27693
  exports.defaultGlobalVolume = defaultGlobalVolume;
27111
27694
  exports.defaultPlugins = defaultPlugins;
@@ -27161,7 +27744,6 @@ exports.isString = isString;
27161
27744
  exports.isUniformStruct = isUniformStruct;
27162
27745
  exports.isUniformStructArray = isUniformStructArray;
27163
27746
  exports.isWebGL2 = isWebGL2;
27164
- exports.itemDefine = item_define;
27165
27747
  exports.itemFrag = itemFrag;
27166
27748
  exports.itemFrameFrag = itemFrameFrag;
27167
27749
  exports.itemVert = itemVert;
@@ -27176,11 +27758,14 @@ exports.math = index;
27176
27758
  exports.modifyMaxKeyframeShader = modifyMaxKeyframeShader;
27177
27759
  exports.nearestPowerOfTwo = nearestPowerOfTwo;
27178
27760
  exports.noop = noop;
27761
+ exports.numberToFix = numberToFix;
27179
27762
  exports.parsePercent = parsePercent$1;
27180
27763
  exports.particleFrag = particleFrag;
27181
27764
  exports.particleOriginTranslateMap = particleOriginTranslateMap;
27765
+ exports.particleUniformTypeMap = particleUniformTypeMap;
27182
27766
  exports.particleVert = particleVert;
27183
27767
  exports.pluginLoaderMap = pluginLoaderMap;
27768
+ exports.pointOnLine = pointOnLine;
27184
27769
  exports.random = random;
27185
27770
  exports.registerFilter = registerFilter;
27186
27771
  exports.registerFilters = registerFilters;