From d0d28baee00ff1fc5ced630a0fac945e00e64b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sat, 20 Jan 2024 23:20:00 -0600 Subject: [PATCH] feat: safer unknown component handling --- scripts/buildAssets/tankModels.ts | 5 +++++ src/core/blitz/extractModel.ts | 29 ++++++++++------------------- src/core/streams/sc2.ts | 11 +++++++++++ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/scripts/buildAssets/tankModels.ts b/scripts/buildAssets/tankModels.ts index b6309a8cd..e32307d9f 100644 --- a/scripts/buildAssets/tankModels.ts +++ b/scripts/buildAssets/tankModels.ts @@ -26,6 +26,11 @@ export async function buildTankModels(production: boolean) { for (const nationIndex in nations) { const changes: FileChange[] = []; const nation = nations[nationIndex]; + + if (['china', 'european', 'france', 'germany', 'japan'].includes(nation)) { + continue; + } + const tanks = await readXMLDVPL<{ root: VehicleDefinitionList }>( `${DATA}/${POI.vehicleDefinitions}/${nation}/list.xml.dvpl`, ); diff --git a/src/core/blitz/extractModel.ts b/src/core/blitz/extractModel.ts index 350051835..837bc3093 100644 --- a/src/core/blitz/extractModel.ts +++ b/src/core/blitz/extractModel.ts @@ -14,6 +14,7 @@ import { ScgStream, vertexAttributeVectorSizes } from '../streams/scg'; import { VertexAttribute } from '../streams/scpg'; import { readDVPLFile } from './readDVPLFile'; +const ERROR_ON_UNKNOWN_COMPONENT = false; const MAX_FLOAT32 = 2 ** 127 * (2 - 2 ** -23); export const vertexAttributeGLTFName: Partial> = @@ -164,21 +165,6 @@ export async function extractModel( components.forEach((component) => { switch (component['comp.typename']) { - case 'ScenarioComponent': - case 'LodComponent': - case 'DecorItemComponent': - case 'NewSlotComponent': - case 'StateSwitcherComponent': - case 'CustomPropertiesComponent': - case 'ActionComponent': - case 'ParticleEffectComponent': - case 'SlotComponent': - case 'MotionComponent': - case 'TankElementComponent': - case 'SkeletonComponent': - case 'AnimationComponent': - break; - case 'TransformComponent': { const translation = new Vector3(); const rotation = new Quaternion(); @@ -336,10 +322,15 @@ export async function extractModel( break; } - default: - throw new TypeError( - `Unhandled component type: ${component['comp.typename']}`, - ); + default: { + const message = `Unhandled component type: ${component['comp.typename']}`; + + if (ERROR_ON_UNKNOWN_COMPONENT) { + throw new Error(message); + } else { + console.warn(`${message}; skipping...`); + } + } } }); diff --git a/src/core/streams/sc2.ts b/src/core/streams/sc2.ts index 7546ecca7..b54fb5b9a 100644 --- a/src/core/streams/sc2.ts +++ b/src/core/streams/sc2.ts @@ -271,6 +271,17 @@ export type Component = animation: bigint; animationTimeScale: number; repeatsCount: number; + } + | { + 'comp.typename': 'SkeletonJointBindingComponent'; + count: number; + map: Record< + string, // 0000, 0001, ... + { + Uid: string; + jointUid: string; + } + >; }; interface SceneComponents {