mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
fix: static
This commit is contained in:
1 parent
99c95a4c15
commit
71caa2f703
2 files changed
+62
-34
No files matched your search
@@ -22,7 +22,10 @@ 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 { useEquipment } from "../../../hooks/useEquipment";
|
||||||
|
import { Duel } from "../../../stores/duel";
|
||||||
import { Tankopedia } from "../../../stores/tankopedia";
|
import { Tankopedia } from "../../../stores/tankopedia";
|
||||||
import { transitionEvent } from "../../Tankopedia/HeroSection/components/TankSandbox/components/Lighting";
|
import { transitionEvent } from "../../Tankopedia/HeroSection/components/TankSandbox/components/Lighting";
|
||||||
import { ArmorType } from "./SpacedArmorScene";
|
import { ArmorType } from "./SpacedArmorScene";
|
||||||
@@ -64,46 +67,68 @@ const externalModuleColor = new Color(192 / 255, 192 / 255, 192 / 255);
|
|||||||
|
|
||||||
export function StaticArmorSceneComponent({
|
export function StaticArmorSceneComponent({
|
||||||
name,
|
name,
|
||||||
thickness,
|
thickness: thicknessRaw,
|
||||||
thicknessRange,
|
thicknessRange,
|
||||||
node,
|
node,
|
||||||
onPointerDown,
|
onPointerDown,
|
||||||
...props
|
...props
|
||||||
}: StaticArmorSceneComponentProps) {
|
}: StaticArmorSceneComponentProps) {
|
||||||
const camera = useThree((state) => state.camera);
|
const camera = useThree((state) => state.camera);
|
||||||
|
const hasEnhancedArmor = useEquipment(110);
|
||||||
|
const tank = Duel.use((state) => state.protagonist.tank);
|
||||||
|
const equalize = Duel.use((state) => state.equalize);
|
||||||
|
const equalizer = (equalize ? tank.equalizer : undefined) ?? defaultEqualizer;
|
||||||
|
const thicknessCoefficient = (hasEnhancedArmor ? 1.03 : 1) * equalizer.armor;
|
||||||
|
const thickness = thicknessRaw * thicknessCoefficient;
|
||||||
const x = thickness / thicknessRange.value;
|
const x = thickness / thicknessRange.value;
|
||||||
const xClamped = clamp(x, 0, 1);
|
const xClamped = clamp(x, 0, 1);
|
||||||
let color: Color;
|
const color = useMemo(() => {
|
||||||
let opacity: number;
|
switch (props.type) {
|
||||||
let depthWrite = true;
|
case ArmorType.Primary: {
|
||||||
|
if (x > 1) {
|
||||||
switch (props.type) {
|
return new Color(clamp(2 - x, 0.5, 1), 0, 0);
|
||||||
case ArmorType.Primary:
|
} else {
|
||||||
if (x > 1) {
|
return new Color(-((1 - x) ** 2) + 1, -(x ** 2) + 1, 0);
|
||||||
color = new Color(clamp(2 - x, 0.5, 1), 0, 0);
|
}
|
||||||
} else {
|
|
||||||
color = new Color(-((1 - x) ** 2) + 1, -(x ** 2) + 1, 0);
|
|
||||||
}
|
}
|
||||||
opacity = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ArmorType.Spaced:
|
case ArmorType.Spaced: {
|
||||||
color = new Color(
|
return new Color(
|
||||||
clamp(1 - (7 / 8) * xClamped, 0, 1),
|
clamp(1 - (7 / 8) * xClamped, 0, 1),
|
||||||
0,
|
0,
|
||||||
clamp(1 - (1 / 8) * xClamped, 0, 1),
|
clamp(1 - (1 / 8) * xClamped, 0, 1),
|
||||||
);
|
);
|
||||||
opacity = clamp(x + 1 / 2, 0, 1);
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case ArmorType.External:
|
case ArmorType.External: {
|
||||||
color = externalModuleColor;
|
return externalModuleColor;
|
||||||
opacity = 1 / 8;
|
}
|
||||||
depthWrite = false;
|
}
|
||||||
break;
|
}, [props.type, xClamped]);
|
||||||
}
|
const opacity = useMemo(() => {
|
||||||
|
switch (props.type) {
|
||||||
|
case ArmorType.Primary:
|
||||||
|
return 1;
|
||||||
|
|
||||||
opacity = clamp(opacity, 0, 1);
|
case ArmorType.Spaced:
|
||||||
|
return clamp(x + 1 / 2, 0, 1);
|
||||||
|
|
||||||
|
case ArmorType.External:
|
||||||
|
return 1 / 8;
|
||||||
|
}
|
||||||
|
}, [props.type, x]);
|
||||||
|
const depthWrite = useMemo(() => {
|
||||||
|
switch (props.type) {
|
||||||
|
case ArmorType.Primary:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case ArmorType.Spaced:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case ArmorType.External:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, [props.type]);
|
||||||
|
|
||||||
const surfaceMaterial = useMemo(
|
const surfaceMaterial = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -115,7 +140,7 @@ export function StaticArmorSceneComponent({
|
|||||||
opacity: 0,
|
opacity: 0,
|
||||||
userData: { opacity0: opacity },
|
userData: { opacity0: opacity },
|
||||||
}),
|
}),
|
||||||
[thickness],
|
[hasEnhancedArmor, equalize],
|
||||||
);
|
);
|
||||||
const outlineMaterial = useMemo(
|
const outlineMaterial = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -126,7 +151,7 @@ export function StaticArmorSceneComponent({
|
|||||||
opacity: 0,
|
opacity: 0,
|
||||||
transparent: true,
|
transparent: true,
|
||||||
}),
|
}),
|
||||||
[thickness],
|
[hasEnhancedArmor, equalize],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -229,7 +254,7 @@ export function StaticArmorSceneComponent({
|
|||||||
return () => {
|
return () => {
|
||||||
unsubscribes.forEach((unsubscribe) => unsubscribe());
|
unsubscribes.forEach((unsubscribe) => unsubscribe());
|
||||||
};
|
};
|
||||||
}, [thickness]);
|
}, [hasEnhancedArmor, equalize]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Box, Flex } from "@radix-ui/themes";
|
|||||||
import { times } from "lodash-es";
|
import { times } from "lodash-es";
|
||||||
import { useEffect, useMemo, useRef } from "react";
|
import { useEffect, useMemo, useRef } from "react";
|
||||||
import { awaitableTankDefinitions } from "../../../core/awaitables/tankDefinitions";
|
import { awaitableTankDefinitions } from "../../../core/awaitables/tankDefinitions";
|
||||||
|
import { defaultEqualizer } from "../../../core/blitzkit/tankToDuelMember";
|
||||||
import { useFullScreen } from "../../../hooks/useFullScreen";
|
import { useFullScreen } from "../../../hooks/useFullScreen";
|
||||||
import { Duel } from "../../../stores/duel";
|
import { Duel } from "../../../stores/duel";
|
||||||
import { Tankopedia } from "../../../stores/tankopedia";
|
import { Tankopedia } from "../../../stores/tankopedia";
|
||||||
@@ -14,7 +15,7 @@ import { Title } from "./components/TankSandbox/Title";
|
|||||||
const tankDefinitions = await awaitableTankDefinitions;
|
const tankDefinitions = await awaitableTankDefinitions;
|
||||||
|
|
||||||
export function HeroSection({ skeleton }: MaybeSkeletonComponentProps) {
|
export function HeroSection({ skeleton }: MaybeSkeletonComponentProps) {
|
||||||
const revealed = Tankopedia.use((state) => state.revealed);
|
const equalize = Duel.use((state) => state.equalize);
|
||||||
const disturbed = Tankopedia.use((state) => state.disturbed);
|
const disturbed = Tankopedia.use((state) => state.disturbed);
|
||||||
const canvas = useRef<HTMLCanvasElement>(null!);
|
const canvas = useRef<HTMLCanvasElement>(null!);
|
||||||
const isFullScreen = useFullScreen();
|
const isFullScreen = useFullScreen();
|
||||||
@@ -28,14 +29,16 @@ export function HeroSection({ skeleton }: MaybeSkeletonComponentProps) {
|
|||||||
(filtered.reduce((accumulator, thisTank) => {
|
(filtered.reduce((accumulator, thisTank) => {
|
||||||
return (
|
return (
|
||||||
accumulator +
|
accumulator +
|
||||||
thisTank.turrets.at(-1)!.guns.at(-1)!.shells[0].penetration!.near
|
thisTank.turrets.at(-1)!.guns.at(-1)!.shells[0].penetration!.near *
|
||||||
|
((equalize ? thisTank.equalizer : undefined) ?? defaultEqualizer)
|
||||||
|
.penetration
|
||||||
);
|
);
|
||||||
}, 0) /
|
}, 0) /
|
||||||
filtered.length) *
|
filtered.length) *
|
||||||
(3 / 4);
|
(3 / 4);
|
||||||
|
|
||||||
return { value } satisfies ThicknessRange;
|
return { value } satisfies ThicknessRange;
|
||||||
}, [protagonist]);
|
}, [protagonist, equalize]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (disturbed) {
|
if (disturbed) {
|
||||||
|
|||||||
Reference in new issue
Block a user