three实现三维古代码头帆船场景代码

代码语言:html

所属分类:三维

代码描述:three实现三维古代码头帆船场景代码

代码标签: three 三维 古代 码头 帆船 场景 代码

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

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Golden Harbour · 古港风帆 - Three.js</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    html, body {
      width: 100%;
      height: 100%;
      overflow: hidden;
      background-color: #b8cad6;
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    }
    #canvas-container {
      width: 100%;
      height: 100%;
      position: relative;
    }
    .hud-top-left {
      position: absolute;
      top: 22px;
      left: 28px;
      color: rgba(255, 255, 255, 0.94);
      text-shadow: 0 2px 10px rgba(24, 42, 60, 0.45);
      pointer-events: none;
      user-select: none;
      z-index: 10;
    }
    .hud-title {
      font-size: 28px;
      font-weight: 600;
      letter-spacing: 0.5px;
      display: flex;
      align-items: baseline;
      gap: 10px;
    }
    .hud-title span.cn {
      font-size: 16px;
      font-weight: 400;
      opacity: 0.85;
    }
    .hud-subtitle {
      margin-top: 4px;
      font-size: 12px;
      letter-spacing: 1.2px;
      opacity: 0.8;
      text-transform: uppercase;
    }
    .hud-controls {
      position: absolute;
      bottom: 24px;
      left: 50%;
      transform: translateX(-50%);
      display: flex;
      gap: 8px;
      padding: 8px 12px;
      border-radius: 999px;
      background: rgba(20, 34, 48, 0.42);
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px);
      border: 1px solid rgba(255, 255, 255, 0.18);
      z-index: 10;
    }
    .hud-btn {
      border: none;
      background: transparent;
      color: rgba(255, 255, 255, 0.85);
      padding: 6px 14px;
      border-radius: 999px;
      font-size: 13px;
      cursor: pointer;
      transition: all 0.25s ease;
    }
    .hud-btn:hover {
      background: rgba(255, 255, 255, 0.18);
      color: #fff;
    }
    .hud-btn.active {
      background: rgba(255, 255, 255, 0.9);
      color: #1c2e3e;
      font-weight: 600;
    }
    .hud-hint {
      position: absolute;
      top: 24px;
      right: 28px;
      font-size: 12px;
      color: rgba(255, 255, 255, 0.8);
      background: rgba(20, 34, 48, 0.3);
      padding: 6px 12px;
      border-radius: 999px;
      backdrop-filter: blur(6px);
      pointer-events: none;
      z-index: 10;
    }
  </style>
  <script type="importmap">
    {
      "imports": {
        "three": "https://unpkg.com/three@0.169.0/build/three.module.js",
        "three/addons/": "https://unpkg.com/three@0.169.0/examples/jsm/"
      }
    }
  </script>
</head>
<body>
  <div id="canvas-container">
    <div class="hud-top-left">
      <div class="hud-title">Golden Harbour <span class="cn">古港风帆</span></div>
      <div class="hud-subtitle">3D · Three.js · GLSL Water &amp; Mist</div>
    </div>
    <div class="hud-hint">左键旋转 · 右键平移 · 滚轮缩放</div>
    <div class="hud-controls">
      <button class="hud-btn active" data-view="overview">港湾全景</button>
      <button class="hud-btn" data-view="pier">码头栈桥</button>
      <button class="hud-btn" data-view="ship">停泊帆船</button>
      <button class="hud-btn" data-view="lighthouse">灯塔远眺</button>
    </div>
  </div>

  <script type="module">
    import * as THREE from 'three';
    import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
    import { Water } from 'three/addons/objects/Water.js';

    // ==========================================
    // 1. 场景、渲染器与相机初始化
    // ==========================================
    const container = document.getElementById('canvas-container');
    const scene = new THREE.Scene();

    // 雾效营造清晨海港朦胧景深
    const fogColor = new THREE.Color(0xc5d6e2).........完整代码请登录后点击上方下载按钮下载查看

网友评论0