mirror of
https://github.com/vercel/eve.git
synced 2026-09-20 05:35:39 +08:00
ed59cb42f4
Signed-off-by: matiasngf <matiasngf@hotmail.com>
24 lines
933 B
TypeScript
24 lines
933 B
TypeScript
import { readFile } from "node:fs/promises";
|
|
import { resolve } from "node:path";
|
|
import { decodeGltfMesh } from "../../app/[lang]/(home)/components/eve-logo-shader/mesh";
|
|
|
|
// Owns disk glTF loading for the offline Eve renderer.
|
|
// INVARIANT: data URI and relative-buffer decoding match the original script.
|
|
// Imported only by render-eve-5.ts.
|
|
|
|
export async function loadMeshFromDisk(path: string) {
|
|
const gltf = JSON.parse(await readFile(path, "utf8"));
|
|
return decodeGltfMesh(gltf, async (uri) => {
|
|
if (uri.startsWith("data:application/octet-stream;base64,")) {
|
|
const [, payload] = uri.split(",");
|
|
return exactArrayBuffer(Buffer.from(payload!, "base64"));
|
|
}
|
|
const bufferPath = resolve(path, "..", uri);
|
|
return exactArrayBuffer(await readFile(bufferPath));
|
|
});
|
|
}
|
|
|
|
function exactArrayBuffer(buffer: Buffer) {
|
|
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
}
|