建站难度 · 进阶#3D#网页#产品图
3D 产品展示页(代码建模)
用代码几何体搭一个可旋转的产品展示台,附参数面板与出图位。
难度 进阶:需要准备素材或背景,产出要自己筛一遍才能用
适用工具ClaudeGeminiChatGPT
请生成一个单文件 3D 产品展示页(index.html,Three.js 经 CDN importmap 引入,几何体全部代码建模,不加载外部模型)。
产品:【如 保温杯 / 耳机 / 机械键盘】。
要求:
1. 建模:把产品拆成基本几何体组合(圆柱、圆角盒、胶囊等),比例参考真实产品尺寸并注明假设;关键细节(按键、接口、logo 位)用几何体示意。
2. 材质:给 3 套可切换配色(PBR 材质参数),右上角色板切换。
3. 交互:自动缓慢旋转,用户拖拽时暂停、松手 3 秒后恢复;部件 hover 高亮并在侧栏显示该部件说明。
4. 参数面板:显示假设的尺寸 / 重量 / 材质,标注「参数为示意」。
5. 光影:影棚式三点布光 + 地面接触阴影,背景浅灰渐变,整体像产品官网而非技术 demo。
输出完整代码。文中【】为可替换变量,使用前请替换成你的具体内容。
变量填充:填一填直接用
已识别 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>3D 产品展示 · 保温柔杯</title>
<style>
html,body { margin:0; height:100%; overflow:hidden;
background:linear-gradient(180deg,#eceef2 0%,#dfe2e8 100%);
font-family:system-ui,"PingFang SC",sans-serif; }
#brand { position:fixed; top:20px; left:24px; color:#3a4152; }
#brand h1 { font-size:21px; margin:0; letter-spacing:1px; }
#brand p { font-size:13px; color:#8a90a0; margin:4px 0 0; }
#swatches { position:fixed; top:20px; right:24px; display:flex; gap:10px; }
.sw { width:34px; height:34px; border-radius:50%; cursor:pointer;
border:2px solid #fff; box-shadow:0 1px 4px rgba(0,0,0,.2);
transition:transform .15s; }
.sw:hover, .sw.on { transform:scale(1.15); }
#panel { position:fixed; bottom:22px; left:24px; background:rgba(255,255,255,.82);
backdrop-filter:blur(8px); border-radius:12px; padding:14px 18px;
font-size:13px; color:#3a4152; max-width:280px; line-height:1.7; }
#panel .tip { color:#a04000; font-size:12px; }
#hint { position:fixed; bottom:22px; right:24px; color:#8a90a0; font-size:13px; }
</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="brand"><h1>保温柔杯 · 500ml 保温杯</h1><p>拖拽旋转 · 悬停部件查看说明</p></div>
<div id="swatches">
<div class="sw on" data-i="0" style="background:#3d5a80"></div>
<div class="sw" data-i="1" style="background:#c2571b"></div>
<div class="sw" data-i="2" style="background:#e5e5e0"></div>
</div>
<div id="panel">
<b id="pName">杯身</b><br>
<span id="pDesc">双层不锈钢真空结构(示意)</span><br><br>
尺寸:高 26cm × 直径 6.5cm(假设)<br>
重量:约 340g(假设)|材质:304 不锈钢(假设)<br>
<span class="tip">参数为示意,非真实产品数据</span>
</div>
<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));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
// 浅灰渐变背景已由 CSS 提供,画布设透明
renderer.setClearColor(0x000000, 0);
const camera = new THREE.PerspectiveCamera(40, innerWidth/innerHeight, .1, 100);
camera.position.set(0, 3.2, 12);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true; controls.enablePan = false;
controls.minDistance = 7; controls.maxDistance = 20;
controls.minPolarAngle = Math.PI * .3; controls.maxPolarAngle = Math.PI * .62;
// 影棚三点布光:主光 + 补光 + 轮廓光
const key = new THREE.DirectionalLight(0xffffff, 2.4);
key.position.set(5, 8, 6); key.castShadow = true;
key.shadow.mapSize.set(1024, 1024);
scene.add(key);
const fill = new THREE.DirectionalLight(0xdde6ff, .8);
fill.position.set(-6, 3, 4); scene.add(fill);
const rim = new THREE.DirectionalLight(0xffffff, 1.2);
rim.position.set(0, 4, -8); scene.add(rim);
scene.add(new THREE.AmbientLight(0xffffff, .5));
// 地面(接收接触阴影)
const ground = new THREE.Mesh(new THREE.CircleGeometry(20, 48),
new THREE.ShadowMaterial({ opacity:.18 }));
ground.rotation.x = -Math.PI / 2; ground.receiveShadow = true;
scene.add(ground);
// ===== 代码建模:保温杯(比例假设:高 26cm 直径 6.5cm → 1 单位 ≈ 1cm) =====
const COLORS = [
{ body:0x3d5a80, lid:0x22334d, name:'雾蓝' },
{ body:0xc2571b, lid:0x8a3c10, name:'落日橙' },
{ body:0xe5e5e0, lid:0xc9c9c2, name:'月白' },
];
const product = new THREE.Group();
const parts = {}; // 部件 hover 用
// 杯身:圆柱(高 20cm)
const bodyMat = new THREE.MeshStandardMaterial(
{ color:COLORS[0].body, metalness:.55, roughness:.32 });
const body = new THREE.Mesh(new THREE.CylinderGeometry(3.25, 3.1, 20, 48), bodyMat);
body.castShadow = true; parts.body = { mesh:body, name:'杯身',
desc:'双层不锈钢真空结构(示意),外壁喷砂工艺' };
product.add(body);
// 杯盖:圆角盒近似(胶囊体旋轴 90° 变盖)+ 提环
const lidMat = new THREE.MeshStandardMaterial(
{ color:COLORS[0].lid, metalness:.2, roughness:.5 });
const lid = new THREE.Mesh(new THREE.CylinderGeometry(3.4, 3.4, 3.2, 48), lidMat);
lid.position.y = 11.6; lid.castShadow = true;
parts.lid = { mesh:lid, name:'杯盖', desc:'旋合式密封盖(示意),内置硅胶圈防漏' };
product.add(lid);
const loop = new THREE.Mesh(new THREE.TorusGeometry(1.1, .18, 12, 24), lidMat);
loop.position.y = 13.8; loop.castShadow = true;
parts.loop = { mesh:loop, name:'提环', desc:'便携提环,可挂背包扣具' };
product.add(loop);
// 饮水口按钮:小胶囊
const btn = new THREE.Mesh(new THREE.CapsuleGeometry(.5, 1.6, 8, 16), lidMat);
btn.rotation.z = Math.PI / 2; btn.position.set(0, 13.2, 0);
btn.castShadow = true;
parts.btn = { mesh:btn, name:'饮水按钮', desc:'单手按压开启饮水口' };
product.add(btn);
// 接口示意:杯底 USB 充电口(智能测温款假设)
const port = new THREE.Mesh(new THREE.BoxGeometry(1.2, .25, .5),
new THREE.MeshStandardMaterial({ color:0x1a1a1a, roughness:.8 }));
port.position.set(0, .12, 3.05);
parts.port = { mesh:port, name:'充电接口', desc:'Type-C 充电口,用于智能测温显示(假设配置)' };
product.add(port);
scene.add(product);
// 配色切换(3 套 PBR 参数)
document.querySelectorAll('.sw').forEach(sw => sw.onclick = () => {
document.querySelectorAll('.sw').forEach(s => s.classList.remove('on'));
sw.classList.add('on');
const c = COLORS[+sw.dataset.i];
bodyMat.color.set(c.body); lidMat.color.set(c.lid);
});
// hover 高亮 + 部件说明
const ray = new THREE.Raycaster(), mouse = new THREE.Vector2();
let hovered = null, resumeAt = 0;
addEventListener('pointermove', e => {
mouse.set(e.clientX/innerWidth*2-1, -(e.clientY/innerHeight)*2+1);
ray.setFromCamera(mouse, camera);
const hit = ray.intersectObject(product, true)[0];
const part = hit && Object.values(parts).find(p => p.mesh === hit.object);
Object.values(parts).forEach(p =>
p.mesh.material.emissive?.setHex(p.mesh.material === bodyMat ? 0x000000 : 0x000000));
if (part) {
hovered = part;
part.mesh.material.emissive = new THREE.Color(0x2a3a5c);
pName.textContent = part.name; pDesc.textContent = part.desc;
controls.autoRotate = false; // 拖拽/悬停暂停自转
resumeAt = performance.now() + 3000;
} else {
hovered?.mesh.material.emissive?.setHex(0x000000);
hovered = null;
}
});
// 自转:拖拽时暂停,松手 3 秒恢复
controls.autoRotate = true; controls.autoRotateSpeed = 1.1;
controls.addEventListener('start', () => { controls.autoRotate = false; });
controls.addEventListener('end', () => { resumeAt = performance.now() + 3000; });
const clock = new THREE.Clock();
function tick() {
requestAnimationFrame(tick);
if (!document.hidden) {
if (resumeAt && performance.now() > resumeAt && !hovered) {
controls.autoRotate = true; resumeAt = 0;
}
controls.update();
renderer.render(scene, camera);
}
}
tick();
addEventListener('resize', () => {
camera.aspect = innerWidth/innerHeight; camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
```
**实现说明**
- 建模:保温杯按「1 单位 ≈ 1cm」假设(高 26cm、直径 6.5cm),杯身圆柱 + 杯盖圆柱 + 提环圆环 + 饮水按钮胶囊 + Type-C 接口方块,全代码几何体。
- 材质:3 套 PBR 配色(雾蓝/落日橙/月白)右上角色板切换,metalness/roughness 按金属杯身与哑光杯盖分别设定。
- 交互:默认自转,拖拽或部件悬停时暂停、松手 3 秒恢复;部件 hover 高亮(emissive)并在左下侧栏显示说明。
- 影棚三点布光(主光投影 + 冷色补光 + 轮廓光)+ 地面接触阴影(ShadowMaterial)+ CSS 浅灰渐变背景,参数面板标注「参数为示意」。几何体代码建模并注明尺寸假设,3 套 PBR 配色切换、自转暂停/3 秒恢复、部件 hover 高亮与说明、三点布光加接触阴影的影棚感全部落实,整体观感向产品官网靠拢。
什么时候会翻车:代码建模的产品是几何体近似,和真实产品差异大,当展示 demo 行当商品页不行;「参数为示意」的标注不能替代真实规格。
想一次试多种填法做 A/B 对比?把这条提示词粘进Prompt 变量模板填充,把要换的部分写成 {{变量}},会自动生成表单并批量渲染出多个版本。
使用技巧
- 「注明尺寸假设」很重要,不然模型按感觉缩放,产品比例会失真。
- 想要更强的真实感,下一步让它输出「这套建模对应的建模软件参数」给 3D 同事参考。
同类提示词
动手做:配套工具
这条提示词是成品,下面几个工具能把它变成你要的那一版。
