ai21.net
语言

可互动的果冻西瓜玩具

演示视频

可互动的果冻西瓜玩具 — 1

提示词

Build "Whole Melon": a single self-contained HTML file (all JS/CSS inline, no build step, no libraries) with a big whole watermelon made of glossy jelly that you can grab, wobble and cut into pieces with a knife. Render with raw WebGPU (WGSL); if WebGPU is missing, show a clean fallback card.

SHAPE AND MATERIAL
- The melon is a signed distance field: an ellipsoid (~32 cm long) lying on its side with a softly flattened belly.
- Layers by depth under the skin: dark-green skin with irregular darker stripes running pole to pole (seamless all the way around), a pale pith band, then translucent red flesh that brightens toward the rind. Add a pale yellow field spot on the belly, a stem scar at one end and a blossom end at the other.
- About 700 seeds in a three-lobed ring at roughly two thirds of the radius (teardrops, wide end pointing outward), plus tiny air bubbles. Mesh seeds only near cut faces; a seed the knife goes through is kept by one side and eased just under the new face, so it shows through a thin film of jelly.
- Three varieties: Crimson, Golden, Rosé.

PIECES AND CUTTING
- Every piece is the melon SDF clipped by the half-spaces of the cuts that made it, with the fresh edges rounded (smooth max). All pieces share the melon's original rest frame, so rind, pith, stripes and seeds stay exactly where they grew.
- Knife tool: the user draws a line across the melon. Read the stroke on top of what it crosses to get a vertical blade plane. For each piece the plane passes through, fit the piece's best rotation, carry the plane into rest space, and split the piece in two.
- Build the new pieces cooperatively (generators with a per-frame time budget) while a steel knife (brushed blade, wooden handle with rivets) lines up over the stroke and presses a groove into the jelly. Swap the new pieces in the moment the edge breaks through, carrying over the position and velocity of the flesh they came from, and let the blade wedge them apart as it sinks. Allow up to about 24 pieces and reject slivers.
- For each piece: a surface-nets render skin (evaluate only the blocks near the surface, one Newton step onto it), a hex lattice in the piece's principal frame with boundary nodes snapped onto the surface, and a fast barycentric embedding.

PHYSICS (XPBD on the CPU, fixed 60 Hz, 6 substeps)
- Cell-wise co-rotational shape matching (8-node cells, warm-started rotation, strain stiffening), tet volume constraints for near-incompressibility, rind firmer than flesh.
- Edge damping, plus damping of each piece's deformation relative to its rigid motion (never its fall or tumble), rolling resistance on the table, and sleep when calm.
- Piece-to-piece contact against each other's exact SDF in a best-fit frame; sleeping pieces act as walls. Floor contact with Coulomb friction.
- Hand tool: grab any piece and pull (soft patch attachment, with enough reach to drag pieces across a wide table). Scroll or a second finger twists while holding. Pinch or scroll zooms; dragging the empty table orbits the camera.

RENDERING (a photographic product shot)
- Procedural studio: pale paper sweep, overhead softbox, back-left strip light, cool fill card.
- Jelly: front faces refract the scene behind by the view-ray thickness (nearest-back-face pass), with Beer–Lambert absorption per material, milky scattering in the pith, a back-lit glow at thin edges, sugar glints, Fresnel studio reflections and GGX highlights.
- Seeds, bubbles and the knife are drawn before the jelly, so they are seen refracted through it.
- Normals follow the jelly's local deformation (cofactor of the node-averaged deformation gradient).
- A soft key shadow coloured by what the light crossed first (rosy through flesh, dark through rind), plus contact occlusion from a top-down height map. MSAA, Khronos PBR Neutral tone mapping.

UI (editorial, like a material study)
- Kicker "Material Studies / No. 010" and a big italic serif title "Whole / Melon."
- A panel with Tool (Hand / Knife), Variety, Firmness and Internal damping sliders, Nudge, Reset, ¼ speed, Show mesh and Pause.
- Live readouts: mass, volume %, kinetic energy, piece count. A collapsible "Inside the experiment" note.
- Responsive down to phones.

Quality bar: it should look and move like a real glossy jelly watermelon, and every cut face should look like a sliced jelly melon with seeds just under the surface. Test headlessly with screenshots: the whole melon, mid-cut, many pieces, a close-up of a cut face, and mobile.

中文译文

构建 "Whole Melon":一个单一的自包含 HTML 文件(所有 JS/CSS 内联,无构建步骤,无库),其中包含一个由光泽果冻制成的大个完整西瓜,你可以抓取、晃动并用刀切成块。使用原生 WebGPU(WGSL)渲染;如果没有 WebGPU,显示一张简洁的降级提示卡。

形状与材质
- 瓜体是一个有符号距离场:一个侧躺的椭球体(长约 32 cm),腹部柔和地压扁。
- 表皮下按深度分层:深绿色表皮,带有从一极延伸到另一极的不规则深色条纹(整圈无缝),一条浅色白瓤带,然后是半透明红色果肉,越靠近外皮越亮。在腹部添加一块淡黄色的着地斑,在一端添加一个瓜蒂疤痕,在另一端添加花蒂端。
- 约 700 颗种子,位于半径约三分之二处的三瓣环上(泪滴形,宽端朝外),外加细小的气泡。仅对切面附近的种子进行网格化;被刀切穿的一颗种子由其中一侧保留,并被轻轻移到新切面之下,让它透过一层薄薄的果冻显现出来。
- 三个品种:Crimson、Golden、Rosé。

切块与切割
- 每一块都是瓜体 SDF 被构成它的那些切割的半空间裁剪后的结果,新切出的边缘做了圆角处理(smooth max)。所有块共享瓜体原始的静止坐标系,因此瓜皮、白瓤、条纹和种子都停留在它们原本生长的确切位置。
- 刀具:用户横跨瓜体画一条线。读取叠加在它所穿过对象上的笔画,得到一个竖直的刀片平面。对于该平面穿过的每一块,拟合该块的最佳旋转,把平面带入静止空间,然后将该块一分为二。
- 以协作方式构建新的块(使用带每帧时间预算的生成器),同时一把钢刀(拉丝刀身、带铆钉的木柄)在笔画上方对准,并在果冻上压出一道凹槽。在刀刃切穿的那一刻换入新的块,沿用它们所来自的果肉的位置和速度,并让刀身在下沉时把它们楔开。最多允许约 24 块,并拒绝薄片。
- 对每一块:一个 surface-nets 渲染表皮(只对表面附近的块求值,并对其做一步 Newton 迭代)、一个位于该块主轴坐标系中的六面体晶格且边界节点吸附到表面,以及一个快速的重心坐标嵌入。

物理(CPU 上的 XPBD,固定 60 Hz,6 个子步)
- 逐单元的共旋转形状匹配(8 节点单元、热启动旋转、应变硬化)、用于近似不可压缩性的四面体体积约束,瓜皮比果肉更硬。
- 边阻尼,加上每一块相对于其刚体运动的形变阻尼(绝不是其下落或翻滚),桌面上的滚动阻力,以及静止时休眠。
- 块与块之间的接触在最佳拟合坐标系中针对彼此精确的 SDF 计算;休眠的块充当墙壁。与地板接触并带库仑摩擦。
- 手部工具:抓住任意一块并拉动(软性面片附着,作用范围足以在宽大的桌面上拖动各块)。按住时滚动或第二根手指会扭转。捏合或滚动可缩放;拖动空桌面则环绕相机。

渲染(一张摄影级产品照)
- 程序化影棚:浅色无缝背景纸、顶部柔光箱、左后方条形灯、冷色补光板。
- 果冻:正面按视线射线厚度(最近背面通道)折射其后的场景,并按材质应用 Beer–Lambert 吸收、白瓤中的乳浊散射、薄边缘处的背光发光、糖晶闪烁、Fresnel 影棚反射和 GGX 高光。
- 种子、气泡和刀在果冻之前绘制,因此会透过果冻被折射看到。
- 法线跟随果冻的局部形变(节点平均形变梯度的余子式)。
- 一片柔和的主光阴影,其颜色由光线最先穿过的材质决定(穿过果肉呈玫瑰色,穿过瓜皮呈深色),再加上来自俯视高度图的接触遮蔽。MSAA、Khronos PBR Neutral 色调映射。

界面(编辑风格,像一份材质研究)
- 眉题 "Material Studies / No. 010",以及大号斜体衬线标题 "Whole / Melon."
- 一个面板,包含 Tool (Hand / Knife)、Variety、Firmness 和 Internal damping 滑块,以及 Nudge、Reset、¼ speed、Show mesh 和 Pause。
- 实时读数:质量、体积 %、动能、块数。一段可折叠的 "Inside the experiment" 说明。
- 响应式,可适配到手机。

质量标准:它的外观和运动都应该像一个真实的、有光泽的果冻西瓜,每个切面都应该看起来像切开的果冻西瓜,种子就在表面之下。用截图进行无头测试:完整西瓜、切割中、许多块、一个切面特写,以及移动端。

溯源

原作者
vib3coded
发布日期
2026-10-02(由推文 ID 反解)
原始出处
查看原帖 ↗
收录来源
zhuyansen/awesome-opus-5.5-video · 2106056420131029473 · 未声明许可