Prompt specification
Build or customize the Three.js 3D scene "Pasta die extrusion model" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Pasta die extrusion model
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/pasta-die-extrusion-model-x0130
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows extruded pasta shapes. Push a symbolic dough block through interchangeable die plates; emerging strands inherit the selected opening shape and maintain continuous movement until the cutter divides them. Low-poly.
Working Three.js Starter (pasta-die-extrusion-model-x0130):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Pasta Press — Extrusion Study</title>
<style>
:root {
--bg: #141612;
--panel: rgba(24, 27, 22, 0.86);
--line: rgba(239, 231, 211, 0.15);
--text: #f0eadb;
--muted: #9c9f91;
--accent: #ef7045;
--gold: #e6ad43;
}
* { box-sizing: border-box; }
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 28px;
left: 32px;
display: flex;
align-items: flex-start;
gap: 14px;
}
.brand-mark {
width: 38px;
height: 38px;
border: 1px solid var(--accent);
display: grid;
place-items: center;
transform: rotate(45deg);
margin-top: 3px;
}
.brand-mark::before {
content: "";
width: 12px;
height: 12px;
background: var(--accent);
}
.eyebrow {
margin: 0 0 7px;
color: var(--accent);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 42px);
line-height: 0.95;
font-weight: 780;
letter-spacing: -0.045em;
text-transform: uppercase;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.06em;
}
.telemetry {
position: absolute;
top: 28px;
right: 28px;
width: 218px;
padding: 17px 18px;
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.panel-label {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 14px;
color: var(--muted);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: #7fc889;
box-shadow: 0 0 12px #7fc889;
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% { opacity: 0.35; transform: scale(0.8); }
}
.telemetry-row {
display: flex;
justify-content: space-between;
gap: 12px;
padding: 8px 0;
border-top: 1px solid rgba(255, 255, 255, 0.06);
font-size: 11px;
}
.telemetry-row span:first-child { color: var(--muted); }
.telemetry-row strong {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 600;
letter-spacing: 0.03em;
}
.die-panel {
position: absolute;
left: 28px;
bottom: 28px;
width: min(470px, calc(100vw - 56px));
padding: 18px;
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.die-heading {
display: flex;
justify-content: space-between;
align-items: end;
gap: 18px;
margin-bottom: 14px;
}
.die-heading h2 {
margin: 0;
font-size: 14px;
font-weight: 720;
letter-spacing: 0.02em;
text-transform: uppercase;
}
.die-heading p {
margin: 0;
color: var(--muted);
font: 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
}
.die-options {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 9px;
}
.die-button {
position: relative;
min-width: 0;
padding: 13px 10px 11px;
border: 1px solid rgba(255, 255, 255, 0.1);
color: var(--text);
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition: border-color 160ms, background 160ms, transform 160ms;
}
.die-button:hover {
border-color: rgba(239, 112, 69, 0.55);
background: rgba(239, 112, 69, 0.07);
transform: translateY(-1px);
}
.die-button.active {
border-color: var(--accent);
background: rgba(239, 112, 69, 0.11);
}
.die-button.active::after {
content: "";
position: absolute;
top: 7px;
right: 7px;
width: 5px;
height: 5px;
background: var(--accent);
border-radius: 50%;
}
.shape {
width: 22px;
height: 22px;
margin: 0 auto 9px;
background: var(--gold);
box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.12);
}
.shape.round { border-radius: 50%; }
.shape.square { border-radius: 1px; }
.shape.star {
clip-path: polygon(
50% 0%, 61% 35%, 98% 35%, 68% 56%, 79% 92%,
50% 71%, 21% 92%, 32% 56%, 2% 35%, 39% 35%
);
}
.die-name {
display: block;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.die-key {
display: block;
margin-top: 5px;
color: var(--muted);
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.hint {
position: absolute;
right: 28px;
bottom: 29px;
color: rgba(240, 234, 219, 0.5);
font: 9px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-align: right;
text-transform: uppercase;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: var(--bg);
color: var(--muted);
font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 500ms, visibility 500ms;
}
#loading.done {
opacity: 0;
visibility: hidden;
}
@media (max-width: 760px) {
.brand { top: 18px; left: 18px; }
.brand-mark { display: none; }
.subtitle { display: none; }
.telemetry { display: none; }
.die-panel {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 13px;
}
.die-heading p { display: none; }
.die-button { padding: 10px 6px 9px; }
.shape { width: 18px; height: 18px; }
.hint { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="overlay">
<header class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<p class="eyebrow">Extrusion study / 03</p>
<h1>Pasta Press</h1>
<p class="subtitle">Interchangeable dies · Continuous strand formation</p>
</div>
</header>
<aside class="telemetry" aria-label="Machine telemetry">
<div class="panel-label">
<span>Live process</span>
<span class="live-dot"></span>
</div>
<div class="telemetry-row">
<span>Die</span><strong id="readout-die">01 / ROUND</strong>
</div>
<div class="telemetry-row">
<span>Strands</span><strong>07 ACTIVE</strong>
</div>
<div class="telemetry-row">
<span>Flow</span><strong id="readout-flow">2.40 M/MIN</strong>
</div>
<div class="telemetry-row">
<span>Cutter</span><strong id="readout-rpm">128 RPM</strong>
</div>
<div class="telemetry-row">
<span>Pressure</span><strong>18.6 BAR</strong>
</div>
</aside>
<section class="die-panel" aria-label="Die plate selection">
<div class="die-heading">
<h2>Select die plate</h2>
<p id="shape-description">Ø 3.2 MM / ROUND PROFILE</p>
</div>
<div class="die-options">
<button class="die-button active" data-kind="round" aria-pressed="true">
<span class="shape round"></span>
<span class="die-name">Spaghetti</span>
<span class="die-key">01 / ROUND</span>
</button>
<button class="die-button" data-kind="square" aria-pressed="false">
<span class="shape square"></span>
<span class="die-name">Penne</span>
<span class="die-key">02 / SQUARE</span>
</button>
<button class="die-button" data-kind="star" aria-pressed="false">
<span class="shape star"></span>
<span class="die-name">Fusilli</span>
<span class="die-key">03 / STAR</span>
</button>
</div>
</section>
<div class="hint">
Drag to orbit · Scroll to zoom<br />
1–3 to switch die · Click a hanging plate
</div>
</div>
<div id="loading">Loading extrusion press…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x141612);
scene.fog = new THREE.Fog(0x141612, 12, 27);
const camera = new THREE.PerspectiveCamera(
39,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
container.appendChild(renderer.domElement);
const cameraTarget = new THREE.Vector3(0.55, -0.05, 0);
let cameraTheta = 0.69;
let cameraPhi = 1.16;
let cameraRadius = innerWidth < 700 ? 14.3 : 11.4;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.cos(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.sin(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xffefd1, 0x1d241f, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe4b0, 4.0);
keyLight.position.set(2.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xd7e1ff, 2.0);
rimLight.position.set(-5, 3, -6);
scene.add(rimLight);
const dieLight = new THREE.PointLight(0xff7b42, 24, 6, 2);
dieLight.position.set(-0.5, 1.0, 2.0);
scene.add(dieLight);
const materials = {
frame: new THREE.MeshStandardMaterial({
color: 0x343a35,
metalness: 0.72,
roughness: 0.42,
flatShading: true
}),
darkFrame: new THREE.MeshStandardMaterial({
color: 0x20241f,
metalness: 0.65,
roughness: 0.5,
flatShading: true
}),
brass: new THREE.MeshStandardMaterial({
color: 0x8c7043,
metalness: 0.66,
roughness: 0.38,
flatShading: true
}),
steel: new THREE.MeshStandardMaterial({
color: 0xa4aaa0,
metalness: 0.84,
roughness: 0.26,
flatShading: true
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x141714,
metalness: 0.05,
roughness: 0.88,
flatShading: true
}),
dough: new THREE.MeshStandardMaterial({
color: 0xe8c675,
roughness: 0.76,
metalness: 0,
flatShading: true
}),
tray: new THREE.MeshStandardMaterial({
color: 0x596157,
metalness: 0.48,
roughness: 0.6,
flatShading: true
}),
accent: new THREE.MeshStandardMaterial({
color: 0xdc613b,
emissive: 0x5d180b,
emissiveIntensity: 0.35,
roughness: 0.42,
metalness: 0.25,
flatShading: true
})
};
const flowUniform = { value: 0 };
const pastaMaterial = new THREE.MeshStandardMaterial({
color: 0xe5aa3e,
roughness: 0.65,
metalness: 0,
flatShading: true,
side: THREE.DoubleSide
});
pastaMaterial.onBeforeCompile = (shader) => {
shader.uniforms.uFlowTime = flowUniform;
shader.vertexShader = shader.vertexShader
.replace(
"#include <common>",
`#include <common>
attribute float aPhase;
varying float vFlowX;`
)
.replace(
"#include <begin_vertex>",
`#include <begin_vertex>
vFlowX = position.x + aPhase;`
);
shader.fragmentShader = shader.fragmentShader
.replace(
"#include <common>",
`#include <common>
uniform float uFlowTime;
varying float vFlowX;`
)
.replace(
"#include <color_fragment>",
`#include <color_fragment>
float stripeWave = 0.5 + 0.5 * sin(vFlowX * 5.8 - uFlowTime * 7.4);
float stripe = pow(stripeWave, 12.0);
diffuseColor.rgb *= 1.0 - stripe * 0.16;`
);
};
pastaMaterial.customProgramCacheKey = () => "pasta-flow-v1";
const cutMaterials = [
new THREE.MeshStandardMaterial({
color: 0xe8ad42,
roughness: 0.65,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xf0ba55,
roughness: 0.68,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xd99a34,
roughness: 0.7,
flatShading: true
})
];
function box(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderX(radius, length, material, x, y, z, parent = scene, segments = 12) {
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
segments
);
geometry.rotateZ(Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 22),
new THREE.MeshStandardMaterial({
color: 0x1c201a,
roughness: 0.93,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.55;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(22, 44, 0x6d735e, 0x343a31);
grid.position.y = -1.535;
grid.material.transparent = true;
grid.material.opacity = 0.18;
scene.add(grid);
// Machine rails and feet.
box(7.8, 0.14, 0.13, materials.frame, 0.55, -1.29, 0.73);
box(7.8, 0.14, 0.13, materials.frame, 0.55, -1.29, -0.73);
for (const x of [-2.75, -1.2, 0.6, 2.25, 4.2]) {
box(0.14, 0.13, 1.65, materials.darkFrame, x, -1.31, 0);
box(0.36, 0.18, 0.32, materials.rubber, x, -1.43, 0.57);
box(0.36, 0.18, 0.32, materials.rubber, x, -1.43, -0.57);
}
// Open feed chamber.
for (const x of [-2.9, -1.42]) {
for (const z of [-0.78, 0.78]) {
box(0.12, 2.12, 0.12, materials.frame, x, -0.18, z);
}
}
box(1.64, 0.12, 1.68, materials.frame, -2.16, 0.88, 0);
box(1.64, 0.12, 1.68, materials.frame, -2.16, -1.13, 0);
box(1.64, 0.08, 0.08, materials.brass, -2.16, 0.85, 0.78);
box(1.64, 0.08, 0.08, materials.brass, -2.16, 0.85, -0.78);
// Symbolic dough block.
const doughGroup = new THREE.Group();
scene.add(doughGroup);
const doughGeometry = new THREE.BoxGeometry(0.7, 0.63, 0.62);
const doughMesh = new THREE.Mesh(doughGeometry, materials.dough);
doughMesh.castShadow = true;
doughMesh.receiveShadow = true;
doughGroup.add(doughMesh);
const doughEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(doughGeometry),
new THREE.LineBasicMaterial({
color: 0x9c7436,
transparent: true,
opacity: 0.6
})
);
doughGroup.add(doughEdges);
const piston = cylinderX(
0.46,
0.16,
materials.steel,
-2.65,
-0.1,
0
);
const pistonRod = box(
1.0,
0.1,
0.1,
materials.steel,
-3.18,
-0.1,
0
);
const pistonHousing = cylinderX(
0.56,
0.85,
materials.darkFrame,
-3.0,
-0.1,
0,
scene,
10
);
// Die station.
const dieX = -1.08;
const strandStartX = -0.91;
const cutterX = 3.02;
const mainDieGroup = new THREE.Group();
scene.add(mainDieGroup);
const mainDieMaterial = new THREE.MeshStandardMaterial({
color: 0x9b8050,
metalness: 0.7,
roughness: 0.36,
emissive: 0x7a2710,
emissiveIntensity: 0,
flatShading: true
});
const apertures = [
{ u: -0.42, v: 0.31 },
{ u: 0.00, v: 0.38 },
{ u: 0.42, v: 0.31 },
{ u: -0.42, v: 0.00 },
{ u: 0.00, v: 0.00 },
{ u: 0.42, v: 0.00 },
{ u: 0.00, v: -0.35 }
];
function profileFor(kind) {
if (kind === "square") {
const r = 0.105;
return [
[-r, -r], [-r, r], [r, r], [r, -r]
];
}
if (kind === "star") {
const points = [];
for (let i = 0; i < 10; i++) {
const angle = Math.PI / 2 + i * Math.PI / 5;
const radius = i % 2 === 0 ? 0.123 : 0.054;
points.push([
Math.cos(angle) * radius,
Math.sin(angle) * radius
]);
}
return points;
}
const points = [];
for (let i = 0; i < 8; i++) {
const angle = i * Math.PI / 4;
points.push([
Math.cos(angle) * 0.087,
Math.sin(angle) * 0.087
]);
}
return points;
}
function makeDieGeometry(kind) {
const shape = new THREE.Shape();
shape.moveTo(-0.79, -0.69);
shape.lineTo(0.79, -0.69);
shape.lineTo(0.79, 0.69);
shape.lineTo(-0.79, 0.69);
shape.closePath();
const profile = profileFor(kind);
const scale = kind === "square" ? 1.18 : kind === "star" ? 1.1 : 1.12;
for (const aperture of apertures) {
const hole = new THREE.Path();
for (let i = profile.length - 1; i >= 0; i--) {
const x = aperture.u + profile[i][0] * scale;
const y = aperture.v + profile[i][1] * scale;
if (i === profile.length - 1) hole.moveTo(x, y);
else hole.lineTo(x, y);
}
hole.closePath();
shape.holes.push(hole);
}
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.17,
bevelEnabled: true,
bevelThickness: 0.018,
bevelSize: 0.014,
bevelSegments: 1,
steps: 1
});
geometry.rotateY(Math.PI / 2);
geometry.computeVertexNormals();
return geometry;
}
let currentKind = "round";
let mainDieMesh = null;
function rebuildMainDie() {
if (mainDieMesh) {
mainDieGroup.remove(mainDieMesh);
mainDieMesh.geometry.dispose();
}
mainDieMesh = new THREE.Mesh(
makeDieGeometry(currentKind),
mainDieMaterial
);
mainDieMesh.position.x = dieX;
mainDieMesh.castShadow = true;
mainDieMesh.receiveShadow = true;
mainDieGroup.add(mainDieMesh);
}
rebuildMainDie();
// Die mounting frame and fasteners.
for (const z of [-0.83, 0.83]) {
box(0.15, 1.75, 0.13, materials.frame, dieX, -0.02, z);
}
box(0.15, 0.13, 1.8, materials.frame, dieX, 0.85, 0);
for (const y of [-0.61, 0.59]) {
for (const z of [-0.68, 0.68]) {
cylinderX(0.035, 0.07, materials.steel, -0.88, y, z, scene, 8);
}
}
// Hanging die library.
const library = new THREE.Group();
scene.add(library);
cylinderX(
0.035,
2.55,
materials.steel,
-0.72,
1.27,
-0.58,
library,
8
);
const miniPlateMeshes = [];
const miniPlateMaterials = [];
const kinds = ["round", "square", "star"];
kinds.forEach((kind, index) => {
const material = new THREE.MeshStandardMaterial({
color: index === 0 ? 0xbd7845 : 0x716851,
metalness: 0.65,
roughness: 0.4,
emissive: 0x8e2d12,
emissiveIntensity: index === 0 ? 0.5 : 0,
flatShading: true
});
const mesh = new THREE.Mesh(makeDieGeometry(kind), material);
mesh.scale.setScalar(0.28);
mesh.position.set(-1.45 + index * 0.68, 1.55, -0.58);
mesh.castShadow = true;
mesh.userData.kind = kind;
library.add(mesh);
miniPlateMeshes.push(mesh);
miniPlateMaterials.push(material);
cylinderX(
0.025,
0.23,
materials.steel,
-1.45 + index * 0.68,
1.39,
-0.58,
library,
8
);
});
// Long strand geometry.
const strandsGroup = new THREE.Group();
scene.add(strandsGroup);
const strandMeshes = [];
const strandLength = cutterX - strandStartX;
function createStrandGeometry(aperture, kind, phase, index) {
const profile = profileFor(kind);
const profileCount = profile.length;
const ringCount = 34;
const vertexCount = ringCount * profileCount + 2;
const positions = new Float32Array(vertexCount * 3);
const phaseValues = new Float32Array(vertexCount);
const indices = [];
phaseValues.fill(phase);
for (let ring = 0; ring < ringCount - 1; ring++) {
for (let point = 0; point < profileCount; point++) {
const nextPoint = (point + 1) % profileCount;
const a = ring * profileCount + point;
const b = ring * profileCount + nextPoint;
const c = (ring + 1) * profileCount + nextPoint;
const d = (ring + 1) * profileCount + point;
indices.push(a, b, d, b, c, d);
}
}
const startCenter = ringCount * profileCount;
const endCenter = startCenter + 1;
for (let point = 0; point < profileCount; point++) {
const nextPoint = (point + 1) % profileCount;
indices.push(startCenter, nextPoint, point);
indices.push(
endCenter,
ringCount * profileCount + point,
ringCount * profileCount + nextPoint
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
geometry.setAttribute("aPhase", new THREE.BufferAttribute(phaseValues, 1));
geometry.setIndex(indices);
geometry.userData = {
profile,
profileCount,
ringCount,
baseY: aperture.v,
baseZ: -aperture.u,
phase,
index,
kind,
length: strandLength
};
updateStrandGeometry(geometry, 0);
return geometry;
}
function updateStrandGeometry(geometry, time) {
const {
profile,
profileCount,
ringCount,
baseY,
baseZ,
phase,
kind,
length
} = geometry.userData;
const positions = geometry.attributes.position.array;
for (let ring = 0; ring < ringCount; ring++) {
const x = (ring / (ringCount - 1)) * length;
const envelope = Math.min(1, x / 0.5);
const wave = x * 1.45 - time * 4.1 + phase;
const centerY =
baseY + Math.sin(wave) * 0.025 * envelope;
const centerZ =
baseZ + Math.cos(wave * 0.87 + phase) * 0.018 * envelope;
const rotation =
kind === "star"
? x * 0.72
: Math.sin(wave) * 0.025;
const cos = Math.cos(rotation);
const sin = Math.sin(rotation);
const ribScale =
kind === "star"
? 1 + Math.sin(x * 8.5 + phase) * 0.12
: kind === "square"
? 1 + Math.sin(x * 3.5) * 0.012
: 1;
for (let point = 0; point < profileCount; point++) {
const py = profile[point][0] * ribScale;
const pz = profile[point][1] * ribScale;
const index = (ring * profileCount + point) * 3;
positions[index] = x;
positions[index + 1] = centerY + py * cos - pz * sin;
positions[index + 2] = centerZ + py * sin + pz * cos;
}
}
const startCenter = ringCount * profileCount;
const endCenter = startCenter + 1;
const endWave = length * 1.45 - time * 4.1 + phase;
const endEnvelope = 1;
positions[startCenter * 3] = 0;
positions[startCenter * 3 + 1] = baseY;
positions[startCenter * 3 + 2] = baseZ;
positions[endCenter * 3] = length;
positions[endCenter * 3 + 1] =
baseY + Math.sin(endWave) * 0.025 * endEnvelope;
positions[endCenter * 3 + 2] =
baseZ + Math.cos(endWave * 0.87 + phase) * 0.018 * endEnvelope;
geometry.attributes.position.needsUpdate = true;
geometry.computeVertexNormals();
}
function rebuildStrands() {
for (const mesh of strandMeshes) {
strandsGroup.remove(mesh);
mesh.geometry.dispose();
}
strandMeshes.length = 0;
apertures.forEach((aperture, index) => {
const mesh = new THREE.Mesh(
createStrandGeometry(
aperture,
currentKind,
index * 1.37 + 0.4,
index
),
pastaMaterial
);
mesh.position.x = strandStartX;
mesh.castShadow = true;
mesh.receiveShadow = true;
strandsGroup.add(mesh);
strandMeshes.push(mesh);
});
}
rebuildStrands();
// Cutter wheel and support.
const cutterGroup = new THREE.Group();
cutterGroup.position.set(cutterX, 0.06, 0);
scene.add(cutterGroup);
const wheelRing = new THREE.Mesh(
new THREE.TorusGeometry(0.69, 0.055, 4, 18),
materials.steel
);
wheelRing.rotation.y = Math.PI / 2;
wheelRing.castShadow = true;
cutterGroup.add(wheelRing);
const bladeA = box(0.065, 1.28, 0.075, materials.steel, 0, 0, 0, cutterGroup);
const bladeB = box(0.065, 0.075, 1.28, materials.steel, 0, 0, 0, cutterGroup);
const cutterHub = cylinderX(
0.13,
0.2,
materials.accent,
0,
0,
0,
cutterGroup,
10
);
for (const z of [-0.96, 0.96]) {
box(0.13, 2.25, 0.13, materials.frame, cutterX, -0.08, z);
}
box(0.14, 0.13, 2.06, materials.frame, cutterX, 1.03, 0);
box(0.14, 0.13, 2.06, materials.frame, cutterX, -1.18, 0);
// Receiving tray.
const tray = new THREE.Group();
tray.position.set(3.95, -1.38, 0);
scene.add(tray);
box(2.05, 0.1, 2.05, materials.tray, 0, 0, 0, tray);
box(2.05, 0.32, 0.09, materials.tray, 0, 0.12, 1.0, tray);
box(2.05, 0.32, 0.09, materials.tray, 0, 0.12, -1.0, tray);
box(0.09, 0.32, 2.05, materials.tray, 1.0, 0.12, 0, tray);
box(0.09, 0.32, 2.05, materials.tray, -1.0, 0.12, 0, tray);
// Small 3D labels.
function makeLabel(text, x, y, z) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(18, 21, 17, 0.88)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "rgba(239, 112, 69, 0.8)";
context.lineWidth = 5;
context.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
context.fillStyle = "#f0eadb";
context.font = "700 38px ui-monospace, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.position.set(x, y, z);
sprite.scale.set(1.02, 0.225, 1);
scene.add(sprite);
}
makeLabel("DIE PLATE", -1.08, 0.88, 0.95);
makeLabel("CUTTER", 3.02, 1.08, 0.95);
// Cut pasta pieces.
const cutPieces = [];
function makeCutGeometry(kind, length) {
const profile = profileFor(kind);
const shape = new THREE.Shape();
profile.forEach((point, index) => {
if (index === 0) shape.moveTo(point[0], point[1]);
else shape.lineTo(point[0], point[1]);
});
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: length,
bevelEnabled: true,
bevelThickness: 0.016,
bevelSize: 0.012,
bevelSegments: 1,
steps: 1
});
geometry.rotateY(Math.PI / 2);
geometry.translate(-length / 2, 0, 0);
geometry.computeVertexNormals();
return geometry;
}
function spawnCutPiece() {
const aperture = apertures[
Math.floor(Math.random() * apertures.length)
];
const length = 0.34 + Math.random() * 0.25;
const mesh = new THREE.Mesh(
makeCutGeometry(currentKind, length),
cutMaterials[Math.floor(Math.random() * cutMaterials.length)]
);
mesh.position.set(
cutterX + 0.04 + Math.random() * 0.08,
aperture.v + (Math.random() - 0.5) * 0.1,
-aperture.u + (Math.random() - 0.5) * 0.08
);
mesh.rotation.set(
Math.random() * Math.PI,
Math.random() * Math.PI,
Math.random() * Math.PI
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
cutPieces.push({
mesh,
velocity: new THREE.Vector3(
0.75 + Math.random() * 0.8,
0.25 + Math.random() * 0.45,
(Math.random() - 0.5) * 0.45
),
age: 0,
landed: false
});
if (cutPieces.length > 52) {
const old = cutPieces.shift();
scene.remove(old.mesh);
old.mesh.geometry.dispose();
}
}
// Selection UI.
const buttons = [...document.querySelectorAll(".die-button")];
const shapeDescription = document.getElementById("shape-description");
const readoutDie = document.getElementById("readout-die");
const descriptions = {
round: "Ø 3.2 MM / ROUND PROFILE",
square: "4.0 MM / SQUARE PROFILE",
star: "5-POINT / RIBBED PROFILE"
};
const readoutNames = {
round: "01 / ROUND",
square: "02 / SQUARE",
star: "03 / STAR"
};
let platePulse = 0;
function selectDie(kind) {
if (!kinds.includes(kind)) return;
currentKind = kind;
platePulse = 1;
rebuildMainDie();
rebuildStrands();
buttons.forEach((button) => {
const active = button.dataset.kind === kind;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
miniPlateMaterials.forEach((material, index) => {
const active = kinds[index] === kind;
material.color.setHex(active ? 0xbd7845 : 0x716851);
material.emissiveIntensity = active ? 0.5 : 0;
});
miniPlateMeshes.forEach((mesh, index) => {
mesh.position.y = kinds[index] === kind ? 1.66 : 1.5;
});
shapeDescription.textContent = descriptions[kind];
readoutDie.textContent = readoutNames[kind];
}
buttons.forEach((button) => {
button.addEventListener("click", () => selectDie(button.dataset.kind));
});
addEventListener("keydown", (event) => {
if (event.key === "1") selectDie("round");
if (event.key === "2") selectDie("square");
if (event.key === "3") selectDie("star");
});
// Direct camera controls and die-library raycasting.
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let pointerDown = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
updatePointer(event);
if (pointerDown) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(dx) + Math.abs(dy) > 1) pointerMoved = true;
cameraTheta -= dx * 0.005;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.0045,
0.62,
1.43
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else {
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(miniPlateMeshes, false).length > 0;
renderer.domElement.style.cursor = hit ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointerDown = false;
if (!pointerMoved) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(miniPlateMeshes, false)[0];
if (hit) selectDie(hit.object.userData.kind);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.008,
7.6,
15.5
);
},
{ passive: false }
);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
const readoutFlow = document.getElementById("readout-flow");
const readoutRpm = document.getElementById("readout-rpm");
const clock = new THREE.Clock();
let cutTimer = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.04);
const time = clock.elapsedTime;
updateCamera();
flowUniform.value = time;
// Feed motion.
const feed = (Math.sin(time * 2.25) + 1) * 0.5;
doughGroup.position.x = -2.22 + feed * 0.8;
doughGroup.scale.x = 1 - feed * 0.08;
piston.position.x = doughGroup.position.x - 0.48;
pistonRod.position.x = (piston.position.x - 3.42) * 0.5;
pistonRod.scale.x = Math.max(0.08, piston.position.x - 3.42);
// Update flowing strands.
for (const strand of strandMeshes) {
updateStrandGeometry(strand.geometry, time);
}
// Cutter wheel.
cutterGroup.rotation.x = -time * 6.75;
cutterHub.rotation.x = time * 1.2;
// Continuous cutting.
cutTimer += delta;
while (cutTimer > 0.105) {
cutTimer -= 0.105;
spawnCutPiece();
}
// Falling cut pieces.
for (let i = cutPieces.length - 1; i >= 0; i--) {
const piece = cutPieces[i];
piece.age += delta;
if (!piece.landed) {
piece.velocity.y -= 4.4 * delta;
piece.mesh.position.addScaledVector(piece.velocity, delta);
piece.mesh.rotation.x += delta * 3.5;
piece.mesh.rotation.z += delta * 2.2;
if (piece.mesh.position.y < -1.25) {
piece.mesh.position.y = -1.25;
piece.landed = true;
if (Math.abs(piece.velocity.y) > 0.45) {
piece.velocity.y = -piece.velocity.y * 0.2;
} else {
piece.velocity.y = 0;
}
piece.velocity.x *= 0.72;
piece.velocity.z *= 0.72;
}
} else {
piece.mesh.position.x += piece.velocity.x * delta;
piece.mesh.position.z += piece.velocity.z * delta;
piece.velocity.x *= 0.9;
piece.velocity.z *= 0.9;
}
if (piece.age > 9 || piece.mesh.position.x > 5.4) {
scene.remove(piece.mesh);
piece.mesh.geometry.dispose();
cutPieces.splice(i, 1);
}
}
// Selection feedback.
if (platePulse > 0) {
platePulse = Math.max(0, platePulse - delta * 2.8);
const scale = 1 + Math.sin(platePulse * Math.PI) * 0.035;
mainDieGroup.scale.set(scale, scale, scale);
mainDieMaterial.emissiveIntensity = platePulse * 0.8;
} else {
mainDieGroup.scale.set(1, 1, 1);
mainDieMaterial.emissiveIntensity = 0;
}
readoutFlow.textContent = `${(2.36 + Math.sin(time * 1.7) * 0.06).toFixed(2)} M/MIN`;
readoutRpm.textContent = `${Math.round(128 + Math.sin(time * 2.1) * 4)} RPM`;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => loading.classList.add("done"));
</script>
</body>
</html>
```