数字孪生 3D 智能仓储管理系统技术解析
数字孪生 3D 智能仓储管理系统是一个基于现代前端技术栈构建的企业级 3D 可视化解决方案。该项目通过 Three.js 技术在 Web 端实现了真实仓储环境的数字化孪生,为智能物流和仓储管理提供了直观的 3D 交互界面。
功能演示
大屏预览
设备运行动画
核心特性
-
🏭 智能仓库 3D 建模:完整的仓储环境 3D 重现
-
📦 货架立库管理:动态货架布局与货物存储可视化
-
🚛 车辆轨迹动画:叉车、无人搬运车等设备的实时轨迹展示
-
📊 数据可视化面板:基于 Ant Design 的现代化管理界面
-
🎮 交互式操作:支持 3D 场景的缩放、旋转、点击交互
-
📱 响应式设计:适配不同屏幕尺寸的设备
项目架构
本项目采用Monorepo架构,使用pnpm
工作空间和turbo
进行统一管理,实现了高效的多包开发模式。
├── apps/ # 应用程序
│ └── admin/ # 管理后台应用
└── packages/ # 共享包
├── apis/ # API请求封装
├── components/ # 通用组件库
├── hooks/ # 自定义Hooks
├── mobx-store/ # MobX状态管理
├── store/ # Redux状态管理
├── three/ # Three.js 3D组件
├── ui/ # UI组件库
└── utils/ # 工具函数
技术栈详解
前端核心
技术 | 作用 |
---|---|
React | 构建用户界面 |
TypeScript | 静态类型检查 |
Vite | 极速开发构建工具 |
Ant Design | 企业级 UI 组件库 |
三维渲染
技术 | 作用 |
---|---|
Three.js | WebGL 渲染引擎 |
@react-three/fiber | React 与 Three.js 的声明式桥接 |
@react-three/drei | 实用三维组件集合 |
@react-three/rapier | 物理引擎集成 |
@react-three/csg | CSG 布尔运算 |
状态管理与工程化
技术 | 作用 |
---|---|
Redux Toolkit | 全局状态管理 |
MobX | 三维场景状态 |
Turbo | Monorepo 构建加速 |
pnpm | 包管理器 |
🔥 核心功能模块
1. 3D 场景渲染引擎
核心文件:packages/three/Canva/index.tsx
const Canva = (props) => {
return (
<Canvas shadows gl={{ logarithmicDepthBuffer: true }}>
<BaseSence /> {/* 基础场景:相机、灯光、天空 */}
<Factory /> {/* 工厂场景:仓库、设备、动画 */}
<Gizmo /> {/* 辅助工具 */}
</Canvas>
);
};
技术实现:
-
使用
@react-three/fiber
将 Three.js 与 React 声明式开发结合 -
支持阴影渲染和对数深度缓冲,提升视觉效果
-
模块化场景管理,便于功能扩展
2. 智能仓储建筑系统
核心文件:packages/three/Canva/components/Factory/components/house.tsx
const House = (props: IHouse) => {
// 复杂的仓库几何体构建
const getBackWallShape = () => {
const shape = getPointToShape([
/* 墙体顶点 */
]);
const doorHoles = new THREE.Path(); // 门洞挖空
shape.holes.push(doorHoles);
return shape;
};
return (
<group position={position}>
{/* 墙体、屋顶、地面 */}
<mesh>
<extrudeGeometry
args={[getBackWallShape(), { depth: wallThickness }]}
/>
</mesh>
{/* 道路、草坪系统 */}
<OutSideSurface />
</group>
);
};
技术亮点:
-
使用
ExtrudeGeometry
构建复杂建筑几何体 -
支持门洞、窗户等细节的布尔运算
-
材质贴图系统,包括墙体、地面、道路纹理
-
程序化生成道路和绿化系统
3. 立体货架系统
核心文件:packages/three/Canva/components/Factory/components/stereoscopicShelf.tsx
function StereoscopicShelf({ layout: { row, col, layer } }) {
// 动态计算货架尺寸
const lenX = useMemo(
() => row * locationSize.x + (row + 1) * shelfRackDiameter,
[row]
);
const lenY = useMemo(
() => shelfBottomHeight + layer * (locationSize.y + shelfRackDiameter),
[layer]
);
return (
<group>
{/* 横向支撑结构 */}
{Array(row + 1)
.fill(1)
.map((_, rowIndex) =>
Array(layer)
.fill(1)
.map((_, layerIndex) => (
<mesh
geometry={rowShelfRackGeometry}
material={shelfRackMaterial}
position={calculatePosition(rowIndex, layerIndex)}
/>
))
)}
{/* 轨道系统 */}
{Array(col + 1)
.fill(1)
.map((_, colIndex) => (
<mesh geometry={shelfTrackGeometry} material={shelfTrackMaterial} />
))}
</group>
);
}
设计特点:
-
参数化货架生成,支持任意行列层配置
-
精确的几何计算,确保货架结构合理
-
轨道系统集成,支持自动化设备运行
-
材质区分不同功能区域
4. 车辆动画系统
核心文件:packages/three/Canva/components/Factory/components/WarehouseMap.tsx
useFrame((_, delta) => {
// 动画数据驱动的车辆运动
const curList = animationData[index];
curList.forEach(({ el, type, hasGoods, radian }) => {
let dis = [0, 0, 0];
let rad = 0;
if (type === "move") dis = getDis(delta, cur);
if (type === "rotate") rad = getRad(delta, cur);
// 更新车辆状态
if (el === "mxwCar") {
setMxwCarData((state) => ({
position: [x + dis[0], y + dis[1], z + dis[2]],
radian: state.radian + rad,
hasGoods,
}));
}
});
});
动画特性:
-
基于关键帧的车辆运动系统
-
支持位移、旋转、货物装卸等复合动作
-
多车辆协调作业的时序控制
-
可配置的动画数据,易于调整运行轨迹
5. 交互式区域管理
核心文件:packages/three/Canva/components/Factory/components/area.tsx
const Area = ({ x, y, width, height, areaNumber }) => {
const [clicked, setClicked] = useState(false);
const handleClick = () => {
const box = new THREE.Box3().setFromCenterAndSize(
new THREE.Vector3(x, (y + textHeight) / 2, z),
new THREE.Vector3(width, textHeight, height)
);
controls.fitToBox(box, true); // 相机聚焦到选中区域
annotationRef.current?.show(); // 显示区域信息
};
return (
<group onClick={handleClick}>
<mesh ref={meshRef}>
<boxGeometry args={size} />
<lineSegments>
<edgesGeometry args={[new THREE.BoxGeometry(...size)]} />
<lineBasicMaterial color={strokeColor} />
</lineSegments>
</mesh>
<Annotation ref={annotationRef} data={annotationData} />
</group>
);
};
交互功能:
-
点击区域自动聚焦相机视角
-
区域边框高亮显示
-
信息标注系统,显示区域详细数据
-
响应式交互反馈
技术亮点
1. 先进的 Monorepo 架构
// turbo.json - 构建管道配置
{
"pipeline": {
"build": { "dependsOn": ["^build"], "outputs": ["dist/**"] },
"dev": { "cache": false, "persistent": true },
"lint": {}
}
}
-
并行构建:Turbo 智能缓存,提升构建效率
-
依赖管理:pnpm 工作空间减少磁盘占用
-
类型共享:统一的 TypeScript 配置
2. 双状态管理架构
Redux 用于全局应用状态:
// 用户权限、路由、系统配置
const store = configureStore({
reducer: {
user: userReducer,
menu: menuReducer,
},
});
MobX 用于 3D 场景状态:
// 3D对象位置、动画状态等
const threeStore = observable({
cameraPosition: [0, 100, 300],
selectedObject: null,
animationProgress: 0,
});
3. 声明式 3D 开发
// 传统Three.js写法
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
// React Three Fiber写法
<mesh>
<boxGeometry args={[1, 1, 1]} />
<meshBasicMaterial color="green" />
</mesh>;
开发与部署
开发环境启动
# 安装依赖
pnpm install
# 启动开发服务器
pnpm dev
# 并行启动所有应用(Turbo加速)
turbo run dev --concurrency 14
项目构建
# 构建所有包
pnpm build
# 代码检查
pnpm lint
# 清理构建产物
pnpm clean
源码地址
https://github.com/anyone-yuren/degital-twin-3d (opens in a new tab)