meshwriter-cudu 3.0.0 → 3.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meshwriter-cudu",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Modern 3D text rendering for Babylon.js with variable font weights and accessibility features",
5
5
  "type": "module",
6
6
  "main": "./dist/meshwriter.cjs.js",
@@ -40,7 +40,10 @@
40
40
  "typescript",
41
41
  "esm"
42
42
  ],
43
- "authors": ["Brian T Button","Cullen Dudas"],
43
+ "authors": [
44
+ "Brian T Button",
45
+ "Cullen Dudas"
46
+ ],
44
47
  "license": "MIT",
45
48
  "peerDependencies": {
46
49
  "@babylonjs/core": ">=6.0.0",
@@ -56,7 +59,7 @@
56
59
  },
57
60
  "devDependencies": {
58
61
  "@babylonjs/core": "^8.0.0",
59
- "@rollup/plugin-commonjs": "^28.0.0",
62
+ "@rollup/plugin-commonjs": "^29.0.0",
60
63
  "@rollup/plugin-node-resolve": "^16.0.0",
61
64
  "@rollup/plugin-terser": "^0.4.0",
62
65
  "earcut": "^3.0.2",
package/dist/index.d.ts DELETED
@@ -1,295 +0,0 @@
1
- /**
2
- * MeshWriter Type Declarations
3
- * Provides TypeScript types for MeshWriter library
4
- *
5
- * Requires: @babylonjs/core (peer dependency)
6
- */
7
-
8
- import type { Scene } from '@babylonjs/core/scene';
9
- import type { Mesh } from '@babylonjs/core/Meshes/mesh';
10
- import type { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';
11
- import type { SolidParticleSystem } from '@babylonjs/core/Particles/solidParticleSystem';
12
- import type { Vector2 } from '@babylonjs/core/Maths/math.vector';
13
-
14
- // ============ Options & Configuration Types ============
15
-
16
- /** Position configuration for text placement */
17
- export interface MeshWriterPosition {
18
- x?: number;
19
- y?: number;
20
- z?: number;
21
- }
22
-
23
- /** Color configuration for material properties */
24
- export interface MeshWriterColors {
25
- diffuse?: string;
26
- specular?: string;
27
- ambient?: string;
28
- emissive?: string;
29
- }
30
-
31
- /** Options for creating text with MeshWriter */
32
- export interface MeshWriterOptions {
33
- /** Position of the text in 3D space */
34
- position?: MeshWriterPosition;
35
- /** Material color properties */
36
- colors?: MeshWriterColors;
37
- /** Font family name (must be registered first) */
38
- 'font-family'?: string;
39
- /** Text anchor point */
40
- anchor?: 'left' | 'right' | 'center';
41
- /** Height of letters in world units */
42
- 'letter-height'?: number;
43
- /** Thickness (depth) of letters in world units */
44
- 'letter-thickness'?: number;
45
- /** Emissive color as hex string (e.g., "#FF0000") */
46
- color?: string;
47
- /** Material alpha/transparency (0-1) */
48
- alpha?: number;
49
- /** If true, disables lighting (only emissive color shows) - gives self-lit appearance */
50
- 'emissive-only'?: boolean;
51
- /** If true, the material is affected by scene fog (default: true) */
52
- 'fog-enabled'?: boolean;
53
- }
54
-
55
- /** Babylon namespace subset used for CSG injection */
56
- export interface BabylonCSGNamespace {
57
- CSG?: unknown;
58
- CSG2?: unknown;
59
- InitializeCSG2Async?: () => void | Promise<void>;
60
- IsCSG2Ready?: () => boolean;
61
- }
62
-
63
- /** Preferences for initializing MeshWriter */
64
- export interface MeshWriterPreferences {
65
- /** Default font family name */
66
- defaultFont?: string;
67
- /** Scale factor for all text */
68
- scale?: number;
69
- /** Origin point for mesh positioning */
70
- meshOrigin?: 'letterCenter' | 'fontOrigin';
71
- /** Enable debug logging */
72
- debug?: boolean;
73
- /** Babylon namespace providing CSG helpers (used for ES module builds) */
74
- babylon?: BabylonCSGNamespace;
75
- }
76
-
77
- // ============ Instance Types ============
78
-
79
- /** A text instance created by MeshWriter */
80
- export interface MeshWriterInstance {
81
- /** Get the SolidParticleSystem containing letter meshes */
82
- getSPS(): SolidParticleSystem | undefined;
83
- /** Get the combined mesh containing all letters */
84
- getMesh(): Mesh | undefined;
85
- /** Get the material applied to the text */
86
- getMaterial(): StandardMaterial;
87
- /** Get the X offset for anchoring */
88
- getOffsetX(): number;
89
- /** Get bounding boxes for each letter */
90
- getLettersBoxes(): number[][];
91
- /** Get origin positions for each letter */
92
- getLettersOrigins(): number[][];
93
- /** Get or set the emissive color */
94
- color(c?: string): string;
95
- /** Get or set the alpha value */
96
- alpha(a?: number): number;
97
- /** Update the emissive color */
98
- setColor(color: string): void;
99
- /** Update the alpha value */
100
- setAlpha(alpha: number): void;
101
- /** Temporarily override alpha */
102
- overrideAlpha(alpha: number): void;
103
- /** Reset alpha to original value */
104
- resetAlpha(): void;
105
- /** Get the center position of a letter by index */
106
- getLetterCenter(ix: number): Vector2;
107
- /** Check if this instance has been disposed */
108
- isDisposed(): boolean;
109
- /** Dispose of all meshes and materials */
110
- dispose(): void;
111
- }
112
-
113
- /** Constructor function returned by MeshWriter factory */
114
- export interface MeshWriterConstructor {
115
- new (letters: string, options?: MeshWriterOptions): MeshWriterInstance;
116
- (letters: string, options?: MeshWriterOptions): MeshWriterInstance;
117
- }
118
-
119
- // ============ Font Types ============
120
-
121
- /** Individual glyph specification */
122
- export interface GlyphSpec {
123
- /** Compressed shape command strings (pre-decompression) */
124
- sC?: string[];
125
- /** Compressed hole command strings - array of holes, each hole is array of command strings */
126
- hC?: string[][];
127
- /** Decompressed shape commands (post-decompression, internal use) */
128
- shapeCmds?: number[][][];
129
- /** Decompressed hole commands (post-decompression, internal use) */
130
- holeCmds?: number[][][][];
131
- /** Minimum X coordinate of bounding box */
132
- xMin: number;
133
- /** Maximum X coordinate of bounding box */
134
- xMax: number;
135
- /** Minimum Y coordinate of bounding box */
136
- yMin: number;
137
- /** Maximum Y coordinate of bounding box */
138
- yMax: number;
139
- /** Character advance width */
140
- wdth: number;
141
- /** X coordinate scale factor (optional) */
142
- xFactor?: number;
143
- /** Y coordinate scale factor (optional) */
144
- yFactor?: number;
145
- /** X coordinate shift (optional) */
146
- xShift?: number;
147
- /** Y coordinate shift (optional) */
148
- yShift?: number;
149
- /** Per-glyph reverse shape override (optional) */
150
- reverseShape?: boolean;
151
- /** Per-glyph reverse hole override (optional) */
152
- reverseHole?: boolean;
153
- }
154
-
155
- /** Font specification object containing glyph data */
156
- export interface FontSpec {
157
- /** Whether to reverse hole winding (default for all glyphs) */
158
- reverseHoles: boolean;
159
- /** Whether to reverse shape winding (default for all glyphs) */
160
- reverseShapes: boolean;
161
- /** Character glyph data - indexed by character */
162
- [character: string]: GlyphSpec | boolean;
163
- }
164
-
165
- /**
166
- * Function that creates font spec from codeList encoder
167
- * @deprecated Use FontSpec directly instead of FontFactory
168
- */
169
- export type FontFactory = (codeList: (list: number[][]) => string) => FontSpec;
170
-
171
- /** Font data - either a FontSpec object or a FontFactory function (legacy) */
172
- export type FontData = FontSpec | FontFactory;
173
-
174
- // ============ Main API Types ============
175
-
176
- /** CSG version used for boolean operations */
177
- export type CSGVersion = 'CSG' | 'CSG2' | null;
178
-
179
- /** MeshWriter static API */
180
- export interface MeshWriterStatic {
181
- /**
182
- * Create a MeshWriter constructor asynchronously (required for Babylon 8+)
183
- * Initializes CSG2 before returning
184
- */
185
- createAsync(scene: Scene, preferences?: MeshWriterPreferences): Promise<MeshWriterConstructor>;
186
-
187
- /**
188
- * Create a MeshWriter constructor synchronously (legacy, Babylon < 7.31)
189
- * @deprecated Use createAsync for Babylon 8+
190
- */
191
- create(scene: Scene, preferences?: MeshWriterPreferences): MeshWriterConstructor;
192
-
193
- /** Check if CSG is initialized and ready */
194
- isReady(): boolean;
195
-
196
- /** Get the CSG version being used */
197
- getCSGVersion(): CSGVersion;
198
-
199
- /** Set a custom CSG2 initializer function */
200
- setCSGInitializer(init: () => void | Promise<void>): void;
201
-
202
- /** Set a custom CSG ready check function */
203
- setCSGReadyCheck(check: () => boolean): void;
204
-
205
- /** Register a callback to run when CSG is ready */
206
- onCSGReady(callback: () => void): void;
207
-
208
- /** Manually mark CSG as ready */
209
- markCSGReady(): void;
210
- /** Initialize the internal CSG module with Babylon helpers */
211
- initCSGModule(babylon: BabylonCSGNamespace): void;
212
-
213
- /** Register a font for use with MeshWriter */
214
- registerFont(name: string, fontData: FontData): void;
215
-
216
- /** Register multiple font aliases pointing to the same font */
217
- registerFontAliases(targetName: string, ...aliases: string[]): void;
218
-
219
- /** Get a registered font by name */
220
- getFont(name: string): FontSpec | undefined;
221
-
222
- /** Check if a font is registered */
223
- isFontRegistered(name: string): boolean;
224
-
225
- /** Encode font coordinates to compressed string */
226
- codeList(list: number[][]): string;
227
-
228
- /** Decode compressed string to font coordinates */
229
- decodeList(encoded: string): number[][];
230
- }
231
-
232
- // ============ Exports ============
233
-
234
- /** Main MeshWriter object with all static methods */
235
- export const MeshWriter: MeshWriterStatic;
236
-
237
- /** Create a MeshWriter constructor asynchronously */
238
- export function createMeshWriterAsync(scene: Scene, preferences?: MeshWriterPreferences): Promise<MeshWriterConstructor>;
239
-
240
- /** Create a MeshWriter constructor synchronously (legacy) */
241
- export function createMeshWriter(scene: Scene, preferences?: MeshWriterPreferences): MeshWriterConstructor;
242
-
243
- /** Check if CSG is initialized and ready */
244
- export function isCSGReady(): boolean;
245
-
246
- /** Get the CSG version being used */
247
- export function getCSGVersion(): CSGVersion;
248
-
249
- /** Set a custom CSG2 initializer function */
250
- export function setCSGInitializer(init: () => void | Promise<void>): void;
251
-
252
- /** Set a custom CSG ready check function */
253
- export function setCSGReadyCheck(check: () => boolean): void;
254
-
255
- /** Register a callback to run when CSG is ready */
256
- export function onCSGReady(callback: () => void): void;
257
-
258
- /** Manually mark CSG as ready */
259
- export function markCSGReady(): void;
260
-
261
- /** Register a font for use with MeshWriter */
262
- export function registerFont(name: string, fontData: FontData): void;
263
-
264
- /** Register multiple font aliases */
265
- export function registerFontAliases(targetName: string, ...aliases: string[]): void;
266
-
267
- /** Get a registered font by name */
268
- export function getFont(name: string): FontSpec | undefined;
269
-
270
- /** Check if a font is registered */
271
- export function isFontRegistered(name: string): boolean;
272
-
273
- /** Encode font coordinates to compressed string */
274
- export function codeList(list: number[][]): string;
275
-
276
- /** Decode compressed string to font coordinates */
277
- export function decodeList(encoded: string): number[][];
278
-
279
- /** Get list of registered font names */
280
- export function getRegisteredFonts(): string[];
281
-
282
- /** Unregister a font (primarily for testing) */
283
- export function unregisterFont(name: string): void;
284
-
285
- /** Clear all registered fonts (primarily for testing) */
286
- export function clearFonts(): void;
287
-
288
- /** Encode font coordinates (alias of codeList) */
289
- export function encodeFontData(list: number[][]): string;
290
-
291
- /** Decode font coordinates (alias of decodeList) */
292
- export function decodeFontData(encoded: string): number[][];
293
-
294
- /** Initialize the internal CSG module with Babylon helpers */
295
- export function initCSGModule(babylon: BabylonCSGNamespace): void;
@@ -1,56 +0,0 @@
1
- /**
2
- * Create a cache key for a glyph at a specific weight
3
- * @param {number} weight - Font weight value
4
- * @param {string} char - Character
5
- * @returns {string} - Cache key
6
- */
7
- export function createGlyphCacheKey(weight: number, char: string): string;
8
- /**
9
- * MeshWriter Variable Font Cache
10
- * LRU cache for variable font glyphs to prevent memory bloat
11
- */
12
- /**
13
- * LRU Cache for glyph specifications
14
- * Prevents memory bloat when using many weight variations
15
- */
16
- export class GlyphCache {
17
- /**
18
- * Create a new glyph cache
19
- * @param {number} [maxSize=5000] - Maximum number of cached entries
20
- */
21
- constructor(maxSize?: number);
22
- _maxSize: number;
23
- _cache: Map<any, any>;
24
- /**
25
- * Get a cached value (moves it to most recently used)
26
- * @param {string} key - Cache key
27
- * @returns {*} - Cached value or undefined
28
- */
29
- get(key: string): any;
30
- /**
31
- * Set a cache value (evicts oldest if at capacity)
32
- * @param {string} key - Cache key
33
- * @param {*} value - Value to cache
34
- */
35
- set(key: string, value: any): void;
36
- /**
37
- * Check if key exists in cache
38
- * @param {string} key - Cache key
39
- * @returns {boolean}
40
- */
41
- has(key: string): boolean;
42
- /**
43
- * Clear all cached entries
44
- */
45
- clear(): void;
46
- /**
47
- * Get current cache size
48
- * @returns {number}
49
- */
50
- get size(): number;
51
- /**
52
- * Get maximum cache size
53
- * @returns {number}
54
- */
55
- get maxSize(): number;
56
- }
@@ -1,21 +0,0 @@
1
- /**
2
- * MeshWriter Variable Font Converter
3
- * Converts fontkit glyph paths to MeshWriter FontSpec format at runtime
4
- */
5
- /**
6
- * Convert fontkit glyph to MeshWriter GlyphSpec
7
- * @param {object} glyph - fontkit glyph object
8
- * @param {number} [scale=1] - Scale factor
9
- * @returns {object|null} - GlyphSpec with shapeCmds/holeCmds, or null if empty
10
- */
11
- export function convertFontkitGlyphToSpec(glyph: object, scale?: number): object | null;
12
- /**
13
- * Extract kerning pairs from fontkit font for given character set
14
- * @param {object} font - fontkit font object
15
- * @param {string} charset - Characters to extract kerning for
16
- * @param {number} [scale=1] - Scale factor
17
- * @returns {object} - Kerning table mapping "char1,char2" to adjustment value
18
- */
19
- export function extractFontkitKerningPairs(font: object, charset: string, scale?: number): object;
20
- export function convertGlyphToSpec(glyph: any, scale?: number): any;
21
- export function extractKerningPairs(font: any, charset: any, scale?: number): any;
@@ -1,99 +0,0 @@
1
- /**
2
- * Load and parse a variable font from URL
3
- * @param {string} url - URL to TTF or WOFF2 file
4
- * @param {object} [options] - Loading options
5
- * @param {number} [options.cacheSize=5000] - Maximum glyph cache size
6
- * @param {number} [options.maxVariations=10] - Maximum cached weight variations
7
- * @returns {Promise<VariableFontHandle>}
8
- */
9
- export function loadVariableFont(url: string, options?: {
10
- cacheSize?: number;
11
- maxVariations?: number;
12
- }): Promise<VariableFontHandle>;
13
- export const DEFAULT_CHARSET: string;
14
- /**
15
- * Handle for a loaded variable font
16
- * Provides methods to generate FontSpec at different weights
17
- */
18
- export class VariableFontHandle {
19
- /**
20
- * @param {object} font - fontkit font object
21
- * @param {object} fontkit - fontkit module reference
22
- * @param {string} url - Source URL
23
- * @param {object} axisInfo - Axis information
24
- * @param {boolean} isVariable - Whether font is actually variable
25
- * @param {number} cacheSize - Maximum glyph cache size
26
- * @param {number} maxVariations - Maximum cached weight variations
27
- */
28
- constructor(font: object, fontkit: object, url: string, axisInfo: object, isVariable: boolean, cacheSize: number, maxVariations: number);
29
- _baseFont: any;
30
- _fontkit: any;
31
- _url: string;
32
- _axisInfo: any;
33
- _isVariable: boolean;
34
- _glyphCache: GlyphCache;
35
- _kerningCache: Map<any, any>;
36
- _fontCache: Map<any, any>;
37
- _maxVariations: number;
38
- _reverseShapes: boolean;
39
- _reverseHoles: boolean;
40
- /**
41
- * Get axis information for this font
42
- * @returns {object} - Axis info with weight min/max/default
43
- */
44
- getAxisInfo(): object;
45
- /**
46
- * Get the source URL
47
- * @returns {string}
48
- */
49
- getUrl(): string;
50
- /**
51
- * Check if this is actually a variable font
52
- * @returns {boolean}
53
- */
54
- isVariable(): boolean;
55
- /**
56
- * Get or create a font instance at the specified weight
57
- * @param {number} weight - Weight value
58
- * @returns {object} - fontkit font instance
59
- */
60
- _getFontAtWeight(weight: number): object;
61
- /**
62
- * Generate FontSpec for a specific weight
63
- * @param {number} weight - Weight value (100-900 for most fonts)
64
- * @param {string} [charset] - Characters to include (default: Latin + symbols)
65
- * @returns {object} - FontSpec compatible with MeshWriter
66
- */
67
- generateFontSpec(weight: number, charset?: string): object;
68
- /**
69
- * Get or create a cached glyph specification
70
- * @param {object} font - fontkit font instance at specific weight
71
- * @param {string} char - Character
72
- * @param {number} weight - Weight value
73
- * @returns {object|null} - GlyphSpec or null if glyph not found
74
- */
75
- _getOrCreateGlyph(font: object, char: string, weight: number): object | null;
76
- /**
77
- * Clear all cached glyphs and font instances
78
- * Call this when changing weight frequently to free memory
79
- */
80
- clearCache(): void;
81
- /**
82
- * Get current cache statistics
83
- * @returns {{ glyphCount: number, kerningCount: number, fontCount: number, maxSize: number, maxVariations: number }}
84
- */
85
- getCacheStats(): {
86
- glyphCount: number;
87
- kerningCount: number;
88
- fontCount: number;
89
- maxSize: number;
90
- maxVariations: number;
91
- };
92
- /**
93
- * Ensure a cache map respects the max variations limit (simple LRU)
94
- * @param {Map} map
95
- * @private
96
- */
97
- private _evictIfNeeded;
98
- }
99
- import { GlyphCache } from './variableFontCache.js';