-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aebe59d
commit d59cf6a
Showing
10 changed files
with
173 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function Input({ value, onChange, placeholder }) { | ||
return ( | ||
<input | ||
type="number" | ||
value={value} | ||
onChange={(event) => { | ||
onChange(event.target.value); | ||
}} | ||
></input> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./Input"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { OrthographicCamera, PerspectiveCamera, useHelper } from "@react-three/drei"; | ||
import React, { useEffect, useRef } from "react"; | ||
import { CameraHelper } from "three"; | ||
|
||
var w = window.innerWidth; | ||
var h = window.innerHeight; | ||
var viewSize = 350; | ||
var aspectRatio = w / h; | ||
|
||
const _viewport = { | ||
left: (-aspectRatio * viewSize) / 2, | ||
right: (aspectRatio * viewSize) / 2, | ||
top: viewSize / 2, | ||
bottom: -viewSize / 2, | ||
}; | ||
|
||
console.log(_viewport); | ||
|
||
export default function Cameras() { | ||
const topDownCameraRef = useRef(null); | ||
|
||
// useHelper(topDownCameraRef && topDownCameraRef, CameraHelper); | ||
|
||
useEffect(() => { | ||
if (topDownCameraRef.current != null) { | ||
topDownCameraRef.current.lookAt(0, 0, 0); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<PerspectiveCamera | ||
// ref={defaultCameraRef} | ||
position={[45, 26, 45]} | ||
fov={35} | ||
far={500} | ||
near={1} | ||
makeDefault={true} | ||
/> | ||
<OrthographicCamera | ||
left={_viewport.left} | ||
right={_viewport.right} | ||
top={_viewport.top} | ||
bottom={_viewport.bottom} | ||
zoom={2.5} | ||
position={[0, 8, 0]} | ||
far={9} | ||
near={1} | ||
ref={topDownCameraRef} | ||
// makeDefault={true} | ||
/> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {default} from './Cameras'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,39 @@ | ||
import shipModel from "../../assets/ship.gltf"; | ||
import { useLoader } from '@react-three/fiber' | ||
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader' | ||
import { useFrame, useLoader } from "@react-three/fiber"; | ||
import { useRef } from "react"; | ||
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader"; | ||
import useStore from "../../store"; | ||
|
||
export default function Ship() { | ||
const gltf = useLoader(GLTFLoader, shipModel) | ||
return <primitive scale={0.1} object={gltf.scene} />; | ||
const shipRef = useRef(); | ||
const dataCounterIndex = useRef(0); | ||
const gltf = useLoader(GLTFLoader, shipModel); | ||
|
||
const simulationData = useStore((state) => state.simulationData); | ||
const indexSkip = useStore((state) => state.indexSkip); | ||
const animating = useStore((state) => state.animating); | ||
const setAnimating = useStore((state) => state.setAnimating); | ||
|
||
useFrame(() => { | ||
if (animating && simulationData && indexSkip) { | ||
const idx = indexSkip * dataCounterIndex.current; | ||
|
||
if (idx < simulationData.length) { | ||
shipRef.current.position.x = simulationData[idx + 0] * 50; | ||
shipRef.current.position.z = simulationData[idx + 1] * 50; | ||
shipRef.current.rotation.y = simulationData[idx + 2]; | ||
|
||
console.log("shipRef.current.position.x", shipRef.current.position.x); | ||
console.log("shipRef.current.position.z", shipRef.current.position.z); | ||
console.log("shipRef.current.rotation.y", shipRef.current.rotation.y); | ||
|
||
dataCounterIndex.current += 1; | ||
} else { | ||
setAnimating(false); | ||
dataCounterIndex.current = 0; | ||
} | ||
} | ||
}); | ||
|
||
return <primitive ref={shipRef} scale={0.1} object={gltf.scene} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters