mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
cool
This commit is contained in:
1 parent
5c92f9f7ee
commit
28c30f210e
1 file changed
+209
-254
@@ -14,6 +14,9 @@ import {
|
|||||||
Object3D,
|
Object3D,
|
||||||
Vector2,
|
Vector2,
|
||||||
} from "three";
|
} from "three";
|
||||||
|
import { applyPitchYawLimits } from "../core/blitz/applyPitchYawLimits";
|
||||||
|
import { hasEquipment } from "../core/blitzkit/hasEquipment";
|
||||||
|
import { modelTransformEvent } from "../core/blitzkit/modelTransform";
|
||||||
import { controlsEnabledEvent } from "../core/controlsEnabled";
|
import { controlsEnabledEvent } from "../core/controlsEnabled";
|
||||||
import { useModel } from "../hooks/useModel";
|
import { useModel } from "../hooks/useModel";
|
||||||
import { useTankModelDefinition } from "../hooks/useTankModelDefinition";
|
import { useTankModelDefinition } from "../hooks/useTankModelDefinition";
|
||||||
@@ -25,10 +28,10 @@ import { ModelTankWrapper } from "./Armor/components/ModelTankWrapper";
|
|||||||
|
|
||||||
interface BatchedProps extends ComponentProps<"group"> {
|
interface BatchedProps extends ComponentProps<"group"> {
|
||||||
slicer: (node: Object3D) => boolean;
|
slicer: (node: Object3D) => boolean;
|
||||||
mutator: (mesh: Mesh) => void;
|
mutator?: (mesh: Mesh) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function useBatched(map: ObjectMap) {
|
function useBatched(map: ObjectMap, shadows = false) {
|
||||||
return function Batched({ slicer, mutator, ...props }: BatchedProps) {
|
return function Batched({ slicer, mutator, ...props }: BatchedProps) {
|
||||||
const groups = new Map<MeshStandardMaterial, Mesh[]>();
|
const groups = new Map<MeshStandardMaterial, Mesh[]>();
|
||||||
|
|
||||||
@@ -68,7 +71,13 @@ function useBatched(map: ObjectMap) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (const mesh of meshes) {
|
for (const mesh of meshes) {
|
||||||
mutator(mesh);
|
if (shadows) {
|
||||||
|
mesh.castShadow = true;
|
||||||
|
mesh.receiveShadow = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
mutator?.(mesh);
|
||||||
|
|
||||||
batched.add(mesh);
|
batched.add(mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,39 +96,36 @@ interface SectionProps {
|
|||||||
map: ObjectMap;
|
map: ObjectMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Hull({ map }: SectionProps) {
|
|
||||||
const Batched = useBatched(map);
|
|
||||||
|
|
||||||
function handlePointerDown(event: ThreeEvent<PointerEvent>) {
|
|
||||||
// event.stopPropagation();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Batched
|
|
||||||
onPointerDown={handlePointerDown}
|
|
||||||
slicer={(node) => {
|
|
||||||
const isHull = node.name === "hull";
|
|
||||||
const isWheel = node.name.startsWith("chassis_wheel_");
|
|
||||||
const isTrack = node.name.startsWith("chassis_track_");
|
|
||||||
|
|
||||||
return isHull || isWheel || isTrack;
|
|
||||||
}}
|
|
||||||
mutator={(mesh) => {
|
|
||||||
mesh.castShadow = true;
|
|
||||||
mesh.receiveShadow = true;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function Tracks({ map }: SectionProps) {
|
function Tracks({ map }: SectionProps) {
|
||||||
const Batched = useBatched(map);
|
const Batched = useBatched(map, true);
|
||||||
|
|
||||||
const position = useRef(new Vector2());
|
const position = useRef(new Vector2());
|
||||||
const delta = useRef(new Vector2());
|
const delta = useRef(new Vector2());
|
||||||
|
|
||||||
const textures = useRef(new Set<Texture | null>());
|
const textures = useRef(new Set<Texture | null>());
|
||||||
|
|
||||||
|
function handlePointerMove(event: PointerEvent) {
|
||||||
|
delta.current.set(event.clientX, event.clientY).sub(position.current);
|
||||||
|
position.current.set(event.clientX, event.clientY);
|
||||||
|
|
||||||
|
const deltaX = delta.current.x / window.innerWidth;
|
||||||
|
const deltaY = delta.current.y / window.innerHeight;
|
||||||
|
|
||||||
|
const offset = deltaX + deltaY;
|
||||||
|
|
||||||
|
for (const texture of textures.current) {
|
||||||
|
if (!texture) continue;
|
||||||
|
texture.offset.y += offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
function handlePointerUp() {
|
||||||
|
controlsEnabledEvent.dispatch(true);
|
||||||
|
|
||||||
|
window.removeEventListener("pointermove", handlePointerMove);
|
||||||
|
window.removeEventListener("pointerup", handlePointerUp);
|
||||||
|
}
|
||||||
function handlePointerDown(event: ThreeEvent<PointerEvent>) {
|
function handlePointerDown(event: ThreeEvent<PointerEvent>) {
|
||||||
if (Tankopedia.state.display !== TankopediaDisplay.Model) {
|
if (Tankopedia.state.display !== TankopediaDisplay.Model) {
|
||||||
return;
|
return;
|
||||||
@@ -143,27 +149,22 @@ function Tracks({ map }: SectionProps) {
|
|||||||
window.addEventListener("pointermove", handlePointerMove);
|
window.addEventListener("pointermove", handlePointerMove);
|
||||||
window.addEventListener("pointerup", handlePointerUp);
|
window.addEventListener("pointerup", handlePointerUp);
|
||||||
}
|
}
|
||||||
function handlePointerMove(event: PointerEvent) {
|
|
||||||
delta.current.set(event.clientX, event.clientY).sub(position.current);
|
|
||||||
position.current.set(event.clientX, event.clientY);
|
|
||||||
|
|
||||||
const deltaX = delta.current.x / window.innerWidth;
|
return (
|
||||||
const deltaY = delta.current.y / window.innerHeight;
|
<Batched
|
||||||
|
onPointerDown={handlePointerDown}
|
||||||
const offset = deltaX + deltaY;
|
slicer={(node) => {
|
||||||
|
return node.name.startsWith("chassis_track_");
|
||||||
for (const texture of textures.current) {
|
}}
|
||||||
if (!texture) continue;
|
/>
|
||||||
texture.offset.y += offset;
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidate();
|
function Hull({ map }: SectionProps) {
|
||||||
}
|
const Batched = useBatched(map, true);
|
||||||
function handlePointerUp() {
|
|
||||||
controlsEnabledEvent.dispatch(true);
|
|
||||||
|
|
||||||
window.removeEventListener("pointermove", handlePointerMove);
|
function handlePointerDown(event: ThreeEvent<PointerEvent>) {
|
||||||
window.removeEventListener("pointerup", handlePointerUp);
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -172,13 +173,166 @@ function Tracks({ map }: SectionProps) {
|
|||||||
slicer={(node) => {
|
slicer={(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_");
|
||||||
const isTrack = node.name.startsWith("chassis_track_");
|
|
||||||
|
|
||||||
return isHull || isWheel || isTrack;
|
return isHull || isWheel;
|
||||||
}}
|
}}
|
||||||
mutator={(mesh) => {
|
/>
|
||||||
mesh.castShadow = true;
|
);
|
||||||
mesh.receiveShadow = true;
|
}
|
||||||
|
|
||||||
|
function Turret({ map }: SectionProps) {
|
||||||
|
const turret = Duel.use((state) => state.protagonist.turret);
|
||||||
|
const gun = Duel.use((state) => state.protagonist.gun);
|
||||||
|
|
||||||
|
const tankModelDefinition = useTankModelDefinition();
|
||||||
|
const turretModelDefinition = tankModelDefinition.turrets[turret.id];
|
||||||
|
const gunModelDefinition = turretModelDefinition.guns[gun.id];
|
||||||
|
|
||||||
|
const Batched = useBatched(map, true);
|
||||||
|
|
||||||
|
const position = useRef(new Vector2());
|
||||||
|
const delta = useRef(new Vector2());
|
||||||
|
|
||||||
|
const canvas = useThree((state) => state.gl.domElement);
|
||||||
|
|
||||||
|
function onPointerDown(event: ThreeEvent<PointerEvent>) {
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
position.current.set(event.clientX, event.clientY);
|
||||||
|
|
||||||
|
controlsEnabledEvent.dispatch(false);
|
||||||
|
Tankopedia.mutate((draft) => {
|
||||||
|
draft.shot = undefined;
|
||||||
|
draft.highlightArmor = undefined;
|
||||||
|
});
|
||||||
|
window.addEventListener("pointermove", handlePointerMove);
|
||||||
|
window.addEventListener("pointerup", handlePointerUp);
|
||||||
|
}
|
||||||
|
function handlePointerMove(event: PointerEvent) {
|
||||||
|
const hasImprovedVerticalStabilizer = hasEquipment(
|
||||||
|
122,
|
||||||
|
Duel.state.protagonist.tank.equipment_preset,
|
||||||
|
Duel.state.protagonist.equipmentMatrix,
|
||||||
|
);
|
||||||
|
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
||||||
|
124,
|
||||||
|
Duel.state.protagonist.tank.equipment_preset,
|
||||||
|
Duel.state.protagonist.equipmentMatrix,
|
||||||
|
);
|
||||||
|
const boundingRect = canvas.getBoundingClientRect();
|
||||||
|
|
||||||
|
delta.current.set(event.clientX, event.clientY).sub(position.current);
|
||||||
|
position.current.set(event.clientX, event.clientY);
|
||||||
|
|
||||||
|
const [pitch, yaw] = applyPitchYawLimits(
|
||||||
|
modelTransformEvent.last!.pitch,
|
||||||
|
modelTransformEvent.last!.yaw +
|
||||||
|
delta.current.x * (Math.PI / boundingRect.width),
|
||||||
|
gunModelDefinition.pitch!,
|
||||||
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
|
hasDownImprovedVerticalStabilizer,
|
||||||
|
);
|
||||||
|
modelTransformEvent.dispatch({ pitch, yaw });
|
||||||
|
}
|
||||||
|
function handlePointerUp() {
|
||||||
|
controlsEnabledEvent.dispatch(true);
|
||||||
|
window.removeEventListener("pointermove", handlePointerMove);
|
||||||
|
window.removeEventListener("pointerup", handlePointerUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Batched
|
||||||
|
onPointerDown={onPointerDown}
|
||||||
|
slicer={(node) => {
|
||||||
|
const isCurrentTurret =
|
||||||
|
node.name ===
|
||||||
|
`turret_${turretModelDefinition.model_id
|
||||||
|
.toString()
|
||||||
|
.padStart(2, "0")}`;
|
||||||
|
|
||||||
|
return isCurrentTurret;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Gun({ map }: SectionProps) {
|
||||||
|
const Batched = useBatched(map, true);
|
||||||
|
|
||||||
|
const turret = Duel.use((state) => state.protagonist.turret);
|
||||||
|
const gun = Duel.use((state) => state.protagonist.gun);
|
||||||
|
|
||||||
|
const tankModelDefinition = useTankModelDefinition();
|
||||||
|
const turretModelDefinition = tankModelDefinition.turrets[turret.id];
|
||||||
|
const gunModelDefinition = turretModelDefinition.guns[gun.id];
|
||||||
|
|
||||||
|
const position = useRef(new Vector2());
|
||||||
|
const delta = useRef(new Vector2());
|
||||||
|
const pitch = useRef(0);
|
||||||
|
const yaw = useRef(0);
|
||||||
|
|
||||||
|
const canvas = useThree((state) => state.gl.domElement);
|
||||||
|
|
||||||
|
function handlePointerMove(event: PointerEvent) {
|
||||||
|
const hasImprovedVerticalStabilizer = hasEquipment(
|
||||||
|
122,
|
||||||
|
Duel.state.protagonist.tank.equipment_preset,
|
||||||
|
Duel.state.protagonist.equipmentMatrix,
|
||||||
|
);
|
||||||
|
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
||||||
|
124,
|
||||||
|
Duel.state.protagonist.tank.equipment_preset,
|
||||||
|
Duel.state.protagonist.equipmentMatrix,
|
||||||
|
);
|
||||||
|
const boundingRect = canvas.getBoundingClientRect();
|
||||||
|
delta.current.set(event.clientX, event.clientY).sub(position.current);
|
||||||
|
position.current.set(event.clientX, event.clientY);
|
||||||
|
|
||||||
|
[pitch.current, yaw.current] = applyPitchYawLimits(
|
||||||
|
pitch.current - delta.current.y * (Math.PI / boundingRect.height),
|
||||||
|
yaw.current + delta.current.x * (Math.PI / boundingRect.width),
|
||||||
|
gunModelDefinition.pitch!,
|
||||||
|
turretModelDefinition.yaw,
|
||||||
|
hasImprovedVerticalStabilizer,
|
||||||
|
hasDownImprovedVerticalStabilizer,
|
||||||
|
);
|
||||||
|
modelTransformEvent.dispatch({ pitch: pitch.current, yaw: yaw.current });
|
||||||
|
}
|
||||||
|
function handlePointerUp() {
|
||||||
|
controlsEnabledEvent.dispatch(true);
|
||||||
|
window.removeEventListener("pointermove", handlePointerMove);
|
||||||
|
window.removeEventListener("pointerup", handlePointerUp);
|
||||||
|
}
|
||||||
|
function onPointerDown(event: ThreeEvent<PointerEvent>) {
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
controlsEnabledEvent.dispatch(false);
|
||||||
|
Tankopedia.mutate((draft) => {
|
||||||
|
draft.shot = undefined;
|
||||||
|
draft.highlightArmor = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
position.current.set(event.clientX, event.clientY);
|
||||||
|
pitch.current = modelTransformEvent.last!.pitch;
|
||||||
|
yaw.current = modelTransformEvent.last!.yaw;
|
||||||
|
|
||||||
|
window.addEventListener("pointermove", handlePointerMove);
|
||||||
|
window.addEventListener("pointerup", handlePointerUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Batched
|
||||||
|
onPointerDown={onPointerDown}
|
||||||
|
slicer={(node) => {
|
||||||
|
const isCurrentMantlet =
|
||||||
|
node.name ===
|
||||||
|
`gun_${gunModelDefinition.model_id.toString().padStart(2, "0")}_mask`;
|
||||||
|
const isCurrentGun =
|
||||||
|
node.name ===
|
||||||
|
`gun_${gunModelDefinition.model_id.toString().padStart(2, "0")}`;
|
||||||
|
|
||||||
|
return isCurrentGun || isCurrentMantlet;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -195,7 +349,6 @@ export function TankModel() {
|
|||||||
const tankModelDefinition = useTankModelDefinition();
|
const tankModelDefinition = useTankModelDefinition();
|
||||||
const turretModelDefinition =
|
const turretModelDefinition =
|
||||||
tankModelDefinition.turrets[protagonist.turret.id];
|
tankModelDefinition.turrets[protagonist.turret.id];
|
||||||
const gunModelDefinition = turretModelDefinition.guns[protagonist.gun.id];
|
|
||||||
|
|
||||||
const { gltf } = useModel(protagonist.tank.id);
|
const { gltf } = useModel(protagonist.tank.id);
|
||||||
|
|
||||||
@@ -203,214 +356,16 @@ export function TankModel() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ModelTankWrapper ref={hullContainer}>
|
<ModelTankWrapper ref={hullContainer}>
|
||||||
<Hull map={gltf} />
|
|
||||||
<Tracks map={gltf} />
|
<Tracks map={gltf} />
|
||||||
|
<Hull map={gltf} />
|
||||||
{/* {nodes.map((node) => {
|
|
||||||
const isHull = node.name === "hull";
|
|
||||||
const isWheel = node.name.startsWith("chassis_wheel_");
|
|
||||||
const isTrack = node.name.startsWith("chassis_track_");
|
|
||||||
const isVisible = isHull || isWheel || isTrack;
|
|
||||||
const position = new Vector2();
|
|
||||||
const delta = new Vector2();
|
|
||||||
|
|
||||||
if (!isVisible) return null;
|
|
||||||
|
|
||||||
function translateTexture(offset: number) {
|
|
||||||
const mesh = node.children[0] as Mesh;
|
|
||||||
const material = mesh?.material as MeshStandardMaterial;
|
|
||||||
|
|
||||||
if (!material) return;
|
|
||||||
|
|
||||||
invalidate();
|
|
||||||
|
|
||||||
const textures = new Set([
|
|
||||||
material.map,
|
|
||||||
material.aoMap,
|
|
||||||
material.normalMap,
|
|
||||||
material.roughnessMap,
|
|
||||||
material.metalnessMap,
|
|
||||||
]);
|
|
||||||
|
|
||||||
for (const texture of textures) {
|
|
||||||
if (texture) texture.offset.y += offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return jsxTree(node, {
|
|
||||||
mesh(_, props, key) {
|
|
||||||
return (
|
|
||||||
<mesh
|
|
||||||
{...props}
|
|
||||||
key={key}
|
|
||||||
onPointerDown={onPointerDown}
|
|
||||||
castShadow
|
|
||||||
receiveShadow
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})}
|
|
||||||
|
|
||||||
<group ref={turretContainer}>
|
<group ref={turretContainer}>
|
||||||
{nodes.map((node) => {
|
<Turret map={gltf} />
|
||||||
const isTurret = node.name.startsWith("turret_");
|
|
||||||
const isCurrentTurret =
|
|
||||||
node.name ===
|
|
||||||
`turret_${turretModelDefinition.model_id
|
|
||||||
.toString()
|
|
||||||
.padStart(2, "0")}`;
|
|
||||||
const isVisible = isCurrentTurret;
|
|
||||||
const position = new Vector2();
|
|
||||||
const delta = new Vector2();
|
|
||||||
|
|
||||||
if (!isVisible) return null;
|
|
||||||
|
|
||||||
function onPointerDown(event: ThreeEvent<PointerEvent>) {
|
|
||||||
event.stopPropagation();
|
|
||||||
|
|
||||||
if (!isTurret) return;
|
|
||||||
|
|
||||||
position.set(event.clientX, event.clientY);
|
|
||||||
|
|
||||||
controlsEnabledEvent.dispatch(false);
|
|
||||||
Tankopedia.mutate((draft) => {
|
|
||||||
draft.shot = undefined;
|
|
||||||
draft.highlightArmor = undefined;
|
|
||||||
});
|
|
||||||
window.addEventListener("pointermove", handlePointerMove);
|
|
||||||
window.addEventListener("pointerup", handlePointerUp);
|
|
||||||
}
|
|
||||||
function handlePointerMove(event: PointerEvent) {
|
|
||||||
const hasImprovedVerticalStabilizer = hasEquipment(
|
|
||||||
122,
|
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
|
||||||
);
|
|
||||||
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
|
||||||
124,
|
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
|
||||||
);
|
|
||||||
const boundingRect = canvas.getBoundingClientRect();
|
|
||||||
|
|
||||||
delta.set(event.clientX, event.clientY).sub(position);
|
|
||||||
position.set(event.clientX, event.clientY);
|
|
||||||
|
|
||||||
const [pitch, yaw] = applyPitchYawLimits(
|
|
||||||
modelTransformEvent.last!.pitch,
|
|
||||||
modelTransformEvent.last!.yaw +
|
|
||||||
delta.x * (Math.PI / boundingRect.width),
|
|
||||||
gunModelDefinition.pitch!,
|
|
||||||
turretModelDefinition.yaw,
|
|
||||||
hasImprovedVerticalStabilizer,
|
|
||||||
hasDownImprovedVerticalStabilizer,
|
|
||||||
);
|
|
||||||
modelTransformEvent.dispatch({ pitch, yaw });
|
|
||||||
}
|
|
||||||
function handlePointerUp() {
|
|
||||||
controlsEnabledEvent.dispatch(true);
|
|
||||||
window.removeEventListener("pointermove", handlePointerMove);
|
|
||||||
window.removeEventListener("pointerup", handlePointerUp);
|
|
||||||
}
|
|
||||||
|
|
||||||
return jsxTree(node, {
|
|
||||||
mesh(_, props, key) {
|
|
||||||
return (
|
|
||||||
<mesh
|
|
||||||
{...props}
|
|
||||||
key={key}
|
|
||||||
onPointerDown={onPointerDown}
|
|
||||||
castShadow
|
|
||||||
receiveShadow
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})}
|
|
||||||
|
|
||||||
<group ref={gunContainer}>
|
<group ref={gunContainer}>
|
||||||
{nodes.map((node) => {
|
<Gun map={gltf} />
|
||||||
const isCurrentMantlet =
|
</group>
|
||||||
node.name ===
|
|
||||||
`gun_${gunModelDefinition.model_id
|
|
||||||
.toString()
|
|
||||||
.padStart(2, "0")}_mask`;
|
|
||||||
const isCurrentGun =
|
|
||||||
node.name ===
|
|
||||||
`gun_${gunModelDefinition.model_id.toString().padStart(2, "0")}`;
|
|
||||||
const isVisible = isCurrentGun || isCurrentMantlet;
|
|
||||||
const position = new Vector2();
|
|
||||||
const delta = new Vector2();
|
|
||||||
|
|
||||||
if (!isVisible) return null;
|
|
||||||
|
|
||||||
let pitch = 0;
|
|
||||||
let yaw = 0;
|
|
||||||
|
|
||||||
function onPointerDown(event: ThreeEvent<PointerEvent>) {
|
|
||||||
event.stopPropagation();
|
|
||||||
|
|
||||||
controlsEnabledEvent.dispatch(false);
|
|
||||||
Tankopedia.mutate((draft) => {
|
|
||||||
draft.shot = undefined;
|
|
||||||
draft.highlightArmor = undefined;
|
|
||||||
});
|
|
||||||
|
|
||||||
position.set(event.clientX, event.clientY);
|
|
||||||
pitch = modelTransformEvent.last!.pitch;
|
|
||||||
yaw = modelTransformEvent.last!.yaw;
|
|
||||||
|
|
||||||
window.addEventListener("pointermove", handlePointerMove);
|
|
||||||
window.addEventListener("pointerup", handlePointerUp);
|
|
||||||
}
|
|
||||||
function handlePointerMove(event: PointerEvent) {
|
|
||||||
const hasImprovedVerticalStabilizer = hasEquipment(
|
|
||||||
122,
|
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
|
||||||
);
|
|
||||||
const hasDownImprovedVerticalStabilizer = hasEquipment(
|
|
||||||
124,
|
|
||||||
Duel.state.protagonist.tank.equipment_preset,
|
|
||||||
Duel.state.protagonist.equipmentMatrix,
|
|
||||||
);
|
|
||||||
const boundingRect = canvas.getBoundingClientRect();
|
|
||||||
delta.set(event.clientX, event.clientY).sub(position);
|
|
||||||
position.set(event.clientX, event.clientY);
|
|
||||||
|
|
||||||
[pitch, yaw] = applyPitchYawLimits(
|
|
||||||
pitch - delta.y * (Math.PI / boundingRect.height),
|
|
||||||
yaw + delta.x * (Math.PI / boundingRect.width),
|
|
||||||
gunModelDefinition.pitch!,
|
|
||||||
turretModelDefinition.yaw,
|
|
||||||
hasImprovedVerticalStabilizer,
|
|
||||||
hasDownImprovedVerticalStabilizer,
|
|
||||||
);
|
|
||||||
modelTransformEvent.dispatch({ pitch, yaw });
|
|
||||||
}
|
|
||||||
function handlePointerUp() {
|
|
||||||
controlsEnabledEvent.dispatch(true);
|
|
||||||
window.removeEventListener("pointermove", handlePointerMove);
|
|
||||||
window.removeEventListener("pointerup", handlePointerUp);
|
|
||||||
}
|
|
||||||
|
|
||||||
return jsxTree(node, {
|
|
||||||
mesh(_, props, key) {
|
|
||||||
return (
|
|
||||||
<mesh
|
|
||||||
{...props}
|
|
||||||
key={key}
|
|
||||||
onPointerDown={onPointerDown}
|
|
||||||
castShadow
|
|
||||||
receiveShadow
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})}
|
|
||||||
</group>
|
</group>
|
||||||
</group> */}
|
|
||||||
</ModelTankWrapper>
|
</ModelTankWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user