素材阁
舆情大数据服务

洞见舆情 先声夺人

全网声音,一屏尽览 · 7×24 监测 · 分钟级预警

详情咨询 132 4126 7144了解服务 ↗
推广
建站难度 · 进阶#网页#3D#交互

Three.js 3D 交互场景页

生成一个可拖拽旋转的 3D 展示页,含光照、材质与性能兜底。

难度 进阶:需要准备素材或背景,产出要自己筛一遍才能用

适用工具ClaudeGeminiChatGPT

提示词

请用 Three.js 生成一个单文件 3D 交互网页(index.html,通过 CDN importmap 引入 three)。
场景主题:【如 漂浮的低多边形小岛 / 发光水晶洞穴 / 产品旋转展示台】。
要求:
1. 3D 内容:用代码几何体与材质搭建(不加载外部模型文件),主体有 3 层以上结构细节。
2. 交互:鼠标拖拽旋转(OrbitControls,限制俯仰角)、滚轮缩放(限制距离范围)、双击复位。
3. 光影:一个主光源 + 环境光 + 雾效,色调统一;加 2~3 个缓慢动画(浮动、旋转、粒子)。
4. 性能兜底:pixelRatio 上限 2;窗口失焦时暂停渲染循环;提供「关闭动效」开关。
5. UI:左上角标题与一句说明,右下角操作提示(拖拽旋转 / 滚轮缩放),样式融入场景不做大白框。
输出完整可运行代码。

文中【】为可替换变量,使用前请替换成你的具体内容。

变量填充:填一填直接用

已识别 1 个【】占位变量,填写后一键生成成品提示词;留空的变量所在行会自动删除,不会留下占位符。

示例输出

下面是按这条提示词填完后的实际产出,可直接对照判断该填成什么样。

产出的样子

```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>漂浮的低多边形小岛</title>
<style>
  html,body { margin:0; height:100%; overflow:hidden; background:#0b1026;
              font-family:system-ui,"PingFang SC",sans-serif; }
  #ui { position:fixed; top:18px; left:20px; color:#cdd6f4; pointer-events:none; }
  #ui h1 { font-size:20px; margin:0 0 6px; font-weight:600; }
  #ui p { font-size:13px; color:#8a93b8; margin:0; }
  #hint { position:fixed; right:20px; bottom:16px; color:#8a93b8; font-size:13px;
          background:rgba(11,16,38,.55); padding:8px 12px; border-radius:8px; }
  #toggle { position:fixed; right:20px; top:18px; color:#cdd6f4; font-size:13px;
            background:rgba(255,255,255,.08); border:1px solid rgba(255,255,255,.18);
            border-radius:8px; padding:6px 12px; cursor:pointer; }
</style>
<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>
</head>
<body>
<div id="ui"><h1>漂浮的低多边形小岛</h1><p>黄昏色调 · 拖拽探索这座会呼吸的岛</p></div>
<button id="toggle">关闭动效</button>
<div id="hint">拖拽旋转 · 滚轮缩放 · 双击复位</div>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

const renderer = new THREE.WebGLRenderer({ antialias:true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2)); // 性能兜底:上限 2
document.body.appendChild(renderer.domElement);

const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1026);
scene.fog = new THREE.FogExp2(0x0b1026, 0.028); // 雾效统一色调

const camera = new THREE.PerspectiveCamera(50, innerWidth/innerHeight, .1, 200);
camera.position.set(14, 9, 14);

const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.minDistance = 8; controls.maxDistance = 40;   // 缩放限制
controls.minPolarAngle = Math.PI * 0.18;
controls.maxPolarAngle = Math.PI * 0.52;               // 俯仰角限制
controls.addEventListener('dblclick', () => controls.reset());

// 光照:主光源 + 环境光
scene.add(new THREE.AmbientLight(0x536493, 0.7));
const sun = new THREE.DirectionalLight(0xffb86b, 1.6);
sun.position.set(12, 14, 6);
scene.add(sun);

// 主体三层结构:岛屿基座 / 悬浮石阵 / 发光水晶
const islandGroup = new THREE.Group();
const rockMat = new THREE.MeshStandardMaterial({ color:0x5d6b8a, flatShading:true });
const grassMat = new THREE.MeshStandardMaterial({ color:0x4c8f6a, flatShading:true });

// 层 1:岛屿基座(倒锥 + 表面草皮块)
const base = new THREE.Mesh(new THREE.ConeGeometry(6, 9, 7), rockMat);
base.rotation.x = Math.PI; base.position.y = -1; islandGroup.add(base);
for (let i = 0; i < 9; i++) {
  const patch = new THREE.Mesh(new THREE.BoxGeometry(1.4, .5, 1.4), grassMat);
  const a = i / 9 * Math.PI * 2;
  patch.position.set(Math.cos(a) * 3.6, 3.55, Math.sin(a) * 3.6);
  patch.rotation.y = a; islandGroup.add(patch);
}
// 层 2:悬浮石阵(三颗绕岛缓慢旋转的浮石)
const stones = new THREE.Group();
[[6.5, 4.5, 0], [-5.5, 6, 3.5], [-2, 7.5, -5.5]].forEach(([x, y, z]) => {
  const s = new THREE.Mesh(new THREE.DodecahedronGeometry(.8), rockMat);
  s.position.set(x, y, z); stones.add(s);
});
islandGroup.add(stones);
// 层 3:发光水晶簇(emissive 材质 + 点光源)
const crystalMat = new THREE.MeshStandardMaterial({
  color:0x7fd4ff, emissive:0x3fa7ff, emissiveIntensity:1.4, flatShading:true });
const crystal = new THREE.Group();
[1.3, .8, .55].forEach((h, i) => {
  const c = new THREE.Mesh(new THREE.ConeGeometry(.35, h, 5), crystalMat);
  c.position.set(i * .55 - .5, 4 + h / 2, i * .3 - .4);
  c.rotation.z = (i - 1) * .22; crystal.add(c);
});
const glow = new THREE.PointLight(0x3fa7ff, 2.2, 16);
glow.position.set(0, 5, 0); islandGroup.add(glow);
islandGroup.add(crystal);
scene.add(islandGroup);

// 粒子:缓慢上浮的光点
const pGeo = new THREE.BufferGeometry();
const pN = 180, pos = new Float32Array(pN * 3);
for (let i = 0; i < pN; i++) {
  pos[i*3] = (Math.random()-.5) * 30; pos[i*3+1] = Math.random() * 16 - 4;
  pos[i*3+2] = (Math.random()-.5) * 30;
}
pGeo.setAttribute('position', new THREE.BufferAttribute(pos, 3));
const particles = new THREE.Points(pGeo,
  new THREE.PointsMaterial({ color:0x9fc4ff, size:.12, transparent:true, opacity:.7 }));
scene.add(particles);

// 缓慢动画 + 失焦暂停 + 动效开关
let animateOn = true;
const clock = new THREE.Clock();
function tick() {
  requestAnimationFrame(tick);
  if (!animateOn || document.hidden) return;      // 失焦暂停渲染
  const t = clock.getElapsedTime();
  islandGroup.position.y = Math.sin(t * .8) * .3;           // 岛屿浮动
  crystal.rotation.y = t * .4;                              // 水晶旋转
  stones.rotation.y = t * .15;                              // 石阵旋转
  particles.rotation.y = t * .03;
  const arr = pGeo.attributes.position.array;
  for (let i = 0; i < pN; i++) arr[i*3+1] += .004;          // 粒子上浮
  if (arr[1] > 14) arr[1] = -4;
  pGeo.attributes.position.needsUpdate = true;
  controls.update();
  renderer.render(scene, camera);
}
tick();
document.getElementById('toggle').onclick = e => {
  animateOn = !animateOn;
  e.target.textContent = animateOn ? '关闭动效' : '开启动效';
};
addEventListener('resize', () => {
  camera.aspect = innerWidth/innerHeight; camera.updateProjectionMatrix();
  renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
```

**实现说明**

- 主体三层结构:岛屿基座(锥体+草皮块)/ 悬浮石阵(三颗绕转浮石)/ 发光水晶簇(自发光 + 点光源)。
- 交互完整:OrbitControls 俯仰角与缩放距离双限位,双击调用 controls.reset() 复位。
- 三个缓慢动画(岛屿浮动、水晶旋转、粒子上浮)+ 一次主光源暖色与雾效统一黄昏色调。
- 性能兜底:pixelRatio 上限 2、document.hidden 时暂停渲染、「关闭动效」开关右上角。

代码几何体搭出三层结构细节,OrbitControls 俯仰/距离限位、双击复位、失焦暂停、pixelRatio 上限与动效开关全部落实,UI 样式融入场景无大白框,CDN importmap 可直接运行。

什么时候会翻车:CDN importmap 依赖外网,离线打开必白屏;模型没真跑过渲染,`OrbitControls` 的导入路径和 three 版本容易对不上,先本地跑通再改。

想一次试多种填法做 A/B 对比?把这条提示词粘进Prompt 变量模板填充,把要换的部分写成 {{变量}},会自动生成表单并批量渲染出多个版本。

使用技巧

这条提示词收录在 1 套精选合集里

合集按真实工作流排好了前后顺序,点进合集可以看「它前面该做什么、后面接什么」。

同类提示词

动手做:配套工具

这条提示词是成品,下面几个工具能把它变成你要的那一版。