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, maximum-scale=1.0, user-scalable=no" />
<title>树脂块微缩岛屿 · Resin Miniature Island Showcase</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body {
width: 100%;
height: 100%;
overflow: hidden;
background-color: #F5F5F0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
color: #2b2b28;
-webkit-font-smoothing: antialiased;
user-select: none;
}
#canvas-container {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
/* 极简美术馆式产品标签 */
.studio-hud {
position: fixed;
left: 28px;
bottom: 26px;
pointer-events: none;
z-index: 10;
display: flex;
flex-direction: column;
gap: 6px;
}
.studio-badge {
font-size: 10px;
letter-spacing: 0.22em;
text-transform: uppercase;
color: rgba(43, 43, 40, 0.55);
font-weight: 600;
}
.studio-title {
font-size: 18px;
font-weight: 500;
letter-spacing: 0.04em;
color: rgba(32, 34, 32, 0.88);
}
.studio-hints {
margin-top: 2px;
font-size: 11.5px;
color: rgba(43, 43, 40, 0.58);
letter-spacing: 0.02em;
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.studio-hints span::before {
content: "•";
margin-right: 6px;
color: #16948f;
}
/* lil-gui 浅色摄影棚风格定制 */
.lil-gui.root {
--background-color: rgba(250, 250, 246, 0.82);
--text-color: #2c2d2a;
--title-background-color: rgba(236, 236, 230, 0.88);
--title-text-color: #1d1e1c;
--widget-color: rgba(215, 216, 208, 0.72);
--hover-color: rgba(196, 198, 189, 0.9);
--focus-color: rgba(182, 185, 175, 0.95);
--number-color: #0e7c78;
--string-color: #0e7c78;
--font-size: 11.5px;
--input-font-size: 11px;
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid rgba(40, 42, 38, 0.08);
border-radius: 10px;
box-shadow: 0 12px 32px rgba(25, 28, 26, 0.08);
top: 18px !important;
right: 18px !important;
overflow: hidden;
}
@media (max-width: 640px) {
.studio-hud {
left: 16px;
bottom: 14px;
}
.studio-title {
font-size: 15px;
}
.studio-hints {
font-size: 10.5px;
}
.lil-gui.root {
top: 10px !important;
right: 10px !important;
max-width: 230px;
}
}
</style>
<!-- Three.js r170 官方模块导入映射 -->
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.170.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.170.0/examples/jsm/",
"lil-gui": "https://cdn.jsdelivr.net/npm/three@0.170.0/examples/jsm/libs/lil-gui.module.min.js"
}
}
</script>
</head>
<body>
<div id="canvas-container"></div>
<div class="studio-hud">
<div class="studio-badge">Studio Archive № 04 · Epoxy Diorama</div>
<div class="studio-title">树脂块微缩岛屿 · Coastal Cliff & Lagoon</div>
<div class="studio-hints">
<span>拖拽旋转视角</span>
<span>划过水面触发涟漪</span>
<span>移动光标体验果冻Q弹</span>
</div>
</div>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';
import * as BufferGeometryUtils from 'three/addons/utils/BufferGeometryUtils.js';
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
import { BokehPass } from 'three/addons/postprocessing/BokehPass.js';
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
import GUI from 'lil-gui';
// =========================================================================
// 0. 全局可调参数与常量定义
// =========================================================================
const DIORAMA = {
innerHalf: 2.0, // 内部地形与水体半宽 (4.0 x 4.0)
outerSize: 4.24, // 透明树脂外壳宽深
outerHeight: 3.16, // 透明树脂外壳总高 (底部 y = 0.0)
baseFloorY: 0.08, // 内部切面底座底面高度
maxBakeHeight: 2.8 // DataTexture 归一化最大高度
};
const params = {
waterColor: '#139490',
waveHeight: 0.022,
rippleStrength: 1.25,
sunAngle: 42,
sunElevation: 48,
waterLevel: 0.78,
jellyStiffness: 135,
dofStrength: 0.38,
rotateSpeed: 0.85,
autoRotate: false
};
// =========================================================================
// 1. 程序化 2D Simplex Noise 与分形噪声模块
// =========================================================================
function createNoiseGenerator(seed = 4219) {
// 确定性伪随机数生成器 (Mulberry32)
let s = seed >>> 0;
const rand = () => {
s += 0x6D2B79F5;
let t = Math.imul(s ^ (s >>> 15), 1 | s);
t ^= t + Math.imul(t ^ (t >>> 7), 61 | t);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
const perm = new Uint8Array(512);
const permMod12 = new Uint8Array(512);
const p = new Uint8Array(256);
for (let i = 0; i < 256; i++) p[i] = i;
for (let i = 255; i > 0; i--) {
const j = Math.floor(rand() * (i + 1));
const tmp = p[i];
p[i] = p[j];
p[j] = tmp;
}
for (let i = 0; i < 512; i++) {
perm[i] = p[i & 255];
permMod12[i] = perm[i] % 12;
}
const grad3 = [
[1, 1], [-1, 1], [1, -1], [-1, -1],
[1, 0], [-1, 0], [1, 0], [-1, 0],
[0, 1], [0, -1], [0, 1], [0, -1]
];
const F2 = 0.5 * (Math.sqrt(3.0) - 1.0);
const G2 = (3.0 - Math.sqrt(3.0)) / 6.0;
function noise2D(xin, yin) {
let n0 = 0, n1 = 0, n2 = 0;
.........完整代码请登录后点击上方下载按钮下载查看















网友评论0