From 292cb4401ad94f02459eb802699ba83b75bfa112 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期五, 19 四月 2024 15:07:05 +0800 Subject: [PATCH] # --- public/models/box/box.fbx | 0 public/models/shlef/row.glb | 0 public/models/agv/fork.fbx | 0 public/models/agv/loader.fbx | 0 public/models/conveyor/conveyor.fbx | 0 src/core/warehouse.jsx | 13 +++++- src/components/agv.jsx | 65 ++++++++++++++++++++++++++++++++ public/models/agv/body.fbx | 0 8 files changed, 76 insertions(+), 2 deletions(-) diff --git a/public/models/agv/body.fbx b/public/models/agv/body.fbx new file mode 100644 index 0000000..0c4f0f2 --- /dev/null +++ b/public/models/agv/body.fbx Binary files differ diff --git a/public/models/agv/fork.fbx b/public/models/agv/fork.fbx new file mode 100644 index 0000000..401934d --- /dev/null +++ b/public/models/agv/fork.fbx Binary files differ diff --git a/public/models/agv/loader.fbx b/public/models/agv/loader.fbx new file mode 100644 index 0000000..5754224 --- /dev/null +++ b/public/models/agv/loader.fbx Binary files differ diff --git a/public/models/box/box.fbx b/public/models/box/box.fbx new file mode 100644 index 0000000..66e8385 --- /dev/null +++ b/public/models/box/box.fbx Binary files differ diff --git a/public/models/conveyor/conveyor.fbx b/public/models/conveyor/conveyor.fbx new file mode 100644 index 0000000..5db1cf4 --- /dev/null +++ b/public/models/conveyor/conveyor.fbx Binary files differ diff --git a/public/models/shlef/row.glb b/public/models/shlef/row.glb new file mode 100644 index 0000000..d37165a --- /dev/null +++ b/public/models/shlef/row.glb Binary files differ diff --git a/src/components/agv.jsx b/src/components/agv.jsx new file mode 100644 index 0000000..b756443 --- /dev/null +++ b/src/components/agv.jsx @@ -0,0 +1,65 @@ +import { useRef, useEffect } from 'react'; +import { useFrame } from '@react-three/fiber'; +import { useFBX, useAnimations } from '@react-three/drei'; +import { AnimationMixer } from 'three'; + +const Agv = (props) => { + const fbxRef = useRef(); + const mixerRef = useRef(); + + const fbx = useFBX('/models/agv/body.fbx'); + + const setShadow = (obj) => { + obj.castShadow = true; + obj.receiveShadow = true; + + if (obj.children) { + obj.children.forEach((child) => { + setShadow(child); + }); + } + }; + + const setColor = (obj) => { + if (obj.material) { + obj.material.color.set(0x4680BF); + } + if (obj.children) { + obj.children.forEach((child) => { + setColor(child); + }); + } + }; + + // setColor(fbx) + if (!fbx.castShadow) { + setShadow(fbx); + } + + useEffect(() => { + mixerRef.current = new AnimationMixer(fbx); + + if (fbx.animations.length > 0) { + useFrame((state, delta) => { + mixerRef?.current?.update(delta); + }); + + const action = mixerRef.current.clipAction(fbx.animations[0]); // 鍋囪鍙湁涓�涓姩鐢伙紝鍙互鏍规嵁瀹為檯鎯呭喌淇敼 + action.play(); + } + + return () => { + mixerRef.current.stopAllAction(); + }; + }, []); + + return ( + <> + <group rotation={[0, 0, 0]} scale={0.5} position={[0, 0, 0]}> + <primitive object={fbx} castShadow /> + </group> + </> + ) +} + +export default Agv; \ No newline at end of file diff --git a/src/core/warehouse.jsx b/src/core/warehouse.jsx index a715cd7..0106022 100644 --- a/src/core/warehouse.jsx +++ b/src/core/warehouse.jsx @@ -1,14 +1,23 @@ import { useEffect, useRef, useMemo } from 'react'; +import Agv from '../components/agv'; const Warehouse = (props) => { useEffect(() => { - + }, []) + + const agvEl = useMemo(() => { + return ( + <Agv /> + ) + }, []); return ( <> - + <group> + {agvEl} + </group> </> ) } -- Gitblit v1.9.1