@galacean/effects-core 2.9.1-beta.0 → 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.
@@ -0,0 +1,109 @@
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 后)。
25
+ * `width` 是逻辑像素宽度(= pw / FONT_SCALE),用于 quad 宽 + cursor advance
26
+ */
27
+ export type GlyphInfo = {
28
+ px: number;
29
+ py: number;
30
+ pw: number;
31
+ ph: number;
32
+ width: number;
33
+ };
34
+ /**
35
+ * 一种字体(family + weight + style + size 唯一确定)对应一张 atlas。
36
+ *
37
+ * Skyline 风格 packer:行内堆字,行尾换行,行高 = (ascent+descent) * FONT_SCALE。
38
+ * atlas 满后 `ensureChar` 返回 null,调用方应跳过该字(不再扩页,v1 范围)。
39
+ *
40
+ * canvas 内容变更后需要 `uploadIfDirty` 重新上传到纹理 — 由调用方在使用纹理前主动触发,
41
+ * 避免每加一字都 upload 一次造成的 GL 开销
42
+ */
43
+ export declare class GlyphAtlas {
44
+ private engine;
45
+ private readonly scaledFontString;
46
+ /** atlas canvas(像素 = ATLAS_SIZE × ATLAS_SIZE,自有不进 canvasPool) */
47
+ readonly canvas: HTMLCanvasElement;
48
+ /** 与 canvas 绑定的纹理,内容变更后通过 updateSource 重传 */
49
+ readonly texture: Texture;
50
+ /** 行高(逻辑像素,= ascent + descent),所有字共享 */
51
+ readonly lineHeight: number;
52
+ /** 行 ascent(逻辑像素,baseline 距行顶距离) */
53
+ readonly ascent: number;
54
+ /** 行 descent(逻辑像素,baseline 距行底距离) */
55
+ readonly descent: number;
56
+ private readonly ctx;
57
+ private readonly glyphs;
58
+ /** 行高(像素,scale 后) */
59
+ private readonly lineHeightPx;
60
+ /** baseline 距行顶距离(像素,scale 后) */
61
+ private readonly ascentPx;
62
+ /** packer 状态:下一字开始的左上角像素位置 */
63
+ private currentX;
64
+ private currentY;
65
+ /** atlas 已满,后续 ensureChar 全部失败(避免反复 measureText) */
66
+ private full;
67
+ /** 自上次 upload 以来 canvas 是否有新字写入 */
68
+ private dirty;
69
+ constructor(engine: Engine, scaledFontString: string, ascent: number, descent: number);
70
+ /**
71
+ * 取(必要时渲染并打包)单字。返回 GlyphInfo 或 null(atlas 已满)
72
+ */
73
+ ensureChar(char: string): GlyphInfo | null;
74
+ /**
75
+ * 若有新字写入 canvas,把整张 canvas 重新上传到纹理。调用方在使用纹理(flushBatch)前调用
76
+ */
77
+ uploadIfDirty(): void;
78
+ dispose(): void;
79
+ }
80
+ /**
81
+ * 字符 atlas 缓存。每种字体(family + weight + style + size)分配一张
82
+ * `ATLAS_SIZE × ATLAS_SIZE` 的离屏 canvas atlas,字符按需逐个绘制并打包,
83
+ * `Graphics.drawText` 通过逐字 quad 引用 atlas 子矩形渲染。
84
+ *
85
+ * - 同一段文本不同颜色不会重复 upload(颜色由顶点 `vColor` 乘上字形 alpha)
86
+ * - 同一字体/字号下重复字符只渲染一次,显著减少 canvas → texture 上传次数
87
+ *
88
+ * 入参全部展开(避免调用方每帧创建临时 style 对象触发 GC)
89
+ */
90
+ export declare class TextCache {
91
+ private engine;
92
+ /** fontKey -> 该字体的字符 atlas */
93
+ private readonly atlases;
94
+ constructor(engine: Engine);
95
+ /**
96
+ * 取(必要时新建)对应字体的字符 atlas
97
+ */
98
+ getAtlas(fontSize: number, fontFamily: string, fontWeight: FontWeight, fontStyle: FontStyle): GlyphAtlas;
99
+ /**
100
+ * 把所有 dirty 的 atlas canvas 内容上传到对应纹理。
101
+ * 由 `Graphics.flushBatch` 在 drawGeometry 前调用,确保即将采样的 atlas 纹理是最新的;
102
+ * 一帧多次 drawText 共写同一 atlas 时,只在 flush 边界 upload 一次,避免逐 drawText 反复重传
103
+ */
104
+ uploadDirty(): void;
105
+ /**
106
+ * 清空所有 atlas 并 dispose 对应纹理。Engine dispose 时调用
107
+ */
108
+ dispose(): void;
109
+ }
@@ -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
- private children;
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 parentMatrixDirty(val: boolean);
94
- get parentMatrixDirty(): boolean;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/effects-core",
3
- "version": "2.9.1-beta.0",
3
+ "version": "2.10.0-alpha.0",
4
4
  "description": "Galacean Effects runtime core for the web",
5
5
  "module": "./dist/index.mjs",
6
6
  "main": "./dist/index.js",