feat: more data driven

This commit is contained in:
TrèsAbhi committed 2023-12-07 22:41:49 -06:00
1 parent 8caf4069dc
commit 81826d0549
2 files changed
+101 -97

No files matched your search

+5
View File
@@ -3,10 +3,12 @@
"Abhi", "Abhi",
"accountinfo", "accountinfo",
"bepaint", "bepaint",
"BINORMAL",
"blitzstars", "blitzstars",
"cleandist", "cleandist",
"cockroackdb", "cockroackdb",
"corsproxy", "corsproxy",
"CUBETEXCOORD",
"customperiod", "customperiod",
"deburr", "deburr",
"diacriticless", "diacriticless",
@@ -17,6 +19,8 @@
"fuzzysort", "fuzzysort",
"gamemode", "gamemode",
"immer", "immer",
"JOINTINDEX",
"JOINTWEIGHT",
"kranvagn", "kranvagn",
"krieg", "krieg",
"Leaderboard", "Leaderboard",
@@ -49,6 +53,7 @@
"tankopedia", "tankopedia",
"tankopedias", "tankopedias",
"tankstats", "tankstats",
"TEXCOORD",
"tresabhi", "tresabhi",
"Unicum", "Unicum",
"Unregistering", "Unregistering",
+96 -97
View File
@@ -1,6 +1,8 @@
import { writeFileSync } from 'fs';
import { readFile } from 'fs/promises'; import { readFile } from 'fs/promises';
import { range } from 'lodash';
enum KATypes { enum KAType {
NONE, NONE,
BOOLEAN, BOOLEAN,
INT32, INT32,
@@ -30,29 +32,61 @@ enum KATypes {
ARRAY, ARRAY,
} }
const VERTEX_TYPES = [ enum VertexType {
'VERTEX', VERTEX,
'NORMAL', NORMAL,
'COLOR', COLOR,
'TEXCOORD0', TEXCOORD0,
'TEXCOORD1', TEXCOORD1,
'TEXCOORD2', TEXCOORD2,
'TEXCOORD3', TEXCOORD3,
'TANGENT', TANGENT,
'BINORMAL', BINORMAL,
'HARD_JOINTINDEX', HARD_JOINTINDEX,
'PIVOT4', PIVOT4,
'FLEXIBILITY', FLEXIBILITY,
'ANGLE_SIN_COS', ANGLE_SIN_COS,
'JOINTINDEX', JOINTINDEX,
'JOINTWEIGHT', JOINTWEIGHT,
'CUBETEXCOORD0', CUBETEXCOORD0,
'CUBETEXCOORD1', CUBETEXCOORD1,
'CUBETEXCOORD2', CUBETEXCOORD2,
'CUBETEXCOORD3', CUBETEXCOORD3,
] as const; }
type VertexType = (typeof VERTEX_TYPES)[number]; const VECTOR_SIZES = [
[
// vector 1; basically array of 1 number
VertexType.COLOR,
VertexType.FLEXIBILITY,
VertexType.HARD_JOINTINDEX,
],
[
// vector 2; 2d vector
VertexType.TEXCOORD0,
VertexType.TEXCOORD1,
VertexType.TEXCOORD2,
VertexType.TEXCOORD3,
VertexType.ANGLE_SIN_COS,
],
[
// vector 3; 3d vector
VertexType.VERTEX,
VertexType.NORMAL,
VertexType.TANGENT,
VertexType.BINORMAL,
VertexType.CUBETEXCOORD0,
VertexType.CUBETEXCOORD1,
VertexType.CUBETEXCOORD2,
VertexType.CUBETEXCOORD3,
],
[
// vector 4; 4d vector or something more complex
VertexType.PIVOT4,
VertexType.JOINTINDEX,
VertexType.JOINTWEIGHT,
],
];
type KAResolvedValue<Type> = { buffer: Buffer; value: Type }; type KAResolvedValue<Type> = { buffer: Buffer; value: Type };
@@ -164,89 +198,54 @@ class SCPGStream {
.padStart(polygonGroupRaw.vertexFormat.buffer.length * 8, '0') .padStart(polygonGroupRaw.vertexFormat.buffer.length * 8, '0')
.split('') .split('')
.map(parseInt) .map(parseInt)
.map((bit, index) => { .map((bit, index) => (bit ? index : null))
if (bit) return VERTEX_TYPES[index]; .filter((index) => index !== null) as VertexType[];
})
.filter(Boolean);
const vertices: { type: VertexType; value: number[] }[] = []; const vertices: { type: VertexType; value: number[] }[] = [];
for (let index = 0; index < polygonGroupRaw.vertexCount.value; index++) { for (let index = 0; index < polygonGroupRaw.vertexCount.value; index++) {
// skipping 4 everytime stops leaving some garbage
verticesStream.skip(4);
vertexFormat.forEach((type) => { vertexFormat.forEach((type) => {
if (['COLOR', 'FLEXIBILITY', 'HARD_JOINTINDEX'].includes(type)) { const resolved = VECTOR_SIZES.some((types, size) => {
vertices.push({ if (types.includes(type)) {
type, vertices.push({
value: [verticesStream.consumeUInt32().value], type,
}); value: range(size + 1).map(
} else if ( () => verticesStream.consumeUInt32().value,
[ ),
'TEXCOORD0', });
'TEXCOORD1',
'TEXCOORD2', return true;
'TEXCOORD3', }
'ANGLE_SIN_COS', });
].includes(type)
) { if (!resolved) {
vertices.push({
type,
value: [
verticesStream.consumeUInt32().value,
verticesStream.consumeUInt32().value,
],
});
} else if (
[
'VERTEX',
'NORMAL',
'TANGENT',
'BINORMAL',
'CUBETEXCOORD0',
'CUBETEXCOORD1',
'CUBETEXCOORD2',
'CUBETEXCOORD3',
].includes(type)
) {
vertices.push({
type,
value: [
verticesStream.consumeUInt32().value,
verticesStream.consumeUInt32().value,
verticesStream.consumeUInt32().value,
],
});
} else if (['PIVOT4', 'JOINTINDEX', 'JOINTWEIGHT'].includes(type)) {
vertices.push({
type,
value: [
verticesStream.consumeUInt32().value,
verticesStream.consumeUInt32().value,
verticesStream.consumeUInt32().value,
verticesStream.consumeUInt32().value,
],
});
} else {
throw new TypeError(`Unknown vertex type: ${type}`); throw new TypeError(`Unknown vertex type: ${type}`);
} }
}); });
} }
console.log(verticesStream.consumeRemaining().length);
return { vertices, indices }; return { vertices, indices };
}); });
// writeFileSync( writeFileSync(
// 'test.txt', 'test.txt',
// polygonGroups polygonGroups
// .map((i) => .map((i) =>
// i.vertices i.vertices
// .map( .map(
// (e) => (e) =>
// `${e.type.padEnd(16, ' ')} ${e.value `${VertexType[e.type].padEnd(16, ' ')} ${e.value
// .map((j) => j.toString(16).padStart(8, '0')) .map((j) => j.toString(16).padStart(8, '0'))
// .join(' ')}`, .join(' ')}`,
// ) )
// .join('\n'), .join('\n'),
// ) )
// .join('\n\n'), .join('\n\n'),
// ); );
return polygonGroups; return polygonGroups;
} }
@@ -262,15 +261,15 @@ class SCPGStream {
const type = this.consumeUInt8().value; const type = this.consumeUInt8().value;
switch (type) { switch (type) {
case KATypes.INT32: case KAType.INT32:
return this.consumeInt32(); return this.consumeInt32();
case KATypes.STRING: { case KAType.STRING: {
const length = this.consumeUInt32(); const length = this.consumeUInt32();
return this.consumeAscii(length.value); return this.consumeAscii(length.value);
} }
case KATypes.BYTE_ARRAY: { case KAType.BYTE_ARRAY: {
const length = this.consumeUInt32(); const length = this.consumeUInt32();
return this.consumeByteArray(length.value); return this.consumeByteArray(length.value);
} }