threejs-towers
它能做什么
这个技能通过代码而不是加载模型文件来创建建筑,使用一组小型形状构建器。适合在网页上制作建筑场景、历史可视化或施工动画的开发者。
适用场景
- ✓当你希望在 Three.js 场景中不用模型文件,直接构建宝塔、城堡、穹顶或尖塔时。
- ✓当你希望制作建筑从地面逐层升起的施工动画时。
- ✓当多座建筑需要共享同一风格,仅通过不同参数区分时。
技能链接
https://github.com/MengTo/Skills/blob/main/agent-skills/web-design/threejs-towers/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能用代码在 Three.js 中生成一座宝塔,并做出从地面逐层建成的动画吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会编写一组简单的构建器,用于生成方块、棱柱、旋转体和屋顶,然后根据参数组装每座建筑。裁剪平面会逐层显示建筑,并按材质合并各部件,以保持场景流畅。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Three.js Towers
Architecture is the one subject where procedural generation pays immediately: buildings are made of repeated, parameterised parts, and once you have the vocabulary a second style costs a parameter set rather than a model.
Stand it in threejs-landscape and weather it with threejs-weather.
Build the vocabulary before the building
Write ten small builders that all append into shared vertex/normal/UV/index arrays, then never write raw geometry again:
face(P, uv) quad with a computed normal
box(cx,cy,cz, sx,sy,sz, ry, uvScale, rz)
prism(y0,y1, R0,R1, uv, capTop, capBot) square on plan
prismN(y0,y1, R0,R1, n, uv, capTop, capBot) any n-gon
sweepPlan(plan, y0,y1, steps, profile) an outline scaled up a curve
lathe(cx,cy,cz, y0,y1, profile, steps, seg) surface of revolution
ring / arc annulus on a face plane
fan(points, z, ry, cx, cy) filled polygon on a face
tube(points, r, sides) swept tube
That set covers a Japanese keep, a Chinese pagoda, an Ottoman dome, a Khmer prasat and a Vietnamese tháp. Each style becomes one assembly function plus a table of levels.
Merge by material, not by part. Six buildings drawn in 11–18 draw calls is the difference between 120fps and 30.
Winding is the bug you will hit most. A prism whose side faces are wound inward gets back-face culled and you find yourself looking at the inside of the far wall. Get one prism right, then copy its vertex order everywhere. When a surface goes missing, suspect winding before you suspect anything else.
Roofs are a function of position along the eave
The whole character of an East Asian roof — flat near the ridge, steepening, then curling up at the corners — comes from one function that maps (panel, position across, position down) to a point:
function roofPoint(o, p, u, t) {
const tc = Math.min(1, t);
const g = 1 - Math.pow(1 - tc, o.pow); // the sag of the slope
const corner = Math.pow(Math.abs(u), 2.0); // 0 mid-eave, 1 at hips
const flare = 1 + o.flare * corner * Math.pow(tc, 3.2);
const y = o.yT - (o.yT - o.yE) * g
+ o.lift * corner * Math.pow(tc, 2.6); // corners lift
return [ /* lerp inner edge → outer edge × flare */ ];
}
Six numbers give you every roof in the set: lift, tip, flare, pow, trunc, ridge. trunc is the one that is easy to miss — it lets a lower roof die cleanly behind the wall above it instead of poking through.
Math.pow(negative, 2.35) is NaN. Tiles that overshoot the eave push t past 1, and the whole roof silently disappears. Clamp tc = Math.min(1, t) and handle the overshoot as a separate linear term.
Non-square plans
prismN handles octagons and sixteen-sided drums. For anything with re-entrant corners — a Khmer prasat is a square pushed out on each axis and stepped back twice before the corner — build the outline once and sweep it:
const oct = [[1+P,0],[1+P,0.30],[1.0,0.30],[1.0,0.45],[0.90,0.45], ... ];
const half = oct.concat(oct.slice(0,-1).reverse().map(q => [q[1], q[0]]));
// mirror across the diagonal, then rotate four times
Then every storey is the same outline at a smaller scale, and the silhouette is coherent for free.
Deck the ledges. Where a storey steps back onto the one above, the gap between the two outlines is open. Fill it with a flat annulus on the plan or the tower reads as a stack of floating shelves with daylight between them.
Size detail to the surface it sits on
The most common modelling mistake is not the geometry, it is the proportion. A doorway sized for a face that turns out to be a third as wide spills onto the returns and reads as noise. Measure the face first, then size the door, the colonnettes and the pediment as fractions of it — and check that the pediment finishes under the cornice rather than through it.
The build animation is one clipping plane
Everything exists from the first frame. A plane facing down travels up, and every structural material clips against it:
renderer.localClippingEnabled = true;
const CLIP = new THREE.Plane(new THREE.Vector3(0, -1, 0), 0);
['stone','plaster','tile','timber', ...].forEach(k => {
MAT[k].clippingPlanes = [CLIP];
MAT[k].clipShadows = true; // or the shadow builds early
});
CLIP.constant = heightAt(t);
A clipped shell is hollow,
常见问题
需要三维模型文件吗?
不需要。建筑由代码和参数生成。
为什么要按材质合并部件?
该技能说明,这样可以减少绘制调用次数,从而保持较高的帧率。
可以只显示完成的建筑,不做动画吗?
可以。建造动画是在程序化生成的建筑之上额外添加的一步。
详情
作者的原始描述
Generate architecture procedurally in Three.js and film it assembling — a small geometry vocabulary that builds pagodas, castles, domes and spires from parameters instead of mesh files, hip roofs with flying eaves driven by a single profile function, and a clipping-plane build animation where everything below a rising line is finished work and scaffolding stands above it. Use for construction studies, architectural title sequences, procedural landmarks, or any hero object that should build itself rather than fade in.
repo: MengTo/Skills
热度
- GitHub 星标
- 7.2k
- 排名
- #13476
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
3d-cloth-material
7.2k帮你的智能体在 Three.js 中制作逼真的编织织物,包括纱线编织纹理、柔和光泽、自然褶皱、下摆和缝线。
3d-falling-leaves
7.2k帮你的智能体在 3D 场景中添加逼真的飘落树叶,树叶会翻滚、随风飘动,并在镜头移动时循环利用。
3d-four-seasons
7.2k帮你的智能体为 3D 场景添加春夏秋冬四季效果,无需重建场景即可改变植被、光线、天空和积雪。
3d-high-poly-models
7.2k帮你的智能体构建形状平滑、边缘可信的精细 3D 模型,然后制作在网页上运行流畅的轻量版本。