@mlightcad/mtext-renderer 0.4.4 → 0.4.6
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/README.md +249 -0
- package/dist/assets/mtextWorker-BlkfNPdt.js +7 -0
- package/dist/index.js +1811 -1420
- package/dist/index.umd.cjs +3 -3
- package/{dist → lib}/font/baseFont.d.ts +12 -0
- package/lib/font/charGeometryCache.d.ts +43 -0
- package/{dist → lib}/font/fontManager.d.ts +16 -0
- package/{dist → lib}/font/meshFont.d.ts +6 -0
- package/{dist → lib}/font/shxFont.d.ts +6 -0
- package/{dist → lib}/font/shxTextShape.d.ts +4 -1
- package/{dist → lib}/index.d.ts +1 -0
- package/lib/worker/base-renderer.d.ts +50 -0
- package/lib/worker/baseRenderer.d.ts +64 -0
- package/lib/worker/index.d.ts +6 -0
- package/lib/worker/main-thread-renderer.d.ts +30 -0
- package/lib/worker/mainThreadRenderer.d.ts +32 -0
- package/lib/worker/mtext-worker.d.ts +1 -0
- package/lib/worker/mtextWorker.d.ts +1 -0
- package/lib/worker/unified-renderer.d.ts +41 -0
- package/lib/worker/unifiedRenderer.d.ts +44 -0
- package/lib/worker/web-worker-renderer.d.ts +115 -0
- package/lib/worker/webWorkerRenderer.d.ts +124 -0
- package/lib/worker/worker-manager.d.ts +113 -0
- package/package.json +4 -3
- /package/{dist → lib}/cache/fontCacheManager.d.ts +0 -0
- /package/{dist → lib}/cache/index.d.ts +0 -0
- /package/{dist → lib}/cache/schema.d.ts +0 -0
- /package/{dist → lib}/common/eventManager.d.ts +0 -0
- /package/{dist → lib}/common/index.d.ts +0 -0
- /package/{dist → lib}/common/utils.d.ts +0 -0
- /package/{dist → lib}/font/baseTextShape.d.ts +0 -0
- /package/{dist → lib}/font/defaultFontLoader.d.ts +0 -0
- /package/{dist → lib}/font/font.d.ts +0 -0
- /package/{dist → lib}/font/fontFactory.d.ts +0 -0
- /package/{dist → lib}/font/fontLoader.d.ts +0 -0
- /package/{dist → lib}/font/index.d.ts +0 -0
- /package/{dist → lib}/font/meshFontParser.d.ts +0 -0
- /package/{dist → lib}/font/meshTextShape.d.ts +0 -0
- /package/{dist → lib}/font/normalComputationToggle.d.ts +0 -0
- /package/{dist → lib}/renderer/index.d.ts +0 -0
- /package/{dist → lib}/renderer/mtext.d.ts +0 -0
- /package/{dist → lib}/renderer/mtextProcessor.d.ts +0 -0
- /package/{dist → lib}/renderer/styleManager.d.ts +0 -0
- /package/{dist → lib}/renderer/types.d.ts +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseTextShape } from './baseTextShape';
|
|
2
|
+
import { CharGeometryCache } from './charGeometryCache';
|
|
2
3
|
import { FontType } from './font';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -14,6 +15,17 @@ export declare abstract class BaseFont {
|
|
|
14
15
|
* This data is used to render characters and calculate metrics.
|
|
15
16
|
*/
|
|
16
17
|
abstract readonly data: unknown;
|
|
18
|
+
/**
|
|
19
|
+
* Caching of font character geometries to improve text rendering performance.
|
|
20
|
+
*/
|
|
21
|
+
cache: CharGeometryCache;
|
|
22
|
+
constructor();
|
|
23
|
+
/**
|
|
24
|
+
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
25
|
+
* @param char - The character to check
|
|
26
|
+
* @returns True if this font contains glyph of the specified character. Otherwise, return false.
|
|
27
|
+
*/
|
|
28
|
+
abstract hasChar(char: string): boolean;
|
|
17
29
|
/**
|
|
18
30
|
* Record of characters that are not supported by this font.
|
|
19
31
|
* Maps character strings to their occurrence count.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* Manages caching of font character geometries to improve text rendering performance.
|
|
4
|
+
*/
|
|
5
|
+
export declare class CharGeometryCache {
|
|
6
|
+
private cache;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Returns true if the geometry of the specified character exists in the cache.
|
|
10
|
+
* Otherwise, returns false.
|
|
11
|
+
* @param char One character.
|
|
12
|
+
* @param size The font size.
|
|
13
|
+
* @returns True if the geometry of the specified character exists in the cache.
|
|
14
|
+
* Otherwise, returns false.
|
|
15
|
+
*/
|
|
16
|
+
hasGeometry(char: string, size: number): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Get the geometry for a single character from cache if available.
|
|
19
|
+
* The cache key includes both character and size.
|
|
20
|
+
* @param char The character to get geometry from cache.
|
|
21
|
+
* @param size The font size.
|
|
22
|
+
* @returns The geometry for a single character from cache if avaiable.
|
|
23
|
+
* Return undefined if the character not found in cache.
|
|
24
|
+
*/
|
|
25
|
+
getGeometry(char: string, size: number): THREE.BufferGeometry | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Set the geometry to cache for a single character.
|
|
28
|
+
* @param char The character to set geometry for.
|
|
29
|
+
* @param size The font size.
|
|
30
|
+
* @param geometry The geometry to set.
|
|
31
|
+
*/
|
|
32
|
+
setGeometry(char: string, size: number, geometry: THREE.BufferGeometry): void;
|
|
33
|
+
/**
|
|
34
|
+
* Dispose all cached geometries.
|
|
35
|
+
*/
|
|
36
|
+
dispose(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Generates cache key by character and font size.
|
|
39
|
+
* @param char One character.
|
|
40
|
+
* @param size The font size.
|
|
41
|
+
*/
|
|
42
|
+
private generateKey;
|
|
43
|
+
}
|
|
@@ -76,6 +76,22 @@ export declare class FontManager {
|
|
|
76
76
|
* @returns The original font name if found, or the replacement font name if not found
|
|
77
77
|
*/
|
|
78
78
|
findAndReplaceFont(fontName: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Gets font by font name. Return undefined if not found.
|
|
81
|
+
* @param fontName - The font name to find
|
|
82
|
+
* @param recordMissedFonts - Record the font name to property `missedFonts` in this class
|
|
83
|
+
* if the specified font name not found.
|
|
84
|
+
* @returns The font with the specified font name, or undefined if not found
|
|
85
|
+
*/
|
|
86
|
+
getFontByName(fontName: string, recordMissedFonts?: boolean): BaseFont | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Gets the first font which contains the specified character.
|
|
89
|
+
* @param char - The character to get the shape for
|
|
90
|
+
* @param fontName - The name of the font to use
|
|
91
|
+
* @param size - The size of the character
|
|
92
|
+
* @returns The text shape for the character, or undefined if not found
|
|
93
|
+
*/
|
|
94
|
+
getFontByChar(char: string): BaseFont | undefined;
|
|
79
95
|
/**
|
|
80
96
|
* Gets the text shape for a specific character with the specified font and size
|
|
81
97
|
* @param char - The character to get the shape for
|
|
@@ -29,6 +29,12 @@ export declare class MeshFont extends BaseFont {
|
|
|
29
29
|
* @param data - Either a MeshFontData object containing font information or an ArrayBuffer containing raw font data
|
|
30
30
|
*/
|
|
31
31
|
constructor(data: MeshFontData | ArrayBuffer);
|
|
32
|
+
/**
|
|
33
|
+
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
34
|
+
* @param char - The character to check
|
|
35
|
+
* @returns True if this font contains glyph of the specified character. Otherwise, return false.
|
|
36
|
+
*/
|
|
37
|
+
hasChar(char: string): boolean;
|
|
32
38
|
/**
|
|
33
39
|
* Generates shapes for a text string
|
|
34
40
|
* @param text - The text to generate shapes for
|
|
@@ -12,6 +12,12 @@ export declare class ShxFont extends BaseFont {
|
|
|
12
12
|
readonly type = "shx";
|
|
13
13
|
readonly data: ShxFontData;
|
|
14
14
|
constructor(data: ShxFontData | ArrayBuffer);
|
|
15
|
+
/**
|
|
16
|
+
* Return true if this font contains glyph of the specified character. Otherwise, return false.
|
|
17
|
+
* @param char - The character to check
|
|
18
|
+
* @returns True if this font contains glyph of the specified character. Otherwise, return false.
|
|
19
|
+
*/
|
|
20
|
+
hasChar(char: string): boolean;
|
|
15
21
|
generateShapes(text: string, size: number): ShxTextShape[];
|
|
16
22
|
/**
|
|
17
23
|
* SHX font always has fixed scale factor 1.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Point, ShxShape } from '@mlightcad/shx-parser';
|
|
2
2
|
import { BaseTextShape } from './baseTextShape';
|
|
3
|
+
import { ShxFont } from './shxFont';
|
|
3
4
|
|
|
4
5
|
import * as THREE from 'three';
|
|
5
6
|
/**
|
|
@@ -10,12 +11,14 @@ import * as THREE from 'three';
|
|
|
10
11
|
export declare class ShxTextShape extends BaseTextShape {
|
|
11
12
|
/** The shape data for this character */
|
|
12
13
|
private readonly shape;
|
|
14
|
+
private readonly font;
|
|
15
|
+
private readonly fontSize;
|
|
13
16
|
/**
|
|
14
17
|
* Creates a new instance of ShxTextShape
|
|
15
18
|
* @param char - The character this shape represents
|
|
16
19
|
* @param shape - The shape data for this character
|
|
17
20
|
*/
|
|
18
|
-
constructor(char: string, shape: ShxShape);
|
|
21
|
+
constructor(char: string, fontSize: number, shape: ShxShape, font: ShxFont);
|
|
19
22
|
protected calcWidth(): number;
|
|
20
23
|
offset(offset: Point): ShxTextShape;
|
|
21
24
|
/**
|
package/{dist → lib}/index.d.ts
RENAMED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MTextData, TextStyle, ColorSettings } from '../renderer/types';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
/**
|
|
4
|
+
* Defines the common rendering contract for producing Three.js objects from MText content.
|
|
5
|
+
*
|
|
6
|
+
* Implementations may render on the main thread or delegate work to a Web Worker,
|
|
7
|
+
* but they must expose the same high-level API so callers can switch strategies
|
|
8
|
+
* without changing usage.
|
|
9
|
+
*/
|
|
10
|
+
export interface MTextBaseRenderer {
|
|
11
|
+
/**
|
|
12
|
+
* Render the provided MText content into a Three.js object hierarchy.
|
|
13
|
+
*
|
|
14
|
+
* The returned root object contains meshes/lines for glyphs and exposes a
|
|
15
|
+
* bounding box on `object.box` if available.
|
|
16
|
+
*
|
|
17
|
+
* @param mtextContent Structured MText input (text, height, width, position).
|
|
18
|
+
* @param textStyle Text style to apply (font, width factor, oblique, etc.).
|
|
19
|
+
* @param colorSettings Optional color context (ByLayer, ByBlock colors).
|
|
20
|
+
* @returns A Promise resolving to a populated `THREE.Object3D` ready to add to a scene.
|
|
21
|
+
*/
|
|
22
|
+
renderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<THREE.Object3D>;
|
|
23
|
+
/**
|
|
24
|
+
* Ensure the specified fonts are available to the renderer.
|
|
25
|
+
*
|
|
26
|
+
* Implementations should load and cache missing fonts; repeated calls should be cheap.
|
|
27
|
+
*
|
|
28
|
+
* @param fonts Font names to load (without extension for built-ins).
|
|
29
|
+
* @returns A Promise with the list of fonts that were processed.
|
|
30
|
+
*/
|
|
31
|
+
loadFonts(fonts: string[]): Promise<{
|
|
32
|
+
loaded: string[];
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieve the list of fonts that can be used by the renderer.
|
|
36
|
+
*
|
|
37
|
+
* The shape of each font entry is implementation-defined but should include a displayable name.
|
|
38
|
+
*
|
|
39
|
+
* @returns A Promise with available font metadata.
|
|
40
|
+
*/
|
|
41
|
+
getAvailableFonts(): Promise<{
|
|
42
|
+
fonts: any[];
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Release any resources owned by the renderer (e.g., terminate Web Workers).
|
|
46
|
+
*
|
|
47
|
+
* Safe to call multiple times.
|
|
48
|
+
*/
|
|
49
|
+
destroy(): void;
|
|
50
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { MTextData, TextStyle, ColorSettings } from '../renderer/types';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a rendered MText object that extends THREE.Object3D with additional MText-specific properties.
|
|
5
|
+
* This interface defines the contract for objects returned by MText renderers.
|
|
6
|
+
*/
|
|
7
|
+
export interface MTextObject extends THREE.Object3D {
|
|
8
|
+
/**
|
|
9
|
+
* The bounding box of the MText object in local coordinates.
|
|
10
|
+
* This box represents the bounds of the text content without considering transformations.
|
|
11
|
+
* To get the world-space bounding box, apply the object's world matrix to this box.
|
|
12
|
+
*/
|
|
13
|
+
box: THREE.Box3;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Defines the common rendering contract for producing Three.js objects from MText content.
|
|
17
|
+
*
|
|
18
|
+
* Implementations may render on the main thread or delegate work to a Web Worker,
|
|
19
|
+
* but they must expose the same high-level API so callers can switch strategies
|
|
20
|
+
* without changing usage.
|
|
21
|
+
*/
|
|
22
|
+
export interface MTextBaseRenderer {
|
|
23
|
+
/**
|
|
24
|
+
* Render the provided MText content into a Three.js object hierarchy.
|
|
25
|
+
*
|
|
26
|
+
* The returned root object contains meshes/lines for glyphs and exposes a
|
|
27
|
+
* bounding box on `object.box`.
|
|
28
|
+
*
|
|
29
|
+
* @param mtextContent Structured MText input (text, height, width, position).
|
|
30
|
+
* @param textStyle Text style to apply (font, width factor, oblique, etc.).
|
|
31
|
+
* @param colorSettings Optional color context (ByLayer, ByBlock colors).
|
|
32
|
+
* @returns A Promise resolving to a populated `MTextObject` ready to add to a scene.
|
|
33
|
+
*/
|
|
34
|
+
renderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
|
|
35
|
+
/**
|
|
36
|
+
* Ensure the specified fonts are available to the renderer.
|
|
37
|
+
*
|
|
38
|
+
* Implementations should load and cache missing fonts; repeated calls should be cheap.
|
|
39
|
+
*
|
|
40
|
+
* @param fonts Font names to load (without extension for built-ins).
|
|
41
|
+
* @returns A Promise with the list of fonts that were processed.
|
|
42
|
+
*/
|
|
43
|
+
loadFonts(fonts: string[]): Promise<{
|
|
44
|
+
loaded: string[];
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieve the list of fonts that can be used by the renderer.
|
|
48
|
+
*
|
|
49
|
+
* The shape of each font entry is implementation-defined but should include a displayable name.
|
|
50
|
+
*
|
|
51
|
+
* @returns A Promise with available font metadata.
|
|
52
|
+
*/
|
|
53
|
+
getAvailableFonts(): Promise<{
|
|
54
|
+
fonts: Array<{
|
|
55
|
+
name: string[];
|
|
56
|
+
}>;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Release any resources owned by the renderer (e.g., terminate Web Workers).
|
|
60
|
+
*
|
|
61
|
+
* Safe to call multiple times.
|
|
62
|
+
*/
|
|
63
|
+
destroy(): void;
|
|
64
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { WebWorkerRenderer as MTextWorkerManager } from './webWorkerRenderer';
|
|
2
|
+
export { MainThreadRenderer } from './mainThreadRenderer';
|
|
3
|
+
export { UnifiedRenderer } from './unifiedRenderer';
|
|
4
|
+
export type { RenderMode } from './unifiedRenderer';
|
|
5
|
+
export type { MTextBaseRenderer as MTextRendererAdapter } from './baseRenderer';
|
|
6
|
+
export type { MTextData, TextStyle, ColorSettings } from '../renderer/types';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MTextData, TextStyle, ColorSettings } from '../renderer/types';
|
|
2
|
+
import { MTextBaseRenderer } from './base-renderer';
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
/**
|
|
5
|
+
* Main thread renderer for MText objects
|
|
6
|
+
* This provides the same interface as the worker but runs in the main thread
|
|
7
|
+
*/
|
|
8
|
+
export declare class MainThreadRenderer implements MTextBaseRenderer {
|
|
9
|
+
private fontManager;
|
|
10
|
+
private styleManager;
|
|
11
|
+
private fontLoader;
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Render MText directly in the main thread
|
|
15
|
+
*/
|
|
16
|
+
renderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<THREE.Object3D>;
|
|
17
|
+
/**
|
|
18
|
+
* Load fonts in the main thread
|
|
19
|
+
*/
|
|
20
|
+
loadFonts(fonts: string[]): Promise<{
|
|
21
|
+
loaded: string[];
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Get available fonts from the main thread
|
|
25
|
+
*/
|
|
26
|
+
getAvailableFonts(): Promise<{
|
|
27
|
+
fonts: any[];
|
|
28
|
+
}>;
|
|
29
|
+
destroy(): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MTextData, TextStyle, ColorSettings } from '../renderer/types';
|
|
2
|
+
import { MTextBaseRenderer, MTextObject } from './baseRenderer';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Main thread renderer for MText objects
|
|
6
|
+
* This provides the same interface as the worker but runs in the main thread
|
|
7
|
+
*/
|
|
8
|
+
export declare class MainThreadRenderer implements MTextBaseRenderer {
|
|
9
|
+
private fontManager;
|
|
10
|
+
private styleManager;
|
|
11
|
+
private fontLoader;
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Render MText directly in the main thread
|
|
15
|
+
*/
|
|
16
|
+
renderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
|
|
17
|
+
/**
|
|
18
|
+
* Load fonts in the main thread
|
|
19
|
+
*/
|
|
20
|
+
loadFonts(fonts: string[]): Promise<{
|
|
21
|
+
loaded: string[];
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Get available fonts from the main thread
|
|
25
|
+
*/
|
|
26
|
+
getAvailableFonts(): Promise<{
|
|
27
|
+
fonts: Array<{
|
|
28
|
+
name: string[];
|
|
29
|
+
}>;
|
|
30
|
+
}>;
|
|
31
|
+
destroy(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MTextData, TextStyle, ColorSettings } from '../renderer/types';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
export type RenderMode = 'main' | 'worker';
|
|
4
|
+
/**
|
|
5
|
+
* Unified renderer that can work in both main thread and web worker modes
|
|
6
|
+
*/
|
|
7
|
+
export declare class UnifiedRenderer {
|
|
8
|
+
private workerManager;
|
|
9
|
+
private mainThreadRenderer;
|
|
10
|
+
private adapter;
|
|
11
|
+
private currentMode;
|
|
12
|
+
constructor(mode?: RenderMode);
|
|
13
|
+
/**
|
|
14
|
+
* Switch between main thread and worker rendering modes
|
|
15
|
+
*/
|
|
16
|
+
switchMode(mode: RenderMode): void;
|
|
17
|
+
/**
|
|
18
|
+
* Get current rendering mode
|
|
19
|
+
*/
|
|
20
|
+
getMode(): RenderMode;
|
|
21
|
+
/**
|
|
22
|
+
* Render MText using the current mode
|
|
23
|
+
*/
|
|
24
|
+
renderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<THREE.Object3D>;
|
|
25
|
+
/**
|
|
26
|
+
* Load fonts using the current mode
|
|
27
|
+
*/
|
|
28
|
+
loadFonts(fonts: string[]): Promise<{
|
|
29
|
+
loaded: string[];
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Get available fonts using the current mode
|
|
33
|
+
*/
|
|
34
|
+
getAvailableFonts(): Promise<{
|
|
35
|
+
fonts: any[];
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Clean up resources
|
|
39
|
+
*/
|
|
40
|
+
destroy(): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { MTextData, TextStyle, ColorSettings } from '../renderer/types';
|
|
2
|
+
import { MTextObject } from './baseRenderer';
|
|
3
|
+
|
|
4
|
+
export type RenderMode = 'main' | 'worker';
|
|
5
|
+
/**
|
|
6
|
+
* Unified renderer that can work in both main thread and web worker modes
|
|
7
|
+
*/
|
|
8
|
+
export declare class UnifiedRenderer {
|
|
9
|
+
private workerManager;
|
|
10
|
+
private mainThreadRenderer;
|
|
11
|
+
private adapter;
|
|
12
|
+
private currentMode;
|
|
13
|
+
constructor(mode?: RenderMode);
|
|
14
|
+
/**
|
|
15
|
+
* Switch between main thread and worker rendering modes
|
|
16
|
+
*/
|
|
17
|
+
switchMode(mode: RenderMode): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get current rendering mode
|
|
20
|
+
*/
|
|
21
|
+
getMode(): RenderMode;
|
|
22
|
+
/**
|
|
23
|
+
* Render MText using the current mode
|
|
24
|
+
*/
|
|
25
|
+
renderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
|
|
26
|
+
/**
|
|
27
|
+
* Load fonts using the current mode
|
|
28
|
+
*/
|
|
29
|
+
loadFonts(fonts: string[]): Promise<{
|
|
30
|
+
loaded: string[];
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Get available fonts using the current mode
|
|
34
|
+
*/
|
|
35
|
+
getAvailableFonts(): Promise<{
|
|
36
|
+
fonts: Array<{
|
|
37
|
+
name: string[];
|
|
38
|
+
}>;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Clean up resources
|
|
42
|
+
*/
|
|
43
|
+
destroy(): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { MTextData, TextStyle, ColorSettings } from '../renderer/types';
|
|
2
|
+
import { MTextBaseRenderer } from './base-renderer';
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
interface SerializedMText {
|
|
5
|
+
type: string;
|
|
6
|
+
position: {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
z: number;
|
|
10
|
+
};
|
|
11
|
+
rotation: {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
z: number;
|
|
15
|
+
w: number;
|
|
16
|
+
};
|
|
17
|
+
scale: {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
z: number;
|
|
21
|
+
};
|
|
22
|
+
box: {
|
|
23
|
+
min: {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
z: number;
|
|
27
|
+
};
|
|
28
|
+
max: {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
z: number;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
children: SerializedChild[];
|
|
35
|
+
}
|
|
36
|
+
interface SerializedChild {
|
|
37
|
+
type: 'mesh' | 'line';
|
|
38
|
+
position: {
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
z: number;
|
|
42
|
+
};
|
|
43
|
+
rotation: {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
z: number;
|
|
47
|
+
w: number;
|
|
48
|
+
};
|
|
49
|
+
scale: {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
z: number;
|
|
53
|
+
};
|
|
54
|
+
geometry: {
|
|
55
|
+
attributes: {
|
|
56
|
+
[key: string]: {
|
|
57
|
+
arrayBuffer: ArrayBuffer;
|
|
58
|
+
byteOffset: number;
|
|
59
|
+
length: number;
|
|
60
|
+
itemSize: number;
|
|
61
|
+
normalized: boolean;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
index: {
|
|
65
|
+
arrayBuffer: ArrayBuffer;
|
|
66
|
+
byteOffset: number;
|
|
67
|
+
length: number;
|
|
68
|
+
} | null;
|
|
69
|
+
};
|
|
70
|
+
material: {
|
|
71
|
+
type: string;
|
|
72
|
+
color: number;
|
|
73
|
+
transparent: boolean;
|
|
74
|
+
opacity: number;
|
|
75
|
+
side?: number;
|
|
76
|
+
linewidth?: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Manages communication with the MText web worker
|
|
81
|
+
*/
|
|
82
|
+
export declare class WebWorkerRenderer implements MTextBaseRenderer {
|
|
83
|
+
private worker;
|
|
84
|
+
private pendingRequests;
|
|
85
|
+
private requestId;
|
|
86
|
+
constructor();
|
|
87
|
+
private handleWorkerMessage;
|
|
88
|
+
private sendMessage;
|
|
89
|
+
/**
|
|
90
|
+
* Render MText in the worker and return serialized data
|
|
91
|
+
*/
|
|
92
|
+
renderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<THREE.Object3D>;
|
|
93
|
+
/**
|
|
94
|
+
* Load fonts in the worker
|
|
95
|
+
*/
|
|
96
|
+
loadFonts(fonts: string[]): Promise<{
|
|
97
|
+
loaded: string[];
|
|
98
|
+
}>;
|
|
99
|
+
/**
|
|
100
|
+
* Get available fonts from the worker
|
|
101
|
+
*/
|
|
102
|
+
getAvailableFonts(): Promise<{
|
|
103
|
+
fonts: any[];
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* Reconstruct MText object from JSON serialized data
|
|
107
|
+
*/
|
|
108
|
+
reconstructMText(serializedData: SerializedMText): THREE.Object3D;
|
|
109
|
+
/**
|
|
110
|
+
* Terminate the worker
|
|
111
|
+
*/
|
|
112
|
+
terminate(): void;
|
|
113
|
+
destroy(): void;
|
|
114
|
+
}
|
|
115
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { MTextData, TextStyle, ColorSettings } from '../renderer/types';
|
|
2
|
+
import { MTextBaseRenderer, MTextObject } from './baseRenderer';
|
|
3
|
+
|
|
4
|
+
interface SerializedMText {
|
|
5
|
+
type: string;
|
|
6
|
+
position: {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
z: number;
|
|
10
|
+
};
|
|
11
|
+
rotation: {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
z: number;
|
|
15
|
+
w: number;
|
|
16
|
+
};
|
|
17
|
+
scale: {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
z: number;
|
|
21
|
+
};
|
|
22
|
+
box: {
|
|
23
|
+
min: {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
z: number;
|
|
27
|
+
};
|
|
28
|
+
max: {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
z: number;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
children: SerializedChild[];
|
|
35
|
+
}
|
|
36
|
+
interface SerializedChild {
|
|
37
|
+
type: 'mesh' | 'line';
|
|
38
|
+
position: {
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
z: number;
|
|
42
|
+
};
|
|
43
|
+
rotation: {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
z: number;
|
|
47
|
+
w: number;
|
|
48
|
+
};
|
|
49
|
+
scale: {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
z: number;
|
|
53
|
+
};
|
|
54
|
+
geometry: {
|
|
55
|
+
attributes: {
|
|
56
|
+
[key: string]: {
|
|
57
|
+
arrayBuffer: ArrayBuffer;
|
|
58
|
+
byteOffset: number;
|
|
59
|
+
length: number;
|
|
60
|
+
itemSize: number;
|
|
61
|
+
normalized: boolean;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
index: {
|
|
65
|
+
arrayBuffer: ArrayBuffer;
|
|
66
|
+
byteOffset: number;
|
|
67
|
+
length: number;
|
|
68
|
+
componentType?: 'uint16' | 'uint32';
|
|
69
|
+
} | null;
|
|
70
|
+
};
|
|
71
|
+
material: {
|
|
72
|
+
type: string;
|
|
73
|
+
color: number;
|
|
74
|
+
transparent: boolean;
|
|
75
|
+
opacity: number;
|
|
76
|
+
side?: number;
|
|
77
|
+
linewidth?: number;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Manages communication with the MText web worker
|
|
82
|
+
*/
|
|
83
|
+
export declare class WebWorkerRenderer implements MTextBaseRenderer {
|
|
84
|
+
private workers;
|
|
85
|
+
private inFlightPerWorker;
|
|
86
|
+
private pendingRequests;
|
|
87
|
+
private requestId;
|
|
88
|
+
private poolSize;
|
|
89
|
+
private readyPromise;
|
|
90
|
+
constructor(poolSize?: number);
|
|
91
|
+
private handleWorkerMessage;
|
|
92
|
+
private attachWorkerHandlers;
|
|
93
|
+
private pickLeastLoadedWorker;
|
|
94
|
+
private sendMessage;
|
|
95
|
+
private ensureInitialized;
|
|
96
|
+
/**
|
|
97
|
+
* Render MText in the worker and return serialized data
|
|
98
|
+
*/
|
|
99
|
+
renderMText(mtextContent: MTextData, textStyle: TextStyle, colorSettings?: ColorSettings): Promise<MTextObject>;
|
|
100
|
+
/**
|
|
101
|
+
* Load fonts in the worker
|
|
102
|
+
*/
|
|
103
|
+
loadFonts(fonts: string[]): Promise<{
|
|
104
|
+
loaded: string[];
|
|
105
|
+
}>;
|
|
106
|
+
/**
|
|
107
|
+
* Get available fonts from the worker
|
|
108
|
+
*/
|
|
109
|
+
getAvailableFonts(): Promise<{
|
|
110
|
+
fonts: Array<{
|
|
111
|
+
name: string[];
|
|
112
|
+
}>;
|
|
113
|
+
}>;
|
|
114
|
+
/**
|
|
115
|
+
* Reconstruct MText object from JSON serialized data
|
|
116
|
+
*/
|
|
117
|
+
reconstructMText(serializedData: SerializedMText): MTextObject;
|
|
118
|
+
/**
|
|
119
|
+
* Terminate the worker
|
|
120
|
+
*/
|
|
121
|
+
terminate(): void;
|
|
122
|
+
destroy(): void;
|
|
123
|
+
}
|
|
124
|
+
export {};
|