Feature: Animated legendary camouflages

Legendary camo add-ons now play their garage animations in the Tankopedia viewer, and a new menu next to the camo column triggers their battle reactions.

**Export (`model.glb` / `skins/[skin].glb`)**
- Customization parts export skeletons, skin weights and one clip per `.anim` motion file (`core/blitzkit/skinAnimations`)
- Sockets bound to skeleton joints follow their joint
- Action lists and scenario graphs are carried in glTF extras
- Part batches with no LODs (`lodIndex` -1) are now exported, fixing meshes that were missing entirely (e.g. the Tiger II cat body, the BDT-5A engine rings)
- Base tank models are unchanged

**Viewer**
- A runtime plays the clips and drives state switchers, action lists and the game's scenario graphs (a small interpreter for the node types the camos use)
- Camo parts render as primitives so their bones can animate
- Garage animations play once rather than looping, so the camo settles

**Animation menu**
- Floats left of the camo column when the selected camo has triggerable animations
- Icon buttons use the game's own white icons, served from `/icons/skin-events/[event].webp`
- Idle replays the garage animation
- Triggers: Shoot, Kill, Take damage, Damage enemy, Ricochet / No penetration, Start moving, Consumable, Reload. Only events that actually animate get a button
- Buttons are disabled while a triggered animation plays; triggering cuts any garage animation short

All legendary skin files together grow from 1.32 GB to 1.35 GB (+2.4%), almost all of it in the 102 animated camos.
This commit is contained in:
Mark Greene committed 2026-10-20 18:48:35 +13:00
1 parent 85e03d3b42
commit ffb5a1f9c8
15 files changed
+1778 -11

No files matched your search

@@ -0,0 +1,67 @@
import type { APIContext } from "astro";
import sharp from "sharp";
import { extractPackedIcon } from "../../../../core/blitz/extractPackedIcon";
import { parsePackedSpriteRect } from "../../../../core/blitz/parsePackedSpriteRect";
import { mixStaticPaths } from "../../../../core/blitzkit/mixStaticPaths";
import { vfs } from "../../../../core/blitzkit/vfs";
import { getStaticPaths as _getStaticPaths } from "../../_index";
interface Icon {
path: string;
/** sprite inside a texture0 atlas described by a .txt file */
atlas: boolean;
}
// white game icons for the camo animation triggers
const ICONS: Record<string, Icon> = {
garage: { path: "Lobby/icons/platoon/icon_hangar_m", atlas: false },
shoot: { path: "UI/BattleScreenHUD/icon_aim-battle_m", atlas: true },
kill: {
path: "UI/BattleScreenHUD/icon_battle-chat_kill-type_default",
atlas: true,
},
damage: { path: "UI/BattleScreenHUD/icon_damage_shadow_m", atlas: true },
damage_enemy: {
path: "UI/BattleScreenHUD/icon_attack-battle_m",
atlas: true,
},
no_pierce: {
path: "UI/BattleScreenHUD/icon_shooting-fb_shield_m",
atlas: true,
},
move: { path: "Lobby/icons/icon_speed_s", atlas: false },
consumable: { path: "Lobby/icons/icon_consumable_l", atlas: false },
reload: { path: "Lobby/icons/icon_rate-of-fire_s", atlas: false },
};
export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () =>
Object.keys(ICONS).map((event) => ({ params: { event }, props: { event } })),
);
export async function GET({ props }: APIContext<{ event: string }>) {
const { path, atlas } = ICONS[props.event];
let buffer: Buffer;
if (atlas) {
const directory = path.split("/").slice(0, -1).join("/");
const sizes = (await vfs.text(`Data/Gfx/${path}@2x.txt`))
.split("\n")[4]
.trim()
.split(" ")
.map(Number);
buffer = await extractPackedIcon(
sharp(await vfs.file(`Data/Gfx/${directory}/[email protected]`)),
sizes.slice(0, 4),
);
} else {
const packedBuffer = await vfs.file(`Data/Gfx/${path}@2x.packed.webp`);
const sizes = parsePackedSpriteRect(packedBuffer);
buffer = sizes
? await extractPackedIcon(sharp(packedBuffer), sizes)
: packedBuffer;
}
return new Response(new Uint8Array(await sharp(buffer).webp().toBuffer()));
}
@@ -8,18 +8,38 @@ import {
toUniqueId,
VertexAttribute,
type ConfigArchive,
type Hierarchy,
type TankParameters,
type Textures,
type VehicleDefinitionList,
} from "@blitzkit/core";
import type { AbstractVFS } from "@blitzkit/core/src/blitzkit/vfs/abstract";
import { Document, Material, Node, NodeIO, Scene } from "@gltf-transform/core";
import {
Document,
Material,
Node,
NodeIO,
Scene,
type Skin,
} from "@gltf-transform/core";
import { ALL_EXTENSIONS } from "@gltf-transform/extensions";
import { dedup, prune } from "@gltf-transform/functions";
import type { APIContext } from "astro";
import { isEqual, times } from "lodash-es";
import { dirname } from "path";
import sharp from "sharp";
import {
addExtras,
toExtras,
} from "../../../../core/blitzkit/skinAnimations/extras";
import type { Motion } from "../../../../core/blitzkit/skinAnimations/motion";
import {
bindSocket,
createMotionClip,
createSkeleton,
loadMotion,
skinPrimitive,
} from "../../../../core/blitzkit/skinAnimations/skeleton";
import { vfs } from "../../../../core/blitzkit/vfs";
import {
vertexAttributeGLTFName,
@@ -86,6 +106,42 @@ export async function extractModel(
const scene = document.createScene();
const buffer = document.createBuffer();
const materials = await extractMaterials(document, sc2, path);
const skeletons = new Map<Hierarchy, ReturnType<typeof createSkeleton>>();
const jointBindings: [
owner: Node,
entity: string,
joint: Node,
skin: Skin,
][] = [];
const motions = new Map<Hierarchy, Motion>();
if (isPart) {
const loading: Promise<void>[] = [];
parseHierarchies(sc2["#hierarchy"], null, (hierarchy, components) => {
for (const component of components) {
if (component["comp.typename"] !== "MotionComponent") continue;
loading.push(
loadMotion(vfs, path, component).then((motion) => {
if (motion) motions.set(hierarchy, motion);
}),
);
}
return null;
});
await Promise.all(loading);
for (const component of Object.values(
(sc2["#sceneComponents"] ?? {}) as Record<string, Record<string, any>>,
)) {
if (component["comp.typename"] === "ScenarioSingletonComponent") {
scene.setExtras({ scripts: toExtras(component["ssc.scripts"]) });
}
}
}
parseHierarchies<Scene | Node>(
sc2["#hierarchy"],
@@ -99,6 +155,41 @@ export async function extractModel(
const node = document.createNode(hierarchy.name);
if (isPart) {
const skeleton = components.find(
(component) => component["comp.typename"] === "SkeletonComponent",
);
const motionComponent = components.find(
(component) => component["comp.typename"] === "MotionComponent",
);
const motion = motionComponent ? motions.get(hierarchy) : undefined;
if (skeleton) {
const created = createSkeleton(
document,
buffer,
node,
skeleton,
motion,
);
skeletons.set(hierarchy, created);
if (motion && motionComponent) {
addExtras(node, {
motion: createMotionClip(
document,
buffer,
`motion${document.getRoot().listAnimations().length}`,
created.joints,
motion,
motionComponent,
),
});
}
}
}
components.forEach((component) => {
switch (component["comp.typename"]) {
case "LodComponent":
@@ -121,18 +212,70 @@ export async function extractModel(
}
case "StateSwitcherComponent":
node.setExtras({
addExtras(node, {
state: component[`ssc.state${component["ssc.activeState"]}`],
});
if (isPart) {
addExtras(node, {
stateNames: times(
component["ssc.statesCount"],
(index) => component[`ssc.state${index}`],
),
});
}
break;
case "ActionComponent":
if (!isPart) break;
addExtras(node, {
actions: toExtras(
times(
component["ac.actionCount"],
(index) => component[index.toString().padStart(4, "0")],
),
),
});
break;
case "ScenarioComponent":
if (!isPart) break;
addExtras(node, { scenario: component["scenario.scriptId"] });
break;
case "SkeletonJointBindingComponent": {
const skeleton = skeletons.get(hierarchy);
if (!skeleton) break;
times(component.count, (index) => {
const binding = component.map[
index.toString().padStart(4, "0")
] as unknown as { entityUid: string; jointUid: string };
const joint = skeleton.joints.get(binding.jointUid);
if (joint) {
jointBindings.push([
node,
binding.entityUid,
joint,
skeleton.skin,
]);
}
});
break;
}
case "RenderComponent": {
const renderObject = component["rc.renderObj"];
times(renderObject["ro.batchCount"], (batchIndex): void => {
const lodIndex = renderObject[`rb${batchIndex}.lodIndex`];
if (lodIndex !== 0) return;
// -1 means the batch has no lods and is always drawn
if (lodIndex !== 0 && !(isPart && lodIndex === -1)) return;
const batchKey = batchIndex.toString().padStart(4, "0");
const batch = renderObject["ro.batches"][batchKey];
@@ -193,10 +336,24 @@ export async function extractModel(
primitive.setAttribute(name, attributeAccessor);
});
const skeleton = skeletons.get(hierarchy);
const mesh = document
.createMesh(batch["##name"])
.addPrimitive(primitive);
lodNode.setMesh(mesh);
if (
skeleton &&
skinPrimitive(
document,
buffer,
primitive,
attributes,
renderObject[`skinnedObject.batch${batchIndex}.targetsData`],
)
) {
lodNode.setSkin(skeleton.skin);
}
node.addChild(lodNode);
});
@@ -219,6 +376,12 @@ export async function extractModel(
},
);
for (const [owner, entity, joint, skin] of jointBindings) {
const socket = findNode(owner, entity);
if (socket) bindSocket(socket, joint, skin);
}
scene.addChild(document.createNode("test"));
await document.transform(prune({ keepAttributes: true }), dedup());
@@ -226,6 +389,16 @@ export async function extractModel(
return document;
}
function findNode(node: Node, name: string): Node | undefined {
for (const child of node.listChildren()) {
if (child.getName() === name) return child;
const found = findNode(child, name);
if (found) return found;
}
}
export async function extractMaterials(
document: Document,
sc2: ReturnType<Sc2ReadStream["sc2"]>,
@@ -6,6 +6,7 @@ import {
type TankParameters,
} from "@blitzkit/core";
import {
Animation,
Document,
Node,
NodeIO,
@@ -19,6 +20,7 @@ import type { Vector3Tuple, Vector4Tuple } from "three";
import { SKIN_NUMBER } from "../../../../../constants/skinNumber";
import { api } from "../../../../../core/blitzkit/api";
import { mixStaticPaths } from "../../../../../core/blitzkit/mixStaticPaths";
import type { SkinMotion } from "../../../../../core/blitzkit/skinAnimations/skeleton";
import { vfs } from "../../../../../core/blitzkit/vfs";
import { getStaticPaths as _getStaticPaths } from "../../../_index";
import { extractMaterials, extractModel } from "../model.glb";
@@ -166,7 +168,26 @@ export async function GET({ props }: APIContext<{ skin: number }>) {
.createNode(name)
.setTranslation(slot.position)
.setRotation(slot.rotation)
.setScale(slot.scale);
.setScale(slot.scale)
.setExtras(partScene.getExtras());
// clip names repeat across parts
for (const animation of part.getRoot().listAnimations()) {
(map.get(animation) as Animation).setName(
`${name}:${animation.getName()}`,
);
}
partScene.traverse((child) => {
const { motion } = child.getExtras() as { motion?: SkinMotion };
if (motion) {
child.setExtras({
...child.getExtras(),
motion: { ...motion, clip: `${name}:${motion.clip}` },
});
}
});
let target = targets.get(slot.target);
if (!target) {