mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-28 21:19:52 +01:00
models shit
This commit is contained in:
1 parent
5c88bda07a
commit
5cae5d1583
6 files changed
+84
-76
No files matched your search
@@ -1,16 +1,16 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { degToRad } from "three/src/math/MathUtils.js";
|
import { degToRad } from "three/src/math/MathUtils.js";
|
||||||
import { Duel } from "../../../../../../stores/duel";
|
|
||||||
import { api } from "../api/dynamic";
|
import { api } from "../api/dynamic";
|
||||||
import { applyPitchYawLimits } from "../core/blitz/applyPitchYawLimits";
|
import { applyPitchYawLimits } from "../core/blitz/applyPitchYawLimits";
|
||||||
import { modelTransformEvent } from "../core/blitzkit/modelTransform";
|
import { modelTransformEvent } from "../core/blitzkit/modelTransform";
|
||||||
|
import { DuelModule, useDuel } from "../hooks/useDuel";
|
||||||
|
|
||||||
const modelDefinitions = await api.models();
|
const modelDefinitions = await api.models();
|
||||||
|
|
||||||
export function InitialCameraAligner() {
|
export function InitialCameraAligner() {
|
||||||
const tank = Duel.use((state) => state.protagonist.tank);
|
const tank = useDuel("protagonist", DuelModule.Tank);
|
||||||
const turret = Duel.use((state) => state.protagonist.turret);
|
const turret = useDuel("protagonist", DuelModule.Turret);
|
||||||
const gun = Duel.use((state) => state.protagonist.gun);
|
const gun = useDuel("protagonist", DuelModule.Gun);
|
||||||
|
|
||||||
const tankModel = modelDefinitions.models[tank.id];
|
const tankModel = modelDefinitions.models[tank.id];
|
||||||
const turretModel = tankModel.turrets[turret.id];
|
const turretModel = tankModel.turrets[turret.id];
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import { correctZYTuple } from "../core/blitz/correctZYTuple";
|
|||||||
import { nameToArmorId } from "../core/blitzkit/nameToArmorId";
|
import { nameToArmorId } from "../core/blitzkit/nameToArmorId";
|
||||||
import { resolveArmor } from "../core/blitzkit/resolveThickness";
|
import { resolveArmor } from "../core/blitzkit/resolveThickness";
|
||||||
import { useArmor } from "../hooks/useArmor";
|
import { useArmor } from "../hooks/useArmor";
|
||||||
|
import { useConsumable } from "../hooks/useConsumable";
|
||||||
import { DuelModule, useDuel } from "../hooks/useDuel";
|
import { DuelModule, useDuel } from "../hooks/useDuel";
|
||||||
import { ModelTankWrapper } from "./ModelTankWrapper";
|
import { useDuelModel } from "../hooks/useDuelModel";
|
||||||
|
import { useTankTransform } from "../hooks/useTankTransform";
|
||||||
import { PrimaryArmorSceneComponent } from "./PrimaryArmorSceneComponent";
|
import { PrimaryArmorSceneComponent } from "./PrimaryArmorSceneComponent";
|
||||||
|
|
||||||
export const PrimaryArmorScene = memo(() => {
|
export const PrimaryArmorScene = memo(() => {
|
||||||
const wrapper = useRef<Group>(null);
|
|
||||||
const turretContainer = useRef<Group>(null!);
|
const turretContainer = useRef<Group>(null!);
|
||||||
const gunContainer = useRef<Group>(null!);
|
const gunContainer = useRef<Group>(null!);
|
||||||
const tank = useDuel("protagonist", DuelModule.Tank);
|
const tank = useDuel("protagonist", DuelModule.Tank);
|
||||||
@@ -18,21 +19,19 @@ export const PrimaryArmorScene = memo(() => {
|
|||||||
const gun = useDuel("protagonist", DuelModule.Gun);
|
const gun = useDuel("protagonist", DuelModule.Gun);
|
||||||
const armorGltf = useArmor(tank.id).gltf;
|
const armorGltf = useArmor(tank.id).gltf;
|
||||||
const armorNodes = Object.values(armorGltf.nodes);
|
const armorNodes = Object.values(armorGltf.nodes);
|
||||||
const tankModelDefinition = useTankModelDefinition();
|
const tankModelDefinition = useDuelModel("protagonist");
|
||||||
const trackModelDefinition = tankModelDefinition.tracks[track.id];
|
const trackModelDefinition = tankModelDefinition.tracks[track.id];
|
||||||
const turretModelDefinition = tankModelDefinition.turrets[turret.id];
|
const turretModelDefinition = tankModelDefinition.turrets[turret.id];
|
||||||
const gunModelDefinition = turretModelDefinition.guns[gun.id];
|
const gunModelDefinition = turretModelDefinition.guns[gun.id];
|
||||||
const hullOrigin = correctZYTuple(trackModelDefinition.origin!);
|
const hullOrigin = correctZYTuple(trackModelDefinition.origin!);
|
||||||
const turretOrigin = correctZYTuple(tankModelDefinition.turret_origin!);
|
const turretOrigin = correctZYTuple(tankModelDefinition.turret_origin!);
|
||||||
const gunOrigin = correctZYTuple(turretModelDefinition.gun_origin!);
|
const gunOrigin = correctZYTuple(turretModelDefinition.gun_origin!);
|
||||||
const isDynamicArmorActive = Duel.use((state) =>
|
const isDynamicArmorActive = useConsumable("protagonist", 73);
|
||||||
state.protagonist.consumables.includes(73),
|
|
||||||
);
|
|
||||||
|
|
||||||
useTankTransform(track, turret, turretContainer, gunContainer);
|
useTankTransform(track, turret, turretContainer, gunContainer);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModelTankWrapper ref={wrapper}>
|
<>
|
||||||
<group position={hullOrigin}>
|
<group position={hullOrigin}>
|
||||||
{armorNodes.map((node) => {
|
{armorNodes.map((node) => {
|
||||||
const isHull = node.name.startsWith("hull_");
|
const isHull = node.name.startsWith("hull_");
|
||||||
@@ -132,6 +131,6 @@ export const PrimaryArmorScene = memo(() => {
|
|||||||
})}
|
})}
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</ModelTankWrapper>
|
</>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -23,7 +23,7 @@ import { hasEquipment } from "../../hooks/useEquipment";
|
|||||||
import { Tankopedia } from "../../stores/tankopedia";
|
import { Tankopedia } from "../../stores/tankopedia";
|
||||||
import { TankopediaPersistent } from "../../stores/tankopediaPersistent";
|
import { TankopediaPersistent } from "../../stores/tankopediaPersistent";
|
||||||
import { transitionEvent } from "../Lighting";
|
import { transitionEvent } from "../Lighting";
|
||||||
import { spacedArmorRenderTarget } from "./PrimaryArmorRenderTarget";
|
import { spacedArmorRenderTarget } from "../PrimaryArmorRenderTarget";
|
||||||
import fragmentShader from "./shaders/fragment.glsl?raw";
|
import fragmentShader from "./shaders/fragment.glsl?raw";
|
||||||
import vertexShader from "./shaders/vertex.glsl?raw";
|
import vertexShader from "./shaders/vertex.glsl?raw";
|
||||||
|
|
||||||
@@ -134,6 +134,8 @@ export function PrimaryArmorSceneComponent({
|
|||||||
if (!noInvalidate) invalidate();
|
if (!noInvalidate) invalidate();
|
||||||
}
|
}
|
||||||
function handleAntagonistEquipmentChange(noInvalidate = false) {
|
function handleAntagonistEquipmentChange(noInvalidate = false) {
|
||||||
|
const antagonist = getDuel("antagonist", DuelModule.Tank);
|
||||||
|
|
||||||
const equipment = Tankopedia.state.antagonist.equipment;
|
const equipment = Tankopedia.state.antagonist.equipment;
|
||||||
const tankopediaEphemeral = Tankopedia.state;
|
const tankopediaEphemeral = Tankopedia.state;
|
||||||
const shell =
|
const shell =
|
||||||
@@ -142,7 +144,7 @@ export function PrimaryArmorSceneComponent({
|
|||||||
const penetration = shell.penetration!.near;
|
const penetration = shell.penetration!.near;
|
||||||
const hasCalibratedShells = hasEquipment(
|
const hasCalibratedShells = hasEquipment(
|
||||||
103,
|
103,
|
||||||
Duel.state.antagonist.tank.equipment_preset,
|
antagonist.equipment_preset,
|
||||||
equipment,
|
equipment,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -150,9 +152,9 @@ export function PrimaryArmorSceneComponent({
|
|||||||
penetration *
|
penetration *
|
||||||
resolvePenetrationCoefficient(
|
resolvePenetrationCoefficient(
|
||||||
hasCalibratedShells,
|
hasCalibratedShells,
|
||||||
Duel.state.equalize,
|
Tankopedia.state.equalize,
|
||||||
shell.type,
|
shell.type,
|
||||||
Duel.state.antagonist.tank.equalizer,
|
antagonist.equalizer,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!noInvalidate) invalidate();
|
if (!noInvalidate) invalidate();
|
||||||
@@ -175,7 +177,7 @@ export function PrimaryArmorSceneComponent({
|
|||||||
transitionEvent.on(handleTransitionEvent);
|
transitionEvent.on(handleTransitionEvent);
|
||||||
|
|
||||||
const unsubscribes = [
|
const unsubscribes = [
|
||||||
Duel.on((state) => state.antagonist.shell, handleShellChange),
|
Tankopedia.on((state) => state.antagonist.shell, handleShellChange),
|
||||||
Tankopedia.on((state) => state.customShell, handleShellChange),
|
Tankopedia.on((state) => state.customShell, handleShellChange),
|
||||||
TankopediaPersistent.on(
|
TankopediaPersistent.on(
|
||||||
(state) => state.greenPenetration,
|
(state) => state.greenPenetration,
|
||||||
@@ -186,15 +188,15 @@ export function PrimaryArmorSceneComponent({
|
|||||||
handleAdvancedHighlightingChange,
|
handleAdvancedHighlightingChange,
|
||||||
),
|
),
|
||||||
TankopediaPersistent.on((state) => state.opaque, handleOpaqueChange),
|
TankopediaPersistent.on((state) => state.opaque, handleOpaqueChange),
|
||||||
Duel.on(
|
Tankopedia.on(
|
||||||
(state) => state.protagonist.equipmentMatrix,
|
(state) => state.protagonist.equipment,
|
||||||
() => handleProtagonistEquipmentChange(),
|
() => handleProtagonistEquipmentChange(),
|
||||||
),
|
),
|
||||||
Duel.on(
|
Tankopedia.on(
|
||||||
(state) => state.antagonist.equipmentMatrix,
|
(state) => state.antagonist.equipment,
|
||||||
() => handleAntagonistEquipmentChange(),
|
() => handleAntagonistEquipmentChange(),
|
||||||
),
|
),
|
||||||
Duel.on(
|
Tankopedia.on(
|
||||||
(state) => state.equalize,
|
(state) => state.equalize,
|
||||||
() => {
|
() => {
|
||||||
handleProtagonistEquipmentChange();
|
handleProtagonistEquipmentChange();
|
||||||
|
|||||||
@@ -3,19 +3,19 @@ import { memo, useRef } from "react";
|
|||||||
import { Group, Plane, Vector2, Vector3 } from "three";
|
import { Group, Plane, Vector2, Vector3 } from "three";
|
||||||
import { applyPitchYawLimits } from "../core/blitz/applyPitchYawLimits";
|
import { applyPitchYawLimits } from "../core/blitz/applyPitchYawLimits";
|
||||||
import { correctZYTuple } from "../core/blitz/correctZYTuple";
|
import { correctZYTuple } from "../core/blitz/correctZYTuple";
|
||||||
import { hasEquipment } from "../core/blitzkit/hasEquipment";
|
|
||||||
import { modelTransformEvent } from "../core/blitzkit/modelTransform";
|
import { modelTransformEvent } from "../core/blitzkit/modelTransform";
|
||||||
import { nameToArmorId } from "../core/blitzkit/nameToArmorId";
|
import { nameToArmorId } from "../core/blitzkit/nameToArmorId";
|
||||||
import { resolveArmor } from "../core/blitzkit/resolveThickness";
|
import { resolveArmor } from "../core/blitzkit/resolveThickness";
|
||||||
import { controlsEnabledEvent } from "../core/controlsEnabled";
|
import { controlsEnabledEvent } from "../core/controlsEnabled";
|
||||||
import { useArmor } from "../hooks/useArmor";
|
import { useArmor } from "../hooks/useArmor";
|
||||||
|
import { useConsumable } from "../hooks/useConsumable";
|
||||||
|
import { DuelModule, getDuel, useDuel } from "../hooks/useDuel";
|
||||||
|
import { useDuelModel } from "../hooks/useDuelModel";
|
||||||
|
import { hasEquipment } from "../hooks/useEquipment";
|
||||||
import { useModel } from "../hooks/useModel";
|
import { useModel } from "../hooks/useModel";
|
||||||
import { useTankModelDefinition } from "../hooks/useTankModelDefinition";
|
|
||||||
import { useTankTransform } from "../hooks/useTankTransform";
|
import { useTankTransform } from "../hooks/useTankTransform";
|
||||||
import { Duel } from "../stores/duel";
|
|
||||||
import { Tankopedia } from "../stores/tankopedia";
|
import { Tankopedia } from "../stores/tankopedia";
|
||||||
import { TankopediaPersistent } from "../stores/tankopediaPersistent";
|
import { TankopediaPersistent } from "../stores/tankopediaPersistent";
|
||||||
import { ModelTankWrapper } from "./ModelTankWrapper";
|
|
||||||
import { ArmorType } from "./SpacedArmorScene";
|
import { ArmorType } from "./SpacedArmorScene";
|
||||||
import { StaticArmorSceneComponent } from "./StaticArmorSceneComponent";
|
import { StaticArmorSceneComponent } from "./StaticArmorSceneComponent";
|
||||||
|
|
||||||
@@ -28,18 +28,19 @@ export interface ThicknessRange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const StaticArmor = memo<ArmorSceneProps>(({ thicknessRange }) => {
|
export const StaticArmor = memo<ArmorSceneProps>(({ thicknessRange }) => {
|
||||||
const wrapper = useRef<Group>(null);
|
|
||||||
const turretContainer = useRef<Group>(null!);
|
const turretContainer = useRef<Group>(null!);
|
||||||
const gunContainer = useRef<Group>(null!);
|
const gunContainer = useRef<Group>(null!);
|
||||||
const tank = Duel.use((state) => state.protagonist.tank);
|
|
||||||
const track = Duel.use((state) => state.protagonist.track);
|
const tank = useDuel("protagonist", DuelModule.Tank);
|
||||||
const turret = Duel.use((state) => state.protagonist.turret);
|
const track = useDuel("protagonist", DuelModule.Track);
|
||||||
const gun = Duel.use((state) => state.protagonist.gun);
|
const turret = useDuel("protagonist", DuelModule.Turret);
|
||||||
|
const gun = useDuel("protagonist", DuelModule.Gun);
|
||||||
|
|
||||||
const { gltf: armorGltf } = useArmor(tank.id);
|
const { gltf: armorGltf } = useArmor(tank.id);
|
||||||
const { gltf: modelGltf } = useModel(tank.id);
|
const { gltf: modelGltf } = useModel(tank.id);
|
||||||
const armorNodes = Object.values(armorGltf.nodes);
|
const armorNodes = Object.values(armorGltf.nodes);
|
||||||
const modelNodes = Object.values(modelGltf.nodes);
|
const modelNodes = Object.values(modelGltf.nodes);
|
||||||
const tankModelDefinition = useTankModelDefinition();
|
const tankModelDefinition = useDuelModel("protagonist");
|
||||||
const trackModelDefinition = tankModelDefinition.tracks[track.id];
|
const trackModelDefinition = tankModelDefinition.tracks[track.id];
|
||||||
const turretModelDefinition = tankModelDefinition.turrets[turret.id];
|
const turretModelDefinition = tankModelDefinition.turrets[turret.id];
|
||||||
const gunModelDefinition = turretModelDefinition.guns[gun.id];
|
const gunModelDefinition = turretModelDefinition.guns[gun.id];
|
||||||
@@ -61,14 +62,12 @@ export const StaticArmor = memo<ArmorSceneProps>(({ thicknessRange }) => {
|
|||||||
const showExternalModules = TankopediaPersistent.use(
|
const showExternalModules = TankopediaPersistent.use(
|
||||||
(state) => state.showExternalModules,
|
(state) => state.showExternalModules,
|
||||||
);
|
);
|
||||||
const isDynamicArmorActive = Duel.use((state) =>
|
const isDynamicArmorActive = useConsumable("protagonist", 73);
|
||||||
state.protagonist.consumables.includes(73),
|
|
||||||
);
|
|
||||||
|
|
||||||
useTankTransform(track, turret, turretContainer, gunContainer);
|
useTankTransform(track, turret, turretContainer, gunContainer);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModelTankWrapper ref={wrapper}>
|
<>
|
||||||
<group position={hullOrigin}>
|
<group position={hullOrigin}>
|
||||||
{armorNodes.map((node) => {
|
{armorNodes.map((node) => {
|
||||||
const isHull = node.name.startsWith("hull_");
|
const isHull = node.name.startsWith("hull_");
|
||||||
@@ -165,15 +164,17 @@ export const StaticArmor = memo<ArmorSceneProps>(({ thicknessRange }) => {
|
|||||||
window.addEventListener("pointerup", handlePointerUp);
|
window.addEventListener("pointerup", handlePointerUp);
|
||||||
}
|
}
|
||||||
function handlePointerMove(event: PointerEvent) {
|
function handlePointerMove(event: PointerEvent) {
|
||||||
|
const protagonist = getDuel("protagonist", DuelModule.Tank);
|
||||||
|
|
||||||
const hasImprovedVerticalStabilizer = hasEquipment(
|
const hasImprovedVerticalStabilizer = hasEquipment(
|
||||||
122,
|
122,
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
protagonist.equipment_preset,
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
Tankopedia.state.protagonist.equipment,
|
||||||
);
|
);
|
||||||
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
||||||
124,
|
124,
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
protagonist.equipment_preset,
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
Tankopedia.state.protagonist.equipment,
|
||||||
);
|
);
|
||||||
const boundingRect = canvas.getBoundingClientRect();
|
const boundingRect = canvas.getBoundingClientRect();
|
||||||
|
|
||||||
@@ -253,15 +254,17 @@ export const StaticArmor = memo<ArmorSceneProps>(({ thicknessRange }) => {
|
|||||||
window.addEventListener("pointerup", handlePointerUp);
|
window.addEventListener("pointerup", handlePointerUp);
|
||||||
}
|
}
|
||||||
function handlePointerMove(event: PointerEvent) {
|
function handlePointerMove(event: PointerEvent) {
|
||||||
|
const protagonist = getDuel("protagonist", DuelModule.Tank);
|
||||||
|
|
||||||
const hasImprovedVerticalStabilizer = hasEquipment(
|
const hasImprovedVerticalStabilizer = hasEquipment(
|
||||||
122,
|
122,
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
protagonist.equipment_preset,
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
Tankopedia.state.protagonist.equipment,
|
||||||
);
|
);
|
||||||
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
||||||
124,
|
124,
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
protagonist.equipment_preset,
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
Tankopedia.state.protagonist.equipment,
|
||||||
);
|
);
|
||||||
const boundingRect = canvas.getBoundingClientRect();
|
const boundingRect = canvas.getBoundingClientRect();
|
||||||
delta.set(event.clientX, event.clientY).sub(position);
|
delta.set(event.clientX, event.clientY).sub(position);
|
||||||
@@ -329,15 +332,17 @@ export const StaticArmor = memo<ArmorSceneProps>(({ thicknessRange }) => {
|
|||||||
window.addEventListener("pointerup", handlePointerUp);
|
window.addEventListener("pointerup", handlePointerUp);
|
||||||
}
|
}
|
||||||
function handlePointerMove(event: PointerEvent) {
|
function handlePointerMove(event: PointerEvent) {
|
||||||
|
const protagonist = getDuel("protagonist", DuelModule.Tank);
|
||||||
|
|
||||||
const hasImprovedVerticalStabilizer = hasEquipment(
|
const hasImprovedVerticalStabilizer = hasEquipment(
|
||||||
122,
|
122,
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
protagonist.equipment_preset,
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
Tankopedia.state.protagonist.equipment,
|
||||||
);
|
);
|
||||||
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
||||||
124,
|
124,
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
protagonist.equipment_preset,
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
Tankopedia.state.protagonist.equipment,
|
||||||
);
|
);
|
||||||
const boundingRect = canvas.getBoundingClientRect();
|
const boundingRect = canvas.getBoundingClientRect();
|
||||||
delta.set(event.clientX, event.clientY).sub(position);
|
delta.set(event.clientX, event.clientY).sub(position);
|
||||||
@@ -385,6 +390,6 @@ export const StaticArmor = memo<ArmorSceneProps>(({ thicknessRange }) => {
|
|||||||
})}
|
})}
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</ModelTankWrapper>
|
</>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -16,16 +16,16 @@ import {
|
|||||||
Quaternion,
|
Quaternion,
|
||||||
Vector3,
|
Vector3,
|
||||||
} from "three";
|
} from "three";
|
||||||
|
import { defaultEqualizer } from "../config/equalizer";
|
||||||
import { unrotateDavaVector } from "../core/blitz/unrotateDavaVector";
|
import { unrotateDavaVector } from "../core/blitz/unrotateDavaVector";
|
||||||
import { jsxTree } from "../core/blitzkit/jsxTree";
|
import { jsxTree } from "../core/blitzkit/jsxTree";
|
||||||
import {
|
import {
|
||||||
modelTransformEvent,
|
modelTransformEvent,
|
||||||
type ModelTransformEventData,
|
type ModelTransformEventData,
|
||||||
} from "../core/blitzkit/modelTransform";
|
} from "../core/blitzkit/modelTransform";
|
||||||
import { defaultEqualizer } from "../core/blitzkit/tankToDuelMember";
|
|
||||||
import { discardClippingPlane } from "../core/three/discardClippingPlane";
|
import { discardClippingPlane } from "../core/three/discardClippingPlane";
|
||||||
|
import { DuelModule, useDuel } from "../hooks/useDuel";
|
||||||
import { useEquipment } from "../hooks/useEquipment";
|
import { useEquipment } from "../hooks/useEquipment";
|
||||||
import { Duel } from "../stores/duel";
|
|
||||||
import { Tankopedia } from "../stores/tankopedia";
|
import { Tankopedia } from "../stores/tankopedia";
|
||||||
import { transitionEvent } from "./Lighting";
|
import { transitionEvent } from "./Lighting";
|
||||||
import { ArmorType } from "./SpacedArmorScene";
|
import { ArmorType } from "./SpacedArmorScene";
|
||||||
@@ -75,8 +75,8 @@ export function StaticArmorSceneComponent({
|
|||||||
}: StaticArmorSceneComponentProps) {
|
}: StaticArmorSceneComponentProps) {
|
||||||
const camera = useThree((state) => state.camera);
|
const camera = useThree((state) => state.camera);
|
||||||
const hasEnhancedArmor = useEquipment("protagonist", 110);
|
const hasEnhancedArmor = useEquipment("protagonist", 110);
|
||||||
const tank = Duel.use((state) => state.protagonist.tank);
|
const tank = useDuel("protagonist", DuelModule.Tank);
|
||||||
const equalize = Duel.use((state) => state.equalize);
|
const equalize = Tankopedia.use((state) => state.equalize);
|
||||||
const equalizer = (equalize ? tank.equalizer : undefined) ?? defaultEqualizer;
|
const equalizer = (equalize ? tank.equalizer : undefined) ?? defaultEqualizer;
|
||||||
const thicknessCoefficient = (hasEnhancedArmor ? 1.04 : 1) * equalizer.armor;
|
const thicknessCoefficient = (hasEnhancedArmor ? 1.04 : 1) * equalizer.armor;
|
||||||
const thickness = thicknessRaw * thicknessCoefficient;
|
const thickness = thicknessRaw * thicknessCoefficient;
|
||||||
|
|||||||
@@ -1,38 +1,36 @@
|
|||||||
import { invalidate, useThree, type ThreeEvent } from "@react-three/fiber";
|
import { invalidate, useThree, type ThreeEvent } from "@react-three/fiber";
|
||||||
import { useRef } from "react";
|
import { useRef } from "react";
|
||||||
import { Group, Mesh, MeshStandardMaterial, Vector2 } from "three";
|
import { Group, Mesh, MeshStandardMaterial, Vector2 } from "three";
|
||||||
import { useTankModelDefinition } from "../../../../../../hooks/useTankModelDefinition";
|
|
||||||
import { Duel } from "../../../../../../stores/duel";
|
|
||||||
import { applyPitchYawLimits } from "../core/blitz/applyPitchYawLimits";
|
import { applyPitchYawLimits } from "../core/blitz/applyPitchYawLimits";
|
||||||
import { hasEquipment } from "../core/blitzkit/hasEquipment";
|
|
||||||
import { jsxTree } from "../core/blitzkit/jsxTree";
|
import { jsxTree } from "../core/blitzkit/jsxTree";
|
||||||
import { modelTransformEvent } from "../core/blitzkit/modelTransform";
|
import { modelTransformEvent } from "../core/blitzkit/modelTransform";
|
||||||
import { controlsEnabledEvent } from "../core/controlsEnabled";
|
import { controlsEnabledEvent } from "../core/controlsEnabled";
|
||||||
|
import { DuelModule, useDuel } from "../hooks/useDuel";
|
||||||
|
import { useDuelModel } from "../hooks/useDuelModel";
|
||||||
|
import { hasEquipment } from "../hooks/useEquipment";
|
||||||
import { useModel } from "../hooks/useModel";
|
import { useModel } from "../hooks/useModel";
|
||||||
import { useTankTransform } from "../hooks/useTankTransform";
|
import { useTankTransform } from "../hooks/useTankTransform";
|
||||||
import { Tankopedia } from "../stores/tankopedia";
|
import { Tankopedia } from "../stores/tankopedia";
|
||||||
import { TankopediaDisplay } from "../stores/tankopediaPersistent/constants";
|
import { TankopediaDisplay } from "../stores/tankopediaPersistent/constants";
|
||||||
import { ModelTankWrapper } from "./ModelTankWrapper";
|
|
||||||
|
|
||||||
export function TankModel() {
|
export function TankModel() {
|
||||||
const protagonist = Duel.use((draft) => draft.protagonist);
|
const protagonist = Tankopedia.use((state) => state.protagonist);
|
||||||
const track = Duel.use((state) => state.protagonist.track);
|
const track = useDuel("protagonist", DuelModule.Track);
|
||||||
const turret = Duel.use((state) => state.protagonist.turret);
|
const turret = useDuel("protagonist", DuelModule.Turret);
|
||||||
|
|
||||||
const canvas = useThree((state) => state.gl.domElement);
|
const canvas = useThree((state) => state.gl.domElement);
|
||||||
const hullContainer = useRef<Group>(null);
|
|
||||||
const turretContainer = useRef<Group>(null!);
|
const turretContainer = useRef<Group>(null!);
|
||||||
const gunContainer = useRef<Group>(null!);
|
const gunContainer = useRef<Group>(null!);
|
||||||
const tankModelDefinition = useTankModelDefinition();
|
const tankModelDefinition = useDuelModel("protagonist");
|
||||||
const turretModelDefinition =
|
const turretModelDefinition = tankModelDefinition.turrets[protagonist.turret];
|
||||||
tankModelDefinition.turrets[protagonist.turret.id];
|
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun];
|
||||||
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
const { gltf } = useModel(protagonist.tank);
|
||||||
const { gltf } = useModel(protagonist.tank.id);
|
|
||||||
const nodes = Object.values(gltf.nodes);
|
const nodes = Object.values(gltf.nodes);
|
||||||
|
|
||||||
useTankTransform(track, turret, turretContainer, gunContainer);
|
useTankTransform(track, turret, turretContainer, gunContainer);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModelTankWrapper ref={hullContainer}>
|
<>
|
||||||
{nodes.map((node) => {
|
{nodes.map((node) => {
|
||||||
const isHull = node.name === "hull";
|
const isHull = node.name === "hull";
|
||||||
const isWheel = node.name.startsWith("chassis_wheel_");
|
const isWheel = node.name.startsWith("chassis_wheel_");
|
||||||
@@ -131,15 +129,17 @@ export function TankModel() {
|
|||||||
window.addEventListener("pointerup", handlePointerUp);
|
window.addEventListener("pointerup", handlePointerUp);
|
||||||
}
|
}
|
||||||
function handlePointerMove(event: PointerEvent) {
|
function handlePointerMove(event: PointerEvent) {
|
||||||
|
const protagonist = useDuel("protagonist", DuelModule.Tank);
|
||||||
|
|
||||||
const hasImprovedVerticalStabilizer = hasEquipment(
|
const hasImprovedVerticalStabilizer = hasEquipment(
|
||||||
122,
|
122,
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
protagonist.equipment_preset,
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
Tankopedia.state.protagonist.equipment,
|
||||||
);
|
);
|
||||||
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
||||||
124,
|
124,
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
protagonist.equipment_preset,
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
Tankopedia.state.protagonist.equipment,
|
||||||
);
|
);
|
||||||
const boundingRect = canvas.getBoundingClientRect();
|
const boundingRect = canvas.getBoundingClientRect();
|
||||||
|
|
||||||
@@ -214,15 +214,17 @@ export function TankModel() {
|
|||||||
window.addEventListener("pointerup", handlePointerUp);
|
window.addEventListener("pointerup", handlePointerUp);
|
||||||
}
|
}
|
||||||
function handlePointerMove(event: PointerEvent) {
|
function handlePointerMove(event: PointerEvent) {
|
||||||
|
const protagonist = useDuel("protagonist", DuelModule.Tank);
|
||||||
|
|
||||||
const hasImprovedVerticalStabilizer = hasEquipment(
|
const hasImprovedVerticalStabilizer = hasEquipment(
|
||||||
122,
|
122,
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
protagonist.equipment_preset,
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
Tankopedia.state.protagonist.equipment,
|
||||||
);
|
);
|
||||||
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
||||||
124,
|
124,
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
protagonist.equipment_preset,
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
Tankopedia.state.protagonist.equipment,
|
||||||
);
|
);
|
||||||
const boundingRect = canvas.getBoundingClientRect();
|
const boundingRect = canvas.getBoundingClientRect();
|
||||||
delta.set(event.clientX, event.clientY).sub(position);
|
delta.set(event.clientX, event.clientY).sub(position);
|
||||||
@@ -260,6 +262,6 @@ export function TankModel() {
|
|||||||
})}
|
})}
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</ModelTankWrapper>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user