diff --git a/package.json b/package.json index 3b9378a4d..8f2e955ee 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "satori": "^0.10.8", "sharp": "^0.33.1", "three": "^0.159.0", + "three-stdlib": "^2.28.11", "vite-node": "^0.34.5", "vitepress": "^1.0.0-rc.20", "vitepress-plugin-auto-sidebar": "^1.1.0", @@ -81,7 +82,7 @@ "@types/parse-dds": "^1.0.3", "@types/pngjs": "^6.0.4", "@types/react": "^18.2.22", - "@types/three": "^0.159.0", + "@types/three": "^0.160.0", "@vanilla-extract/next-plugin": "^2.3.1", "compare-versions": "^6.1.0", "crc": "^4.3.2", diff --git a/src/app/tools/tankopedia/[id]/components/tankAlignment.ts b/src/app/tools/tankopedia/[id]/components/tankAlignment.ts deleted file mode 100644 index e3e5962e1..000000000 --- a/src/app/tools/tankopedia/[id]/components/tankAlignment.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { useThree } from '@react-three/fiber'; -import { RefObject, useEffect } from 'react'; -import { Box3, Group } from 'three'; - -interface TankAlignmentProps { - model: RefObject; -} - -export function TankAlignment({ model }: TankAlignmentProps) { - const camera = useThree((state) => state.camera); - - useEffect(() => { - const box = new Box3().setFromObject(model.current!); - const diameter = Math.max(box.max.x - box.min.x, box.max.z - box.min.z); - const radius = diameter / 2; - - camera.position.set(0, (box.min.y + box.max.y) / 2, -10); - }, []); - - return null; -} diff --git a/src/app/tools/tankopedia/[id]/components/tankAlignment.tsx b/src/app/tools/tankopedia/[id]/components/tankAlignment.tsx new file mode 100644 index 000000000..acf0110d4 --- /dev/null +++ b/src/app/tools/tankopedia/[id]/components/tankAlignment.tsx @@ -0,0 +1,31 @@ +import { OrbitControls } from '@react-three/drei'; +import { useThree } from '@react-three/fiber'; +import { RefObject, useEffect, useRef } from 'react'; +import { Box3, Group, Vector3 } from 'three'; +import { OrbitControls as OrbitControlsImpl } from 'three-stdlib'; + +interface TankAlignmentProps { + model: RefObject; + orbit: boolean; +} + +export function TankAlignment({ model, orbit }: TankAlignmentProps) { + const controls = useRef(null); + const camera = useThree((state) => state.camera); + + useEffect(() => { + const box = new Box3().setFromObject(model.current!); + const diameter = Math.max(box.max.x - box.min.x, box.max.z - box.min.z); + + 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 ( + + ); +} diff --git a/src/app/tools/tankopedia/[id]/page.tsx b/src/app/tools/tankopedia/[id]/page.tsx index 6b58da012..e396930fe 100644 --- a/src/app/tools/tankopedia/[id]/page.tsx +++ b/src/app/tools/tankopedia/[id]/page.tsx @@ -5,7 +5,6 @@ import { CaretRightIcon, MagnifyingGlassIcon, } from '@radix-ui/react-icons'; - import { Button, Card, @@ -20,7 +19,6 @@ import { Theme, Tooltip, } from '@radix-ui/themes'; -import { OrbitControls } from '@react-three/drei'; import { Canvas, ThreeEvent, useLoader } from '@react-three/fiber'; import { go } from 'fuzzysort'; import { debounce } from 'lodash'; @@ -140,19 +138,19 @@ export default function Page({ params }: { params: { id: string } }) { onPointerDown={(event) => event.preventDefault()} camera={{ fov: 20 }} > - - + +