3d-arena / src /routes /viewers /ViewerFactory.ts
dylanebert's picture
dylanebert HF staff
vote layout
c99cc8d
raw
history blame
757 Bytes
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");
}
await viewer.loadScene(url, onProgress);
return viewer;
}