Spaces:
Running
Running
import type { IViewer } from "./IViewer"; | |
import { BabylonViewer } from "./BabylonViewer"; | |
import { SplatViewer } from "./SplatViewer"; | |
const meshFormats = ["obj", "stl", "gltf", "glb"]; | |
const splatFormats = ["splat", "ply"]; | |
export async function createViewer( | |
url: string, | |
canvas: HTMLCanvasElement, | |
onProgress: (progress: number) => void | |
): Promise<IViewer> { | |
let viewer: IViewer; | |
if (meshFormats.some((format) => url.endsWith(format))) { | |
viewer = new BabylonViewer(canvas); | |
} else if (splatFormats.some((format) => url.endsWith(format))) { | |
viewer = new SplatViewer(canvas); | |
} else { | |
throw new Error("Unsupported file format"); | |
} | |
const topoOnly: boolean = url.endsWith(".obj"); | |
await viewer.loadScene(url, onProgress, topoOnly); | |
return viewer; | |
} | |