| | |
| | | import { useFrame } from '@react-three/fiber'; |
| | | import { useFBX, useAnimations } from '@react-three/drei'; |
| | | import * as THREE from 'three'; |
| | | import { MODEL_BOX_SCALE } from '@/config/setting' |
| | | import { MODEL_BOX_SCALE, SHELF_BAY_GROUP_COUNT } from '@/config/setting' |
| | | import * as Common from '../utils/common'; |
| | | import { useStore } from '@/store'; |
| | | |
| | |
| | | } |
| | | |
| | | const getShelfBay = (bay) => { |
| | | return bay - (bay - 1) % 3; |
| | | return bay - (bay - 1) % SHELF_BAY_GROUP_COUNT; |
| | | } |
| | | |
| | | const getShelfLev = (lev) => { |
| | |
| | | } |
| | | |
| | | const getShelfNo = (row, bay, lev) => { |
| | | return getShelfRow(row) + '-' + getShelfBay(bay) + '-' + getShelfLev(lev); |
| | | return Common.generateLocNo(getShelfRow(row), getShelfBay(bay), getShelfLev(lev)); |
| | | } |
| | | |
| | | const Box = (props) => { |
| | |
| | | const state = useStore(); |
| | | |
| | | const [pos, setPos] = useState([]); |
| | | const [rotaY, setRotaY] = useState(0); |
| | | |
| | | const boxModel = useMemo(() => { |
| | | const fbx = useFBX('/models/box/box.fbx'); |
| | |
| | | // from shelf |
| | | const shelfNo = getShelfNo(row, bay, lev); |
| | | const shelfPos = state.shelfList[shelfNo]; |
| | | setPos(shelfPos); |
| | | const { row: shelfRow, bay: shelfBay, lev: shelfLev } = Common.parseLocNo(shelfNo); |
| | | |
| | | console.log([shelfPos[0], shelfPos[1] + (bay - shelfBay) * 100, shelfPos[2] + (lev - shelfLev) * 100]); |
| | | |
| | | setPos([shelfPos[0], shelfPos[1] + (bay - shelfBay) * 10, shelfPos[2] + (lev - shelfLev) * 100]); |
| | | setRotaY(Math.PI / 2); |
| | | } else { |
| | | // from agv |
| | | setPos(position); |
| | | setRotaY(rotationY); |
| | | } |
| | | }, [props]); |
| | | |
| | | return ( |
| | | <> |
| | | <group rotation-y={rotationY} position={pos}> |
| | | <group rotation-y={rotaY} position={pos}> |
| | | <primitive object={boxModel} castShadow /> |
| | | </group> |
| | | </> |