From 2e2ab9b2d915bc4710b53f07189b3065906bff6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:01:50 -0600 Subject: [PATCH] fix: added binary start padding --- scripts/buildAssets.ts | 2 ++ src/core/blitz/SCPGStream.ts | 25 ++++++++++--------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/scripts/buildAssets.ts b/scripts/buildAssets.ts index 8d143790d..526eda156 100644 --- a/scripts/buildAssets.ts +++ b/scripts/buildAssets.ts @@ -298,6 +298,7 @@ if (allTargets || targets?.includes('tankModels')) { const nationVehicleId = tank.id; const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1; + // if (id !== 897) continue; console.log(`Building model ${id} @ ${nation}/${tankIndex}`); const parameters = await readYAMLDVPL( @@ -314,6 +315,7 @@ if (allTargets || targets?.includes('tankModels')) { const scgStream = await SCPGStream.fromDVPLFile( `${DATA}/${DOI['3d']}/${scgPath}.dvpl`, ); + const sc2 = sc2Stream.consumeSC2(); const scg = scgStream.consumeSCG(); } diff --git a/src/core/blitz/SCPGStream.ts b/src/core/blitz/SCPGStream.ts index 369890d76..5cb39fe60 100644 --- a/src/core/blitz/SCPGStream.ts +++ b/src/core/blitz/SCPGStream.ts @@ -90,12 +90,7 @@ const VECTOR_SIZES = [ VertexType.CUBETEXCOORD2, VertexType.CUBETEXCOORD3, ], - [ - VertexType.PIVOT4, - VertexType.JOINTINDEX, - VertexType.JOINTWEIGHT, - // VertexType.TANGENT, - ], + [VertexType.PIVOT4, VertexType.JOINTINDEX, VertexType.JOINTWEIGHT], ]; export class SCPGStream { @@ -221,22 +216,22 @@ export class SCPGStream { } const verticesStream = new SCPGStream(polygonGroupRaw.vertices); - const vertexFormat = [ - ...polygonGroupRaw.vertexFormat.toString(2).padEnd(64, '0'), - ] - .map((bit, index) => (bit === '1' ? index : null)) - .filter((index) => index !== null) as VertexType[]; const vertices: Partial>[] = []; + const vertexFormatBuffer = Buffer.alloc(4); + vertexFormatBuffer.writeUInt32LE(polygonGroupRaw.vertexFormat, 0); + const vertexFormat = [...vertexFormatBuffer] + .map((number) => number.toString(2)) + .join('') + .split('') + .map((bitString, index) => (bitString === '1' ? index : null)) + .filter((type) => type !== null) as VertexType[]; for (let index = 0; index < polygonGroupRaw.vertexCount; index++) { vertexFormat.forEach((type) => { const resolved = VECTOR_SIZES.some((types, size) => { if (types.includes(type)) { if (!(index in vertices)) vertices[index] = {}; - - vertices[index][type] = times(size + 1).map(() => - verticesStream.consumeFloat(), - ); + vertices[index][type] = verticesStream.consumeVectorN(size + 1); return true; }