@aibee/crc-bmap 0.14.28 → 0.14.29
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/lib/index.cjs +87 -20
- package/lib/index.esm.min.js +87 -20
- package/lib/meta.json +428 -274
- package/lib/src/elements/poi2.d.ts +30 -13
- package/lib/src/elements/text-texture.d.ts +2 -0
- package/lib/src/factory/index.d.ts +2 -1
- package/lib/src/factory/sdf-material.d.ts +50 -0
- package/lib/src/factory/sdf-text.d.ts +107 -0
- package/lib/src/utils/index-db.d.ts +2 -1
- package/lib/src/utils/index.d.ts +1 -0
- package/lib/src/utils/text-layout.d.ts +57 -0
- package/lib/worker/{loader.worker-2CGJ23U5.js → loader.worker-SKK7VPJG.js} +9 -9
- package/lib/worker/sdf-text.worker-WGWC2SON.js +3 -0
- package/lib/worker/sdf-text.worker-YGTPYDBG.js +1 -0
- package/package.json +2 -1
- package/lib/src/factory/text-texture.d.ts +0 -74
- package/lib/src/factory/worker/text-texture.worker.d.ts +0 -1
- package/lib/worker/lazy-indexdb-text-texture.worker-GTG7ASSH.js +0 -3
- package/lib/worker/lazy-indexdb-text-texture.worker-YSMTLMGO.js +0 -1
- package/lib/worker/text-texture.worker-6IXOXREW.js +0 -3
- package/lib/worker/text-texture.worker-U4G7IIG7.js +0 -1
- /package/lib/src/factory/worker/{lazy-indexdb-text-texture.worker.d.ts → sdf-text.worker.d.ts} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Context } from "../context/context";
|
|
2
|
-
import { Box2, DataTexture, Object3D, Object3DEventMap, Sprite, Vector3 } from "three";
|
|
2
|
+
import { Box2, DataTexture, Mesh, Object3D, Object3DEventMap, ShaderMaterial, Sprite, Vector3 } from "three";
|
|
3
|
+
import type { TextLayoutResult } from "../utils/text-layout";
|
|
3
4
|
export interface PoiOptions2 {
|
|
4
5
|
text: string;
|
|
5
6
|
icon: string;
|
|
@@ -14,13 +15,12 @@ export interface PoiOptions2 {
|
|
|
14
15
|
z: number;
|
|
15
16
|
};
|
|
16
17
|
text_font_size: number;
|
|
18
|
+
/** 文字字重:400(常规)/'bold'、700(加粗)。不同字重使用独立的 SDF 图集 */
|
|
19
|
+
text_font_weight: string | number;
|
|
20
|
+
/** 文字描边宽度,单位 CSS 像素(0 表示不描边) */
|
|
21
|
+
text_outline_width: number;
|
|
17
22
|
icon_rotate: number;
|
|
18
23
|
depth_test: boolean;
|
|
19
|
-
text_texture?: DataTexture;
|
|
20
|
-
text_texture_width?: number;
|
|
21
|
-
text_texture_height?: number;
|
|
22
|
-
text_texture_offset_x?: number;
|
|
23
|
-
text_texture_offset_y?: number;
|
|
24
24
|
hide_text: boolean;
|
|
25
25
|
icon_border?: {
|
|
26
26
|
width: number;
|
|
@@ -50,16 +50,18 @@ export type PoiOptionsParam2 = Partial<PoiOptions2>;
|
|
|
50
50
|
export declare class Poi2 extends Object3D<PoiEventMap2> {
|
|
51
51
|
context: Context;
|
|
52
52
|
options: PoiOptions2;
|
|
53
|
-
spriteText?: Sprite;
|
|
54
53
|
spriteIcon?: Sprite;
|
|
54
|
+
/** SDF 文字网格 */
|
|
55
|
+
meshText?: Mesh;
|
|
56
|
+
/** SDF 文字背景块网格 */
|
|
57
|
+
meshBackground?: Mesh;
|
|
58
|
+
/** 文字垂直 pivot(对应原 Sprite.center.y) */
|
|
59
|
+
private textCenterY;
|
|
55
60
|
box: Box2;
|
|
56
61
|
boxHelper?: HTMLDivElement;
|
|
57
62
|
private _shouldShow;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
lines: number;
|
|
61
|
-
textAspect: number;
|
|
62
|
-
}>;
|
|
63
|
+
/** 文字布局结果(按 textTextureKey 缓存) */
|
|
64
|
+
textLayoutMap: Record<string, TextLayoutResult>;
|
|
63
65
|
textTextureRectMap: Record<string, {
|
|
64
66
|
width: number;
|
|
65
67
|
height: number;
|
|
@@ -67,7 +69,15 @@ export declare class Poi2 extends Object3D<PoiEventMap2> {
|
|
|
67
69
|
aspect: number;
|
|
68
70
|
}>;
|
|
69
71
|
constructor(context: Context, options: PoiOptionsParam2);
|
|
72
|
+
/** 当前文字使用的 SDF 字体规格:字重不同即对应不同图集 */
|
|
73
|
+
get sdfFontSpec(): import("../factory").SdfFontSpec;
|
|
70
74
|
get textTexture(): DataTexture | null;
|
|
75
|
+
/** 当前文字渲染对象 */
|
|
76
|
+
get textObject(): Mesh | undefined;
|
|
77
|
+
/** 当前文字材质列表(字形分布在多张图集页时,每页对应一个材质) */
|
|
78
|
+
get textMaterials(): ShaderMaterial[];
|
|
79
|
+
/** 合并各图集页的几何;只有一页时直接复用,避免无谓开销 */
|
|
80
|
+
private mergeTextParts;
|
|
71
81
|
get textTextureRect(): {
|
|
72
82
|
width: number;
|
|
73
83
|
height: number;
|
|
@@ -82,7 +92,6 @@ export declare class Poi2 extends Object3D<PoiEventMap2> {
|
|
|
82
92
|
get iconHeight(): number;
|
|
83
93
|
get textWidth(): number;
|
|
84
94
|
get textHeight(): number;
|
|
85
|
-
get hasOriginTexture(): boolean;
|
|
86
95
|
get initedTextRect(): true | "" | {
|
|
87
96
|
width: number;
|
|
88
97
|
height: number;
|
|
@@ -99,10 +108,18 @@ export declare class Poi2 extends Object3D<PoiEventMap2> {
|
|
|
99
108
|
get textTextureKey(): string;
|
|
100
109
|
_initTextTexture: () => Promise<void>;
|
|
101
110
|
initTextTexture: () => Promise<void>;
|
|
111
|
+
/** 计算文字的 SDF 布局(含换行),度量来自共享字形图集;结果会缓存到 textLayoutMap */
|
|
112
|
+
private layoutText;
|
|
102
113
|
_initTextTextureRect: () => Promise<void>;
|
|
103
114
|
initTextTextureRect: () => Promise<void>;
|
|
104
115
|
initText(): Promise<void>;
|
|
116
|
+
/** 构建文字背景块(圆角矩形) */
|
|
117
|
+
private initBackgroundMesh;
|
|
105
118
|
initSize(): void;
|
|
119
|
+
/** pivot(textCenterY)变化后重建文字与背景几何 */
|
|
120
|
+
private rebuildTextMeshes;
|
|
121
|
+
/** 背景块几何:以文字 pivot 为原点,尺寸按 SDF 布局换算 */
|
|
122
|
+
private buildBackgroundGeometry;
|
|
106
123
|
init(): Promise<void>;
|
|
107
124
|
protected _initScale: ({ zoom }: {
|
|
108
125
|
zoom: number;
|
|
@@ -24,6 +24,8 @@ export declare class TextTexture extends Object3D {
|
|
|
24
24
|
mesh?: Mesh;
|
|
25
25
|
constructor(context: Context, options: TextTextureOptionsParam[]);
|
|
26
26
|
init(): Promise<void>;
|
|
27
|
+
private createMaterial;
|
|
28
|
+
private get materials();
|
|
27
29
|
setOpacity(opacity: number): void;
|
|
28
30
|
dispose(): void;
|
|
29
31
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ShaderMaterial, Texture } from "three";
|
|
2
|
+
/**
|
|
3
|
+
* tiny-sdf 默认 cutoff。
|
|
4
|
+
* 注意:tiny-sdf 的距离场编码为 `data = 255 * (1 - cutoff) - (255 / radius) * distance`,
|
|
5
|
+
* 因此字形边界对应的采样值是 `1 - cutoff`(默认 0.75),而不是 0.5。
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_SDF_CUTOFF = 0.25;
|
|
8
|
+
export declare const DEFAULT_SDF_EDGE: number;
|
|
9
|
+
export interface SdfTextMaterialOptions {
|
|
10
|
+
atlas: Texture;
|
|
11
|
+
/** 填充色,默认黑色 */
|
|
12
|
+
fillColor?: string;
|
|
13
|
+
/** 填充不透明度,默认 1 */
|
|
14
|
+
fillOpacity?: number;
|
|
15
|
+
/** 描边色,默认白色 */
|
|
16
|
+
outlineColor?: string;
|
|
17
|
+
/** 描边不透明度,默认 1 */
|
|
18
|
+
outlineOpacity?: number;
|
|
19
|
+
/** 描边宽度(屏幕像素),默认 1 */
|
|
20
|
+
outlineWidth?: number;
|
|
21
|
+
/** 整体不透明度,默认 1 */
|
|
22
|
+
opacity?: number;
|
|
23
|
+
/** 距离场边界值,默认 1 - tiny-sdf cutoff = 0.75 */
|
|
24
|
+
edge?: number;
|
|
25
|
+
depthTest?: boolean;
|
|
26
|
+
depthWrite?: boolean;
|
|
27
|
+
/** 是否始终面向相机(POI 文字需要),默认 false */
|
|
28
|
+
billboard?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 创建 SDF 文字材质。
|
|
32
|
+
* 距离场边缘宽度使用屏幕空间导数(fwidth)自适应,因此任意缩放都保持锐利。
|
|
33
|
+
*/
|
|
34
|
+
export declare function createSdfTextMaterial(options: SdfTextMaterialOptions): ShaderMaterial;
|
|
35
|
+
export interface SdfBackgroundMaterialOptions {
|
|
36
|
+
color?: string;
|
|
37
|
+
opacity?: number;
|
|
38
|
+
/** 圆角半径,单位为归一化(基于高度)后的长度 */
|
|
39
|
+
radius?: number;
|
|
40
|
+
/** 背景块归一化宽高(与几何一致,用于 SDF 计算) */
|
|
41
|
+
size: {
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
};
|
|
45
|
+
depthTest?: boolean;
|
|
46
|
+
/** 是否始终面向相机,默认 false */
|
|
47
|
+
billboard?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** 创建文字背景块(圆角矩形)材质,用于 `text_background` */
|
|
50
|
+
export declare function createSdfBackgroundMaterial(options: SdfBackgroundMaterialOptions): ShaderMaterial;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { DataTexture } from "three";
|
|
2
|
+
/**
|
|
3
|
+
* 影响字形生成与图集分组的字体规格。
|
|
4
|
+
* SDF 与最终显示字号无关,这里固定一个足够大的基准字号即可支持任意缩放。
|
|
5
|
+
*/
|
|
6
|
+
export interface SdfFontSpec {
|
|
7
|
+
fontFamily: string;
|
|
8
|
+
fontSize: number;
|
|
9
|
+
fontWeight: string | number;
|
|
10
|
+
/** 距离场可线性编码的半径(参考像素):外侧可编码距离 = radius × (1 - cutoff) */
|
|
11
|
+
radius: number;
|
|
12
|
+
cutoff: number;
|
|
13
|
+
/** 字形位图四周的 SDF padding(参考像素),决定描边的最大可用宽度 */
|
|
14
|
+
buffer: number;
|
|
15
|
+
/** 行距(在 fontSize 之上追加的参考像素),与 SDF padding 解耦 */
|
|
16
|
+
lineGap: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 默认字体规格。
|
|
20
|
+
* 基准字号决定 SDF 的精度与可放大倍率:字号越大,距离场纹素越多,
|
|
21
|
+
* 在高 DPR 屏幕上重采样时越锐利(也越占图集空间)。
|
|
22
|
+
*/
|
|
23
|
+
export declare const defaultSdfFontSpec: SdfFontSpec;
|
|
24
|
+
/** 单字符在图集中的位置与度量(长度单位为 SDF 基准字号像素) */
|
|
25
|
+
export interface GlyphRecord {
|
|
26
|
+
u0: number;
|
|
27
|
+
v0: number;
|
|
28
|
+
u1: number;
|
|
29
|
+
v1: number;
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
glyphWidth: number;
|
|
33
|
+
glyphHeight: number;
|
|
34
|
+
glyphLeft: number;
|
|
35
|
+
glyphTop: number;
|
|
36
|
+
glyphAdvance: number;
|
|
37
|
+
blank?: boolean;
|
|
38
|
+
/** 所在图集页索引(同一字体规格可能有多页,渲染时按页分组选纹理) */
|
|
39
|
+
page?: number;
|
|
40
|
+
}
|
|
41
|
+
/** 单张 SDF 图集(一页)。一个字体规格的字形放满一页后会追加新页。 */
|
|
42
|
+
export interface SdfAtlasPage {
|
|
43
|
+
index: number;
|
|
44
|
+
buffer: Uint8Array;
|
|
45
|
+
texture: DataTexture;
|
|
46
|
+
cursorX: number;
|
|
47
|
+
cursorY: number;
|
|
48
|
+
rowHeight: number;
|
|
49
|
+
}
|
|
50
|
+
export interface SdfAtlas {
|
|
51
|
+
key: string;
|
|
52
|
+
spec: SdfFontSpec;
|
|
53
|
+
size: number;
|
|
54
|
+
/** 允许的最大页数(按显存预算推导,见 calcMaxPages) */
|
|
55
|
+
maxPages: number;
|
|
56
|
+
/** 图集页列表(至少一页);字形通过 record.page 指向所属页 */
|
|
57
|
+
pages: SdfAtlasPage[];
|
|
58
|
+
charMap: Map<string, GlyphRecord>;
|
|
59
|
+
}
|
|
60
|
+
export declare class SdfTextFactory {
|
|
61
|
+
private static atlases;
|
|
62
|
+
private static timer;
|
|
63
|
+
private static worker;
|
|
64
|
+
private static workerFailed;
|
|
65
|
+
private static dbReady;
|
|
66
|
+
private static warnedFull;
|
|
67
|
+
private static maxTextureSize;
|
|
68
|
+
static getSpec(partial?: Partial<SdfFontSpec>): SdfFontSpec;
|
|
69
|
+
static getFontKey(spec: SdfFontSpec): string;
|
|
70
|
+
/**
|
|
71
|
+
* 读取设备支持的最大纹理边长(结果缓存)。
|
|
72
|
+
* 通过一个临时 WebGL 上下文查询 MAX_TEXTURE_SIZE,随后立即释放该上下文。
|
|
73
|
+
*/
|
|
74
|
+
private static getMaxTextureSize;
|
|
75
|
+
/** 图集实际边长:不超过设备支持的最大纹理尺寸,也不低于下限 */
|
|
76
|
+
static getAtlasSize(): number;
|
|
77
|
+
/** 获取(必要时创建)某个字体规格对应的共享图集 */
|
|
78
|
+
static getAtlas(partial?: Partial<SdfFontSpec>): SdfAtlas;
|
|
79
|
+
/** 图集第一页纹理(单页场景的常用入口) */
|
|
80
|
+
static getTexture(partial?: Partial<SdfFontSpec>): DataTexture;
|
|
81
|
+
/** 该字体规格的全部图集页纹理(多页时按字形所属页取用) */
|
|
82
|
+
static getTextures(partial?: Partial<SdfFontSpec>): DataTexture[];
|
|
83
|
+
static getGlyph(char: string, partial?: Partial<SdfFontSpec>): GlyphRecord | null;
|
|
84
|
+
/**
|
|
85
|
+
* 确保 text 中所有字符均已就绪(已写入图集)。
|
|
86
|
+
* 命中内存/持久缓存则直接复用,仅对缺失字符执行生成。
|
|
87
|
+
*/
|
|
88
|
+
static ensureText(text: string, partial?: Partial<SdfFontSpec>): Promise<SdfAtlas>;
|
|
89
|
+
private static createAtlas;
|
|
90
|
+
/** 新建一张图集页(独立的缓冲与纹理) */
|
|
91
|
+
private static createPage;
|
|
92
|
+
private static generateMissing;
|
|
93
|
+
/** 将字形数据写入图集(shelf packing),返回度量记录 */
|
|
94
|
+
private static insertGlyph;
|
|
95
|
+
/** 判断某页还能否放下指定尺寸的字形(shelf packing 规则) */
|
|
96
|
+
private static pageCanFit;
|
|
97
|
+
/** 选择可容纳该字形的图集页;所有页都放不下时新建一页 */
|
|
98
|
+
private static pickPage;
|
|
99
|
+
private static generate;
|
|
100
|
+
private static getWorker;
|
|
101
|
+
/** 主线程分帧生成(不支持 OffscreenCanvas 时的回退路径) */
|
|
102
|
+
private static generateInMainThread;
|
|
103
|
+
private static initDb;
|
|
104
|
+
private static readFromDb;
|
|
105
|
+
private static writeToDb;
|
|
106
|
+
static dispose(): void;
|
|
107
|
+
}
|
|
@@ -8,7 +8,8 @@ export declare enum MAP_DB_TABLES {
|
|
|
8
8
|
POI_TEXT = "poi_text_1",// poi文本
|
|
9
9
|
POI_TEXT_RECT = "poi_text_rect",// poi文本
|
|
10
10
|
LAZY_TEXTURE = "lazy_texture",// poi纹理
|
|
11
|
-
LAZY_POI = "lazy_poi"
|
|
11
|
+
LAZY_POI = "lazy_poi",// 车位poi
|
|
12
|
+
SDF_GLYPH = "sdf_glyph_1"
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* 获取indexDb连接
|
package/lib/src/utils/index.d.ts
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { BufferGeometry } from "three";
|
|
2
|
+
import type { GlyphRecord, SdfFontSpec } from "../factory/sdf-text";
|
|
3
|
+
/** 与旧位图实现一致的参考字号(旧实现固定 28px 字体) */
|
|
4
|
+
export declare const SDF_REFERENCE_FONT_SIZE = 28;
|
|
5
|
+
export interface PositionedGlyph {
|
|
6
|
+
char: string;
|
|
7
|
+
record: GlyphRecord;
|
|
8
|
+
/** 字形位图左边界(相对文本块左下角) */
|
|
9
|
+
x: number;
|
|
10
|
+
/** 字形位图底边界(相对文本块左下角,向上为正) */
|
|
11
|
+
y: number;
|
|
12
|
+
}
|
|
13
|
+
export interface TextLayoutResult {
|
|
14
|
+
lines: string[];
|
|
15
|
+
glyphs: PositionedGlyph[];
|
|
16
|
+
/** 布局宽度(SDF 基准字号像素) */
|
|
17
|
+
width: number;
|
|
18
|
+
/** 布局高度(SDF 基准字号像素) */
|
|
19
|
+
height: number;
|
|
20
|
+
/** 宽高比 */
|
|
21
|
+
aspect: number;
|
|
22
|
+
/** 行数 */
|
|
23
|
+
linesCount: number;
|
|
24
|
+
}
|
|
25
|
+
type MeasureFn = (str: string) => number;
|
|
26
|
+
/**
|
|
27
|
+
* 按括号/空格/中文逐字规则换行。
|
|
28
|
+
* 逻辑与旧 `TextTextureFactory.splitText` 保持一致,仅把度量方式换成字形 advance 累加。
|
|
29
|
+
*/
|
|
30
|
+
export declare function splitTextByMeasure(text: string, maxWidth: number, measure: MeasureFn): string[];
|
|
31
|
+
/**
|
|
32
|
+
* 对文字进行 SDF 布局。
|
|
33
|
+
* @param text 文本
|
|
34
|
+
* @param charMap 字符 → 字形度量(来自 SdfTextFactory 图集)
|
|
35
|
+
* @param spec 字体规格
|
|
36
|
+
* @param maxWidth 最大行宽(逻辑像素,基于 SDF_REFERENCE_FONT_SIZE)
|
|
37
|
+
*/
|
|
38
|
+
export declare function layoutSdfText(text: string, charMap: Map<string, GlyphRecord>, spec: SdfFontSpec, maxWidth?: number): TextLayoutResult;
|
|
39
|
+
interface BuildGeometryOptions {
|
|
40
|
+
/** 垂直 pivot(0 = 底部,0.5 = 居中,1 = 顶部),对应 Sprite.center.y */
|
|
41
|
+
pivotY?: number;
|
|
42
|
+
/** 水平 pivot,对应 Sprite.center.x,默认 0.5 */
|
|
43
|
+
pivotX?: number;
|
|
44
|
+
}
|
|
45
|
+
/** 某个图集页对应的那部分文字几何 */
|
|
46
|
+
export interface SdfTextGeometryPart {
|
|
47
|
+
/** 字形所属图集页索引,用于选择对应纹理 */
|
|
48
|
+
page: number;
|
|
49
|
+
geometry: BufferGeometry;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 由布局结果构建逐字 quad 几何。
|
|
53
|
+
* 几何归一化到高度 = 1(宽度 = aspect),并以 pivot 为原点,便于复用 Sprite 的 scale/position 语义。
|
|
54
|
+
* 字形可能分布在多张图集页上,因此按页分组返回;调用方需为每一页提供一个材质。
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildSdfTextGeometry(layout: TextLayoutResult, options?: BuildGeometryOptions): SdfTextGeometryPart[];
|
|
57
|
+
export {};
|