fix: little endian pvr

This commit is contained in:
TrèsAbhi committed 2023-12-30 11:44:42 -06:00
1 parent fa625dc887
commit 21daf9f3bb
5 files changed
+15 -6

No files matched your search

+4
View File
@@ -533,6 +533,10 @@ if (allTargets || targets?.includes('tankModels')) {
baseColor,
);
// writeFile(
// `dist/assets/models/${id}.glb`,
// await nodeIO.writeBinary(model),
// );
await mkdir(`dist/assets/models/${id}`, { recursive: true });
nodeIO.write(`dist/assets/models/${id}/index.gltf`, model);
}
+3
View File
@@ -199,6 +199,7 @@ export async function extractModel(
}
let minLODDistance = Infinity;
let isFirstMaxFloat = true;
range(component['rc.renderObj']['ro.batchCount']).forEach(
(id) => {
@@ -209,8 +210,10 @@ export async function extractModel(
if (
lodDistance <= minLODDistance ||
// (lodDistance === MAX_FLOAT32 && isFirstMaxFloat)
lodDistance === MAX_FLOAT32
) {
if (lodDistance === MAX_FLOAT32) isFirstMaxFloat = false;
minLODDistance = lodDistance;
minLODDistanceBatchId = id;
}
+4
View File
@@ -31,6 +31,7 @@ export async function readTexture(path: string, options?: ReadTextureOptions) {
? ddsTexturePath
: ddsTexturePath.replace('.dds', '.pvr');
const decompressedDvpl = await readDVPLFile(resolvedTexturePath);
const raw = isDds
? await new DdsStream(decompressedDvpl).dds()
: new PvrStream(decompressedDvpl).pvr();
@@ -82,6 +83,9 @@ export async function readTexture(path: string, options?: ReadTextureOptions) {
const g = raw.data[index + 1] / 255;
const b = raw.data[index + 2] / 255;
const a = raw.data[index + 3] / 255;
if (a === 0) continue;
const invA = 1 - a;
const rPrime = r + invA * options.baseColor[0];
const gPrime = g + invA * options.baseColor[1];
-2
View File
@@ -177,8 +177,6 @@ export class DdsStream extends WindowsStream {
const header = this.header();
const dxgiFormat = this.resolveDxgiFormat(header);
console.log(DxgiFormat[dxgiFormat]);
switch (dxgiFormat) {
case DxgiFormat.BC1_TYPELESS:
case DxgiFormat.BC1_UNORM:
+4 -4
View File
@@ -119,10 +119,10 @@ export class PvrStream extends BufferStream {
times(pixelCount, (index) => {
const buffer = this.consume(2);
const bufferIndex = index * 4;
const r = ((buffer[0] & 0b11110000) >>> 4) / 15;
const g = (buffer[0] & 0b1111) / 15;
const b = ((buffer[1] & 0b11110000) >>> 4) / 15;
const a = (buffer[1] & 0b1111) / 15;
const r = ((buffer[1] & 0b11110000) >>> 4) / 15;
const g = (buffer[1] & 0b1111) / 15;
const b = ((buffer[0] & 0b11110000) >>> 4) / 15;
const a = (buffer[0] & 0b1111) / 15;
data[bufferIndex] = Math.round(clamp(r * 255, 0, 255));
data[bufferIndex + 1] = Math.round(clamp(g * 255, 0, 255));