3d-arena / src /routes /viewers /ViewerFactory.ts
dylanebert's picture
dylanebert HF staff
support topology-only outputs
9c554be
raw
history blame contribute delete
819 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");
}
const topoOnly: boolean = url.endsWith(".obj");
await viewer.loadScene(url, onProgress, topoOnly);
return viewer;
}