/** * Emscripten FS interface (subset used by MeshRepair) */ export declare interface EmscriptenFS { writeFile(path: string, data: string | ArrayBufferView, opts?: { encoding?: string; }): void; readFile(path: string, opts?: { encoding?: string; }): Uint8Array; unlink(path: string): void; mkdir(path: string): void; rmdir(path: string): void; readdir(path: string): string[]; stat(path: string): { mode: number; }; isDir(mode: number): boolean; } /** * Options for initializing MeshRepair */ export declare interface InitOptions { /** * Custom function to locate WASM/data files * @param path - Filename being requested * @param prefix - Default prefix path * @returns Full path to the file */ locateFile?: (path: string, prefix: string) => string; } /** * MeshRepair - WebAssembly STL Mesh Repair Library * * A lightweight, headless port of VCGlib for automated repair * and sanitization of STL files in the browser. * * @example * ```typescript * import { MeshRepair } from '@goodtools/meshrepair'; * import loadMeshRepair from '@goodtools/meshrepair/wasm'; * * const meshrepair = await MeshRepair.init(loadMeshRepair); * const { result, output } = meshrepair.repair('model.stl', stlData, 'print-ready'); * console.log(`Repaired: ${result.holesFilled} holes filled`); * ``` */ declare class MeshRepair { /** Direct access to Emscripten virtual filesystem */ readonly FS: EmscriptenFS; private lib; private uploadDir; private outputDir; /** * Initialize MeshRepair WASM module * * @param loader - Function that loads the WASM module (import from '@goodtools/meshrepair/wasm') * @param options - Initialization options * @returns Promise resolving to MeshRepair instance * * @example * ```typescript * import { MeshRepair } from '@goodtools/meshrepair'; * import loadMeshRepair from '@goodtools/meshrepair/wasm'; * * const meshrepair = await MeshRepair.init(loadMeshRepair); * * // With custom WASM location * const meshrepair = await MeshRepair.init(loadMeshRepair, { * locateFile: (path) => `/assets/${path}` * }); * ``` */ static init(loader: MeshRepairLoader, options?: InitOptions): Promise; private constructor(); /** * Repair an STL file by passing data directly * * Convenience method for smaller files. For large files, * use `FS.writeFile()` followed by `repairFile()`. * * @param name - Filename (used for virtual FS path) * @param data - STL file data * @param options - Repair options or preset name * @param onProgress - Optional progress callback * @returns Repair result and output buffer * * @example * ```typescript * const stlData = await fetch('/model.stl').then(r => r.arrayBuffer()); * const { result, output } = meshrepair.repair('model.stl', new Uint8Array(stlData), 'print-ready'); * ``` */ repair(name: string, data: string | ArrayBufferView, options?: RepairOptions | PresetName, onProgress?: ProgressCallback): { result: RepairResult; output: Uint8Array; }; /** * Repair an STL file from a path in the virtual filesystem * * Use this for large files - write with `FS.writeFile()` first. * * @param inputPath - Path to STL file in virtual FS * @param options - Repair options * @returns Repair result, output buffer, and output path * * @example * ```typescript * // Write large file directly to FS * meshrepair.FS.writeFile('/uploads/huge.stl', hugeBuffer); * * // Repair by path * const { result, output } = meshrepair.repairFile('/uploads/huge.stl', { * options: 'print-ready', * onProgress: (step, p) => console.log(`${step}: ${p * 100}%`) * }); * ``` */ repairFile(inputPath: string, options?: RepairFileOptions): { result: RepairResult; output: Uint8Array; outputPath: string; }; /** * Repair an STL file without reading output back to JavaScript * * Memory-efficient for large files or when chaining operations. * The output file remains in the virtual FS. * * @param inputPath - Path to STL file in virtual FS * @param options - Repair options * @returns Repair result and output path * * @example * ```typescript * meshrepair.FS.writeFile('/uploads/huge.stl', hugeBuffer); * * const { result, outputPath } = meshrepair.repairFileInPlace('/uploads/huge.stl', { * options: 'aggressive' * }); * * // Read output when needed * const repairedData = meshrepair.FS.readFile(outputPath); * ``` */ repairFileInPlace(inputPath: string, options?: RepairFileOptions): { result: RepairResult; outputPath: string; }; /** * Clean up resources and remove working directories */ destroy(): void; /** * Generate output path from input path */ private generateOutputPath; /** * Recursively remove a directory */ private removeDir; } export { MeshRepair } export default MeshRepair; /** * Type of the function that loads the MeshRepair WASM module */ export declare type MeshRepairLoader = (options?: InitOptions) => Promise; /** * Internal: MeshRepair WASM module interface */ export declare interface MeshRepairModule { FS: EmscriptenFS; RepairSession: new (path: string) => RepairSessionInstance; } /** * Available preset names */ export declare type PresetName = 'minimal' | 'print-ready' | 'aggressive'; /** * Preset configurations for common repair operations */ export declare const PRESETS: Record>; /** * Progress callback function type * @param step - Current repair step name * @param progress - Progress value (0.0 to 1.0) */ export declare type ProgressCallback = (step: string, progress: number) => void; /** * Options for repairFile and repairFileInPlace methods */ export declare interface RepairFileOptions { /** Repair options or preset name */ options?: RepairOptions | PresetName; /** Output file path in virtual FS (auto-generated if not provided) */ outputPath?: string; /** Progress callback */ onProgress?: ProgressCallback; } /** * MeshRepair - WebAssembly STL Mesh Repair Library * * TypeScript type definitions * * SPDX-License-Identifier: GPL-3.0 */ /** * Repair options - controls which repair operations to run */ export declare interface RepairOptions { /** Remove vertices at the same position (default: true) */ removeDuplicateVertex?: boolean; /** Remove faces with identical vertex references (default: true) */ removeDuplicateFace?: boolean; /** Remove vertices not referenced by any face (default: true) */ removeUnreferencedVertex?: boolean; /** Remove faces with zero area or repeated vertices (default: true) */ removeDegenerateFace?: boolean; /** Fill holes in the mesh (default: false) */ fillHoles?: boolean; /** Maximum hole size to fill (edges in boundary) (default: 100) */ maxHoleSize?: number; /** Remove non-manifold faces (more than 2 faces per edge) (default: false) */ removeNonManifoldFace?: boolean; /** Remove non-manifold vertices (default: false) */ removeNonManifoldVertex?: boolean; /** Make face orientations consistent (default: false) */ fixNormalOrientation?: boolean; /** Flip normals to point outward (default: false) */ flipNormalsOutside?: boolean; /** Remove T-vertices by edge flipping (default: false) */ removeTVertexByFlip?: boolean; /** Remove face folds by edge flipping (default: false) */ removeFaceFoldByFlip?: boolean; /** Output binary STL (true) or ASCII STL (false) (default: true) */ binaryOutput?: boolean; } /** * Result of a repair operation */ export declare interface RepairResult { /** 0 = success, non-zero = error */ code: number; /** Error message if code != 0 */ error?: string; /** Number of vertices before repair */ originalVertices: number; /** Number of faces before repair */ originalFaces: number; /** Number of vertices after repair */ finalVertices: number; /** Number of faces after repair */ finalFaces: number; /** Number of duplicate vertices removed */ duplicateVerticesRemoved: number; /** Number of duplicate faces removed */ duplicateFacesRemoved: number; /** Number of unreferenced vertices removed */ unreferencedVerticesRemoved: number; /** Number of degenerate faces removed */ degenerateFacesRemoved: number; /** Number of non-manifold faces removed */ nonManifoldFacesRemoved: number; /** Number of non-manifold vertices removed */ nonManifoldVerticesRemoved: number; /** Number of holes filled */ holesFilled: number; } /** * Internal: RepairSession instance from WASM module */ export declare interface RepairSessionInstance { repair(options: RepairOptions, outputPath: string, callback?: ProgressCallback): RepairResult; getOutputPath(): string; delete(): void; } export { }