-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathskeleton.test.ts
70 lines (56 loc) · 2.13 KB
/
skeleton.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { test, expect } from "bun:test";
import { readFileSync } from "fs";
import megamanSkeleton from "../fixtures/megamanSkeleton.json";
import rollSkeleton from "../fixtures/rollSkeleton.json";
import ByteReader from "../src/ByteReader";
const SCALE = 0.00125;
const ROT = new Matrix4();
ROT.makeRotationX(Math.PI);
type Vector = {
x: number;
y: number;
z: number;
};
import { Vector3, Matrix4 } from "three";
test("reading the MegaMan skeleton", () => {
const file = readFileSync(`./bin/PL00P000.BIN`);
const dat = file.subarray(0x30, 0x30 + 0x2b40);
const { buffer } = Buffer.from(dat);
const reader = new ByteReader(buffer as ArrayBuffer);
const bones: Vector[] = [];
for (let i = 0; i < 16; i++) {
const xRaw = reader.readInt16();
const yRaw = reader.readInt16();
const zRaw = reader.readInt16();
const vec3 = new Vector3(xRaw, yRaw, zRaw);
vec3.multiplyScalar(SCALE);
vec3.applyMatrix4(ROT);
const { x, y, z } = vec3;
const xAdjust = parseFloat((Math.abs(x) < 0.01 ? 0 : x).toFixed(3));
const yAdjust = parseFloat((Math.abs(y) < 0.01 ? 0 : y).toFixed(3));
const zAdjust = parseFloat((Math.abs(z) < 0.01 ? 0 : z).toFixed(3));
bones.push({ x: xAdjust, y: yAdjust, z: zAdjust });
}
expect(bones).toEqual(megamanSkeleton);
});
test("reading the Roll skeleton", () => {
const file = readFileSync(`./bin/PL01P000.BIN`);
const dat = file.subarray(0x30, 0x30 + 0x2b40);
const { buffer } = Buffer.from(dat);
const reader = new ByteReader(buffer as ArrayBuffer);
const bones: Vector[] = [];
for (let i = 0; i < 16; i++) {
const xRaw = reader.readInt16();
const yRaw = reader.readInt16();
const zRaw = reader.readInt16();
const vec3 = new Vector3(xRaw, yRaw, zRaw);
vec3.multiplyScalar(SCALE);
vec3.applyMatrix4(ROT);
const { x, y, z } = vec3;
const xAdjust = parseFloat((Math.abs(x) < 0.01 ? 0 : x).toFixed(3));
const yAdjust = parseFloat((Math.abs(y) < 0.01 ? 0 : y).toFixed(3));
const zAdjust = parseFloat((Math.abs(z) < 0.01 ? 0 : z).toFixed(3));
bones.push({ x: xAdjust, y: yAdjust, z: zAdjust });
}
expect(bones).toEqual(rollSkeleton);
});