From 21daf9f3bb71e00c1a11a10aab03e4417c59cb1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sat, 30 Dec 2023 11:44:42 -0600 Subject: [PATCH] fix: little endian pvr --- scripts/buildAssets.ts | 4 ++++ src/core/blitz/extractModel.ts | 3 +++ src/core/blitzkrieg/readTexture.ts | 4 ++++ src/core/streams/dds.ts | 2 -- src/core/streams/pvr.ts | 8 ++++---- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/buildAssets.ts b/scripts/buildAssets.ts index 833df45a5..15c663754 100644 --- a/scripts/buildAssets.ts +++ b/scripts/buildAssets.ts @@ -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); } diff --git a/src/core/blitz/extractModel.ts b/src/core/blitz/extractModel.ts index fb7fe0e51..cd1f31507 100644 --- a/src/core/blitz/extractModel.ts +++ b/src/core/blitz/extractModel.ts @@ -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; } diff --git a/src/core/blitzkrieg/readTexture.ts b/src/core/blitzkrieg/readTexture.ts index e9bdc6746..b418344fd 100644 --- a/src/core/blitzkrieg/readTexture.ts +++ b/src/core/blitzkrieg/readTexture.ts @@ -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]; diff --git a/src/core/streams/dds.ts b/src/core/streams/dds.ts index f4604159c..a8efb0423 100644 --- a/src/core/streams/dds.ts +++ b/src/core/streams/dds.ts @@ -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: diff --git a/src/core/streams/pvr.ts b/src/core/streams/pvr.ts index 6d99c4f85..847c38e4d 100644 --- a/src/core/streams/pvr.ts +++ b/src/core/streams/pvr.ts @@ -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));