From 60a115b7d8aa6c0f287d10e7aca21c53b86914c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sun, 18 Feb 2024 16:17:00 -0600 Subject: [PATCH] feat: more accurate models --- package.json | 4 ++-- scripts/buildAssets/index.ts | 2 +- src/core/blitz/extractArmor.ts | 4 ++-- src/core/blitz/extractModel.ts | 8 ++++---- src/core/blitzkrieg/equipmentDefinitions.ts | 2 -- src/core/blitzkrieg/readTexture.ts | 10 +++++----- src/core/streams/sc2.ts | 20 ++++++++++---------- src/core/streams/scg.ts | 17 ++++++++++------- yarn.lock | 10 +++++----- 9 files changed, 39 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index 7ee6b09db..07d985e78 100644 --- a/package.json +++ b/package.json @@ -65,8 +65,8 @@ "react-spinners": "^0.13.8", "satori": "^0.10.8", "sharp": "0.33.1", - "three": "0.159.0", - "three-stdlib": "^2.29.1", + "three": "^0.161.0", + "three-stdlib": "^2.29.4", "vite-node": "^0.34.5", "vitepress": "^1.0.0-rc.20", "vitepress-plugin-auto-sidebar": "^1.1.0", diff --git a/scripts/buildAssets/index.ts b/scripts/buildAssets/index.ts index cb1751c7a..6d2421499 100644 --- a/scripts/buildAssets/index.ts +++ b/scripts/buildAssets/index.ts @@ -40,5 +40,5 @@ const methods = [ ]; for (const method of methods) { - if (allTargets || targets?.includes(method.name)) method(production); + if (allTargets || targets?.includes(method.name)) await method(production); } diff --git a/src/core/blitz/extractArmor.ts b/src/core/blitz/extractArmor.ts index f0b8072d4..b2819ff05 100644 --- a/src/core/blitz/extractArmor.ts +++ b/src/core/blitz/extractArmor.ts @@ -16,8 +16,8 @@ Buffer.prototype.toJSON = function () { export async function extractArmor(data: string, fileName: string) { const sc2Path = `${data}/3d/Tanks/CollisionMeshes/${fileName}.sc2.dvpl`; const scgPath = `${data}/3d/Tanks/CollisionMeshes/${fileName}.scg.dvpl`; - const sc2 = new Sc2ReadStream(await readDVPLFile(sc2Path)).sc2(); - const scg = new ScgReadStream(await readDVPLFile(scgPath)).scg(); + const sc2 = new Sc2ReadStream((await readDVPLFile(sc2Path)).buffer).sc2(); + const scg = new ScgReadStream((await readDVPLFile(scgPath)).buffer).scg(); const document = new Document(); const scene = document.createScene(); const buffer = document.createBuffer(); diff --git a/src/core/blitz/extractModel.ts b/src/core/blitz/extractModel.ts index fa00d9387..87d2b61b4 100644 --- a/src/core/blitz/extractModel.ts +++ b/src/core/blitz/extractModel.ts @@ -48,8 +48,8 @@ export async function extractModel( ) { const sc2Path = `${data}/3d/${path}.sc2.dvpl`; const scgPath = `${data}/3d/${path}.scg.dvpl`; - const sc2 = new Sc2ReadStream(await readDVPLFile(sc2Path)).sc2(); - const scg = new ScgReadStream(await readDVPLFile(scgPath)).scg(); + const sc2 = new Sc2ReadStream((await readDVPLFile(sc2Path)).buffer).sc2(); + const scg = new ScgReadStream((await readDVPLFile(scgPath)).buffer).scg(); const document = new Document(); const scene = document.createScene(); const buffer = document.createBuffer(); @@ -58,7 +58,7 @@ export async function extractModel( // create materials await Promise.all( sc2['#dataNodes'].map(async (node) => { - const id = node['#id'].readBigUInt64LE(); + const id = new DataView(node['#id']).getBigUint64(0, true); if (node.parentMaterialKey !== undefined) { /** @@ -140,7 +140,7 @@ export async function extractModel( } } - materials.set(node['#id'].readBigUInt64LE(), material); + materials.set(new DataView(node['#id']).getBigUint64(0, true), material); }), ); diff --git a/src/core/blitzkrieg/equipmentDefinitions.ts b/src/core/blitzkrieg/equipmentDefinitions.ts index ead52a68c..65b032f40 100644 --- a/src/core/blitzkrieg/equipmentDefinitions.ts +++ b/src/core/blitzkrieg/equipmentDefinitions.ts @@ -25,5 +25,3 @@ export interface EquipmentDefinitions { export const equipmentDefinitions = fetchCdonLz4( asset('definitions/equipment.cdon.lz4'), ); - -equipmentDefinitions.then(console.log); diff --git a/src/core/blitzkrieg/readTexture.ts b/src/core/blitzkrieg/readTexture.ts index fd5620b20..81fe709fb 100644 --- a/src/core/blitzkrieg/readTexture.ts +++ b/src/core/blitzkrieg/readTexture.ts @@ -36,8 +36,8 @@ export async function readTexture(path: string, options?: ReadTextureOptions) { const decompressedDvpl = await readDVPLFile(resolvedTexturePath); const raw = isDds - ? await new DdsReadStream(decompressedDvpl).dds() - : new PvrReadStream(decompressedDvpl).pvr(); + ? await new DdsReadStream(decompressedDvpl.buffer).dds() + : new PvrReadStream(decompressedDvpl.buffer).pvr(); const channels = 4 * raw.width * raw.height; switch (options?.mutation) { @@ -81,11 +81,11 @@ export async function readTexture(path: string, options?: ReadTextureOptions) { case TextureMutation.Miscellaneous: { for (let index = 0; index < channels; index += 4) { /** - * Green is ambient occlusion and alpha is emissive. But very few tanks + * Alpha is ambient occlusion and green is emissive. But very few tanks * use emissive so I am ignoring it for now. */ - const occlusion = raw.data[index + 1]; - // const emissive = raw.data[index + 3]; + // const emissive = raw.data[index + 1]; + const occlusion = raw.data[index + 3]; raw.data[index] = occlusion; raw.data[index + 1] = 0; diff --git a/src/core/streams/sc2.ts b/src/core/streams/sc2.ts index b9dd1c5d3..506aee783 100644 --- a/src/core/streams/sc2.ts +++ b/src/core/streams/sc2.ts @@ -9,7 +9,7 @@ export interface SC2 { type DataNode = { '##name': 'NMaterial'; - '#id': Buffer; + '#id': ArrayBuffer; materialName: string; parentMaterialKey?: bigint; qualityGroup?: string; @@ -46,15 +46,15 @@ interface Flags { } interface Properties { - alphatestThreshold: Buffer; - attenuationBoxHalfSize: Buffer; - attenuationBoxSmoothness: Buffer; - baseColorFactor?: Buffer; - decalTileCoordScale?: Buffer; - inGlossiness: Buffer; - inSpecularity: Buffer; - metalFresnelReflectance: Buffer; - metallicRoughnessFactor?: Buffer; + alphatestThreshold: ArrayBuffer; + attenuationBoxHalfSize: ArrayBuffer; + attenuationBoxSmoothness: ArrayBuffer; + baseColorFactor?: ArrayBuffer; + decalTileCoordScale?: ArrayBuffer; + inGlossiness: ArrayBuffer; + inSpecularity: ArrayBuffer; + metalFresnelReflectance: ArrayBuffer; + metallicRoughnessFactor?: ArrayBuffer; } interface TextureSampleStates { diff --git a/src/core/streams/scg.ts b/src/core/streams/scg.ts index c703a3f7b..2297a799d 100644 --- a/src/core/streams/scg.ts +++ b/src/core/streams/scg.ts @@ -2,18 +2,18 @@ import { ScpgReadStream, VertexAttribute } from './scpg'; interface PolygonGroupRaw { '##name': 'PolygonGroup'; - '#id': Buffer; + '#id': ArrayBuffer; cubeTextureCoordCount: number; indexCount: number; indexFormat: 0 | 1; - indices: Buffer; + indices: ArrayBuffer; packing: 0 | 1; primitiveCount: number; rhi_primitiveType: 1 | 2 | 10; textureCoordCount: number; vertexCount: number; vertexFormat: number; - vertices: Buffer; + vertices: ArrayBuffer; } type BlitzkriegVertex = { attribute: VertexAttribute; value: number[] }[]; @@ -104,10 +104,13 @@ export class ScgReadStream extends ScpgReadStream { })); } - polygonGroups.set(polygonGroupRaw['#id'].readBigUInt64LE(), { - vertices, - indices, - }); + polygonGroups.set( + new DataView(polygonGroupRaw['#id']).getBigUint64(0, true), + { + vertices, + indices, + }, + ); }); return polygonGroups; diff --git a/yarn.lock b/yarn.lock index 09b485c8e..8f4cb727a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5342,7 +5342,7 @@ three-mesh-bvh@^0.7.0: resolved "https://registry.yarnpkg.com/three-mesh-bvh/-/three-mesh-bvh-0.7.1.tgz#c11461b73e71c143717f95e0a8e6c9721ad0de77" integrity sha512-63xvjnmK3FpA41klHfVvTMi2JRFdKeu3b4STBcLvGyDMYRpkBIyJ2d77CnNvKBZl9bed4sdEyrqE3AOsGorjUA== -three-stdlib@^2.29.1, three-stdlib@^2.29.4: +three-stdlib@^2.29.4: version "2.29.4" resolved "https://registry.yarnpkg.com/three-stdlib/-/three-stdlib-2.29.4.tgz#6e8741f6a2d435d15ed73f3a14dd149660d4ce51" integrity sha512-XNzGCrz/uAk9XoLwd35eN7dQyI4ggXZTeqjcN034YdYBpBlNO9kmLHehl/0Nw9jCelblB7jla+unHAOIyLyV6Q== @@ -5354,10 +5354,10 @@ three-stdlib@^2.29.1, three-stdlib@^2.29.4: fflate "^0.6.9" potpack "^1.0.1" -three@0.159.0: - version "0.159.0" - resolved "https://registry.yarnpkg.com/three/-/three-0.159.0.tgz#6576b1210805b14f0765bac41fd0e4ec18e43b2e" - integrity sha512-eCmhlLGbBgucuo4VEA9IO3Qpc7dh8Bd4VKzr7WfW4+8hMcIfoAVi1ev0pJYN9PTTsCslbcKgBwr2wNZ1EvLInA== +three@^0.161.0: + version "0.161.0" + resolved "https://registry.yarnpkg.com/three/-/three-0.161.0.tgz#38aafaa82fe5467fde2e33933515d1b6beb17d91" + integrity sha512-LC28VFtjbOyEu5b93K0bNRLw1rQlMJ85lilKsYj6dgTu+7i17W+JCCEbvrpmNHF1F3NAUqDSWq50UD7w9H2xQw== through2@^4.0.0: version "4.0.2"