diff --git a/bun.lockb b/bun.lockb index 6ed8d4c..6c58055 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/tests/basic.test.ts b/test/basic.test.skip.ts similarity index 100% rename from tests/basic.test.ts rename to test/basic.test.skip.ts diff --git a/tests/bin.test.ts b/test/bin.test.skip.ts similarity index 100% rename from tests/bin.test.ts rename to test/bin.test.skip.ts diff --git a/tests/body.test.ts b/test/body.test.ts similarity index 68% rename from tests/body.test.ts rename to test/body.test.ts index cf21d93..e8487b3 100644 --- a/tests/body.test.ts +++ b/test/body.test.ts @@ -118,15 +118,63 @@ test('Re-encoding the vertices read from the body', () => { }); -// test('Re-encoding the faces read from the body', () => { -// const buffer = readFileSync(`./bin/PL00P000.BIN`); -// const dat = buffer.subarray(0x30, 0x30 + 0x2b40); -// const reader = new ByteReader(dat.buffer as ArrayBuffer); - -// const geometry = body.map((mesh) => { -// const { triOfs, triCount } = mesh; - -// const triList = readFace(reader, triOfs, triCount, false); - -// }); -// }); +test('Re-encoding the faces read from the body', () => { + const buffer = readFileSync(`./bin/PL00P000.BIN`); + const dat = buffer.subarray(0x30, 0x30 + 0x2b40); + const reader = new ByteReader(dat.buffer as ArrayBuffer); + + const FACE_MASK = 0x7f; + const PIXEL_TO_FLOAT_RATIO = 0.00390625; + const PIXEL_ADJUSTMEST = 0.001953125; + + const geometry = body.map((mesh) => { + const { triOfs, triCount } = mesh; + reader.seek(triOfs) + for (let i = 0; i < triCount; i++) { + const au = reader.readUInt8(); + const av = reader.readUInt8(); + const bu = reader.readUInt8(); + const bv = reader.readUInt8(); + const cu = reader.readUInt8(); + const cv = reader.readUInt8(); + reader.seekRel(2); + + const dword = reader.readUInt32(); + const materialIndex = ((dword >> 28) & 0x3); + + const indexA = (dword >> 0x00) & FACE_MASK; + const indexB = (dword >> 0x07) & FACE_MASK; + const indexC = (dword >> 0x0e) & FACE_MASK; + + const a = { + materialIndex, + index: indexA, + u : au * PIXEL_TO_FLOAT_RATIO + PIXEL_ADJUSTMEST, + v : av * PIXEL_TO_FLOAT_RATIO + PIXEL_ADJUSTMEST, + } + + const b = { + materialIndex, + index: indexB, + u : bu * PIXEL_TO_FLOAT_RATIO + PIXEL_ADJUSTMEST, + v : bv * PIXEL_TO_FLOAT_RATIO + PIXEL_ADJUSTMEST, + } + const c = { + materialIndex, + index: indexC, + u : cu * PIXEL_TO_FLOAT_RATIO + PIXEL_ADJUSTMEST, + v : cv * PIXEL_TO_FLOAT_RATIO + PIXEL_ADJUSTMEST, + } + + expect(Math.floor((a.u - PIXEL_ADJUSTMEST) / PIXEL_TO_FLOAT_RATIO)).toEqual(au); + expect(Math.floor((a.v - PIXEL_ADJUSTMEST) / PIXEL_TO_FLOAT_RATIO)).toEqual(av); + expect(Math.floor((b.u - PIXEL_ADJUSTMEST) / PIXEL_TO_FLOAT_RATIO)).toEqual(bu); + expect(Math.floor((b.v - PIXEL_ADJUSTMEST) / PIXEL_TO_FLOAT_RATIO)).toEqual(bv); + expect(Math.floor((c.u - PIXEL_ADJUSTMEST) / PIXEL_TO_FLOAT_RATIO)).toEqual(cu); + expect(Math.floor((c.v - PIXEL_ADJUSTMEST) / PIXEL_TO_FLOAT_RATIO)).toEqual(cv); + + expect(indexA | (indexB << 7) | (indexC << 14) | (materialIndex << 28)).toEqual(dword); + } + + }); +}); diff --git a/tests/buster.test.ts b/test/buster.test.skip.ts similarity index 100% rename from tests/buster.test.ts rename to test/buster.test.skip.ts diff --git a/tests/hair.test.ts b/test/hair.test.skip.ts similarity index 100% rename from tests/hair.test.ts rename to test/hair.test.skip.ts diff --git a/tests/helmet.test.ts b/test/helmet.test.skip.ts similarity index 100% rename from tests/helmet.test.ts rename to test/helmet.test.skip.ts diff --git a/tests/left-arm.test.ts b/test/left-arm.test.skip.ts similarity index 100% rename from tests/left-arm.test.ts rename to test/left-arm.test.skip.ts diff --git a/tests/right-arm.test.ts b/test/right-arm.test.skip.ts similarity index 100% rename from tests/right-arm.test.ts rename to test/right-arm.test.skip.ts diff --git a/tests/shoes-asbestos.test.ts b/test/shoes-asbestos.test.skip.ts similarity index 100% rename from tests/shoes-asbestos.test.ts rename to test/shoes-asbestos.test.skip.ts diff --git a/tests/shoes-cleated.test.ts b/test/shoes-cleated.test.skip.ts similarity index 100% rename from tests/shoes-cleated.test.ts rename to test/shoes-cleated.test.skip.ts diff --git a/tests/shoes-hover.test.ts b/test/shoes-hover.test.skip.ts similarity index 100% rename from tests/shoes-hover.test.ts rename to test/shoes-hover.test.skip.ts diff --git a/tests/shoes-hydro.test.ts b/test/shoes-hydro.test.skip.ts similarity index 100% rename from tests/shoes-hydro.test.ts rename to test/shoes-hydro.test.skip.ts diff --git a/tests/shoes-jet.test.ts b/test/shoes-jet.test.skip.ts similarity index 100% rename from tests/shoes-jet.test.ts rename to test/shoes-jet.test.skip.ts diff --git a/tests/shoes-normal.test.ts b/test/shoes-normal.test.skip.ts similarity index 100% rename from tests/shoes-normal.test.ts rename to test/shoes-normal.test.skip.ts