From ca030688cbd95df9de1ac053c539b65e7021d9f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:45:43 -0600 Subject: [PATCH] feat: things? --- scripts/buildAssets/tankArmors.ts | 2 + scripts/buildAssets/tankIcons.ts | 1 + scripts/buildAssets/tankModels.ts | 15 ++- src/core/blitz/extractModel.ts | 112 ++++++++++++-------- src/core/blitzkrieg/commitAssets.ts | 2 + src/core/blitzkrieg/createBlob.ts | 2 +- src/core/blitzkrieg/equipmentDefinitions.ts | 2 - src/core/streams/cdon.ts | 4 +- 8 files changed, 83 insertions(+), 57 deletions(-) diff --git a/scripts/buildAssets/tankArmors.ts b/scripts/buildAssets/tankArmors.ts index 9e67677e2..b23bbf1ae 100644 --- a/scripts/buildAssets/tankArmors.ts +++ b/scripts/buildAssets/tankArmors.ts @@ -29,6 +29,8 @@ export async function tankArmors(production: boolean) { const id = toUniqueId(nation, tank.id); + if (id !== 12913) return; + console.log(`Building armor ${id} @ ${nation}/${tankKey}`); const model = await extractArmor(DATA, `${nation}-${tankKey}`); diff --git a/scripts/buildAssets/tankIcons.ts b/scripts/buildAssets/tankIcons.ts index c89df9498..2bef7b303 100644 --- a/scripts/buildAssets/tankIcons.ts +++ b/scripts/buildAssets/tankIcons.ts @@ -47,6 +47,7 @@ export async function tankIcons(production: boolean) { const nationVehicleId = tank.id; const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1; + if (12913 !== id) return; const parameters = await readYAMLDVPL( `${DATA}/${POI.tankParameters}/${nation}/${tankKey}.yaml.dvpl`, ); diff --git a/scripts/buildAssets/tankModels.ts b/scripts/buildAssets/tankModels.ts index 1943befc8..e9295b04f 100644 --- a/scripts/buildAssets/tankModels.ts +++ b/scripts/buildAssets/tankModels.ts @@ -5,6 +5,7 @@ import { extractModel } from '../../src/core/blitz/extractModel'; import { readXMLDVPL } from '../../src/core/blitz/readXMLDVPL'; import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL'; import { toUniqueId } from '../../src/core/blitz/toUniqueId'; +import { FileChange } from '../../src/core/blitzkrieg/commitMultipleFiles'; import { AssetCommit } from '../../src/core/github/assetCommit'; import { DATA, POI } from './constants'; import { VehicleDefinitionList } from './definitions'; @@ -24,6 +25,7 @@ export async function tankModels(production: boolean) { for (const nationIndex in nations) { const nation = nations[nationIndex]; + const changes: FileChange[] = []; const assetCommit = new AssetCommit(`tank models ${nation}`, production); const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>( `${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`, @@ -56,14 +58,17 @@ export async function tankModels(production: boolean) { baseColor, ); - assetCommit.add( - `3d/tanks/models/${id}.glb`, - Buffer.from(await nodeIO.writeBinary(model)).toString('base64'), - 'base64', - ); + changes.push({ + path: `3d/tanks/models/${id}.glb`, + content: Buffer.from(await nodeIO.writeBinary(model)).toString( + 'base64', + ), + encoding: 'base64', + }); }), ); assetCommit.push(); + // await commitAssets(`tank models ${nation}`, changes, production); } } diff --git a/src/core/blitz/extractModel.ts b/src/core/blitz/extractModel.ts index 87d2b61b4..454d8aeda 100644 --- a/src/core/blitz/extractModel.ts +++ b/src/core/blitz/extractModel.ts @@ -1,5 +1,5 @@ import { Document, Material, Node, Scene } from '@gltf-transform/core'; -import { range, times } from 'lodash'; +import { times } from 'lodash'; import { dirname } from 'path'; import { Matrix4, @@ -221,59 +221,77 @@ export async function extractModel( } case 'RenderComponent': { - let minLODDistanceBatchId: undefined | number; + // let minLODDistanceBatchId: undefined | number; - if (component['rc.renderObj']['rb0.lodIndex'] === -1) { - minLODDistanceBatchId = 0; - } else { - const lodList = components.find( - (component) => component['comp.typename'] === 'LodComponent', - ); + // if (component['rc.renderObj']['rb0.lodIndex'] === -1) { + // minLODDistanceBatchId = 0; + // } else { + // const lodList = components.find( + // (component) => component['comp.typename'] === 'LodComponent', + // ); - if ( - lodList === undefined || - lodList['comp.typename'] !== 'LodComponent' // type annotation hack - ) { - throw new SyntaxError('Missing LodComponent'); - } + // if ( + // lodList === undefined || + // lodList['comp.typename'] !== 'LodComponent' // type annotation hack + // ) { + // throw new SyntaxError('Missing LodComponent'); + // } - let minLODDistance = Infinity; - let isFirstMaxFloat = true; - let lodIndexStreak = 0; - let lodIndexStreakIndex: undefined | number = undefined; + // let minLODDistance = Infinity; + // let isFirstMaxFloat = true; + // let lodIndexStreak = 0; + // let lodIndexStreakIndex: undefined | number = undefined; - range(component['rc.renderObj']['ro.batchCount']).forEach( - (id) => { - const lodIndex = - component['rc.renderObj'][`rb${id}.lodIndex`]; - const lodDistance = - lodList['lc.loddist'][`distance${lodIndex}`]; + // range(component['rc.renderObj']['ro.batchCount']).forEach( + // (id) => { + // const lodIndex = + // component['rc.renderObj'][`rb${id}.lodIndex`]; + // const lodDistance = + // lodList['lc.loddist'][`distance${lodIndex}`]; - if (lodIndexStreakIndex === lodIndex) { - lodIndexStreak++; - } else { - lodIndexStreak = 0; - lodIndexStreakIndex = lodIndex; - } + // if (lodIndexStreakIndex === lodIndex) { + // lodIndexStreak++; + // } else { + // lodIndexStreak = 0; + // lodIndexStreakIndex = lodIndex; + // } - if ( - lodDistance < minLODDistance || - (lodDistance === minLODDistance && lodIndexStreak > 0) || - (lodDistance === MAX_FLOAT32 && isFirstMaxFloat) - ) { - if (lodDistance === MAX_FLOAT32) isFirstMaxFloat = false; - minLODDistance = lodDistance; - minLODDistanceBatchId = id; - } - }, - ); - } + // if ( + // lodDistance < minLODDistance || + // (lodDistance === minLODDistance && lodIndexStreak > 0) || + // (lodDistance === MAX_FLOAT32 && isFirstMaxFloat) + // ) { + // if (lodDistance === MAX_FLOAT32) isFirstMaxFloat = false; + // minLODDistance = lodDistance; + // minLODDistanceBatchId = id; + // } + // }, + // ); + // } - const batch = - component['rc.renderObj']['ro.batches'][ - minLODDistanceBatchId!.toString().padStart(4, '0') - ]; - const polygonGroup = scg.get(batch['rb.datasource']); + let batch = component['rc.renderObj']['ro.batches']['0000']; + let polygonGroup = scg.get(batch['rb.datasource'])!; + + Object.values(component['rc.renderObj']['ro.batches']).forEach( + (thisBatch) => { + const thisPolygonGroup = scg.get(thisBatch['rb.datasource']); + + if ( + thisPolygonGroup && + thisPolygonGroup.vertices.length > + polygonGroup.vertices.length + ) { + batch = thisBatch; + polygonGroup = thisPolygonGroup; + } + }, + ); + + // const batch = + // component['rc.renderObj']['ro.batches'][ + // minLODDistanceBatchId!.toString().padStart(4, '0') + // ]; + // const polygonGroup = scg.get(batch['rb.datasource']); if (!polygonGroup) { console.warn( diff --git a/src/core/blitzkrieg/commitAssets.ts b/src/core/blitzkrieg/commitAssets.ts index 55a366023..2c53e8814 100644 --- a/src/core/blitzkrieg/commitAssets.ts +++ b/src/core/blitzkrieg/commitAssets.ts @@ -7,6 +7,8 @@ export async function commitAssets( ) { console.log(`Committing ${message}...`); + if (changes.length === 0) return; + await commitMultipleFiles( 'tresabhi', 'blitzkrieg-assets', diff --git a/src/core/blitzkrieg/createBlob.ts b/src/core/blitzkrieg/createBlob.ts index 227cd2987..743820083 100644 --- a/src/core/blitzkrieg/createBlob.ts +++ b/src/core/blitzkrieg/createBlob.ts @@ -40,6 +40,6 @@ export const createBlob = throttle( } } }, - 1000, + (5000 / (60 * 60 * 1000)) * 0.95, // 5% less than max rate { trailing: true }, ); 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/streams/cdon.ts b/src/core/streams/cdon.ts index 8daf24923..3fe5a4504 100644 --- a/src/core/streams/cdon.ts +++ b/src/core/streams/cdon.ts @@ -212,7 +212,7 @@ export class CdonWriteStream extends WriteStream { object: CdonValue, stringTable: Map, ) { - if (object === null || object === undefined) { + if (object === null) { this.uint8(ValueType.Null); } else if (typeof object === 'boolean') { this.uint8(ValueType.Boolean); @@ -289,7 +289,7 @@ export class CdonWriteStream extends WriteStream { object.forEach((value) => this.value(fastStringFormat, value, stringTable), ); - } else { + } else if (object !== undefined) { const entries = Object.entries(object); this.uint8(ValueType.Object);