three模拟三维空间无人机飞行避障轨迹到达目标可视化代码

代码语言:html

所属分类:三维

代码描述:three模拟三维空间无人机飞行避障轨迹到达目标可视化代码

代码标签: three 模拟 三维 空间 无人机 飞行 避障 轨迹 到达 目标 可视化 代码

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

<!doctype html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8" />
  <title>Three.js 三维无人机避障飞行演示</title>
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <style>
    html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1020; color: #eee; }
    #info {
      position: absolute; left: 12px; top: 10px; z-index: 10;
      padding: 8px 12px; background: rgba(0,0,0,0.35); border: 1px solid rgba(255,255,255,0.08); border-radius: 8px;
      font: 13px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    }
    #info a { color: #78a6ff; text-decoration: none; }
    #legend {
      position: absolute; right: 12px; top: 10px; z-index: 10;
      padding: 8px 12px; background: rgba(0,0,0,0.35); border: 1px solid rgba(255,255,255,0.08); border-radius: 8px;
      font: 12px/1.4 system-ui;
    }
    .pill { display: inline-block; padding: 2px 8px; border-radius:999px; margin-right:6px; font-size:11px; }
    .p-drone { background:#00bcd4; color:#00151a; }
    .p-goal { background:#7CFC00; color:#0a1c00; }
    .p-obst { background:#ffb3b3; color:#290000; }
    .p-sensor { background:#ffe58f; color:#302300; }
  </style>
</head>
<body>
  <div id="info">
    Three.js 无人机避障演示<br/>
    - 鼠标左键旋转,滚轮缩放,右键平移<br/>
    - 可拖动绿色目标点与障碍物(会自动贴地)<br/>
    - lil-gui 面板可调参数/重置/随机障碍<br/>
  </div>
  <div id="legend">
    <span class="pill p-drone">无人机</span>
    <span class="pill p-goal">目标</span>
    <span class="pill p-obst">障碍物</span>
    <span class="pill p-sensor">传感射线</span>
  </div>
      <script type="importmap">
{
 "imports":{
    "three":"//repo.bfw.wiki/bfwrepo/js/module/three/build/164/three.module.js",
    "three/addons/":"//repo.bfw.wiki/bfwrepo/js/module/three/examples/164/jsm/"
 }
}
</script>
  <script type="module">
    import * as THREE from 'three';
    import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
    import { DragControls } from 'three/addons/controls/DragControls.js';
    import { GUI } from '//repo.bfw.wiki/bfwrepo/js/lil-gui.esm.js';

    // ---------- 基本场景 ----------
    const renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.shadowMap.enabled = true;
    document.body.appendChild(renderer.domElement);

    const scene = new THREE.Scene();
    scene.background = new THREE.Color(0x0b1020);
    // 环境光 + 平行光
    scene.add(new THREE.AmbientLight(0xffffff, 0.25));
    const dirLight = new THREE.DirectionalLight(0xffffff, 1.0);
    dirLight.position.set(10, 20, 10);
    dirLight.castShadow = true;
    dirLight.shadow.mapSize.set(2048, 2048);
    scene.add(dirLight);

    // 相机与轨控
    const camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 0.1, 2000);
    camera.position.set(18, 14, 18);
    const controls = new OrbitControls(camera, renderer.domElement);
    controls.target.set(0, 2, 0);

    // 地面与网格
    const world = { half: 20, floorY: 0 };
    const ground = new THREE.Mesh(
      new THREE.PlaneGeometry(world.half*2, world.half*2, 1, 1),
      new TH.........完整代码请登录后点击上方下载按钮下载查看

网友评论0