Prompt specification
Build or customize the Three.js 3D scene "Drainable toothbrush tumbler" 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: Drainable toothbrush tumbler
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/drainable-toothbrush-tumbler-x0073
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a toothbrush cup. Model a short tumbler with four drainage slots and three distinctly sized toothbrushes, showing bristle blocks, handles, and enough spacing to identify each silhouette. Stylized solid forms.
Working Three.js Starter (drainable-toothbrush-tumbler-x0073):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Toothbrush Cup</title>
<style>
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eaf2ef;
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.hint {
position: fixed;
left: 18px;
bottom: 16px;
padding: 9px 13px;
border: 1px solid rgba(39, 78, 73, 0.14);
border-radius: 999px;
color: rgba(39, 78, 73, 0.72);
background: rgba(255, 255, 255, 0.72);
backdrop-filter: blur(8px);
font-size: 12px;
letter-spacing: 0.02em;
pointer-events: none;
user-select: none;
}
</style>
</head>
<body>
<div class="hint">Drag to orbit · Scroll or pinch to zoom</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeaf2ef);
scene.fog = new THREE.Fog(0xeaf2ef, 8, 15);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive three-dimensional toothbrush cup");
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Simple custom camera controls; no addons are used.
const controls = {
target: new THREE.Vector3(0, 1.23, 0),
azimuth: 0.18,
polar: 1.18,
radius: 5.35,
goalAzimuth: 0.18,
goalPolar: 1.18,
goalRadius: 5.35
};
function updateCamera() {
const sinPolar = Math.sin(controls.polar);
camera.position.set(
controls.target.x + controls.radius * sinPolar * Math.sin(controls.azimuth),
controls.target.y + controls.radius * Math.cos(controls.polar),
controls.target.z + controls.radius * sinPolar * Math.cos(controls.azimuth)
);
camera.lookAt(controls.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf7fffc, 0x728a84, 2.25);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xfff4df, 3.2);
key.position.set(4.5, 7, 4.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -4;
key.shadow.camera.right = 4;
key.shadow.camera.top = 5;
key.shadow.camera.bottom = -2;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 15;
key.shadow.bias = -0.0004;
key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0xb8dcff, 1.15);
fill.position.set(-4, 3.5, 2);
scene.add(fill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0xdde9e4,
roughness: 0.92,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.012;
floor.receiveShadow = true;
scene.add(floor);
const cupOuter = new THREE.MeshStandardMaterial({
color: 0x70b6aa,
roughness: 0.43,
metalness: 0.02
});
const cupInner = new THREE.MeshStandardMaterial({
color: 0x286761,
roughness: 0.58,
metalness: 0
});
const cupEdge = new THREE.MeshStandardMaterial({
color: 0xcce9df,
roughness: 0.38,
metalness: 0.02
});
/*
Creates a closed, tapered shell section from curved outer and inner
surfaces. Separate arcs are used below the rim so that the gaps
become four genuine drainage slots.
*/
function createShellArc({
y0,
y1,
outerBottom,
outerTop,
innerBottom,
innerTop,
thetaStart = 0,
thetaLength = Math.PI * 2,
segments = 64
}) {
const outer = [];
const inner = [];
const top = [];
const bottom = [];
const ends = [];
const step = thetaLength / segments;
const fullCircle = Math.abs(thetaLength - Math.PI * 2) < 0.00001;
function point(radius, y, theta) {
return [
radius * Math.sin(theta),
y,
radius * Math.cos(theta)
];
}
function quad(array, a, b, c, d) {
array.push(...a, ...b, ...c, ...a, ...c, ...d);
}
for (let i = 0; i < segments; i++) {
const a = thetaStart + i * step;
const b = thetaStart + (i + 1) * step;
const ob0 = point(outerBottom, y0, a);
const ob1 = point(outerBottom, y0, b);
const ot0 = point(outerTop, y1, a);
const ot1 = point(outerTop, y1, b);
const ib0 = point(innerBottom, y0, a);
const ib1 = point(innerBottom, y0, b);
const it0 = point(innerTop, y1, a);
const it1 = point(innerTop, y1, b);
quad(outer, ob0, ob1, ot1, ot0);
quad(inner, ib0, it0, it1, ib1);
quad(top, ot0, ot1, it1, it0);
quad(bottom, ob0, ib0, ib1, ob1);
if (!fullCircle && (i === 0 || i === segments - 1)) {
if (i === 0) {
quad(ends, ob0, ot0, it0, ib0);
} else {
quad(ends, ob1, ib1, it1, ot1);
}
}
}
const positions = [];
const geometry = new THREE.BufferGeometry();
let offset = 0;
function addPart(part, materialIndex) {
positions.push(...part);
geometry.addGroup(offset, part.length / 3, materialIndex);
offset += part.length / 3;
}
addPart(outer, 0);
addPart(inner, 1);
addPart(top, 2);
addPart(bottom, 2);
if (ends.length) addPart(ends, 2);
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return new THREE.Mesh(geometry, [cupOuter, cupInner, cupEdge]);
}
const cup = new THREE.Group();
scene.add(cup);
// Solid foot band.
const foot = createShellArc({
y0: 0.12,
y1: 0.25,
outerBottom: 0.75,
outerTop: 0.78,
innerBottom: 0.64,
innerTop: 0.67,
segments: 64
});
foot.castShadow = true;
foot.receiveShadow = true;
cup.add(foot);
// Four evenly distributed drainage slots, offset so two face the camera.
const slotCenters = [
Math.PI / 4,
(3 * Math.PI) / 4,
(5 * Math.PI) / 4,
(7 * Math.PI) / 4
];
const slotHalfWidth = 0.115;
for (let i = 0; i < slotCenters.length; i++) {
const start = slotCenters[i] + slotHalfWidth;
const nextCenter = slotCenters[i + 1] ?? (slotCenters[0] + 2 * Math.PI);
const end = nextCenter - slotHalfWidth;
const slottedPanel = createShellArc({
y0: 0.25,
y1: 0.60,
outerBottom: 0.78,
outerTop: 0.83,
innerBottom: 0.67,
innerTop: 0.72,
thetaStart: start,
thetaLength: end - start,
segments: 18
});
slottedPanel.castShadow = true;
slottedPanel.receiveShadow = true;
cup.add(slottedPanel);
}
// Main upper body.
const body = createShellArc({
y0: 0.60,
y1: 1.47,
outerBottom: 0.83,
outerTop: 0.92,
innerBottom: 0.72,
innerTop: 0.82,
segments: 64
});
body.castShadow = true;
body.receiveShadow = true;
cup.add(body);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.78, 0.74, 0.14, 64),
cupOuter
);
base.position.y = 0.07;
base.castShadow = true;
base.receiveShadow = true;
cup.add(base);
const interiorFloor = new THREE.Mesh(
new THREE.CircleGeometry(0.65, 64),
cupInner
);
interiorFloor.rotation.x = -Math.PI / 2;
interiorFloor.position.y = 0.155;
interiorFloor.receiveShadow = true;
cup.add(interiorFloor);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.87, 0.055, 12, 64),
cupEdge
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 1.47;
rim.castShadow = true;
rim.receiveShadow = true;
cup.add(rim);
const decorativeBand = new THREE.Mesh(
new THREE.TorusGeometry(0.875, 0.017, 8, 64),
new THREE.MeshStandardMaterial({
color: 0x4d9288,
roughness: 0.48
})
);
decorativeBand.rotation.x = Math.PI / 2;
decorativeBand.position.y = 1.17;
cup.add(decorativeBand);
function roundedRectShape(width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + height - r);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
shape.lineTo(x + r, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
return shape;
}
function extrudedRoundedRect(width, height, depth, radius, material) {
const geometry = new THREE.ExtrudeGeometry(
roundedRectShape(width, height, radius),
{
depth,
steps: 1,
bevelEnabled: true,
bevelThickness: 0.025,
bevelSize: 0.025,
bevelOffset: 0,
bevelSegments: 3
}
);
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
const sharedBristleGeometry = new THREE.CylinderGeometry(
0.018,
0.022,
0.11,
8
);
function makeToothbrush({
handleLength,
handleWidth,
headWidth,
headHeight,
handleColor,
headColor,
panelColor,
bristleColor,
accentColor,
position,
rotation
}) {
const group = new THREE.Group();
const handleMaterial = new THREE.MeshStandardMaterial({
color: handleColor,
roughness: 0.38,
metalness: 0.03
});
const headMaterial = new THREE.MeshStandardMaterial({
color: headColor,
roughness: 0.42,
metalness: 0.02
});
const panelMaterial = new THREE.MeshStandardMaterial({
color: panelColor,
roughness: 0.48
});
const gripMaterial = new THREE.MeshStandardMaterial({
color: accentColor,
roughness: 0.4
});
const bristleMaterial = new THREE.MeshStandardMaterial({
color: bristleColor,
roughness: 0.68
});
// Rounded solid handle.
const handle = extrudedRoundedRect(
handleWidth,
handleLength,
0.14,
Math.min(0.10, handleWidth * 0.38),
handleMaterial
);
handle.position.y = handleLength / 2;
group.add(handle);
// Raised front grip.
const grip = new THREE.Mesh(
new THREE.CapsuleGeometry(
handleWidth * 0.145,
handleLength * 0.38,
4,
10
),
gripMaterial
);
grip.position.set(0, handleLength * 0.43, 0.083);
grip.scale.z = 0.45;
grip.castShadow = true;
group.add(grip);
// Small neck transition.
const neck = new THREE.Mesh(
new THREE.CapsuleGeometry(
handleWidth * 0.18,
0.22,
4,
10
),
headMaterial
);
neck.position.set(0, handleLength - 0.03, 0.005);
neck.scale.z = 0.7;
neck.castShadow = true;
group.add(neck);
// Solid bristle backing block.
const headCenterY = handleLength + headHeight / 2 - 0.12;
const head = extrudedRoundedRect(
headWidth,
headHeight,
0.15,
0.075,
headMaterial
);
head.position.y = headCenterY;
group.add(head);
// Lighter inset makes each bristle block immediately legible.
const headPanel = extrudedRoundedRect(
headWidth * 0.78,
headHeight * 0.76,
0.025,
0.045,
panelMaterial
);
headPanel.position.set(0, headCenterY, 0.082);
group.add(headPanel);
// Individual solid bristle tufts.
const columns = headWidth > 0.55 ? 5 : headWidth > 0.43 ? 4 : 3;
const rows = headHeight > 0.68 ? 6 : 5;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
const x =
(col / Math.max(1, columns - 1) - 0.5) *
headWidth * 0.62;
const y =
headCenterY +
(row / Math.max(1, rows - 1) - 0.5) *
headHeight * 0.56;
const tuft = new THREE.Mesh(
sharedBristleGeometry,
bristleMaterial
);
tuft.rotation.x = Math.PI / 2;
tuft.position.set(x, y, 0.135);
group.add(tuft);
}
}
group.position.copy(position);
group.rotation.set(
rotation.x,
rotation.y,
rotation.z,
"ZXY"
);
scene.add(group);
return group;
}
// Tall, narrow blue toothbrush.
makeToothbrush({
handleLength: 1.72,
handleWidth: 0.27,
headWidth: 0.39,
headHeight: 0.72,
handleColor: 0x3478d4,
headColor: 0x2055a5,
panelColor: 0xa8d7f4,
bristleColor: 0xf8fcff,
accentColor: 0x74c7ee,
position: new THREE.Vector3(-0.43, 0.29, 0.12),
rotation: new THREE.Euler(-0.035, -0.10, -0.075)
});
// Medium coral toothbrush.
makeToothbrush({
handleLength: 1.43,
handleWidth: 0.29,
headWidth: 0.48,
headHeight: 0.64,
handleColor: 0xef6d5d,
headColor: 0xc94c43,
panelColor: 0xf7b0a5,
bristleColor: 0xfff7e9,
accentColor: 0xffa08e,
position: new THREE.Vector3(0.02, 0.29, -0.17),
rotation: new THREE.Euler(0.025, 0.055, 0.015)
});
// Short, broad golden toothbrush.
makeToothbrush({
handleLength: 1.12,
handleWidth: 0.32,
headWidth: 0.62,
headHeight: 0.64,
handleColor: 0xf3b83f,
headColor: 0xd88c22,
panelColor: 0xffe09a,
bristleColor: 0xfffaf0,
accentColor: 0xffd36b,
position: new THREE.Vector3(0.49, 0.29, 0.08),
rotation: new THREE.Euler(-0.045, -0.16, 0.085)
});
// Pointer, wheel, and pinch camera controls.
const pointers = new Map();
let previousSingle = null;
let previousPinchDistance = null;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
previousSingle = { x: event.clientX, y: event.clientY };
} else {
previousPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && previousSingle) {
const dx = event.clientX - previousSingle.x;
const dy = event.clientY - previousSingle.y;
controls.goalAzimuth -= dx * 0.006;
controls.goalPolar = THREE.MathUtils.clamp(
controls.goalPolar + dy * 0.005,
0.62,
1.43
);
previousSingle = { x: event.clientX, y: event.clientY };
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance && distance > 0) {
controls.goalRadius = THREE.MathUtils.clamp(
controls.goalRadius *
(previousPinchDistance / distance),
3.7,
8.2
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
previousSingle = { x: remaining.x, y: remaining.y };
previousPinchDistance = null;
} else {
previousSingle = null;
previousPinchDistance = null;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.goalRadius = THREE.MathUtils.clamp(
controls.goalRadius * Math.exp(event.deltaY * 0.001),
3.7,
8.2
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
controls.goalAzimuth = 0.18;
controls.goalPolar = 1.18;
controls.goalRadius = 5.35;
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function animate() {
requestAnimationFrame(animate);
const damping = 0.11;
controls.azimuth +=
(controls.goalAzimuth - controls.azimuth) * damping;
controls.polar +=
(controls.goalPolar - controls.polar) * damping;
controls.radius +=
(controls.goalRadius - controls.radius) * damping;
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```