feat: rewrite some systems

This commit is contained in:
TrèsAbhi committed 2025-09-05 23:34:59 -05:00
1 parent 95fa5bc1a5
commit 335cd4d699
11 files changed
+212 -107

No files matched your search

@@ -0,0 +1,27 @@
import { writeFile } from "fs/promises";
import sharp from "sharp";
import { readTexture } from "./readTexture";
export async function readRoughnessMetallic(path: string) {
const raw = await readTexture(path);
const blitz = sharp(raw.data, { raw: raw });
const metallicness = await blitz?.extractChannel(1).raw().toBuffer();
const roughness = await blitz?.extractChannel(3).raw().toBuffer();
const combined = Buffer.alloc(raw.width * raw.height * 3);
for (let i = 0; i < raw.width * raw.height; i++) {
combined[i * 3 + 1] = roughness?.[i] ?? 0;
combined[i * 3 + 2] = metallicness?.[i] ?? 0;
}
const image = await sharp(combined, {
raw: { width: raw.width, height: raw.height, channels: 3 },
})
.jpeg()
.toBuffer();
writeFile("test.rm.jpg", image);
return image;
}