1// The built-in phantoms, bundled as genuine `.phantom` (HDF5) assets. They are
2// generated by scripts/gen-phantoms.mjs. Vite's `?url` import copies each file
3// into the build and gives a base-correct URL to fetch at runtime.
4import cubeUrl from './data/cube.phantom?url'
5import sphereUrl from './data/sphere.phantom?url'
6import { loadPhantom } from './loadPhantom.ts'
7import type { Phantom } from './phantomTypes.ts'
9export interface BuiltinPhantom {
10 id: string
11 label: string
12 description: string
13 url: string
14}
16export const BUILTIN_PHANTOMS: BuiltinPhantom[] = [
17 {
18 id: 'cube',
19 label: 'Cube',
20 description: '10 mm cube, uniform spins',
21 url: cubeUrl,
22 },
23 {
24 id: 'sphere',
25 label: 'Sphere',
26 description: '10 mm sphere, uniform spins',
27 url: sphereUrl,
28 },
29]
31export async function fetchBuiltinPhantom(b: BuiltinPhantom): Promise<Phantom> {
32 const resp = await fetch(b.url)
33 if (!resp.ok) throw new Error(`Failed to fetch phantom "${b.id}": ${resp.status}`)
34 const buf = await resp.arrayBuffer()
35 return loadPhantom(buf, b.label)
36}