import { useState, useMemo, useRef, useEffect } from 'react';
|
import { useFrame } from '@react-three/fiber';
|
import { useFBX, useAnimations } from '@react-three/drei';
|
import * as THREE from 'three';
|
import * as Common from '../utils/common';
|
import * as TWEEN from "@tweenjs/tween.js";
|
import { useStore } from '@/store';
|
import {
|
INTERVAL_TIME,
|
MODEL_AGV_SCALE,
|
REAL_COMPARE_MAP_SCALE,
|
REAL_COMPARE_MAP_OFFSET_X,
|
REAL_COMPARE_MAP_OFFSET_Z,
|
} from '../config/setting'
|
|
const width = 200;
|
|
const getMajorPos = (position) => {
|
return {
|
x: position?.[2] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_X,
|
y: position?.[1] * REAL_COMPARE_MAP_SCALE + 10,
|
z: position?.[0] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_Z,
|
}
|
}
|
|
const Path = (props) => {
|
const { list } = props;
|
|
const lineRef = useRef();
|
|
// Convert list of positions to THREE.Vector3 objects
|
const points = useMemo(() => {
|
return list.map(item => {
|
const { x, y, z } = getMajorPos(item.position);
|
return new THREE.Vector3(x, y, z);
|
});
|
}, [list]);
|
|
useEffect(() => {
|
if (lineRef.current) {
|
lineRef.current.geometry.setFromPoints(points);
|
}
|
console.log(points);
|
|
}, [points]);
|
|
useEffect(() => {
|
// console.log(JSON.stringify(props.list));
|
//[{"code":"00000052","position":[4961,0,2420],"serial":6},{"code":"00000053","position":[5491,0,2420],"serial":7},{"code":"00000054","position":[6021,0,2420],"serial":8}]
|
}, [props])
|
|
return (
|
<>
|
<group>
|
{/* <mesh position={} rotation={[]}>
|
<planeGeometry
|
args={[width, height]}
|
></planeGeometry>
|
<meshBasicMaterial color="rgb(23,146,247)"></meshBasicMaterial>
|
</mesh> */}
|
<line ref={lineRef}>
|
<bufferGeometry attach="geometry" />
|
<lineBasicMaterial attach="material" color="rgb(23,146,247)" linewidth={width} />
|
</line>
|
</group>
|
</>
|
)
|
}
|
|
export default Path;
|