mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
fix: static armor show on deselect
This commit is contained in:
1 parent
10d7fe1e75
commit
102072746a
1 file changed
+9
-8
@@ -1,5 +1,5 @@
|
|||||||
import { I_HAT, J_HAT } from "@blitzkit/core";
|
import { I_HAT, J_HAT } from "@blitzkit/core";
|
||||||
import { useThree } from "@react-three/fiber";
|
import { invalidate, useThree } from "@react-three/fiber";
|
||||||
import { clamp } from "lodash-es";
|
import { clamp } from "lodash-es";
|
||||||
import type { QuicklimeEvent } from "quicklime";
|
import type { QuicklimeEvent } from "quicklime";
|
||||||
import { useEffect, useMemo, type ComponentProps } from "react";
|
import { useEffect, useMemo, type ComponentProps } from "react";
|
||||||
@@ -91,7 +91,7 @@ export function StaticArmorSceneComponent({
|
|||||||
color = new Color(
|
color = 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);
|
opacity = clamp(x + 1 / 2, 0, 1);
|
||||||
break;
|
break;
|
||||||
@@ -115,7 +115,7 @@ export function StaticArmorSceneComponent({
|
|||||||
opacity: 0,
|
opacity: 0,
|
||||||
userData: { opacity0: opacity },
|
userData: { opacity0: opacity },
|
||||||
}),
|
}),
|
||||||
[thickness]
|
[thickness],
|
||||||
);
|
);
|
||||||
const outlineMaterial = useMemo(
|
const outlineMaterial = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -126,7 +126,7 @@ export function StaticArmorSceneComponent({
|
|||||||
opacity: 0,
|
opacity: 0,
|
||||||
transparent: true,
|
transparent: true,
|
||||||
}),
|
}),
|
||||||
[thickness]
|
[thickness],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -165,6 +165,7 @@ export function StaticArmorSceneComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
surfaceMaterial.needsUpdate = true;
|
surfaceMaterial.needsUpdate = true;
|
||||||
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleTransitionEvent(event: QuicklimeEvent<number>) {
|
function handleTransitionEvent(event: QuicklimeEvent<number>) {
|
||||||
@@ -180,7 +181,7 @@ export function StaticArmorSceneComponent({
|
|||||||
const unsubscribes = [
|
const unsubscribes = [
|
||||||
Tankopedia.on(
|
Tankopedia.on(
|
||||||
(state) => state.highlightArmor?.name,
|
(state) => state.highlightArmor?.name,
|
||||||
handleHighlightArmor
|
handleHighlightArmor,
|
||||||
),
|
),
|
||||||
() => transitionEvent.off(handleTransitionEvent),
|
() => transitionEvent.off(handleTransitionEvent),
|
||||||
];
|
];
|
||||||
@@ -194,14 +195,14 @@ export function StaticArmorSceneComponent({
|
|||||||
const { clip } = props;
|
const { clip } = props;
|
||||||
const gunOrigin = unrotateDavaVector(props.gunOrigin.clone());
|
const gunOrigin = unrotateDavaVector(props.gunOrigin.clone());
|
||||||
const neckOrigin = unrotateDavaVector(props.hullOrigin.clone()).add(
|
const neckOrigin = unrotateDavaVector(props.hullOrigin.clone()).add(
|
||||||
unrotateDavaVector(props.turretOrigin.clone())
|
unrotateDavaVector(props.turretOrigin.clone()),
|
||||||
);
|
);
|
||||||
const barrelOrigin = neckOrigin.clone().add(gunOrigin);
|
const barrelOrigin = neckOrigin.clone().add(gunOrigin);
|
||||||
const distanceToBarrel = clip.distanceToPoint(barrelOrigin);
|
const distanceToBarrel = clip.distanceToPoint(barrelOrigin);
|
||||||
const point = new Vector3();
|
const point = new Vector3();
|
||||||
|
|
||||||
function handleModelTransform(
|
function handleModelTransform(
|
||||||
event: QuicklimeEvent<ModelTransformEventData>
|
event: QuicklimeEvent<ModelTransformEventData>,
|
||||||
) {
|
) {
|
||||||
clip.normal
|
clip.normal
|
||||||
.set(0, 0, -1)
|
.set(0, 0, -1)
|
||||||
@@ -266,7 +267,7 @@ export function StaticArmorSceneComponent({
|
|||||||
const surfaceNormal = event
|
const surfaceNormal = event
|
||||||
.normal!.clone()
|
.normal!.clone()
|
||||||
.applyQuaternion(
|
.applyQuaternion(
|
||||||
event.object.getWorldQuaternion(new Quaternion())
|
event.object.getWorldQuaternion(new Quaternion()),
|
||||||
);
|
);
|
||||||
const angle = surfaceNormal.angleTo(cameraNormal);
|
const angle = surfaceNormal.angleTo(cameraNormal);
|
||||||
const thicknessAngled =
|
const thicknessAngled =
|
||||||
|
|||||||
Reference in new issue
Block a user