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

42 lines
1.5 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";
import { extractModel } from "../core/blitz/extractModel";
2025-10-23 21:22:21 -05:00
import { AssetUploader } from "../core/github/assetUploader";
2025-11-26 13:18:44 -06:00
import { vfs } from "./constants";
2025-09-05 20:45:04 -05:00
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);
2025-11-26 13:18:44 -06:00
const nations = vfs.dir(`Data/XML/item_defs/vehicles`).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];
2025-11-26 13:18:44 -06:00
const tanks = await vfs.xml<{ root: VehicleDefinitionList }>(
`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);
2025-11-26 13:18:44 -06:00
const parameters = await vfs.yaml<TankParameters>(
`Data/3d/Tanks/Parameters/${nation}/${tankKey}.yaml`
2025-04-05 02:07:35 +00:00
);
const model = await extractModel(
2025-11-26 13:18:44 -06:00
vfs,
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
}