feat: texturing

This commit is contained in:
TrèsAbhi committed 2023-12-19 20:11:37 -06:00
1 parent f61725a021
commit 4ad10deb00
4 files changed
+146 -92

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
import { execFile } from 'child_process';
import { existsSync } from 'fs';
import { mkdir, readFile, rm, writeFile } from 'fs/promises';
import { uniqueId } from 'lodash';
import { promisify } from 'util';
export async function clearDdsToPng() {
await rm('temp/ddsToPng/images', { force: true, recursive: true });
}
const execFilePromise = promisify(execFile);
let downloadStatus: Promise<void> | undefined = undefined;
export async function ddsToPng(ddsBuffer: Buffer) {
const id = uniqueId();
await mkdir('temp/ddsToPng/images', { recursive: true });
if (
!existsSync('temp/ddsToPng/texconv.exe') &&
downloadStatus === undefined
) {
console.log('texconv.exe not found, downloading...');
downloadStatus = new Promise<void>(async (resolve, reject) => {
const releaseResponse = await fetch(
'https://api.github.com/repos/microsoft/DirectXTex/releases/latest',
);
const releaseData = (await releaseResponse.json()) as {
assets: { browser_download_url: string; name: string }[];
};
const asset = releaseData.assets.find(
(asset) => asset.name === 'texconv.exe',
);
if (!asset) throw new Error('Could not find texconv.exe');
const downloadResponse = await fetch(asset.browser_download_url);
const downloadData = await downloadResponse.arrayBuffer();
await writeFile(
'temp/ddsToPng/texconv.exe',
new Uint8Array(downloadData),
);
resolve();
});
}
await downloadStatus;
return new Promise<Buffer>(async (resolve, reject) => {
await writeFile(`temp/ddsToPng/images/${id}.dds`, ddsBuffer);
await execFilePromise('temp/ddsToPng/texconv.exe', [
'-ft',
'png',
'-o',
'temp/ddsToPng/images',
`temp/ddsToPng/images/${id}.dds`,
]);
const pngBuffer = await readFile(`temp/ddsToPng/images/${id}.png`);
resolve(pngBuffer);
rm(`temp/ddsToPng/images/${id}.dds`);
// rm(`temp/ddsToPng/images/${id}.png`);
});
}
+8 -2
View File
@@ -10,9 +10,15 @@ type DataNode = {
'##name': 'NMaterial';
'#id': Buffer;
materialName: string;
parentMaterialKey?: string;
parentMaterialKey?: bigint;
qualityGroup?: string;
fxName?: string;
textures?: {
albedo: string;
decalmask: string;
normalmap: string;
};
} & (
| ({
configCount: number;
@@ -99,7 +105,7 @@ type RoBatches = Record<
'rb.aabbox': RbAabbox;
'rb.classname': 'RenderBatch';
'rb.datasource': bigint;
'rb.nmatname': string;
'rb.nmatname': bigint;
'rb.sortingKey': number;
}
>;