Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode tri #4

Merged
merged 3 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.