feat: more props

This commit is contained in:
tresabhi committed 2024-12-01 22:21:33 -06:00
1 parent 65c52c2e82
commit 7f9a54ef85
3 files changed
+63 -44

No files matched your search

@@ -97,7 +97,7 @@ export function Options({ thicknessRange, canvas }: OptionsProps) {
style={{ style={{
backgroundImage: `url(${imgur('27Gwth4')})`, backgroundImage: `url(${imgur('27Gwth4')})`,
backgroundSize: 'contain', backgroundSize: 'contain',
transform: 'translate(-50%, -50%)', transform: 'translateX(-50%)',
borderRadius: '50%', borderRadius: '50%',
}} }}
/> />
@@ -25,10 +25,8 @@ const ARCADE_MODE_ANGLE = Math.PI / 8;
export const ARCADE_MODE_FOV = 54; export const ARCADE_MODE_FOV = 54;
export const INSPECT_MODE_FOV = 25; export const INSPECT_MODE_FOV = 25;
const emptyVector = new Vector2();
export function Controls() { export function Controls() {
const helper = useRef<AxesHelper>(null);
const display = TankopediaEphemeral.use((state) => state.display); const display = TankopediaEphemeral.use((state) => state.display);
const duelStore = Duel.useStore(); const duelStore = Duel.useStore();
const tankopediaEphemeralStore = TankopediaEphemeral.useStore(); const tankopediaEphemeralStore = TankopediaEphemeral.useStore();
@@ -81,8 +79,6 @@ export function Controls() {
protagonistTurretOrigin.y + protagonistTurretOrigin.y +
protagonistGunOrigin.y; protagonistGunOrigin.y;
const initialPosition = [-8, gunHeight + 4, -13] as const; const initialPosition = [-8, gunHeight + 4, -13] as const;
const raycaster = useThree((state) => state.raycaster);
const scene = useThree((state) => state.scene);
useEffect(() => { useEffect(() => {
if (!orbitControls.current) return; if (!orbitControls.current) return;
@@ -237,38 +233,16 @@ export function Controls() {
}, []); }, []);
return ( return (
<> <OrbitControls
<axesHelper ref={helper} /> maxDistance={20}
<OrbitControls minDistance={5}
maxDistance={20} ref={orbitControls}
minDistance={5} enabled={tankopediaEphemeralStore.getState().controlsEnabled}
ref={orbitControls} rotateSpeed={0.25}
enabled={tankopediaEphemeralStore.getState().controlsEnabled} enableDamping={false}
rotateSpeed={0.25} maxPolarAngle={degToRad(100)}
enableDamping={false} autoRotate={autoRotate}
maxPolarAngle={degToRad(100)} autoRotateSpeed={1 / 4}
autoRotate={autoRotate} />
autoRotateSpeed={1 / 4}
onChange={() => {
if (display !== TankopediaDisplay.ShootingRange || !helper.current) {
return;
}
raycaster.setFromCamera(emptyVector, camera);
const intersections = raycaster.intersectObjects(
scene.children,
true,
);
const first = intersections.find(
(intersection) => intersection.object !== helper.current,
);
if (first === undefined) return;
helper.current.position.copy(first.point);
}}
/>
</>
); );
} }
@@ -1,18 +1,28 @@
import { useFrame, useLoader } from '@react-three/fiber'; import { useFrame, useLoader } from '@react-three/fiber';
import { clamp } from 'lodash-es'; import { clamp } from 'lodash-es';
import { useRef } from 'react'; import { useRef } from 'react';
import { MeshStandardMaterial, TextureLoader } from 'three'; import {
AxesHelper,
Group,
MeshStandardMaterial,
TextureLoader,
Vector2,
} from 'three';
import { TankopediaEphemeral } from '../../../../../../stores/tankopediaEphemeral'; import { TankopediaEphemeral } from '../../../../../../stores/tankopediaEphemeral';
import { TankopediaPersistent } from '../../../../../../stores/tankopediaPersistent'; import { TankopediaPersistent } from '../../../../../../stores/tankopediaPersistent';
import { TankopediaDisplay } from '../../../../../../stores/tankopediaPersistent/constants'; import { TankopediaDisplay } from '../../../../../../stores/tankopediaPersistent/constants';
const emptyVector = new Vector2();
export function SceneProps() { export function SceneProps() {
const helper = useRef<AxesHelper>(null);
const show = TankopediaPersistent.use( const show = TankopediaPersistent.use(
(state) => state.showGrid && !state.showEnvironment, (state) => state.showGrid && !state.showEnvironment,
); );
const texture = useLoader(TextureLoader, 'https://i.imgur.com/C28Z8nU.png'); const texture = useLoader(TextureLoader, 'https://i.imgur.com/C28Z8nU.png');
const material = useRef<MeshStandardMaterial>(null); const material = useRef<MeshStandardMaterial>(null);
const display = TankopediaEphemeral.use((state) => state.display); const display = TankopediaEphemeral.use((state) => state.display);
const playground = useRef<Group>(null);
useFrame(({ camera }) => { useFrame(({ camera }) => {
if (!material.current) return; if (!material.current) return;
@@ -21,6 +31,27 @@ export function SceneProps() {
texture.anisotropy = 2; texture.anisotropy = 2;
useFrame(({ raycaster, scene, camera }) => {
if (
display !== TankopediaDisplay.ShootingRange ||
!playground.current ||
!helper.current
) {
return;
}
raycaster.setFromCamera(emptyVector, camera);
const intersections = raycaster.intersectObjects(
playground.current.children,
true,
);
if (intersections.length === 0) return;
helper.current.position.copy(intersections[0].point);
});
return ( return (
<> <>
{show && display !== TankopediaDisplay.ShootingRange && ( {show && display !== TankopediaDisplay.ShootingRange && (
@@ -29,13 +60,27 @@ export function SceneProps() {
<meshStandardMaterial ref={material} map={texture} transparent /> <meshStandardMaterial ref={material} map={texture} transparent />
</mesh> </mesh>
)} )}
{display === TankopediaDisplay.ShootingRange && ( {display === TankopediaDisplay.ShootingRange && (
<> <>
{/* <fog color="black" /> */} <axesHelper ref={helper} />
<mesh rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
<planeGeometry args={[100, 100]} /> <group ref={playground}>
<meshStandardMaterial color={0x404040} /> <mesh rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
</mesh> <planeGeometry args={[100, 100]} />
<meshStandardMaterial color={0x404040} />
</mesh>
<mesh
receiveShadow
castShadow
position={[10, 1.5, -10]}
rotation={[0, Math.PI / 4, 0]}
>
<boxGeometry args={[1, 3, 1]} />
<meshStandardMaterial color={0xff8040} />
</mesh>
</group>
</> </>
)} )}
</> </>