( camerasFile: File, imagesFile: File, points3DFile: File, rigsFile?: File, framesFile?: File, )
| 19 | * Returns the WASM wrapper along with parsed data so it can be kept alive for fast rendering path |
| 20 | */ |
| 21 | export async function parseWithWasm( |
| 22 | camerasFile: File, |
| 23 | imagesFile: File, |
| 24 | points3DFile: File, |
| 25 | rigsFile?: File, |
| 26 | framesFile?: File, |
| 27 | ): Promise<{ |
| 28 | cameras: Map<number, Camera>; |
| 29 | images: Map<number, ColmapImage>; |
| 30 | rigData?: RigData; |
| 31 | wasmWrapper: WasmReconstructionWrapper; |
| 32 | } | null> { |
| 33 | let wasm: WasmReconstructionWrapper | null = null; |
| 34 | |
| 35 | try { |
| 36 | wasm = await createWasmReconstruction(); |
| 37 | if (!wasm) { |
| 38 | appLogger.warn('[WASM] Module not available, falling back to JS parser'); |
| 39 | return null; |
| 40 | } |
| 41 | |
| 42 | // Only parse binary files with WASM (text files use JS parser) |
| 43 | if (!camerasFile.name.endsWith('.bin') || |
| 44 | !imagesFile.name.endsWith('.bin') || |
| 45 | !points3DFile.name.endsWith('.bin')) { |
| 46 | appLogger.info('[WASM] Text files detected, using JS parser'); |
| 47 | wasm.dispose(); |
| 48 | return null; |
| 49 | } |
| 50 | |
| 51 | // Also check if rig files are text (will fall back to JS for those specifically) |
| 52 | const canParseRigsWithWasm = rigsFile && framesFile && |
| 53 | rigsFile.name.endsWith('.bin') && framesFile.name.endsWith('.bin'); |
| 54 | |
| 55 | const startTime = performance.now(); |
| 56 | |
| 57 | // Parse all files with WASM |
| 58 | const [camerasBuffer, imagesBuffer, points3DBuffer] = await Promise.all([ |
| 59 | camerasFile.arrayBuffer(), |
| 60 | imagesFile.arrayBuffer(), |
| 61 | points3DFile.arrayBuffer(), |
| 62 | ]); |
| 63 | |
| 64 | const camerasOk = wasm.parseCameras(camerasBuffer); |
| 65 | // Use lazy parsing - 2D points are NOT cached in WASM memory |
| 66 | // Instead, only file offsets are stored (~50KB), and 2D points are loaded on-demand |
| 67 | // This enables loading 1.9GB+ images.bin files without running out of memory |
| 68 | const imagesOk = wasm.parseImagesLazy(imagesBuffer); |
| 69 | const points3DOk = wasm.parsePoints3D(points3DBuffer); |
| 70 | |
| 71 | if (!camerasOk || !imagesOk || !points3DOk) { |
| 72 | appLogger.warn('[WASM] Failed to parse some files, falling back to JS parser'); |
| 73 | wasm.dispose(); |
| 74 | return null; |
| 75 | } |
| 76 | |
| 77 | const parseTime = performance.now() - startTime; |
| 78 | appLogger.info(`[WASM] Parsed in ${parseTime.toFixed(0)}ms: ${wasm.cameraCount} cameras, ${wasm.imageCount} images, ${wasm.pointCount} points`); |
no test coverage detected