@galacean/effects-core 2.9.1 → 2.10.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas-pool.d.ts +58 -3
- package/dist/components/canvas-item.d.ts +131 -0
- package/dist/components/canvas-layer.d.ts +23 -0
- package/dist/components/control.d.ts +18 -0
- package/dist/components/index.d.ts +3 -1
- package/dist/composition.d.ts +12 -3
- package/dist/engine.d.ts +6 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11231 -8952
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11220 -8951
- package/dist/index.mjs.map +1 -1
- package/dist/math/index.d.ts +3 -2
- package/dist/math/shape/build-adaptive-bezier.d.ts +1 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/shape/contour-measure.d.ts +43 -0
- package/dist/plugins/shape/contour-path-utils.d.ts +10 -0
- package/dist/plugins/shape/contour-path.d.ts +20 -0
- package/dist/{math → plugins}/shape/graphics-path.d.ts +1 -1
- package/dist/plugins/shape/index.d.ts +2 -0
- package/dist/{components → plugins/shape}/shape-component.d.ts +13 -7
- package/dist/{math → plugins}/shape/shape-path.d.ts +3 -3
- package/dist/plugins/shape/trim-path.d.ts +25 -0
- package/dist/plugins/text/text-component-base.d.ts +1 -0
- package/dist/rect-transform.d.ts +145 -0
- package/dist/render/graphics.d.ts +127 -51
- package/dist/render/index.d.ts +1 -0
- package/dist/render/text-cache.d.ts +109 -0
- package/dist/transform.d.ts +14 -3
- package/package.json +1 -1
package/dist/math/index.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ export * from './translate';
|
|
|
3
3
|
export * from './utils';
|
|
4
4
|
export * from './value-getters';
|
|
5
5
|
export * from './shape/build-line';
|
|
6
|
-
export * from './shape/graphics-path';
|
|
7
6
|
export * from './shape/ellipse';
|
|
7
|
+
export * from './shape/rectangle';
|
|
8
|
+
export * from './shape/triangle';
|
|
8
9
|
export * from './shape/poly-star';
|
|
10
|
+
export * from './shape/circle';
|
|
9
11
|
export * from './shape/polygon';
|
|
10
|
-
export * from './shape/shape-path';
|
|
11
12
|
export * from './bezier';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function buildAdaptiveBezier(points: number[], sX: number, sY: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, eX: number, eY: number, smoothness?: number, scale?: number): number[];
|
|
1
|
+
export declare function buildAdaptiveBezier(points: number[], sX: number, sY: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, eX: number, eY: number, smoothness?: number, scale?: number, tValues?: number[]): number[];
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Vector2 } from '@galacean/effects-math/es/core/vector2';
|
|
2
|
+
import type { GraphicsPath } from './graphics-path';
|
|
3
|
+
export type ContourMeasureSegmentType = 'line' | 'cubic';
|
|
4
|
+
export type ContourMeasureSegment = {
|
|
5
|
+
distance: number;
|
|
6
|
+
pointIndex: number;
|
|
7
|
+
tValue: number;
|
|
8
|
+
type: ContourMeasureSegmentType;
|
|
9
|
+
smoothness?: number;
|
|
10
|
+
scale?: number;
|
|
11
|
+
};
|
|
12
|
+
export type ContourMeasurePosTan = {
|
|
13
|
+
pos: Vector2;
|
|
14
|
+
tan: Vector2;
|
|
15
|
+
};
|
|
16
|
+
export declare class ContourMeasure {
|
|
17
|
+
private readonly segments;
|
|
18
|
+
private readonly points;
|
|
19
|
+
private readonly contourLength;
|
|
20
|
+
private readonly contourClosed;
|
|
21
|
+
constructor(segments: ContourMeasureSegment[], points: Vector2[], contourLength: number, contourClosed: boolean);
|
|
22
|
+
length(): number;
|
|
23
|
+
isClosed(): boolean;
|
|
24
|
+
getPosTan(distance: number): ContourMeasurePosTan;
|
|
25
|
+
getSegment(startDistance: number, endDistance: number, destination: GraphicsPath, startWithMove: boolean): void;
|
|
26
|
+
warp(source: Vector2): Vector2;
|
|
27
|
+
dump(): void;
|
|
28
|
+
private findSegment;
|
|
29
|
+
private computeT;
|
|
30
|
+
private extractWholeSegment;
|
|
31
|
+
private extractSegment;
|
|
32
|
+
}
|
|
33
|
+
export declare class ContourMeasureIter {
|
|
34
|
+
static readonly defaultTolerance = 0.5;
|
|
35
|
+
private contourPath;
|
|
36
|
+
private cursor;
|
|
37
|
+
private screenScale;
|
|
38
|
+
constructor(source: GraphicsPath, screenScale?: number);
|
|
39
|
+
rewind(source: GraphicsPath, screenScale?: number): void;
|
|
40
|
+
private tryNext;
|
|
41
|
+
next(): ContourMeasure | null;
|
|
42
|
+
toArray(): ContourMeasure[];
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Vector2 } from '@galacean/effects-math/es/core/vector2';
|
|
2
|
+
export declare function clampNumber(value: number, min: number, max: number): number;
|
|
3
|
+
export declare function lerpNumber(start: number, end: number, t: number): number;
|
|
4
|
+
export declare function pointsEqual(left: Vector2, right: Vector2): boolean;
|
|
5
|
+
export declare function clonePoint(point: Vector2): Vector2;
|
|
6
|
+
export declare function normalizeVector2(x: number, y: number): Vector2;
|
|
7
|
+
export declare function cubicPointAt(points: readonly Vector2[], t: number): Vector2;
|
|
8
|
+
export declare function lineExtract(points: readonly Vector2[], startT: number, endT: number): [Vector2, Vector2];
|
|
9
|
+
export declare function cubicSubdivide(points: readonly Vector2[], t: number): [Vector2[], Vector2[]];
|
|
10
|
+
export declare function cubicExtract(points: readonly Vector2[], startT: number, endT: number): Vector2[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Vector2 } from '@galacean/effects-math/es/core/vector2';
|
|
2
|
+
import type { GraphicsPath } from './graphics-path';
|
|
3
|
+
import type { ShapePath } from './shape-path';
|
|
4
|
+
export type ContourPathCommand = {
|
|
5
|
+
action: 'moveTo';
|
|
6
|
+
data: [Vector2];
|
|
7
|
+
} | {
|
|
8
|
+
action: 'lineTo';
|
|
9
|
+
data: [Vector2];
|
|
10
|
+
} | {
|
|
11
|
+
action: 'bezierCurveTo';
|
|
12
|
+
data: [Vector2, Vector2, Vector2];
|
|
13
|
+
smoothness?: number;
|
|
14
|
+
scale?: number;
|
|
15
|
+
} | {
|
|
16
|
+
action: 'closePath';
|
|
17
|
+
data: [];
|
|
18
|
+
};
|
|
19
|
+
export declare function tryMakeContourPathFromGraphicsPath(source: GraphicsPath): ContourPathCommand[] | null;
|
|
20
|
+
export declare function makeContourPathFromShapePath(shapePath: ShapePath, screenScale: number): ContourPathCommand[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Matrix4 } from '@galacean/effects-math/es/core/matrix4';
|
|
2
2
|
import { ShapePath } from './shape-path';
|
|
3
|
-
import type { StarType } from '
|
|
3
|
+
import type { StarType } from '../../math';
|
|
4
4
|
export declare class GraphicsPath {
|
|
5
5
|
instructions: PathInstruction[];
|
|
6
6
|
private dirty;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Color } from '@galacean/effects-math/es/core/color';
|
|
2
2
|
import { Vector2 } from '@galacean/effects-math/es/core/vector2';
|
|
3
3
|
import * as spec from '@galacean/effects-specification';
|
|
4
|
-
import type { Engine } from '
|
|
5
|
-
import type { Maskable } from '
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
4
|
+
import type { Engine } from '../../engine';
|
|
5
|
+
import type { Maskable } from '../../material';
|
|
6
|
+
import type { Renderer } from '../../render';
|
|
7
|
+
import type { GradientValue } from '../../math';
|
|
8
|
+
import { RendererComponent } from '../../components';
|
|
9
|
+
import type { Texture } from '../../texture/texture';
|
|
10
|
+
import { TrimPath } from './trim-path';
|
|
11
|
+
import type { BoundingBoxInfo } from '../interact/mesh-collider';
|
|
12
|
+
import type { BoundingBoxTriangle, HitTestTriangleParams } from '../interact/click-handler';
|
|
11
13
|
export interface SolidPaint {
|
|
12
14
|
type: spec.FillType.Solid;
|
|
13
15
|
color: Color;
|
|
@@ -134,11 +136,15 @@ export declare class ShapeComponent extends RendererComponent implements Maskabl
|
|
|
134
136
|
private strokeJoin;
|
|
135
137
|
private strokes;
|
|
136
138
|
private shapeAttributes;
|
|
139
|
+
private _strokeTrimPath;
|
|
140
|
+
private _fillTrimPath;
|
|
137
141
|
private rendererOptions;
|
|
138
142
|
private geometry;
|
|
139
143
|
private fillMaterials;
|
|
140
144
|
private strokeMaterials;
|
|
141
145
|
get shape(): ShapeAttributes;
|
|
146
|
+
get strokeTrimPath(): TrimPath | null;
|
|
147
|
+
get fillTrimPath(): TrimPath | null;
|
|
142
148
|
/**
|
|
143
149
|
*
|
|
144
150
|
* @param engine
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Matrix4 } from '@galacean/effects-math/es/core/matrix4';
|
|
2
|
-
import { Polygon } from './polygon';
|
|
3
2
|
import type { GraphicsPath } from './graphics-path';
|
|
4
|
-
import type { ShapePrimitive } from '
|
|
5
|
-
import type { StarType } from '
|
|
3
|
+
import type { ShapePrimitive } from '../../math/shape/shape-primitive';
|
|
4
|
+
import type { StarType } from '../../math';
|
|
5
|
+
import { Polygon } from '../../math';
|
|
6
6
|
export declare class ShapePath {
|
|
7
7
|
private graphicsPath;
|
|
8
8
|
currentPoly: Polygon | null;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { GraphicsPath } from './graphics-path';
|
|
2
|
+
export interface TrimPathData {
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
offset: number;
|
|
6
|
+
mode: TrimPathMode;
|
|
7
|
+
}
|
|
8
|
+
export declare enum TrimPathMode {
|
|
9
|
+
Synchronized = 0,
|
|
10
|
+
Sequential = 1
|
|
11
|
+
}
|
|
12
|
+
export declare class TrimPath {
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
offset: number;
|
|
16
|
+
mode: TrimPathMode;
|
|
17
|
+
private trimmedGraphicsPath;
|
|
18
|
+
clone(): TrimPath;
|
|
19
|
+
createTrimmedPath(source: GraphicsPath, screenScale: number): GraphicsPath;
|
|
20
|
+
isIdentity(): boolean;
|
|
21
|
+
fromData(data: TrimPathData): void;
|
|
22
|
+
private normalizeTrimOffset;
|
|
23
|
+
private applySequentialTrimPath;
|
|
24
|
+
private applySynchronizedTrimPath;
|
|
25
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Vector2 } from '@galacean/effects-math/es/core/vector2';
|
|
2
|
+
import type * as spec from '@galacean/effects-specification';
|
|
3
|
+
import { Transform } from './transform';
|
|
4
|
+
/**
|
|
5
|
+
* 2D 矩形,`position` 为左下角(Y 向上),`size` 为宽高
|
|
6
|
+
*/
|
|
7
|
+
export type Rect = {
|
|
8
|
+
position: Vector2;
|
|
9
|
+
size: Vector2;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* 16 个内建锚点预设,字面意义对应屏幕视觉位置(Y 向上)
|
|
13
|
+
*/
|
|
14
|
+
export type LayoutPreset = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'centerLeft' | 'centerTop' | 'centerRight' | 'centerBottom' | 'center' | 'leftWide' | 'topWide' | 'rightWide' | 'bottomWide' | 'vcenterWide' | 'hcenterWide' | 'fullRect';
|
|
15
|
+
/**
|
|
16
|
+
* 锚点布局变换。`RectTransform extends Transform`,在 Transform 的 position/rotation/scale/size/anchor(=pivot 偏移)
|
|
17
|
+
* 之上额外维护 4 边锚点 + 4 边像素偏移,提供 rect 解算与编辑 API。
|
|
18
|
+
*
|
|
19
|
+
* 解算公式(Y 向上,父 vertex 坐标原点 = 父 rect 左下角):
|
|
20
|
+
* ```
|
|
21
|
+
* left = offsetMin.x + anchorMin.x * parentSize.x
|
|
22
|
+
* bottom = offsetMin.y + anchorMin.y * parentSize.y
|
|
23
|
+
* right = offsetMax.x + anchorMax.x * parentSize.x
|
|
24
|
+
* top = offsetMax.y + anchorMax.y * parentSize.y
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* 写回 Transform:
|
|
28
|
+
* - `position` ← `(left, bottom)`(rect 左下角,父 vertex 坐标)
|
|
29
|
+
* - `size` ← rect 尺寸
|
|
30
|
+
* - `anchor`(Vector3 像素 pivot 偏移)由用户独立设置,仅作旋转/缩放中心
|
|
31
|
+
*
|
|
32
|
+
* **解算入口** 是 `sizeChanged()` 方法:
|
|
33
|
+
* - 父是 RectTransform → 用 `parent.size` 作 parentSize 解算自身,写回 `position` / `size`
|
|
34
|
+
* - 否则(顶层 / 没父):自身 size 视为权威值(由外部 — 通常是 CanvasLayer — 直接写),不再自解算
|
|
35
|
+
* - 末尾遍历 `children` 中的 RectTransform,直接调它们的 `sizeChanged()`,链式向下传播
|
|
36
|
+
*
|
|
37
|
+
* **重写 `setPosition` / `setSize`** 让其语义变为"用户输入 rect 位置 / 尺寸":
|
|
38
|
+
* - 顶层(无 RectTransform 父):直接写 `super.setPosition / super.setSize`,然后 `sizeChanged` 传播给子节点
|
|
39
|
+
* - 否则:反推 offset 维持当前 anchor,然后 `sizeChanged` 重算并向下传
|
|
40
|
+
*/
|
|
41
|
+
export declare class RectTransform extends Transform {
|
|
42
|
+
/**
|
|
43
|
+
* 父 rect 上的归一化最小角 `(anchorLeft, anchorBottom)`
|
|
44
|
+
*/
|
|
45
|
+
readonly anchorMin: Vector2;
|
|
46
|
+
/**
|
|
47
|
+
* 父 rect 上的归一化最大角 `(anchorRight, anchorTop)`
|
|
48
|
+
*/
|
|
49
|
+
readonly anchorMax: Vector2;
|
|
50
|
+
/**
|
|
51
|
+
* rect 左/下边相对 anchorMin 锚点的像素偏移 `(offsetLeft, offsetBottom)`
|
|
52
|
+
*/
|
|
53
|
+
readonly offsetMin: Vector2;
|
|
54
|
+
/**
|
|
55
|
+
* rect 右/上边相对 anchorMax 锚点的像素偏移 `(offsetRight, offsetTop)`
|
|
56
|
+
*/
|
|
57
|
+
readonly offsetMax: Vector2;
|
|
58
|
+
/**
|
|
59
|
+
* 自身 rect 上的归一化轴心 `(0..1)`,默认 `(0.5, 0.5)`(中心)。两层效果:
|
|
60
|
+
* 1. **Layout**:`setSize` 时 rect 围绕此点对称缩放(pivot=(0.5, 0.5) → 居中扩展;pivot=(0, 0) → 从左下扩展;pivot=(1, 1) → 向左下缩)
|
|
61
|
+
* 2. **矩阵**:`pivot` 自动同步到 `transform.anchor = pivot * size`(像素值,矩阵旋转/缩放中心),
|
|
62
|
+
* 所以旋转/缩放也围绕同一点。`setPivot` 和每次 `sizeChanged`(size 重算后)都会刷新 `transform.anchor`
|
|
63
|
+
*/
|
|
64
|
+
readonly pivot: Vector2;
|
|
65
|
+
/**
|
|
66
|
+
* 用既有 Transform 的状态创建 RectTransform。
|
|
67
|
+
* 用于 Control / CanvasLayer 接管 VFXItem 时,把 VFXItem 自带的 Transform 升级为 RectTransform 而不丢失 position/rotation/scale 等已设置好的状态。
|
|
68
|
+
*/
|
|
69
|
+
static fromTransform(t: Transform): RectTransform;
|
|
70
|
+
/**
|
|
71
|
+
* 反序列化:在 `Transform.fromData` 基础上还原 RectTransform 特有的 `pivot` /
|
|
72
|
+
* `anchorMin` / `anchorMax` / `offsetMin` / `offsetMax`。
|
|
73
|
+
*
|
|
74
|
+
* 顺序:
|
|
75
|
+
* 1. `super.fromData` 还原 `position` / `rotation` / `scale` / `size` / `anchor`
|
|
76
|
+
* 2. 若数据有 size,从 `anchor / size` 反推 `pivot`,保持 `anchor = pivot * size` 一致
|
|
77
|
+
* 3. 应用 `anchorMin/Max` / `offsetMin/Max`,每个 setter 末尾会触发 `sizeChanged`
|
|
78
|
+
* 重新解算 rect 与同步 `transform.anchor`
|
|
79
|
+
*/
|
|
80
|
+
fromData(data: spec.TransformData): void;
|
|
81
|
+
setAnchorMin(x: number, y: number): void;
|
|
82
|
+
setAnchorMax(x: number, y: number): void;
|
|
83
|
+
setOffsetMin(x: number, y: number): void;
|
|
84
|
+
setOffsetMax(x: number, y: number): void;
|
|
85
|
+
/**
|
|
86
|
+
* 设置 rect 内的归一化轴心 `(0..1)`,同时把 `transform.anchor`(矩阵旋转/缩放中心)同步到 `pivot * size`。
|
|
87
|
+
* 不重算 rect(pivot 只决定 setSize 行为,不直接影响当前 rect 位置 / 尺寸)
|
|
88
|
+
*/
|
|
89
|
+
setPivot(x: number, y: number): void;
|
|
90
|
+
/**
|
|
91
|
+
* 重写父类 `setPosition`:
|
|
92
|
+
* - 顶层(无 RectTransform 父):直接 `super.setPosition` 写位置,触发 `sizeChanged` 传播
|
|
93
|
+
* - 非顶层:语义为"设置 rect 左下角到 (x, y)",反推 offset 维持当前 anchor,然后 `sizeChanged` 重算
|
|
94
|
+
*
|
|
95
|
+
* @param keepOffsets - 默认 false。true 时反推 anchor 而非 offset(rect 在屏幕上不动,但 anchor 比例改变)
|
|
96
|
+
*/
|
|
97
|
+
setPosition(x: number, y: number, z: number, keepOffsets?: boolean): void;
|
|
98
|
+
/**
|
|
99
|
+
* 重写父类 `setSize`:
|
|
100
|
+
* - 顶层:直接 `super.setSize`,触发 `sizeChanged` 传播
|
|
101
|
+
* - 非顶层:反推 offset 维持当前 anchor,然后 `sizeChanged` 重算
|
|
102
|
+
*/
|
|
103
|
+
setSize(x: number, y: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* 当前自身 rect(在父 vertex 坐标下,Y 向上)。`sizeChanged` 之后才有意义
|
|
106
|
+
*/
|
|
107
|
+
getRect(): Rect;
|
|
108
|
+
private onCanvasResize;
|
|
109
|
+
/**
|
|
110
|
+
* 解算入口:
|
|
111
|
+
*
|
|
112
|
+
* 1. 父是 RectTransform → 从 `parent.size` 求自身 rect,通过 `super.setPosition / super.setSize` 写回
|
|
113
|
+
* (避免触发本类 setPosition / setSize 重写)
|
|
114
|
+
* 2. 顶层(无 RectTransform 父):自身 size 视为权威值(由 CanvasLayer 等外部直接写),不自解算
|
|
115
|
+
* 3. 遍历 `children` 中所有 RectTransform 子节点,直接调它们的 `sizeChanged()` 链式传播
|
|
116
|
+
*/
|
|
117
|
+
sizeChanged(): void;
|
|
118
|
+
/**
|
|
119
|
+
* 给定目标 rect 反推 offsetMin/Max,保持当前 anchor 不变
|
|
120
|
+
*/
|
|
121
|
+
private computeOffsets;
|
|
122
|
+
/**
|
|
123
|
+
* 给定目标 rect 反推 anchorMin/Max,保持当前 offset 不变。父 size 为 0 的方向不修改
|
|
124
|
+
*/
|
|
125
|
+
private computeAnchors;
|
|
126
|
+
/**
|
|
127
|
+
* 把 anchorMin/Max 设为内建预设。
|
|
128
|
+
* @param keepOffsets - 默认 true:offset 不动,rect 实际位置会跳到新 anchor 计算的位置(要求保留视觉位置请用 setAnchorsAndOffsetsPreset)
|
|
129
|
+
*/
|
|
130
|
+
setAnchorsPreset(preset: LayoutPreset, keepOffsets?: boolean): void;
|
|
131
|
+
/**
|
|
132
|
+
* 把 offsetMin/Max 设为预设值,使 rect 在父 rect 内落在视觉上对应的位置(留 margin 像素边距)。
|
|
133
|
+
* 当 anchor 已经按相同 preset 设定时,等价于“贴边放置带 margin 的 rect”。
|
|
134
|
+
* 使用当前 size 作为 rect 尺寸。
|
|
135
|
+
*/
|
|
136
|
+
setOffsetsPreset(preset: LayoutPreset, margin?: number): void;
|
|
137
|
+
/**
|
|
138
|
+
* 同时设置 anchor 和 offset,达到“按 preset 摆放并贴边带 margin”的效果。
|
|
139
|
+
*
|
|
140
|
+
* 注意第一步用 `keepOffsets=false`(反推 offset 维持 rect 视觉位置),不能用默认 `true`:
|
|
141
|
+
* 后者会让 rect 的 size 在中间步先跳到错值(因为 anchor 改了 offset 没改),
|
|
142
|
+
* 第二步 `setOffsetsPreset` 又用这个错 size 算 offset,最终 rect size 不对
|
|
143
|
+
*/
|
|
144
|
+
setAnchorsAndOffsetsPreset(preset: LayoutPreset, margin?: number): void;
|
|
145
|
+
}
|
|
@@ -1,15 +1,37 @@
|
|
|
1
1
|
import { Color } from '@galacean/effects-math/es/core/color';
|
|
2
2
|
import { Matrix3 } from '@galacean/effects-math/es/core/matrix3';
|
|
3
3
|
import type { Engine } from '../engine';
|
|
4
|
+
import type { Texture } from '../texture';
|
|
5
|
+
import type { FontStyle, FontWeight } from './text-cache';
|
|
6
|
+
/**
|
|
7
|
+
* 纹理 UV 子矩形(Y 向上,Y=0 在底部)。 全图为 `{u0:0, v0:0, u1:1, v1:1}`
|
|
8
|
+
*/
|
|
9
|
+
export type TextureRegion = {
|
|
10
|
+
u0: number;
|
|
11
|
+
v0: number;
|
|
12
|
+
u1: number;
|
|
13
|
+
v1: number;
|
|
14
|
+
};
|
|
4
15
|
export declare class Graphics {
|
|
5
16
|
private engine;
|
|
6
17
|
private geometry;
|
|
7
|
-
private
|
|
8
|
-
private
|
|
18
|
+
private coloredMaterial;
|
|
19
|
+
private texturedMaterial;
|
|
20
|
+
private readonly lineShape;
|
|
21
|
+
private readonly bezierShape;
|
|
22
|
+
private readonly triangleShape;
|
|
23
|
+
private readonly rectangleShape;
|
|
24
|
+
private readonly circleShape;
|
|
25
|
+
private readonly buildPoints;
|
|
9
26
|
private vertices;
|
|
10
27
|
private colors;
|
|
28
|
+
private uvs;
|
|
11
29
|
private indices;
|
|
12
30
|
private lineStyle;
|
|
31
|
+
private currentBatchType;
|
|
32
|
+
private currentBatchTexture;
|
|
33
|
+
/** 文本纹理 LRU 缓存,drawText 用 */
|
|
34
|
+
private textCache;
|
|
13
35
|
private transformStack;
|
|
14
36
|
private currentTransform;
|
|
15
37
|
private get currentVertexCount();
|
|
@@ -21,7 +43,7 @@ export declare class Graphics {
|
|
|
21
43
|
begin(): void;
|
|
22
44
|
/**
|
|
23
45
|
* 将当前变换压入栈,并设置新的变换
|
|
24
|
-
* @param transform -
|
|
46
|
+
* @param transform - 新的变换矩阵(会与当前变换相乘)
|
|
25
47
|
*/
|
|
26
48
|
pushTransform(transform: Matrix3): void;
|
|
27
49
|
/**
|
|
@@ -32,47 +54,55 @@ export declare class Graphics {
|
|
|
32
54
|
* 刷新并渲染所有累积的绘制命令
|
|
33
55
|
*/
|
|
34
56
|
end(): void;
|
|
57
|
+
/**
|
|
58
|
+
* 切换到指定批次类型/纹理。若与当前批次不一致,先 flush 已累积顶点
|
|
59
|
+
*/
|
|
60
|
+
private ensureBatch;
|
|
61
|
+
/**
|
|
62
|
+
* 提交当前累积的顶点到 renderer,清空缓冲(批次内部 flush 不重置 batchType)
|
|
63
|
+
*/
|
|
64
|
+
private flushBatch;
|
|
35
65
|
/**
|
|
36
66
|
* 线段顶点按顺序连接 (p0-p1, p1-p2, p2-p3, ...)
|
|
37
|
-
* @param points - 点数组,格式 [x1,y1,x2,y2,...],至少需要2
|
|
67
|
+
* @param points - 点数组,格式 [x1,y1,x2,y2,...],至少需要2个点(4个数值)
|
|
38
68
|
* @param color - 线条颜色,范围 0-1
|
|
39
|
-
* @param thickness -
|
|
69
|
+
* @param thickness - 线宽(像素)
|
|
40
70
|
*/
|
|
41
71
|
drawLines(points: number[], color?: Color, thickness?: number): void;
|
|
42
72
|
/**
|
|
43
73
|
* 绘制单条线段
|
|
44
|
-
* @param x1 - 起点
|
|
45
|
-
* @param y1 - 起点
|
|
46
|
-
* @param x2 - 终点
|
|
47
|
-
* @param y2 - 终点
|
|
48
|
-
* @param color -
|
|
49
|
-
* @param thickness - 线宽
|
|
74
|
+
* @param x1 - 起点 X 坐标
|
|
75
|
+
* @param y1 - 起点 Y 坐标
|
|
76
|
+
* @param x2 - 终点 X 坐标
|
|
77
|
+
* @param y2 - 终点 Y 坐标
|
|
78
|
+
* @param color - 线条颜色,默认白色,范围 0-1
|
|
79
|
+
* @param thickness - 线宽(像素),默认 1
|
|
50
80
|
*/
|
|
51
81
|
drawLine(x1: number, y1: number, x2: number, y2: number, color?: Color, thickness?: number): void;
|
|
52
82
|
/**
|
|
53
|
-
*
|
|
54
|
-
* @param x1 - 起点
|
|
55
|
-
* @param y1 - 起点
|
|
56
|
-
* @param x2 -
|
|
57
|
-
* @param y2 -
|
|
58
|
-
* @param x3 -
|
|
59
|
-
* @param y3 -
|
|
60
|
-
* @param x4 - 终点
|
|
61
|
-
* @param y4 - 终点
|
|
62
|
-
* @param color -
|
|
63
|
-
* @param thickness - 线宽
|
|
83
|
+
* 绘制三阶贝塞尔曲线(P0 起点,P1/P2 控制点,P3 终点)
|
|
84
|
+
* @param x1 - P0 起点 X 坐标
|
|
85
|
+
* @param y1 - P0 起点 Y 坐标
|
|
86
|
+
* @param x2 - P1 第一控制点 X 坐标
|
|
87
|
+
* @param y2 - P1 第一控制点 Y 坐标
|
|
88
|
+
* @param x3 - P2 第二控制点 X 坐标
|
|
89
|
+
* @param y3 - P2 第二控制点 Y 坐标
|
|
90
|
+
* @param x4 - P3 终点 X 坐标
|
|
91
|
+
* @param y4 - P3 终点 Y 坐标
|
|
92
|
+
* @param color - 曲线颜色,默认白色,范围 0-1
|
|
93
|
+
* @param thickness - 线宽(像素),默认 1
|
|
64
94
|
*/
|
|
65
95
|
drawBezier(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x4: number, y4: number, color?: Color, thickness?: number): void;
|
|
66
96
|
/**
|
|
67
|
-
*
|
|
68
|
-
* @param x1 - 顶点
|
|
69
|
-
* @param y1 - 顶点
|
|
70
|
-
* @param x2 - 顶点
|
|
71
|
-
* @param y2 - 顶点
|
|
72
|
-
* @param x3 - 顶点
|
|
73
|
-
* @param y3 - 顶点
|
|
74
|
-
* @param color -
|
|
75
|
-
* @param thickness - 线宽
|
|
97
|
+
* 绘制三角形边框(闭合连接 3 个顶点)
|
|
98
|
+
* @param x1 - 顶点 1 X 坐标
|
|
99
|
+
* @param y1 - 顶点 1 Y 坐标
|
|
100
|
+
* @param x2 - 顶点 2 X 坐标
|
|
101
|
+
* @param y2 - 顶点 2 Y 坐标
|
|
102
|
+
* @param x3 - 顶点 3 X 坐标
|
|
103
|
+
* @param y3 - 顶点 3 Y 坐标
|
|
104
|
+
* @param color - 边框颜色,默认白色,范围 0-1
|
|
105
|
+
* @param thickness - 线宽(像素),默认 1
|
|
76
106
|
*/
|
|
77
107
|
drawTriangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color?: Color, thickness?: number): void;
|
|
78
108
|
/**
|
|
@@ -81,27 +111,28 @@ export declare class Graphics {
|
|
|
81
111
|
* @param y - 矩形左下角 Y 坐标
|
|
82
112
|
* @param width - 矩形宽度
|
|
83
113
|
* @param height - 矩形高度
|
|
84
|
-
* @param color -
|
|
114
|
+
* @param color - 边框颜色,默认白色,范围 0-1
|
|
115
|
+
* @param thickness - 线宽(像素),默认 1
|
|
85
116
|
*/
|
|
86
117
|
drawRectangle(x: number, y: number, width: number, height: number, color?: Color, thickness?: number): void;
|
|
87
118
|
/**
|
|
88
119
|
* 绘制圆形边框
|
|
89
|
-
* @param cx - 圆心
|
|
90
|
-
* @param cy - 圆心
|
|
91
|
-
* @param radius - 半径
|
|
92
|
-
* @param color -
|
|
93
|
-
* @param thickness - 线宽
|
|
120
|
+
* @param cx - 圆心 X 坐标
|
|
121
|
+
* @param cy - 圆心 Y 坐标
|
|
122
|
+
* @param radius - 半径(像素)
|
|
123
|
+
* @param color - 边框颜色,默认白色,范围 0-1
|
|
124
|
+
* @param thickness - 线宽(像素),默认 1
|
|
94
125
|
*/
|
|
95
126
|
drawCircle(cx: number, cy: number, radius: number, color?: Color, thickness?: number): void;
|
|
96
127
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @param x1 - 顶点
|
|
99
|
-
* @param y1 - 顶点
|
|
100
|
-
* @param x2 - 顶点
|
|
101
|
-
* @param y2 - 顶点
|
|
102
|
-
* @param x3 - 顶点
|
|
103
|
-
* @param y3 - 顶点
|
|
104
|
-
* @param color -
|
|
128
|
+
* 绘制填充三角形(实心)
|
|
129
|
+
* @param x1 - 顶点 1 X 坐标
|
|
130
|
+
* @param y1 - 顶点 1 Y 坐标
|
|
131
|
+
* @param x2 - 顶点 2 X 坐标
|
|
132
|
+
* @param y2 - 顶点 2 Y 坐标
|
|
133
|
+
* @param x3 - 顶点 3 X 坐标
|
|
134
|
+
* @param y3 - 顶点 3 Y 坐标
|
|
135
|
+
* @param color - 填充颜色,默认白色,范围 0-1
|
|
105
136
|
*/
|
|
106
137
|
fillTriangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color?: Color): void;
|
|
107
138
|
/**
|
|
@@ -110,21 +141,66 @@ export declare class Graphics {
|
|
|
110
141
|
* @param y - 矩形左下角 Y 坐标
|
|
111
142
|
* @param width - 矩形宽度
|
|
112
143
|
* @param height - 矩形高度
|
|
113
|
-
* @param color -
|
|
144
|
+
* @param color - 填充颜色,默认白色,范围 0-1
|
|
145
|
+
*
|
|
146
|
+
* 直接用 pushQuad(2 三角形分割)而不是 setRectangleShape + buildShape,
|
|
147
|
+
* 后者走 Rectangle.triangulate 的中心 fan,中心顶点连到 4 角的 4 条对角内边
|
|
148
|
+
* 在 MSAA / 亚像素精度下会暴露 1-2 像素缝隙,叠层时底层颜色透出形成可见对角痕迹
|
|
114
149
|
*/
|
|
115
150
|
fillRectangle(x: number, y: number, width: number, height: number, color?: Color): void;
|
|
116
151
|
/**
|
|
117
|
-
*
|
|
118
|
-
* @param cx - 圆心
|
|
119
|
-
* @param cy - 圆心
|
|
120
|
-
* @param radius - 半径
|
|
121
|
-
* @param color -
|
|
152
|
+
* 绘制填充圆形(实心)
|
|
153
|
+
* @param cx - 圆心 X 坐标
|
|
154
|
+
* @param cy - 圆心 Y 坐标
|
|
155
|
+
* @param radius - 半径(像素)
|
|
156
|
+
* @param color - 填充颜色,默认白色,范围 0-1
|
|
122
157
|
*/
|
|
123
158
|
fillCircle(cx: number, cy: number, radius: number, color?: Color): void;
|
|
159
|
+
/**
|
|
160
|
+
* 绘制纹理矩形(本地坐标,Y 向上,(x, y) 为左下角)
|
|
161
|
+
* @param x - 矩形左下角 X 坐标
|
|
162
|
+
* @param y - 矩形左下角 Y 坐标
|
|
163
|
+
* @param width - 矩形宽度
|
|
164
|
+
* @param height - 矩形高度
|
|
165
|
+
* @param texture - 要采样的纹理。同纹理连续绘制会合批,纹理切换会自动 flush 当前批次
|
|
166
|
+
* @param region - 纹理 UV 子矩形,默认全图。Y 向上,(u0,v0) 为左下角 UV
|
|
167
|
+
* @param color - 乘色,默认白色
|
|
168
|
+
*/
|
|
169
|
+
drawTexture(x: number, y: number, width: number, height: number, texture: Texture, region?: TextureRegion, color?: Color): void;
|
|
170
|
+
/**
|
|
171
|
+
* 绘制文本(本地坐标,Y 向上,(x, y) 为文本左下角)。
|
|
172
|
+
*
|
|
173
|
+
* 文本走字符级 bitmap atlas(同一字体下每个字只渲染一次,任意文本组合复用 atlas);
|
|
174
|
+
* `color` 作为乘色与白色字形 alpha 相乘,任意颜色都不会污染 atlas。
|
|
175
|
+
*
|
|
176
|
+
* 字体参数全部展开,避免调用方每帧创建临时 style 对象触发 GC
|
|
177
|
+
* @param x - 文本左下角 X 坐标
|
|
178
|
+
* @param y - 文本左下角 Y 坐标(对齐 baseline 上方 ascent 处)
|
|
179
|
+
* @param text - 要绘制的文本内容,空串直接 return
|
|
180
|
+
* @param fontSize - 字号(逻辑像素)
|
|
181
|
+
* @param color - 乘色,默认白色,范围 0-1
|
|
182
|
+
* @param fontFamily - 字体族,默认 `sans-serif`
|
|
183
|
+
* @param fontWeight - 字重,默认 `normal`,支持 `'bold'` 或数字
|
|
184
|
+
* @param fontStyle - 字形,默认 `normal`,支持 `'italic'`
|
|
185
|
+
*/
|
|
186
|
+
drawText(x: number, y: number, text: string, fontSize: number, color?: Color, fontFamily?: string, fontWeight?: FontWeight, fontStyle?: FontStyle): void;
|
|
124
187
|
dispose(): void;
|
|
125
188
|
private buildShape;
|
|
126
189
|
private buildShapeLine;
|
|
190
|
+
private setTriangleShape;
|
|
191
|
+
private setRectangleShape;
|
|
192
|
+
private setCircleShape;
|
|
127
193
|
private applyTransformAndColor;
|
|
194
|
+
/**
|
|
195
|
+
* 推一个 quad(4 顶点 + 6 索引,2 个三角形)。
|
|
196
|
+
*
|
|
197
|
+
* - colored 批次:`region` 省略 → UV 写 0(shader 不读)
|
|
198
|
+
* - textured 批次:传 `region` → UV 按 region 写
|
|
199
|
+
*
|
|
200
|
+
* 之所以用 2 三角形而不是中心 fan(像 Rectangle.triangulate),是因为 fan 的中心顶点连到 4 角的对角内边
|
|
201
|
+
* 在像素级亚像素精度下会暴露 1-2 像素缝隙,叠层时底层颜色透出形成可见的对角痕迹
|
|
202
|
+
*/
|
|
203
|
+
private pushQuad;
|
|
128
204
|
/**
|
|
129
205
|
* 应用自定义变换到点
|
|
130
206
|
* @param x - 点的 x 坐标
|
package/dist/render/index.d.ts
CHANGED