@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.mjs 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
  import * as THREE from 'three';
@@ -1037,7 +1037,8 @@ function _inherits(subClass, superClass) {
1037
1037
  JSONSceneVersion["2_4"] = "2.4";
1038
1038
  JSONSceneVersion["3_0"] = "3.0";
1039
1039
  JSONSceneVersion["3_1"] = "3.1";
1040
- JSONSceneVersion["LATEST"] = "3.1";
1040
+ JSONSceneVersion["3_2"] = "3.2";
1041
+ JSONSceneVersion["LATEST"] = "3.2";
1041
1042
  })(JSONSceneVersion || (JSONSceneVersion = {}));
1042
1043
 
1043
1044
  /*********************************************/ /* 元素属性参数类型 */ /*********************************************/ /**
@@ -1575,7 +1576,7 @@ var MaterialBlending;
1575
1576
  var TextOverflow;
1576
1577
  (function(TextOverflow) {
1577
1578
  /**
1578
- * display 模式下,会显示所有文本,存在文本超过边界框的情况。
1579
+ * display 模式下,会显示所有文本,文本大小会根据边界框调整。
1579
1580
  */ TextOverflow[TextOverflow["display"] = 0] = "display";
1580
1581
  /**
1581
1582
  * clip 模式下,当文本内容超出边界框时,多余的会被截断。
@@ -1668,12 +1669,18 @@ var BuiltinObjectGUID = {
1668
1669
  */ ShapePrimitiveType[ShapePrimitiveType["Star"] = 4] = "Star";
1669
1670
  })(ShapePrimitiveType || (ShapePrimitiveType = {}));
1670
1671
 
1671
- // 本期无该功能 待补充
1672
- var ShapeConnectType;
1673
- (function(ShapeConnectType) {})(ShapeConnectType || (ShapeConnectType = {}));
1674
- // @待补充
1675
- var ShapePointType;
1676
- (function(ShapePointType) {})(ShapePointType || (ShapePointType = {}));
1672
+ var LineCap;
1673
+ (function(LineCap) {
1674
+ /** 默认值。向线条的每个末端添加平直的边缘 */ LineCap[LineCap["Butt"] = 0] = "Butt";
1675
+ /** 向线条的每个末端添加圆形线帽 */ LineCap[LineCap["Round"] = 1] = "Round";
1676
+ /** 向线条的每个末端添加正方形线帽 */ LineCap[LineCap["Square"] = 2] = "Square";
1677
+ })(LineCap || (LineCap = {}));
1678
+ var LineJoin;
1679
+ (function(LineJoin) {
1680
+ /** 创建圆角 */ LineJoin[LineJoin["Round"] = 0] = "Round";
1681
+ /** 创建斜角 */ LineJoin[LineJoin["Bevel"] = 1] = "Bevel";
1682
+ /** 创建尖角 */ LineJoin[LineJoin["Miter"] = 2] = "Miter";
1683
+ })(LineJoin || (LineJoin = {}));
1677
1684
 
1678
1685
  /**
1679
1686
  * 动态换图类型
@@ -1882,8 +1889,8 @@ var index$1 = /*#__PURE__*/Object.freeze({
1882
1889
  get FontStyle () { return FontStyle; },
1883
1890
  BuiltinObjectGUID: BuiltinObjectGUID,
1884
1891
  get ShapePrimitiveType () { return ShapePrimitiveType; },
1885
- get ShapeConnectType () { return ShapeConnectType; },
1886
- get ShapePointType () { return ShapePointType; },
1892
+ get LineCap () { return LineCap; },
1893
+ get LineJoin () { return LineJoin; },
1887
1894
  get BackgroundType () { return BackgroundType; },
1888
1895
  get MultimediaType () { return MultimediaType; },
1889
1896
  get DataType () { return DataType; },
@@ -3802,7 +3809,9 @@ Vector4.ZERO = new Vector4(0.0, 0.0, 0.0, 0.0);
3802
3809
  if (renderer.renderingData.currentFrame.globalUniforms) {
3803
3810
  renderer.setGlobalMatrix("effects_ObjectToWorld", this.transform.getWorldMatrix());
3804
3811
  }
3805
- renderer.drawGeometry(this.geometry, this.material);
3812
+ for(var i = 0; i < this.materials.length; i++){
3813
+ renderer.drawGeometry(this.geometry, this.materials[i], i);
3814
+ }
3806
3815
  };
3807
3816
  _proto.getBoundingBox = function getBoundingBox() {
3808
3817
  var worldMatrix = this.transform.getWorldMatrix();
@@ -7337,7 +7346,15 @@ var BYTES_TYPE_MAP = (_obj$6 = {}, _obj$6[glContext.FLOAT] = Float32Array.BYTES_
7337
7346
  */ var Geometry = /*#__PURE__*/ function(EffectsObject) {
7338
7347
  _inherits(Geometry, EffectsObject);
7339
7348
  function Geometry() {
7340
- return EffectsObject.apply(this, arguments);
7349
+ var _this;
7350
+ _this = EffectsObject.apply(this, arguments) || this;
7351
+ /**
7352
+ * Geometry 的名称
7353
+ */ _this.name = "";
7354
+ /**
7355
+ * 子网格数据
7356
+ */ _this.subMeshes = [];
7357
+ return _this;
7341
7358
  }
7342
7359
  var _proto = Geometry.prototype;
7343
7360
  /**
@@ -12703,18 +12720,12 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
12703
12720
  var keyTimeStart = this.curveMap[keyTimeData[0]].timeStart;
12704
12721
  var keyTimeEnd = this.curveMap[keyTimeData[keyTimeData.length - 1]].timeEnd;
12705
12722
  if (time <= keyTimeStart) {
12706
- if (this.startKeyframe[0] === BezierKeyframeType.LINE || this.startKeyframe[0] === BezierKeyframeType.HOLD) {
12707
- keyframeInfo.getPointIndexInCurve(this.startKeyframe, keyframeInfo.pointIndexCache);
12708
- return this.endKeyframe[1][keyframeInfo.pointIndexCache.yIndex];
12709
- }
12710
- return this.getCurveValue(keyTimeData[0], keyTimeStart);
12723
+ keyframeInfo.getPointIndexInCurve(this.startKeyframe, keyframeInfo.pointIndexCache);
12724
+ return this.startKeyframe[1][keyframeInfo.pointIndexCache.yIndex];
12711
12725
  }
12712
12726
  if (time >= keyTimeEnd) {
12713
- if (this.endKeyframe[0] === BezierKeyframeType.LINE || this.endKeyframe[0] === BezierKeyframeType.HOLD) {
12714
- keyframeInfo.getPointIndexInCurve(this.endKeyframe, keyframeInfo.pointIndexCache);
12715
- return this.endKeyframe[1][keyframeInfo.pointIndexCache.yIndex];
12716
- }
12717
- return this.getCurveValue(keyTimeData[keyTimeData.length - 1], keyTimeEnd);
12727
+ keyframeInfo.getPointIndexInCurve(this.endKeyframe, keyframeInfo.pointIndexCache);
12728
+ return this.endKeyframe[1][keyframeInfo.pointIndexCache.yIndex];
12718
12729
  }
12719
12730
  for(var i = 0; i < keyTimeData.length; i++){
12720
12731
  var xMin = this.curveMap[keyTimeData[i]].timeStart;
@@ -14860,6 +14871,10 @@ function triangulate(contours) {
14860
14871
  points
14861
14872
  ]);
14862
14873
  var indexStart = vertices.length / 2;
14874
+ // 当所有 points 在一条直线时, gluTess 三角化 triangles 会返回空数组,这边做一下额外处理返回线段左右端点组成的三角形,确保拿到的包围盒是正确的。
14875
+ if (triangles.length === 0) {
14876
+ this.getLineEndPointsTriangle(points, triangles);
14877
+ }
14863
14878
  for(var i = 0; i < triangles.length; i++){
14864
14879
  vertices[verticesOffset * 2 + i] = triangles[i];
14865
14880
  }
@@ -14868,6 +14883,57 @@ function triangulate(contours) {
14868
14883
  indices[indicesOffset + i1] = indexStart + i1;
14869
14884
  }
14870
14885
  };
14886
+ /**
14887
+ * 获取直线上最远的两个端点坐标组成的三角形
14888
+ */ _proto.getLineEndPointsTriangle = function getLineEndPointsTriangle(points, triangles) {
14889
+ // 参数检查
14890
+ if (!points || points.length < 2 || points.length % 2 !== 0) {
14891
+ throw new Error("Invalid points array");
14892
+ }
14893
+ if (points.length === 2) {
14894
+ triangles.push(points[0], points[1], points[0], points[1], points[0], points[1]);
14895
+ return;
14896
+ }
14897
+ // 取第一个线段计算斜率
14898
+ var dx = points[2] - points[0];
14899
+ var dy = points[3] - points[1];
14900
+ // 存放结果坐标
14901
+ var startX = points[0];
14902
+ var startY = points[1];
14903
+ var endX = points[0];
14904
+ var endY = points[1];
14905
+ // 根据斜率决定比较x还是y
14906
+ if (Math.abs(dx) >= Math.abs(dy)) {
14907
+ // 水平方向为主,比较x坐标
14908
+ for(var i = 0; i < points.length; i += 2){
14909
+ var x = points[i];
14910
+ var y = points[i + 1];
14911
+ if (x < startX) {
14912
+ startX = x;
14913
+ startY = y;
14914
+ }
14915
+ if (x > endX) {
14916
+ endX = x;
14917
+ endY = y;
14918
+ }
14919
+ }
14920
+ } else {
14921
+ // 垂直方向为主,比较y坐标
14922
+ for(var i1 = 0; i1 < points.length; i1 += 2){
14923
+ var x1 = points[i1];
14924
+ var y1 = points[i1 + 1];
14925
+ if (y1 < startY) {
14926
+ startX = x1;
14927
+ startY = y1;
14928
+ }
14929
+ if (y1 > endY) {
14930
+ endX = x1;
14931
+ endY = y1;
14932
+ }
14933
+ }
14934
+ }
14935
+ triangles.push(startX, startY, endX, endY, endX, endY);
14936
+ };
14871
14937
  _create_class(Polygon, [
14872
14938
  {
14873
14939
  key: "lastX",
@@ -15341,47 +15407,48 @@ var PolyStar = /*#__PURE__*/ function(ShapePrimitive) {
15341
15407
  }(ShapePrimitive);
15342
15408
 
15343
15409
  // Based on:
15344
- // const tempPoints = [new Point(), new Point(), new Point(), new Point()];
15345
15410
  /**
15346
- * The `Rectangle` object is an area defined by its position, as indicated by its upper-left corner
15347
- * point (`x`, `y`) and by its `width` and its `height`.
15411
+ * The `Rectangle` object is an area defined by its position, as indicated by its top-left corner
15412
+ * point (`x`, `y`) and by its `width` and its `height`, including a `roundness` property that
15413
+ * defines the roundness of the rounded corners.
15414
+ * @memberof maths
15348
15415
  */ var Rectangle$1 = /*#__PURE__*/ function(ShapePrimitive) {
15349
15416
  _inherits(Rectangle, ShapePrimitive);
15350
- function Rectangle(x, y, width, height) {
15417
+ function Rectangle(x, y, width, height, roundness) {
15351
15418
  if (x === void 0) x = 0;
15352
15419
  if (y === void 0) y = 0;
15353
15420
  if (width === void 0) width = 0;
15354
15421
  if (height === void 0) height = 0;
15422
+ if (roundness === void 0) roundness = 20;
15355
15423
  var _this;
15356
15424
  _this = ShapePrimitive.call(this) || this;
15357
- _this.x = Number(x);
15358
- _this.y = Number(y);
15359
- _this.width = Number(width);
15360
- _this.height = Number(height);
15425
+ _this.x = x;
15426
+ _this.y = y;
15427
+ _this.width = width;
15428
+ _this.height = height;
15429
+ _this.roundness = roundness;
15361
15430
  return _this;
15362
15431
  }
15363
15432
  var _proto = Rectangle.prototype;
15364
- /** Determines whether the Rectangle is empty. */ _proto.isEmpty = function isEmpty() {
15365
- return this.left === this.right || this.top === this.bottom;
15433
+ /**
15434
+ * Returns the framing rectangle of the rectangle as a Rectangle object
15435
+ * @param out - optional rectangle to store the result
15436
+ * @returns The framing rectangle
15437
+ */ _proto.getBounds = function getBounds(out) {
15438
+ out = out || new Rectangle();
15439
+ out.x = this.x;
15440
+ out.y = this.y;
15441
+ out.width = this.width;
15442
+ out.height = this.height;
15443
+ return out;
15366
15444
  };
15367
15445
  /**
15368
- * Creates a clone of this Rectangle
15369
- * @returns a copy of the rectangle
15446
+ * Creates a clone of this rectangle.
15447
+ * @returns - A copy of the rectangle.
15370
15448
  */ _proto.clone = function clone() {
15371
- return new Rectangle(this.x, this.y, this.width, this.height);
15449
+ return new Rectangle(this.x, this.y, this.width, this.height, this.roundness);
15372
15450
  };
15373
15451
  /**
15374
- * Converts a Bounds object to a Rectangle object.
15375
- * @param bounds - The bounds to copy and convert to a rectangle.
15376
- * @returns Returns itself.
15377
- */ // copyFromBounds (bounds: Bounds): this {
15378
- // this.x = bounds.minX;
15379
- // this.y = bounds.minY;
15380
- // this.width = bounds.maxX - bounds.minX;
15381
- // this.height = bounds.maxY - bounds.minY;
15382
- // return this;
15383
- // }
15384
- /**
15385
15452
  * Copies another rectangle to this one.
15386
15453
  * @param rectangle - The rectangle to copy from.
15387
15454
  * @returns Returns itself.
@@ -15390,6 +15457,7 @@ var PolyStar = /*#__PURE__*/ function(ShapePrimitive) {
15390
15457
  this.y = rectangle.y;
15391
15458
  this.width = rectangle.width;
15392
15459
  this.height = rectangle.height;
15460
+ this.roundness = rectangle.roundness;
15393
15461
  return this;
15394
15462
  };
15395
15463
  /**
@@ -15400,267 +15468,121 @@ var PolyStar = /*#__PURE__*/ function(ShapePrimitive) {
15400
15468
  rectangle.copyFrom(this);
15401
15469
  return rectangle;
15402
15470
  };
15403
- /**
15404
- * Checks whether the x and y coordinates given are contained within this Rectangle
15405
- * @param x - The X coordinate of the point to test
15406
- * @param y - The Y coordinate of the point to test
15407
- * @returns Whether the x/y coordinates are within this Rectangle
15408
- */ _proto.contains = function contains(x, y) {
15409
- if (this.width <= 0 || this.height <= 0) {
15410
- return false;
15471
+ _proto.build = function build(points) {
15472
+ var ry;
15473
+ var halfWidth = this.width / 2;
15474
+ var halfHeight = this.height / 2;
15475
+ var x = this.x + halfWidth;
15476
+ var y = this.y + halfHeight;
15477
+ var rx = ry = Math.max(0, Math.min(this.roundness / 100, 1) * Math.min(halfWidth, halfHeight));
15478
+ var dx = halfWidth - rx;
15479
+ var dy = halfHeight - ry;
15480
+ if (!(rx >= 0 && ry >= 0 && dx >= 0 && dy >= 0)) {
15481
+ return;
15411
15482
  }
15412
- if (x >= this.x && x < this.x + this.width) {
15413
- if (y >= this.y && y < this.y + this.height) {
15414
- return true;
15415
- }
15483
+ // 控制边缘的平滑程度
15484
+ var densityScale = 5;
15485
+ // Choose a number of segments such that the maximum absolute deviation from the circle is approximately 0.029
15486
+ var n = densityScale * Math.ceil(2.3 * Math.sqrt(rx + ry));
15487
+ var m = n * 8 + (dx ? 4 : 0) + (dy ? 4 : 0);
15488
+ if (m === 0) {
15489
+ return;
15416
15490
  }
15417
- return false;
15418
- };
15419
- /**
15420
- * Checks whether the x and y coordinates given are contained within this rectangle including the stroke.
15421
- * @param x - The X coordinate of the point to test
15422
- * @param y - The Y coordinate of the point to test
15423
- * @param strokeWidth - The width of the line to check
15424
- * @returns Whether the x/y coordinates are within this rectangle
15425
- */ _proto.strokeContains = function strokeContains(x, y, strokeWidth) {
15426
- var _this = this, width = _this.width, height = _this.height;
15427
- if (width <= 0 || height <= 0) {
15428
- return false;
15491
+ if (n === 0) {
15492
+ points[0] = points[6] = x + dx;
15493
+ points[1] = points[3] = y + dy;
15494
+ points[2] = points[4] = x - dx;
15495
+ points[5] = points[7] = y - dy;
15496
+ return;
15429
15497
  }
15430
- var _x = this.x;
15431
- var _y = this.y;
15432
- var outerLeft = _x - strokeWidth / 2;
15433
- var outerRight = _x + width + strokeWidth / 2;
15434
- var outerTop = _y - strokeWidth / 2;
15435
- var outerBottom = _y + height + strokeWidth / 2;
15436
- var innerLeft = _x + strokeWidth / 2;
15437
- var innerRight = _x + width - strokeWidth / 2;
15438
- var innerTop = _y + strokeWidth / 2;
15439
- var innerBottom = _y + height - strokeWidth / 2;
15440
- return x >= outerLeft && x <= outerRight && y >= outerTop && y <= outerBottom && !(x > innerLeft && x < innerRight && y > innerTop && y < innerBottom);
15441
- };
15442
- /**
15443
- * Determines whether the `other` Rectangle transformed by `transform` intersects with `this` Rectangle object.
15444
- * Returns true only if the area of the intersection is >0, this means that Rectangles
15445
- * sharing a side are not overlapping. Another side effect is that an arealess rectangle
15446
- * (width or height equal to zero) can't intersect any other rectangle.
15447
- * @param {Rectangle} other - The Rectangle to intersect with `this`.
15448
- * @param {Matrix} transform - The transformation matrix of `other`.
15449
- * @returns {boolean} A value of `true` if the transformed `other` Rectangle intersects with `this`; otherwise `false`.
15450
- */ // intersects (other: Rectangle, transform?: Matrix4): boolean {
15451
- // if (!transform) {
15452
- // const x0 = this.x < other.x ? other.x : this.x;
15453
- // const x1 = this.right > other.right ? other.right : this.right;
15454
- // if (x1 <= x0) {
15455
- // return false;
15456
- // }
15457
- // const y0 = this.y < other.y ? other.y : this.y;
15458
- // const y1 = this.bottom > other.bottom ? other.bottom : this.bottom;
15459
- // return y1 > y0;
15460
- // }
15461
- // const x0 = this.left;
15462
- // const x1 = this.right;
15463
- // const y0 = this.top;
15464
- // const y1 = this.bottom;
15465
- // if (x1 <= x0 || y1 <= y0) {
15466
- // return false;
15467
- // }
15468
- // const lt = tempPoints[0].set(other.left, other.top);
15469
- // const lb = tempPoints[1].set(other.left, other.bottom);
15470
- // const rt = tempPoints[2].set(other.right, other.top);
15471
- // const rb = tempPoints[3].set(other.right, other.bottom);
15472
- // if (rt.x <= lt.x || lb.y <= lt.y) {
15473
- // return false;
15474
- // }
15475
- // const s = Math.sign((transform.a * transform.d) - (transform.b * transform.c));
15476
- // if (s === 0) {
15477
- // return false;
15478
- // }
15479
- // transform.apply(lt, lt);
15480
- // transform.apply(lb, lb);
15481
- // transform.apply(rt, rt);
15482
- // transform.apply(rb, rb);
15483
- // if (Math.max(lt.x, lb.x, rt.x, rb.x) <= x0
15484
- // || Math.min(lt.x, lb.x, rt.x, rb.x) >= x1
15485
- // || Math.max(lt.y, lb.y, rt.y, rb.y) <= y0
15486
- // || Math.min(lt.y, lb.y, rt.y, rb.y) >= y1) {
15487
- // return false;
15488
- // }
15489
- // const nx = s * (lb.y - lt.y);
15490
- // const ny = s * (lt.x - lb.x);
15491
- // const n00 = (nx * x0) + (ny * y0);
15492
- // const n10 = (nx * x1) + (ny * y0);
15493
- // const n01 = (nx * x0) + (ny * y1);
15494
- // const n11 = (nx * x1) + (ny * y1);
15495
- // if (Math.max(n00, n10, n01, n11) <= (nx * lt.x) + (ny * lt.y)
15496
- // || Math.min(n00, n10, n01, n11) >= (nx * rb.x) + (ny * rb.y)) {
15497
- // return false;
15498
- // }
15499
- // const mx = s * (lt.y - rt.y);
15500
- // const my = s * (rt.x - lt.x);
15501
- // const m00 = (mx * x0) + (my * y0);
15502
- // const m10 = (mx * x1) + (my * y0);
15503
- // const m01 = (mx * x0) + (my * y1);
15504
- // const m11 = (mx * x1) + (my * y1);
15505
- // if (Math.max(m00, m10, m01, m11) <= (mx * lt.x) + (my * lt.y)
15506
- // || Math.min(m00, m10, m01, m11) >= (mx * rb.x) + (my * rb.y)) {
15507
- // return false;
15508
- // }
15509
- // return true;
15510
- // }
15511
- /**
15512
- * Pads the rectangle making it grow in all directions.
15513
- * If paddingY is omitted, both paddingX and paddingY will be set to paddingX.
15514
- * @param paddingX - The horizontal padding amount.
15515
- * @param paddingY - The vertical padding amount.
15516
- * @returns Returns itself.
15517
- */ _proto.pad = function pad(paddingX, paddingY) {
15518
- if (paddingX === void 0) paddingX = 0;
15519
- if (paddingY === void 0) paddingY = paddingX;
15520
- this.x -= paddingX;
15521
- this.y -= paddingY;
15522
- this.width += paddingX * 2;
15523
- this.height += paddingY * 2;
15524
- return this;
15525
- };
15526
- /**
15527
- * Fits this rectangle around the passed one.
15528
- * @param rectangle - The rectangle to fit.
15529
- * @returns Returns itself.
15530
- */ _proto.fit = function fit(rectangle) {
15531
- var x1 = Math.max(this.x, rectangle.x);
15532
- var x2 = Math.min(this.x + this.width, rectangle.x + rectangle.width);
15533
- var y1 = Math.max(this.y, rectangle.y);
15534
- var y2 = Math.min(this.y + this.height, rectangle.y + rectangle.height);
15535
- this.x = x1;
15536
- this.width = Math.max(x2 - x1, 0);
15537
- this.y = y1;
15538
- this.height = Math.max(y2 - y1, 0);
15539
- return this;
15540
- };
15541
- /**
15542
- * Enlarges rectangle that way its corners lie on grid
15543
- * @param resolution - resolution
15544
- * @param eps - precision
15545
- * @returns Returns itself.
15546
- */ _proto.ceil = function ceil(resolution, eps) {
15547
- if (resolution === void 0) resolution = 1;
15548
- if (eps === void 0) eps = 0.001;
15549
- var x2 = Math.ceil((this.x + this.width - eps) * resolution) / resolution;
15550
- var y2 = Math.ceil((this.y + this.height - eps) * resolution) / resolution;
15551
- this.x = Math.floor((this.x + eps) * resolution) / resolution;
15552
- this.y = Math.floor((this.y + eps) * resolution) / resolution;
15553
- this.width = x2 - this.x;
15554
- this.height = y2 - this.y;
15555
- return this;
15556
- };
15557
- /**
15558
- * Enlarges this rectangle to include the passed rectangle.
15559
- * @param rectangle - The rectangle to include.
15560
- * @returns Returns itself.
15561
- */ _proto.enlarge = function enlarge(rectangle) {
15562
- var x1 = Math.min(this.x, rectangle.x);
15563
- var x2 = Math.max(this.x + this.width, rectangle.x + rectangle.width);
15564
- var y1 = Math.min(this.y, rectangle.y);
15565
- var y2 = Math.max(this.y + this.height, rectangle.y + rectangle.height);
15566
- this.x = x1;
15567
- this.width = x2 - x1;
15568
- this.y = y1;
15569
- this.height = y2 - y1;
15570
- return this;
15571
- };
15572
- /**
15573
- * Returns the framing rectangle of the rectangle as a Rectangle object
15574
- * @param out - optional rectangle to store the result
15575
- * @returns The framing rectangle
15576
- */ _proto.getBounds = function getBounds(out) {
15577
- out = out || new Rectangle();
15578
- out.copyFrom(this);
15579
- return out;
15580
- };
15581
- _proto.getX = function getX() {
15582
- return this.x;
15583
- };
15584
- _proto.getY = function getY() {
15585
- return this.y;
15586
- };
15587
- _proto.build = function build(points) {
15588
- var x = this.x;
15589
- var y = this.y;
15590
- var width = this.width;
15591
- var height = this.height;
15592
- if (!(width >= 0 && height >= 0)) {
15593
- return points;
15498
+ var j1 = 0;
15499
+ var j2 = n * 4 + (dx ? 2 : 0) + 2;
15500
+ var j3 = j2;
15501
+ var j4 = m;
15502
+ var x0 = dx + rx;
15503
+ var y0 = dy;
15504
+ var x1 = x + x0;
15505
+ var x2 = x - x0;
15506
+ var y1 = y + y0;
15507
+ points[j1++] = x1;
15508
+ points[j1++] = y1;
15509
+ points[--j2] = y1;
15510
+ points[--j2] = x2;
15511
+ if (dy) {
15512
+ var y2 = y - y0;
15513
+ points[j3++] = x2;
15514
+ points[j3++] = y2;
15515
+ points[--j4] = y2;
15516
+ points[--j4] = x1;
15517
+ }
15518
+ for(var i = 1; i < n; i++){
15519
+ var a = Math.PI / 2 * (i / n);
15520
+ var x01 = dx + Math.cos(a) * rx;
15521
+ var y01 = dy + Math.sin(a) * ry;
15522
+ var x11 = x + x01;
15523
+ var x21 = x - x01;
15524
+ var y11 = y + y01;
15525
+ var y21 = y - y01;
15526
+ points[j1++] = x11;
15527
+ points[j1++] = y11;
15528
+ points[--j2] = y11;
15529
+ points[--j2] = x21;
15530
+ points[j3++] = x21;
15531
+ points[j3++] = y21;
15532
+ points[--j4] = y21;
15533
+ points[--j4] = x11;
15534
+ }
15535
+ x0 = dx;
15536
+ y0 = dy + ry;
15537
+ x1 = x + x0;
15538
+ x2 = x - x0;
15539
+ y1 = y + y0;
15540
+ var y22 = y - y0;
15541
+ points[j1++] = x1;
15542
+ points[j1++] = y1;
15543
+ points[--j4] = y22;
15544
+ points[--j4] = x1;
15545
+ if (dx) {
15546
+ points[j1++] = x2;
15547
+ points[j1++] = y1;
15548
+ points[--j4] = y22;
15549
+ points[--j4] = x2;
15594
15550
  }
15595
- points[0] = x;
15596
- points[1] = y;
15597
- points[2] = x + width;
15598
- points[3] = y;
15599
- points[4] = x + width;
15600
- points[5] = y + height;
15601
- points[6] = x;
15602
- points[7] = y + height;
15603
- return points;
15604
15551
  };
15605
15552
  _proto.triangulate = function triangulate(points, vertices, verticesOffset, indices, indicesOffset) {
15606
- var count = 0;
15607
- var verticesStride = 2;
15608
- verticesOffset *= verticesStride;
15609
- vertices[verticesOffset + count] = points[0];
15610
- vertices[verticesOffset + count + 1] = points[1];
15611
- count += verticesStride;
15612
- vertices[verticesOffset + count] = points[2];
15613
- vertices[verticesOffset + count + 1] = points[3];
15614
- count += verticesStride;
15615
- vertices[verticesOffset + count] = points[6];
15616
- vertices[verticesOffset + count + 1] = points[7];
15617
- count += verticesStride;
15618
- vertices[verticesOffset + count] = points[4];
15619
- vertices[verticesOffset + count + 1] = points[5];
15620
- count += verticesStride;
15621
- var verticesIndex = verticesOffset / verticesStride;
15622
- // triangle 1
15623
- indices[indicesOffset++] = verticesIndex;
15624
- indices[indicesOffset++] = verticesIndex + 1;
15625
- indices[indicesOffset++] = verticesIndex + 2;
15626
- // triangle 2
15627
- indices[indicesOffset++] = verticesIndex + 1;
15628
- indices[indicesOffset++] = verticesIndex + 3;
15629
- indices[indicesOffset++] = verticesIndex + 2;
15630
- };
15631
- _create_class(Rectangle, [
15632
- {
15633
- key: "left",
15634
- get: /** Returns the left edge of the rectangle. */ function get() {
15635
- return this.x;
15636
- }
15637
- },
15638
- {
15639
- key: "right",
15640
- get: /** Returns the right edge of the rectangle. */ function get() {
15641
- return this.x + this.width;
15642
- }
15643
- },
15644
- {
15645
- key: "top",
15646
- get: /** Returns the top edge of the rectangle. */ function get() {
15647
- return this.y;
15648
- }
15649
- },
15650
- {
15651
- key: "bottom",
15652
- get: /** Returns the bottom edge of the rectangle. */ function get() {
15653
- return this.y + this.height;
15654
- }
15553
+ if (points.length === 0) {
15554
+ return;
15655
15555
  }
15656
- ], [
15657
- {
15658
- key: "EMPTY",
15659
- get: /** A constant empty rectangle. This is a new object every time the property is accessed */ function get() {
15660
- return new Rectangle(0, 0, 0, 0);
15556
+ // Compute center (average of all points)
15557
+ var centerX = 0;
15558
+ var centerY = 0;
15559
+ for(var i = 0; i < points.length; i += 2){
15560
+ centerX += points[i];
15561
+ centerY += points[i + 1];
15562
+ }
15563
+ centerX /= points.length / 2;
15564
+ centerY /= points.length / 2;
15565
+ // Set center vertex
15566
+ var count = verticesOffset;
15567
+ vertices[count * 2] = centerX;
15568
+ vertices[count * 2 + 1] = centerY;
15569
+ var centerIndex = count++;
15570
+ // Set edge vertices and indices
15571
+ for(var i1 = 0; i1 < points.length; i1 += 2){
15572
+ vertices[count * 2] = points[i1];
15573
+ vertices[count * 2 + 1] = points[i1 + 1];
15574
+ if (i1 > 0) {
15575
+ indices[indicesOffset++] = count;
15576
+ indices[indicesOffset++] = centerIndex;
15577
+ indices[indicesOffset++] = count - 1;
15661
15578
  }
15579
+ count++;
15662
15580
  }
15663
- ]);
15581
+ // Connect last point to the first edge point
15582
+ indices[indicesOffset++] = centerIndex + 1;
15583
+ indices[indicesOffset++] = centerIndex;
15584
+ indices[indicesOffset++] = count - 1;
15585
+ };
15664
15586
  return Rectangle;
15665
15587
  }(ShapePrimitive);
15666
15588
 
@@ -15758,8 +15680,8 @@ var ShapePath = /*#__PURE__*/ function() {
15758
15680
  * @param h - The height of the rectangle.
15759
15681
  * @param transform - An optional `Matrix` object to apply a transformation to the rectangle.
15760
15682
  * @returns The instance of the current object for chaining.
15761
- */ _proto.rect = function rect(x, y, w, h, transform) {
15762
- this.drawShape(new Rectangle$1(x, y, w, h), transform);
15683
+ */ _proto.rect = function rect(x, y, w, h, roundness, transform) {
15684
+ this.drawShape(new Rectangle$1(x, y, w, h, roundness), transform);
15763
15685
  return this;
15764
15686
  };
15765
15687
  /**
@@ -15905,7 +15827,7 @@ var GraphicsPath = /*#__PURE__*/ function() {
15905
15827
  * @param h - The height of the rectangle.
15906
15828
  * @param transform - An optional `Matrix` object to apply a transformation to the rectangle.
15907
15829
  * @returns The instance of the current object for chaining.
15908
- */ _proto.rect = function rect(x, y, w, h, transform) {
15830
+ */ _proto.rect = function rect(x, y, w, h, roundness, transform) {
15909
15831
  this.instructions.push({
15910
15832
  action: "rect",
15911
15833
  data: [
@@ -15913,6 +15835,7 @@ var GraphicsPath = /*#__PURE__*/ function() {
15913
15835
  y,
15914
15836
  w,
15915
15837
  h,
15838
+ roundness,
15916
15839
  transform
15917
15840
  ]
15918
15841
  });
@@ -16222,9 +16145,9 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16222
16145
  var innerWeight = (1 - ratio) * 2;
16223
16146
  var outerWeight = ratio * 2;
16224
16147
  if (!closedShape) {
16225
- if (style.cap === "round") {
16148
+ if (style.cap === LineCap.Round) {
16226
16149
  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;
16227
- } else if (style.cap === "square") {
16150
+ } else if (style.cap === LineCap.Square) {
16228
16151
  indexCount += square(x0, y0, perpX, perpY, innerWeight, outerWeight, true, verts);
16229
16152
  }
16230
16153
  }
@@ -16263,7 +16186,7 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16263
16186
  verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
16264
16187
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
16265
16188
  /* 180 degree corner? */ if (dot >= 0) {
16266
- if (style.join === "round") {
16189
+ if (style.join === LineJoin.Round) {
16267
16190
  indexCount += round(x1, y1, x1 - perpX * innerWeight, y1 - perpY * innerWeight, x1 - perp1x * innerWeight, y1 - perp1y * innerWeight, verts, false) + 4;
16268
16191
  } else {
16269
16192
  indexCount += 2;
@@ -16287,7 +16210,7 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16287
16210
  var smallerInsideDiagonalSq = smallerInsideSegmentSq + insideWeight * insideWeight * widthSquared;
16288
16211
  var insideMiterOk = pDist <= smallerInsideDiagonalSq;
16289
16212
  if (insideMiterOk) {
16290
- if (style.join === "bevel" || pDist / widthSquared > miterLimitSquared) {
16213
+ if (style.join === LineJoin.Bevel || pDist / widthSquared > miterLimitSquared) {
16291
16214
  if (clockwise) /* rotating at inner angle */ {
16292
16215
  verts.push(imx, imy); // inner miter point
16293
16216
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight); // first segment's outer vertex
@@ -16300,7 +16223,7 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16300
16223
  verts.push(omx, omy); // outer miter point
16301
16224
  }
16302
16225
  indexCount += 2;
16303
- } else if (style.join === "round") {
16226
+ } else if (style.join === LineJoin.Round) {
16304
16227
  if (clockwise) /* arc is outside */ {
16305
16228
  verts.push(imx, imy);
16306
16229
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
@@ -16321,13 +16244,13 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16321
16244
  } else {
16322
16245
  verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight); // first segment's inner vertex
16323
16246
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight); // first segment's outer vertex
16324
- if (style.join === "round") {
16247
+ if (style.join === LineJoin.Round) {
16325
16248
  if (clockwise) /* arc is outside */ {
16326
16249
  indexCount += round(x1, y1, x1 + perpX * outerWeight, y1 + perpY * outerWeight, x1 + perp1x * outerWeight, y1 + perp1y * outerWeight, verts, true) + 2;
16327
16250
  } else /* arc is inside */ {
16328
16251
  indexCount += round(x1, y1, x1 - perpX * innerWeight, y1 - perpY * innerWeight, x1 - perp1x * innerWeight, y1 - perp1y * innerWeight, verts, false) + 2;
16329
16252
  }
16330
- } else if (style.join === "miter" && pDist / widthSquared <= miterLimitSquared) {
16253
+ } else if (style.join === LineJoin.Miter && pDist / widthSquared <= miterLimitSquared) {
16331
16254
  if (clockwise) {
16332
16255
  verts.push(omx, omy); // inner miter point
16333
16256
  verts.push(omx, omy); // inner miter point
@@ -16356,9 +16279,9 @@ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16356
16279
  verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
16357
16280
  verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
16358
16281
  if (!closedShape) {
16359
- if (style.cap === "round") {
16282
+ if (style.cap === LineCap.Round) {
16360
16283
  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;
16361
- } else if (style.cap === "square") {
16284
+ } else if (style.cap === LineCap.Square) {
16362
16285
  indexCount += square(x1, y1, perpX, perpY, innerWeight, outerWeight, false, verts);
16363
16286
  }
16364
16287
  }
@@ -16385,9 +16308,10 @@ var ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16385
16308
  var _this;
16386
16309
  _this = MeshComponent.call(this, engine) || this;
16387
16310
  _this.isStroke = false;
16311
+ _this.isFill = false;
16312
+ _this.shapeDirty = true;
16388
16313
  _this.graphicsPath = new GraphicsPath();
16389
16314
  _this.curveValues = [];
16390
- _this.shapeDirty = true;
16391
16315
  _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";
16392
16316
  _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";
16393
16317
  if (!_this.geometry) {
@@ -16420,6 +16344,15 @@ var ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16420
16344
  mode: glContext.TRIANGLES,
16421
16345
  drawCount: 4
16422
16346
  });
16347
+ _this.geometry.subMeshes.push({
16348
+ offset: 0,
16349
+ indexCount: 0,
16350
+ vertexCount: 0
16351
+ }, {
16352
+ offset: 0,
16353
+ indexCount: 0,
16354
+ vertexCount: 0
16355
+ });
16423
16356
  }
16424
16357
  if (!_this.material) {
16425
16358
  var materialProps = {
@@ -16429,18 +16362,29 @@ var ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16429
16362
  glslVersion: GLSLVersion.GLSL1
16430
16363
  }
16431
16364
  };
16432
- _this.material = Material.create(engine, materialProps);
16433
- _this.material.setColor("_Color", new Color(1, 1, 1, 1));
16434
- _this.material.depthMask = false;
16435
- _this.material.depthTest = true;
16436
- _this.material.blending = true;
16365
+ var fillMaterial = Material.create(engine, materialProps);
16366
+ fillMaterial.setColor("_Color", new Color(1, 1, 1, 1));
16367
+ fillMaterial.depthMask = false;
16368
+ fillMaterial.depthTest = true;
16369
+ fillMaterial.blending = true;
16370
+ _this.material = fillMaterial;
16371
+ var strokeMaterial = Material.create(engine, materialProps);
16372
+ strokeMaterial.setColor("_Color", new Color(0.25, 0.25, 0.25, 1));
16373
+ strokeMaterial.depthMask = false;
16374
+ strokeMaterial.depthTest = true;
16375
+ strokeMaterial.blending = true;
16376
+ _this.materials[1] = strokeMaterial;
16437
16377
  }
16438
16378
  _this.strokeAttributes = {
16439
16379
  width: 1,
16440
16380
  alignment: 0.5,
16441
- cap: "butt",
16442
- join: "miter",
16443
- miterLimit: 10
16381
+ cap: LineCap.Butt,
16382
+ join: LineJoin.Miter,
16383
+ miterLimit: 10,
16384
+ color: new Color(1, 1, 1, 1)
16385
+ };
16386
+ _this.fillAttribute = {
16387
+ color: new Color(1, 1, 1, 1)
16444
16388
  };
16445
16389
  _this.shapeAttribute = {
16446
16390
  type: ShapePrimitiveType.Custom,
@@ -16456,6 +16400,8 @@ var ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16456
16400
  this.item.getHitTestParams = this.getHitTestParams;
16457
16401
  };
16458
16402
  _proto.onUpdate = function onUpdate(dt) {
16403
+ this.material.color = this.fillAttribute.color;
16404
+ this.materials[1].color = this.strokeAttributes.color;
16459
16405
  if (this.shapeDirty) {
16460
16406
  this.buildPath(this.shapeAttribute);
16461
16407
  this.buildGeometryFromPath(this.graphicsPath.shapePath);
@@ -16466,22 +16412,34 @@ var ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16466
16412
  var shapePrimitives = shapePath.shapePrimitives;
16467
16413
  var vertices = [];
16468
16414
  var indices = [];
16469
- // triangulate shapePrimitive
16470
- for(var _iterator = _create_for_of_iterator_helper_loose(shapePrimitives), _step; !(_step = _iterator()).done;){
16471
- var shapePrimitive = _step.value;
16472
- var shape = shapePrimitive.shape;
16473
- var points = [];
16474
- var indexOffset = indices.length;
16475
- var vertOffset = vertices.length / 2;
16476
- shape.build(points);
16477
- if (!this.isStroke) {
16415
+ // Triangulate shapePrimitive
16416
+ //---------------------------------------------------
16417
+ if (this.isFill) {
16418
+ for(var _iterator = _create_for_of_iterator_helper_loose(shapePrimitives), _step; !(_step = _iterator()).done;){
16419
+ var shapePrimitive = _step.value;
16420
+ var shape = shapePrimitive.shape;
16421
+ var points = [];
16422
+ var indexOffset = indices.length;
16423
+ var vertOffset = vertices.length / 2;
16424
+ shape.build(points);
16478
16425
  shape.triangulate(points, vertices, vertOffset, indices, indexOffset);
16479
- } else {
16426
+ }
16427
+ }
16428
+ var fillIndexCount = indices.length;
16429
+ if (this.isStroke) {
16430
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(shapePrimitives), _step1; !(_step1 = _iterator1()).done;){
16431
+ var shapePrimitive1 = _step1.value;
16432
+ var shape1 = shapePrimitive1.shape;
16433
+ var points1 = [];
16434
+ indices.length;
16435
+ var vertOffset1 = vertices.length / 2;
16480
16436
  var close = true;
16481
16437
  var lineStyle = this.strokeAttributes;
16482
- buildLine(points, lineStyle, false, close, vertices, 2, vertOffset, indices);
16438
+ shape1.build(points1);
16439
+ buildLine(points1, lineStyle, false, close, vertices, 2, vertOffset1, indices);
16483
16440
  }
16484
16441
  }
16442
+ var strokeIndexCount = indices.length - fillIndexCount;
16485
16443
  var vertexCount = vertices.length / 2;
16486
16444
  // get the current attribute and index arrays from the geometry, avoiding re-creation
16487
16445
  var positionArray = this.geometry.getAttributeData("aPos");
@@ -16514,6 +16472,12 @@ var ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16514
16472
  this.geometry.setAttributeData("aUV", uvArray);
16515
16473
  this.geometry.setIndexData(indexArray);
16516
16474
  this.geometry.setDrawCount(indices.length);
16475
+ var u16Size = 2;
16476
+ var fillSubMesh = this.geometry.subMeshes[0];
16477
+ var strokeSubMesh = this.geometry.subMeshes[1];
16478
+ fillSubMesh.indexCount = fillIndexCount;
16479
+ strokeSubMesh.offset = fillIndexCount * u16Size;
16480
+ strokeSubMesh.indexCount = strokeIndexCount;
16517
16481
  };
16518
16482
  _proto.buildPath = function buildPath(shapeAttribute) {
16519
16483
  this.graphicsPath.clear();
@@ -16527,7 +16491,6 @@ var ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16527
16491
  for(var _iterator = _create_for_of_iterator_helper_loose(customShapeAtribute.shapes), _step; !(_step = _iterator()).done;){
16528
16492
  var shape = _step.value;
16529
16493
  this.curveValues = [];
16530
- this.setFillColor(shape.fill);
16531
16494
  var indices = shape.indexes;
16532
16495
  for(var i = 1; i < indices.length; i++){
16533
16496
  var pointIndex = indices[i];
@@ -16559,38 +16522,28 @@ var ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16559
16522
  {
16560
16523
  var ellipseData = shapeAttribute;
16561
16524
  this.graphicsPath.ellipse(0, 0, ellipseData.xRadius, ellipseData.yRadius);
16562
- this.setFillColor(ellipseData.fill);
16563
16525
  break;
16564
16526
  }
16565
16527
  case ShapePrimitiveType.Rectangle:
16566
16528
  {
16567
16529
  var rectangleData = shapeAttribute;
16568
- this.graphicsPath.rect(-rectangleData.width / 2, -rectangleData.height / 2, rectangleData.width, rectangleData.height);
16569
- this.setFillColor(rectangleData.fill);
16530
+ this.graphicsPath.rect(-rectangleData.width / 2, -rectangleData.height / 2, rectangleData.width, rectangleData.height, rectangleData.roundness);
16570
16531
  break;
16571
16532
  }
16572
16533
  case ShapePrimitiveType.Star:
16573
16534
  {
16574
16535
  var starData = shapeAttribute;
16575
16536
  this.graphicsPath.polyStar(starData.pointCount, starData.outerRadius, starData.innerRadius, starData.outerRoundness, starData.innerRoundness, StarType.Star);
16576
- this.setFillColor(starData.fill);
16577
16537
  break;
16578
16538
  }
16579
16539
  case ShapePrimitiveType.Polygon:
16580
16540
  {
16581
16541
  var polygonData = shapeAttribute;
16582
16542
  this.graphicsPath.polyStar(polygonData.pointCount, polygonData.radius, polygonData.radius, polygonData.roundness, polygonData.roundness, StarType.Polygon);
16583
- this.setFillColor(polygonData.fill);
16584
16543
  break;
16585
16544
  }
16586
16545
  }
16587
16546
  };
16588
- _proto.setFillColor = function setFillColor(fill) {
16589
- if (fill) {
16590
- var color = fill.color;
16591
- this.material.setColor("_Color", new Color(color.r, color.g, color.b, color.a));
16592
- }
16593
- };
16594
16547
  _proto.fromData = function fromData(data) {
16595
16548
  MeshComponent.prototype.fromData.call(this, data);
16596
16549
  this.shapeDirty = true;
@@ -16598,19 +16551,27 @@ var ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16598
16551
  if (strokeParam) {
16599
16552
  this.isStroke = true;
16600
16553
  this.strokeAttributes.width = strokeParam.width;
16554
+ this.strokeAttributes.color.copyFrom(strokeParam.color);
16555
+ this.strokeAttributes.cap = strokeParam.cap;
16556
+ this.strokeAttributes.join = strokeParam.join;
16557
+ }
16558
+ var fillParam = data.fill;
16559
+ if (fillParam) {
16560
+ this.isFill = true;
16561
+ this.fillAttribute.color.copyFrom(fillParam.color);
16601
16562
  }
16602
16563
  switch(data.type){
16603
16564
  case ShapePrimitiveType.Custom:
16604
16565
  {
16605
- this.shapeAttribute = {
16566
+ var customShapeData = data;
16567
+ var customShapeAttribute = {
16606
16568
  type: ShapePrimitiveType.Custom,
16607
16569
  points: [],
16608
16570
  easingIns: [],
16609
16571
  easingOuts: [],
16610
- shapes: []
16572
+ shapes: [],
16573
+ fill: customShapeData.fill
16611
16574
  };
16612
- var customShapeData = data;
16613
- var customShapeAttribute = this.shapeAttribute;
16614
16575
  for(var _iterator = _create_for_of_iterator_helper_loose(customShapeData.points), _step; !(_step = _iterator()).done;){
16615
16576
  var point = _step.value;
16616
16577
  customShapeAttribute.points.push(new Vector2(point.x, point.y));
@@ -16624,6 +16585,7 @@ var ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16624
16585
  customShapeAttribute.easingOuts.push(new Vector2(easingOut.x, easingOut.y));
16625
16586
  }
16626
16587
  customShapeAttribute.shapes = customShapeData.shapes;
16588
+ this.shapeAttribute = customShapeAttribute;
16627
16589
  break;
16628
16590
  }
16629
16591
  case ShapePrimitiveType.Ellipse:
@@ -17514,10 +17476,8 @@ function shouldIgnoreBouncing(arg, mul) {
17514
17476
  };
17515
17477
  };
17516
17478
  _proto.setGeometry = function setGeometry(geometry, worldMatrix) {
17517
- if (this.geometry !== geometry) {
17518
- this.triangles = this.geometryToTriangles(geometry);
17519
- this.geometry = geometry;
17520
- }
17479
+ this.triangles = this.geometryToTriangles(geometry);
17480
+ this.geometry = geometry;
17521
17481
  var area = [];
17522
17482
  for(var _iterator = _create_for_of_iterator_helper_loose(this.triangles), _step; !(_step = _iterator()).done;){
17523
17483
  var triangle = _step.value;
@@ -17538,10 +17498,11 @@ function shouldIgnoreBouncing(arg, mul) {
17538
17498
  _proto.geometryToTriangles = function geometryToTriangles(geometry) {
17539
17499
  var _geometry_getIndexData;
17540
17500
  var indices = (_geometry_getIndexData = geometry.getIndexData()) != null ? _geometry_getIndexData : [];
17501
+ var drawCount = geometry.getDrawCount();
17541
17502
  var _geometry_getAttributeData;
17542
17503
  var vertices = (_geometry_getAttributeData = geometry.getAttributeData("aPos")) != null ? _geometry_getAttributeData : [];
17543
17504
  var res = [];
17544
- for(var i = 0; i < indices.length; i += 3){
17505
+ for(var i = 0; i < drawCount; i += 3){
17545
17506
  var index0 = indices[i] * 3;
17546
17507
  var index1 = indices[i + 1] * 3;
17547
17508
  var index2 = indices[i + 2] * 3;
@@ -25524,6 +25485,9 @@ var TextComponent = /*#__PURE__*/ function(BaseRenderComponent) {
25524
25485
  /**
25525
25486
  * 文本行数
25526
25487
  */ _this.lineCount = 0;
25488
+ /**
25489
+ * 每一行文本的最大宽度
25490
+ */ _this.maxLineWidth = 0;
25527
25491
  _this.SCALE_FACTOR = 0.1;
25528
25492
  _this.ALPHA_FIX_VALUE = 1 / 255;
25529
25493
  _this.name = "MText" + seed$2++;
@@ -25607,12 +25571,9 @@ var TextComponentBase = /*#__PURE__*/ function() {
25607
25571
  this.textStyle = new TextStyle(options);
25608
25572
  this.textLayout = new TextLayout(options);
25609
25573
  this.text = options.text.toString();
25610
- this.lineCount = this.getLineCount(options.text, true);
25611
25574
  };
25612
- _proto.getLineCount = function getLineCount(text, init) {
25613
- var context = this.context;
25614
- var letterSpace = this.textLayout.letterSpace;
25615
- var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
25575
+ _proto.getLineCount = function getLineCount(text, context) {
25576
+ var _this_textLayout = this.textLayout, letterSpace = _this_textLayout.letterSpace, overflow = _this_textLayout.overflow;
25616
25577
  var width = this.textLayout.width + this.textStyle.fontOffset;
25617
25578
  var lineCount = 1;
25618
25579
  var x = 0;
@@ -25620,15 +25581,27 @@ var TextComponentBase = /*#__PURE__*/ function() {
25620
25581
  var _context_measureText;
25621
25582
  var str = text[i];
25622
25583
  var _context_measureText_width;
25623
- 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;
25584
+ 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;
25624
25585
  // 和浏览器行为保持一致
25625
25586
  x += letterSpace;
25626
- if (x + textMetrics > width && i > 0 || str === "\n") {
25627
- lineCount++;
25628
- x = 0;
25629
- }
25630
- if (str !== "\n") {
25631
- x += textMetrics;
25587
+ // 处理文本结束行为
25588
+ if (overflow === TextOverflow.display) {
25589
+ if (str === "\n") {
25590
+ lineCount++;
25591
+ x = 0;
25592
+ } else {
25593
+ x += textMetrics;
25594
+ this.maxLineWidth = Math.max(this.maxLineWidth, x);
25595
+ }
25596
+ } else {
25597
+ if (x + textMetrics > width && i > 0 || str === "\n") {
25598
+ lineCount++;
25599
+ this.maxLineWidth = Math.max(this.maxLineWidth, x);
25600
+ x = 0;
25601
+ }
25602
+ if (str !== "\n") {
25603
+ x += textMetrics;
25604
+ }
25632
25605
  }
25633
25606
  }
25634
25607
  return lineCount;
@@ -25678,7 +25651,6 @@ var TextComponentBase = /*#__PURE__*/ function() {
25678
25651
  return;
25679
25652
  }
25680
25653
  this.text = value.toString();
25681
- this.lineCount = this.getLineCount(value, false);
25682
25654
  this.isDirty = true;
25683
25655
  };
25684
25656
  /**
@@ -25760,6 +25732,18 @@ var TextComponentBase = /*#__PURE__*/ function() {
25760
25732
  this.isDirty = true;
25761
25733
  };
25762
25734
  /**
25735
+ * 设置文本溢出模式
25736
+ *
25737
+ * - clip: 当文本内容超出边界框时,多余的会被截断。
25738
+ * - display: 该模式下会显示所有文本,会自动调整文本字号以保证显示完整。
25739
+ * > 当存在多行时,部分行内文本可能存在文本字号变小的情况,其他行为正常情况
25740
+ *
25741
+ * @param overflow - 文本溢出模式
25742
+ */ _proto.setOverflow = function setOverflow(overflow) {
25743
+ this.textLayout.overflow = overflow;
25744
+ this.isDirty = true;
25745
+ };
25746
+ /**
25763
25747
  * 设置阴影颜色
25764
25748
  * @param value - 阴影颜色
25765
25749
  * @returns
@@ -25827,28 +25811,35 @@ var TextComponentBase = /*#__PURE__*/ function() {
25827
25811
  var layout = this.textLayout;
25828
25812
  var fontScale = style.fontScale;
25829
25813
  var width = (layout.width + style.fontOffset) * fontScale;
25830
- var finalHeight = layout.lineHeight * this.lineCount;
25831
25814
  var fontSize = style.fontSize * fontScale;
25832
25815
  var lineHeight = layout.lineHeight * fontScale;
25816
+ style.fontDesc = this.getFontDesc(fontSize);
25833
25817
  this.char = (this.text || "").split("");
25834
25818
  this.canvas.width = width;
25819
+ var height = this.canvas.height;
25820
+ context.font = style.fontDesc;
25821
+ this.lineCount = this.getLineCount(this.text, context);
25822
+ var finalHeight = layout.lineHeight * this.lineCount;
25835
25823
  if (layout.autoWidth) {
25836
25824
  this.canvas.height = finalHeight * fontScale;
25837
25825
  this.item.transform.size.set(1, finalHeight / layout.height);
25838
25826
  } else {
25839
25827
  this.canvas.height = layout.height * fontScale;
25840
25828
  }
25841
- var height = this.canvas.height;
25842
- context.clearRect(0, 0, width, height);
25829
+ // canvas size 变化后重新刷新 context
25830
+ if (this.maxLineWidth > width && layout.overflow === TextOverflow.display) {
25831
+ context.font = this.getFontDesc(fontSize * width / this.maxLineWidth);
25832
+ } else {
25833
+ context.font = style.fontDesc;
25834
+ }
25843
25835
  // fix bug 1/255
25844
25836
  context.fillStyle = "rgba(255, 255, 255, 0.0039)";
25837
+ context.clearRect(0, 0, width, height);
25845
25838
  if (!flipY) {
25846
25839
  context.translate(0, height);
25847
25840
  context.scale(1, -1);
25848
25841
  }
25849
25842
  context.fillRect(0, 0, width, height);
25850
- style.fontDesc = this.getFontDesc();
25851
- context.font = style.fontDesc;
25852
25843
  if (style.hasShadow) {
25853
25844
  this.setupShadow();
25854
25845
  }
@@ -25920,9 +25911,9 @@ var TextComponentBase = /*#__PURE__*/ function() {
25920
25911
  this.material.setTexture("_MainTex", texture);
25921
25912
  this.isDirty = false;
25922
25913
  };
25923
- _proto.getFontDesc = function getFontDesc() {
25924
- 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;
25925
- var fontDesc = "" + (fontSize * fontScale).toString() + "px ";
25914
+ _proto.getFontDesc = function getFontDesc(fontSize) {
25915
+ var _this_textStyle = this.textStyle, fontFamily = _this_textStyle.fontFamily, textWeight = _this_textStyle.textWeight, fontStyle = _this_textStyle.fontStyle;
25916
+ var fontDesc = "" + fontSize.toString() + "px ";
25926
25917
  if (!DEFAULT_FONTS.includes(fontFamily)) {
25927
25918
  fontDesc += '"' + fontFamily + '"';
25928
25919
  } else {
@@ -26692,12 +26683,29 @@ function getStandardInteractContent(ui) {
26692
26683
  * 3.1 版本数据适配
26693
26684
  * - 富文本插件名称的适配
26694
26685
  */ function version31Migration(json) {
26695
- var _json_plugins;
26686
+ var // 修正老版本数据中,富文本插件名称的问题
26687
+ _json_plugins;
26696
26688
  (_json_plugins = json.plugins) == null ? void 0 : _json_plugins.forEach(function(plugin, index) {
26697
26689
  if (plugin === "richtext") {
26698
26690
  json.plugins[index] = "rich-text";
26699
26691
  }
26700
26692
  });
26693
+ // Custom shape fill 属性位置迁移
26694
+ for(var _iterator = _create_for_of_iterator_helper_loose(json.components), _step; !(_step = _iterator()).done;){
26695
+ var component = _step.value;
26696
+ if (component.dataType === DataType.ShapeComponent) {
26697
+ var shapeComponent = component;
26698
+ if (shapeComponent.type === ShapePrimitiveType.Custom) {
26699
+ var _customShapeComponent_shapes;
26700
+ var customShapeComponent = shapeComponent;
26701
+ //@ts-expect-error
26702
+ if (((_customShapeComponent_shapes = customShapeComponent.shapes) == null ? void 0 : _customShapeComponent_shapes.length) > 0 && customShapeComponent.shapes[0].fill) {
26703
+ // @ts-expect-error
26704
+ customShapeComponent.fill = customShapeComponent.shapes[0].fill;
26705
+ }
26706
+ }
26707
+ }
26708
+ }
26701
26709
  return json;
26702
26710
  }
26703
26711
  /**
@@ -27527,8 +27535,6 @@ function getStandardJSON(json) {
27527
27535
  }
27528
27536
  // 修正老版本数据中,meshItem 以及 lightItem 结束行为错误问题
27529
27537
  version22Migration(json);
27530
- // 修正老版本数据中,富文本插件名称的问题
27531
- version31Migration(json);
27532
27538
  if (v0.test(json.version)) {
27533
27539
  var _exec;
27534
27540
  reverseParticle = ((_exec = /^(\d+)/.exec(json.version)) == null ? void 0 : _exec[0]) === "0";
@@ -27543,7 +27549,13 @@ function getStandardJSON(json) {
27543
27549
  json = version24Migration(json);
27544
27550
  }
27545
27551
  if (mainVersion < 3) {
27546
- return version30Migration(version21Migration(json));
27552
+ json = version30Migration(version21Migration(json));
27553
+ }
27554
+ // 3.x 版本格式转换
27555
+ if (mainVersion < 4) {
27556
+ if (minorVersion < 2) {
27557
+ json = version31Migration(json);
27558
+ }
27547
27559
  }
27548
27560
  return json;
27549
27561
  }
@@ -27599,13 +27611,11 @@ function getStandardJSONFromV0(json) {
27599
27611
  }
27600
27612
  function getStandardImage(image, index, imageTags) {
27601
27613
  var renderLevel = imageTags[index];
27602
- var oriY = image.oriY;
27603
27614
  if (typeof image === "string") {
27604
27615
  return {
27605
27616
  id: generateGUID(),
27606
27617
  renderLevel: renderLevel,
27607
- url: image,
27608
- oriY: oriY
27618
+ url: image
27609
27619
  };
27610
27620
  } else if (image.template) {
27611
27621
  return {
@@ -27613,14 +27623,12 @@ function getStandardImage(image, index, imageTags) {
27613
27623
  url: image.url,
27614
27624
  template: image.template,
27615
27625
  webp: image.webp,
27616
- renderLevel: renderLevel,
27617
- oriY: oriY
27626
+ renderLevel: renderLevel
27618
27627
  };
27619
27628
  } else if (image.compressed) {
27620
27629
  return {
27621
27630
  id: generateGUID(),
27622
27631
  url: image.url,
27623
- oriY: oriY,
27624
27632
  compressed: {
27625
27633
  astc: image.compressed.android,
27626
27634
  pvrtc: image.compressed.iOS
@@ -27633,8 +27641,7 @@ function getStandardImage(image, index, imageTags) {
27633
27641
  id: generateGUID(),
27634
27642
  url: image.url,
27635
27643
  webp: image.webp,
27636
- renderLevel: renderLevel,
27637
- oriY: oriY
27644
+ renderLevel: renderLevel
27638
27645
  };
27639
27646
  } else if (image && image.sourceType) {
27640
27647
  return image;
@@ -32076,7 +32083,7 @@ registerPlugin("sprite", SpriteLoader, VFXItem, true);
32076
32083
  registerPlugin("particle", ParticleLoader, VFXItem, true);
32077
32084
  registerPlugin("cal", CalculateLoader, VFXItem, true);
32078
32085
  registerPlugin("interact", InteractLoader, VFXItem, true);
32079
- var version$1 = "2.3.0-alpha.1";
32086
+ var version$1 = "2.3.0-alpha.2";
32080
32087
  logger.info("Core version: " + version$1 + ".");
32081
32088
 
32082
32089
  var _obj;
@@ -33709,7 +33716,7 @@ setMaxSpriteMeshItemCount(8);
33709
33716
  */ Mesh.create = function(engine, props) {
33710
33717
  return new ThreeMesh(engine, props);
33711
33718
  };
33712
- var version = "2.3.0-alpha.1";
33719
+ var version = "2.3.0-alpha.2";
33713
33720
  logger.info("THREEJS plugin version: " + version + ".");
33714
33721
 
33715
33722
  export { AbstractPlugin, ActivationPlayable, ActivationPlayableAsset, ActivationTrack, AnimationClip, AnimationClipPlayable, Asset, AssetLoader, AssetManager, BYTES_TYPE_MAP, BaseRenderComponent, Behaviour, BezierCurve, BezierCurvePath, BezierCurveQuat, BinaryAsset, COMPRESSED_TEXTURE, CONSTANT_MAP_BLEND, CONSTANT_MAP_DEPTH, CONSTANT_MAP_STENCIL_FUNC, CONSTANT_MAP_STENCIL_OP, COPY_FRAGMENT_SHADER, COPY_MESH_SHADER_ID, COPY_VERTEX_SHADER, CalculateLoader, Camera, CameraController, CameraVFXItemLoader, ColorCurve, ColorPropertyPlayableAsset, ColorPropertyTrack, Component, Composition, CompositionComponent, CompositionSourceManager, DEFAULT_FONTS, DEFAULT_FPS, Database, DestroyOptions, Downloader, EFFECTS_COPY_MESH_NAME, EVENT_TYPE_CLICK, EVENT_TYPE_TOUCH_END, EVENT_TYPE_TOUCH_MOVE, EVENT_TYPE_TOUCH_START, EffectComponent, EffectsObject, EffectsPackage, Engine, EventEmitter, EventSystem, Fake3DAnimationMode, Fake3DComponent, FilterMode, Float16ArrayWrapper, FloatPropertyPlayableAsset, FloatPropertyTrack, Framebuffer, GLSLVersion, GPUCapability, Geometry, GlobalUniforms, GradientValue, HELP_LINK, HitTestType, InteractComponent, InteractLoader, InteractMesh, Item, KTXTexture, LineSegments, LinearValue, Material, MaterialDataBlock, MaterialRenderType, MaterialTrack, Mesh, MeshCollider, ObjectBindingTrack, OrderType, PLAYER_OPTIONS_ENV_EDITOR, POST_PROCESS_SETTINGS, ParticleBehaviourPlayable, ParticleBehaviourPlayableAsset, ParticleLoader, ParticleMesh, ParticleSystem, ParticleSystemRenderer, ParticleTrack, PassTextureCache, PathSegments, PluginSystem, PostProcessVolume, PropertyTrack, RENDER_PASS_NAME_PREFIX, RENDER_PREFER_LOOKUP_TEXTURE, RUNTIME_ENV, RandomSetValue, RandomValue, RandomVectorValue, RenderFrame, RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, RenderTargetHandle, RenderTextureFormat, Renderbuffer, Renderer, RendererComponent, RuntimeClip, SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_0, SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_SIZE_0, SEMANTIC_PRE_COLOR_ATTACHMENT_0, SEMANTIC_PRE_COLOR_ATTACHMENT_SIZE_0, SPRITE_VERTEX_STRIDE, Scene, SemanticMap, SerializationHelper, Shader, ShaderCompileResultStatus, ShaderFactory, ShaderType, ShaderVariant, ShapeComponent, SpriteColorPlayableAsset, SpriteColorTrack, SpriteComponent, SpriteLoader, StaticValue, SubCompositionPlayableAsset, SubCompositionTrack, TEMPLATE_USE_OFFSCREEN_CANVAS, TEXTURE_UNIFORM_MAP, TextComponent, TextComponentBase, TextLayout, TextLoader, TextStyle, Texture, TextureFactory, TextureLoadAction, TextureSourceType, TextureStoreAction, ThreeComposition, ThreeDisplayObject, ThreeEngine, ThreeMaterial, ThreeSpriteComponent, ThreeTextComponent, ThreeTexture, Ticker, TimelineAsset, TimelineClip, TimelinePlayable, TrackAsset, TrackSortWrapper, TrackType, Transform, TransformAnimationPlayable, TransformPlayableAsset, TransformTrack, VFXItem, ValueGetter, Vector2Curve, Vector2PropertyPlayableAsset, Vector2PropertyTrack, Vector4Curve, Vector4PropertyPlayableAsset, Vector4PropertyTrack, addByOrder, addItem, addItemWithOrder, applyMixins, assertExist, asserts, base64ToFile, blend, calculateTranslation, canvasPool, colorGradingFrag, colorStopsFromGradient, colorToArr$1 as colorToArr, combineImageTemplate, createCopyShader, createGLContext, createKeyFrameMeta, createShape, createValueGetter, decimalEqual, defaultPlugins, deserializeMipmapTexture, earcut, effectsClass, effectsClassStore, enlargeBuffer, ensureFixedNumber, ensureVec3, findPreviousRenderPass, gaussianDown_frag as gaussianDownFrag, gaussianDownHFrag, gaussianDownVFrag, gaussianUpFrag, generateEmptyTypedArray, generateGUID, generateHalfFloatTexture, generateTransparentTexture, generateWhiteTexture, getBackgroundImage, getColorFromGradientStops, getConfig, getDefaultTextureFactory, getGeometryByShape, getGeometryTriangles, getImageItemRenderInfo, getKTXTextureOptions, getKeyFrameMetaByRawValue, getMergedStore, getParticleMeshShader, getPixelRatio, getPreMultiAlpha, getStandardComposition, getStandardImage, getStandardItem, getStandardJSON, getTextureSize, glContext, glType2VertexFormatType, gpuTimer, imageDataFromColor, imageDataFromGradient, initErrors, initGLContext, integrate, interpolateColor, isAlipayMiniApp, isAndroid, isArray, isCanvas, isFunction, isIOS, isIOSByUA, isMiniProgram, isObject, isSimulatorCellPhone, isString, isUniformStruct, isUniformStructArray, isValidFontFamily, isWebGL2, isWechatMiniApp, itemFrag, itemFrameFrag, itemVert, loadAVIFOptional, loadBinary, loadBlob, loadImage, loadMedia, loadVideo, loadWebPOptional, logger, index as math, maxSpriteMeshItemCount, modifyMaxKeyframeShader, nearestPowerOfTwo, noop, normalizeColor, numberToFix, parsePercent$1 as parsePercent, particleFrag, particleOriginTranslateMap$1 as particleOriginTranslateMap, particleUniformTypeMap, particleVert, passRenderLevel, pluginLoaderMap, randomInRange, registerPlugin, removeItem, rotateVec2, screenMeshVert, serialize, setBlendMode, setConfig, setDefaultTextureFactory, setMaskMode, setMaxSpriteMeshItemCount, setRayFromCamera, setSideMode, setSpriteMeshMaxItemCountByGPU, setUniformValue, sortByOrder, index$1 as spec, spriteMeshShaderFromFilter, spriteMeshShaderFromRenderInfo, spriteMeshShaderIdFromRenderInfo, thresholdFrag, throwDestroyedError, trailVert, translatePoint, trianglesFromRect, unregisterPlugin, valIfUndefined, value, valueDefine, vecFill, vecMulCombine, version, vertexFormatType2GLType };