Files
blitzkit/packages/scripts/src/buildAssets/tankModels.ts
T

47 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-09-05 20:45:04 -05:00
import { toUniqueId } from "@blitzkit/core";
import { NodeIO } from "@gltf-transform/core";
import { ALL_EXTENSIONS } from "@gltf-transform/extensions";
2025-09-06 00:48:39 -05:00
import { readdir } from "fs/promises";
2025-09-05 20:45:04 -05:00
import { extractModel } from "../core/blitz/extractModel";
import { readXMLDVPL } from "../core/blitz/readXMLDVPL";
import { readYAMLDVPL } from "../core/blitz/readYAMLDVPL";
2025-10-23 21:22:21 -05:00
import { AssetUploader } from "../core/github/assetUploader";
2025-09-05 20:45:04 -05:00
import { DATA } from "./constants";
import { VehicleDefinitionList } from "./definitions";
import { TankParameters } from "./tankIcons";
2024-01-07 20:07:45 -06:00
2024-08-27 14:40:43 -05:00
export async function tankModels() {
2025-09-05 20:45:04 -05:00
console.log("Building tank models...");
2024-01-07 20:07:45 -06:00
2025-10-23 21:22:21 -05:00
using uploader = new AssetUploader("tank models");
2024-11-11 12:50:33 -06:00
const nodeIO = new NodeIO().registerExtensions(ALL_EXTENSIONS);
2024-08-14 14:04:06 -05:00
const nations = await readdir(`${DATA}/XML/item_defs/vehicles`).then(
2025-09-05 20:45:04 -05:00
(nations) => nations.filter((nation) => nation !== "common")
2024-01-07 20:07:45 -06:00
);
2024-01-20 22:11:56 -06:00
for (const nationIndex in nations) {
const nation = nations[nationIndex];
2024-02-21 08:07:27 -06:00
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
2025-09-05 20:45:04 -05:00
`${DATA}/XML/item_defs/vehicles/${nation}/list.xml`
2024-01-20 22:11:56 -06:00
);
2025-09-05 20:45:04 -05:00
const entries = Object.entries(tanks.root);
2024-01-19 23:33:27 -06:00
2025-09-05 20:45:04 -05:00
for (const [tankKey, tank] of entries) {
if (tankKey.includes("tutorial_bot")) continue;
2024-01-07 20:07:45 -06:00
2025-04-05 02:07:35 +00:00
const id = toUniqueId(nation, tank.id);
const parameters = await readYAMLDVPL<TankParameters>(
2025-09-05 20:45:04 -05:00
`${DATA}/3d/Tanks/Parameters/${nation}/${tankKey}.yaml`
2025-04-05 02:07:35 +00:00
);
const model = await extractModel(
DATA,
2025-09-05 20:45:04 -05:00
parameters.resourcesPath.blitzModelPath.replace(/\.sc2$/, "")
2025-04-05 02:07:35 +00:00
);
2025-09-05 23:34:59 -05:00
const content = Buffer.from(await nodeIO.writeBinary(model));
2024-01-07 20:07:45 -06:00
2025-10-23 21:22:21 -05:00
await uploader.add({ path: `3d/tanks/models/${id}.glb`, content });
2025-04-05 02:07:35 +00:00
}
2024-01-20 22:11:56 -06:00
}
2025-10-23 21:22:21 -05:00
await uploader.flush();
2024-01-07 20:07:45 -06:00
}