25 lines
1.3 KiB
JavaScript
25 lines
1.3 KiB
JavaScript
// Lädt die benötigten Poly-Haven-Texturen in 1k nach public/textures/. Vorhandene Dateien bleiben
|
|
// unangetastet, damit ein neuer Eintrag die übrigen Texturen nicht still ändert.
|
|
import { existsSync } from "node:fs";
|
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
|
|
const UA = { "User-Agent": "leonida-assets/0.1 (local hobby project)" };
|
|
const SLUGS = ["asphalt_02", "concrete_pavement_03", "white_stucco", "sand_01", "leafy_grass", "grass_path_2", "palm_bark",
|
|
"concrete_pavement"];
|
|
const MAPS = ["Diffuse", "nor_gl", "arm"];
|
|
|
|
await mkdir("public/textures", { recursive: true });
|
|
for (const slug of SLUGS) {
|
|
if (MAPS.every((map) => existsSync(`public/textures/${slug}_${map}.jpg`))) continue;
|
|
const files = await (await fetch(`https://api.polyhaven.com/files/${slug}`, { headers: UA })).json();
|
|
for (const map of MAPS) {
|
|
const target = `public/textures/${slug}_${map}.jpg`;
|
|
if (existsSync(target)) continue;
|
|
const entry = files[map]?.["1k"]?.jpg;
|
|
if (!entry) { console.warn(`${slug}: ${map} fehlt`); continue; }
|
|
const buf = Buffer.from(await (await fetch(entry.url, { headers: UA })).arrayBuffer());
|
|
await writeFile(target, buf);
|
|
console.log(`${slug}_${map}.jpg ${(buf.length / 1e6).toFixed(1)} MB`);
|
|
}
|
|
}
|