2025-09-27 16:07:45 -05:00
|
|
|
import { memo, useRef } from "react";
|
|
|
|
|
import { Group, Plane, Scene, Vector3 } from "three";
|
2026-09-27 16:46:22 -05:00
|
|
|
import { nameToArmorId } from "../core/blitzkit/nameToArmorId";
|
|
|
|
|
import { resolveArmor } from "../core/blitzkit/resolveThickness";
|
|
|
|
|
import { useArmor } from "../hooks/useArmor";
|
2026-09-30 17:36:51 -05:00
|
|
|
import { useConsumable } from "../hooks/useConsumable";
|
2026-11-14 01:17:38 -06:00
|
|
|
import { useDuelModels } from "../hooks/useDuelModels";
|
|
|
|
|
import { useDuelModules } from "../hooks/useDuelModules";
|
2026-09-27 16:46:22 -05:00
|
|
|
import { useModel } from "../hooks/useModel";
|
|
|
|
|
import { useTankTransform } from "../hooks/useTankTransform";
|
2026-09-30 20:59:18 -05:00
|
|
|
import { toThreeVector } from "../three/toThreeVector";
|
2025-09-27 16:07:45 -05:00
|
|
|
import { SpacedArmorSceneComponent } from "./SpacedArmorSceneComponent";
|
2024-01-15 21:55:09 -06:00
|
|
|
|
2024-02-26 13:29:05 -06:00
|
|
|
export enum ArmorType {
|
2024-07-29 20:46:57 -05:00
|
|
|
Primary,
|
2024-02-26 13:29:05 -06:00
|
|
|
Spaced,
|
|
|
|
|
External,
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 22:29:21 -06:00
|
|
|
interface SpacedArmorSceneProps {
|
|
|
|
|
scene: Scene;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const SpacedArmorScene = memo<SpacedArmorSceneProps>(({ scene }) => {
|
2025-09-27 16:07:45 -05:00
|
|
|
const turretContainer = useRef<Group>(null!);
|
|
|
|
|
const gunContainer = useRef<Group>(null!);
|
2026-11-14 01:17:38 -06:00
|
|
|
const protagonist = useDuelModules("protagonist");
|
|
|
|
|
const { gltf: armorGltf } = useArmor(protagonist.tank.id);
|
|
|
|
|
const { gltf: modelGltf } = useModel(protagonist.tank.id);
|
2024-07-22 20:47:29 -05:00
|
|
|
const armorNodes = Object.values(armorGltf.nodes);
|
|
|
|
|
const modelNodes = Object.values(modelGltf.nodes);
|
2026-11-14 01:17:38 -06:00
|
|
|
const models = useDuelModels("protagonist");
|
|
|
|
|
const hullOrigin = toThreeVector(models.track.origin);
|
|
|
|
|
const turretOrigin = toThreeVector(models.tank.turret_origin);
|
|
|
|
|
const gunOrigin = toThreeVector(models.turret.gun_origin);
|
2024-07-22 20:47:29 -05:00
|
|
|
const maskOrigin =
|
2026-11-14 01:17:38 -06:00
|
|
|
models.gun.mask === undefined
|
2024-07-22 20:47:29 -05:00
|
|
|
? undefined
|
2026-11-14 01:17:38 -06:00
|
|
|
: models.gun.mask + hullOrigin.y + turretOrigin.y + gunOrigin.y;
|
2026-09-30 17:36:51 -05:00
|
|
|
const isDynamicArmorActive = useConsumable("protagonist", 73);
|
2024-02-02 10:31:40 -06:00
|
|
|
|
2026-11-14 01:17:38 -06:00
|
|
|
useTankTransform(
|
|
|
|
|
protagonist.track,
|
|
|
|
|
protagonist.turret,
|
|
|
|
|
turretContainer,
|
|
|
|
|
gunContainer,
|
|
|
|
|
);
|
2024-02-28 17:41:59 -06:00
|
|
|
|
|
|
|
|
return (
|
2026-09-30 17:36:51 -05:00
|
|
|
<>
|
2024-02-28 17:41:59 -06:00
|
|
|
<group position={hullOrigin}>
|
|
|
|
|
{armorNodes.map((node) => {
|
2025-09-27 16:07:45 -05:00
|
|
|
const isHull = node.name.startsWith("hull_");
|
2024-02-28 17:41:59 -06:00
|
|
|
const isVisible = isHull;
|
|
|
|
|
const armorId = nameToArmorId(node.name);
|
|
|
|
|
const { spaced, thickness } = resolveArmor(
|
2026-11-14 01:17:38 -06:00
|
|
|
models.tank.armor!,
|
2026-03-31 14:11:45 -05:00
|
|
|
armorId,
|
2024-02-28 17:41:59 -06:00
|
|
|
);
|
|
|
|
|
|
2024-08-28 21:16:25 -05:00
|
|
|
if (
|
|
|
|
|
!isVisible ||
|
|
|
|
|
thickness === undefined ||
|
2025-09-27 16:07:45 -05:00
|
|
|
(isDynamicArmorActive && node.name.includes("state_00")) ||
|
|
|
|
|
(!isDynamicArmorActive && node.name.includes("state_01"))
|
2024-08-28 21:16:25 -05:00
|
|
|
)
|
|
|
|
|
return null;
|
2024-02-28 17:41:59 -06:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<SpacedArmorSceneComponent
|
2024-02-28 22:29:21 -06:00
|
|
|
scene={scene}
|
2025-04-15 16:29:14 -05:00
|
|
|
key={`${node.uuid}-hull`}
|
2024-07-29 20:46:57 -05:00
|
|
|
type={spaced ? ArmorType.Spaced : ArmorType.Primary}
|
2024-02-28 17:41:59 -06:00
|
|
|
thickness={thickness}
|
|
|
|
|
node={node}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</group>
|
2024-07-24 20:46:42 -05:00
|
|
|
|
2024-02-28 17:41:59 -06:00
|
|
|
{modelNodes.map((node) => {
|
2025-09-27 16:07:45 -05:00
|
|
|
const isWheel = node.name.startsWith("chassis_wheel_");
|
|
|
|
|
const isTrack = node.name.startsWith("chassis_track_");
|
2024-02-28 17:41:59 -06:00
|
|
|
const isVisible = isWheel || isTrack;
|
|
|
|
|
|
|
|
|
|
if (!isVisible) return null;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<SpacedArmorSceneComponent
|
2024-02-28 22:29:21 -06:00
|
|
|
scene={scene}
|
2025-04-15 16:29:14 -05:00
|
|
|
key={`${node.uuid}-track`}
|
2024-02-28 17:41:59 -06:00
|
|
|
type={ArmorType.External}
|
2026-11-14 01:17:38 -06:00
|
|
|
thickness={models.track.thickness}
|
2024-02-28 17:41:59 -06:00
|
|
|
variant="track"
|
|
|
|
|
node={node}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
|
|
|
|
|
<group ref={turretContainer}>
|
2024-07-24 20:46:42 -05:00
|
|
|
{armorNodes.map((node) => {
|
|
|
|
|
const isCurrentTurret = node.name.startsWith(
|
2026-11-14 01:17:38 -06:00
|
|
|
`turret_${models.turret.model_id.toString().padStart(2, "0")}`,
|
2024-07-24 20:46:42 -05:00
|
|
|
);
|
|
|
|
|
const isVisible = isCurrentTurret;
|
|
|
|
|
const armorId = nameToArmorId(node.name);
|
|
|
|
|
const { spaced, thickness } = resolveArmor(
|
2026-11-14 01:17:38 -06:00
|
|
|
models.turret.armor!,
|
2026-03-31 14:11:45 -05:00
|
|
|
armorId,
|
2024-07-24 20:46:42 -05:00
|
|
|
);
|
|
|
|
|
|
2024-08-28 21:16:25 -05:00
|
|
|
if (
|
|
|
|
|
!isVisible ||
|
|
|
|
|
thickness === undefined ||
|
2025-09-27 16:07:45 -05:00
|
|
|
(isDynamicArmorActive && node.name.includes("state_00")) ||
|
|
|
|
|
(!isDynamicArmorActive && node.name.includes("state_01"))
|
2024-08-28 21:16:25 -05:00
|
|
|
)
|
|
|
|
|
return null;
|
2024-07-24 20:46:42 -05:00
|
|
|
|
|
|
|
|
return (
|
2024-09-22 21:27:46 -05:00
|
|
|
<group position={hullOrigin} key={node.uuid}>
|
|
|
|
|
<group position={turretOrigin}>
|
2024-07-27 13:46:36 -05:00
|
|
|
<SpacedArmorSceneComponent
|
|
|
|
|
scene={scene}
|
2025-04-15 16:29:14 -05:00
|
|
|
key={`${node.uuid}-turret`}
|
2024-07-29 20:46:57 -05:00
|
|
|
type={spaced ? ArmorType.Spaced : ArmorType.Primary}
|
2024-07-27 13:46:36 -05:00
|
|
|
thickness={thickness}
|
|
|
|
|
node={node}
|
|
|
|
|
/>
|
|
|
|
|
</group>
|
2024-07-24 20:46:42 -05:00
|
|
|
</group>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
|
|
|
|
|
<group ref={gunContainer}>
|
2024-01-15 21:55:09 -06:00
|
|
|
{armorNodes.map((node) => {
|
2024-07-24 20:46:42 -05:00
|
|
|
const isCurrentGun = node.name.startsWith(
|
2026-11-14 01:17:38 -06:00
|
|
|
`gun_${models.gun.model_id.toString().padStart(2, "0")}`,
|
2024-02-28 17:41:59 -06:00
|
|
|
);
|
2024-07-24 20:46:42 -05:00
|
|
|
const isVisible = isCurrentGun;
|
2024-01-15 21:55:09 -06:00
|
|
|
const armorId = nameToArmorId(node.name);
|
|
|
|
|
const { spaced, thickness } = resolveArmor(
|
2026-11-14 01:17:38 -06:00
|
|
|
models.gun.armor!,
|
2026-03-31 14:11:45 -05:00
|
|
|
armorId,
|
2024-01-15 21:55:09 -06:00
|
|
|
);
|
|
|
|
|
|
2024-08-28 21:16:25 -05:00
|
|
|
if (
|
|
|
|
|
!isVisible ||
|
|
|
|
|
thickness === undefined ||
|
2025-09-27 16:07:45 -05:00
|
|
|
(isDynamicArmorActive && node.name.includes("state_00")) ||
|
|
|
|
|
(!isDynamicArmorActive && node.name.includes("state_01"))
|
2024-08-28 21:16:25 -05:00
|
|
|
)
|
|
|
|
|
return null;
|
2024-01-15 21:55:09 -06:00
|
|
|
|
|
|
|
|
return (
|
2025-04-15 16:29:14 -05:00
|
|
|
<group position={hullOrigin} key={`${node.uuid}-gun-spaced}`}>
|
2024-09-22 21:27:46 -05:00
|
|
|
<group position={turretOrigin.clone().add(gunOrigin)}>
|
2024-07-27 13:46:36 -05:00
|
|
|
<SpacedArmorSceneComponent
|
|
|
|
|
scene={scene}
|
2024-07-29 20:46:57 -05:00
|
|
|
type={spaced ? ArmorType.Spaced : ArmorType.Primary}
|
2024-07-27 13:46:36 -05:00
|
|
|
thickness={thickness}
|
|
|
|
|
node={node}
|
|
|
|
|
/>
|
|
|
|
|
</group>
|
2024-02-28 17:41:59 -06:00
|
|
|
</group>
|
2024-01-15 21:55:09 -06:00
|
|
|
);
|
|
|
|
|
})}
|
2024-01-23 13:37:32 -06:00
|
|
|
|
2024-02-28 17:41:59 -06:00
|
|
|
{modelNodes.map((node) => {
|
2026-11-14 01:17:38 -06:00
|
|
|
const gunString = `gun_${models.gun.model_id
|
2024-09-06 23:17:53 -05:00
|
|
|
.toString()
|
2025-09-27 16:07:45 -05:00
|
|
|
.padStart(2, "0")}`;
|
2026-11-14 01:17:38 -06:00
|
|
|
const isCurrentGun = models.gun.mask
|
2024-06-03 13:47:55 -05:00
|
|
|
? node.name.startsWith(gunString)
|
|
|
|
|
: node.name === gunString;
|
2024-02-28 17:41:59 -06:00
|
|
|
const isVisible = isCurrentGun;
|
2024-01-20 12:01:05 -06:00
|
|
|
|
2024-02-28 17:41:59 -06:00
|
|
|
if (!isVisible) return null;
|
2024-01-20 12:01:05 -06:00
|
|
|
|
2024-02-28 17:41:59 -06:00
|
|
|
return (
|
|
|
|
|
<SpacedArmorSceneComponent
|
2024-02-28 22:29:21 -06:00
|
|
|
scene={scene}
|
2025-04-15 16:29:14 -05:00
|
|
|
key={`${node.uuid}-gun-external`}
|
2024-02-28 17:41:59 -06:00
|
|
|
type={ArmorType.External}
|
2026-11-14 01:17:38 -06:00
|
|
|
thickness={models.gun.thickness}
|
2024-02-28 17:41:59 -06:00
|
|
|
variant="gun"
|
|
|
|
|
node={node}
|
2024-04-13 10:38:13 -05:00
|
|
|
clip={
|
|
|
|
|
maskOrigin === undefined
|
|
|
|
|
? undefined
|
|
|
|
|
: new Plane(new Vector3(0, 0, -1), -maskOrigin)
|
|
|
|
|
}
|
2024-02-28 17:41:59 -06:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2024-01-15 21:55:09 -06:00
|
|
|
</group>
|
|
|
|
|
</group>
|
2026-09-30 17:36:51 -05:00
|
|
|
</>
|
2024-02-28 17:41:59 -06:00
|
|
|
);
|
|
|
|
|
});
|