Skip to content

Commit

Permalink
Merge pull request #4 from kion-dgl/encode-tri
Browse files Browse the repository at this point in the history
Encode tri
  • Loading branch information
kion-dgl authored Jul 7, 2024
2 parents 05011aa + c348aa4 commit 81077fb
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 12 deletions.
Binary file modified bun.lockb
Binary file not shown.
File renamed without changes.
File renamed without changes.
72 changes: 60 additions & 12 deletions tests/body.test.ts → test/body.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 81077fb

Please sign in to comment.