Prompt specification
Build or customize the Three.js 3D scene "Two-Part Mold Around a Simple Token" 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: Two-Part Mold Around a Simple Token
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-part-mold-around-a-simple-token-x2049
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this cutaway scene: Model two mold halves surrounding an original geometric token with a visible parting plane. Show complementary cavities and ensure the halves separate without intersecting the token.
Working Three.js Starter (two-part-mold-around-a-simple-token-x2049):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Three.js Cutaway Mold — Geometric Token</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(8, 19, 34, 0.78);
--border: rgba(151, 213, 255, 0.18);
--text: #eaf7ff;
--muted: #92abc0;
--cyan: #60f2dc;
--gold: #ffc56e;
--coral: #ff826d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111f;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(340px, calc(100vw - 44px));
padding: 20px;
border: 1px solid var(--border);
border-radius: 18px;
color: var(--text);
background: var(--panel);
box-shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(16px) saturate(125%);
-webkit-backdrop-filter: blur(16px) saturate(125%);
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 24px;
line-height: 1.12;
letter-spacing: -0.035em;
}
.description {
margin: 11px 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
font-size: 12px;
font-weight: 650;
}
output {
min-width: 58px;
color: var(--cyan);
text-align: right;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0 15px;
border-radius: 99px;
outline: none;
appearance: none;
background: linear-gradient(
90deg,
rgba(96, 242, 220, 0.75),
rgba(96, 242, 220, 0.16)
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #102337;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 16px rgba(96, 242, 220, 0.65);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #102337;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 16px rgba(96, 242, 220, 0.65);
}
button {
width: 100%;
padding: 11px 14px;
border: 1px solid rgba(96, 242, 220, 0.35);
border-radius: 11px;
color: #06141e;
background: var(--cyan);
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition: transform 150ms ease, filter 150ms ease;
}
button:hover {
filter: brightness(1.08);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px 12px;
margin-top: 18px;
padding-top: 16px;
border-top: 1px solid var(--border);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 11px;
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
box-shadow: 0 0 9px currentColor;
}
.swatch.token {
color: var(--cyan);
background: var(--cyan);
}
.swatch.cavity {
color: var(--gold);
background: var(--gold);
}
.swatch.cut {
color: var(--coral);
background: var(--coral);
}
.swatch.plane {
color: #72aaff;
background: #72aaff;
}
.fit-status {
margin-top: 15px;
padding: 10px 11px;
border: 1px solid rgba(96, 242, 220, 0.18);
border-radius: 10px;
color: #aee9df;
background: rgba(96, 242, 220, 0.055);
font-size: 10px;
line-height: 1.45;
}
.hint {
position: fixed;
z-index: 10;
right: 20px;
bottom: 18px;
padding: 10px 13px;
border: 1px solid var(--border);
border-radius: 10px;
color: var(--muted);
background: rgba(8, 19, 34, 0.66);
font-size: 11px;
backdrop-filter: blur(10px);
pointer-events: none;
}
@media (max-width: 650px) {
.panel {
top: 12px;
left: 12px;
width: min(300px, calc(100vw - 24px));
padding: 15px;
}
h1 {
font-size: 20px;
}
.description {
margin-bottom: 13px;
}
.legend {
display: none;
}
.hint {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<section class="panel">
<div class="eyebrow">Cutaway / Mold Study</div>
<h1>Geometric Token Mold</h1>
<p class="description">
Two sectioned mold halves surround a faceted original. Gold surfaces show
the negative cavities; the cyan plane marks the parting line.
</p>
<div class="control-row">
<label for="separation">Exploded separation</label>
<output id="separationValue">0.00</output>
</div>
<input
id="separation"
type="range"
min="0"
max="1.5"
step="0.01"
value="0"
aria-label="Mold half separation"
/>
<button id="toggle" type="button">Separate halves</button>
<div class="legend">
<div class="legend-item">
<span class="swatch token"></span>
Original token
</div>
<div class="legend-item">
<span class="swatch cavity"></span>
Negative cavity
</div>
<div class="legend-item">
<span class="swatch cut"></span>
Cut section
</div>
<div class="legend-item">
<span class="swatch plane"></span>
Parting plane
</div>
</div>
<div id="fitStatus" class="fit-status">
FIT CHECK: PASS · 0.08 radial clearance
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.FogExp2(0x07111f, 0.028);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb9dcff, 0x07111f, 2.1));
const keyLight = new THREE.DirectionalLight(0xffffff, 4.2);
keyLight.position.set(4.5, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const cyanRim = new THREE.PointLight(0x36e9ff, 26, 14, 2);
cyanRim.position.set(-4, 2.5, 4);
scene.add(cyanRim);
const warmRim = new THREE.PointLight(0xff9c55, 18, 12, 2);
warmRim.position.set(4, -1, 3);
scene.add(warmRim);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const moldMaterial = new THREE.MeshStandardMaterial({
color: 0x263c50,
metalness: 0.72,
roughness: 0.34,
side: THREE.DoubleSide
});
const cavityMaterial = new THREE.MeshStandardMaterial({
color: 0xffb85b,
emissive: 0x4b2606,
emissiveIntensity: 0.28,
metalness: 0.68,
roughness: 0.26,
side: THREE.DoubleSide
});
const sectionMaterial = new THREE.MeshStandardMaterial({
color: 0xd75d4d,
emissive: 0x3b0e08,
emissiveIntensity: 0.15,
metalness: 0.36,
roughness: 0.5,
side: THREE.DoubleSide
});
const sectionEdgeMaterial = new THREE.LineBasicMaterial({
color: 0xffc28c,
transparent: true,
opacity: 0.8,
depthWrite: false
});
const tokenMaterial = new THREE.MeshStandardMaterial({
color: 0x5cf4d7,
emissive: 0x073f39,
emissiveIntensity: 0.42,
metalness: 0.32,
roughness: 0.2,
flatShading: true
});
const tokenEdgeMaterial = new THREE.LineBasicMaterial({
color: 0xe2fff9,
transparent: true,
opacity: 0.82
});
const glowMaterial = new THREE.MeshBasicMaterial({
color: 0x60f2dc,
transparent: true,
opacity: 0.65,
depthWrite: false
});
// -------------------------------------------------------------------------
// Mold geometry
//
// The cavity profile is generated from the token's profile with a constant
// 0.08-unit radial clearance. The token is faceted, while the cavity is a
// slightly polygonal circular fit. Therefore the token remains entirely
// inside the cavity at every height.
//
// The front 112-degree sector is omitted to create the cutaway. Radial
// section caps close the two exposed cut faces.
// -------------------------------------------------------------------------
const TAU = Math.PI * 2;
const MOLD_SEGMENTS = 64;
const TOKEN_SEGMENTS = 16;
const RADIAL_CLEARANCE = 0.08;
const PHI_START = THREE.MathUtils.degToRad(56);
const PHI_LENGTH = THREE.MathUtils.degToRad(248);
// Radius / height profile of the upper mold.
const upperMoldProfile = [
new THREE.Vector2(2.34, 0.00),
new THREE.Vector2(2.52, 0.12),
new THREE.Vector2(2.52, 1.38),
new THREE.Vector2(2.36, 1.56),
new THREE.Vector2(0.00, 1.56),
new THREE.Vector2(0.00, 1.24),
new THREE.Vector2(0.26, 1.08), // cavity ceiling
new THREE.Vector2(0.72, 0.58),
new THREE.Vector2(1.08, 0.00) // cavity mouth
];
const upperCavityProfile = [
new THREE.Vector2(1.08, 0.00),
new THREE.Vector2(0.72, 0.58),
new THREE.Vector2(0.26, 1.08),
new THREE.Vector2(0.00, 1.24)
];
function mirrorProfile(points) {
return points
.map((point) => new THREE.Vector2(point.x, -point.y))
.reverse();
}
function makeSectionCap(profile, angle, group) {
const shape = new THREE.Shape(profile);
const geometry = new THREE.ShapeGeometry(shape);
const cap = new THREE.Mesh(geometry, sectionMaterial);
cap.rotation.y = angle - Math.PI / 2;
cap.castShadow = true;
cap.receiveShadow = true;
group.add(cap);
const edgeGeometry = new THREE.EdgesGeometry(geometry, 16);
const edge = new THREE.LineSegments(
edgeGeometry,
sectionEdgeMaterial
);
edge.rotation.copy(cap.rotation);
edge.renderOrder = 3;
group.add(edge);
}
function createMoldHalf(isUpper) {
const group = new THREE.Group();
const bodyProfile = isUpper
? upperMoldProfile.map((point) => point.clone())
: mirrorProfile(upperMoldProfile);
// Repeat the first point so LatheGeometry creates the closing annulus.
const closedProfile = bodyProfile.concat([
bodyProfile[0].clone()
]);
const bodyGeometry = new THREE.LatheGeometry(
closedProfile,
MOLD_SEGMENTS,
PHI_START,
PHI_LENGTH
);
const body = new THREE.Mesh(bodyGeometry, moldMaterial);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
// The gold liner sits just inside the mold body and shows the negative
// cavity clearly. Its extra 0.012 offset still preserves ample clearance
// from the original token.
const cavityProfile = upperCavityProfile.map((point) => {
const y = isUpper ? point.y : -point.y;
const x = point.x === 0 ? 0 : point.x + 0.012;
return new THREE.Vector2(x, y);
});
const cavityGeometry = new THREE.LatheGeometry(
cavityProfile,
MOLD_SEGMENTS,
PHI_START,
PHI_LENGTH
);
const cavity = new THREE.Mesh(cavityGeometry, cavityMaterial);
cavity.castShadow = true;
cavity.receiveShadow = true;
group.add(cavity);
// Close the two radial faces created by the cutaway.
makeSectionCap(bodyProfile, PHI_START, group);
makeSectionCap(
bodyProfile,
PHI_START + PHI_LENGTH,
group
);
scene.add(group);
return group;
}
const upperMold = createMoldHalf(true);
const lowerMold = createMoldHalf(false);
// -------------------------------------------------------------------------
// Original faceted geometric token
//
// Profiles:
// equator: radius 1.00
// shoulder: radius 0.64
// crown: radius 0.18
//
// Every mold cavity radius is the corresponding token radius plus 0.08.
// -------------------------------------------------------------------------
function createToken() {
const positions = [];
const point = (radius, y, index) =>
new THREE.Vector3(
radius * Math.sin((index / TOKEN_SEGMENTS) * TAU),
y,
radius * Math.cos((index / TOKEN_SEGMENTS) * TAU)
);
const equator = [];
const upperShoulder = [];
const upperCrown = [];
const lowerShoulder = [];
const lowerCrown = [];
for (let i = 0; i < TOKEN_SEGMENTS; i++) {
equator.push(point(1.00, 0.00, i));
upperShoulder.push(point(0.64, 0.58, i));
upperCrown.push(point(0.18, 1.08, i));
lowerShoulder.push(point(0.64, -0.58, i));
lowerCrown.push(point(0.18, -1.08, i));
}
const triangle = (a, b, c) => {
positions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
};
for (let i = 0; i < TOKEN_SEGMENTS; i++) {
const j = (i + 1) % TOKEN_SEGMENTS;
// Upper sides.
triangle(equator[i], equator[j], upperShoulder[i]);
triangle(equator[j], upperShoulder[j], upperShoulder[i]);
triangle(
upperShoulder[i],
upperShoulder[j],
upperCrown[i]
);
triangle(
upperShoulder[j],
upperCrown[j],
upperCrown[i]
);
// Lower sides.
triangle(equator[i], lowerShoulder[i], equator[j]);
triangle(equator[j], lowerShoulder[i], lowerShoulder[j]);
triangle(
lowerShoulder[i],
lowerShoulder[j],
lowerCrown[i]
);
triangle(
lowerShoulder[j],
lowerCrown[j],
lowerCrown[i]
);
}
const topCenter = new THREE.Vector3(0, 1.08, 0);
const bottomCenter = new THREE.Vector3(0, -1.08, 0);
for (let i = 0; i < TOKEN_SEGMENTS; i++) {
const j = (i + 1) % TOKEN_SEGMENTS;
triangle(topCenter, upperCrown[i], upperCrown[j]);
triangle(bottomCenter, lowerCrown[j], lowerCrown[i]);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const token = new THREE.Mesh(geometry, tokenMaterial);
token.castShadow = true;
token.receiveShadow = true;
scene.add(token);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 8),
tokenEdgeMaterial
);
edges.renderOrder = 4;
scene.add(edges);
// A thin glow ring communicates the radial fit without touching the token.
const clearanceRing = new THREE.Mesh(
new THREE.TorusGeometry(1.045, 0.012, 8, 72),
glowMaterial
);
clearanceRing.rotation.x = Math.PI / 2;
clearanceRing.renderOrder = 5;
scene.add(clearanceRing);
return { token, clearanceRing };
}
const { clearanceRing } = createToken();
// -------------------------------------------------------------------------
// Parting plane
// -------------------------------------------------------------------------
const partingPlane = new THREE.Mesh(
new THREE.PlaneGeometry(5.15, 5.15),
new THREE.MeshBasicMaterial({
color: 0x4d9eff,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false
})
);
partingPlane.rotation.x = -Math.PI / 2;
partingPlane.position.y = 0;
partingPlane.renderOrder = 1;
scene.add(partingPlane);
const partingGrid = new THREE.GridHelper(
5.0,
10,
0x69adff,
0x315b91
);
partingGrid.position.y = 0.006;
partingGrid.material.transparent = true;
partingGrid.material.opacity = 0.3;
partingGrid.material.depthWrite = false;
partingGrid.renderOrder = 2;
scene.add(partingGrid);
const planeBorder = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.PlaneGeometry(5.15, 5.15)),
new THREE.LineBasicMaterial({
color: 0x78b8ff,
transparent: true,
opacity: 0.55
})
);
planeBorder.rotation.x = -Math.PI / 2;
planeBorder.position.y = 0.008;
scene.add(planeBorder);
// -------------------------------------------------------------------------
// Ground and background grid
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x08131f,
metalness: 0.1,
roughness: 0.88
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -3.12;
ground.receiveShadow = true;
scene.add(ground);
const groundGrid = new THREE.GridHelper(
30,
30,
0x19344c,
0x10283b
);
groundGrid.position.y = -3.105;
groundGrid.material.transparent = true;
groundGrid.material.opacity = 0.32;
scene.add(groundGrid);
// -------------------------------------------------------------------------
// Separation controls
//
// The halves only travel along +/-Y. Since they start outside the token
// envelope, moving them farther away cannot create a token intersection.
// -------------------------------------------------------------------------
const separationSlider = document.querySelector("#separation");
const separationValue = document.querySelector("#separationValue");
const toggleButton = document.querySelector("#toggle");
const fitStatus = document.querySelector("#fitStatus");
let separation = 0;
let targetSeparation = 0;
let userControlled = false;
function updateToggleLabel() {
toggleButton.textContent =
targetSeparation > 0.4 ? "Close halves" : "Separate halves";
}
toggleButton.addEventListener("click", () => {
userControlled = true;
targetSeparation = targetSeparation > 0.4 ? 0 : 1.25;
separationSlider.value = String(targetSeparation);
updateToggleLabel();
});
separationSlider.addEventListener("input", () => {
userControlled = true;
targetSeparation = Number(separationSlider.value);
updateToggleLabel();
});
// Automatic exploded view, unless the user takes control first.
const autoSeparateTimer = window.setTimeout(() => {
if (!userControlled) {
targetSeparation = 1.25;
separationSlider.value = String(targetSeparation);
updateToggleLabel();
}
}, 900);
window.addEventListener(
"pointerdown",
() => {
userControlled = true;
clearTimeout(autoSeparateTimer);
},
{ once: true }
);
// -------------------------------------------------------------------------
// Custom camera controls — no addon imports
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, -0.05, 0);
let cameraTheta = 0.48;
let cameraPhi = 1.05;
let cameraRadius = 9.7;
let dragging = false;
let previousX = 0;
let previousY = 0;
function applyCamera() {
const horizontalRadius =
cameraRadius * Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x +
horizontalRadius * Math.sin(cameraTheta),
cameraTarget.y +
cameraRadius * Math.cos(cameraPhi),
cameraTarget.z +
horizontalRadius * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraTheta = 0.48;
cameraPhi = 1.05;
cameraRadius = 9.7;
applyCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - deltaY * 0.005,
0.32,
1.48
);
previousX = event.clientX;
previousY = event.clientY;
applyCamera();
});
function stopDragging(event) {
dragging = false;
if (
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
6.4,
14
);
applyCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
applyCamera();
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
// Smooth movement toward the requested exploded position.
const easing = 1 - Math.exp(-delta * 5.5);
separation += (targetSeparation - separation) * easing;
const seam = 0.012;
upperMold.position.y = seam + separation;
lowerMold.position.y = -seam - separation;
separationValue.value = separation.toFixed(2);
if (separation < 0.025) {
fitStatus.textContent =
"FIT CHECK: PASS · 0.08 radial clearance · halves nested";
} else {
fitStatus.textContent =
"FIT CHECK: PASS · halves travel on ±Y · token remains clear";
}
clearanceRing.material.opacity =
0.48 + Math.sin(elapsed * 2.3) * 0.12;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```