three实现三维林间小屋场景景色代码

代码语言:html

所属分类:其他

代码由deepseek-4.1 ai生成,可能有错误,仅供参考:点击查看提示词

代码描述:三维林间小屋场景景色

代码标签: 三维 林间 小屋 场景 景色 代码

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

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>森林乡间小屋 · Forest Cabin</title>
<style>
  * { margin:0; padding:0; box-sizing:border-box; }
  html, body { width:100%; height:100%; overflow:hidden; background:#0d1418; }
  canvas { display:block; }

  #hud {
    position: fixed; left: 22px; top: 20px; z-index: 10;
    font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #eef4f7;
    user-select: none;
    pointer-events: none;
  }
  #hud h1 {
    font-size: 19px; font-weight: 600; letter-spacing: 3px;
    text-shadow: 0 2px 14px rgba(0,0,0,.75), 0 0 2px rgba(0,0,0,.6);
    margin-bottom: 6px;
  }
  #hud .sub {
    font-size: 12px; letter-spacing: 1.4px; opacity: .72;
    text-shadow: 0 1px 8px rgba(0,0,0,.8);
  }
  #panel {
    position: fixed; left: 22px; bottom: 22px; z-index: 10;
    display: flex; gap: 10px; flex-wrap: wrap;
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  }
  .btn {
    pointer-events: auto;
    padding: 10px 18px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,.22);
    background: rgba(20, 32, 38, .46);
    backdrop-filter: blur(14px) saturate(140%);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    color: #dfe9ee;
    font-size: 13px;
    letter-spacing: 1.2px;
    cursor: pointer;
    transition: all .25s cubic-bezier(.4,0,.2,1);
    box-shadow: 0 6px 22px rgba(0,0,0,.32), inset 0 1px 0 rgba(255,255,255,.1);
  }
  .btn:hover { background: rgba(38, 60, 68, .62); transform: translateY(-1px); }
  .btn:active { transform: translateY(0) scale(.98); }
  .btn.on {
    border-color: rgba(255, 199, 120, .78);
    color: #ffe0ac;
    background: rgba(88, 60, 26, .55);
    box-shadow: 0 0 26px rgba(255,178,80,.36), 0 6px 22px rgba(0,0,0,.34), inset 0 1px 0 rgba(255,255,255,.16);
  }
  #loading {
    position: fixed; inset: 0; z-index: 50;
    display: flex; align-items: center; justify-content: center;
    background: #10181d; color: #9fb4c0;
    font-family: "PingFang SC", sans-serif; font-size: 13px; letter-spacing: 3px;
    transition: opacity .8s ease; pointer-events: none;
  }
  #loading.hide { opacity: 0; }
</style>
</head>
<body>

<div id="hud">
  <h1>森 林 乡 间 小 屋</h1>
  <div class="sub">拖动旋转 · 滚轮缩放 · 右键平移</div>
</div>

<div id="panel">
  <button class="btn on" id="btnLight">房屋灯光 · 开</button>
  <button class="btn" id="btnRotate">自动环视</button>
</div>

<div id="loading">正 在 生 长 森 林 …</div>

<script type="importmap">
{
  "imports": {
    "three": "https://unpkg.com/three@0.160.0/build/three.module.js",
    "three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
  }
}
</script>

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

/* =========================================================
   0. 工具函数
   ========================================================= */
const clamp = (v, a, b) => Math.min(b, Math.max(a, v));
const rand = (a, b) => a + Math.random() * (b - a);
const smoothstep = (a, b, x) => { const t = clamp((x - a) / (b - a), 0, 1); return t * t * (3 - 2 * t); };

function hash2(x, y) {
  const s = Math.sin(x * 127.1 + y * 311.7) * 43758.5453;
  return s - Math.floor(s);
}
function vnoise(x, y) {
  const xi = Math.floor(x), yi = Math.floor(y);
  const xf = x - xi, yf = y - yi;
  const u = xf * xf * (3 - 2 * xf), v = yf * yf * (3 - 2 * yf);
  const a = hash2(xi, yi), b = hash2(xi + 1, yi), c = hash2(xi, yi + 1), d = hash2(xi + 1, yi + 1);
  return a + (b - a) * u + (c - a) * v + (a - b - c + d) * u * v;
}
function fbm(x, y) {
  return vnoise(x, y) * 0.6 + vnoise(x * 2.13, y * 2.13) * 0.28 + vnoise(x * 4.37, y * 4.37) * 0.12;
}
function roundRectPath(ctx, x, y, w, h, r) {
  r = Math.min(r, w * 0.5, h * 0.5);
  ctx.beginPath();
  ctx.moveTo(x + r, y);
  ctx.lineTo(x + w - r, y); ctx.quadraticCurveTo(x + w, y, x + w, y + r);
  ctx.lineTo(x + w, y + h - r); ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
  ctx.lineTo(x + r, y + h); ctx.quadraticCurveTo(x, y + h, x, y + h - r);
  ctx.lineTo(x, y + r); ctx.quadraticCurveTo(x, y, x + r, y);
  ctx.closePath();
}

/* =========================================================
   1. 程序化纹理(Canvas)
   ========================================================= */
function makeTex(w, h, draw, rep) {
  const c = document.createElement('canvas');
  c.width = w; c.height = h;
  const ctx = c.getContext('2d');
  draw(ctx, w, h);
  const t = new THREE.CanvasTexture(c);
  t.wrapS = t.wrapT = THREE.RepeatWrapping;
  t.colorSpace = THREE.SRGBColorSpace;
  t.anisotropy = 4;
  if (rep) t.repeat.set(rep[0], rep[1]);
  return t;
}

/* 木纹 */
const woodTex = makeTex(256, 256, (ctx, w, h) => {
  ctx.fillStyle = '#ab8e6a'; ctx.fillRect(0, 0, w, h);
  for (let i = 0; i < 190; i++) {
    const y = Math.random() * h;
    const dark = Math.random() < 0.55;
    ctx.strokeStyle = dark
      ? `rgba(${92 + Math.random() * 40 | 0},${66 + Math.random() * 30 | 0},${43 + Math.random() * 20 | 0},${0.10 + Math.random() * 0.26})`
      : `.........完整代码请登录后点击上方下载按钮下载查看

网友评论0