Feature: Looping garage animations for legendary camouflages

Legendary camo add-ons now loop their garage animation in the Tankopedia viewer. It's always on, with no settings.

- The garage replay now also works out which motions end up looping, and the export writes only those clips
- Customization parts export skeletons, skin weights and sockets
- Parts render as primitives so their bones can animate, with attachments layered on top
- Base tank models are unchanged
This commit is contained in:
Mark Greene committed 2026-10-31 22:15:57 +13:00
commit 8566b2cc2f
94 files changed
+2037 -1861

No files matched your search

@@ -1,67 +0,0 @@
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()));
}
@@ -0,0 +1,13 @@
---
import CreditsPromo from "../../../../components/CreditsPromo.astro";
import { tools } from "../../../../constants/tools";
import ToolLayout from "../../../../layouts/ToolLayout.astro";
export { getStaticPaths } from "../index.astro";
const { locale } = Astro.props;
---
<ToolLayout tool={tools.credits} {locale}>
<CreditsPromo {locale} />
</ToolLayout>
@@ -5,6 +5,7 @@ import locales from "@blitzkit/i18n/locales.json";
import { literals } from "@blitzkit/i18n/src/literals";
import { Box, Flex, Link } from "@radix-ui/themes";
import { AesonPlug } from "../../../components/AesonPlug";
import { Beg } from "../../../components/Beg";
import HomeHero from "../../../components/HomeHero.astro";
import { Plugs } from "../../../components/Plugs";
import ToolCard from "../../../components/ToolCard.astro";
@@ -65,6 +66,8 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, () => {
<BaseLayout {locale}>
<HomeHero />
<Beg />
{
locale !== locales.default && (
<Flex justify="center" pt="4" my="4">
@@ -13,6 +13,7 @@ import { load } from "cheerio";
import { api } from "../../../../../core/blitzkit/api";
import { mixStaticPaths } from "../../../../../core/blitzkit/mixStaticPaths";
import { tankCharacteristics } from "../../../../../core/blitzkit/tankCharacteristics";
import { defaultTankWeapon } from "../../../../../core/blitzkit/tankToDuelMember";
import { getStrings } from "../../../../../core/i18n/getStrings";
import BaseLayout from "../../../../../layouts/BaseLayout.astro";
import { genericDefaultEquipmentMatrix } from "../../../../../stores/duel/constants";
@@ -53,9 +54,7 @@ const title = literals(strings.website.tools.tankopedia.tank_seo_title, {
const url = import.meta.env.SITE + Astro.url.pathname;
const icon = alias("api", `/tanks/${id}/icons/big.webp`);
const turret = tank.turrets.at(-1)!;
const gun = turret.guns.at(-1)!;
const shell = gun.shells[0];
const { turret, gun, shell } = defaultTankWeapon(tank);
const characteristics = tankCharacteristics(
{
tank,
@@ -6,8 +6,8 @@ import {
type TankParameters,
} from "@blitzkit/core";
import {
Animation,
Document,
Material,
Node,
NodeIO,
PropertyType,
@@ -17,13 +17,19 @@ import { ALL_EXTENSIONS } from "@gltf-transform/extensions";
import { dedup, mergeDocuments, unpartition } from "@gltf-transform/functions";
import type { APIContext } from "astro";
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";
import { SKIN_NUMBER } from "../../../../constants/skinNumber";
import { api } from "../../../../core/blitzkit/api";
import { mixStaticPaths } from "../../../../core/blitzkit/mixStaticPaths";
import {
partGarage,
switcherStates,
} from "../../../../core/blitzkit/switcherStates";
import { vfs } from "../../../../core/blitzkit/vfs";
import {
extractMaterials,
extractModel,
} from "../../../[...chunk_models_tanks]/[id]/model.glb";
import { getStaticPaths as _getStaticPaths } from "../../_index";
const SKIN_NUMBER_SLOTS = 5;
const DIGIT_COLUMNS = 5;
@@ -66,8 +72,10 @@ export async function GET({ props }: APIContext<{ skin: number }>) {
const [nation, tankKey] = (
include as { vehicle: { name: string } }
).vehicle.name.split(":");
const { preset, customEntities } = camouflagesYaml[key];
const skinNumber = Number(preset?.match(/(\d+)$/)?.[1] ?? 1);
const { customEntities } = camouflagesYaml[key];
const preset =
camouflagesYaml[key].preset ??
camouflagesYaml[key].override?.[nation]?.override?.[tankKey]?.preset;
const parameters = await vfs.yaml<TankParameters>(
`Data/3d/Tanks/Parameters/${nation}/${tankKey}.yaml`,
);
@@ -87,7 +95,6 @@ export async function GET({ props }: APIContext<{ skin: number }>) {
scale: Vector3Tuple;
}
> = {};
const states: Record<string, string | null> = {};
parseHierarchies(sc2["#hierarchy"], null, (hierarchy, components) => {
for (const component of components) {
@@ -110,43 +117,50 @@ export async function GET({ props }: APIContext<{ skin: number }>) {
scale: component["sc.attachmentScale"] as Vector3Tuple,
};
}
if (component["comp.typename"] !== "StateSwitcherComponent") continue;
const active = component[`ssc.state${component["ssc.activeState"]}`];
// camos without their own variant keep the default piece, but groups
// of elements to hide stay hidden
let state: string | null =
active && !/skin\d*/.test(active) && !active.includes("hide")
? active
: null;
for (let index = 0; index < component["ssc.statesCount"]; index++) {
const name = component[`ssc.state${index}`];
const match = name.match(/skin(\d*)/);
if (
match &&
!name.includes("hide") &&
Number(match[1] || 1) === skinNumber
) {
state = name;
}
}
states[hierarchy.name] = state;
}
return null;
});
const attachments = new Map<string, string[]>();
for (const name in customEntities) {
const slot = slots[name];
if (!slot) continue;
attachments.set(slot.target, [
...(attachments.get(slot.target) ?? []),
customEntities[name].item,
]);
}
const states = switcherStates(sc2, preset, attachments);
// attachments are layered over camouflages, so they only keep what they change
if (camouflagesXml.root.camouflages[key].kind === "customization") {
const baseline = switcherStates(sc2, preset, new Map());
for (const name in states) {
if (states[name] === baseline[name]) delete states[name];
}
}
const document = new Document();
const scene = document.createScene().setExtras({ states });
const scene = document.createScene();
const targets = new Map<string, Node>();
document.createBuffer();
if (preset) await extractMaterials(document, sc2, basePath, preset);
if (preset) {
const materials = await extractMaterials(document, sc2, basePath, preset);
// parts may share these names, so mark the ones that replace the tank's
for (const material of materials.values()) {
if (!(material instanceof Material)) continue;
material.setExtras({ ...material.getExtras(), camouflage: true });
}
}
for (const name in customEntities) {
const slot = slots[name];
@@ -161,33 +175,20 @@ export async function GET({ props }: APIContext<{ skin: number }>) {
continue;
}
const part = await extractModel(vfs, path, true);
const part = await extractModel(vfs, path, true, preset);
const partSc2 = new Sc2ReadStream(
(await vfs.file(`Data/3d/${path}.sc2`)).buffer as ArrayBuffer,
).sc2();
Object.assign(states, partGarage(partSc2, preset).states);
const map = mergeDocuments(document, part);
const partScene = map.get(part.getRoot().listScenes()[0]) as Scene;
const node = document
.createNode(name)
.setTranslation(slot.position)
.setRotation(slot.rotation)
.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}` },
});
}
});
.setScale(slot.scale);
let target = targets.get(slot.target);
if (!target) {
@@ -204,6 +205,8 @@ export async function GET({ props }: APIContext<{ skin: number }>) {
target.addChild(node);
}
scene.setExtras({ states });
applySkinNumber(document, SKIN_NUMBER);
await document.transform(
@@ -0,0 +1,3 @@
import { chunkedStaticPaths } from "../../core/blitzkit/chunkedStaticPaths";
export const getStaticPaths = chunkedStaticPaths("models_legendary");
Whitespace-only changes.
@@ -0,0 +1,12 @@
import { api } from "../../../core/blitzkit/api";
import { mixStaticPaths } from "../../../core/blitzkit/mixStaticPaths";
import { getStaticPaths as _getStaticPaths } from "../_index";
export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
const tanks = await api.tankDefinitions();
return Object.values(tanks.tanks).map((tank) => ({
params: { id: tank.id },
props: { id: tank.id },
}));
});
@@ -10,7 +10,7 @@ import {
import type { AbstractVFS } from "@blitzkit/core/src/blitzkit/vfs/abstract";
import { Accessor, Document, Node, NodeIO, Scene } from "@gltf-transform/core";
import type { APIContext } from "astro";
import { vfs } from "../../../../core/blitzkit/vfs";
import { vfs } from "../../../core/blitzkit/vfs";
export { getStaticPaths } from "./_index";
@@ -28,19 +28,16 @@ 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 type { Motion } from "../../../core/blitzkit/skinAnimations/motion";
import {
bindSocket,
createMotionClip,
createSkeleton,
loadMotion,
skinPrimitive,
} from "../../../../core/blitzkit/skinAnimations/skeleton";
import { vfs } from "../../../../core/blitzkit/vfs";
} from "../../../core/blitzkit/skinAnimations/skeleton";
import { partGarage } from "../../../core/blitzkit/switcherStates";
import { vfs } from "../../../core/blitzkit/vfs";
import {
vertexAttributeGLTFName,
vertexAttributeGltfVectorSizes,
@@ -85,7 +82,13 @@ export async function GET({ props }: APIContext<{ id: number }>) {
const ERROR_ON_UNKNOWN_COMPONENT = false;
const omitMeshNames = {
start: ["chassis_chassis_", "chassis_track_crash_", "HP_"],
start: [
"chassis_chassis_",
"chassis_track_crash_",
"HP_",
// mastery marks a new tank doesn't have yet
"custom_gun_marks_",
],
end: ["_POINT"],
};
@@ -93,6 +96,7 @@ export async function extractModel(
vfs: AbstractVFS,
path: string,
isPart = false,
preset?: string,
) {
const sc2Path = `Data/3d/${path}.sc2`;
const scgPath = `Data/3d/${path}.scg`;
@@ -114,6 +118,7 @@ export async function extractModel(
skin: Skin,
][] = [];
const motions = new Map<Hierarchy, Motion>();
const garageMotions = isPart ? partGarage(sc2, preset).motions : new Set();
if (isPart) {
const loading: Promise<void>[] = [];
@@ -124,7 +129,7 @@ export async function extractModel(
loading.push(
loadMotion(vfs, path, component).then((motion) => {
if (motion) motions.set(hierarchy, motion);
motions.set(hierarchy, motion);
}),
);
}
@@ -133,14 +138,6 @@ export async function extractModel(
});
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>(
@@ -162,7 +159,7 @@ export async function extractModel(
const motionComponent = components.find(
(component) => component["comp.typename"] === "MotionComponent",
);
const motion = motionComponent ? motions.get(hierarchy) : undefined;
const motion = motions.get(hierarchy);
if (skeleton) {
const created = createSkeleton(
@@ -175,17 +172,16 @@ export async function extractModel(
skeletons.set(hierarchy, created);
if (motion && motionComponent) {
addExtras(node, {
motion: createMotionClip(
document,
buffer,
`motion${document.getRoot().listAnimations().length}`,
created.joints,
motion,
motionComponent,
),
});
// only what loops in the garage is exported
if (motion && motionComponent && garageMotions.has(hierarchy)) {
createMotionClip(
document,
buffer,
`motion${document.getRoot().listAnimations().length}`,
created.joints,
motion,
motionComponent,
);
}
}
}
@@ -212,37 +208,9 @@ export async function extractModel(
}
case "StateSwitcherComponent":
addExtras(node, {
node.setExtras({
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": {
@@ -256,14 +224,14 @@ export async function extractModel(
] as unknown as { entityUid: string; jointUid: string };
const joint = skeleton.joints.get(binding.jointUid);
if (joint) {
jointBindings.push([
node,
binding.entityUid,
joint,
skeleton.skin,
]);
}
if (!joint) throw new Error(`Missing joint ${binding.jointUid}`);
jointBindings.push([
node,
binding.entityUid,
joint,
skeleton.skin,
]);
});
break;
}
@@ -379,7 +347,9 @@ export async function extractModel(
for (const [owner, entity, joint, skin] of jointBindings) {
const socket = findNode(owner, entity);
if (socket) bindSocket(socket, joint, skin);
if (!socket) throw new Error(`Missing socket ${entity}`);
bindSocket(socket, joint, skin);
}
scene.addChild(document.createNode("test"));
@@ -518,6 +488,27 @@ export async function extractMaterials(
}
}
const enabledPresets =
node.enabledPresets ?? defaultConfigArchive?.enabledPresets;
const fxName = node.fxName ?? defaultConfigArchive?.fxName;
if (enabledPresets?.AlphaBlend || enabledPresets?.AlphaBlendAdditive) {
material.setAlphaMode("BLEND");
}
if (enabledPresets?.AlphaBlendAdditive) {
// gltf has no additive blending so the viewer applies it
material.setExtras({ blending: "additive" });
}
if (fxName?.endsWith("/Textured.material")) {
// unlit in game, emissive so the viewer can fade it with the lights
material
.setEmissiveTexture(material.getBaseColorTexture())
.setEmissiveFactor([1, 1, 1])
.setBaseColorFactor([0, 0, 0, 1]);
}
if (textures.miscMap) {
material.setOcclusionTexture(
document
@@ -0,0 +1,3 @@
import { chunkedStaticPaths } from "../../core/blitzkit/chunkedStaticPaths";
export const getStaticPaths = chunkedStaticPaths("models_tanks");