mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
feat: simpler turret rotation
This commit is contained in:
1 parent
88cc37a6af
commit
e65582a432
2 files changed
+12
-67
No files matched your search
Vendored
+1
@@ -26,6 +26,7 @@
|
|||||||
"deburr",
|
"deburr",
|
||||||
"decalmask",
|
"decalmask",
|
||||||
"diacriticless",
|
"diacriticless",
|
||||||
|
"drei",
|
||||||
"dvpl",
|
"dvpl",
|
||||||
"DVPLCRC",
|
"DVPLCRC",
|
||||||
"dxgi",
|
"dxgi",
|
||||||
|
|||||||
@@ -62,9 +62,6 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
const [versusTurret, setVersusTurret] = useState(versusTank.turrets.at(-1)!);
|
const [versusTurret, setVersusTurret] = useState(versusTank.turrets.at(-1)!);
|
||||||
const [versusGun, setVersusGun] = useState(versusTurret.guns.at(-1)!);
|
const [versusGun, setVersusGun] = useState(versusTurret.guns.at(-1)!);
|
||||||
const [versusTankTab, setVersusTankTab] = useState('search');
|
const [versusTankTab, setVersusTankTab] = useState('search');
|
||||||
const turretObject3D = useRef<Mesh>(null);
|
|
||||||
const mantletObject3D = useRef<Mesh>(null);
|
|
||||||
const gunObject3D = useRef<Mesh>(null);
|
|
||||||
const canvas = useRef<HTMLCanvasElement>(null);
|
const canvas = useRef<HTMLCanvasElement>(null);
|
||||||
const gltf = useLoader(GLTFLoader, '/test/5137.glb');
|
const gltf = useLoader(GLTFLoader, '/test/5137.glb');
|
||||||
const turretOrigin = new Vector3(
|
const turretOrigin = new Vector3(
|
||||||
@@ -163,7 +160,7 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
|
|
||||||
<group
|
<group
|
||||||
ref={hullContainer}
|
ref={hullContainer}
|
||||||
rotation={[-Math.PI / 2, 0, hullRotation]}
|
rotation={[0 /*-Math.PI / 2*/, 0, hullRotation]}
|
||||||
>
|
>
|
||||||
{gltf.scene.children[0].children.map((child) => {
|
{gltf.scene.children[0].children.map((child) => {
|
||||||
const isHull = child.name === 'hull';
|
const isHull = child.name === 'hull';
|
||||||
@@ -235,8 +232,12 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
})}
|
})}
|
||||||
|
|
||||||
<group
|
<group
|
||||||
|
position={new Vector3()
|
||||||
|
.sub(turretOrigin)
|
||||||
|
.applyAxisAngle(new Vector3(0, 0, 1), turretRotation)
|
||||||
|
.add(turretOrigin)}
|
||||||
|
rotation={[0, 0, turretRotation]}
|
||||||
ref={turretContainer}
|
ref={turretContainer}
|
||||||
// rotation={[-Math.PI / 2, 0, 0]}
|
|
||||||
>
|
>
|
||||||
{gltf.scene.children[0].children.map((child) => {
|
{gltf.scene.children[0].children.map((child) => {
|
||||||
const isTurret = child.name.startsWith('turret_');
|
const isTurret = child.name.startsWith('turret_');
|
||||||
@@ -261,33 +262,9 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
const isVisible =
|
const isVisible =
|
||||||
isCurrentTurret || isCurrentGun || isCurrentMantlet;
|
isCurrentTurret || isCurrentGun || isCurrentMantlet;
|
||||||
let draftTurretRotation = 0;
|
let draftTurretRotation = 0;
|
||||||
const position = child.position.clone();
|
|
||||||
const rotation = new Vector3().setFromEuler(
|
|
||||||
child.rotation,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isVisible) return null;
|
if (!isVisible) return null;
|
||||||
|
|
||||||
if (isTurret || isMantlet) {
|
|
||||||
position
|
|
||||||
.sub(turretOrigin)
|
|
||||||
.applyAxisAngle(
|
|
||||||
new Vector3(0, 0, 1),
|
|
||||||
turretRotation,
|
|
||||||
)
|
|
||||||
.add(turretOrigin);
|
|
||||||
rotation.add(new Vector3(0, 0, turretRotation));
|
|
||||||
} else if (isGun) {
|
|
||||||
position
|
|
||||||
.sub(turretOrigin)
|
|
||||||
.applyAxisAngle(
|
|
||||||
new Vector3(0, 0, 1),
|
|
||||||
turretRotation,
|
|
||||||
)
|
|
||||||
.add(turretOrigin);
|
|
||||||
rotation.add(new Vector3(0, 0, turretRotation));
|
|
||||||
}
|
|
||||||
|
|
||||||
function handlePointerDown(
|
function handlePointerDown(
|
||||||
event: ThreeEvent<PointerEvent>,
|
event: ThreeEvent<PointerEvent>,
|
||||||
) {
|
) {
|
||||||
@@ -317,39 +294,15 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
event.movementX * rotationSpeed;
|
event.movementX * rotationSpeed;
|
||||||
draftTurretRotation += deltaTurretRotation;
|
draftTurretRotation += deltaTurretRotation;
|
||||||
|
|
||||||
if (turretObject3D.current) {
|
if (turretContainer.current) {
|
||||||
turretObject3D.current.position
|
turretContainer.current.position
|
||||||
.sub(turretOrigin)
|
.sub(turretOrigin)
|
||||||
.applyAxisAngle(
|
.applyAxisAngle(
|
||||||
new Vector3(0, 0, 1),
|
new Vector3(0, 0, 1),
|
||||||
deltaTurretRotation,
|
deltaTurretRotation,
|
||||||
)
|
)
|
||||||
.add(turretOrigin);
|
.add(turretOrigin);
|
||||||
turretObject3D.current.rotation.z =
|
turretContainer.current.rotation.z =
|
||||||
draftTurretRotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mantletObject3D.current) {
|
|
||||||
mantletObject3D.current.position
|
|
||||||
.sub(turretOrigin)
|
|
||||||
.applyAxisAngle(
|
|
||||||
new Vector3(0, 0, 1),
|
|
||||||
deltaTurretRotation,
|
|
||||||
)
|
|
||||||
.add(turretOrigin);
|
|
||||||
mantletObject3D.current.rotation.z =
|
|
||||||
draftTurretRotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gunObject3D.current) {
|
|
||||||
gunObject3D.current.position
|
|
||||||
.sub(turretOrigin)
|
|
||||||
.applyAxisAngle(
|
|
||||||
new Vector3(0, 0, 1),
|
|
||||||
deltaTurretRotation,
|
|
||||||
)
|
|
||||||
.add(turretOrigin);
|
|
||||||
gunObject3D.current.rotation.z =
|
|
||||||
draftTurretRotation;
|
draftTurretRotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -379,18 +332,9 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
receiveShadow
|
receiveShadow
|
||||||
geometry={(child as Mesh).geometry}
|
geometry={(child as Mesh).geometry}
|
||||||
material={(child as Mesh).material}
|
material={(child as Mesh).material}
|
||||||
position={position}
|
position={child.position}
|
||||||
rotation={rotation.toArray()}
|
rotation={child.rotation}
|
||||||
scale={child.scale}
|
scale={child.scale}
|
||||||
ref={
|
|
||||||
isTurret
|
|
||||||
? turretObject3D
|
|
||||||
: isGun
|
|
||||||
? gunObject3D
|
|
||||||
: isMantlet
|
|
||||||
? mantletObject3D
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
Reference in new issue
Block a user