mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
feat: pbr
This commit is contained in:
1 parent
0627f678ea
commit
d60a102c0d
6 files changed
+201
-90
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import { existsSync } from 'fs';
|
||||
import { readDVPLFile } from '../blitz/readDVPLFile';
|
||||
import { ToJpgOptions, toJpg } from './toJpg';
|
||||
|
||||
export async function readTexture(
|
||||
path: string,
|
||||
options?: Partial<Omit<ToJpgOptions, 'format'>>,
|
||||
) {
|
||||
const ddsTexturePath = path.replace('.tex', '.dx11.dds.dvpl');
|
||||
const isDds = existsSync(ddsTexturePath);
|
||||
const resolvedTexturePath = isDds
|
||||
? ddsTexturePath
|
||||
: ddsTexturePath.replace('.dds', '.pvr');
|
||||
const decompressedTexture = await readDVPLFile(resolvedTexturePath);
|
||||
const jpg = await toJpg(decompressedTexture, {
|
||||
...options,
|
||||
format: isDds ? 'dds' : 'pvr',
|
||||
});
|
||||
|
||||
return jpg;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { exec } from 'child_process';
|
||||
import { mkdir, readFile, rm, writeFile } from 'fs/promises';
|
||||
import { generateUUID } from 'three/src/math/MathUtils';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const execPromise = promisify(exec);
|
||||
|
||||
type Channel = 'red' | 'green' | 'blue' | 'alpha';
|
||||
|
||||
export interface ToJpgOptions {
|
||||
format: string;
|
||||
swap: [Channel, Channel][];
|
||||
invert: boolean;
|
||||
}
|
||||
|
||||
const toJpgDefaultOptions: ToJpgOptions = {
|
||||
format: 'dds',
|
||||
swap: [],
|
||||
invert: false,
|
||||
};
|
||||
|
||||
export async function toJpg(
|
||||
inputBuffer: Buffer,
|
||||
options?: Partial<ToJpgOptions>,
|
||||
) {
|
||||
const mergedOptions = { ...toJpgDefaultOptions, ...options };
|
||||
const id = generateUUID();
|
||||
const input = `temp/toJpg/${id}.${mergedOptions.format}`;
|
||||
const output = `temp/toJpg/${id}.jpg`;
|
||||
const command = `PVRTexToolCLI -noout -i ${input} ${
|
||||
mergedOptions.swap.length === 0
|
||||
? ''
|
||||
: mergedOptions.swap
|
||||
.map(
|
||||
(swapChannels) => `-${swapChannels[1]} ${input},${swapChannels[0]}`,
|
||||
)
|
||||
.join(' ')
|
||||
} ${
|
||||
mergedOptions.invert ? `-diff ${input},DIFFINVERT,255` : ''
|
||||
} -d ${output}`;
|
||||
|
||||
console.log(command);
|
||||
|
||||
await mkdir('temp/toJpg', { recursive: true });
|
||||
await writeFile(`temp/toJpg/${id}.${mergedOptions.format}`, inputBuffer);
|
||||
await execPromise(command);
|
||||
|
||||
const jpgBuffer = await readFile(`temp/toJpg/${id}.jpg`);
|
||||
|
||||
rm(`temp/toJpg/${id}.${mergedOptions.format}`);
|
||||
rm(`temp/toJpg/${id}.jpg`);
|
||||
|
||||
return jpgBuffer;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import { exec } from 'child_process';
|
||||
import { mkdir, readFile, rm, writeFile } from 'fs/promises';
|
||||
import { generateUUID } from 'three/src/math/MathUtils';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const execPromise = promisify(exec);
|
||||
|
||||
interface ToPngOptions {
|
||||
format: string;
|
||||
alpha: boolean;
|
||||
}
|
||||
|
||||
const toPngDefaultOptions: ToPngOptions = {
|
||||
format: 'dds',
|
||||
alpha: true,
|
||||
};
|
||||
|
||||
export async function toPng(
|
||||
inputBuffer: Buffer,
|
||||
options?: Partial<ToPngOptions>,
|
||||
) {
|
||||
const mergedOptions = { ...toPngDefaultOptions, ...options };
|
||||
const id = generateUUID();
|
||||
await mkdir('temp/toPng', { recursive: true });
|
||||
await writeFile(`temp/toPng/${id}.${mergedOptions.format}`, inputBuffer);
|
||||
await execPromise(
|
||||
`PVRTexToolCLI -noout -i temp/toPng/${id}.${mergedOptions.format} -f ${
|
||||
mergedOptions.alpha ? 'r8g8b8a8' : 'r8g8b8'
|
||||
},UB,sRGB -d temp/toPng/${id}.png`,
|
||||
);
|
||||
|
||||
const pngBuffer = await readFile(`temp/toPng/${id}.png`);
|
||||
|
||||
rm(`temp/toPng/${id}.${mergedOptions.format}`);
|
||||
rm(`temp/toPng/${id}.png`);
|
||||
|
||||
return pngBuffer;
|
||||
}
|
||||
+8
-12
@@ -14,11 +14,7 @@ type DataNode = {
|
||||
qualityGroup?: string;
|
||||
fxName?: string;
|
||||
|
||||
textures?: {
|
||||
albedo: string;
|
||||
decalmask: string;
|
||||
normalmap: string;
|
||||
};
|
||||
textures?: Textures;
|
||||
} & (
|
||||
| ({
|
||||
configCount: number;
|
||||
@@ -70,15 +66,15 @@ interface TextureSampleStates {
|
||||
normalmap: number;
|
||||
}
|
||||
|
||||
interface Textures {
|
||||
export interface Textures {
|
||||
albedo: string;
|
||||
baseColorMap: string;
|
||||
baseNormalMap: string;
|
||||
baseRMMap: string;
|
||||
baseColorMap?: string;
|
||||
baseNormalMap?: string;
|
||||
baseRMMap?: string;
|
||||
decalmask?: string;
|
||||
maskMap: string;
|
||||
miscMap: string;
|
||||
normalmap: string;
|
||||
maskMap?: string;
|
||||
miscMap?: string;
|
||||
normalmap?: string;
|
||||
}
|
||||
|
||||
export interface Hierarchy {
|
||||
|
||||
Reference in new issue
Block a user