three+react实现三维扫地机器人算法运行模拟动画代码

代码语言:html

所属分类:三维

代码描述:three+react实现三维扫地机器人算法运行模拟动画代码,通过多个房屋环境模拟可视化扫地机器人运行过程算法。

代码标签: three react 三维 扫地 机器人 算法 运行 模拟 动画 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Robot Vacuum Simulator - 扫地机器人模拟</title>
    <!-- Tailwind CSS -->
    <script src="https://cdn.tailwindcss.com"></script>
    <!-- Babel for in-browser JSX compilation -->
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
    
    <style>
        body, html, #root { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background-color: #181a20; }
        /* 隐藏滚动条 */
        ::-webkit-scrollbar { width: 6px; height: 6px; }
        ::-webkit-scrollbar-track { background: transparent; }
        ::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
    </style>

    <!-- 
      Import Maps: 严格约束所有的基础依赖,避免多重 React 实例导致 useRef 崩溃
    -->
    <script type="importmap">
    {
        "imports": {
            "react": "https://esm.sh/react@18.2.0",
            "react/": "https://esm.sh/react@18.2.0/",
            "react-dom": "https://esm.sh/react-dom@18.2.0",
            "react-dom/": "https://esm.sh/react-dom@18.2.0/",
            "react-dom/client": "https://esm.sh/react-dom@18.2.0/client",
            "three": "https://esm.sh/three@0.160.0",
            "three/": "https://esm.sh/three@0.160.0/",
            "@react-three/fiber": "https://esm.sh/@react-three/fiber@8.15.12?external=react,react-dom,three",
            "@react-three/drei": "https://esm.sh/@react-three/drei@9.96.1?external=react,react-dom,three,@react-three/fiber",
            "zustand": "https://esm.sh/zustand@4.5.0?external=react",
            "framer-motion": "https://esm.sh/framer-motion@11.0.3?external=react,react-dom",
            "lucide-react": "https://esm.sh/lucide-react@0.323.0?external=react"
        }
    }
    </script>
</head>
<body>
    <div id="root"></div>

    <script type="text/babel" data-type="module">
        import React, { useState, useEffect, useRef, useMemo } from 'react';
        import { createRoot } from 'react-dom/client';
        import * as THREE from 'three';
        import { Canvas, useFrame, useThree } from '@react-three/fiber';
        import { OrbitControls, Grid, Html, Line } from '@react-three/drei';
        import { create } from 'zustand';
        import { motion, AnimatePresence } from 'framer-motion';
        import { 
            Sun, Moon, Play, Pause, Maximize, Code, X, Save, 
            Grid3X3, Layers, Trash2, Wind, Zap, BrainCircuit,
            ChevronLeft, ChevronRight
        } from 'lucide-react';

        // --- 核心常量与初始数据 ---
        const GRID_SIZE = 100;
        const RESOLUTION = 0.2;
        const CELL_STATE = { UNKNOWN: 0, FREE: 1, OBSTACLE: 2, CLEANED: 3 };

        const THEMES = [
            { id: "dark", name: "Dark", primary: "#06b6d4", secondary: "#1e3a8a", background: "#181a20", grid: "#3a404d", wallEdge: "#ffffff" },
            { id: "light", name: "Light", primary: "#0ea5e9", secondary: "#e0f2fe", background: "#f8fafc", grid: "#94a3b8", wallEdge: "#334155" }
        ];

        const DEFAULT_FLOOR_PLAN = {
            rooms: [
                { id: "living-room", name: "Living Room", height: 3, color: "#f9a5cf", polygon: [{x: 0, y: 0}, {x: 7, y: 0}, {x: 6, y: 5}, {x: 0, y: 5}] },
                { id: "bedroom", name: "Master Bedroom", height: 3, color: "#f3de87", polygon: [{x: 7, y: 0}, {x: 10, y: 0}, {x: 10, y: 4}, {x: 6, y: 4}] },
                { id: "kitchen", name: "Kitchen", height: 3, color: "#ecfccb", polygon: [{x: 6, y: 4}, {x: 10, y: 4}, {x: 10, y: 7}, {x: 6, y: 7}] },
                { id: "bathroom", name: "Bathroom", height: 3, color: "#afeef4", polygon: [{x: 0, y: 5}, {x: 3, y: 5}, {x: 3, y: 8}, {x: 0, y: 8}] },
                { id: "entry-hall", name: "Entry", height: 3, color: "#afc8fb", polygon: [{x: 3, y: 5}, {x: 6, y: 5}, {x: 6, y: 7}, {x: 3, y: 8}] },
                { id: "study", name: "Study", height: 3, color: "#e9d5ff", polygon: [{x: -4, y: 0}, {x: 0, y: 0}, {x: 0, y: 5}, {x: -4, y: 5}] },
                { id: "balcony", name: "Balcony", height: 1, color: "#e2e8f0", polygon: [{x: 0, y: -2}, {x: 6, y: -2}, {x: 7, y: 0}, .........完整代码请登录后点击上方下载按钮下载查看

网友评论0