Merge branch 'main' into batched-mesh

This commit is contained in:
tresabhi committed 2026-11-29 17:46:24 -06:00
commit 52bf5731c1
154 files changed
+4486 -1488

No files matched your search

+55 -18
View File
@@ -4,6 +4,7 @@ import {
type ObjectMap,
type ThreeEvent,
} from "@react-three/fiber";
import type { QuicklimeEvent } from "quicklime";
import { useRef } from "react";
import type { Texture } from "three";
import { Group, Mesh, MeshStandardMaterial, Vector2 } from "three";
@@ -13,19 +14,47 @@ import { modelTransformEvent } from "../core/blitzkit/modelTransform";
import { controlsEnabledEvent } from "../core/controlsEnabled";
import { useBatched } from "../hooks/useBatched";
import { useModel } from "../hooks/useModel";
import { useSkin, type Skin } from "../hooks/useSkin";
import { useSkinAnimation } from "../hooks/useSkinAnimation";
import { useTankModelDefinition } from "../hooks/useTankModelDefinition";
import { useTankTransform } from "../hooks/useTankTransform";
import { Duel } from "../stores/duel";
import { Tankopedia } from "../stores/tankopedia";
import { TankopediaDisplay } from "../stores/tankopediaPersistent/constants";
import { ModelTankWrapper } from "./Armor/components/ModelTankWrapper";
import { transitionEvent } from "./Tankopedia/HeroSection/components/TankSandbox/components/Lighting";
interface SectionProps {
map: ObjectMap;
skins: Skin[];
}
function Tracks({ map }: SectionProps) {
const Batched = useBatched(map, true);
// emissive parts fade with the lights instead of glowing in the dark
function fadeEmissive(materials: MeshStandardMaterial[]) {
const emissiveMaterials = materials.filter(
(material) => material.emissiveMap
);
function applyIntensity(intensity: number) {
for (const material of emissiveMaterials) {
material.emissiveIntensity = intensity;
}
}
function handleTransitionEvent(event: QuicklimeEvent<number>) {
applyIntensity(event.data);
}
applyIntensity(transitionEvent.last!);
transitionEvent.on(handleTransitionEvent);
return () => {
transitionEvent.off(handleTransitionEvent);
};
}
function Tracks({ map, skins }: SectionProps) {
const Batched = useBatched(map, true, skins);
const position = useRef(new Vector2());
const delta = useRef(new Vector2());
@@ -80,6 +109,7 @@ function Tracks({ map }: SectionProps) {
return (
<Batched
onMaterials={fadeEmissive}
onPointerDown={handlePointerDown}
slicer={(node) => {
return node.name.startsWith("chassis_track_");
@@ -88,8 +118,8 @@ function Tracks({ map }: SectionProps) {
);
}
function Hull({ map }: SectionProps) {
const Batched = useBatched(map, true);
function Hull({ map, skins }: SectionProps) {
const Batched = useBatched(map, true, skins);
function handlePointerDown(event: ThreeEvent<PointerEvent>) {
event.stopPropagation();
@@ -97,6 +127,7 @@ function Hull({ map }: SectionProps) {
return (
<Batched
onMaterials={fadeEmissive}
onPointerDown={handlePointerDown}
slicer={(node) => {
const isHull = node.name === "hull";
@@ -108,7 +139,7 @@ function Hull({ map }: SectionProps) {
);
}
function Turret({ map }: SectionProps) {
function Turret({ map, skins }: SectionProps) {
const turret = Duel.use((state) => state.protagonist.turret);
const gun = Duel.use((state) => state.protagonist.gun);
@@ -116,7 +147,7 @@ function Turret({ map }: SectionProps) {
const turretModelDefinition = tankModelDefinition.turrets[turret.id];
const gunModelDefinition = turretModelDefinition.guns[gun.id];
const Batched = useBatched(map, true);
const Batched = useBatched(map, true, skins);
const position = useRef(new Vector2());
const delta = useRef(new Vector2());
@@ -140,12 +171,12 @@ function Turret({ map }: SectionProps) {
const hasImprovedVerticalStabilizer = hasEquipment(
122,
Duel.state.protagonist.tank.equipment_preset,
Duel.state.protagonist.equipmentMatrix,
Duel.state.protagonist.equipmentMatrix
);
const hasDownImprovedVerticalStabilizer = hasEquipment(
124,
Duel.state.protagonist.tank.equipment_preset,
Duel.state.protagonist.equipmentMatrix,
Duel.state.protagonist.equipmentMatrix
);
const boundingRect = canvas.getBoundingClientRect();
@@ -159,7 +190,7 @@ function Turret({ map }: SectionProps) {
gunModelDefinition.pitch!,
turretModelDefinition.yaw,
hasImprovedVerticalStabilizer,
hasDownImprovedVerticalStabilizer,
hasDownImprovedVerticalStabilizer
);
modelTransformEvent.dispatch({ pitch, yaw });
}
@@ -171,6 +202,7 @@ function Turret({ map }: SectionProps) {
return (
<Batched
onMaterials={fadeEmissive}
onPointerDown={onPointerDown}
slicer={(node) => {
const isCurrentTurret =
@@ -185,8 +217,8 @@ function Turret({ map }: SectionProps) {
);
}
function Gun({ map }: SectionProps) {
const Batched = useBatched(map, true);
function Gun({ map, skins }: SectionProps) {
const Batched = useBatched(map, true, skins);
const turret = Duel.use((state) => state.protagonist.turret);
const gun = Duel.use((state) => state.protagonist.gun);
@@ -206,12 +238,12 @@ function Gun({ map }: SectionProps) {
const hasImprovedVerticalStabilizer = hasEquipment(
122,
Duel.state.protagonist.tank.equipment_preset,
Duel.state.protagonist.equipmentMatrix,
Duel.state.protagonist.equipmentMatrix
);
const hasDownImprovedVerticalStabilizer = hasEquipment(
124,
Duel.state.protagonist.tank.equipment_preset,
Duel.state.protagonist.equipmentMatrix,
Duel.state.protagonist.equipmentMatrix
);
const boundingRect = canvas.getBoundingClientRect();
delta.current.set(event.clientX, event.clientY).sub(position.current);
@@ -223,7 +255,7 @@ function Gun({ map }: SectionProps) {
gunModelDefinition.pitch!,
turretModelDefinition.yaw,
hasImprovedVerticalStabilizer,
hasDownImprovedVerticalStabilizer,
hasDownImprovedVerticalStabilizer
);
modelTransformEvent.dispatch({ pitch: pitch.current, yaw: yaw.current });
}
@@ -251,6 +283,7 @@ function Gun({ map }: SectionProps) {
return (
<Batched
onMaterials={fadeEmissive}
onPointerDown={onPointerDown}
slicer={(node) => {
const isCurrentMantlet =
@@ -277,19 +310,23 @@ export function TankModel() {
const gunContainer = useRef<Group>(null!);
const { gltf } = useModel(protagonist.tank.id);
const skinGltf = useSkin(protagonist.tank.id);
const attachmentGltf = useSkin(protagonist.tank.id, "attachment");
const skins = [skinGltf, attachmentGltf].filter((skin) => skin !== undefined);
useTankTransform(track, turret, turretContainer, gunContainer);
useSkinAnimation(skins);
return (
<ModelTankWrapper ref={hullContainer}>
<Tracks map={gltf} />
<Hull map={gltf} />
<Tracks map={gltf} skins={skins} />
<Hull map={gltf} skins={skins} />
<group ref={turretContainer}>
<Turret map={gltf} />
<Turret map={gltf} skins={skins} />
<group ref={gunContainer}>
<Gun map={gltf} />
<Gun map={gltf} skins={skins} />
</group>
</group>
</ModelTankWrapper>