From 7f9a54ef85f8b2f4fb7dd09cb9f96bd3d14d9e83 Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Sun, 1 Dec 2024 22:21:33 -0600 Subject: [PATCH] feat: more props --- .../HeroSection/components/Options/index.tsx | 2 +- .../TankSandbox/components/Control.tsx | 48 ++++------------ .../TankSandbox/components/SceneProps.tsx | 57 +++++++++++++++++-- 3 files changed, 63 insertions(+), 44 deletions(-) diff --git a/packages/website/src/components/Tankopedia/HeroSection/components/Options/index.tsx b/packages/website/src/components/Tankopedia/HeroSection/components/Options/index.tsx index a3c447445..8d14df365 100644 --- a/packages/website/src/components/Tankopedia/HeroSection/components/Options/index.tsx +++ b/packages/website/src/components/Tankopedia/HeroSection/components/Options/index.tsx @@ -97,7 +97,7 @@ export function Options({ thicknessRange, canvas }: OptionsProps) { style={{ backgroundImage: `url(${imgur('27Gwth4')})`, backgroundSize: 'contain', - transform: 'translate(-50%, -50%)', + transform: 'translateX(-50%)', borderRadius: '50%', }} /> diff --git a/packages/website/src/components/Tankopedia/HeroSection/components/TankSandbox/components/Control.tsx b/packages/website/src/components/Tankopedia/HeroSection/components/TankSandbox/components/Control.tsx index edfc695ce..8ae5711a4 100644 --- a/packages/website/src/components/Tankopedia/HeroSection/components/TankSandbox/components/Control.tsx +++ b/packages/website/src/components/Tankopedia/HeroSection/components/TankSandbox/components/Control.tsx @@ -25,10 +25,8 @@ const ARCADE_MODE_ANGLE = Math.PI / 8; export const ARCADE_MODE_FOV = 54; export const INSPECT_MODE_FOV = 25; -const emptyVector = new Vector2(); export function Controls() { - const helper = useRef(null); const display = TankopediaEphemeral.use((state) => state.display); const duelStore = Duel.useStore(); const tankopediaEphemeralStore = TankopediaEphemeral.useStore(); @@ -81,8 +79,6 @@ export function Controls() { protagonistTurretOrigin.y + protagonistGunOrigin.y; const initialPosition = [-8, gunHeight + 4, -13] as const; - const raycaster = useThree((state) => state.raycaster); - const scene = useThree((state) => state.scene); useEffect(() => { if (!orbitControls.current) return; @@ -237,38 +233,16 @@ export function Controls() { }, []); return ( - <> - - { - 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); - }} - /> - + ); } diff --git a/packages/website/src/components/Tankopedia/HeroSection/components/TankSandbox/components/SceneProps.tsx b/packages/website/src/components/Tankopedia/HeroSection/components/TankSandbox/components/SceneProps.tsx index 738e94149..7a88c5a2b 100644 --- a/packages/website/src/components/Tankopedia/HeroSection/components/TankSandbox/components/SceneProps.tsx +++ b/packages/website/src/components/Tankopedia/HeroSection/components/TankSandbox/components/SceneProps.tsx @@ -1,18 +1,28 @@ import { useFrame, useLoader } from '@react-three/fiber'; import { clamp } from 'lodash-es'; import { useRef } from 'react'; -import { MeshStandardMaterial, TextureLoader } from 'three'; +import { + AxesHelper, + Group, + MeshStandardMaterial, + TextureLoader, + Vector2, +} from 'three'; import { TankopediaEphemeral } from '../../../../../../stores/tankopediaEphemeral'; import { TankopediaPersistent } from '../../../../../../stores/tankopediaPersistent'; import { TankopediaDisplay } from '../../../../../../stores/tankopediaPersistent/constants'; +const emptyVector = new Vector2(); + export function SceneProps() { + const helper = useRef(null); const show = TankopediaPersistent.use( (state) => state.showGrid && !state.showEnvironment, ); const texture = useLoader(TextureLoader, 'https://i.imgur.com/C28Z8nU.png'); const material = useRef(null); const display = TankopediaEphemeral.use((state) => state.display); + const playground = useRef(null); useFrame(({ camera }) => { if (!material.current) return; @@ -21,6 +31,27 @@ export function SceneProps() { 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 ( <> {show && display !== TankopediaDisplay.ShootingRange && ( @@ -29,13 +60,27 @@ export function SceneProps() { )} + {display === TankopediaDisplay.ShootingRange && ( <> - {/* */} - - - - + + + + + + + + + + + + + )}