mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 03:29:51 +01:00
feat: initial turret rotation
This commit is contained in:
1 parent
d408df8b4c
commit
c10060decc
5 files changed
+97
-36
No files matched your search
+28
-22
@@ -97,9 +97,8 @@ type ShellDefinitionsList = Record<
|
|||||||
interface VehicleDefinitions {
|
interface VehicleDefinitions {
|
||||||
invisibility: { moving: number; still: number; firePenalty: number };
|
invisibility: { moving: number; still: number; firePenalty: number };
|
||||||
hull: {
|
hull: {
|
||||||
turretPositions: {
|
turretPositions: { turret: string };
|
||||||
turret: string;
|
turretInitialRotation?: { yaw: 0; pitch: 6.5; roll: 0 };
|
||||||
};
|
|
||||||
};
|
};
|
||||||
turrets0: {
|
turrets0: {
|
||||||
[key: string]: {
|
[key: string]: {
|
||||||
@@ -250,6 +249,13 @@ if (allTargets || targets?.includes('definitions')) {
|
|||||||
|
|
||||||
modelDefinitions[tankId] = {
|
modelDefinitions[tankId] = {
|
||||||
turretOrigin,
|
turretOrigin,
|
||||||
|
turretRotation: tankDefinition.root.hull.turretInitialRotation
|
||||||
|
? {
|
||||||
|
yaw: tankDefinition.root.hull.turretInitialRotation.yaw,
|
||||||
|
pitch: tankDefinition.root.hull.turretInitialRotation.pitch,
|
||||||
|
roll: tankDefinition.root.hull.turretInitialRotation.roll,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
turrets: {},
|
turrets: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -409,25 +415,25 @@ if (allTargets || targets?.includes('definitions')) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
console.log('Committing definitions...');
|
console.log('Committing definitions...');
|
||||||
// await commitMultipleFiles(
|
await commitMultipleFiles(
|
||||||
// 'tresabhi',
|
'tresabhi',
|
||||||
// 'blitzkrieg-assets',
|
'blitzkrieg-assets',
|
||||||
// 'main',
|
'main',
|
||||||
// 'definitions',
|
'definitions',
|
||||||
// [
|
[
|
||||||
// {
|
{
|
||||||
// content: JSON.stringify(tankDefinitions),
|
content: JSON.stringify(tankDefinitions),
|
||||||
// encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
// path: 'definitions/tanks.json',
|
path: 'definitions/tanks.json',
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// content: JSON.stringify(modelDefinitions),
|
content: JSON.stringify(modelDefinitions),
|
||||||
// encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
// path: 'definitions/models.json',
|
path: 'definitions/models.json',
|
||||||
// },
|
},
|
||||||
// ],
|
],
|
||||||
// true,
|
true,
|
||||||
// );
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { clamp } from 'lodash';
|
|||||||
import { RefObject, forwardRef, useImperativeHandle, useRef } from 'react';
|
import { RefObject, forwardRef, useImperativeHandle, useRef } from 'react';
|
||||||
import { Group, Mesh, Object3D, Vector3 } from 'three';
|
import { Group, Mesh, Object3D, Vector3 } from 'three';
|
||||||
import {
|
import {
|
||||||
|
InitialTurretRotation,
|
||||||
PitchLimits,
|
PitchLimits,
|
||||||
YawLimits,
|
YawLimits,
|
||||||
} from '../../../../../core/blitzkrieg/modelDefinitions';
|
} from '../../../../../core/blitzkrieg/modelDefinitions';
|
||||||
@@ -20,6 +21,7 @@ interface GunContainerProps {
|
|||||||
pitchLimits: PitchLimits;
|
pitchLimits: PitchLimits;
|
||||||
onPitchStart: () => void;
|
onPitchStart: () => void;
|
||||||
onPitchEnd: (pitch: number, yaw: number) => void;
|
onPitchEnd: (pitch: number, yaw: number) => void;
|
||||||
|
initialTurretRotation?: InitialTurretRotation;
|
||||||
turretContainer: RefObject<Group>;
|
turretContainer: RefObject<Group>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +31,7 @@ export const GunContainer = forwardRef<Group, GunContainerProps>(
|
|||||||
gunOrigin,
|
gunOrigin,
|
||||||
turretOrigin,
|
turretOrigin,
|
||||||
pitch,
|
pitch,
|
||||||
|
initialTurretRotation,
|
||||||
yaw,
|
yaw,
|
||||||
objects,
|
objects,
|
||||||
yawLimits,
|
yawLimits,
|
||||||
@@ -163,9 +166,21 @@ export const GunContainer = forwardRef<Group, GunContainerProps>(
|
|||||||
turretContainer.current.position
|
turretContainer.current.position
|
||||||
.set(0, 0, 0)
|
.set(0, 0, 0)
|
||||||
.sub(turretOrigin)
|
.sub(turretOrigin)
|
||||||
.applyAxisAngle(new Vector3(0, 0, 1), draftYaw)
|
.applyAxisAngle(new Vector3(0, 0, 1), draftYaw);
|
||||||
.add(turretOrigin);
|
|
||||||
turretContainer.current.rotation.z = draftYaw;
|
turretContainer.current.rotation.z = draftYaw;
|
||||||
|
|
||||||
|
if (initialTurretRotation) {
|
||||||
|
const pitch = -initialTurretRotation.pitch * (Math.PI / 180);
|
||||||
|
const yaw = -initialTurretRotation.yaw * (Math.PI / 180);
|
||||||
|
const roll = -initialTurretRotation.roll * (Math.PI / 180);
|
||||||
|
|
||||||
|
turretContainer.current.position
|
||||||
|
.applyAxisAngle(new Vector3(1, 0, 0), pitch)
|
||||||
|
.applyAxisAngle(new Vector3(0, 1, 0), roll)
|
||||||
|
.applyAxisAngle(new Vector3(0, 0, 1), yaw);
|
||||||
|
}
|
||||||
|
|
||||||
|
turretContainer.current.position.add(turretOrigin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function handlePointerUp() {
|
function handlePointerUp() {
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ import {
|
|||||||
useImperativeHandle,
|
useImperativeHandle,
|
||||||
useRef,
|
useRef,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { Group, Mesh, Object3D, Vector3 } from 'three';
|
import { Euler, Group, Mesh, Object3D, Vector3 } from 'three';
|
||||||
import {
|
import {
|
||||||
|
InitialTurretRotation,
|
||||||
PitchLimits,
|
PitchLimits,
|
||||||
YawLimits,
|
YawLimits,
|
||||||
} from '../../../../../core/blitzkrieg/modelDefinitions';
|
} from '../../../../../core/blitzkrieg/modelDefinitions';
|
||||||
@@ -28,6 +29,7 @@ interface TurretContainerProps {
|
|||||||
onYawStart: () => void;
|
onYawStart: () => void;
|
||||||
onYawEnd: (pitch: number, yaw: number) => void;
|
onYawEnd: (pitch: number, yaw: number) => void;
|
||||||
gunContainer: RefObject<Group>;
|
gunContainer: RefObject<Group>;
|
||||||
|
initialTurretRotation?: InitialTurretRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TurretContainer = forwardRef(
|
export const TurretContainer = forwardRef(
|
||||||
@@ -45,23 +47,37 @@ export const TurretContainer = forwardRef(
|
|||||||
gunOrigin,
|
gunOrigin,
|
||||||
pitchLimits,
|
pitchLimits,
|
||||||
onYawStart,
|
onYawStart,
|
||||||
|
initialTurretRotation,
|
||||||
}: TurretContainerProps,
|
}: TurretContainerProps,
|
||||||
ref,
|
ref,
|
||||||
) => {
|
) => {
|
||||||
const canvas = useThree((state) => state.gl.domElement);
|
const canvas = useThree((state) => state.gl.domElement);
|
||||||
const turretContainer = useRef<Group>(null);
|
const turretContainer = useRef<Group>(null);
|
||||||
|
const position = new Vector3()
|
||||||
|
.sub(turretOrigin)
|
||||||
|
.applyAxisAngle(new Vector3(0, 0, 1), yaw);
|
||||||
|
const rotation = new Euler(0, 0, yaw);
|
||||||
|
|
||||||
|
if (initialTurretRotation) {
|
||||||
|
const pitch = -initialTurretRotation.pitch * (Math.PI / 180);
|
||||||
|
const yaw = -initialTurretRotation.yaw * (Math.PI / 180);
|
||||||
|
const roll = -initialTurretRotation.roll * (Math.PI / 180);
|
||||||
|
|
||||||
|
position
|
||||||
|
.applyAxisAngle(new Vector3(1, 0, 0), pitch)
|
||||||
|
.applyAxisAngle(new Vector3(0, 1, 0), roll)
|
||||||
|
.applyAxisAngle(new Vector3(0, 0, 1), yaw);
|
||||||
|
rotation.x += pitch;
|
||||||
|
rotation.y += roll;
|
||||||
|
rotation.z += yaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
position.add(turretOrigin);
|
||||||
|
|
||||||
useImperativeHandle(ref, () => turretContainer.current!);
|
useImperativeHandle(ref, () => turretContainer.current!);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<group
|
<group position={position} rotation={rotation} ref={turretContainer}>
|
||||||
position={new Vector3()
|
|
||||||
.sub(turretOrigin)
|
|
||||||
.applyAxisAngle(new Vector3(0, 0, 1), yaw)
|
|
||||||
.add(turretOrigin)}
|
|
||||||
rotation={[0, 0, yaw]}
|
|
||||||
ref={turretContainer}
|
|
||||||
>
|
|
||||||
{objects.map((object) => {
|
{objects.map((object) => {
|
||||||
const isTurret = object.name.startsWith('turret_');
|
const isTurret = object.name.startsWith('turret_');
|
||||||
const isCurrentTurret =
|
const isCurrentTurret =
|
||||||
@@ -167,9 +183,21 @@ export const TurretContainer = forwardRef(
|
|||||||
turretContainer.current.position
|
turretContainer.current.position
|
||||||
.set(0, 0, 0)
|
.set(0, 0, 0)
|
||||||
.sub(turretOrigin)
|
.sub(turretOrigin)
|
||||||
.applyAxisAngle(new Vector3(0, 0, 1), draftYaw)
|
.applyAxisAngle(new Vector3(0, 0, 1), draftYaw);
|
||||||
.add(turretOrigin);
|
|
||||||
turretContainer.current.rotation.z = draftYaw;
|
turretContainer.current.rotation.z = draftYaw;
|
||||||
|
|
||||||
|
if (initialTurretRotation) {
|
||||||
|
const pitch = -initialTurretRotation.pitch * (Math.PI / 180);
|
||||||
|
const yaw = -initialTurretRotation.yaw * (Math.PI / 180);
|
||||||
|
const roll = -initialTurretRotation.roll * (Math.PI / 180);
|
||||||
|
|
||||||
|
turretContainer.current.position
|
||||||
|
.applyAxisAngle(new Vector3(1, 0, 0), pitch)
|
||||||
|
.applyAxisAngle(new Vector3(0, 1, 0), roll)
|
||||||
|
.applyAxisAngle(new Vector3(0, 0, 1), yaw);
|
||||||
|
}
|
||||||
|
|
||||||
|
turretContainer.current.position.add(turretOrigin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function handlePointerUp() {
|
function handlePointerUp() {
|
||||||
|
|||||||
@@ -109,7 +109,9 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
function handlePointerMove(event: PointerEvent) {
|
function handlePointerMove(event: PointerEvent) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
function handlePointerUp() {
|
function handlePointerUp(event: PointerEvent) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
window.removeEventListener('pointermove', handlePointerMove);
|
window.removeEventListener('pointermove', handlePointerMove);
|
||||||
window.removeEventListener('pointerup', handlePointerUp);
|
window.removeEventListener('pointerup', handlePointerUp);
|
||||||
}
|
}
|
||||||
@@ -167,6 +169,7 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
onTrackEnd={() => setControlsEnabled(true)}
|
onTrackEnd={() => setControlsEnabled(true)}
|
||||||
>
|
>
|
||||||
<TurretContainer
|
<TurretContainer
|
||||||
|
initialTurretRotation={tankModelDefinition.turretRotation}
|
||||||
gunOrigin={gunOrigin}
|
gunOrigin={gunOrigin}
|
||||||
ref={turretContainer}
|
ref={turretContainer}
|
||||||
objects={gltf.scene.children[0].children}
|
objects={gltf.scene.children[0].children}
|
||||||
@@ -186,6 +189,9 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
>
|
>
|
||||||
<GunContainer
|
<GunContainer
|
||||||
ref={gunContainer}
|
ref={gunContainer}
|
||||||
|
initialTurretRotation={
|
||||||
|
tankModelDefinition.turretRotation
|
||||||
|
}
|
||||||
onPitchStart={() => setControlsEnabled(false)}
|
onPitchStart={() => setControlsEnabled(false)}
|
||||||
pitchLimits={gunModelDefinition.pitch}
|
pitchLimits={gunModelDefinition.pitch}
|
||||||
turretContainer={turretContainer}
|
turretContainer={turretContainer}
|
||||||
|
|||||||
@@ -4,8 +4,14 @@ import { asset } from './asset';
|
|||||||
export type ModelDefinitions = Record<number, ModelDefinition>;
|
export type ModelDefinitions = Record<number, ModelDefinition>;
|
||||||
interface ModelDefinition {
|
interface ModelDefinition {
|
||||||
turretOrigin: Vector3Tuple;
|
turretOrigin: Vector3Tuple;
|
||||||
|
turretRotation?: InitialTurretRotation;
|
||||||
turrets: Record<number, TurretModelDefinition>;
|
turrets: Record<number, TurretModelDefinition>;
|
||||||
}
|
}
|
||||||
|
export interface InitialTurretRotation {
|
||||||
|
yaw: number;
|
||||||
|
pitch: number;
|
||||||
|
roll: number;
|
||||||
|
}
|
||||||
interface TurretModelDefinition {
|
interface TurretModelDefinition {
|
||||||
model: number;
|
model: number;
|
||||||
gunOrigin: Vector3Tuple;
|
gunOrigin: Vector3Tuple;
|
||||||
|
|||||||
Reference in new issue
Block a user