mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: remove controls
This commit is contained in:
1 parent
f15bee34fb
commit
ff66d99fc6
4 files changed
+45
-59
No files matched your search
Binary file not shown.
@@ -586,7 +586,8 @@ if (allTargets || targets?.includes('tankModels')) {
|
|||||||
const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1;
|
const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1;
|
||||||
|
|
||||||
// if (id !== 15697) continue; // chieftain TODO: investigate vertices stream over read
|
// if (id !== 15697) continue; // chieftain TODO: investigate vertices stream over read
|
||||||
if (id !== 24609) continue; // concept 1b
|
// if (id !== 24609) continue; // concept 1b
|
||||||
|
if (id !== 7425) continue; // isu 152
|
||||||
// if (id !== 4417) continue; // amx m4 mle
|
// if (id !== 4417) continue; // amx m4 mle
|
||||||
// if (id !== 7297) continue; // 60tp
|
// if (id !== 7297) continue; // 60tp
|
||||||
// if (id !== 1) continue; // t-34
|
// if (id !== 1) continue; // t-34
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
import { OrbitControls } from '@react-three/drei';
|
|
||||||
import { useThree } from '@react-three/fiber';
|
|
||||||
import { RefObject, memo, useEffect, useRef } from 'react';
|
|
||||||
import { Box3, Group, Vector3 } from 'three';
|
|
||||||
import { OrbitControls as OrbitControlsImpl } from 'three-stdlib';
|
|
||||||
|
|
||||||
interface TankAlignmentProps {
|
|
||||||
model: RefObject<Group>;
|
|
||||||
orbit: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const TankAlignment = memo(
|
|
||||||
({ model, orbit }: TankAlignmentProps) => {
|
|
||||||
const controls = useRef<OrbitControlsImpl>(null);
|
|
||||||
const camera = useThree((state) => state.camera);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const box = new Box3().setFromObject(model.current!);
|
|
||||||
controls.current?.target.set(0, (2 * box.min.y + box.max.y) / 3, 0);
|
|
||||||
camera.position.set(-5, (box.min.y + box.max.y) / 2, -15);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<OrbitControls
|
|
||||||
ref={controls}
|
|
||||||
enabled={orbit}
|
|
||||||
target={new Vector3(0, 2, 0)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
() => false,
|
|
||||||
);
|
|
||||||
@@ -40,7 +40,6 @@ import {
|
|||||||
} from '../../../../core/blitzkrieg/tankDefinitions';
|
} from '../../../../core/blitzkrieg/tankDefinitions';
|
||||||
import { normalizeAnglePI } from '../../../../core/math/normalizeAngle180';
|
import { normalizeAnglePI } from '../../../../core/math/normalizeAngle180';
|
||||||
import * as styles from '../page.css';
|
import * as styles from '../page.css';
|
||||||
import { TankAlignment } from './components/TankAlignment';
|
|
||||||
|
|
||||||
const X_AXIS = new Vector3(1, 0, 0);
|
const X_AXIS = new Vector3(1, 0, 0);
|
||||||
|
|
||||||
@@ -82,7 +81,6 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
const [turretYaw, setTurretYaw] = useState(0);
|
const [turretYaw, setTurretYaw] = useState(0);
|
||||||
const [hullYaw, setHullYaw] = useState(0);
|
const [hullYaw, setHullYaw] = useState(0);
|
||||||
const [gunPitch, setGunPitch] = useState(0);
|
const [gunPitch, setGunPitch] = useState(0);
|
||||||
const [orbitControlsEnabled, setOrbitControlsEnabled] = useState(true);
|
|
||||||
const turretYawInput = useRef<HTMLInputElement>(null);
|
const turretYawInput = useRef<HTMLInputElement>(null);
|
||||||
const hullYawInput = useRef<HTMLInputElement>(null);
|
const hullYawInput = useRef<HTMLInputElement>(null);
|
||||||
const gunPitchInput = useRef<HTMLInputElement>(null);
|
const gunPitchInput = useRef<HTMLInputElement>(null);
|
||||||
@@ -146,17 +144,7 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
</Tabs.Root>
|
</Tabs.Root>
|
||||||
|
|
||||||
<div style={{ height: '50vh', maxHeight: 576 }}>
|
<div style={{ height: '50vh', maxHeight: 576 }}>
|
||||||
<Canvas
|
<Canvas shadows ref={canvas} camera={{ fov: 20 }}>
|
||||||
shadows
|
|
||||||
ref={canvas}
|
|
||||||
onPointerDown={(event) => event.preventDefault()}
|
|
||||||
camera={{ fov: 20 }}
|
|
||||||
>
|
|
||||||
<TankAlignment
|
|
||||||
model={hullContainer}
|
|
||||||
orbit={orbitControlsEnabled}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<InfiniteGridHelper
|
<InfiniteGridHelper
|
||||||
size1={1 / 5}
|
size1={1 / 5}
|
||||||
size2={1}
|
size2={1}
|
||||||
@@ -200,7 +188,6 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
) {
|
) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
draftHullYaw = hullYaw;
|
draftHullYaw = hullYaw;
|
||||||
setOrbitControlsEnabled(false);
|
|
||||||
window.addEventListener(
|
window.addEventListener(
|
||||||
'pointermove',
|
'pointermove',
|
||||||
handlePointerMove,
|
handlePointerMove,
|
||||||
@@ -217,7 +204,6 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function handlePointerUp() {
|
function handlePointerUp() {
|
||||||
setOrbitControlsEnabled(true);
|
|
||||||
setHullYaw(normalizeAnglePI(draftHullYaw));
|
setHullYaw(normalizeAnglePI(draftHullYaw));
|
||||||
window.removeEventListener(
|
window.removeEventListener(
|
||||||
'pointermove',
|
'pointermove',
|
||||||
@@ -270,7 +256,6 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
if (isTurret) {
|
if (isTurret) {
|
||||||
draftTurretYaw = turretYaw;
|
draftTurretYaw = turretYaw;
|
||||||
setOrbitControlsEnabled(false);
|
|
||||||
window.addEventListener(
|
window.addEventListener(
|
||||||
'pointermove',
|
'pointermove',
|
||||||
handlePointerMove,
|
handlePointerMove,
|
||||||
@@ -299,7 +284,6 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function handlePointerUp() {
|
function handlePointerUp() {
|
||||||
setOrbitControlsEnabled(true);
|
|
||||||
setTurretYaw(normalizeAnglePI(draftTurretYaw));
|
setTurretYaw(normalizeAnglePI(draftTurretYaw));
|
||||||
window.removeEventListener(
|
window.removeEventListener(
|
||||||
'pointermove',
|
'pointermove',
|
||||||
@@ -340,21 +324,26 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
ref={gunContainer}
|
ref={gunContainer}
|
||||||
>
|
>
|
||||||
{gltf.scene.children[0].children.map((child) => {
|
{gltf.scene.children[0].children.map((child) => {
|
||||||
const isGun =
|
const isCurrentMantlet =
|
||||||
child.name.startsWith('gun_') &&
|
child.name ===
|
||||||
!child.name.endsWith('_mask');
|
`gun_${gunModelDefinition.model
|
||||||
const isMantlet =
|
.toString()
|
||||||
child.name.startsWith('gun_') &&
|
.padStart(2, '0')}_mask`;
|
||||||
child.name.endsWith('_mask');
|
const isCurrentGun =
|
||||||
const isVisible = isGun || isMantlet;
|
child.name ===
|
||||||
|
`gun_${gunModelDefinition.model
|
||||||
|
.toString()
|
||||||
|
.padStart(2, '0')}`;
|
||||||
|
const isVisible = isCurrentGun || isCurrentMantlet;
|
||||||
let draftMantletPitch = 0;
|
let draftMantletPitch = 0;
|
||||||
|
let draftTurretYaw = 0;
|
||||||
|
|
||||||
function handlePointerDown(
|
function handlePointerDown(
|
||||||
event: ThreeEvent<PointerEvent>,
|
event: ThreeEvent<PointerEvent>,
|
||||||
) {
|
) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
draftMantletPitch = gunPitch;
|
draftMantletPitch = gunPitch;
|
||||||
setOrbitControlsEnabled(false);
|
draftTurretYaw = turretYaw;
|
||||||
window.addEventListener(
|
window.addEventListener(
|
||||||
'pointermove',
|
'pointermove',
|
||||||
handlePointerMove,
|
handlePointerMove,
|
||||||
@@ -365,6 +354,21 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
function handlePointerMove(event: PointerEvent) {
|
function handlePointerMove(event: PointerEvent) {
|
||||||
|
if (turretModelDefinition.yaw) {
|
||||||
|
draftTurretYaw = clamp(
|
||||||
|
draftTurretYaw +
|
||||||
|
event.movementX *
|
||||||
|
(Math.PI / canvas.current!.width),
|
||||||
|
-turretModelDefinition.yaw.max *
|
||||||
|
(Math.PI / 180),
|
||||||
|
-turretModelDefinition.yaw.min *
|
||||||
|
(Math.PI / 180),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
draftTurretYaw +=
|
||||||
|
event.movementX *
|
||||||
|
((2 * Math.PI) / canvas.current!.width);
|
||||||
|
}
|
||||||
draftMantletPitch = clamp(
|
draftMantletPitch = clamp(
|
||||||
draftMantletPitch -
|
draftMantletPitch -
|
||||||
event.movementY *
|
event.movementY *
|
||||||
@@ -387,10 +391,23 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
gunContainer.current.rotation.x =
|
gunContainer.current.rotation.x =
|
||||||
draftMantletPitch;
|
draftMantletPitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (turretContainer.current) {
|
||||||
|
turretContainer.current.position
|
||||||
|
.set(0, 0, 0)
|
||||||
|
.sub(turretOrigin)
|
||||||
|
.applyAxisAngle(
|
||||||
|
new Vector3(0, 0, 1),
|
||||||
|
draftTurretYaw,
|
||||||
|
)
|
||||||
|
.add(turretOrigin);
|
||||||
|
turretContainer.current.rotation.z =
|
||||||
|
draftTurretYaw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function handlePointerUp() {
|
function handlePointerUp() {
|
||||||
setOrbitControlsEnabled(true);
|
|
||||||
setGunPitch(normalizeAnglePI(draftMantletPitch));
|
setGunPitch(normalizeAnglePI(draftMantletPitch));
|
||||||
|
setTurretYaw(normalizeAnglePI(draftTurretYaw));
|
||||||
window.removeEventListener(
|
window.removeEventListener(
|
||||||
'pointermove',
|
'pointermove',
|
||||||
handlePointerMove,
|
handlePointerMove,
|
||||||
|
|||||||
Reference in new issue
Block a user