@galacean/effects-core 2.9.3 → 2.10.0-alpha.1
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/base-render-component.d.ts +4 -0
- 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 +17 -3
- package/dist/engine.d.ts +29 -5
- package/dist/fallback/migration.d.ts +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12389 -9421
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12375 -9420
- package/dist/index.mjs.map +1 -1
- package/dist/material/types.d.ts +4 -0
- package/dist/material/utils.d.ts +4 -0
- package/dist/math/index.d.ts +3 -2
- package/dist/math/shape/build-adaptive-bezier.d.ts +1 -1
- package/dist/math/value-getters/index.d.ts +1 -0
- package/dist/math/value-getters/reference-curve.d.ts +19 -0
- package/dist/math/value-getters/value-getter-map.d.ts +5 -0
- package/dist/plugin-system.d.ts +6 -4
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/particle/particle-mesh.d.ts +0 -2
- package/dist/plugins/particle/trail-mesh.d.ts +0 -2
- package/dist/plugins/plugin.d.ts +14 -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/sprite/sprite-item.d.ts +31 -5
- package/dist/plugins/sprite/sprite.d.ts +42 -0
- package/dist/plugins/text/text-component-base.d.ts +1 -0
- package/dist/plugins/timeline/playable-assets/index.d.ts +1 -0
- package/dist/plugins/timeline/playable-assets/sprite-property-playable-asset.d.ts +23 -0
- package/dist/plugins/timeline/playables/index.d.ts +1 -0
- package/dist/plugins/timeline/playables/sprite-property-mixer-playable.d.ts +11 -0
- package/dist/plugins/timeline/playables/transform-mixer-playable.d.ts +6 -0
- package/dist/plugins/timeline/playables/transform-playable.d.ts +17 -2
- package/dist/plugins/timeline/tracks/index.d.ts +1 -0
- package/dist/plugins/timeline/tracks/sprite-property-track.d.ts +11 -0
- package/dist/plugins/timeline/transform-clip-mixer.d.ts +33 -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 +117 -0
- package/dist/scene.d.ts +7 -4
- package/dist/transform.d.ts +14 -3
- package/dist/utils/index.d.ts +1 -1
- package/package.json +2 -2
|
@@ -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 坐标(首字 ink 起始处,含 padding 的 quad 会向左延伸)
|
|
178
|
+
* @param y - 文本左下角 Y 坐标(cell 底,含底部 padding;字形 ink 在其上方 padding+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
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { Engine } from '../engine';
|
|
2
|
+
import { Texture } from '../texture';
|
|
3
|
+
/**
|
|
4
|
+
* 字重(对齐 canvas 2d font 字符串可接受值)
|
|
5
|
+
*/
|
|
6
|
+
export type FontWeight = 'normal' | 'bold' | number;
|
|
7
|
+
/**
|
|
8
|
+
* 字形(对齐 canvas 2d font 字符串可接受值)
|
|
9
|
+
*/
|
|
10
|
+
export type FontStyle = 'normal' | 'italic';
|
|
11
|
+
/**
|
|
12
|
+
* 字形纹理超采样倍数。canvas 按 `fontSize * FONT_SCALE` 渲染,纹理像素也是 scale 倍,
|
|
13
|
+
* 但 quad 仍按 1x 逻辑尺寸绘制 — 双线性 downsample 后比原 1x 渲染清晰得多
|
|
14
|
+
*/
|
|
15
|
+
export declare const FONT_SCALE = 2;
|
|
16
|
+
/**
|
|
17
|
+
* 单张字符 atlas 的边长(像素,scale 后的实际像素,非逻辑尺寸)。
|
|
18
|
+
* 512×512 在 24px 字号下约可容纳 250+ 字形,常见 demo 文本足够
|
|
19
|
+
*/
|
|
20
|
+
export declare const ATLAS_SIZE = 512;
|
|
21
|
+
/**
|
|
22
|
+
* 单个字形在 atlas 中的位置 / 度量。
|
|
23
|
+
*
|
|
24
|
+
* `px/py/pw/ph` 是 atlas canvas 像素(scale 后,含四周 padding)。
|
|
25
|
+
* `advance` 是逻辑像素光标前进量(1x,不含 padding)— quad 宽度含 padding,
|
|
26
|
+
* 但相邻字只按 advance 前进,padding 区透明因此重叠无妨。
|
|
27
|
+
* `paddingLeft` 是逻辑像素左侧留白(1x),quad 起点左偏此量使字形 ink 落在 cursorX
|
|
28
|
+
*/
|
|
29
|
+
export type GlyphInfo = {
|
|
30
|
+
px: number;
|
|
31
|
+
py: number;
|
|
32
|
+
pw: number;
|
|
33
|
+
ph: number;
|
|
34
|
+
advance: number;
|
|
35
|
+
paddingLeft: number;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* 一种字体(family + weight + style + size 唯一确定)对应一张 atlas。
|
|
39
|
+
*
|
|
40
|
+
* Skyline 风格 packer:行内堆字,行尾换行,cell 高 = ceil((fontHeight + padding*2) * 1),
|
|
41
|
+
* 所有字共用同一 cell 高与 baseline,实现同行 baseline 对齐。
|
|
42
|
+
* atlas 满后 `ensureChar` 返回 null,调用方应跳过该字(不再扩页,v1 范围)。
|
|
43
|
+
*
|
|
44
|
+
* canvas 内容变更后需要 `uploadIfDirty` 重新上传到纹理 — 由调用方在使用纹理前主动触发,
|
|
45
|
+
* 避免每加一字都 upload 一次造成的 GL 开销
|
|
46
|
+
*/
|
|
47
|
+
export declare class GlyphAtlas {
|
|
48
|
+
private engine;
|
|
49
|
+
private readonly scaledFontString;
|
|
50
|
+
/** atlas canvas(像素 = ATLAS_SIZE × ATLAS_SIZE,自有不进 canvasPool) */
|
|
51
|
+
readonly canvas: HTMLCanvasElement;
|
|
52
|
+
/** 与 canvas 绑定的纹理,内容变更后通过 updateSource 重传 */
|
|
53
|
+
readonly texture: Texture;
|
|
54
|
+
/** cell 高(逻辑像素,含 padding),用于 quad 高度 */
|
|
55
|
+
readonly lineHeight: number;
|
|
56
|
+
private readonly ctx;
|
|
57
|
+
private readonly glyphs;
|
|
58
|
+
/** baseline 距 cell 顶距离(像素,scale 后,含顶部 padding) */
|
|
59
|
+
private readonly baselinePx;
|
|
60
|
+
/** cell 高(像素,scale 后,含 padding) */
|
|
61
|
+
private readonly cellHPx;
|
|
62
|
+
/** 四周留白(像素,scale 后) */
|
|
63
|
+
private readonly paddingPx;
|
|
64
|
+
/** italic 字形 cell 宽额外放大倍数(防斜体越界重叠) */
|
|
65
|
+
private readonly italicScale;
|
|
66
|
+
/** packer 状态:下一字开始的左上角像素位置 */
|
|
67
|
+
private currentX;
|
|
68
|
+
private currentY;
|
|
69
|
+
/** atlas 已满,后续 ensureChar 全部失败(避免反复 measureText) */
|
|
70
|
+
private full;
|
|
71
|
+
/** 自上次 upload 以来 canvas 是否有新字写入 */
|
|
72
|
+
private dirty;
|
|
73
|
+
constructor(engine: Engine, scaledFontString: string,
|
|
74
|
+
/** baseline 距 cell 顶距离(像素,scale 后,仅 ascent 部分,不含 padding) */
|
|
75
|
+
ascentPx: number,
|
|
76
|
+
/** baseline 距 cell 底距离(像素,scale 后,仅 descent 部分) */
|
|
77
|
+
descentPx: number, fontStyle: FontStyle);
|
|
78
|
+
/**
|
|
79
|
+
* 取(必要时渲染并打包)单字。返回 GlyphInfo 或 null(atlas 已满)
|
|
80
|
+
*/
|
|
81
|
+
ensureChar(char: string): GlyphInfo | null;
|
|
82
|
+
/**
|
|
83
|
+
* 若有新字写入 canvas,把整张 canvas 重新上传到纹理。调用方在使用纹理(flushBatch)前调用
|
|
84
|
+
*/
|
|
85
|
+
uploadIfDirty(): void;
|
|
86
|
+
dispose(): void;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 字符 atlas 缓存。每种字体(family + weight + style + size)分配一张
|
|
90
|
+
* `ATLAS_SIZE × ATLAS_SIZE` 的离屏 canvas atlas,字符按需逐个绘制并打包,
|
|
91
|
+
* `Graphics.drawText` 通过逐字 quad 引用 atlas 子矩形渲染。
|
|
92
|
+
*
|
|
93
|
+
* - 同一段文本不同颜色不会重复 upload(颜色由顶点 `vColor` 乘上字形 alpha)
|
|
94
|
+
* - 同一字体/字号下重复字符只渲染一次,显著减少 canvas → texture 上传次数
|
|
95
|
+
*
|
|
96
|
+
* 入参全部展开(避免调用方每帧创建临时 style 对象触发 GC)
|
|
97
|
+
*/
|
|
98
|
+
export declare class TextCache {
|
|
99
|
+
private engine;
|
|
100
|
+
/** fontKey -> 该字体的字符 atlas */
|
|
101
|
+
private readonly atlases;
|
|
102
|
+
constructor(engine: Engine);
|
|
103
|
+
/**
|
|
104
|
+
* 取(必要时新建)对应字体的字符 atlas
|
|
105
|
+
*/
|
|
106
|
+
getAtlas(fontSize: number, fontFamily: string, fontWeight: FontWeight, fontStyle: FontStyle): GlyphAtlas;
|
|
107
|
+
/**
|
|
108
|
+
* 把所有 dirty 的 atlas canvas 内容上传到对应纹理。
|
|
109
|
+
* 由 `Graphics.flushBatch` 在 drawGeometry 前调用,确保即将采样的 atlas 纹理是最新的;
|
|
110
|
+
* 一帧多次 drawText 共写同一 atlas 时,只在 flush 边界 upload 一次,避免逐 drawText 反复重传
|
|
111
|
+
*/
|
|
112
|
+
uploadDirty(): void;
|
|
113
|
+
/**
|
|
114
|
+
* 清空所有 atlas 并 dispose 对应纹理。Engine dispose 时调用
|
|
115
|
+
*/
|
|
116
|
+
dispose(): void;
|
|
117
|
+
}
|
package/dist/scene.d.ts
CHANGED
|
@@ -67,13 +67,16 @@ export interface SceneLoadOptions {
|
|
|
67
67
|
*/
|
|
68
68
|
variables?: spec.TemplateVariables;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
70
|
+
* 是否优先使用压缩纹理
|
|
71
|
+
* 当资源存在且当前环境支持时使用,否则回退到普通图片
|
|
72
|
+
* 需要注册 KTX2 loader,例如 import '@galacean/effects-plugin-ktx2'
|
|
73
|
+
* @default true
|
|
72
74
|
*/
|
|
73
75
|
useCompressedTexture?: boolean;
|
|
74
76
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
+
* 是否优先使用 Hevc 视频
|
|
78
|
+
* 当资源存在且当前环境支持时使用,否则回退到普通视频
|
|
79
|
+
* @default true
|
|
77
80
|
*/
|
|
78
81
|
useHevcVideo?: boolean;
|
|
79
82
|
/**
|
package/dist/transform.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Euler, Matrix4, Quaternion, Vector2, Vector3 } from '@galacean/effects-math/es/core/index';
|
|
2
|
+
import { Matrix3 } from '@galacean/effects-math/es/core/matrix3';
|
|
2
3
|
import type * as spec from '@galacean/effects-specification';
|
|
3
4
|
import type { Disposable } from './utils';
|
|
4
5
|
import type { Engine } from './engine';
|
|
@@ -53,7 +54,7 @@ export declare class Transform implements Disposable {
|
|
|
53
54
|
/**
|
|
54
55
|
* 子变换,可以有多个
|
|
55
56
|
*/
|
|
56
|
-
|
|
57
|
+
protected children: Transform[];
|
|
57
58
|
/**
|
|
58
59
|
* 父变换,只能有一个
|
|
59
60
|
*/
|
|
@@ -70,6 +71,10 @@ export declare class Transform implements Disposable {
|
|
|
70
71
|
* 仅包含自身变换的模型矩阵
|
|
71
72
|
*/
|
|
72
73
|
private localMatrix;
|
|
74
|
+
/**
|
|
75
|
+
* 自身变换在 2D 平面(XY)上的仿射部分缓存,按需从 localMatrix 提取
|
|
76
|
+
*/
|
|
77
|
+
private localMatrix2D;
|
|
73
78
|
/**
|
|
74
79
|
* 变换是否需要生效,不生效返回的模型矩阵为单位矩阵,需要随元素生命周期改变
|
|
75
80
|
*/
|
|
@@ -90,8 +95,8 @@ export declare class Transform implements Disposable {
|
|
|
90
95
|
constructor(props?: TransformProps, parent?: Transform);
|
|
91
96
|
set parentTransform(transform: Transform | null);
|
|
92
97
|
get parentTransform(): Transform | null;
|
|
93
|
-
set
|
|
94
|
-
get
|
|
98
|
+
private set worldMatrixDirty(value);
|
|
99
|
+
private get worldMatrixDirty();
|
|
95
100
|
/**
|
|
96
101
|
* 设置位置
|
|
97
102
|
* @param x
|
|
@@ -184,6 +189,12 @@ export declare class Transform implements Disposable {
|
|
|
184
189
|
* @returns
|
|
185
190
|
*/
|
|
186
191
|
getMatrix(): Matrix4;
|
|
192
|
+
/**
|
|
193
|
+
* 获取自身变换对应模型矩阵在 XY 平面上的 3x3 仿射矩阵
|
|
194
|
+
* 仅当 localMatrix 变化时才重新提取,否则返回缓存。返回的 Matrix3 在调用之间复用,调用方不应缓存其引用。
|
|
195
|
+
* @returns
|
|
196
|
+
*/
|
|
197
|
+
getMatrix2D(): Matrix3;
|
|
187
198
|
/**
|
|
188
199
|
* 获取父矩阵,如果有多级父节点,返回整体变换
|
|
189
200
|
* @returns
|
package/dist/utils/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@galacean/effects-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0-alpha.1",
|
|
4
4
|
"description": "Galacean Effects runtime core for the web",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@galacean/effects-specification": "^2.8.1",
|
|
46
|
-
"@galacean/effects-math": "1.
|
|
46
|
+
"@galacean/effects-math": "1.2.0",
|
|
47
47
|
"flatbuffers": "24.3.25",
|
|
48
48
|
"uuid": "9.0.1",
|
|
49
49
|
"libtess": "1.2.2"
|