|
| 1 | +import * as React from 'react'; |
| 2 | +import {Canvas, useFrame /*useFrame*/} from 'react-three-fiber'; |
| 3 | +import Controls from './OrbitControls'; |
| 4 | +import Cell from './Cells'; |
| 5 | +import {useImperativeHandle, useRef, forwardRef} from 'react'; |
| 6 | +import {TrackballControls} from 'three/examples/jsm/controls/TrackballControls'; |
| 7 | +import OrbitControls from './OrbitControls'; |
| 8 | +// import create from 'zustand'; |
| 9 | + |
| 10 | +// const useStore = create((set) => ({target: null, setTarget: (target) => set({target})})); |
| 11 | + |
| 12 | +export const Board = ({board, layoutType, selectedPoint, onSelectPoint}, ref) => { |
| 13 | + const controlsRef = useRef(OrbitControls); |
| 14 | + // const borderRef = new BorderBox(layoutType.width, layoutType.height, layoutType.depth); |
| 15 | + // const setTarget = useStore((state) => state.setTarget) |
| 16 | + |
| 17 | + useImperativeHandle(ref, () => ({ |
| 18 | + resetCamera: () => { |
| 19 | + return controlsRef.current.resetCamera(); |
| 20 | + }, |
| 21 | + |
| 22 | + // setTarget: (target) => { |
| 23 | + // console.log('ZOOOooom: ' + target.position); |
| 24 | + // return controlsRef.current.setCurrentTarget(target); |
| 25 | + // }, |
| 26 | + })); |
| 27 | + |
| 28 | + // useFrame(({ camera }) => { |
| 29 | + // ref.current.position.copy(camera.position); |
| 30 | + // ref.current.quaternion.copy(camera.quaternion); |
| 31 | + // |
| 32 | + // // Apply offset |
| 33 | + // ref.current.translateZ(-5); |
| 34 | + // }); |
| 35 | + |
| 36 | + |
| 37 | + return ( |
| 38 | + <Canvas className = "board" camera = {{position: [0, 0, 80], far: 1000}}> |
| 39 | + {/*<PerspectiveCamera position={[2, 2, 2]} makeDefault />*/} |
| 40 | + <Controls ref = {controlsRef} selectedPoint={selectedPoint}/> |
| 41 | + {/* <instancedMesh> */} |
| 42 | + <mesh> {/* BorderBox */} |
| 43 | + {(layoutType === 'standard') ? |
| 44 | + <boxBufferGeometry attach = "geometry" args = {[110, 110, -10]}/> |
| 45 | + : |
| 46 | + <boxBufferGeometry attach = "geometry" args = {[180, 180, -10]}/> |
| 47 | + } |
| 48 | + <meshBasicMaterial attach = "material" color = "black"/> |
| 49 | + </mesh> |
| 50 | + |
| 51 | + |
| 52 | + <ambientLight color = "white" intensity = {0.1}/> |
| 53 | + <hemisphereLight |
| 54 | + color = "#ffffff" |
| 55 | + skyColor = "#ffffbb" |
| 56 | + groundColor = "black" |
| 57 | + intensity = {1.0} |
| 58 | + /> |
| 59 | + <Cell |
| 60 | + board = {board} |
| 61 | + layoutType = {layoutType} |
| 62 | + selectedPoint = {selectedPoint} |
| 63 | + onSelectPoint = {onSelectPoint} |
| 64 | + /> |
| 65 | + {/*<Effects />*/} |
| 66 | + </Canvas> |
| 67 | + ); |
| 68 | +}; |
| 69 | + |
| 70 | +export default forwardRef(Board); |
0 commit comments