@galacean/effects-core 2.3.0-alpha.1 → 2.3.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.3.0-alpha.1
6
+ * Version: v2.3.0-alpha.2
7
7
  */
8
8
 
9
9
  'use strict';
@@ -1039,7 +1039,8 @@ function _inherits(subClass, superClass) {
1039
1039
  JSONSceneVersion["2_4"] = "2.4";
1040
1040
  JSONSceneVersion["3_0"] = "3.0";
1041
1041
  JSONSceneVersion["3_1"] = "3.1";
1042
- JSONSceneVersion["LATEST"] = "3.1";
1042
+ JSONSceneVersion["3_2"] = "3.2";
1043
+ JSONSceneVersion["LATEST"] = "3.2";
1043
1044
  })(JSONSceneVersion || (JSONSceneVersion = {}));
1044
1045
 
1045
1046
  /*********************************************/ /* 元素属性参数类型 */ /*********************************************/ /**
@@ -1577,7 +1578,7 @@ var MaterialBlending;
1577
1578
  var TextOverflow;
1578
1579
  (function(TextOverflow) {
1579
1580
  /**
1580
- * display 模式下,会显示所有文本,存在文本超过边界框的情况。
1581
+ * display 模式下,会显示所有文本,文本大小会根据边界框调整。
1581
1582
  */ TextOverflow[TextOverflow["display"] = 0] = "display";
1582
1583
  /**
1583
1584
  * clip 模式下,当文本内容超出边界框时,多余的会被截断。
@@ -1670,12 +1671,18 @@ var BuiltinObjectGUID = {
1670
1671
  */ ShapePrimitiveType[ShapePrimitiveType["Star"] = 4] = "Star";
1671
1672
  })(ShapePrimitiveType || (ShapePrimitiveType = {}));
1672
1673
 
1673
- // 本期无该功能 待补充
1674
- var ShapeConnectType;
1675
- (function(ShapeConnectType) {})(ShapeConnectType || (ShapeConnectType = {}));
1676
- // @待补充
1677
- var ShapePointType;
1678
- (function(ShapePointType) {})(ShapePointType || (ShapePointType = {}));
1674
+ var LineCap;
1675
+ (function(LineCap) {
1676
+ /** 默认值。向线条的每个末端添加平直的边缘 */ LineCap[LineCap["Butt"] = 0] = "Butt";
1677
+ /** 向线条的每个末端添加圆形线帽 */ LineCap[LineCap["Round"] = 1] = "Round";
1678
+ /** 向线条的每个末端添加正方形线帽 */ LineCap[LineCap["Square"] = 2] = "Square";
1679
+ })(LineCap || (LineCap = {}));
1680
+ var LineJoin;
1681
+ (function(LineJoin) {
1682
+ /** 创建圆角 */ LineJoin[LineJoin["Round"] = 0] = "Round";
1683
+ /** 创建斜角 */ LineJoin[LineJoin["Bevel"] = 1] = "Bevel";
1684
+ /** 创建尖角 */ LineJoin[LineJoin["Miter"] = 2] = "Miter";
1685
+ })(LineJoin || (LineJoin = {}));
1679
1686
 
1680
1687
  /**
1681
1688
  * 动态换图类型
@@ -1884,8 +1891,8 @@ var index$1 = /*#__PURE__*/Object.freeze({
1884
1891
  get FontStyle () { return FontStyle; },
1885
1892
  BuiltinObjectGUID: BuiltinObjectGUID,
1886
1893
  get ShapePrimitiveType () { return ShapePrimitiveType; },
1887
- get ShapeConnectType () { return ShapeConnectType; },
1888
- get ShapePointType () { return ShapePointType; },
1894
+ get LineCap () { return LineCap; },
1895
+ get LineJoin () { return LineJoin; },
1889
1896
  get BackgroundType () { return BackgroundType; },
1890
1897
  get MultimediaType () { return MultimediaType; },
1891
1898
  get DataType () { return DataType; },
@@ -3804,7 +3811,9 @@ Vector4.ZERO = new Vector4(0.0, 0.0, 0.0, 0.0);
3804
3811
  if (renderer.renderingData.currentFrame.globalUniforms) {
3805
3812
  renderer.setGlobalMatrix("effects_ObjectToWorld", this.transform.getWorldMatrix());
3806
3813
  }
3807
- renderer.drawGeometry(this.geometry, this.material);
3814
+ for(var i = 0; i < this.materials.length; i++){
3815
+ renderer.drawGeometry(this.geometry, this.materials[i], i);
3816
+ }
3808
3817
  };
3809
3818
  _proto.getBoundingBox = function getBoundingBox() {
3810
3819
  var worldMatrix = this.transform.getWorldMatrix();
@@ -7339,7 +7348,15 @@ var BYTES_TYPE_MAP = (_obj$5 = {}, _obj$5[glContext.FLOAT] = Float32Array.BYTES_
7339
7348
  */ var Geometry = /*#__PURE__*/ function(EffectsObject) {
7340
7349
  _inherits(Geometry, EffectsObject);
7341
7350
  function Geometry() {
7342
- return EffectsObject.apply(this, arguments);
7351
+ var _this;
7352
+ _this = EffectsObject.apply(this, arguments) || this;
7353
+ /**
7354
+ * Geometry 的名称
7355
+ */ _this.name = "";
7356
+ /**
7357
+ * 子网格数据
7358
+ */ _this.subMeshes = [];
7359
+ return _this;
7343
7360
  }
7344
7361
  var _proto = Geometry.prototype;
7345
7362
  /**
@@ -12705,18 +12722,12 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
12705
12722
  var keyTimeStart = this.curveMap[keyTimeData[0]].timeStart;
12706
12723
  var keyTimeEnd = this.curveMap[keyTimeData[keyTimeData.length - 1]].timeEnd;
12707
12724
  if (time <= keyTimeStart) {
12708
- if (this.startKeyframe[0] === BezierKeyframeType.LINE || this.startKeyframe[0] === BezierKeyframeType.HOLD) {
12709
- keyframeInfo.getPointIndexInCurve(this.startKeyframe, keyframeInfo.pointIndexCache);
12710
- return this.endKeyframe[1][keyframeInfo.pointIndexCache.yIndex];
12711
- }
12712
- return this.getCurveValue(keyTimeData[0], keyTimeStart);
12725
+ keyframeInfo.getPointIndexInCurve(this.startKeyframe, keyframeInfo.pointIndexCache);
12726
+ return this.startKeyframe[1][keyframeInfo.pointIndexCache.yIndex];
12713
12727
  }
12714
12728
  if (time >= keyTimeEnd) {
12715
- if (this.endKeyframe[0] === BezierKeyframeType.LINE || this.endKeyframe[0] === BezierKeyframeType.HOLD) {
12716
- keyframeInfo.getPointIndexInCurve(this.endKeyframe, keyframeInfo.pointIndexCache);
12717
- return this.endKeyframe[1][keyframeInfo.pointIndexCache.yIndex];
12718
- }
12719
- return this.getCurveValue(keyTimeData[keyTimeData.length - 1], keyTimeEnd);
12729
+ keyframeInfo.getPointIndexInCurve(this.endKeyframe, keyframeInfo.pointIndexCache);
12730
+ return this.endKeyframe[1][keyframeInfo.pointIndexCache.yIndex];
12720
12731
  }
12721
12732
  for(var i = 0; i < keyTimeData.length; i++){
12722
12733
  var xMin = this.curveMap[keyTimeData[i]].timeStart;
@@ -14862,6 +14873,10 @@ function triangulate(contours) {
14862
14873
  points
14863
14874
  ]);
14864
14875
  var indexStart = vertices.length / 2;
14876
+ // 当所有 points 在一条直线时, gluTess 三角化 triangles 会返回空数组,这边做一下额外处理返回线段左右端点组成的三角形,确保拿到的包围盒是正确的。
14877
+ if (triangles.length === 0) {
14878
+ this.getLineEndPointsTriangle(points, triangles);
14879
+ }
14865
14880
  for(var i = 0; i < triangles.length; i++){
14866
14881
  vertices[verticesOffset * 2 + i] = triangles[i];
14867
14882
  }
@@ -14870,6 +14885,57 @@ function triangulate(contours) {
14870
14885
  indices[indicesOffset + i1] = indexStart + i1;
14871
14886
  }
14872
14887
  };
14888
+ /**
14889
+ * 获取直线上最远的两个端点坐标组成的三角形
14890
+ */ _proto.getLineEndPointsTriangle = function getLineEndPointsTriangle(points, triangles) {
14891
+ // 参数检查
14892
+ if (!points || points.length < 2 || points.length % 2 !== 0) {
14893
+ throw new Error("Invalid points array");
14894
+ }
14895
+ if (points.length === 2) {
14896
+ triangles.push(points[0], points[1], points[0], points[1], points[0], points[1]);
14897
+ return;
14898
+ }
14899
+ // 取第一个线段计算斜率
14900
+ var dx = points[2] - points[0];
14901
+ var dy = points[3] - points[1];
14902
+ // 存放结果坐标
14903
+ var startX = points[0];
14904
+ var startY = points[1];
14905
+ var endX = points[0];
14906
+ var endY = points[1];
14907
+ // 根据斜率决定比较x还是y
14908
+ if (Math.abs(dx) >= Math.abs(dy)) {
14909
+ // 水平方向为主,比较x坐标
14910
+ for(var i = 0; i < points.length; i += 2){
14911
+ var x = points[i];
14912
+ var y = points[i + 1];
14913
+ if (x < startX) {
14914
+ startX = x;
14915
+ startY = y;
14916
+ }
14917
+ if (x > endX) {
14918
+ endX = x;
14919
+ endY = y;
14920
+ }
14921
+ }
14922
+ } else {
14923
+ // 垂直方向为主,比较y坐标
14924
+ for(var i1 = 0; i1 < points.length; i1 += 2){
14925
+ var x1 = points[i1];
14926
+ var y1 = points[i1 + 1];
14927
+ if (y1 < startY) {
14928
+ startX = x1;
14929
+ startY = y1;
14930
+ }
14931
+ if (y1 > endY) {
14932
+ endX = x1;
14933
+ endY = y1;
14934
+ }
14935
+ }
14936
+ }
14937
+ triangles.push(startX, startY, endX, endY, endX, endY);
14938
+ };
14873
14939
  _create_class(Polygon, [
14874
14940
  {
14875
14941
  key: "lastX",
@@ -15343,47 +15409,48 @@ var PolyStar = /*#__PURE__*/ function(ShapePrimitive) {
15343
15409
  }(ShapePrimitive);
15344
15410
 
15345
15411
  // Based on:
15346
- // const tempPoints = [new Point(), new Point(), new Point(), new Point()];
15347
15412
  /**
15348
- * The `Rectangle` object is an area defined by its position, as indicated by its upper-left corner
15349
- * point (`x`, `y`) and by its `width` and its `height`.
15413
+ * The `Rectangle` object is an area defined by its position, as indicated by its top-left corner
15414
+ * point (`x`, `y`) and by its `width` and its `height`, including a `roundness` property that
15415
+ * defines the roundness of the rounded corners.
15416
+ * @memberof maths
15350
15417
  */ var Rectangle$1 = /*#__PURE__*/ function(ShapePrimitive) {
15351
15418
  _inherits(Rectangle, ShapePrimitive);
15352
- function Rectangle(x, y, width, height) {
15419
+ function Rectangle(x, y, width, height, roundness) {
15353
15420
  if (x === void 0) x = 0;
15354
15421
  if (y === void 0) y = 0;
15355
15422
  if (width === void 0) width = 0;
15356
15423
  if (height === void 0) height = 0;
15424
+ if (roundness === void 0) roundness = 20;
15357
15425
  var _this;
15358
15426
  _this = ShapePrimitive.call(this) || this;
15359
- _this.x = Number(x);
15360
- _this.y = Number(y);
15361
- _this.width = Number(width);
15362
- _this.height = Number(height);
15427
+ _this.x = x;
15428
+ _this.y = y;
15429
+ _this.width = width;
15430
+ _this.height = height;
15431
+ _this.roundness = roundness;
15363
15432
  return _this;
15364
15433
  }
15365
15434
  var _proto = Rectangle.prototype;
15366
- /** Determines whether the Rectangle is empty. */ _proto.isEmpty = function isEmpty() {
15367
- return this.left === this.right || this.top === this.bottom;
15435
+ /**
15436
+ * Returns the framing rectangle of the rectangle as a Rectangle object
15437
+ * @param out - optional rectangle to store the result
15438
+ * @returns The framing rectangle
15439
+ */ _proto.getBounds = function getBounds(out) {
15440
+ out = out || new Rectangle();
15441
+ out.x = this.x;
15442
+ out.y = this.y;
15443
+ out.width = this.width;
15444
+ out.height = this.height;
15445
+ return out;
15368
15446
  };
15369
15447
  /**
15370
- * Creates a clone of this Rectangle
15371
- * @returns a copy of the rectangle
15448
+ * Creates a clone of this rectangle.
15449
+ * @returns - A copy of the rectangle.
15372
15450
  */ _proto.clone = function clone() {
15373
- return new Rectangle(this.x, this.y, this.width, this.height);
15451
+ return new Rectangle(this.x, this.y, this.width, this.height, this.roundness);
15374
15452
  };
15375
15453
  /**
15376
- * Converts a Bounds object to a Rectangle object.
15377
- * @param bounds - The bounds to copy and convert to a rectangle.
15378
- * @returns Returns itself.
15379
- */ // copyFromBounds (bounds: Bounds): this {
15380
- // this.x = bounds.minX;
15381
- // this.y = bounds.minY;
15382
- // this.width = bounds.maxX - bounds.minX;
15383
- // this.height = bounds.maxY - bounds.minY;
15384
- // return this;
15385
- // }
15386
- /**
15387
15454
  * Copies another rectangle to this one.
15388
15455
  * @param rectangle - The rectangle to copy from.
15389
15456
  * @returns Returns itself.
@@ -15392,6 +15459,7 @@ var PolyStar = /*#__PURE__*/ function(ShapePrimitive) {
15392
15459
  this.y = rectangle.y;
15393
15460
  this.width = rectangle.width;
15394
15461
  this.height = rectangle.height;
15462
+ this.roundness = rectangle.roundness;
15395
15463
  return this;
15396
15464
  };
15397
15465
  /**
@@ -15402,267 +15470,121 @@ var PolyStar = /*#__PURE__*/ function(ShapePrimitive) {
15402
15470
  rectangle.copyFrom(this);
15403
15471
  return rectangle;
15404
15472
  };
15405
- /**
15406
- * Checks whether the x and y coordinates given are contained within this Rectangle
15407
- * @param x - The X coordinate of the point to test
15408
- * @param y - The Y coordinate of the point to test
15409
- * @returns Whether the x/y coordinates are within this Rectangle
15410
- */ _proto.contains = function contains(x, y) {
15411
- if (this.width <= 0 || this.height <= 0) {
15412
- return false;
15473
+ _proto.build = function build(points) {
15474
+ var ry;
15475
+ var halfWidth = this.width / 2;
15476
+ var halfHeight = this.height / 2;
15477
+ var x = this.x + halfWidth;
15478
+ var y = this.y + halfHeight;
15479
+ var rx = ry = Math.max(0, Math.min(this.roundness / 100, 1) * Math.min(halfWidth, halfHeight));
15480
+ var dx = halfWidth - rx;
15481
+ var dy = halfHeight - ry;
15482
+ if (!(rx >= 0 && ry >= 0 && dx >= 0 && dy >= 0)) {
15483
+ return;
15413
15484
  }
15414
- if (x >= this.x && x < this.x + this.width) {
15415
- if (y >= this.y && y < this.y + this.height) {
15416
- return true;
15417
- }
15485
+ // 控制边缘的平滑程度
15486
+ var densityScale = 5;
15487
+ // Choose a number of segments such that the maximum absolute deviation from the circle is approximately 0.029
15488
+ var n = densityScale * Math.ceil(2.3 * Math.sqrt(rx + ry));
15489
+ var m = n * 8 + (dx ? 4 : 0) + (dy ? 4 : 0);
15490
+ if (m === 0) {
15491
+ return;
15418
15492
  }
15419
- return false;
15420
- };
15421
- /**
15422
- * Checks whether the x and y coordinates given are contained within this rectangle including the stroke.
15423
- * @param x - The X coordinate of the point to test
15424
- * @param y - The Y coordinate of the point to test
15425
- * @param strokeWidth - The width of the line to check
15426
- * @returns Whether the x/y coordinates are within this rectangle
15427
- */ _proto.strokeContains = function strokeContains(x, y, strokeWidth) {
15428
- var _this = this, width = _this.width, height = _this.height;
15429
- if (width <= 0 || height <= 0) {
15430
- return false;
15493
+ if (n === 0) {
15494
+ points[0] = points[6] = x + dx;
15495
+ points[1] = points[3] = y + dy;
15496
+ points[2] = points[4] = x - dx;
15497
+ points[5] = points[7] = y - dy;
15498
+ return;
15431
15499
  }
15432
- var _x = this.x;
15433
- var _y = this.y;
15434
- var outerLeft = _x - strokeWidth / 2;
15435
- var outerRight = _x + width + strokeWidth / 2;
15436
- var outerTop = _y - strokeWidth / 2;
15437
- var outerBottom = _y + height + strokeWidth / 2;
15438
- var innerLeft = _x + strokeWidth / 2;
15439
- var innerRight = _x + width - strokeWidth / 2;
15440
- var innerTop = _y + strokeWidth / 2;
15441
- var innerBottom = _y + height - strokeWidth / 2;
15442
- return x >= outerLeft && x <= outerRight && y >= outerTop && y <= outerBottom && !(x > innerLeft && x < innerRight && y > innerTop && y < innerBottom);
15443
- };
15444
- /**
15445
- * Determines whether the `other` Rectangle transformed by `transform` intersects with `this` Rectangle object.
15446
- * Returns true only if the area of the intersection is >0, this means that Rectangles
15447
- * sharing a side are not overlapping. Another side effect is that an arealess rectangle
15448
- * (width or height equal to zero) can't intersect any other rectangle.
15449
- * @param {Rectangle} other - The Rectangle to intersect with `this`.
15450
- * @param {Matrix} transform - The transformation matrix of `other`.
15451
- * @returns {boolean} A value of `true` if the transformed `other` Rectangle intersects with `this`; otherwise `false`.
15452
- */ // intersects (other: Rectangle, transform?: Matrix4): boolean {
15453
- // if (!transform) {
15454
- // const x0 = this.x < other.x ? other.x : this.x;
15455
- // const x1 = this.right > other.right ? other.right : this.right;
15456
- // if (x1 <= x0) {
15457
- // return false;
15458
- // }
15459
- // const y0 = this.y < other.y ? other.y : this.y;
15460
- // const y1 = this.bottom > other.bottom ? other.bottom : this.bottom;
15461
- // return y1 > y0;
15462
- // }
15463
- // const x0 = this.left;
15464
- // const x1 = this.right;
15465
- // const y0 = this.top;
15466
- // const y1 = this.bottom;
15467
- // if (x1 <= x0 || y1 <= y0) {
15468
- // return false;
15469
- // }
15470
- // const lt = tempPoints[0].set(other.left, other.top);
15471
- // const lb = tempPoints[1].set(other.left, other.bottom);
15472
- // const rt = tempPoints[2].set(other.right, other.top);
15473
- // const rb = tempPoints[3].set(other.right, other.bottom);
15474
- // if (rt.x <= lt.x || lb.y <= lt.y) {
15475
- // return false;
15476
- // }
15477
- // const s = Math.sign((transform.a * transform.d) - (transform.b * transform.c));
15478
- // if (s === 0) {
15479
- // return false;
15480
- // }
15481
- // transform.apply(lt, lt);
15482
- // transform.apply(lb, lb);
15483
- // transform.apply(rt, rt);
15484
- // transform.apply(rb, rb);
15485
- // if (Math.max(lt.x, lb.x, rt.x, rb.x) <= x0
15486
- // || Math.min(lt.x, lb.x, rt.x, rb.x) >= x1
15487
- // || Math.max(lt.y, lb.y, rt.y, rb.y) <= y0
15488
- // || Math.min(lt.y, lb.y, rt.y, rb.y) >= y1) {
15489
- // return false;
15490
- // }
15491
- // const nx = s * (lb.y - lt.y);
15492
- // const ny = s * (lt.x - lb.x);
15493
- // const n00 = (nx * x0) + (ny * y0);
15494
- // const n10 = (nx * x1) + (ny * y0);
15495
- // const n01 = (nx * x0) + (ny * y1);
15496
- // const n11 = (nx * x1) + (ny * y1);
15497
- // if (Math.max(n00, n10, n01, n11) <= (nx * lt.x) + (ny * lt.y)
15498
- // || Math.min(n00, n10, n01, n11) >= (nx * rb.x) + (ny * rb.y)) {
15499
- // return false;
15500
- // }
15501
- // const mx = s * (lt.y - rt.y);
15502
- // const my = s * (rt.x - lt.x);
15503
- // const m00 = (mx * x0) + (my * y0);
15504
- // const m10 = (mx * x1) + (my * y0);
15505
- // const m01 = (mx * x0) + (my * y1);
15506
- // const m11 = (mx * x1) + (my * y1);
15507
- // if (Math.max(m00, m10, m01, m11) <= (mx * lt.x) + (my * lt.y)
15508
- // || Math.min(m00, m10, m01, m11) >= (mx * rb.x) + (my * rb.y)) {
15509
- // return false;
15510
- // }
15511
- // return true;
15512
- // }
15513
- /**
15514
- * Pads the rectangle making it grow in all directions.
15515
- * If paddingY is omitted, both paddingX and paddingY will be set to paddingX.
15516
- * @param paddingX - The horizontal padding amount.
15517
- * @param paddingY - The vertical padding amount.
15518
- * @returns Returns itself.
15519
- */ _proto.pad = function pad(paddingX, paddingY) {
15520
- if (paddingX === void 0) paddingX = 0;
15521
- if (paddingY === void 0) paddingY = paddingX;
15522
- this.x -= paddingX;
15523
- this.y -= paddingY;
15524
- this.width += paddingX * 2;
15525
- this.height += paddingY * 2;
15526
- return this;
15527
- };
15528
- /**
15529
- * Fits this rectangle around the passed one.
15530
- * @param rectangle - The rectangle to fit.
15531
- * @returns Returns itself.
15532
- */ _proto.fit = function fit(rectangle) {
15533
- var x1 = Math.max(this.x, rectangle.x);
15534
- var x2 = Math.min(this.x + this.width, rectangle.x + rectangle.width);
15535
- var y1 = Math.max(this.y, rectangle.y);
15536
- var y2 = Math.min(this.y + this.height, rectangle.y + rectangle.height);
15537
- this.x = x1;
15538
- this.width = Math.max(x2 - x1, 0);
15539
- this.y = y1;
15540
- this.height = Math.max(y2 - y1, 0);
15541
- return this;
15542
- };
15543
- /**
15544
- * Enlarges rectangle that way its corners lie on grid
15545
- * @param resolution - resolution
15546
- * @param eps - precision
15547
- * @returns Returns itself.
15548
- */ _proto.ceil = function ceil(resolution, eps) {
15549
- if (resolution === void 0) resolution = 1;
15550
- if (eps === void 0) eps = 0.001;
15551
- var x2 = Math.ceil((this.x + this.width - eps) * resolution) / resolution;
15552
- var y2 = Math.ceil((this.y + this.height - eps) * resolution) / resolution;
15553
- this.x = Math.floor((this.x + eps) * resolution) / resolution;
15554
- this.y = Math.floor((this.y + eps) * resolution) / resolution;
15555
- this.width = x2 - this.x;
15556
- this.height = y2 - this.y;
15557
- return this;
15558
- };
15559
- /**
15560
- * Enlarges this rectangle to include the passed rectangle.
15561
- * @param rectangle - The rectangle to include.
15562
- * @returns Returns itself.
15563
- */ _proto.enlarge = function enlarge(rectangle) {
15564
- var x1 = Math.min(this.x, rectangle.x);
15565
- var x2 = Math.max(this.x + this.width, rectangle.x + rectangle.width);
15566
- var y1 = Math.min(this.y, rectangle.y);
15567
- var y2 = Math.max(this.y + this.height, rectangle.y + rectangle.height);
15568
- this.x = x1;
15569
- this.width = x2 - x1;
15570
- this.y = y1;
15571
- this.height = y2 - y1;
15572
- return this;
15573
- };
15574
- /**
15575
- * Returns the framing rectangle of the rectangle as a Rectangle object
15576
- * @param out - optional rectangle to store the result
15577
- * @returns The framing rectangle
15578
- */ _proto.getBounds = function getBounds(out) {
15579
- out = out || new Rectangle();
15580
- out.copyFrom(this);
15581
- return out;
15582
- };
15583
- _proto.getX = function getX() {
15584
- return this.x;
15585
- };
15586
- _proto.getY = function getY() {
15587
- return this.y;
15588
- };
15589
- _proto.build = function build(points) {
15590
- var x = this.x;
15591
- var y = this.y;
15592
- var width = this.width;
15593
- var height = this.height;
15594
- if (!(width >= 0 && height >= 0)) {
15595
- return points;
15500
+ var j1 = 0;
15501
+ var j2 = n * 4 + (dx ? 2 : 0) + 2;
15502
+ var j3 = j2;
15503
+ var j4 = m;
15504
+ var x0 = dx + rx;
15505
+ var y0 = dy;
15506
+ var x1 = x + x0;
15507
+ var x2 = x - x0;
15508
+ var y1 = y + y0;
15509
+ points[j1++] = x1;
15510
+ points[j1++] = y1;
15511
+ points[--j2] = y1;
15512
+ points[--j2] = x2;
15513
+ if (dy) {
15514
+ var y2 = y - y0;
15515
+ points[j3++] = x2;
15516
+ points[j3++] = y2;
15517
+ points[--j4] = y2;
15518
+ points[--j4] = x1;
15519
+ }
15520
+ for(var i = 1; i < n; i++){
15521
+ var a = Math.PI / 2 * (i / n);
15522
+ var x01 = dx + Math.cos(a) * rx;
15523
+ var y01 = dy + Math.sin(a) * ry;
15524
+ var x11 = x + x01;
15525
+ var x21 = x - x01;
15526
+ var y11 = y + y01;
15527
+ var y21 = y - y01;
15528
+ points[j1++] = x11;
15529
+ points[j1++] = y11;
15530
+ points[--j2] = y11;
15531
+ points[--j2] = x21;
15532
+ points[j3++] = x21;
15533
+ points[j3++] = y21;
15534
+ points[--j4] = y21;
15535
+ points[--j4] = x11;
15536
+ }
15537
+ x0 = dx;
15538
+ y0 = dy + ry;
15539
+ x1 = x + x0;
15540
+ x2 = x - x0;
15541
+ y1 = y + y0;
15542
+ var y22 = y - y0;
15543
+ points[j1++] = x1;
15544
+ points[j1++] = y1;
15545
+ points[--j4] = y22;
15546
+ points[--j4] = x1;
15547
+ if (dx) {
15548
+ points[j1++] = x2;
15549
+ points[j1++] = y1;
15550
+ points[--j4] = y22;
15551
+ points[--j4] = x2;
15596
15552
  }
15597
- points[0] = x;
15598
- points[1] = y;
15599
- points[2] = x + width;
15600
- points[3] = y;
15601
- points[4] = x + width;
15602
- points[5] = y + height;
15603
- points[6] = x;
15604
- points[7] = y + height;
15605
- return points;
15606
15553
  };
15607
15554
  _proto.triangulate = function triangulate(points, vertices, verticesOffset, indices, indicesOffset) {
15608
- var count = 0;
15609
- var verticesStride = 2;
15610
- verticesOffset *= verticesStride;
15611
- vertices[verticesOffset + count] = points[0];
15612
- vertices[verticesOffset + count + 1] = points[1];
15613
- count += verticesStride;
15614
- vertices[verticesOffset + count] = points[2];
15615
- vertices[verticesOffset + count + 1] = points[3];
15616
- count += verticesStride;
15617
- vertices[verticesOffset + count] = points[6];
15618
- vertices[verticesOffset + count + 1] = points[7];
15619
- count += verticesStride;
15620
- vertices[verticesOffset + count] = points[4];
15621
- vertices[verticesOffset + count + 1] = points[5];
15622
- count += verticesStride;
15623
- var verticesIndex = verticesOffset / verticesStride;
15624
- // triangle 1
15625
- indices[indicesOffset++] = verticesIndex;
15626
- indices[indicesOffset++] = verticesIndex + 1;
15627
- indices[indicesOffset++] = verticesIndex + 2;
15628
- // triangle 2
15629
- indices[indicesOffset++] = verticesIndex + 1;
15630
- indices[indicesOffset++] = verticesIndex + 3;
15631
- indices[indicesOffset++] = verticesIndex + 2;
15632
- };
15633
- _create_class(Rectangle, [
15634
- {
15635
- key: "left",
15636
- get: /** Returns the left edge of the rectangle. */ function get() {
15637
- return this.x;
15638
- }
15639
- },
15640
- {
15641
- key: "right",
15642
- get: /** Returns the right edge of the rectangle. */ function get() {
15643
- return this.x + this.width;
15644
- }
15645
- },
15646
- {
15647
- key: "top",
15648
- get: /** Returns the top edge of the rectangle. */ function get() {
15649
- return this.y;
15650
- }
15651
- },
15652
- {
15653
- key: "bottom",
15654
- get: /** Returns the bottom edge of the rectangle. */ function get() {
15655
- return this.y + this.height;
15656
- }
15555
+ if (points.length === 0) {
15556
+ return;
15657
15557
  }
15658
- ], [
15659
- {
15660
- key: "EMPTY",
15661
- get: /** A constant empty rectangle. This is a new object every time the property is accessed */ function get() {
15662
- return new Rectangle(0, 0, 0, 0);
15558
+ // Compute center (average of all points)
15559
+ var centerX = 0;
15560
+ var centerY = 0;
15561
+ for(var i = 0; i < points.length; i += 2){
15562
+ centerX += points[i];
15563
+ centerY += points[i + 1];
15564
+ }
15565
+ centerX /= points.length / 2;
15566
+ centerY /= points.length / 2;
15567
+ // Set center vertex
15568
+ var count = verticesOffset;
15569
+ vertices[count * 2] = centerX;
15570
+ vertices[count * 2 + 1] = centerY;
15571
+ var centerIndex = count++;
15572
+ // Set edge vertices and indices
15573
+ for(var i1 = 0; i1 < points.length; i1 += 2){
15574
+ vertices[count * 2] = points[i1];
15575
+ vertices[count * 2 + 1] = points[i1 + 1];
15576
+ if (i1 > 0) {
15577
+ indices[indicesOffset++] = count;
15578
+ indices[indicesOffset++] = centerIndex;
15579
+ indices[indicesOffset++] = count - 1;
15663
15580
  }
15581
+ count++;
15664
15582
  }
15665
- ]);
15583
+ // Connect last point to the first edge point
15584
+ indices[indicesOffset++] = centerIndex + 1;
15585
+ indices[indicesOffset++] = centerIndex;
15586
+ indices[indicesOffset++] = count - 1;
15587
+ };
15666
15588
  return Rectangle;
15667
15589
  }(ShapePrimitive);
15668
15590
 
@@ -15760,8 +15682,8 @@ var ShapePath = /*#__PURE__*/ function() {
15760
15682
  * @param h - The height of the rectangle.
15761
15683
  * @param transform - An optional `Matrix` object to apply a transformation to the rectangle.
15762
15684
  * @returns The instance of the current object for chaining.
15763
- */ _proto.rect = function rect(x, y, w, h, transform) {
15764
- this.drawShape(new Rectangle$1(x, y, w, h), transform);
15685
+ */ _proto.rect = function rect(x, y, w, h, roundness, transform) {
15686
+ this.drawShape(new Rectangle$1(x, y, w, h, roundness), transform);
15765
15687
  return this;
15766
15688
  };
15767
15689
  /**
@@ -15907,7 +15829,7 @@ var GraphicsPath = /*#__PURE__*/ function() {
15907
15829
  * @param h - The height of the rectangle.
15908
15830
  * @param transform - An optional `Matrix` object to apply a transformation to the rectangle.
15909
15831
  * @returns The instance of the current object for chaining.
15910
- */ _proto.rect = function rect(x, y, w, h, transform) {
15832
+ */ _proto.rect = function rect(x, y, w, h, roundness, transform) {
15911
15833
  this.instructions.push({
15912
15834
  action: "rect",
15913
15835
  data: [
@@ -15915,6 +15837,7 @@ var GraphicsPath = /*#__PURE__*/ function() {
15915
15837
  y,
15916
15838
  w,
15917
15839
  h,
15840
+ roundness,
15918
15841
  transform
15919
15842
  ]
15920
15843
  });
@@ -16224,9 +16147,9 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16224
16147
  var innerWeight = (1 - ratio) * 2;
16225
16148
  var outerWeight = ratio * 2;
16226
16149
  if (!closedShape) {
16227
- if (style.cap === "round") {
16150
+ if (style.cap === LineCap.Round) {
16228
16151
  indexCount += round(x0 - perpX * (innerWeight - outerWeight) * 0.5, y0 - perpY * (innerWeight - outerWeight) * 0.5, x0 - perpX * innerWeight, y0 - perpY * innerWeight, x0 + perpX * outerWeight, y0 + perpY * outerWeight, verts, true) + 2;
16229
- } else if (style.cap === "square") {
16152
+ } else if (style.cap === LineCap.Square) {
16230
16153
  indexCount += square(x0, y0, perpX, perpY, innerWeight, outerWeight, true, verts);
16231
16154
  }
16232
16155
  }
@@ -16265,7 +16188,7 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16265
16188
  verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
16266
16189
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
16267
16190
  /* 180 degree corner? */ if (dot >= 0) {
16268
- if (style.join === "round") {
16191
+ if (style.join === LineJoin.Round) {
16269
16192
  indexCount += round(x1, y1, x1 - perpX * innerWeight, y1 - perpY * innerWeight, x1 - perp1x * innerWeight, y1 - perp1y * innerWeight, verts, false) + 4;
16270
16193
  } else {
16271
16194
  indexCount += 2;
@@ -16289,7 +16212,7 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16289
16212
  var smallerInsideDiagonalSq = smallerInsideSegmentSq + insideWeight * insideWeight * widthSquared;
16290
16213
  var insideMiterOk = pDist <= smallerInsideDiagonalSq;
16291
16214
  if (insideMiterOk) {
16292
- if (style.join === "bevel" || pDist / widthSquared > miterLimitSquared) {
16215
+ if (style.join === LineJoin.Bevel || pDist / widthSquared > miterLimitSquared) {
16293
16216
  if (clockwise) /* rotating at inner angle */ {
16294
16217
  verts.push(imx, imy); // inner miter point
16295
16218
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight); // first segment's outer vertex
@@ -16302,7 +16225,7 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16302
16225
  verts.push(omx, omy); // outer miter point
16303
16226
  }
16304
16227
  indexCount += 2;
16305
- } else if (style.join === "round") {
16228
+ } else if (style.join === LineJoin.Round) {
16306
16229
  if (clockwise) /* arc is outside */ {
16307
16230
  verts.push(imx, imy);
16308
16231
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
@@ -16323,13 +16246,13 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16323
16246
  } else {
16324
16247
  verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight); // first segment's inner vertex
16325
16248
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight); // first segment's outer vertex
16326
- if (style.join === "round") {
16249
+ if (style.join === LineJoin.Round) {
16327
16250
  if (clockwise) /* arc is outside */ {
16328
16251
  indexCount += round(x1, y1, x1 + perpX * outerWeight, y1 + perpY * outerWeight, x1 + perp1x * outerWeight, y1 + perp1y * outerWeight, verts, true) + 2;
16329
16252
  } else /* arc is inside */ {
16330
16253
  indexCount += round(x1, y1, x1 - perpX * innerWeight, y1 - perpY * innerWeight, x1 - perp1x * innerWeight, y1 - perp1y * innerWeight, verts, false) + 2;
16331
16254
  }
16332
- } else if (style.join === "miter" && pDist / widthSquared <= miterLimitSquared) {
16255
+ } else if (style.join === LineJoin.Miter && pDist / widthSquared <= miterLimitSquared) {
16333
16256
  if (clockwise) {
16334
16257
  verts.push(omx, omy); // inner miter point
16335
16258
  verts.push(omx, omy); // inner miter point
@@ -16358,9 +16281,9 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16358
16281
  verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
16359
16282
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
16360
16283
  if (!closedShape) {
16361
- if (style.cap === "round") {
16284
+ if (style.cap === LineCap.Round) {
16362
16285
  indexCount += round(x1 - perpX * (innerWeight - outerWeight) * 0.5, y1 - perpY * (innerWeight - outerWeight) * 0.5, x1 - perpX * innerWeight, y1 - perpY * innerWeight, x1 + perpX * outerWeight, y1 + perpY * outerWeight, verts, false) + 2;
16363
- } else if (style.cap === "square") {
16286
+ } else if (style.cap === LineCap.Square) {
16364
16287
  indexCount += square(x1, y1, perpX, perpY, innerWeight, outerWeight, false, verts);
16365
16288
  }
16366
16289
  }
@@ -16387,9 +16310,10 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16387
16310
  var _this;
16388
16311
  _this = MeshComponent.call(this, engine) || this;
16389
16312
  _this.isStroke = false;
16313
+ _this.isFill = false;
16314
+ _this.shapeDirty = true;
16390
16315
  _this.graphicsPath = new GraphicsPath();
16391
16316
  _this.curveValues = [];
16392
- _this.shapeDirty = true;
16393
16317
  _this.vert = "\nprecision highp float;\n\nattribute vec3 aPos;//x y\n\nuniform mat4 effects_MatrixVP;\nuniform mat4 effects_MatrixInvV;\nuniform mat4 effects_ObjectToWorld;\n\nvoid main() {\n vec4 pos = vec4(aPos.xyz, 1.0);\n gl_Position = effects_MatrixVP * effects_ObjectToWorld * pos;\n}\n";
16394
16318
  _this.frag = "\nprecision highp float;\n\nuniform vec4 _Color;\n\nvoid main() {\n vec4 color = _Color;\n color.rgb *= color.a;\n gl_FragColor = color;\n}\n";
16395
16319
  if (!_this.geometry) {
@@ -16422,6 +16346,15 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16422
16346
  mode: glContext.TRIANGLES,
16423
16347
  drawCount: 4
16424
16348
  });
16349
+ _this.geometry.subMeshes.push({
16350
+ offset: 0,
16351
+ indexCount: 0,
16352
+ vertexCount: 0
16353
+ }, {
16354
+ offset: 0,
16355
+ indexCount: 0,
16356
+ vertexCount: 0
16357
+ });
16425
16358
  }
16426
16359
  if (!_this.material) {
16427
16360
  var materialProps = {
@@ -16431,18 +16364,29 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16431
16364
  glslVersion: exports.GLSLVersion.GLSL1
16432
16365
  }
16433
16366
  };
16434
- _this.material = Material.create(engine, materialProps);
16435
- _this.material.setColor("_Color", new Color(1, 1, 1, 1));
16436
- _this.material.depthMask = false;
16437
- _this.material.depthTest = true;
16438
- _this.material.blending = true;
16367
+ var fillMaterial = Material.create(engine, materialProps);
16368
+ fillMaterial.setColor("_Color", new Color(1, 1, 1, 1));
16369
+ fillMaterial.depthMask = false;
16370
+ fillMaterial.depthTest = true;
16371
+ fillMaterial.blending = true;
16372
+ _this.material = fillMaterial;
16373
+ var strokeMaterial = Material.create(engine, materialProps);
16374
+ strokeMaterial.setColor("_Color", new Color(0.25, 0.25, 0.25, 1));
16375
+ strokeMaterial.depthMask = false;
16376
+ strokeMaterial.depthTest = true;
16377
+ strokeMaterial.blending = true;
16378
+ _this.materials[1] = strokeMaterial;
16439
16379
  }
16440
16380
  _this.strokeAttributes = {
16441
16381
  width: 1,
16442
16382
  alignment: 0.5,
16443
- cap: "butt",
16444
- join: "miter",
16445
- miterLimit: 10
16383
+ cap: LineCap.Butt,
16384
+ join: LineJoin.Miter,
16385
+ miterLimit: 10,
16386
+ color: new Color(1, 1, 1, 1)
16387
+ };
16388
+ _this.fillAttribute = {
16389
+ color: new Color(1, 1, 1, 1)
16446
16390
  };
16447
16391
  _this.shapeAttribute = {
16448
16392
  type: ShapePrimitiveType.Custom,
@@ -16458,6 +16402,8 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16458
16402
  this.item.getHitTestParams = this.getHitTestParams;
16459
16403
  };
16460
16404
  _proto.onUpdate = function onUpdate(dt) {
16405
+ this.material.color = this.fillAttribute.color;
16406
+ this.materials[1].color = this.strokeAttributes.color;
16461
16407
  if (this.shapeDirty) {
16462
16408
  this.buildPath(this.shapeAttribute);
16463
16409
  this.buildGeometryFromPath(this.graphicsPath.shapePath);
@@ -16468,22 +16414,34 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16468
16414
  var shapePrimitives = shapePath.shapePrimitives;
16469
16415
  var vertices = [];
16470
16416
  var indices = [];
16471
- // triangulate shapePrimitive
16472
- for(var _iterator = _create_for_of_iterator_helper_loose(shapePrimitives), _step; !(_step = _iterator()).done;){
16473
- var shapePrimitive = _step.value;
16474
- var shape = shapePrimitive.shape;
16475
- var points = [];
16476
- var indexOffset = indices.length;
16477
- var vertOffset = vertices.length / 2;
16478
- shape.build(points);
16479
- if (!this.isStroke) {
16417
+ // Triangulate shapePrimitive
16418
+ //---------------------------------------------------
16419
+ if (this.isFill) {
16420
+ for(var _iterator = _create_for_of_iterator_helper_loose(shapePrimitives), _step; !(_step = _iterator()).done;){
16421
+ var shapePrimitive = _step.value;
16422
+ var shape = shapePrimitive.shape;
16423
+ var points = [];
16424
+ var indexOffset = indices.length;
16425
+ var vertOffset = vertices.length / 2;
16426
+ shape.build(points);
16480
16427
  shape.triangulate(points, vertices, vertOffset, indices, indexOffset);
16481
- } else {
16428
+ }
16429
+ }
16430
+ var fillIndexCount = indices.length;
16431
+ if (this.isStroke) {
16432
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(shapePrimitives), _step1; !(_step1 = _iterator1()).done;){
16433
+ var shapePrimitive1 = _step1.value;
16434
+ var shape1 = shapePrimitive1.shape;
16435
+ var points1 = [];
16436
+ indices.length;
16437
+ var vertOffset1 = vertices.length / 2;
16482
16438
  var close = true;
16483
16439
  var lineStyle = this.strokeAttributes;
16484
- buildLine(points, lineStyle, false, close, vertices, 2, vertOffset, indices);
16440
+ shape1.build(points1);
16441
+ buildLine(points1, lineStyle, false, close, vertices, 2, vertOffset1, indices);
16485
16442
  }
16486
16443
  }
16444
+ var strokeIndexCount = indices.length - fillIndexCount;
16487
16445
  var vertexCount = vertices.length / 2;
16488
16446
  // get the current attribute and index arrays from the geometry, avoiding re-creation
16489
16447
  var positionArray = this.geometry.getAttributeData("aPos");
@@ -16516,6 +16474,12 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16516
16474
  this.geometry.setAttributeData("aUV", uvArray);
16517
16475
  this.geometry.setIndexData(indexArray);
16518
16476
  this.geometry.setDrawCount(indices.length);
16477
+ var u16Size = 2;
16478
+ var fillSubMesh = this.geometry.subMeshes[0];
16479
+ var strokeSubMesh = this.geometry.subMeshes[1];
16480
+ fillSubMesh.indexCount = fillIndexCount;
16481
+ strokeSubMesh.offset = fillIndexCount * u16Size;
16482
+ strokeSubMesh.indexCount = strokeIndexCount;
16519
16483
  };
16520
16484
  _proto.buildPath = function buildPath(shapeAttribute) {
16521
16485
  this.graphicsPath.clear();
@@ -16529,7 +16493,6 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16529
16493
  for(var _iterator = _create_for_of_iterator_helper_loose(customShapeAtribute.shapes), _step; !(_step = _iterator()).done;){
16530
16494
  var shape = _step.value;
16531
16495
  this.curveValues = [];
16532
- this.setFillColor(shape.fill);
16533
16496
  var indices = shape.indexes;
16534
16497
  for(var i = 1; i < indices.length; i++){
16535
16498
  var pointIndex = indices[i];
@@ -16561,38 +16524,28 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16561
16524
  {
16562
16525
  var ellipseData = shapeAttribute;
16563
16526
  this.graphicsPath.ellipse(0, 0, ellipseData.xRadius, ellipseData.yRadius);
16564
- this.setFillColor(ellipseData.fill);
16565
16527
  break;
16566
16528
  }
16567
16529
  case ShapePrimitiveType.Rectangle:
16568
16530
  {
16569
16531
  var rectangleData = shapeAttribute;
16570
- this.graphicsPath.rect(-rectangleData.width / 2, -rectangleData.height / 2, rectangleData.width, rectangleData.height);
16571
- this.setFillColor(rectangleData.fill);
16532
+ this.graphicsPath.rect(-rectangleData.width / 2, -rectangleData.height / 2, rectangleData.width, rectangleData.height, rectangleData.roundness);
16572
16533
  break;
16573
16534
  }
16574
16535
  case ShapePrimitiveType.Star:
16575
16536
  {
16576
16537
  var starData = shapeAttribute;
16577
16538
  this.graphicsPath.polyStar(starData.pointCount, starData.outerRadius, starData.innerRadius, starData.outerRoundness, starData.innerRoundness, StarType.Star);
16578
- this.setFillColor(starData.fill);
16579
16539
  break;
16580
16540
  }
16581
16541
  case ShapePrimitiveType.Polygon:
16582
16542
  {
16583
16543
  var polygonData = shapeAttribute;
16584
16544
  this.graphicsPath.polyStar(polygonData.pointCount, polygonData.radius, polygonData.radius, polygonData.roundness, polygonData.roundness, StarType.Polygon);
16585
- this.setFillColor(polygonData.fill);
16586
16545
  break;
16587
16546
  }
16588
16547
  }
16589
16548
  };
16590
- _proto.setFillColor = function setFillColor(fill) {
16591
- if (fill) {
16592
- var color = fill.color;
16593
- this.material.setColor("_Color", new Color(color.r, color.g, color.b, color.a));
16594
- }
16595
- };
16596
16549
  _proto.fromData = function fromData(data) {
16597
16550
  MeshComponent.prototype.fromData.call(this, data);
16598
16551
  this.shapeDirty = true;
@@ -16600,19 +16553,27 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16600
16553
  if (strokeParam) {
16601
16554
  this.isStroke = true;
16602
16555
  this.strokeAttributes.width = strokeParam.width;
16556
+ this.strokeAttributes.color.copyFrom(strokeParam.color);
16557
+ this.strokeAttributes.cap = strokeParam.cap;
16558
+ this.strokeAttributes.join = strokeParam.join;
16559
+ }
16560
+ var fillParam = data.fill;
16561
+ if (fillParam) {
16562
+ this.isFill = true;
16563
+ this.fillAttribute.color.copyFrom(fillParam.color);
16603
16564
  }
16604
16565
  switch(data.type){
16605
16566
  case ShapePrimitiveType.Custom:
16606
16567
  {
16607
- this.shapeAttribute = {
16568
+ var customShapeData = data;
16569
+ var customShapeAttribute = {
16608
16570
  type: ShapePrimitiveType.Custom,
16609
16571
  points: [],
16610
16572
  easingIns: [],
16611
16573
  easingOuts: [],
16612
- shapes: []
16574
+ shapes: [],
16575
+ fill: customShapeData.fill
16613
16576
  };
16614
- var customShapeData = data;
16615
- var customShapeAttribute = this.shapeAttribute;
16616
16577
  for(var _iterator = _create_for_of_iterator_helper_loose(customShapeData.points), _step; !(_step = _iterator()).done;){
16617
16578
  var point = _step.value;
16618
16579
  customShapeAttribute.points.push(new Vector2(point.x, point.y));
@@ -16626,6 +16587,7 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16626
16587
  customShapeAttribute.easingOuts.push(new Vector2(easingOut.x, easingOut.y));
16627
16588
  }
16628
16589
  customShapeAttribute.shapes = customShapeData.shapes;
16590
+ this.shapeAttribute = customShapeAttribute;
16629
16591
  break;
16630
16592
  }
16631
16593
  case ShapePrimitiveType.Ellipse:
@@ -17516,10 +17478,8 @@ function shouldIgnoreBouncing(arg, mul) {
17516
17478
  };
17517
17479
  };
17518
17480
  _proto.setGeometry = function setGeometry(geometry, worldMatrix) {
17519
- if (this.geometry !== geometry) {
17520
- this.triangles = this.geometryToTriangles(geometry);
17521
- this.geometry = geometry;
17522
- }
17481
+ this.triangles = this.geometryToTriangles(geometry);
17482
+ this.geometry = geometry;
17523
17483
  var area = [];
17524
17484
  for(var _iterator = _create_for_of_iterator_helper_loose(this.triangles), _step; !(_step = _iterator()).done;){
17525
17485
  var triangle = _step.value;
@@ -17540,10 +17500,11 @@ function shouldIgnoreBouncing(arg, mul) {
17540
17500
  _proto.geometryToTriangles = function geometryToTriangles(geometry) {
17541
17501
  var _geometry_getIndexData;
17542
17502
  var indices = (_geometry_getIndexData = geometry.getIndexData()) != null ? _geometry_getIndexData : [];
17503
+ var drawCount = geometry.getDrawCount();
17543
17504
  var _geometry_getAttributeData;
17544
17505
  var vertices = (_geometry_getAttributeData = geometry.getAttributeData("aPos")) != null ? _geometry_getAttributeData : [];
17545
17506
  var res = [];
17546
- for(var i = 0; i < indices.length; i += 3){
17507
+ for(var i = 0; i < drawCount; i += 3){
17547
17508
  var index0 = indices[i] * 3;
17548
17509
  var index1 = indices[i + 1] * 3;
17549
17510
  var index2 = indices[i + 2] * 3;
@@ -25526,6 +25487,9 @@ exports.TextComponent = /*#__PURE__*/ function(BaseRenderComponent) {
25526
25487
  /**
25527
25488
  * 文本行数
25528
25489
  */ _this.lineCount = 0;
25490
+ /**
25491
+ * 每一行文本的最大宽度
25492
+ */ _this.maxLineWidth = 0;
25529
25493
  _this.SCALE_FACTOR = 0.1;
25530
25494
  _this.ALPHA_FIX_VALUE = 1 / 255;
25531
25495
  _this.name = "MText" + seed$1++;
@@ -25609,12 +25573,9 @@ var TextComponentBase = /*#__PURE__*/ function() {
25609
25573
  this.textStyle = new TextStyle(options);
25610
25574
  this.textLayout = new TextLayout(options);
25611
25575
  this.text = options.text.toString();
25612
- this.lineCount = this.getLineCount(options.text, true);
25613
25576
  };
25614
- _proto.getLineCount = function getLineCount(text, init) {
25615
- var context = this.context;
25616
- var letterSpace = this.textLayout.letterSpace;
25617
- var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
25577
+ _proto.getLineCount = function getLineCount(text, context) {
25578
+ var _this_textLayout = this.textLayout, letterSpace = _this_textLayout.letterSpace, overflow = _this_textLayout.overflow;
25618
25579
  var width = this.textLayout.width + this.textStyle.fontOffset;
25619
25580
  var lineCount = 1;
25620
25581
  var x = 0;
@@ -25622,15 +25583,27 @@ var TextComponentBase = /*#__PURE__*/ function() {
25622
25583
  var _context_measureText;
25623
25584
  var str = text[i];
25624
25585
  var _context_measureText_width;
25625
- var textMetrics = ((_context_measureText_width = context == null ? void 0 : (_context_measureText = context.measureText(str)) == null ? void 0 : _context_measureText.width) != null ? _context_measureText_width : 0) * fontScale;
25586
+ var textMetrics = (_context_measureText_width = context == null ? void 0 : (_context_measureText = context.measureText(str)) == null ? void 0 : _context_measureText.width) != null ? _context_measureText_width : 0;
25626
25587
  // 和浏览器行为保持一致
25627
25588
  x += letterSpace;
25628
- if (x + textMetrics > width && i > 0 || str === "\n") {
25629
- lineCount++;
25630
- x = 0;
25631
- }
25632
- if (str !== "\n") {
25633
- x += textMetrics;
25589
+ // 处理文本结束行为
25590
+ if (overflow === TextOverflow.display) {
25591
+ if (str === "\n") {
25592
+ lineCount++;
25593
+ x = 0;
25594
+ } else {
25595
+ x += textMetrics;
25596
+ this.maxLineWidth = Math.max(this.maxLineWidth, x);
25597
+ }
25598
+ } else {
25599
+ if (x + textMetrics > width && i > 0 || str === "\n") {
25600
+ lineCount++;
25601
+ this.maxLineWidth = Math.max(this.maxLineWidth, x);
25602
+ x = 0;
25603
+ }
25604
+ if (str !== "\n") {
25605
+ x += textMetrics;
25606
+ }
25634
25607
  }
25635
25608
  }
25636
25609
  return lineCount;
@@ -25680,7 +25653,6 @@ var TextComponentBase = /*#__PURE__*/ function() {
25680
25653
  return;
25681
25654
  }
25682
25655
  this.text = value.toString();
25683
- this.lineCount = this.getLineCount(value, false);
25684
25656
  this.isDirty = true;
25685
25657
  };
25686
25658
  /**
@@ -25762,6 +25734,18 @@ var TextComponentBase = /*#__PURE__*/ function() {
25762
25734
  this.isDirty = true;
25763
25735
  };
25764
25736
  /**
25737
+ * 设置文本溢出模式
25738
+ *
25739
+ * - clip: 当文本内容超出边界框时,多余的会被截断。
25740
+ * - display: 该模式下会显示所有文本,会自动调整文本字号以保证显示完整。
25741
+ * > 当存在多行时,部分行内文本可能存在文本字号变小的情况,其他行为正常情况
25742
+ *
25743
+ * @param overflow - 文本溢出模式
25744
+ */ _proto.setOverflow = function setOverflow(overflow) {
25745
+ this.textLayout.overflow = overflow;
25746
+ this.isDirty = true;
25747
+ };
25748
+ /**
25765
25749
  * 设置阴影颜色
25766
25750
  * @param value - 阴影颜色
25767
25751
  * @returns
@@ -25829,28 +25813,35 @@ var TextComponentBase = /*#__PURE__*/ function() {
25829
25813
  var layout = this.textLayout;
25830
25814
  var fontScale = style.fontScale;
25831
25815
  var width = (layout.width + style.fontOffset) * fontScale;
25832
- var finalHeight = layout.lineHeight * this.lineCount;
25833
25816
  var fontSize = style.fontSize * fontScale;
25834
25817
  var lineHeight = layout.lineHeight * fontScale;
25818
+ style.fontDesc = this.getFontDesc(fontSize);
25835
25819
  this.char = (this.text || "").split("");
25836
25820
  this.canvas.width = width;
25821
+ var height = this.canvas.height;
25822
+ context.font = style.fontDesc;
25823
+ this.lineCount = this.getLineCount(this.text, context);
25824
+ var finalHeight = layout.lineHeight * this.lineCount;
25837
25825
  if (layout.autoWidth) {
25838
25826
  this.canvas.height = finalHeight * fontScale;
25839
25827
  this.item.transform.size.set(1, finalHeight / layout.height);
25840
25828
  } else {
25841
25829
  this.canvas.height = layout.height * fontScale;
25842
25830
  }
25843
- var height = this.canvas.height;
25844
- context.clearRect(0, 0, width, height);
25831
+ // canvas size 变化后重新刷新 context
25832
+ if (this.maxLineWidth > width && layout.overflow === TextOverflow.display) {
25833
+ context.font = this.getFontDesc(fontSize * width / this.maxLineWidth);
25834
+ } else {
25835
+ context.font = style.fontDesc;
25836
+ }
25845
25837
  // fix bug 1/255
25846
25838
  context.fillStyle = "rgba(255, 255, 255, 0.0039)";
25839
+ context.clearRect(0, 0, width, height);
25847
25840
  if (!flipY) {
25848
25841
  context.translate(0, height);
25849
25842
  context.scale(1, -1);
25850
25843
  }
25851
25844
  context.fillRect(0, 0, width, height);
25852
- style.fontDesc = this.getFontDesc();
25853
- context.font = style.fontDesc;
25854
25845
  if (style.hasShadow) {
25855
25846
  this.setupShadow();
25856
25847
  }
@@ -25922,9 +25913,9 @@ var TextComponentBase = /*#__PURE__*/ function() {
25922
25913
  this.material.setTexture("_MainTex", texture);
25923
25914
  this.isDirty = false;
25924
25915
  };
25925
- _proto.getFontDesc = function getFontDesc() {
25926
- var _this_textStyle = this.textStyle, fontSize = _this_textStyle.fontSize, fontScale = _this_textStyle.fontScale, fontFamily = _this_textStyle.fontFamily, textWeight = _this_textStyle.textWeight, fontStyle = _this_textStyle.fontStyle;
25927
- var fontDesc = "" + (fontSize * fontScale).toString() + "px ";
25916
+ _proto.getFontDesc = function getFontDesc(fontSize) {
25917
+ var _this_textStyle = this.textStyle, fontFamily = _this_textStyle.fontFamily, textWeight = _this_textStyle.textWeight, fontStyle = _this_textStyle.fontStyle;
25918
+ var fontDesc = "" + fontSize.toString() + "px ";
25928
25919
  if (!DEFAULT_FONTS.includes(fontFamily)) {
25929
25920
  fontDesc += '"' + fontFamily + '"';
25930
25921
  } else {
@@ -26694,12 +26685,29 @@ function getStandardInteractContent(ui) {
26694
26685
  * 3.1 版本数据适配
26695
26686
  * - 富文本插件名称的适配
26696
26687
  */ function version31Migration(json) {
26697
- var _json_plugins;
26688
+ var // 修正老版本数据中,富文本插件名称的问题
26689
+ _json_plugins;
26698
26690
  (_json_plugins = json.plugins) == null ? void 0 : _json_plugins.forEach(function(plugin, index) {
26699
26691
  if (plugin === "richtext") {
26700
26692
  json.plugins[index] = "rich-text";
26701
26693
  }
26702
26694
  });
26695
+ // Custom shape fill 属性位置迁移
26696
+ for(var _iterator = _create_for_of_iterator_helper_loose(json.components), _step; !(_step = _iterator()).done;){
26697
+ var component = _step.value;
26698
+ if (component.dataType === DataType.ShapeComponent) {
26699
+ var shapeComponent = component;
26700
+ if (shapeComponent.type === ShapePrimitiveType.Custom) {
26701
+ var _customShapeComponent_shapes;
26702
+ var customShapeComponent = shapeComponent;
26703
+ //@ts-expect-error
26704
+ if (((_customShapeComponent_shapes = customShapeComponent.shapes) == null ? void 0 : _customShapeComponent_shapes.length) > 0 && customShapeComponent.shapes[0].fill) {
26705
+ // @ts-expect-error
26706
+ customShapeComponent.fill = customShapeComponent.shapes[0].fill;
26707
+ }
26708
+ }
26709
+ }
26710
+ }
26703
26711
  return json;
26704
26712
  }
26705
26713
  /**
@@ -27529,8 +27537,6 @@ function getStandardJSON(json) {
27529
27537
  }
27530
27538
  // 修正老版本数据中,meshItem 以及 lightItem 结束行为错误问题
27531
27539
  version22Migration(json);
27532
- // 修正老版本数据中,富文本插件名称的问题
27533
- version31Migration(json);
27534
27540
  if (v0.test(json.version)) {
27535
27541
  var _exec;
27536
27542
  reverseParticle = ((_exec = /^(\d+)/.exec(json.version)) == null ? void 0 : _exec[0]) === "0";
@@ -27545,7 +27551,13 @@ function getStandardJSON(json) {
27545
27551
  json = version24Migration(json);
27546
27552
  }
27547
27553
  if (mainVersion < 3) {
27548
- return version30Migration(version21Migration(json));
27554
+ json = version30Migration(version21Migration(json));
27555
+ }
27556
+ // 3.x 版本格式转换
27557
+ if (mainVersion < 4) {
27558
+ if (minorVersion < 2) {
27559
+ json = version31Migration(json);
27560
+ }
27549
27561
  }
27550
27562
  return json;
27551
27563
  }
@@ -27601,13 +27613,11 @@ function getStandardJSONFromV0(json) {
27601
27613
  }
27602
27614
  function getStandardImage(image, index, imageTags) {
27603
27615
  var renderLevel = imageTags[index];
27604
- var oriY = image.oriY;
27605
27616
  if (typeof image === "string") {
27606
27617
  return {
27607
27618
  id: generateGUID(),
27608
27619
  renderLevel: renderLevel,
27609
- url: image,
27610
- oriY: oriY
27620
+ url: image
27611
27621
  };
27612
27622
  } else if (image.template) {
27613
27623
  return {
@@ -27615,14 +27625,12 @@ function getStandardImage(image, index, imageTags) {
27615
27625
  url: image.url,
27616
27626
  template: image.template,
27617
27627
  webp: image.webp,
27618
- renderLevel: renderLevel,
27619
- oriY: oriY
27628
+ renderLevel: renderLevel
27620
27629
  };
27621
27630
  } else if (image.compressed) {
27622
27631
  return {
27623
27632
  id: generateGUID(),
27624
27633
  url: image.url,
27625
- oriY: oriY,
27626
27634
  compressed: {
27627
27635
  astc: image.compressed.android,
27628
27636
  pvrtc: image.compressed.iOS
@@ -27635,8 +27643,7 @@ function getStandardImage(image, index, imageTags) {
27635
27643
  id: generateGUID(),
27636
27644
  url: image.url,
27637
27645
  webp: image.webp,
27638
- renderLevel: renderLevel,
27639
- oriY: oriY
27646
+ renderLevel: renderLevel
27640
27647
  };
27641
27648
  } else if (image && image.sourceType) {
27642
27649
  return image;
@@ -32078,7 +32085,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem, true);
32078
32085
  registerPlugin("particle", ParticleLoader, exports.VFXItem, true);
32079
32086
  registerPlugin("cal", CalculateLoader, exports.VFXItem, true);
32080
32087
  registerPlugin("interact", InteractLoader, exports.VFXItem, true);
32081
- var version = "2.3.0-alpha.1";
32088
+ var version = "2.3.0-alpha.2";
32082
32089
  logger.info("Core version: " + version + ".");
32083
32090
 
32084
32091
  exports.AbstractPlugin = AbstractPlugin;