babylonjs-addons 8.6.2 → 8.7.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/138.js +2 -0
- package/138.js.map +1 -0
- package/205.js +2 -0
- package/205.js.map +1 -0
- package/315.js +2 -0
- package/315.js.map +1 -0
- package/372.js +2 -0
- package/372.js.map +1 -0
- package/babylonjs.addons.d.ts +352 -0
- package/babylonjs.addons.js +847 -9
- package/babylonjs.addons.min.js +1 -1
- package/babylonjs.addons.min.js.map +1 -1
- package/babylonjs.addons.module.d.ts +739 -0
- package/dev_addons_src_msdfText_webgl_fragment_ts.js +24 -0
- package/dev_addons_src_msdfText_webgl_vertex_ts.js +24 -0
- package/dev_addons_src_msdfText_webgpu_fragment_ts.js +24 -0
- package/dev_addons_src_msdfText_webgpu_vertex_ts.js +24 -0
- package/package.json +2 -2
@@ -1,6 +1,393 @@
|
|
1
1
|
|
2
2
|
declare module "babylonjs-addons/index" {
|
3
3
|
export * from "babylonjs-addons/htmlMesh";
|
4
|
+
export * from "babylonjs-addons/msdfText";
|
5
|
+
|
6
|
+
}
|
7
|
+
declare module "babylonjs-addons/msdfText/textRenderer" {
|
8
|
+
import { AbstractEngine } from "babylonjs/Engines/abstractEngine";
|
9
|
+
import { IDisposable } from "babylonjs/scene";
|
10
|
+
import { Nullable } from "babylonjs/types";
|
11
|
+
import { FontAsset } from "babylonjs-addons/msdfText/fontAsset";
|
12
|
+
import { ParagraphOptions } from "babylonjs-addons/msdfText/paragraphOptions";
|
13
|
+
import { ThinMatrix } from "babylonjs/Maths/ThinMaths/thinMath.matrix";
|
14
|
+
import { IColor4Like, IMatrixLike } from "babylonjs/Maths";
|
15
|
+
/**
|
16
|
+
* Abstract Node class from Babylon.js
|
17
|
+
*/
|
18
|
+
export interface INodeLike {
|
19
|
+
getWorldMatrix(): ThinMatrix;
|
20
|
+
}
|
21
|
+
/**
|
22
|
+
* Class used to render text using MSDF (Multi-channel Signed Distance Field) technique
|
23
|
+
* Thanks a lot to the work of Bhushan_Wagh and zb_sj for their amazing work on MSDF for Babylon.js
|
24
|
+
* #6RLCWP#16
|
25
|
+
* Star wars scroller: #6RLCWP#29
|
26
|
+
* With metrics: #6RLCWP#35
|
27
|
+
* Thickness: #IABMEZ#3
|
28
|
+
* Solar system: #9YCDYC#9
|
29
|
+
*/
|
30
|
+
export class TextRenderer implements IDisposable {
|
31
|
+
private readonly _useVAO;
|
32
|
+
private _engine;
|
33
|
+
private _shaderLanguage;
|
34
|
+
private _vertexBuffers;
|
35
|
+
private _spriteBuffer;
|
36
|
+
private _worldBuffer;
|
37
|
+
private _uvBuffer;
|
38
|
+
private _drawWrapperBase;
|
39
|
+
private _vertexArrayObject;
|
40
|
+
private _font;
|
41
|
+
private _charMatrices;
|
42
|
+
private _charUvs;
|
43
|
+
private _isDirty;
|
44
|
+
private _baseLine;
|
45
|
+
private _scalingMatrix;
|
46
|
+
private _fontScaleMatrix;
|
47
|
+
private _offsetMatrix;
|
48
|
+
private _translationMatrix;
|
49
|
+
private _baseMatrix;
|
50
|
+
private _scaledMatrix;
|
51
|
+
private _localMatrix;
|
52
|
+
private _finalMatrix;
|
53
|
+
private _lineMatrix;
|
54
|
+
private _parentWorldMatrix;
|
55
|
+
private _storedTranslation;
|
56
|
+
/**
|
57
|
+
* Gets or sets the color of the text
|
58
|
+
*/
|
59
|
+
color: IColor4Like;
|
60
|
+
/**
|
61
|
+
* Gets or sets the thickness of the text (0 means as defined in the font)
|
62
|
+
* Value must be between -0.5 and 0.5
|
63
|
+
*/
|
64
|
+
thicknessControl: number;
|
65
|
+
private _parent;
|
66
|
+
/**
|
67
|
+
* Gets or sets the parent of the text renderer
|
68
|
+
*/
|
69
|
+
get parent(): Nullable<INodeLike>;
|
70
|
+
set parent(value: Nullable<INodeLike>);
|
71
|
+
/**
|
72
|
+
* Gets or sets if the text is billboarded
|
73
|
+
*/
|
74
|
+
isBillboard: boolean;
|
75
|
+
/**
|
76
|
+
* Gets the number of characters in the text renderer
|
77
|
+
*/
|
78
|
+
get characterCount(): number;
|
79
|
+
private constructor();
|
80
|
+
private _resizeBuffers;
|
81
|
+
private _setShaders;
|
82
|
+
/**
|
83
|
+
* Add a paragraph of text to the renderer
|
84
|
+
* @param text define the text to add
|
85
|
+
* @param options define the options to use for the paragraph (optional)
|
86
|
+
* @param worldMatrix define the world matrix to use for the paragraph (optional)
|
87
|
+
*/
|
88
|
+
addParagraph(text: string, options?: Partial<ParagraphOptions>, worldMatrix?: IMatrixLike): void;
|
89
|
+
/**
|
90
|
+
* Render the text using the provided view and projection matrices
|
91
|
+
* @param viewMatrix define the view matrix to use
|
92
|
+
* @param projectionMatrix define the projection matrix to use
|
93
|
+
*/
|
94
|
+
render(viewMatrix: IMatrixLike, projectionMatrix: IMatrixLike): void;
|
95
|
+
/**
|
96
|
+
* Release associated resources
|
97
|
+
*/
|
98
|
+
dispose(): void;
|
99
|
+
/**
|
100
|
+
* Creates a new TextRenderer instance asynchronously
|
101
|
+
* @param font define the font asset to use
|
102
|
+
* @param engine define the engine to use
|
103
|
+
* @returns a promise that resolves to the created TextRenderer instance
|
104
|
+
*/
|
105
|
+
static CreateTextRendererAsync(font: FontAsset, engine: AbstractEngine): Promise<TextRenderer>;
|
106
|
+
}
|
107
|
+
|
108
|
+
}
|
109
|
+
declare module "babylonjs-addons/msdfText/paragraphOptions" {
|
110
|
+
import { Vector2 } from "babylonjs/Maths/math.vector";
|
111
|
+
/** @internal */
|
112
|
+
export type ParagraphOptions = {
|
113
|
+
maxWidth: number;
|
114
|
+
lineHeight: number;
|
115
|
+
letterSpacing: number;
|
116
|
+
tabSize: number;
|
117
|
+
whiteSpace: "pre-line";
|
118
|
+
textAlign: "left" | "right" | "center";
|
119
|
+
translate: Vector2 | undefined;
|
120
|
+
};
|
121
|
+
/** @internal */
|
122
|
+
export const DefaultParagraphOptions: ParagraphOptions;
|
123
|
+
|
124
|
+
}
|
125
|
+
declare module "babylonjs-addons/msdfText/index" {
|
126
|
+
export * from "babylonjs-addons/msdfText/fontAsset";
|
127
|
+
export * from "babylonjs-addons/msdfText/paragraphOptions";
|
128
|
+
export * from "babylonjs-addons/msdfText/textRenderer";
|
129
|
+
|
130
|
+
}
|
131
|
+
declare module "babylonjs-addons/msdfText/fontAsset" {
|
132
|
+
import { BMFontChar } from "babylonjs-addons/msdfText/sdf/bmFont";
|
133
|
+
import { SdfFont } from "babylonjs-addons/msdfText/sdf/font";
|
134
|
+
import { Texture } from "babylonjs/Materials/Textures/texture";
|
135
|
+
/**
|
136
|
+
* Class representing a font asset for SDF (Signed Distance Field) rendering.
|
137
|
+
*/
|
138
|
+
export class FontAsset {
|
139
|
+
private readonly _chars;
|
140
|
+
private readonly _charsRegex;
|
141
|
+
private readonly _kernings;
|
142
|
+
/** @internal */
|
143
|
+
readonly _font: SdfFont;
|
144
|
+
/**
|
145
|
+
* Gets the font scale value
|
146
|
+
*/
|
147
|
+
readonly scale: number;
|
148
|
+
/**
|
149
|
+
* Gets the list of used textures
|
150
|
+
*/
|
151
|
+
readonly textures: Texture[];
|
152
|
+
/**
|
153
|
+
* Creates a new FontAsset instance.
|
154
|
+
* @param definitionData defines the font data in JSON format.
|
155
|
+
* @param textureUrl defines the url of the texture to use for the font.
|
156
|
+
*/
|
157
|
+
constructor(definitionData: string, textureUrl: string);
|
158
|
+
private _updateFallbacks;
|
159
|
+
/** @internal */
|
160
|
+
_getChar(charCode: number): BMFontChar;
|
161
|
+
/** @internal */
|
162
|
+
_getKerning(first: number, second: number): number;
|
163
|
+
/** @internal */
|
164
|
+
_unsupportedChars(text: string): string;
|
165
|
+
}
|
166
|
+
|
167
|
+
}
|
168
|
+
declare module "babylonjs-addons/msdfText/webgpu/vertex" {
|
169
|
+
/** @internal */
|
170
|
+
export const msdfVertexShader: {
|
171
|
+
name: string;
|
172
|
+
shader: string;
|
173
|
+
};
|
174
|
+
|
175
|
+
}
|
176
|
+
declare module "babylonjs-addons/msdfText/webgpu/fragment" {
|
177
|
+
/** @internal */
|
178
|
+
export const msdfFragmentShader: {
|
179
|
+
name: string;
|
180
|
+
shader: string;
|
181
|
+
};
|
182
|
+
|
183
|
+
}
|
184
|
+
declare module "babylonjs-addons/msdfText/webgl/vertex" {
|
185
|
+
/** @internal */
|
186
|
+
export const msdfVertexShader: {
|
187
|
+
name: string;
|
188
|
+
shader: string;
|
189
|
+
};
|
190
|
+
|
191
|
+
}
|
192
|
+
declare module "babylonjs-addons/msdfText/webgl/fragment" {
|
193
|
+
/** @internal */
|
194
|
+
export const msdfFragmentShader: {
|
195
|
+
name: string;
|
196
|
+
shader: string;
|
197
|
+
};
|
198
|
+
|
199
|
+
}
|
200
|
+
declare module "babylonjs-addons/msdfText/sdf/paragraph" {
|
201
|
+
import { FontAsset } from "babylonjs-addons/msdfText/fontAsset";
|
202
|
+
import { type ParagraphOptions } from "babylonjs-addons/msdfText/paragraphOptions";
|
203
|
+
import { SdfGlyph } from "babylonjs-addons/msdfText/sdf/glyph";
|
204
|
+
import { SdfTextLine } from "babylonjs-addons/msdfText/sdf/line";
|
205
|
+
/** @internal */
|
206
|
+
export class SdfTextParagraph {
|
207
|
+
readonly text: string;
|
208
|
+
readonly fontAsset: FontAsset;
|
209
|
+
readonly options: ParagraphOptions;
|
210
|
+
get lineHeight(): number;
|
211
|
+
readonly paragraph: string;
|
212
|
+
readonly lines: SdfTextLine[];
|
213
|
+
readonly width: number;
|
214
|
+
readonly height: number;
|
215
|
+
readonly glyphs: SdfGlyph[];
|
216
|
+
constructor(text: string, fontAsset: FontAsset, options?: Partial<ParagraphOptions>);
|
217
|
+
private _computeMetrics;
|
218
|
+
private _breakLines;
|
219
|
+
private _collapse;
|
220
|
+
private _wrap;
|
221
|
+
}
|
222
|
+
|
223
|
+
}
|
224
|
+
declare module "babylonjs-addons/msdfText/sdf/line" {
|
225
|
+
import { SdfGlyph } from "babylonjs-addons/msdfText/sdf/glyph";
|
226
|
+
/** @internal */
|
227
|
+
export type SdfTextLine = {
|
228
|
+
text: string;
|
229
|
+
glyphs: SdfGlyph[];
|
230
|
+
start: number;
|
231
|
+
end: number;
|
232
|
+
width: number;
|
233
|
+
};
|
234
|
+
|
235
|
+
}
|
236
|
+
declare module "babylonjs-addons/msdfText/sdf/glyph" {
|
237
|
+
import { BMFontChar } from "babylonjs-addons/msdfText/sdf/bmFont";
|
238
|
+
/** @internal */
|
239
|
+
export type SdfGlyph = {
|
240
|
+
char: BMFontChar;
|
241
|
+
/** index of the line */
|
242
|
+
line: number;
|
243
|
+
/** position within the line */
|
244
|
+
position: number;
|
245
|
+
x: number;
|
246
|
+
y: number;
|
247
|
+
};
|
248
|
+
|
249
|
+
}
|
250
|
+
declare module "babylonjs-addons/msdfText/sdf/font" {
|
251
|
+
import { BMFont } from "babylonjs-addons/msdfText/sdf/bmFont";
|
252
|
+
export type SdfFontDistanceField = {
|
253
|
+
fieldType: "sdf" | "msdf";
|
254
|
+
distanceRange: number;
|
255
|
+
};
|
256
|
+
export type SdfFont = BMFont & {
|
257
|
+
distanceField: SdfFontDistanceField;
|
258
|
+
};
|
259
|
+
|
260
|
+
}
|
261
|
+
declare module "babylonjs-addons/msdfText/sdf/bmFont" {
|
262
|
+
/**
|
263
|
+
* Holds information on how the font was generated.
|
264
|
+
*/
|
265
|
+
export type BMFontInfo = {
|
266
|
+
/** The name of the font */
|
267
|
+
face: string;
|
268
|
+
/** The size of the font */
|
269
|
+
size: number;
|
270
|
+
/** The font is bold */
|
271
|
+
bold: number;
|
272
|
+
/** The font is italic */
|
273
|
+
italic: number;
|
274
|
+
/** The charset of the font */
|
275
|
+
charset: string[];
|
276
|
+
/** The charset is unicode */
|
277
|
+
unicode: number;
|
278
|
+
/** The font height stretch in percentage. 100% means no stretch. */
|
279
|
+
stretchH: number;
|
280
|
+
/** Set to 1 if smoothing was turned on. */
|
281
|
+
smooth: number;
|
282
|
+
/** The supersampling level used. 1 means no supersampling was used. */
|
283
|
+
aa: number;
|
284
|
+
/** The padding for each character (up, right, down, left). */
|
285
|
+
padding: [number, number, number, number];
|
286
|
+
/** The spacing for each character (horizontal, vertical). */
|
287
|
+
spacing: [number, number];
|
288
|
+
/**
|
289
|
+
* The outline thickness for the characters.
|
290
|
+
*
|
291
|
+
* @remark missing in msdf-bmfont-xml
|
292
|
+
*/
|
293
|
+
outline?: number;
|
294
|
+
};
|
295
|
+
/**
|
296
|
+
* Holds information common to all characters.
|
297
|
+
*/
|
298
|
+
export type BMFontCommon = {
|
299
|
+
/** Distance in pixels between each line of text */
|
300
|
+
lineHeight: number;
|
301
|
+
/** The number of pixels from the absolute top of the line to the base of the characters */
|
302
|
+
base: number;
|
303
|
+
/** The width of the texture, normally used to scale the x pos of the character image */
|
304
|
+
scaleW: number;
|
305
|
+
/** The height of the texture, normally used to scale the y pos of the character image */
|
306
|
+
scaleH: number;
|
307
|
+
/** The number of pages in the font */
|
308
|
+
pages: number;
|
309
|
+
/** Set to 1 if the monochrome characters have been packed into each of the texture channels. In this case alphaChnl describes what is stored in each channel. */
|
310
|
+
packed: number;
|
311
|
+
/** Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. */
|
312
|
+
alphaChnl: number;
|
313
|
+
/** Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. */
|
314
|
+
redChnl: number;
|
315
|
+
/** Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. */
|
316
|
+
greenChnl: number;
|
317
|
+
/** Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. */
|
318
|
+
blueChnl: number;
|
319
|
+
};
|
320
|
+
/** Name of a texture file. There is one for each page in the font. */
|
321
|
+
export type BMFontPages = {
|
322
|
+
[id: number]: string;
|
323
|
+
} & Array<string>;
|
324
|
+
/**
|
325
|
+
* Describes a single character in the font
|
326
|
+
*/
|
327
|
+
export type BMFontChar = {
|
328
|
+
/** Character id (charCode) */
|
329
|
+
id: number;
|
330
|
+
/** Left position of the character image in the texture. */
|
331
|
+
x: number;
|
332
|
+
/** Right position of the character image in the texture */
|
333
|
+
y: number;
|
334
|
+
/** Width of the chracter image in the texture */
|
335
|
+
width: number;
|
336
|
+
/** Height of the chracter image in the texture */
|
337
|
+
height: number;
|
338
|
+
/** Horizontal offset to be applied on screen */
|
339
|
+
xoffset: number;
|
340
|
+
/** Vertical offset to be applied on screen */
|
341
|
+
yoffset: number;
|
342
|
+
/** Horizontal advance after the character */
|
343
|
+
xadvance: number;
|
344
|
+
/** Page index where the character image is found */
|
345
|
+
page: number;
|
346
|
+
/** Texture channel where the chracter image is found
|
347
|
+
* - 1 = blue
|
348
|
+
* - 2 = green
|
349
|
+
* - 3 = red
|
350
|
+
* - 8 = alpha
|
351
|
+
* - 15 = all channels
|
352
|
+
*/
|
353
|
+
chnl: number;
|
354
|
+
} & BMFontCharExtra;
|
355
|
+
/**
|
356
|
+
* additional context from msdf-bmfont-xml
|
357
|
+
*/
|
358
|
+
export type BMFontCharExtra = {
|
359
|
+
/** index of opentype.js glyph */
|
360
|
+
index: number;
|
361
|
+
/** actual character*/
|
362
|
+
char: string;
|
363
|
+
};
|
364
|
+
/**
|
365
|
+
* The kerning information is used to adjust the distance between certain characters, e.g. some characters should be placed closer to each other than others.
|
366
|
+
*/
|
367
|
+
export type BMFontKerning = {
|
368
|
+
/** The first character id. */
|
369
|
+
first: number;
|
370
|
+
/** The second character id. */
|
371
|
+
second: number;
|
372
|
+
/** How much the x position should be adjusted when drawing the second character immediately following the first. */
|
373
|
+
amount: number;
|
374
|
+
};
|
375
|
+
/**
|
376
|
+
* Compatible with [msdf-bmfont-xml](https://github.com/soimy/msdf-bmfont-xml)
|
377
|
+
* @see https://www.angelcode.com/products/bmfont/doc/file_format.html
|
378
|
+
*/
|
379
|
+
export type BMFont = {
|
380
|
+
/** {@inheritDoc BMFontInfo} */
|
381
|
+
info: BMFontInfo;
|
382
|
+
/** {@inheritDoc BMFontCommon} */
|
383
|
+
common: BMFontCommon;
|
384
|
+
/** {@inheritDoc BMFontPages} */
|
385
|
+
pages: BMFontPages;
|
386
|
+
/** {@inheritDoc BMFontChar} */
|
387
|
+
chars: BMFontChar[];
|
388
|
+
/** {@inheritDoc BMFontKerning} */
|
389
|
+
kernings: BMFontKerning[];
|
390
|
+
};
|
4
391
|
|
5
392
|
}
|
6
393
|
declare module "babylonjs-addons/htmlMesh/pointerEventsCaptureBehavior" {
|
@@ -315,6 +702,358 @@ declare module "babylonjs-addons" {
|
|
315
702
|
declare module ADDONS {
|
316
703
|
|
317
704
|
|
705
|
+
/**
|
706
|
+
* Abstract Node class from Babylon.js
|
707
|
+
*/
|
708
|
+
export interface INodeLike {
|
709
|
+
getWorldMatrix(): BABYLON.ThinMatrix;
|
710
|
+
}
|
711
|
+
/**
|
712
|
+
* Class used to render text using MSDF (Multi-channel Signed Distance Field) technique
|
713
|
+
* Thanks a lot to the work of Bhushan_Wagh and zb_sj for their amazing work on MSDF for Babylon.js
|
714
|
+
* #6RLCWP#16
|
715
|
+
* Star wars scroller: #6RLCWP#29
|
716
|
+
* With metrics: #6RLCWP#35
|
717
|
+
* Thickness: #IABMEZ#3
|
718
|
+
* Solar system: #9YCDYC#9
|
719
|
+
*/
|
720
|
+
export class TextRenderer implements BABYLON.IDisposable {
|
721
|
+
private readonly _useVAO;
|
722
|
+
private _engine;
|
723
|
+
private _shaderLanguage;
|
724
|
+
private _vertexBuffers;
|
725
|
+
private _spriteBuffer;
|
726
|
+
private _worldBuffer;
|
727
|
+
private _uvBuffer;
|
728
|
+
private _drawWrapperBase;
|
729
|
+
private _vertexArrayObject;
|
730
|
+
private _font;
|
731
|
+
private _charMatrices;
|
732
|
+
private _charUvs;
|
733
|
+
private _isDirty;
|
734
|
+
private _baseLine;
|
735
|
+
private _scalingMatrix;
|
736
|
+
private _fontScaleMatrix;
|
737
|
+
private _offsetMatrix;
|
738
|
+
private _translationMatrix;
|
739
|
+
private _baseMatrix;
|
740
|
+
private _scaledMatrix;
|
741
|
+
private _localMatrix;
|
742
|
+
private _finalMatrix;
|
743
|
+
private _lineMatrix;
|
744
|
+
private _parentWorldMatrix;
|
745
|
+
private _storedTranslation;
|
746
|
+
/**
|
747
|
+
* Gets or sets the color of the text
|
748
|
+
*/
|
749
|
+
color: BABYLON.IColor4Like;
|
750
|
+
/**
|
751
|
+
* Gets or sets the thickness of the text (0 means as defined in the font)
|
752
|
+
* Value must be between -0.5 and 0.5
|
753
|
+
*/
|
754
|
+
thicknessControl: number;
|
755
|
+
private _parent;
|
756
|
+
/**
|
757
|
+
* Gets or sets the parent of the text renderer
|
758
|
+
*/
|
759
|
+
get parent(): BABYLON.Nullable<INodeLike>;
|
760
|
+
set parent(value: BABYLON.Nullable<INodeLike>);
|
761
|
+
/**
|
762
|
+
* Gets or sets if the text is billboarded
|
763
|
+
*/
|
764
|
+
isBillboard: boolean;
|
765
|
+
/**
|
766
|
+
* Gets the number of characters in the text renderer
|
767
|
+
*/
|
768
|
+
get characterCount(): number;
|
769
|
+
private constructor();
|
770
|
+
private _resizeBuffers;
|
771
|
+
private _setShaders;
|
772
|
+
/**
|
773
|
+
* Add a paragraph of text to the renderer
|
774
|
+
* @param text define the text to add
|
775
|
+
* @param options define the options to use for the paragraph (optional)
|
776
|
+
* @param worldMatrix define the world matrix to use for the paragraph (optional)
|
777
|
+
*/
|
778
|
+
addParagraph(text: string, options?: Partial<ParagraphOptions>, worldMatrix?: BABYLON.IMatrixLike): void;
|
779
|
+
/**
|
780
|
+
* Render the text using the provided view and projection matrices
|
781
|
+
* @param viewMatrix define the view matrix to use
|
782
|
+
* @param projectionMatrix define the projection matrix to use
|
783
|
+
*/
|
784
|
+
render(viewMatrix: BABYLON.IMatrixLike, projectionMatrix: BABYLON.IMatrixLike): void;
|
785
|
+
/**
|
786
|
+
* Release associated resources
|
787
|
+
*/
|
788
|
+
dispose(): void;
|
789
|
+
/**
|
790
|
+
* Creates a new TextRenderer instance asynchronously
|
791
|
+
* @param font define the font asset to use
|
792
|
+
* @param engine define the engine to use
|
793
|
+
* @returns a promise that resolves to the created TextRenderer instance
|
794
|
+
*/
|
795
|
+
static CreateTextRendererAsync(font: FontAsset, engine: BABYLON.AbstractEngine): Promise<TextRenderer>;
|
796
|
+
}
|
797
|
+
|
798
|
+
|
799
|
+
/** @internal */
|
800
|
+
export type ParagraphOptions = {
|
801
|
+
maxWidth: number;
|
802
|
+
lineHeight: number;
|
803
|
+
letterSpacing: number;
|
804
|
+
tabSize: number;
|
805
|
+
whiteSpace: "pre-line";
|
806
|
+
textAlign: "left" | "right" | "center";
|
807
|
+
translate: BABYLON.Vector2 | undefined;
|
808
|
+
};
|
809
|
+
/** @internal */
|
810
|
+
export var DefaultParagraphOptions: ParagraphOptions;
|
811
|
+
|
812
|
+
|
813
|
+
|
814
|
+
|
815
|
+
/**
|
816
|
+
* Class representing a font asset for SDF (Signed Distance Field) rendering.
|
817
|
+
*/
|
818
|
+
export class FontAsset {
|
819
|
+
private readonly _chars;
|
820
|
+
private readonly _charsRegex;
|
821
|
+
private readonly _kernings;
|
822
|
+
/** @internal */
|
823
|
+
readonly _font: SdfFont;
|
824
|
+
/**
|
825
|
+
* Gets the font scale value
|
826
|
+
*/
|
827
|
+
readonly scale: number;
|
828
|
+
/**
|
829
|
+
* Gets the list of used textures
|
830
|
+
*/
|
831
|
+
readonly textures: BABYLON.Texture[];
|
832
|
+
/**
|
833
|
+
* Creates a new FontAsset instance.
|
834
|
+
* @param definitionData defines the font data in JSON format.
|
835
|
+
* @param textureUrl defines the url of the texture to use for the font.
|
836
|
+
*/
|
837
|
+
constructor(definitionData: string, textureUrl: string);
|
838
|
+
private _updateFallbacks;
|
839
|
+
/** @internal */
|
840
|
+
_getChar(charCode: number): BMFontChar;
|
841
|
+
/** @internal */
|
842
|
+
_getKerning(first: number, second: number): number;
|
843
|
+
/** @internal */
|
844
|
+
_unsupportedChars(text: string): string;
|
845
|
+
}
|
846
|
+
|
847
|
+
|
848
|
+
/** @internal */
|
849
|
+
export var msdfVertexShader: {
|
850
|
+
name: string;
|
851
|
+
shader: string;
|
852
|
+
};
|
853
|
+
|
854
|
+
|
855
|
+
/** @internal */
|
856
|
+
export var msdfFragmentShader: {
|
857
|
+
name: string;
|
858
|
+
shader: string;
|
859
|
+
};
|
860
|
+
|
861
|
+
|
862
|
+
/** @internal */
|
863
|
+
export var msdfVertexShader: {
|
864
|
+
name: string;
|
865
|
+
shader: string;
|
866
|
+
};
|
867
|
+
|
868
|
+
|
869
|
+
/** @internal */
|
870
|
+
export var msdfFragmentShader: {
|
871
|
+
name: string;
|
872
|
+
shader: string;
|
873
|
+
};
|
874
|
+
|
875
|
+
|
876
|
+
/** @internal */
|
877
|
+
export class SdfTextParagraph {
|
878
|
+
readonly text: string;
|
879
|
+
readonly fontAsset: FontAsset;
|
880
|
+
readonly options: ParagraphOptions;
|
881
|
+
get lineHeight(): number;
|
882
|
+
readonly paragraph: string;
|
883
|
+
readonly lines: SdfTextLine[];
|
884
|
+
readonly width: number;
|
885
|
+
readonly height: number;
|
886
|
+
readonly glyphs: SdfGlyph[];
|
887
|
+
constructor(text: string, fontAsset: FontAsset, options?: Partial<ParagraphOptions>);
|
888
|
+
private _computeMetrics;
|
889
|
+
private _breakLines;
|
890
|
+
private _collapse;
|
891
|
+
private _wrap;
|
892
|
+
}
|
893
|
+
|
894
|
+
|
895
|
+
/** @internal */
|
896
|
+
export type SdfTextLine = {
|
897
|
+
text: string;
|
898
|
+
glyphs: SdfGlyph[];
|
899
|
+
start: number;
|
900
|
+
end: number;
|
901
|
+
width: number;
|
902
|
+
};
|
903
|
+
|
904
|
+
|
905
|
+
/** @internal */
|
906
|
+
export type SdfGlyph = {
|
907
|
+
char: BMFontChar;
|
908
|
+
/** index of the line */
|
909
|
+
line: number;
|
910
|
+
/** position within the line */
|
911
|
+
position: number;
|
912
|
+
x: number;
|
913
|
+
y: number;
|
914
|
+
};
|
915
|
+
|
916
|
+
|
917
|
+
export type SdfFontDistanceField = {
|
918
|
+
fieldType: "sdf" | "msdf";
|
919
|
+
distanceRange: number;
|
920
|
+
};
|
921
|
+
export type SdfFont = BMFont & {
|
922
|
+
distanceField: SdfFontDistanceField;
|
923
|
+
};
|
924
|
+
|
925
|
+
|
926
|
+
/**
|
927
|
+
* Holds information on how the font was generated.
|
928
|
+
*/
|
929
|
+
export type BMFontInfo = {
|
930
|
+
/** The name of the font */
|
931
|
+
face: string;
|
932
|
+
/** The size of the font */
|
933
|
+
size: number;
|
934
|
+
/** The font is bold */
|
935
|
+
bold: number;
|
936
|
+
/** The font is italic */
|
937
|
+
italic: number;
|
938
|
+
/** The charset of the font */
|
939
|
+
charset: string[];
|
940
|
+
/** The charset is unicode */
|
941
|
+
unicode: number;
|
942
|
+
/** The font height stretch in percentage. 100% means no stretch. */
|
943
|
+
stretchH: number;
|
944
|
+
/** Set to 1 if smoothing was turned on. */
|
945
|
+
smooth: number;
|
946
|
+
/** The supersampling level used. 1 means no supersampling was used. */
|
947
|
+
aa: number;
|
948
|
+
/** The padding for each character (up, right, down, left). */
|
949
|
+
padding: [number, number, number, number];
|
950
|
+
/** The spacing for each character (horizontal, vertical). */
|
951
|
+
spacing: [number, number];
|
952
|
+
/**
|
953
|
+
* The outline thickness for the characters.
|
954
|
+
*
|
955
|
+
* @remark missing in msdf-bmfont-xml
|
956
|
+
*/
|
957
|
+
outline?: number;
|
958
|
+
};
|
959
|
+
/**
|
960
|
+
* Holds information common to all characters.
|
961
|
+
*/
|
962
|
+
export type BMFontCommon = {
|
963
|
+
/** Distance in pixels between each line of text */
|
964
|
+
lineHeight: number;
|
965
|
+
/** The number of pixels from the absolute top of the line to the base of the characters */
|
966
|
+
base: number;
|
967
|
+
/** The width of the texture, normally used to scale the x pos of the character image */
|
968
|
+
scaleW: number;
|
969
|
+
/** The height of the texture, normally used to scale the y pos of the character image */
|
970
|
+
scaleH: number;
|
971
|
+
/** The number of pages in the font */
|
972
|
+
pages: number;
|
973
|
+
/** Set to 1 if the monochrome characters have been packed into each of the texture channels. In this case alphaChnl describes what is stored in each channel. */
|
974
|
+
packed: number;
|
975
|
+
/** Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. */
|
976
|
+
alphaChnl: number;
|
977
|
+
/** Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. */
|
978
|
+
redChnl: number;
|
979
|
+
/** Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. */
|
980
|
+
greenChnl: number;
|
981
|
+
/** Set to 0 if the channel holds the glyph data, 1 if it holds the outline, 2 if it holds the glyph and the outline, 3 if its set to zero, and 4 if its set to one. */
|
982
|
+
blueChnl: number;
|
983
|
+
};
|
984
|
+
/** Name of a texture file. There is one for each page in the font. */
|
985
|
+
export type BMFontPages = {
|
986
|
+
[id: number]: string;
|
987
|
+
} & Array<string>;
|
988
|
+
/**
|
989
|
+
* Describes a single character in the font
|
990
|
+
*/
|
991
|
+
export type BMFontChar = {
|
992
|
+
/** Character id (charCode) */
|
993
|
+
id: number;
|
994
|
+
/** Left position of the character image in the texture. */
|
995
|
+
x: number;
|
996
|
+
/** Right position of the character image in the texture */
|
997
|
+
y: number;
|
998
|
+
/** Width of the chracter image in the texture */
|
999
|
+
width: number;
|
1000
|
+
/** Height of the chracter image in the texture */
|
1001
|
+
height: number;
|
1002
|
+
/** Horizontal offset to be applied on screen */
|
1003
|
+
xoffset: number;
|
1004
|
+
/** Vertical offset to be applied on screen */
|
1005
|
+
yoffset: number;
|
1006
|
+
/** Horizontal advance after the character */
|
1007
|
+
xadvance: number;
|
1008
|
+
/** Page index where the character image is found */
|
1009
|
+
page: number;
|
1010
|
+
/** Texture channel where the chracter image is found
|
1011
|
+
* - 1 = blue
|
1012
|
+
* - 2 = green
|
1013
|
+
* - 3 = red
|
1014
|
+
* - 8 = alpha
|
1015
|
+
* - 15 = all channels
|
1016
|
+
*/
|
1017
|
+
chnl: number;
|
1018
|
+
} & BMFontCharExtra;
|
1019
|
+
/**
|
1020
|
+
* additional context from msdf-bmfont-xml
|
1021
|
+
*/
|
1022
|
+
export type BMFontCharExtra = {
|
1023
|
+
/** index of opentype.js glyph */
|
1024
|
+
index: number;
|
1025
|
+
/** actual character*/
|
1026
|
+
char: string;
|
1027
|
+
};
|
1028
|
+
/**
|
1029
|
+
* The kerning information is used to adjust the distance between certain characters, e.g. some characters should be placed closer to each other than others.
|
1030
|
+
*/
|
1031
|
+
export type BMFontKerning = {
|
1032
|
+
/** The first character id. */
|
1033
|
+
first: number;
|
1034
|
+
/** The second character id. */
|
1035
|
+
second: number;
|
1036
|
+
/** How much the x position should be adjusted when drawing the second character immediately following the first. */
|
1037
|
+
amount: number;
|
1038
|
+
};
|
1039
|
+
/**
|
1040
|
+
* Compatible with [msdf-bmfont-xml](https://github.com/soimy/msdf-bmfont-xml)
|
1041
|
+
* @see https://www.angelcode.com/products/bmfont/doc/file_format.html
|
1042
|
+
*/
|
1043
|
+
export type BMFont = {
|
1044
|
+
/** {@inheritDoc BMFontInfo} */
|
1045
|
+
info: BMFontInfo;
|
1046
|
+
/** {@inheritDoc BMFontCommon} */
|
1047
|
+
common: BMFontCommon;
|
1048
|
+
/** {@inheritDoc BMFontPages} */
|
1049
|
+
pages: BMFontPages;
|
1050
|
+
/** {@inheritDoc BMFontChar} */
|
1051
|
+
chars: BMFontChar[];
|
1052
|
+
/** {@inheritDoc BMFontKerning} */
|
1053
|
+
kernings: BMFontKerning[];
|
1054
|
+
};
|
1055
|
+
|
1056
|
+
|
318
1057
|
/**
|
319
1058
|
* BABYLON.Behavior for any content that can capture pointer events, i.e. bypass the Babylon pointer event handling
|
320
1059
|
* and receive pointer events directly. It will register the capture triggers and negotiate the capture and
|