feat: gun & turret origins

This commit is contained in:
TrèsAbhi committed 2023-12-31 19:26:08 -06:00
1 parent b433129354
commit 28dde23115
3 files changed
+54 -41

No files matched your search

+42 -39
View File
@@ -1,6 +1,6 @@
import { NodeIO } from '@gltf-transform/core'; import { NodeIO } from '@gltf-transform/core';
import { config } from 'dotenv'; import { config } from 'dotenv';
import { mkdir, readdir } from 'fs/promises'; import { readdir, writeFile } from 'fs/promises';
import { argv } from 'process'; import { argv } from 'process';
import sharp from 'sharp'; import sharp from 'sharp';
import { Vector3Tuple } from 'three'; import { Vector3Tuple } from 'three';
@@ -96,11 +96,17 @@ type ShellDefinitionsList = Record<
}; };
interface VehicleDefinitions { interface VehicleDefinitions {
invisibility: { moving: number; still: number; firePenalty: number }; invisibility: { moving: number; still: number; firePenalty: number };
hull: {
turretPositions: {
turret: string;
};
};
turrets0: { turrets0: {
[key: string]: { [key: string]: {
userString: number; userString: number;
level: number; level: number;
yawLimits: string | string[]; yawLimits: string | string[];
gunPosition: string | string[];
guns: { guns: {
[key: string]: { [key: string]: {
reloadTime: number; reloadTime: number;
@@ -164,7 +170,7 @@ if (!targets && !allTargets) throw new Error('No target(s) specified');
if (allTargets || targets?.includes('definitions')) { if (allTargets || targets?.includes('definitions')) {
console.log('Building tank definitions...'); console.log('Building tank definitions...');
const definitions: TankDefinitions = {}; const tankDefinitions: TankDefinitions = {};
const nations = await readdir(`${DATA}/${DOI.vehicleDefinitions}`).then( const nations = await readdir(`${DATA}/${DOI.vehicleDefinitions}`).then(
(nations) => nations.filter((nation) => nation !== 'common'), (nations) => nations.filter((nation) => nation !== 'common'),
); );
@@ -202,6 +208,9 @@ if (allTargets || targets?.includes('definitions')) {
const tankDefinition = await readXMLDVPL<{ root: VehicleDefinitions }>( const tankDefinition = await readXMLDVPL<{ root: VehicleDefinitions }>(
`${DATA}/${DOI.vehicleDefinitions}/${nation}/${tankKey}.xml.dvpl`, `${DATA}/${DOI.vehicleDefinitions}/${nation}/${tankKey}.xml.dvpl`,
); );
const turretOrigin = tankDefinition.root.hull.turretPositions.turret
.split(' ')
.map(Number) as Vector3Tuple;
const tankId = toUniqueId(nation, tank.id); const tankId = toUniqueId(nation, tank.id);
const tankTags = tank.tags.split(' '); const tankTags = tank.tags.split(' ');
const tankTurrets = Object.keys(tankDefinition.root.turrets0).map( const tankTurrets = Object.keys(tankDefinition.root.turrets0).map(
@@ -215,6 +224,13 @@ if (allTargets || targets?.includes('definitions')) {
) )
.split(' ') .split(' ')
.map(Number) as [number, number]; .map(Number) as [number, number];
const gunOrigin = (
typeof turret.gunPosition === 'string'
? turret.gunPosition
: turret.gunPosition[0]
)
.split(' ')
.map(Number) as Vector3Tuple;
const turretGuns = Object.keys(turret.guns).map((gunKey) => { const turretGuns = Object.keys(turret.guns).map((gunKey) => {
const turretGunEntry = turret.guns[gunKey]; const turretGunEntry = turret.guns[gunKey];
const gunId = toUniqueId(nation, gunList.root.ids[gunKey]); const gunId = toUniqueId(nation, gunList.root.ids[gunKey]);
@@ -291,12 +307,13 @@ if (allTargets || targets?.includes('definitions')) {
.replace(/^(Turret ([0-9] )?)+/, ''), .replace(/^(Turret ([0-9] )?)+/, ''),
tier: turret.level as Tier, tier: turret.level as Tier,
yaw: -turretYaw[0] + turretYaw[1] === 360 ? undefined : turretYaw, yaw: -turretYaw[0] + turretYaw[1] === 360 ? undefined : turretYaw,
gunOrigin,
guns: turretGuns, guns: turretGuns,
} satisfies TurretDefinition; } satisfies TurretDefinition;
}, },
); );
definitions[tankId] = { tankDefinitions[tankId] = {
id: tankId, id: tankId,
name: name:
(tank.shortUserString (tank.shortUserString
@@ -305,6 +322,7 @@ if (allTargets || targets?.includes('definitions')) {
strings[tank.userString] ?? strings[tank.userString] ??
tankKey.replaceAll('_', ' '), tankKey.replaceAll('_', ' '),
nation, nation,
turretOrigin,
tree_type: (tank.sellPrice ? 'gold' in tank.sellPrice : false) tree_type: (tank.sellPrice ? 'gold' in tank.sellPrice : false)
? 'collector' ? 'collector'
: (typeof tank.price === 'number' ? false : 'gold' in tank.price) : (typeof tank.price === 'number' ? false : 'gold' in tank.price)
@@ -326,36 +344,21 @@ if (allTargets || targets?.includes('definitions')) {
); );
console.log('Committing tank definitions...'); console.log('Committing tank definitions...');
// await commitMultipleFiles( writeFile('test.json', JSON.stringify(tankDefinitions));
// 'tresabhi', await commitMultipleFiles(
// 'blitzkrieg-assets', 'tresabhi',
// 'main', 'blitzkrieg-assets',
// 'definitions', 'main',
// [ 'definitions',
// { [
// content: JSON.stringify(tankDefinitions), {
// encoding: 'utf-8', content: JSON.stringify(tankDefinitions),
// path: 'definitions/tanks.json', encoding: 'utf-8',
// }, path: 'definitions/tanks.json',
// { },
// content: JSON.stringify(turretDefinitions), ],
// encoding: 'utf-8', true,
// path: 'definitions/turrets.json', );
// },
// {
// content: JSON.stringify(gunDefinitions),
// encoding: 'utf-8',
// path: 'definitions/guns.json',
// },
// {
// content: JSON.stringify(shellDefinitions),
// encoding: 'utf-8',
// path: 'definitions/shells.json',
// },
// ],
// true,
// );
} }
if ( if (
@@ -533,12 +536,12 @@ if (allTargets || targets?.includes('tankModels')) {
baseColor, baseColor,
); );
// writeFile( writeFile(
// `dist/assets/models/${id}.glb`, `dist/assets/models/${id}.glb`,
// await nodeIO.writeBinary(model), await nodeIO.writeBinary(model),
// ); );
await mkdir(`dist/assets/models/${id}`, { recursive: true }); // await mkdir(`dist/assets/models/${id}`, { recursive: true });
nodeIO.write(`dist/assets/models/${id}/index.gltf`, model); // nodeIO.write(`dist/assets/models/${id}/index.gltf`, model);
} }
}), }),
); );
+9 -2
View File
@@ -35,7 +35,10 @@ const vertexAttributeGltfVectorSizes = {
[VertexAttribute.TANGENT]: 4, [VertexAttribute.TANGENT]: 4,
} as const; } as const;
const omitNames = ['chassis_chassis_', 'chassis_track_crash_', 'HP_']; const omitMeshNames = {
start: ['chassis_chassis_', 'chassis_track_crash_', 'HP_'],
end: ['_POINT'],
};
export async function extractModel( export async function extractModel(
data: string, data: string,
@@ -145,7 +148,11 @@ export async function extractModel(
function parseHierarchies(hierarchies: Hierarchy[], parent: Scene | Node) { function parseHierarchies(hierarchies: Hierarchy[], parent: Scene | Node) {
hierarchies.forEach((hierarchy) => { hierarchies.forEach((hierarchy) => {
if (omitNames.some((omit) => hierarchy.name.startsWith(omit))) return; if (
omitMeshNames.start.some((omit) => hierarchy.name.startsWith(omit)) ||
omitMeshNames.end.some((omit) => hierarchy.name.endsWith(omit))
)
return;
const node = document.createNode(hierarchy.name); const node = document.createNode(hierarchy.name);
const components = times( const components = times(
+3
View File
@@ -1,4 +1,5 @@
import { deburr } from 'lodash'; import { deburr } from 'lodash';
import { Vector3Tuple } from 'three';
import { TankType, TreeTypeString } from '../../components/Tanks'; import { TankType, TreeTypeString } from '../../components/Tanks';
import { asset } from './asset'; import { asset } from './asset';
@@ -9,6 +10,7 @@ export interface TankDefinition {
id: number; id: number;
nation: string; nation: string;
name: string; name: string;
turretOrigin: Vector3Tuple;
tree_type: TreeTypeString; tree_type: TreeTypeString;
tier: Tier; tier: Tier;
type: TankType; type: TankType;
@@ -25,6 +27,7 @@ export interface TurretDefinition {
name: string; name: string;
tier: Tier; tier: Tier;
yaw?: [number, number]; yaw?: [number, number];
gunOrigin: Vector3Tuple;
guns: GunDefinition[]; guns: GunDefinition[];
} }
export type GunDefinition = GunDefinitionBase & export type GunDefinition = GunDefinitionBase &