Spaces:
Running
Running
File size: 819 Bytes
31a2d08 c99cc8d 31a2d08 9c554be 31a2d08 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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;
}
|