2024-01-07 20:07:45 -06:00
|
|
|
import { NodeIO } from '@gltf-transform/core';
|
2024-01-09 13:36:33 -06:00
|
|
|
import { readdir } from 'fs/promises';
|
2024-01-07 20:07:45 -06:00
|
|
|
import { Vector3Tuple } from 'three';
|
|
|
|
|
import { extractModel } from '../../src/core/blitz/extractModel';
|
|
|
|
|
import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL';
|
|
|
|
|
import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL';
|
2024-01-08 18:34:04 -06:00
|
|
|
import { toUniqueId } from '../../src/core/blitz/toUniqueId';
|
2024-02-19 18:45:43 -06:00
|
|
|
import { FileChange } from '../../src/core/blitzkrieg/commitMultipleFiles';
|
2024-02-18 19:11:41 -06:00
|
|
|
import { AssetCommit } from '../../src/core/github/assetCommit';
|
2024-01-16 16:58:00 -06:00
|
|
|
import { DATA, POI } from './constants';
|
2024-01-07 20:07:45 -06:00
|
|
|
import { VehicleDefinitionList } from './definitions';
|
|
|
|
|
import { TankParameters } from './tankIcons';
|
|
|
|
|
|
|
|
|
|
interface VehicleCustomization {
|
|
|
|
|
armorColor: string;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 15:27:21 -06:00
|
|
|
export async function tankModels(production: boolean) {
|
2024-01-07 20:07:45 -06:00
|
|
|
console.log('Building tank models...');
|
|
|
|
|
|
|
|
|
|
const nodeIO = new NodeIO();
|
2024-01-16 16:58:00 -06:00
|
|
|
const nations = await readdir(`${DATA}/${POI.vehicleDefinitions}`).then(
|
2024-01-07 20:07:45 -06:00
|
|
|
(nations) => nations.filter((nation) => nation !== 'common'),
|
|
|
|
|
);
|
|
|
|
|
|
2024-01-20 22:11:56 -06:00
|
|
|
for (const nationIndex in nations) {
|
|
|
|
|
const nation = nations[nationIndex];
|
2024-02-19 18:45:43 -06:00
|
|
|
const changes: FileChange[] = [];
|
2024-02-18 19:11:41 -06:00
|
|
|
const assetCommit = new AssetCommit(`tank models ${nation}`, production);
|
2024-01-20 22:11:56 -06:00
|
|
|
const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>(
|
|
|
|
|
`${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`,
|
|
|
|
|
);
|
|
|
|
|
const customization = await readXMLDVPL<{ root: VehicleCustomization }>(
|
|
|
|
|
`${DATA}/${POI.vehicleDefinitions}/${nation}/customization.xml.dvpl`,
|
|
|
|
|
);
|
|
|
|
|
const baseColor = customization.root.armorColor
|
|
|
|
|
.split(' ')
|
|
|
|
|
.slice(0, 3)
|
|
|
|
|
.map(Number)
|
|
|
|
|
.map((channel) => channel / 255) as Vector3Tuple;
|
2024-01-19 23:33:27 -06:00
|
|
|
|
2024-02-18 19:11:41 -06:00
|
|
|
if (nation !== 'other') continue;
|
|
|
|
|
|
2024-01-20 22:11:56 -06:00
|
|
|
await Promise.all(
|
|
|
|
|
Object.entries(tanks.root).map(async ([tankKey, tank]) => {
|
|
|
|
|
if (tankKey.includes('tutorial_bot')) return;
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2024-01-20 22:11:56 -06:00
|
|
|
const id = toUniqueId(nation, tank.id);
|
2024-01-20 13:43:03 -06:00
|
|
|
|
2024-01-20 22:11:56 -06:00
|
|
|
console.log(`Building model ${id} @ ${nation}/${tankKey}`);
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2024-01-20 22:11:56 -06:00
|
|
|
const parameters = await readYAMLDVPL<TankParameters>(
|
|
|
|
|
`${DATA}/${POI.tankParameters}/${nation}/${tankKey}.yaml.dvpl`,
|
|
|
|
|
);
|
|
|
|
|
const model = await extractModel(
|
|
|
|
|
DATA,
|
|
|
|
|
parameters.resourcesPath.blitzModelPath.replace(/\.sc2$/, ''),
|
|
|
|
|
baseColor,
|
|
|
|
|
);
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2024-02-19 18:45:43 -06:00
|
|
|
changes.push({
|
|
|
|
|
path: `3d/tanks/models/${id}.glb`,
|
|
|
|
|
content: Buffer.from(await nodeIO.writeBinary(model)).toString(
|
|
|
|
|
'base64',
|
|
|
|
|
),
|
|
|
|
|
encoding: 'base64',
|
|
|
|
|
});
|
2024-01-20 22:11:56 -06:00
|
|
|
}),
|
|
|
|
|
);
|
2024-01-07 20:07:45 -06:00
|
|
|
|
2024-02-18 19:11:41 -06:00
|
|
|
assetCommit.push();
|
2024-02-19 18:45:43 -06:00
|
|
|
// await commitAssets(`tank models ${nation}`, changes, production);
|
2024-01-20 22:11:56 -06:00
|
|
|
}
|
2024-01-07 20:07:45 -06:00
|
|
|
}
|