meshwriter-cudu 3.0.0 → 3.0.3
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/meshwriter.cjs.js +103 -39
- package/dist/meshwriter.cjs.js.map +1 -1
- package/dist/meshwriter.esm.js +103 -39
- package/dist/meshwriter.esm.js.map +1 -1
- package/dist/meshwriter.min.js +1 -1
- package/dist/meshwriter.min.js.map +1 -1
- package/dist/meshwriter.umd.js +103 -39
- package/dist/meshwriter.umd.js.map +1 -1
- package/dist/src/fogPlugin.d.ts +30 -4
- package/package.json +6 -3
- package/src/fogPlugin.js +91 -30
- package/src/material.js +12 -9
- package/dist/index.d.ts +0 -295
- package/dist/src/variableFontCache.d.ts +0 -56
- package/dist/src/variableFontConverter.d.ts +0 -21
- package/dist/src/variableFontLoader.d.ts +0 -99
package/dist/src/fogPlugin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Plugin that applies scene fog to text materials
|
|
3
|
-
*
|
|
2
|
+
* Plugin that applies scene fog to text materials uniformly.
|
|
3
|
+
* Handles fog for both diffuse and emissive components in one pass.
|
|
4
4
|
*/
|
|
5
5
|
export class TextFogPlugin extends MaterialPluginBase {
|
|
6
6
|
/**
|
|
@@ -14,19 +14,45 @@ export class TextFogPlugin extends MaterialPluginBase {
|
|
|
14
14
|
* @param {import('@babylonjs/core/Meshes/mesh').Mesh} mesh
|
|
15
15
|
*/
|
|
16
16
|
prepareDefines(defines: object, scene: import("@babylonjs/core/scene").Scene, mesh: import("@babylonjs/core/Meshes/mesh").Mesh): void;
|
|
17
|
+
/**
|
|
18
|
+
* Define our own fog uniforms since material.fogEnabled = false
|
|
19
|
+
* means Babylon's built-in fog uniforms won't be available
|
|
20
|
+
*/
|
|
17
21
|
getUniforms(): {
|
|
18
|
-
ubo:
|
|
22
|
+
ubo: {
|
|
23
|
+
name: string;
|
|
24
|
+
size: number;
|
|
25
|
+
type: string;
|
|
26
|
+
}[];
|
|
27
|
+
vertex: string;
|
|
28
|
+
fragment: string;
|
|
19
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Bind fog values from the scene to our custom uniforms
|
|
32
|
+
* @param {import('@babylonjs/core/Materials/uniformBuffer').UniformBuffer} uniformBuffer
|
|
33
|
+
* @param {import('@babylonjs/core/scene').Scene} scene
|
|
34
|
+
* @param {import('@babylonjs/core/Engines/engine').Engine} engine
|
|
35
|
+
* @param {import('@babylonjs/core/Meshes/subMesh').SubMesh} subMesh
|
|
36
|
+
*/
|
|
37
|
+
bindForSubMesh(uniformBuffer: import("@babylonjs/core/Materials/uniformBuffer").UniformBuffer, scene: import("@babylonjs/core/scene").Scene, engine: import("@babylonjs/core/Engines/engine").Engine, subMesh: import("@babylonjs/core/Meshes/subMesh").SubMesh): void;
|
|
20
38
|
/**
|
|
21
39
|
* Clean up the plugin
|
|
22
40
|
*/
|
|
23
41
|
dispose(): void;
|
|
24
42
|
/**
|
|
25
|
-
* Inject shader code to
|
|
43
|
+
* Inject shader code to calculate fog distance and apply fog blending
|
|
26
44
|
* @param {string} shaderType - 'vertex' or 'fragment'
|
|
27
45
|
*/
|
|
28
46
|
getCustomCode(shaderType: string): {
|
|
47
|
+
CUSTOM_VERTEX_DEFINITIONS: string;
|
|
48
|
+
CUSTOM_VERTEX_MAIN_END: string;
|
|
49
|
+
CUSTOM_FRAGMENT_DEFINITIONS?: undefined;
|
|
50
|
+
CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR?: undefined;
|
|
51
|
+
} | {
|
|
52
|
+
CUSTOM_FRAGMENT_DEFINITIONS: string;
|
|
29
53
|
CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: string;
|
|
54
|
+
CUSTOM_VERTEX_DEFINITIONS?: undefined;
|
|
55
|
+
CUSTOM_VERTEX_MAIN_END?: undefined;
|
|
30
56
|
};
|
|
31
57
|
}
|
|
32
58
|
import { MaterialPluginBase } from './babylonImports.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meshwriter-cudu",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
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": [
|
|
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": "^
|
|
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/src/fogPlugin.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TextFogPlugin - MaterialPluginBase that applies fog to
|
|
2
|
+
* TextFogPlugin - MaterialPluginBase that applies fog to text materials
|
|
3
3
|
*
|
|
4
|
-
* Babylon's
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Since we disable Babylon's built-in fog (material.fogEnabled = false) to avoid
|
|
5
|
+
* double-fogging of diffuse colors, this plugin handles ALL fog application.
|
|
6
|
+
* It supplies its own uniforms and varyings to calculate fog distance and blend.
|
|
7
|
+
*
|
|
8
|
+
* This ensures text (with emissive colors) fades into fog at the same rate as
|
|
9
|
+
* terrain (which uses only diffuse colors with standard fog).
|
|
7
10
|
*/
|
|
8
11
|
|
|
9
12
|
import { MaterialPluginBase } from './babylonImports.js';
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
|
-
* Plugin that applies scene fog to text materials
|
|
13
|
-
*
|
|
15
|
+
* Plugin that applies scene fog to text materials uniformly.
|
|
16
|
+
* Handles fog for both diffuse and emissive components in one pass.
|
|
14
17
|
*/
|
|
15
18
|
export class TextFogPlugin extends MaterialPluginBase {
|
|
16
19
|
/**
|
|
@@ -31,6 +34,7 @@ export class TextFogPlugin extends MaterialPluginBase {
|
|
|
31
34
|
*/
|
|
32
35
|
prepareDefines(defines, scene, mesh) {
|
|
33
36
|
// Enable when scene has any fog mode set (1=LINEAR, 2=EXP, 3=EXP2)
|
|
37
|
+
// This is independent of material.fogEnabled since we handle fog ourselves
|
|
34
38
|
defines['MESHWRITER_TEXT_FOG'] = scene.fogMode !== 0;
|
|
35
39
|
}
|
|
36
40
|
|
|
@@ -38,10 +42,45 @@ export class TextFogPlugin extends MaterialPluginBase {
|
|
|
38
42
|
return 'TextFogPlugin';
|
|
39
43
|
}
|
|
40
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Define our own fog uniforms since material.fogEnabled = false
|
|
47
|
+
* means Babylon's built-in fog uniforms won't be available
|
|
48
|
+
*/
|
|
41
49
|
getUniforms() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
return {
|
|
51
|
+
ubo: [
|
|
52
|
+
{ name: 'textFogInfos', size: 4, type: 'vec4' },
|
|
53
|
+
{ name: 'textFogColor', size: 3, type: 'vec3' }
|
|
54
|
+
],
|
|
55
|
+
vertex: '',
|
|
56
|
+
fragment: ''
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Bind fog values from the scene to our custom uniforms
|
|
62
|
+
* @param {import('@babylonjs/core/Materials/uniformBuffer').UniformBuffer} uniformBuffer
|
|
63
|
+
* @param {import('@babylonjs/core/scene').Scene} scene
|
|
64
|
+
* @param {import('@babylonjs/core/Engines/engine').Engine} engine
|
|
65
|
+
* @param {import('@babylonjs/core/Meshes/subMesh').SubMesh} subMesh
|
|
66
|
+
*/
|
|
67
|
+
bindForSubMesh(uniformBuffer, scene, engine, subMesh) {
|
|
68
|
+
if (scene.fogMode === 0) return;
|
|
69
|
+
|
|
70
|
+
// textFogInfos: x=fogMode, y=fogStart, z=fogEnd, w=fogDensity
|
|
71
|
+
uniformBuffer.updateFloat4(
|
|
72
|
+
'textFogInfos',
|
|
73
|
+
scene.fogMode,
|
|
74
|
+
scene.fogStart,
|
|
75
|
+
scene.fogEnd,
|
|
76
|
+
scene.fogDensity
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// textFogColor: RGB color of the fog
|
|
80
|
+
uniformBuffer.updateColor3(
|
|
81
|
+
'textFogColor',
|
|
82
|
+
scene.fogColor
|
|
83
|
+
);
|
|
45
84
|
}
|
|
46
85
|
|
|
47
86
|
/**
|
|
@@ -52,47 +91,69 @@ export class TextFogPlugin extends MaterialPluginBase {
|
|
|
52
91
|
}
|
|
53
92
|
|
|
54
93
|
/**
|
|
55
|
-
* Inject shader code to
|
|
94
|
+
* Inject shader code to calculate fog distance and apply fog blending
|
|
56
95
|
* @param {string} shaderType - 'vertex' or 'fragment'
|
|
57
96
|
*/
|
|
58
97
|
getCustomCode(shaderType) {
|
|
98
|
+
if (shaderType === 'vertex') {
|
|
99
|
+
return {
|
|
100
|
+
// Declare our varying for fog distance
|
|
101
|
+
'CUSTOM_VERTEX_DEFINITIONS': `
|
|
102
|
+
#ifdef MESHWRITER_TEXT_FOG
|
|
103
|
+
varying vec3 textFogDistance;
|
|
104
|
+
#endif
|
|
105
|
+
`,
|
|
106
|
+
// Calculate fog distance in view space at end of vertex shader
|
|
107
|
+
// finalWorld and positionUpdated are Babylon's built-in variables
|
|
108
|
+
'CUSTOM_VERTEX_MAIN_END': `
|
|
109
|
+
#ifdef MESHWRITER_TEXT_FOG
|
|
110
|
+
vec4 textWorldPos = finalWorld * vec4(positionUpdated, 1.0);
|
|
111
|
+
textFogDistance = (view * textWorldPos).xyz;
|
|
112
|
+
#endif
|
|
113
|
+
`
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
59
117
|
if (shaderType === 'fragment') {
|
|
60
118
|
return {
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
119
|
+
// Declare uniforms and varying in fragment shader
|
|
120
|
+
'CUSTOM_FRAGMENT_DEFINITIONS': `
|
|
121
|
+
#ifdef MESHWRITER_TEXT_FOG
|
|
122
|
+
uniform vec4 textFogInfos;
|
|
123
|
+
uniform vec3 textFogColor;
|
|
124
|
+
varying vec3 textFogDistance;
|
|
125
|
+
#endif
|
|
126
|
+
`,
|
|
127
|
+
// Apply fog to the entire fragment color before final output
|
|
128
|
+
// This runs just before gl_FragColor is set
|
|
65
129
|
'CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR': `
|
|
66
130
|
#ifdef MESHWRITER_TEXT_FOG
|
|
67
|
-
|
|
68
|
-
//
|
|
69
|
-
// vFogInfos: x=fogMode, y=fogStart, z=fogEnd, w=fogDensity
|
|
70
|
-
// vFogColor: fog RGB color
|
|
71
|
-
// vFogDistance: vec3 distance from camera (set by vertex shader)
|
|
131
|
+
// textFogInfos: x=fogMode, y=fogStart, z=fogEnd, w=fogDensity
|
|
132
|
+
// Fog modes: 1=LINEAR, 2=EXP, 3=EXP2
|
|
72
133
|
|
|
73
134
|
float textFogFactor = 1.0;
|
|
74
|
-
float textFogDist = length(
|
|
135
|
+
float textFogDist = length(textFogDistance);
|
|
75
136
|
|
|
76
|
-
if (
|
|
137
|
+
if (textFogInfos.x == 1.0) {
|
|
77
138
|
// Linear fog: factor = (end - dist) / (end - start)
|
|
78
|
-
textFogFactor = clamp((
|
|
79
|
-
} else if (
|
|
139
|
+
textFogFactor = clamp((textFogInfos.z - textFogDist) / (textFogInfos.z - textFogInfos.y), 0.0, 1.0);
|
|
140
|
+
} else if (textFogInfos.x == 2.0) {
|
|
80
141
|
// Exponential fog: factor = exp(-dist * density)
|
|
81
|
-
textFogFactor = clamp(exp(-textFogDist *
|
|
82
|
-
} else if (
|
|
142
|
+
textFogFactor = clamp(exp(-textFogDist * textFogInfos.w), 0.0, 1.0);
|
|
143
|
+
} else if (textFogInfos.x == 3.0) {
|
|
83
144
|
// Exponential squared fog: factor = exp(-(dist * density)^2)
|
|
84
|
-
float fogDistDensity = textFogDist *
|
|
145
|
+
float fogDistDensity = textFogDist * textFogInfos.w;
|
|
85
146
|
textFogFactor = clamp(exp(-fogDistDensity * fogDistDensity), 0.0, 1.0);
|
|
86
147
|
}
|
|
87
148
|
|
|
88
|
-
// Blend the entire fragment (
|
|
149
|
+
// Blend the entire fragment (diffuse + emissive) toward fog color
|
|
89
150
|
// textFogFactor: 1.0 = no fog (full color), 0.0 = full fog
|
|
90
|
-
color.rgb = mix(
|
|
151
|
+
color.rgb = mix(textFogColor, color.rgb, textFogFactor);
|
|
91
152
|
#endif
|
|
92
|
-
|
|
93
|
-
`,
|
|
153
|
+
`
|
|
94
154
|
};
|
|
95
155
|
}
|
|
156
|
+
|
|
96
157
|
return null;
|
|
97
158
|
}
|
|
98
159
|
}
|
package/src/material.js
CHANGED
|
@@ -61,15 +61,17 @@ export function makeMaterial(scene, letters, emissive, ambient, specular, diffus
|
|
|
61
61
|
// Emissive-only materials should be self-lit and not affected by fog
|
|
62
62
|
if (emissiveOnly) {
|
|
63
63
|
material.fogEnabled = false;
|
|
64
|
+
} else if (fogEnabled) {
|
|
65
|
+
// IMPORTANT: Disable Babylon's built-in fog when using TextFogPlugin.
|
|
66
|
+
// Built-in fog only affects diffuse/ambient, not emissive.
|
|
67
|
+
// If we left fogEnabled=true, diffuse would be fogged twice (once by Babylon,
|
|
68
|
+
// once by the plugin), while emissive would only be fogged once by the plugin.
|
|
69
|
+
// By disabling built-in fog and handling ALL fog in the plugin, we get uniform
|
|
70
|
+
// fog application to the entire fragment (matching terrain behavior).
|
|
71
|
+
material.fogEnabled = false;
|
|
72
|
+
material._textFogPlugin = new TextFogPlugin(material);
|
|
64
73
|
} else {
|
|
65
|
-
material.fogEnabled =
|
|
66
|
-
// Attach fog plugin to properly blend emissive color with fog
|
|
67
|
-
// Babylon's standard fog only affects diffuse/ambient, not emissive.
|
|
68
|
-
// The plugin re-fogs the entire fragment output so emissive fades properly.
|
|
69
|
-
// (The slight double-fog on diffuse/ambient is negligible since text is primarily emissive)
|
|
70
|
-
if (fogEnabled) {
|
|
71
|
-
material._textFogPlugin = new TextFogPlugin(material);
|
|
72
|
-
}
|
|
74
|
+
material.fogEnabled = false;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
return material;
|
|
@@ -95,7 +97,8 @@ export function makeFaceMaterial(scene, letters, emissive, opac, fogEnabled = tr
|
|
|
95
97
|
material.disableLighting = true;
|
|
96
98
|
material.alpha = opac;
|
|
97
99
|
material.backFaceCulling = false;
|
|
98
|
-
|
|
100
|
+
// Disable Babylon's built-in fog - TextFogPlugin handles all fog uniformly
|
|
101
|
+
material.fogEnabled = false;
|
|
99
102
|
if (fogEnabled) {
|
|
100
103
|
material._textFogPlugin = new TextFogPlugin(material);
|
|
101
104
|
}
|
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;
|