@galacean/effects-threejs 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 threejs plugin 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';
@@ -1061,7 +1061,8 @@ function _inherits(subClass, superClass) {
1061
1061
  JSONSceneVersion["2_4"] = "2.4";
1062
1062
  JSONSceneVersion["3_0"] = "3.0";
1063
1063
  JSONSceneVersion["3_1"] = "3.1";
1064
- JSONSceneVersion["LATEST"] = "3.1";
1064
+ JSONSceneVersion["3_2"] = "3.2";
1065
+ JSONSceneVersion["LATEST"] = "3.2";
1065
1066
  })(JSONSceneVersion || (JSONSceneVersion = {}));
1066
1067
 
1067
1068
  /*********************************************/ /* 元素属性参数类型 */ /*********************************************/ /**
@@ -1599,7 +1600,7 @@ var MaterialBlending;
1599
1600
  var TextOverflow;
1600
1601
  (function(TextOverflow) {
1601
1602
  /**
1602
- * display 模式下,会显示所有文本,存在文本超过边界框的情况。
1603
+ * display 模式下,会显示所有文本,文本大小会根据边界框调整。
1603
1604
  */ TextOverflow[TextOverflow["display"] = 0] = "display";
1604
1605
  /**
1605
1606
  * clip 模式下,当文本内容超出边界框时,多余的会被截断。
@@ -1692,12 +1693,18 @@ var BuiltinObjectGUID = {
1692
1693
  */ ShapePrimitiveType[ShapePrimitiveType["Star"] = 4] = "Star";
1693
1694
  })(ShapePrimitiveType || (ShapePrimitiveType = {}));
1694
1695
 
1695
- // 本期无该功能 待补充
1696
- var ShapeConnectType;
1697
- (function(ShapeConnectType) {})(ShapeConnectType || (ShapeConnectType = {}));
1698
- // @待补充
1699
- var ShapePointType;
1700
- (function(ShapePointType) {})(ShapePointType || (ShapePointType = {}));
1696
+ var LineCap;
1697
+ (function(LineCap) {
1698
+ /** 默认值。向线条的每个末端添加平直的边缘 */ LineCap[LineCap["Butt"] = 0] = "Butt";
1699
+ /** 向线条的每个末端添加圆形线帽 */ LineCap[LineCap["Round"] = 1] = "Round";
1700
+ /** 向线条的每个末端添加正方形线帽 */ LineCap[LineCap["Square"] = 2] = "Square";
1701
+ })(LineCap || (LineCap = {}));
1702
+ var LineJoin;
1703
+ (function(LineJoin) {
1704
+ /** 创建圆角 */ LineJoin[LineJoin["Round"] = 0] = "Round";
1705
+ /** 创建斜角 */ LineJoin[LineJoin["Bevel"] = 1] = "Bevel";
1706
+ /** 创建尖角 */ LineJoin[LineJoin["Miter"] = 2] = "Miter";
1707
+ })(LineJoin || (LineJoin = {}));
1701
1708
 
1702
1709
  /**
1703
1710
  * 动态换图类型
@@ -1906,8 +1913,8 @@ var index$1 = /*#__PURE__*/Object.freeze({
1906
1913
  get FontStyle () { return FontStyle; },
1907
1914
  BuiltinObjectGUID: BuiltinObjectGUID,
1908
1915
  get ShapePrimitiveType () { return ShapePrimitiveType; },
1909
- get ShapeConnectType () { return ShapeConnectType; },
1910
- get ShapePointType () { return ShapePointType; },
1916
+ get LineCap () { return LineCap; },
1917
+ get LineJoin () { return LineJoin; },
1911
1918
  get BackgroundType () { return BackgroundType; },
1912
1919
  get MultimediaType () { return MultimediaType; },
1913
1920
  get DataType () { return DataType; },
@@ -3826,7 +3833,9 @@ Vector4.ZERO = new Vector4(0.0, 0.0, 0.0, 0.0);
3826
3833
  if (renderer.renderingData.currentFrame.globalUniforms) {
3827
3834
  renderer.setGlobalMatrix("effects_ObjectToWorld", this.transform.getWorldMatrix());
3828
3835
  }
3829
- renderer.drawGeometry(this.geometry, this.material);
3836
+ for(var i = 0; i < this.materials.length; i++){
3837
+ renderer.drawGeometry(this.geometry, this.materials[i], i);
3838
+ }
3830
3839
  };
3831
3840
  _proto.getBoundingBox = function getBoundingBox() {
3832
3841
  var worldMatrix = this.transform.getWorldMatrix();
@@ -7361,7 +7370,15 @@ var BYTES_TYPE_MAP = (_obj$6 = {}, _obj$6[glContext.FLOAT] = Float32Array.BYTES_
7361
7370
  */ var Geometry = /*#__PURE__*/ function(EffectsObject) {
7362
7371
  _inherits(Geometry, EffectsObject);
7363
7372
  function Geometry() {
7364
- return EffectsObject.apply(this, arguments);
7373
+ var _this;
7374
+ _this = EffectsObject.apply(this, arguments) || this;
7375
+ /**
7376
+ * Geometry 的名称
7377
+ */ _this.name = "";
7378
+ /**
7379
+ * 子网格数据
7380
+ */ _this.subMeshes = [];
7381
+ return _this;
7365
7382
  }
7366
7383
  var _proto = Geometry.prototype;
7367
7384
  /**
@@ -12727,18 +12744,12 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
12727
12744
  var keyTimeStart = this.curveMap[keyTimeData[0]].timeStart;
12728
12745
  var keyTimeEnd = this.curveMap[keyTimeData[keyTimeData.length - 1]].timeEnd;
12729
12746
  if (time <= keyTimeStart) {
12730
- if (this.startKeyframe[0] === BezierKeyframeType.LINE || this.startKeyframe[0] === BezierKeyframeType.HOLD) {
12731
- keyframeInfo.getPointIndexInCurve(this.startKeyframe, keyframeInfo.pointIndexCache);
12732
- return this.endKeyframe[1][keyframeInfo.pointIndexCache.yIndex];
12733
- }
12734
- return this.getCurveValue(keyTimeData[0], keyTimeStart);
12747
+ keyframeInfo.getPointIndexInCurve(this.startKeyframe, keyframeInfo.pointIndexCache);
12748
+ return this.startKeyframe[1][keyframeInfo.pointIndexCache.yIndex];
12735
12749
  }
12736
12750
  if (time >= keyTimeEnd) {
12737
- if (this.endKeyframe[0] === BezierKeyframeType.LINE || this.endKeyframe[0] === BezierKeyframeType.HOLD) {
12738
- keyframeInfo.getPointIndexInCurve(this.endKeyframe, keyframeInfo.pointIndexCache);
12739
- return this.endKeyframe[1][keyframeInfo.pointIndexCache.yIndex];
12740
- }
12741
- return this.getCurveValue(keyTimeData[keyTimeData.length - 1], keyTimeEnd);
12751
+ keyframeInfo.getPointIndexInCurve(this.endKeyframe, keyframeInfo.pointIndexCache);
12752
+ return this.endKeyframe[1][keyframeInfo.pointIndexCache.yIndex];
12742
12753
  }
12743
12754
  for(var i = 0; i < keyTimeData.length; i++){
12744
12755
  var xMin = this.curveMap[keyTimeData[i]].timeStart;
@@ -14884,6 +14895,10 @@ function triangulate(contours) {
14884
14895
  points
14885
14896
  ]);
14886
14897
  var indexStart = vertices.length / 2;
14898
+ // 当所有 points 在一条直线时, gluTess 三角化 triangles 会返回空数组,这边做一下额外处理返回线段左右端点组成的三角形,确保拿到的包围盒是正确的。
14899
+ if (triangles.length === 0) {
14900
+ this.getLineEndPointsTriangle(points, triangles);
14901
+ }
14887
14902
  for(var i = 0; i < triangles.length; i++){
14888
14903
  vertices[verticesOffset * 2 + i] = triangles[i];
14889
14904
  }
@@ -14892,6 +14907,57 @@ function triangulate(contours) {
14892
14907
  indices[indicesOffset + i1] = indexStart + i1;
14893
14908
  }
14894
14909
  };
14910
+ /**
14911
+ * 获取直线上最远的两个端点坐标组成的三角形
14912
+ */ _proto.getLineEndPointsTriangle = function getLineEndPointsTriangle(points, triangles) {
14913
+ // 参数检查
14914
+ if (!points || points.length < 2 || points.length % 2 !== 0) {
14915
+ throw new Error("Invalid points array");
14916
+ }
14917
+ if (points.length === 2) {
14918
+ triangles.push(points[0], points[1], points[0], points[1], points[0], points[1]);
14919
+ return;
14920
+ }
14921
+ // 取第一个线段计算斜率
14922
+ var dx = points[2] - points[0];
14923
+ var dy = points[3] - points[1];
14924
+ // 存放结果坐标
14925
+ var startX = points[0];
14926
+ var startY = points[1];
14927
+ var endX = points[0];
14928
+ var endY = points[1];
14929
+ // 根据斜率决定比较x还是y
14930
+ if (Math.abs(dx) >= Math.abs(dy)) {
14931
+ // 水平方向为主,比较x坐标
14932
+ for(var i = 0; i < points.length; i += 2){
14933
+ var x = points[i];
14934
+ var y = points[i + 1];
14935
+ if (x < startX) {
14936
+ startX = x;
14937
+ startY = y;
14938
+ }
14939
+ if (x > endX) {
14940
+ endX = x;
14941
+ endY = y;
14942
+ }
14943
+ }
14944
+ } else {
14945
+ // 垂直方向为主,比较y坐标
14946
+ for(var i1 = 0; i1 < points.length; i1 += 2){
14947
+ var x1 = points[i1];
14948
+ var y1 = points[i1 + 1];
14949
+ if (y1 < startY) {
14950
+ startX = x1;
14951
+ startY = y1;
14952
+ }
14953
+ if (y1 > endY) {
14954
+ endX = x1;
14955
+ endY = y1;
14956
+ }
14957
+ }
14958
+ }
14959
+ triangles.push(startX, startY, endX, endY, endX, endY);
14960
+ };
14895
14961
  _create_class(Polygon, [
14896
14962
  {
14897
14963
  key: "lastX",
@@ -15365,47 +15431,48 @@ var PolyStar = /*#__PURE__*/ function(ShapePrimitive) {
15365
15431
  }(ShapePrimitive);
15366
15432
 
15367
15433
  // Based on:
15368
- // const tempPoints = [new Point(), new Point(), new Point(), new Point()];
15369
15434
  /**
15370
- * The `Rectangle` object is an area defined by its position, as indicated by its upper-left corner
15371
- * point (`x`, `y`) and by its `width` and its `height`.
15435
+ * The `Rectangle` object is an area defined by its position, as indicated by its top-left corner
15436
+ * point (`x`, `y`) and by its `width` and its `height`, including a `roundness` property that
15437
+ * defines the roundness of the rounded corners.
15438
+ * @memberof maths
15372
15439
  */ var Rectangle$1 = /*#__PURE__*/ function(ShapePrimitive) {
15373
15440
  _inherits(Rectangle, ShapePrimitive);
15374
- function Rectangle(x, y, width, height) {
15441
+ function Rectangle(x, y, width, height, roundness) {
15375
15442
  if (x === void 0) x = 0;
15376
15443
  if (y === void 0) y = 0;
15377
15444
  if (width === void 0) width = 0;
15378
15445
  if (height === void 0) height = 0;
15446
+ if (roundness === void 0) roundness = 20;
15379
15447
  var _this;
15380
15448
  _this = ShapePrimitive.call(this) || this;
15381
- _this.x = Number(x);
15382
- _this.y = Number(y);
15383
- _this.width = Number(width);
15384
- _this.height = Number(height);
15449
+ _this.x = x;
15450
+ _this.y = y;
15451
+ _this.width = width;
15452
+ _this.height = height;
15453
+ _this.roundness = roundness;
15385
15454
  return _this;
15386
15455
  }
15387
15456
  var _proto = Rectangle.prototype;
15388
- /** Determines whether the Rectangle is empty. */ _proto.isEmpty = function isEmpty() {
15389
- return this.left === this.right || this.top === this.bottom;
15457
+ /**
15458
+ * Returns the framing rectangle of the rectangle as a Rectangle object
15459
+ * @param out - optional rectangle to store the result
15460
+ * @returns The framing rectangle
15461
+ */ _proto.getBounds = function getBounds(out) {
15462
+ out = out || new Rectangle();
15463
+ out.x = this.x;
15464
+ out.y = this.y;
15465
+ out.width = this.width;
15466
+ out.height = this.height;
15467
+ return out;
15390
15468
  };
15391
15469
  /**
15392
- * Creates a clone of this Rectangle
15393
- * @returns a copy of the rectangle
15470
+ * Creates a clone of this rectangle.
15471
+ * @returns - A copy of the rectangle.
15394
15472
  */ _proto.clone = function clone() {
15395
- return new Rectangle(this.x, this.y, this.width, this.height);
15473
+ return new Rectangle(this.x, this.y, this.width, this.height, this.roundness);
15396
15474
  };
15397
15475
  /**
15398
- * Converts a Bounds object to a Rectangle object.
15399
- * @param bounds - The bounds to copy and convert to a rectangle.
15400
- * @returns Returns itself.
15401
- */ // copyFromBounds (bounds: Bounds): this {
15402
- // this.x = bounds.minX;
15403
- // this.y = bounds.minY;
15404
- // this.width = bounds.maxX - bounds.minX;
15405
- // this.height = bounds.maxY - bounds.minY;
15406
- // return this;
15407
- // }
15408
- /**
15409
15476
  * Copies another rectangle to this one.
15410
15477
  * @param rectangle - The rectangle to copy from.
15411
15478
  * @returns Returns itself.
@@ -15414,6 +15481,7 @@ var PolyStar = /*#__PURE__*/ function(ShapePrimitive) {
15414
15481
  this.y = rectangle.y;
15415
15482
  this.width = rectangle.width;
15416
15483
  this.height = rectangle.height;
15484
+ this.roundness = rectangle.roundness;
15417
15485
  return this;
15418
15486
  };
15419
15487
  /**
@@ -15424,267 +15492,121 @@ var PolyStar = /*#__PURE__*/ function(ShapePrimitive) {
15424
15492
  rectangle.copyFrom(this);
15425
15493
  return rectangle;
15426
15494
  };
15427
- /**
15428
- * Checks whether the x and y coordinates given are contained within this Rectangle
15429
- * @param x - The X coordinate of the point to test
15430
- * @param y - The Y coordinate of the point to test
15431
- * @returns Whether the x/y coordinates are within this Rectangle
15432
- */ _proto.contains = function contains(x, y) {
15433
- if (this.width <= 0 || this.height <= 0) {
15434
- return false;
15495
+ _proto.build = function build(points) {
15496
+ var ry;
15497
+ var halfWidth = this.width / 2;
15498
+ var halfHeight = this.height / 2;
15499
+ var x = this.x + halfWidth;
15500
+ var y = this.y + halfHeight;
15501
+ var rx = ry = Math.max(0, Math.min(this.roundness / 100, 1) * Math.min(halfWidth, halfHeight));
15502
+ var dx = halfWidth - rx;
15503
+ var dy = halfHeight - ry;
15504
+ if (!(rx >= 0 && ry >= 0 && dx >= 0 && dy >= 0)) {
15505
+ return;
15435
15506
  }
15436
- if (x >= this.x && x < this.x + this.width) {
15437
- if (y >= this.y && y < this.y + this.height) {
15438
- return true;
15439
- }
15507
+ // 控制边缘的平滑程度
15508
+ var densityScale = 5;
15509
+ // Choose a number of segments such that the maximum absolute deviation from the circle is approximately 0.029
15510
+ var n = densityScale * Math.ceil(2.3 * Math.sqrt(rx + ry));
15511
+ var m = n * 8 + (dx ? 4 : 0) + (dy ? 4 : 0);
15512
+ if (m === 0) {
15513
+ return;
15440
15514
  }
15441
- return false;
15442
- };
15443
- /**
15444
- * Checks whether the x and y coordinates given are contained within this rectangle including the stroke.
15445
- * @param x - The X coordinate of the point to test
15446
- * @param y - The Y coordinate of the point to test
15447
- * @param strokeWidth - The width of the line to check
15448
- * @returns Whether the x/y coordinates are within this rectangle
15449
- */ _proto.strokeContains = function strokeContains(x, y, strokeWidth) {
15450
- var _this = this, width = _this.width, height = _this.height;
15451
- if (width <= 0 || height <= 0) {
15452
- return false;
15515
+ if (n === 0) {
15516
+ points[0] = points[6] = x + dx;
15517
+ points[1] = points[3] = y + dy;
15518
+ points[2] = points[4] = x - dx;
15519
+ points[5] = points[7] = y - dy;
15520
+ return;
15453
15521
  }
15454
- var _x = this.x;
15455
- var _y = this.y;
15456
- var outerLeft = _x - strokeWidth / 2;
15457
- var outerRight = _x + width + strokeWidth / 2;
15458
- var outerTop = _y - strokeWidth / 2;
15459
- var outerBottom = _y + height + strokeWidth / 2;
15460
- var innerLeft = _x + strokeWidth / 2;
15461
- var innerRight = _x + width - strokeWidth / 2;
15462
- var innerTop = _y + strokeWidth / 2;
15463
- var innerBottom = _y + height - strokeWidth / 2;
15464
- return x >= outerLeft && x <= outerRight && y >= outerTop && y <= outerBottom && !(x > innerLeft && x < innerRight && y > innerTop && y < innerBottom);
15465
- };
15466
- /**
15467
- * Determines whether the `other` Rectangle transformed by `transform` intersects with `this` Rectangle object.
15468
- * Returns true only if the area of the intersection is >0, this means that Rectangles
15469
- * sharing a side are not overlapping. Another side effect is that an arealess rectangle
15470
- * (width or height equal to zero) can't intersect any other rectangle.
15471
- * @param {Rectangle} other - The Rectangle to intersect with `this`.
15472
- * @param {Matrix} transform - The transformation matrix of `other`.
15473
- * @returns {boolean} A value of `true` if the transformed `other` Rectangle intersects with `this`; otherwise `false`.
15474
- */ // intersects (other: Rectangle, transform?: Matrix4): boolean {
15475
- // if (!transform) {
15476
- // const x0 = this.x < other.x ? other.x : this.x;
15477
- // const x1 = this.right > other.right ? other.right : this.right;
15478
- // if (x1 <= x0) {
15479
- // return false;
15480
- // }
15481
- // const y0 = this.y < other.y ? other.y : this.y;
15482
- // const y1 = this.bottom > other.bottom ? other.bottom : this.bottom;
15483
- // return y1 > y0;
15484
- // }
15485
- // const x0 = this.left;
15486
- // const x1 = this.right;
15487
- // const y0 = this.top;
15488
- // const y1 = this.bottom;
15489
- // if (x1 <= x0 || y1 <= y0) {
15490
- // return false;
15491
- // }
15492
- // const lt = tempPoints[0].set(other.left, other.top);
15493
- // const lb = tempPoints[1].set(other.left, other.bottom);
15494
- // const rt = tempPoints[2].set(other.right, other.top);
15495
- // const rb = tempPoints[3].set(other.right, other.bottom);
15496
- // if (rt.x <= lt.x || lb.y <= lt.y) {
15497
- // return false;
15498
- // }
15499
- // const s = Math.sign((transform.a * transform.d) - (transform.b * transform.c));
15500
- // if (s === 0) {
15501
- // return false;
15502
- // }
15503
- // transform.apply(lt, lt);
15504
- // transform.apply(lb, lb);
15505
- // transform.apply(rt, rt);
15506
- // transform.apply(rb, rb);
15507
- // if (Math.max(lt.x, lb.x, rt.x, rb.x) <= x0
15508
- // || Math.min(lt.x, lb.x, rt.x, rb.x) >= x1
15509
- // || Math.max(lt.y, lb.y, rt.y, rb.y) <= y0
15510
- // || Math.min(lt.y, lb.y, rt.y, rb.y) >= y1) {
15511
- // return false;
15512
- // }
15513
- // const nx = s * (lb.y - lt.y);
15514
- // const ny = s * (lt.x - lb.x);
15515
- // const n00 = (nx * x0) + (ny * y0);
15516
- // const n10 = (nx * x1) + (ny * y0);
15517
- // const n01 = (nx * x0) + (ny * y1);
15518
- // const n11 = (nx * x1) + (ny * y1);
15519
- // if (Math.max(n00, n10, n01, n11) <= (nx * lt.x) + (ny * lt.y)
15520
- // || Math.min(n00, n10, n01, n11) >= (nx * rb.x) + (ny * rb.y)) {
15521
- // return false;
15522
- // }
15523
- // const mx = s * (lt.y - rt.y);
15524
- // const my = s * (rt.x - lt.x);
15525
- // const m00 = (mx * x0) + (my * y0);
15526
- // const m10 = (mx * x1) + (my * y0);
15527
- // const m01 = (mx * x0) + (my * y1);
15528
- // const m11 = (mx * x1) + (my * y1);
15529
- // if (Math.max(m00, m10, m01, m11) <= (mx * lt.x) + (my * lt.y)
15530
- // || Math.min(m00, m10, m01, m11) >= (mx * rb.x) + (my * rb.y)) {
15531
- // return false;
15532
- // }
15533
- // return true;
15534
- // }
15535
- /**
15536
- * Pads the rectangle making it grow in all directions.
15537
- * If paddingY is omitted, both paddingX and paddingY will be set to paddingX.
15538
- * @param paddingX - The horizontal padding amount.
15539
- * @param paddingY - The vertical padding amount.
15540
- * @returns Returns itself.
15541
- */ _proto.pad = function pad(paddingX, paddingY) {
15542
- if (paddingX === void 0) paddingX = 0;
15543
- if (paddingY === void 0) paddingY = paddingX;
15544
- this.x -= paddingX;
15545
- this.y -= paddingY;
15546
- this.width += paddingX * 2;
15547
- this.height += paddingY * 2;
15548
- return this;
15549
- };
15550
- /**
15551
- * Fits this rectangle around the passed one.
15552
- * @param rectangle - The rectangle to fit.
15553
- * @returns Returns itself.
15554
- */ _proto.fit = function fit(rectangle) {
15555
- var x1 = Math.max(this.x, rectangle.x);
15556
- var x2 = Math.min(this.x + this.width, rectangle.x + rectangle.width);
15557
- var y1 = Math.max(this.y, rectangle.y);
15558
- var y2 = Math.min(this.y + this.height, rectangle.y + rectangle.height);
15559
- this.x = x1;
15560
- this.width = Math.max(x2 - x1, 0);
15561
- this.y = y1;
15562
- this.height = Math.max(y2 - y1, 0);
15563
- return this;
15564
- };
15565
- /**
15566
- * Enlarges rectangle that way its corners lie on grid
15567
- * @param resolution - resolution
15568
- * @param eps - precision
15569
- * @returns Returns itself.
15570
- */ _proto.ceil = function ceil(resolution, eps) {
15571
- if (resolution === void 0) resolution = 1;
15572
- if (eps === void 0) eps = 0.001;
15573
- var x2 = Math.ceil((this.x + this.width - eps) * resolution) / resolution;
15574
- var y2 = Math.ceil((this.y + this.height - eps) * resolution) / resolution;
15575
- this.x = Math.floor((this.x + eps) * resolution) / resolution;
15576
- this.y = Math.floor((this.y + eps) * resolution) / resolution;
15577
- this.width = x2 - this.x;
15578
- this.height = y2 - this.y;
15579
- return this;
15580
- };
15581
- /**
15582
- * Enlarges this rectangle to include the passed rectangle.
15583
- * @param rectangle - The rectangle to include.
15584
- * @returns Returns itself.
15585
- */ _proto.enlarge = function enlarge(rectangle) {
15586
- var x1 = Math.min(this.x, rectangle.x);
15587
- var x2 = Math.max(this.x + this.width, rectangle.x + rectangle.width);
15588
- var y1 = Math.min(this.y, rectangle.y);
15589
- var y2 = Math.max(this.y + this.height, rectangle.y + rectangle.height);
15590
- this.x = x1;
15591
- this.width = x2 - x1;
15592
- this.y = y1;
15593
- this.height = y2 - y1;
15594
- return this;
15595
- };
15596
- /**
15597
- * Returns the framing rectangle of the rectangle as a Rectangle object
15598
- * @param out - optional rectangle to store the result
15599
- * @returns The framing rectangle
15600
- */ _proto.getBounds = function getBounds(out) {
15601
- out = out || new Rectangle();
15602
- out.copyFrom(this);
15603
- return out;
15604
- };
15605
- _proto.getX = function getX() {
15606
- return this.x;
15607
- };
15608
- _proto.getY = function getY() {
15609
- return this.y;
15610
- };
15611
- _proto.build = function build(points) {
15612
- var x = this.x;
15613
- var y = this.y;
15614
- var width = this.width;
15615
- var height = this.height;
15616
- if (!(width >= 0 && height >= 0)) {
15617
- return points;
15522
+ var j1 = 0;
15523
+ var j2 = n * 4 + (dx ? 2 : 0) + 2;
15524
+ var j3 = j2;
15525
+ var j4 = m;
15526
+ var x0 = dx + rx;
15527
+ var y0 = dy;
15528
+ var x1 = x + x0;
15529
+ var x2 = x - x0;
15530
+ var y1 = y + y0;
15531
+ points[j1++] = x1;
15532
+ points[j1++] = y1;
15533
+ points[--j2] = y1;
15534
+ points[--j2] = x2;
15535
+ if (dy) {
15536
+ var y2 = y - y0;
15537
+ points[j3++] = x2;
15538
+ points[j3++] = y2;
15539
+ points[--j4] = y2;
15540
+ points[--j4] = x1;
15541
+ }
15542
+ for(var i = 1; i < n; i++){
15543
+ var a = Math.PI / 2 * (i / n);
15544
+ var x01 = dx + Math.cos(a) * rx;
15545
+ var y01 = dy + Math.sin(a) * ry;
15546
+ var x11 = x + x01;
15547
+ var x21 = x - x01;
15548
+ var y11 = y + y01;
15549
+ var y21 = y - y01;
15550
+ points[j1++] = x11;
15551
+ points[j1++] = y11;
15552
+ points[--j2] = y11;
15553
+ points[--j2] = x21;
15554
+ points[j3++] = x21;
15555
+ points[j3++] = y21;
15556
+ points[--j4] = y21;
15557
+ points[--j4] = x11;
15558
+ }
15559
+ x0 = dx;
15560
+ y0 = dy + ry;
15561
+ x1 = x + x0;
15562
+ x2 = x - x0;
15563
+ y1 = y + y0;
15564
+ var y22 = y - y0;
15565
+ points[j1++] = x1;
15566
+ points[j1++] = y1;
15567
+ points[--j4] = y22;
15568
+ points[--j4] = x1;
15569
+ if (dx) {
15570
+ points[j1++] = x2;
15571
+ points[j1++] = y1;
15572
+ points[--j4] = y22;
15573
+ points[--j4] = x2;
15618
15574
  }
15619
- points[0] = x;
15620
- points[1] = y;
15621
- points[2] = x + width;
15622
- points[3] = y;
15623
- points[4] = x + width;
15624
- points[5] = y + height;
15625
- points[6] = x;
15626
- points[7] = y + height;
15627
- return points;
15628
15575
  };
15629
15576
  _proto.triangulate = function triangulate(points, vertices, verticesOffset, indices, indicesOffset) {
15630
- var count = 0;
15631
- var verticesStride = 2;
15632
- verticesOffset *= verticesStride;
15633
- vertices[verticesOffset + count] = points[0];
15634
- vertices[verticesOffset + count + 1] = points[1];
15635
- count += verticesStride;
15636
- vertices[verticesOffset + count] = points[2];
15637
- vertices[verticesOffset + count + 1] = points[3];
15638
- count += verticesStride;
15639
- vertices[verticesOffset + count] = points[6];
15640
- vertices[verticesOffset + count + 1] = points[7];
15641
- count += verticesStride;
15642
- vertices[verticesOffset + count] = points[4];
15643
- vertices[verticesOffset + count + 1] = points[5];
15644
- count += verticesStride;
15645
- var verticesIndex = verticesOffset / verticesStride;
15646
- // triangle 1
15647
- indices[indicesOffset++] = verticesIndex;
15648
- indices[indicesOffset++] = verticesIndex + 1;
15649
- indices[indicesOffset++] = verticesIndex + 2;
15650
- // triangle 2
15651
- indices[indicesOffset++] = verticesIndex + 1;
15652
- indices[indicesOffset++] = verticesIndex + 3;
15653
- indices[indicesOffset++] = verticesIndex + 2;
15654
- };
15655
- _create_class(Rectangle, [
15656
- {
15657
- key: "left",
15658
- get: /** Returns the left edge of the rectangle. */ function get() {
15659
- return this.x;
15660
- }
15661
- },
15662
- {
15663
- key: "right",
15664
- get: /** Returns the right edge of the rectangle. */ function get() {
15665
- return this.x + this.width;
15666
- }
15667
- },
15668
- {
15669
- key: "top",
15670
- get: /** Returns the top edge of the rectangle. */ function get() {
15671
- return this.y;
15672
- }
15673
- },
15674
- {
15675
- key: "bottom",
15676
- get: /** Returns the bottom edge of the rectangle. */ function get() {
15677
- return this.y + this.height;
15678
- }
15577
+ if (points.length === 0) {
15578
+ return;
15679
15579
  }
15680
- ], [
15681
- {
15682
- key: "EMPTY",
15683
- get: /** A constant empty rectangle. This is a new object every time the property is accessed */ function get() {
15684
- return new Rectangle(0, 0, 0, 0);
15580
+ // Compute center (average of all points)
15581
+ var centerX = 0;
15582
+ var centerY = 0;
15583
+ for(var i = 0; i < points.length; i += 2){
15584
+ centerX += points[i];
15585
+ centerY += points[i + 1];
15586
+ }
15587
+ centerX /= points.length / 2;
15588
+ centerY /= points.length / 2;
15589
+ // Set center vertex
15590
+ var count = verticesOffset;
15591
+ vertices[count * 2] = centerX;
15592
+ vertices[count * 2 + 1] = centerY;
15593
+ var centerIndex = count++;
15594
+ // Set edge vertices and indices
15595
+ for(var i1 = 0; i1 < points.length; i1 += 2){
15596
+ vertices[count * 2] = points[i1];
15597
+ vertices[count * 2 + 1] = points[i1 + 1];
15598
+ if (i1 > 0) {
15599
+ indices[indicesOffset++] = count;
15600
+ indices[indicesOffset++] = centerIndex;
15601
+ indices[indicesOffset++] = count - 1;
15685
15602
  }
15603
+ count++;
15686
15604
  }
15687
- ]);
15605
+ // Connect last point to the first edge point
15606
+ indices[indicesOffset++] = centerIndex + 1;
15607
+ indices[indicesOffset++] = centerIndex;
15608
+ indices[indicesOffset++] = count - 1;
15609
+ };
15688
15610
  return Rectangle;
15689
15611
  }(ShapePrimitive);
15690
15612
 
@@ -15782,8 +15704,8 @@ var ShapePath = /*#__PURE__*/ function() {
15782
15704
  * @param h - The height of the rectangle.
15783
15705
  * @param transform - An optional `Matrix` object to apply a transformation to the rectangle.
15784
15706
  * @returns The instance of the current object for chaining.
15785
- */ _proto.rect = function rect(x, y, w, h, transform) {
15786
- this.drawShape(new Rectangle$1(x, y, w, h), transform);
15707
+ */ _proto.rect = function rect(x, y, w, h, roundness, transform) {
15708
+ this.drawShape(new Rectangle$1(x, y, w, h, roundness), transform);
15787
15709
  return this;
15788
15710
  };
15789
15711
  /**
@@ -15929,7 +15851,7 @@ var GraphicsPath = /*#__PURE__*/ function() {
15929
15851
  * @param h - The height of the rectangle.
15930
15852
  * @param transform - An optional `Matrix` object to apply a transformation to the rectangle.
15931
15853
  * @returns The instance of the current object for chaining.
15932
- */ _proto.rect = function rect(x, y, w, h, transform) {
15854
+ */ _proto.rect = function rect(x, y, w, h, roundness, transform) {
15933
15855
  this.instructions.push({
15934
15856
  action: "rect",
15935
15857
  data: [
@@ -15937,6 +15859,7 @@ var GraphicsPath = /*#__PURE__*/ function() {
15937
15859
  y,
15938
15860
  w,
15939
15861
  h,
15862
+ roundness,
15940
15863
  transform
15941
15864
  ]
15942
15865
  });
@@ -16246,9 +16169,9 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16246
16169
  var innerWeight = (1 - ratio) * 2;
16247
16170
  var outerWeight = ratio * 2;
16248
16171
  if (!closedShape) {
16249
- if (style.cap === "round") {
16172
+ if (style.cap === LineCap.Round) {
16250
16173
  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;
16251
- } else if (style.cap === "square") {
16174
+ } else if (style.cap === LineCap.Square) {
16252
16175
  indexCount += square(x0, y0, perpX, perpY, innerWeight, outerWeight, true, verts);
16253
16176
  }
16254
16177
  }
@@ -16287,7 +16210,7 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16287
16210
  verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
16288
16211
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
16289
16212
  /* 180 degree corner? */ if (dot >= 0) {
16290
- if (style.join === "round") {
16213
+ if (style.join === LineJoin.Round) {
16291
16214
  indexCount += round(x1, y1, x1 - perpX * innerWeight, y1 - perpY * innerWeight, x1 - perp1x * innerWeight, y1 - perp1y * innerWeight, verts, false) + 4;
16292
16215
  } else {
16293
16216
  indexCount += 2;
@@ -16311,7 +16234,7 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16311
16234
  var smallerInsideDiagonalSq = smallerInsideSegmentSq + insideWeight * insideWeight * widthSquared;
16312
16235
  var insideMiterOk = pDist <= smallerInsideDiagonalSq;
16313
16236
  if (insideMiterOk) {
16314
- if (style.join === "bevel" || pDist / widthSquared > miterLimitSquared) {
16237
+ if (style.join === LineJoin.Bevel || pDist / widthSquared > miterLimitSquared) {
16315
16238
  if (clockwise) /* rotating at inner angle */ {
16316
16239
  verts.push(imx, imy); // inner miter point
16317
16240
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight); // first segment's outer vertex
@@ -16324,7 +16247,7 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16324
16247
  verts.push(omx, omy); // outer miter point
16325
16248
  }
16326
16249
  indexCount += 2;
16327
- } else if (style.join === "round") {
16250
+ } else if (style.join === LineJoin.Round) {
16328
16251
  if (clockwise) /* arc is outside */ {
16329
16252
  verts.push(imx, imy);
16330
16253
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
@@ -16345,13 +16268,13 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16345
16268
  } else {
16346
16269
  verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight); // first segment's inner vertex
16347
16270
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight); // first segment's outer vertex
16348
- if (style.join === "round") {
16271
+ if (style.join === LineJoin.Round) {
16349
16272
  if (clockwise) /* arc is outside */ {
16350
16273
  indexCount += round(x1, y1, x1 + perpX * outerWeight, y1 + perpY * outerWeight, x1 + perp1x * outerWeight, y1 + perp1y * outerWeight, verts, true) + 2;
16351
16274
  } else /* arc is inside */ {
16352
16275
  indexCount += round(x1, y1, x1 - perpX * innerWeight, y1 - perpY * innerWeight, x1 - perp1x * innerWeight, y1 - perp1y * innerWeight, verts, false) + 2;
16353
16276
  }
16354
- } else if (style.join === "miter" && pDist / widthSquared <= miterLimitSquared) {
16277
+ } else if (style.join === LineJoin.Miter && pDist / widthSquared <= miterLimitSquared) {
16355
16278
  if (clockwise) {
16356
16279
  verts.push(omx, omy); // inner miter point
16357
16280
  verts.push(omx, omy); // inner miter point
@@ -16380,9 +16303,9 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16380
16303
  verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
16381
16304
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
16382
16305
  if (!closedShape) {
16383
- if (style.cap === "round") {
16306
+ if (style.cap === LineCap.Round) {
16384
16307
  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;
16385
- } else if (style.cap === "square") {
16308
+ } else if (style.cap === LineCap.Square) {
16386
16309
  indexCount += square(x1, y1, perpX, perpY, innerWeight, outerWeight, false, verts);
16387
16310
  }
16388
16311
  }
@@ -16409,9 +16332,10 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16409
16332
  var _this;
16410
16333
  _this = MeshComponent.call(this, engine) || this;
16411
16334
  _this.isStroke = false;
16335
+ _this.isFill = false;
16336
+ _this.shapeDirty = true;
16412
16337
  _this.graphicsPath = new GraphicsPath();
16413
16338
  _this.curveValues = [];
16414
- _this.shapeDirty = true;
16415
16339
  _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";
16416
16340
  _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";
16417
16341
  if (!_this.geometry) {
@@ -16444,6 +16368,15 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16444
16368
  mode: glContext.TRIANGLES,
16445
16369
  drawCount: 4
16446
16370
  });
16371
+ _this.geometry.subMeshes.push({
16372
+ offset: 0,
16373
+ indexCount: 0,
16374
+ vertexCount: 0
16375
+ }, {
16376
+ offset: 0,
16377
+ indexCount: 0,
16378
+ vertexCount: 0
16379
+ });
16447
16380
  }
16448
16381
  if (!_this.material) {
16449
16382
  var materialProps = {
@@ -16453,18 +16386,29 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16453
16386
  glslVersion: exports.GLSLVersion.GLSL1
16454
16387
  }
16455
16388
  };
16456
- _this.material = Material.create(engine, materialProps);
16457
- _this.material.setColor("_Color", new Color(1, 1, 1, 1));
16458
- _this.material.depthMask = false;
16459
- _this.material.depthTest = true;
16460
- _this.material.blending = true;
16389
+ var fillMaterial = Material.create(engine, materialProps);
16390
+ fillMaterial.setColor("_Color", new Color(1, 1, 1, 1));
16391
+ fillMaterial.depthMask = false;
16392
+ fillMaterial.depthTest = true;
16393
+ fillMaterial.blending = true;
16394
+ _this.material = fillMaterial;
16395
+ var strokeMaterial = Material.create(engine, materialProps);
16396
+ strokeMaterial.setColor("_Color", new Color(0.25, 0.25, 0.25, 1));
16397
+ strokeMaterial.depthMask = false;
16398
+ strokeMaterial.depthTest = true;
16399
+ strokeMaterial.blending = true;
16400
+ _this.materials[1] = strokeMaterial;
16461
16401
  }
16462
16402
  _this.strokeAttributes = {
16463
16403
  width: 1,
16464
16404
  alignment: 0.5,
16465
- cap: "butt",
16466
- join: "miter",
16467
- miterLimit: 10
16405
+ cap: LineCap.Butt,
16406
+ join: LineJoin.Miter,
16407
+ miterLimit: 10,
16408
+ color: new Color(1, 1, 1, 1)
16409
+ };
16410
+ _this.fillAttribute = {
16411
+ color: new Color(1, 1, 1, 1)
16468
16412
  };
16469
16413
  _this.shapeAttribute = {
16470
16414
  type: ShapePrimitiveType.Custom,
@@ -16480,6 +16424,8 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16480
16424
  this.item.getHitTestParams = this.getHitTestParams;
16481
16425
  };
16482
16426
  _proto.onUpdate = function onUpdate(dt) {
16427
+ this.material.color = this.fillAttribute.color;
16428
+ this.materials[1].color = this.strokeAttributes.color;
16483
16429
  if (this.shapeDirty) {
16484
16430
  this.buildPath(this.shapeAttribute);
16485
16431
  this.buildGeometryFromPath(this.graphicsPath.shapePath);
@@ -16490,22 +16436,34 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16490
16436
  var shapePrimitives = shapePath.shapePrimitives;
16491
16437
  var vertices = [];
16492
16438
  var indices = [];
16493
- // triangulate shapePrimitive
16494
- for(var _iterator = _create_for_of_iterator_helper_loose(shapePrimitives), _step; !(_step = _iterator()).done;){
16495
- var shapePrimitive = _step.value;
16496
- var shape = shapePrimitive.shape;
16497
- var points = [];
16498
- var indexOffset = indices.length;
16499
- var vertOffset = vertices.length / 2;
16500
- shape.build(points);
16501
- if (!this.isStroke) {
16439
+ // Triangulate shapePrimitive
16440
+ //---------------------------------------------------
16441
+ if (this.isFill) {
16442
+ for(var _iterator = _create_for_of_iterator_helper_loose(shapePrimitives), _step; !(_step = _iterator()).done;){
16443
+ var shapePrimitive = _step.value;
16444
+ var shape = shapePrimitive.shape;
16445
+ var points = [];
16446
+ var indexOffset = indices.length;
16447
+ var vertOffset = vertices.length / 2;
16448
+ shape.build(points);
16502
16449
  shape.triangulate(points, vertices, vertOffset, indices, indexOffset);
16503
- } else {
16450
+ }
16451
+ }
16452
+ var fillIndexCount = indices.length;
16453
+ if (this.isStroke) {
16454
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(shapePrimitives), _step1; !(_step1 = _iterator1()).done;){
16455
+ var shapePrimitive1 = _step1.value;
16456
+ var shape1 = shapePrimitive1.shape;
16457
+ var points1 = [];
16458
+ indices.length;
16459
+ var vertOffset1 = vertices.length / 2;
16504
16460
  var close = true;
16505
16461
  var lineStyle = this.strokeAttributes;
16506
- buildLine(points, lineStyle, false, close, vertices, 2, vertOffset, indices);
16462
+ shape1.build(points1);
16463
+ buildLine(points1, lineStyle, false, close, vertices, 2, vertOffset1, indices);
16507
16464
  }
16508
16465
  }
16466
+ var strokeIndexCount = indices.length - fillIndexCount;
16509
16467
  var vertexCount = vertices.length / 2;
16510
16468
  // get the current attribute and index arrays from the geometry, avoiding re-creation
16511
16469
  var positionArray = this.geometry.getAttributeData("aPos");
@@ -16538,6 +16496,12 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16538
16496
  this.geometry.setAttributeData("aUV", uvArray);
16539
16497
  this.geometry.setIndexData(indexArray);
16540
16498
  this.geometry.setDrawCount(indices.length);
16499
+ var u16Size = 2;
16500
+ var fillSubMesh = this.geometry.subMeshes[0];
16501
+ var strokeSubMesh = this.geometry.subMeshes[1];
16502
+ fillSubMesh.indexCount = fillIndexCount;
16503
+ strokeSubMesh.offset = fillIndexCount * u16Size;
16504
+ strokeSubMesh.indexCount = strokeIndexCount;
16541
16505
  };
16542
16506
  _proto.buildPath = function buildPath(shapeAttribute) {
16543
16507
  this.graphicsPath.clear();
@@ -16551,7 +16515,6 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16551
16515
  for(var _iterator = _create_for_of_iterator_helper_loose(customShapeAtribute.shapes), _step; !(_step = _iterator()).done;){
16552
16516
  var shape = _step.value;
16553
16517
  this.curveValues = [];
16554
- this.setFillColor(shape.fill);
16555
16518
  var indices = shape.indexes;
16556
16519
  for(var i = 1; i < indices.length; i++){
16557
16520
  var pointIndex = indices[i];
@@ -16583,38 +16546,28 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16583
16546
  {
16584
16547
  var ellipseData = shapeAttribute;
16585
16548
  this.graphicsPath.ellipse(0, 0, ellipseData.xRadius, ellipseData.yRadius);
16586
- this.setFillColor(ellipseData.fill);
16587
16549
  break;
16588
16550
  }
16589
16551
  case ShapePrimitiveType.Rectangle:
16590
16552
  {
16591
16553
  var rectangleData = shapeAttribute;
16592
- this.graphicsPath.rect(-rectangleData.width / 2, -rectangleData.height / 2, rectangleData.width, rectangleData.height);
16593
- this.setFillColor(rectangleData.fill);
16554
+ this.graphicsPath.rect(-rectangleData.width / 2, -rectangleData.height / 2, rectangleData.width, rectangleData.height, rectangleData.roundness);
16594
16555
  break;
16595
16556
  }
16596
16557
  case ShapePrimitiveType.Star:
16597
16558
  {
16598
16559
  var starData = shapeAttribute;
16599
16560
  this.graphicsPath.polyStar(starData.pointCount, starData.outerRadius, starData.innerRadius, starData.outerRoundness, starData.innerRoundness, StarType.Star);
16600
- this.setFillColor(starData.fill);
16601
16561
  break;
16602
16562
  }
16603
16563
  case ShapePrimitiveType.Polygon:
16604
16564
  {
16605
16565
  var polygonData = shapeAttribute;
16606
16566
  this.graphicsPath.polyStar(polygonData.pointCount, polygonData.radius, polygonData.radius, polygonData.roundness, polygonData.roundness, StarType.Polygon);
16607
- this.setFillColor(polygonData.fill);
16608
16567
  break;
16609
16568
  }
16610
16569
  }
16611
16570
  };
16612
- _proto.setFillColor = function setFillColor(fill) {
16613
- if (fill) {
16614
- var color = fill.color;
16615
- this.material.setColor("_Color", new Color(color.r, color.g, color.b, color.a));
16616
- }
16617
- };
16618
16571
  _proto.fromData = function fromData(data) {
16619
16572
  MeshComponent.prototype.fromData.call(this, data);
16620
16573
  this.shapeDirty = true;
@@ -16622,19 +16575,27 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16622
16575
  if (strokeParam) {
16623
16576
  this.isStroke = true;
16624
16577
  this.strokeAttributes.width = strokeParam.width;
16578
+ this.strokeAttributes.color.copyFrom(strokeParam.color);
16579
+ this.strokeAttributes.cap = strokeParam.cap;
16580
+ this.strokeAttributes.join = strokeParam.join;
16581
+ }
16582
+ var fillParam = data.fill;
16583
+ if (fillParam) {
16584
+ this.isFill = true;
16585
+ this.fillAttribute.color.copyFrom(fillParam.color);
16625
16586
  }
16626
16587
  switch(data.type){
16627
16588
  case ShapePrimitiveType.Custom:
16628
16589
  {
16629
- this.shapeAttribute = {
16590
+ var customShapeData = data;
16591
+ var customShapeAttribute = {
16630
16592
  type: ShapePrimitiveType.Custom,
16631
16593
  points: [],
16632
16594
  easingIns: [],
16633
16595
  easingOuts: [],
16634
- shapes: []
16596
+ shapes: [],
16597
+ fill: customShapeData.fill
16635
16598
  };
16636
- var customShapeData = data;
16637
- var customShapeAttribute = this.shapeAttribute;
16638
16599
  for(var _iterator = _create_for_of_iterator_helper_loose(customShapeData.points), _step; !(_step = _iterator()).done;){
16639
16600
  var point = _step.value;
16640
16601
  customShapeAttribute.points.push(new Vector2(point.x, point.y));
@@ -16648,6 +16609,7 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16648
16609
  customShapeAttribute.easingOuts.push(new Vector2(easingOut.x, easingOut.y));
16649
16610
  }
16650
16611
  customShapeAttribute.shapes = customShapeData.shapes;
16612
+ this.shapeAttribute = customShapeAttribute;
16651
16613
  break;
16652
16614
  }
16653
16615
  case ShapePrimitiveType.Ellipse:
@@ -17538,10 +17500,8 @@ function shouldIgnoreBouncing(arg, mul) {
17538
17500
  };
17539
17501
  };
17540
17502
  _proto.setGeometry = function setGeometry(geometry, worldMatrix) {
17541
- if (this.geometry !== geometry) {
17542
- this.triangles = this.geometryToTriangles(geometry);
17543
- this.geometry = geometry;
17544
- }
17503
+ this.triangles = this.geometryToTriangles(geometry);
17504
+ this.geometry = geometry;
17545
17505
  var area = [];
17546
17506
  for(var _iterator = _create_for_of_iterator_helper_loose(this.triangles), _step; !(_step = _iterator()).done;){
17547
17507
  var triangle = _step.value;
@@ -17562,10 +17522,11 @@ function shouldIgnoreBouncing(arg, mul) {
17562
17522
  _proto.geometryToTriangles = function geometryToTriangles(geometry) {
17563
17523
  var _geometry_getIndexData;
17564
17524
  var indices = (_geometry_getIndexData = geometry.getIndexData()) != null ? _geometry_getIndexData : [];
17525
+ var drawCount = geometry.getDrawCount();
17565
17526
  var _geometry_getAttributeData;
17566
17527
  var vertices = (_geometry_getAttributeData = geometry.getAttributeData("aPos")) != null ? _geometry_getAttributeData : [];
17567
17528
  var res = [];
17568
- for(var i = 0; i < indices.length; i += 3){
17529
+ for(var i = 0; i < drawCount; i += 3){
17569
17530
  var index0 = indices[i] * 3;
17570
17531
  var index1 = indices[i + 1] * 3;
17571
17532
  var index2 = indices[i + 2] * 3;
@@ -25548,6 +25509,9 @@ exports.TextComponent = /*#__PURE__*/ function(BaseRenderComponent) {
25548
25509
  /**
25549
25510
  * 文本行数
25550
25511
  */ _this.lineCount = 0;
25512
+ /**
25513
+ * 每一行文本的最大宽度
25514
+ */ _this.maxLineWidth = 0;
25551
25515
  _this.SCALE_FACTOR = 0.1;
25552
25516
  _this.ALPHA_FIX_VALUE = 1 / 255;
25553
25517
  _this.name = "MText" + seed$2++;
@@ -25631,12 +25595,9 @@ var TextComponentBase = /*#__PURE__*/ function() {
25631
25595
  this.textStyle = new TextStyle(options);
25632
25596
  this.textLayout = new TextLayout(options);
25633
25597
  this.text = options.text.toString();
25634
- this.lineCount = this.getLineCount(options.text, true);
25635
25598
  };
25636
- _proto.getLineCount = function getLineCount(text, init) {
25637
- var context = this.context;
25638
- var letterSpace = this.textLayout.letterSpace;
25639
- var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
25599
+ _proto.getLineCount = function getLineCount(text, context) {
25600
+ var _this_textLayout = this.textLayout, letterSpace = _this_textLayout.letterSpace, overflow = _this_textLayout.overflow;
25640
25601
  var width = this.textLayout.width + this.textStyle.fontOffset;
25641
25602
  var lineCount = 1;
25642
25603
  var x = 0;
@@ -25644,15 +25605,27 @@ var TextComponentBase = /*#__PURE__*/ function() {
25644
25605
  var _context_measureText;
25645
25606
  var str = text[i];
25646
25607
  var _context_measureText_width;
25647
- 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;
25608
+ 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;
25648
25609
  // 和浏览器行为保持一致
25649
25610
  x += letterSpace;
25650
- if (x + textMetrics > width && i > 0 || str === "\n") {
25651
- lineCount++;
25652
- x = 0;
25653
- }
25654
- if (str !== "\n") {
25655
- x += textMetrics;
25611
+ // 处理文本结束行为
25612
+ if (overflow === TextOverflow.display) {
25613
+ if (str === "\n") {
25614
+ lineCount++;
25615
+ x = 0;
25616
+ } else {
25617
+ x += textMetrics;
25618
+ this.maxLineWidth = Math.max(this.maxLineWidth, x);
25619
+ }
25620
+ } else {
25621
+ if (x + textMetrics > width && i > 0 || str === "\n") {
25622
+ lineCount++;
25623
+ this.maxLineWidth = Math.max(this.maxLineWidth, x);
25624
+ x = 0;
25625
+ }
25626
+ if (str !== "\n") {
25627
+ x += textMetrics;
25628
+ }
25656
25629
  }
25657
25630
  }
25658
25631
  return lineCount;
@@ -25702,7 +25675,6 @@ var TextComponentBase = /*#__PURE__*/ function() {
25702
25675
  return;
25703
25676
  }
25704
25677
  this.text = value.toString();
25705
- this.lineCount = this.getLineCount(value, false);
25706
25678
  this.isDirty = true;
25707
25679
  };
25708
25680
  /**
@@ -25784,6 +25756,18 @@ var TextComponentBase = /*#__PURE__*/ function() {
25784
25756
  this.isDirty = true;
25785
25757
  };
25786
25758
  /**
25759
+ * 设置文本溢出模式
25760
+ *
25761
+ * - clip: 当文本内容超出边界框时,多余的会被截断。
25762
+ * - display: 该模式下会显示所有文本,会自动调整文本字号以保证显示完整。
25763
+ * > 当存在多行时,部分行内文本可能存在文本字号变小的情况,其他行为正常情况
25764
+ *
25765
+ * @param overflow - 文本溢出模式
25766
+ */ _proto.setOverflow = function setOverflow(overflow) {
25767
+ this.textLayout.overflow = overflow;
25768
+ this.isDirty = true;
25769
+ };
25770
+ /**
25787
25771
  * 设置阴影颜色
25788
25772
  * @param value - 阴影颜色
25789
25773
  * @returns
@@ -25851,28 +25835,35 @@ var TextComponentBase = /*#__PURE__*/ function() {
25851
25835
  var layout = this.textLayout;
25852
25836
  var fontScale = style.fontScale;
25853
25837
  var width = (layout.width + style.fontOffset) * fontScale;
25854
- var finalHeight = layout.lineHeight * this.lineCount;
25855
25838
  var fontSize = style.fontSize * fontScale;
25856
25839
  var lineHeight = layout.lineHeight * fontScale;
25840
+ style.fontDesc = this.getFontDesc(fontSize);
25857
25841
  this.char = (this.text || "").split("");
25858
25842
  this.canvas.width = width;
25843
+ var height = this.canvas.height;
25844
+ context.font = style.fontDesc;
25845
+ this.lineCount = this.getLineCount(this.text, context);
25846
+ var finalHeight = layout.lineHeight * this.lineCount;
25859
25847
  if (layout.autoWidth) {
25860
25848
  this.canvas.height = finalHeight * fontScale;
25861
25849
  this.item.transform.size.set(1, finalHeight / layout.height);
25862
25850
  } else {
25863
25851
  this.canvas.height = layout.height * fontScale;
25864
25852
  }
25865
- var height = this.canvas.height;
25866
- context.clearRect(0, 0, width, height);
25853
+ // canvas size 变化后重新刷新 context
25854
+ if (this.maxLineWidth > width && layout.overflow === TextOverflow.display) {
25855
+ context.font = this.getFontDesc(fontSize * width / this.maxLineWidth);
25856
+ } else {
25857
+ context.font = style.fontDesc;
25858
+ }
25867
25859
  // fix bug 1/255
25868
25860
  context.fillStyle = "rgba(255, 255, 255, 0.0039)";
25861
+ context.clearRect(0, 0, width, height);
25869
25862
  if (!flipY) {
25870
25863
  context.translate(0, height);
25871
25864
  context.scale(1, -1);
25872
25865
  }
25873
25866
  context.fillRect(0, 0, width, height);
25874
- style.fontDesc = this.getFontDesc();
25875
- context.font = style.fontDesc;
25876
25867
  if (style.hasShadow) {
25877
25868
  this.setupShadow();
25878
25869
  }
@@ -25944,9 +25935,9 @@ var TextComponentBase = /*#__PURE__*/ function() {
25944
25935
  this.material.setTexture("_MainTex", texture);
25945
25936
  this.isDirty = false;
25946
25937
  };
25947
- _proto.getFontDesc = function getFontDesc() {
25948
- 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;
25949
- var fontDesc = "" + (fontSize * fontScale).toString() + "px ";
25938
+ _proto.getFontDesc = function getFontDesc(fontSize) {
25939
+ var _this_textStyle = this.textStyle, fontFamily = _this_textStyle.fontFamily, textWeight = _this_textStyle.textWeight, fontStyle = _this_textStyle.fontStyle;
25940
+ var fontDesc = "" + fontSize.toString() + "px ";
25950
25941
  if (!DEFAULT_FONTS.includes(fontFamily)) {
25951
25942
  fontDesc += '"' + fontFamily + '"';
25952
25943
  } else {
@@ -26716,12 +26707,29 @@ function getStandardInteractContent(ui) {
26716
26707
  * 3.1 版本数据适配
26717
26708
  * - 富文本插件名称的适配
26718
26709
  */ function version31Migration(json) {
26719
- var _json_plugins;
26710
+ var // 修正老版本数据中,富文本插件名称的问题
26711
+ _json_plugins;
26720
26712
  (_json_plugins = json.plugins) == null ? void 0 : _json_plugins.forEach(function(plugin, index) {
26721
26713
  if (plugin === "richtext") {
26722
26714
  json.plugins[index] = "rich-text";
26723
26715
  }
26724
26716
  });
26717
+ // Custom shape fill 属性位置迁移
26718
+ for(var _iterator = _create_for_of_iterator_helper_loose(json.components), _step; !(_step = _iterator()).done;){
26719
+ var component = _step.value;
26720
+ if (component.dataType === DataType.ShapeComponent) {
26721
+ var shapeComponent = component;
26722
+ if (shapeComponent.type === ShapePrimitiveType.Custom) {
26723
+ var _customShapeComponent_shapes;
26724
+ var customShapeComponent = shapeComponent;
26725
+ //@ts-expect-error
26726
+ if (((_customShapeComponent_shapes = customShapeComponent.shapes) == null ? void 0 : _customShapeComponent_shapes.length) > 0 && customShapeComponent.shapes[0].fill) {
26727
+ // @ts-expect-error
26728
+ customShapeComponent.fill = customShapeComponent.shapes[0].fill;
26729
+ }
26730
+ }
26731
+ }
26732
+ }
26725
26733
  return json;
26726
26734
  }
26727
26735
  /**
@@ -27551,8 +27559,6 @@ function getStandardJSON(json) {
27551
27559
  }
27552
27560
  // 修正老版本数据中,meshItem 以及 lightItem 结束行为错误问题
27553
27561
  version22Migration(json);
27554
- // 修正老版本数据中,富文本插件名称的问题
27555
- version31Migration(json);
27556
27562
  if (v0.test(json.version)) {
27557
27563
  var _exec;
27558
27564
  reverseParticle = ((_exec = /^(\d+)/.exec(json.version)) == null ? void 0 : _exec[0]) === "0";
@@ -27567,7 +27573,13 @@ function getStandardJSON(json) {
27567
27573
  json = version24Migration(json);
27568
27574
  }
27569
27575
  if (mainVersion < 3) {
27570
- return version30Migration(version21Migration(json));
27576
+ json = version30Migration(version21Migration(json));
27577
+ }
27578
+ // 3.x 版本格式转换
27579
+ if (mainVersion < 4) {
27580
+ if (minorVersion < 2) {
27581
+ json = version31Migration(json);
27582
+ }
27571
27583
  }
27572
27584
  return json;
27573
27585
  }
@@ -27623,13 +27635,11 @@ function getStandardJSONFromV0(json) {
27623
27635
  }
27624
27636
  function getStandardImage(image, index, imageTags) {
27625
27637
  var renderLevel = imageTags[index];
27626
- var oriY = image.oriY;
27627
27638
  if (typeof image === "string") {
27628
27639
  return {
27629
27640
  id: generateGUID(),
27630
27641
  renderLevel: renderLevel,
27631
- url: image,
27632
- oriY: oriY
27642
+ url: image
27633
27643
  };
27634
27644
  } else if (image.template) {
27635
27645
  return {
@@ -27637,14 +27647,12 @@ function getStandardImage(image, index, imageTags) {
27637
27647
  url: image.url,
27638
27648
  template: image.template,
27639
27649
  webp: image.webp,
27640
- renderLevel: renderLevel,
27641
- oriY: oriY
27650
+ renderLevel: renderLevel
27642
27651
  };
27643
27652
  } else if (image.compressed) {
27644
27653
  return {
27645
27654
  id: generateGUID(),
27646
27655
  url: image.url,
27647
- oriY: oriY,
27648
27656
  compressed: {
27649
27657
  astc: image.compressed.android,
27650
27658
  pvrtc: image.compressed.iOS
@@ -27657,8 +27665,7 @@ function getStandardImage(image, index, imageTags) {
27657
27665
  id: generateGUID(),
27658
27666
  url: image.url,
27659
27667
  webp: image.webp,
27660
- renderLevel: renderLevel,
27661
- oriY: oriY
27668
+ renderLevel: renderLevel
27662
27669
  };
27663
27670
  } else if (image && image.sourceType) {
27664
27671
  return image;
@@ -32100,7 +32107,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem, true);
32100
32107
  registerPlugin("particle", ParticleLoader, exports.VFXItem, true);
32101
32108
  registerPlugin("cal", CalculateLoader, exports.VFXItem, true);
32102
32109
  registerPlugin("interact", InteractLoader, exports.VFXItem, true);
32103
- var version$1 = "2.3.0-alpha.1";
32110
+ var version$1 = "2.3.0-alpha.2";
32104
32111
  logger.info("Core version: " + version$1 + ".");
32105
32112
 
32106
32113
  var _obj;
@@ -33733,7 +33740,7 @@ setMaxSpriteMeshItemCount(8);
33733
33740
  */ Mesh.create = function(engine, props) {
33734
33741
  return new ThreeMesh(engine, props);
33735
33742
  };
33736
- var version = "2.3.0-alpha.1";
33743
+ var version = "2.3.0-alpha.2";
33737
33744
  logger.info("THREEJS plugin version: " + version + ".");
33738
33745
 
33739
33746
  exports.AbstractPlugin = AbstractPlugin;