@gaussforge/wasm
v0.5.3
Published
GaussForge WASM library for Gaussian Splatting format conversion
Maintainers
Readme
GaussForge WASM
WebAssembly version of GaussForge, providing TypeScript wrapper library for use in browsers and Node.js.
Features
- Support for multiple Gaussian splatting formats: PLY, Compressed PLY, Splat, KSplat, SPZ
- Format conversion functionality
- TypeScript type support
- Browser and Node.js compatible
Installation
npm install @gaussforge/wasmUsage
Browser
import { createGaussForge } from '@gaussforge/wasm';
async function handleFileUpload(file: File) {
// Initialize
const gaussForge = await createGaussForge();
// Read file
const fileData = await file.arrayBuffer();
const result = await gaussForge.read(fileData, 'ply');
console.log(`Loaded ${result.data.numPoints} points`);
// Convert format
const converted = await gaussForge.convert(fileData, 'ply', 'splat');
// Download the result
const blob = new Blob([converted.data], { type: 'application/octet-stream' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'output.splat';
a.click();
URL.revokeObjectURL(url);
}
// Usage with file input
const fileInput = document.querySelector('input[type="file"]');
fileInput.addEventListener('change', (e) => {
const file = (e.target as HTMLInputElement).files?.[0];
if (file) {
handleFileUpload(file);
}
});Node.js
import { createGaussForge } from '@gaussforge/wasm';
import fs from 'fs';
async function convertFile() {
const gaussForge = await createGaussForge();
// Read file
const inputData = fs.readFileSync('input.ply');
const result = await gaussForge.read(inputData, 'ply');
console.log(`Loaded ${result.data.numPoints} points`);
// Convert format
const converted = await gaussForge.convert(inputData, 'ply', 'splat');
// Save file
fs.writeFileSync('output.splat', converted.data);
}
convertFile().catch(console.error);API
createGaussForge(moduleFactory?)
Create and initialize a GaussForge instance.
read(data, format, options?)
Read Gaussian splatting data.
data:ArrayBuffer | Uint8Array- Input dataformat:SupportedFormat | string- File formatoptions.strict:boolean- Whether to use strict mode
Returns: Promise<ReadResult>
write(ir, format, options?)
Write Gaussian splatting data.
ir:GaussianCloudIR- Gaussian splatting intermediate representationformat:SupportedFormat | string- Output formatoptions.strict:boolean- Whether to use strict mode
Returns: Promise<WriteResult>
convert(data, inFormat, outFormat, options?)
Convert file format.
data:ArrayBuffer | Uint8Array- Input datainFormat:SupportedFormat | string- Input formatoutFormat:SupportedFormat | string- Output formatoptions.strict:boolean- Whether to use strict mode
Returns: Promise<ConvertResult>
getSupportedFormats()
Get the list of supported formats.
Returns: SupportedFormat[]
isFormatSupported(format)
Check if a format is supported.
format:string- Format name to check
Returns: boolean
Supported Formats
ply- PLY formatcompressed.ply- Compressed PLY formatsplat- Splat formatksplat- KSplat formatspz- SPZ formatsog- SOG format
Development
Build WASM
cd wasm
npm install
npm run build:wasmBuild TypeScript
npm run build:tsFull Build
npm run buildError Handling
All methods may throw errors. It's recommended to wrap API calls in try-catch blocks:
try {
const result = await gaussForge.read(fileData, 'ply');
// Handle success
} catch (error) {
console.error('Error reading file:', error.message);
// Handle error
}Requirements
- Emscripten SDK (for building WASM)
- Node.js 18+ (for development)
- TypeScript 5+ (for development)
