mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-01 13:55:01 +01:00
Merge branch 'main' into data-driven
This commit is contained in:
5 files changed
+68
-32
No files matched your search
@@ -122,7 +122,7 @@ export function SpacedArmorSceneComponent({
|
||||
const antagonist = getDuelModules("antagonist").tank;
|
||||
|
||||
const { customShell } = Tankopedia.state;
|
||||
const shell = customShell ?? getDuelModules("protagonist").shell;
|
||||
const shell = customShell ?? getDuelModules("antagonist").shell;
|
||||
const { equalize } = Tankopedia.state.environment;
|
||||
const protagonistEqualizer =
|
||||
(equalize ? protagonist.equalizer : undefined) ?? defaultEqualizer;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { MeshBasicMaterial } from "three";
|
||||
import type { ArmorPlate } from "../../hooks/useArmorPlates";
|
||||
import { usePlateItems } from "../../hooks/usePlateItems";
|
||||
import { Batch } from "../Batch";
|
||||
|
||||
interface SpacedArmorSubPrimaryProps {
|
||||
plates: ArmorPlate[];
|
||||
}
|
||||
|
||||
const omitMaterial = new MeshBasicMaterial({
|
||||
colorWrite: false,
|
||||
depthWrite: true,
|
||||
});
|
||||
|
||||
export function SpacedArmorSubPrimary({ plates }: SpacedArmorSubPrimaryProps) {
|
||||
const items = usePlateItems(plates);
|
||||
|
||||
return <Batch items={items} material={omitMaterial} renderOrder={0} />;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { ContactShadows } from "@react-three/drei";
|
||||
import { Tankopedia } from "../../stores/tankopedia";
|
||||
import { TankopediaDisplay } from "../../stores/tankopediaPersistent/constants";
|
||||
|
||||
/**
|
||||
* drei's ContactShadows, but only redrawn when the scene changes instead of
|
||||
* every frame. drei resets its frame count on every render, so re-rendering
|
||||
* with frames={1} draws it once more.
|
||||
*/
|
||||
export function TankopediaContactShadows() {
|
||||
const display = Tankopedia.use((state) => state.loaders.display.loaded);
|
||||
|
||||
if (display === TankopediaDisplay.StaticArmor) return null;
|
||||
|
||||
return (
|
||||
<ContactShadows
|
||||
frames={1}
|
||||
width={1.5}
|
||||
height={1.5}
|
||||
near={0}
|
||||
far={1}
|
||||
opacity={2 ** 1}
|
||||
blur={2 ** 1}
|
||||
resolution={2 ** 6}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { Armor } from "@blitzkit/core";
|
||||
import type { Armor } from "@blitzkit/protos";
|
||||
import { useMemo } from "react";
|
||||
import type { Object3D } from "three";
|
||||
import { nameToArmorId } from "../core/blitzkit/nameToArmorId";
|
||||
import { resolveArmor } from "../core/blitzkit/resolveThickness";
|
||||
import { Duel } from "../stores/duel";
|
||||
import { Tankopedia } from "../stores/tankopedia";
|
||||
import { useArmor } from "./useArmor";
|
||||
import { useTankModelDefinition } from "./useTankModelDefinition";
|
||||
import { useDuelModels } from "./useDuelModels";
|
||||
|
||||
export interface ArmorPlate {
|
||||
node: Object3D;
|
||||
@@ -20,15 +20,11 @@ interface SectionPlates {
|
||||
// the protagonist's hull, turret and gun plates; nodes whose name contains
|
||||
// hiddenState are dynamic armor in the other state
|
||||
export function useArmorPlates(hiddenState: string) {
|
||||
const tank = Duel.use((state) => state.protagonist.tank);
|
||||
const turret = Duel.use((state) => state.protagonist.turret);
|
||||
const gun = Duel.use((state) => state.protagonist.gun);
|
||||
const { gltf } = useArmor(tank.id);
|
||||
const tankModelDefinition = useTankModelDefinition();
|
||||
const tank = Tankopedia.use((state) => state.protagonist.tank);
|
||||
const models = useDuelModels("protagonist");
|
||||
const { gltf } = useArmor(tank);
|
||||
|
||||
return useMemo(() => {
|
||||
const turretModelDefinition = tankModelDefinition.turrets[turret.id];
|
||||
const gunModelDefinition = turretModelDefinition.guns[gun.id];
|
||||
const nodes = Object.values(gltf.nodes);
|
||||
|
||||
function platesOf(prefix: string, armor: Armor) {
|
||||
@@ -41,7 +37,7 @@ export function useArmorPlates(hiddenState: string) {
|
||||
|
||||
const { spaced, thickness } = resolveArmor(
|
||||
armor,
|
||||
nameToArmorId(node.name),
|
||||
nameToArmorId(node.name)
|
||||
);
|
||||
|
||||
plates[spaced ? "spaced" : "primary"].push({ node, thickness });
|
||||
@@ -50,16 +46,16 @@ export function useArmorPlates(hiddenState: string) {
|
||||
return plates;
|
||||
}
|
||||
|
||||
const hullPlates = platesOf("hull_", tankModelDefinition.armor!);
|
||||
const hullPlates = platesOf("hull_", models.tank.armor!);
|
||||
const turretPlates = platesOf(
|
||||
`turret_${turretModelDefinition.model_id.toString().padStart(2, "0")}`,
|
||||
turretModelDefinition.armor!,
|
||||
`turret_${models.turret.model_id.toString().padStart(2, "0")}`,
|
||||
models.turret.armor!
|
||||
);
|
||||
const gunPlates = platesOf(
|
||||
`gun_${gunModelDefinition.model_id.toString().padStart(2, "0")}`,
|
||||
gunModelDefinition.armor!,
|
||||
`gun_${models.gun.model_id.toString().padStart(2, "0")}`,
|
||||
models.gun.armor!
|
||||
);
|
||||
|
||||
return { hull: hullPlates, turret: turretPlates, gun: gunPlates };
|
||||
}, [gltf, tankModelDefinition, turret.id, gun.id, hiddenState]);
|
||||
}, [gltf, models.tank, models.turret, models.gun, hiddenState]);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useMemo } from "react";
|
||||
import type { Object3D } from "three";
|
||||
import { Duel } from "../stores/duel";
|
||||
import { Tankopedia } from "../stores/tankopedia";
|
||||
import { useDuelModels } from "./useDuelModels";
|
||||
import { useModel } from "./useModel";
|
||||
import { useTankModelDefinition } from "./useTankModelDefinition";
|
||||
|
||||
interface ModelNodes {
|
||||
hull: Object3D[];
|
||||
@@ -15,21 +15,15 @@ interface ModelNodes {
|
||||
|
||||
// the protagonist's visual model split into its parts
|
||||
export function useModelNodes() {
|
||||
const tank = Duel.use((state) => state.protagonist.tank);
|
||||
const turret = Duel.use((state) => state.protagonist.turret);
|
||||
const gun = Duel.use((state) => state.protagonist.gun);
|
||||
const { gltf } = useModel(tank.id);
|
||||
const tankModelDefinition = useTankModelDefinition();
|
||||
const tank = Tankopedia.use((state) => state.protagonist.tank);
|
||||
const models = useDuelModels("protagonist");
|
||||
const { gltf } = useModel(tank);
|
||||
|
||||
return useMemo(() => {
|
||||
const turretModelDefinition = tankModelDefinition.turrets[turret.id];
|
||||
const gunModelDefinition = turretModelDefinition.guns[gun.id];
|
||||
const turretName = `turret_${turretModelDefinition.model_id
|
||||
.toString()
|
||||
.padStart(2, "0")}`;
|
||||
const gunName = `gun_${gunModelDefinition.model_id
|
||||
const turretName = `turret_${models.turret.model_id
|
||||
.toString()
|
||||
.padStart(2, "0")}`;
|
||||
const gunName = `gun_${models.gun.model_id.toString().padStart(2, "0")}`;
|
||||
const maskName = `${gunName}_mask`;
|
||||
const nodes: ModelNodes = {
|
||||
hull: [],
|
||||
@@ -67,5 +61,5 @@ export function useModelNodes() {
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}, [gltf, tankModelDefinition, turret.id, gun.id]);
|
||||
}, [gltf, models.turret, models.gun]);
|
||||
}
|
||||
Reference in new issue
Block a user