Prompt specification
Build or customize the Three.js 3D scene "Sealed Personal Envelopes and Total Counter" 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: Sealed Personal Envelopes and Total Counter
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sealed-personal-envelopes-and-total-counter-x3245
Scene Description Prompt:
Sealed personal envelopes and total counter. Arrange sealed envelopes feeding only a total-count display. Show that the aggregate changes when an envelope is added without displaying the contents of any individual envelope. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (sealed-personal-envelopes-and-total-counter-x3245):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sealed Envelope Counter</title>
<style>
:root {
color-scheme: dark;
--ink: #eaf8f1;
--muted: #abc8bd;
--panel: rgba(10, 35, 31, 0.88);
--line: rgba(137, 233, 194, 0.25);
--accent: #71efbd;
--accent-dark: #123d33;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b8cbc0;
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;
outline: none;
}
.controls {
position: fixed;
z-index: 10;
top: 24px;
left: 24px;
width: min(350px, calc(100vw - 48px));
padding: 22px;
color: var(--ink);
background: var(--panel);
border: 1px solid var(--line);
border-radius: 18px;
box-shadow: 0 20px 55px rgba(8, 32, 27, 0.22);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.eyebrow {
margin-bottom: 8px;
color: var(--accent);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.45rem, 4vw, 2rem);
line-height: 1.08;
letter-spacing: -0.035em;
}
p {
margin: 12px 0 18px;
color: var(--muted);
font-size: 0.92rem;
line-height: 1.55;
}
.button-row {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
button {
min-height: 44px;
padding: 0 16px;
border: 0;
border-radius: 11px;
color: #09271f;
background: var(--accent);
font: inherit;
font-size: 0.88rem;
font-weight: 800;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease,
box-shadow 150ms ease;
}
button:hover {
transform: translateY(-2px);
background: #8af8ca;
box-shadow: 0 8px 20px rgba(45, 224, 157, 0.2);
}
button:active {
transform: translateY(0);
}
button:focus-visible {
outline: 3px solid rgba(255, 255, 255, 0.8);
outline-offset: 3px;
}
button.secondary {
color: var(--ink);
background: rgba(255, 255, 255, 0.08);
border: 1px solid var(--line);
}
button.secondary:hover {
background: rgba(255, 255, 255, 0.13);
}
.hint {
position: fixed;
z-index: 10;
right: 20px;
bottom: 18px;
padding: 9px 12px;
color: rgba(14, 48, 40, 0.8);
background: rgba(241, 250, 245, 0.72);
border: 1px solid rgba(32, 80, 67, 0.12);
border-radius: 999px;
font-size: 0.76rem;
font-weight: 700;
pointer-events: none;
backdrop-filter: blur(8px);
}
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 700px) {
.controls {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px;
}
p {
margin-bottom: 14px;
}
.hint {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section class="controls" aria-label="Envelope feeder controls">
<div class="eyebrow">Aggregate-only counter</div>
<h1>Sealed envelope feeder</h1>
<p>
Opaque, sealed envelopes pass through the machine. Individual contents,
identities, and labels are never rendered—only the running total is exposed.
</p>
<div class="button-row">
<button id="add-envelope" type="button">Add sealed envelope</button>
<button id="reset-total" class="secondary" type="button">Reset total</button>
</div>
<div id="announcement" class="visually-hidden" aria-live="polite"></div>
</section>
<div class="hint">Drag to orbit · Scroll 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";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const sceneHost = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Low-poly sealed envelope feeder with a total-only counter"
);
renderer.domElement.tabIndex = 0;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8cbc0);
scene.fog = new THREE.Fog(0xb8cbc0, 24, 43);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(-0.1, 1.65, 0);
const cameraState = {
radius: window.innerWidth < 700 ? 20.5 : 16.8,
targetRadius: window.innerWidth < 700 ? 20.5 : 16.8,
theta: 0.38,
targetTheta: 0.38,
phi: 1.04,
targetPhi: 1.04
};
const hemisphere = new THREE.HemisphereLight(
0xf1fff8,
0x52665d,
2.3
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff7df, 3.2);
keyLight.position.set(-4, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 32;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xa9ddff, 1.1);
fillLight.position.set(8, 5, -8);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.03,
flatShading: true,
...options
});
const floorMaterial = material(0xb6c9bd);
const darkMetal = material(0x203b36);
const beltMaterial = material(0x142824);
const railMaterial = material(0x45665d);
const rollerMaterial = material(0x78958a);
const hopperMaterial = material(0x54766d);
const collectorMaterial = material(0x174c45);
const collectorTrim = material(0x2c7567);
const panelMaterial = material(0x071c19);
const ribMaterial = material(0x34534b);
const envelopeMaterials = [
material(0xe2c38f),
material(0xd4b278),
material(0xe8d19f)
];
const flapMaterials = [
material(0xc9a66b),
material(0xbb9257),
material(0xd2b47d)
];
const waxMaterial = material(0xa8463f);
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
function box(width, height, depth, mat, x, y, z, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function cylinder(radius, length, mat, x, y, z, rotationX = Math.PI / 2) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 8),
mat
);
mesh.position.set(x, y, z);
mesh.rotation.x = rotationX;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Ground and low-poly environment
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
// Low circular inspection pad.
const pad = new THREE.Mesh(
new THREE.CylinderGeometry(10.5, 10.8, 0.18, 12),
material(0xa7beb1)
);
pad.position.set(-0.5, 0.05, 0);
pad.receiveShadow = true;
scene.add(pad);
// -------------------------------------------------------------------------
// Conveyor
// -------------------------------------------------------------------------
const beltStart = -6.25;
const beltEnd = 3.25;
const beltLength = beltEnd - beltStart;
const beltCenter = (beltStart + beltEnd) / 2;
box(
beltLength,
0.34,
2.55,
darkMetal,
beltCenter,
0.72,
0
);
box(
beltLength - 0.15,
0.16,
2.2,
beltMaterial,
beltCenter,
1.0,
0
);
box(
beltLength,
0.24,
0.16,
railMaterial,
beltCenter,
1.16,
-1.31
);
box(
beltLength,
0.24,
0.16,
railMaterial,
beltCenter,
1.16,
1.31
);
// Faceted rollers.
for (let x = beltStart + 0.35; x < beltEnd; x += 0.85) {
cylinder(0.19, 2.58, rollerMaterial, x, 0.83, 0);
}
// Conveyor legs.
for (const x of [-5.2, -1.35, 2.55]) {
for (const z of [-1.0, 1.0]) {
box(0.18, 0.88, 0.18, darkMetal, x, 0.42, z);
}
box(0.18, 0.14, 2.15, darkMetal, x, 0.45, 0);
}
// Moving transverse belt ribs.
const movingRibs = [];
for (let x = beltStart + 0.25; x < beltEnd; x += 0.68) {
const rib = box(
0.075,
0.025,
2.08,
ribMaterial,
x,
1.095,
0,
false
);
movingRibs.push(rib);
}
// -------------------------------------------------------------------------
// Opaque input hopper
// -------------------------------------------------------------------------
box(2.25, 2.85, 3.0, hopperMaterial, -7.35, 1.65, 0);
box(2.42, 0.18, 3.16, railMaterial, -7.35, 3.12, 0);
box(0.16, 0.58, 1.76, panelMaterial, -6.19, 1.18, 0);
for (const z of [-1.05, 1.05]) {
box(0.2, 0.9, 0.2, darkMetal, -7.35, 0.42, z);
}
// -------------------------------------------------------------------------
// Opaque aggregate counter housing
// -------------------------------------------------------------------------
box(3.5, 3.65, 3.3, collectorMaterial, 5.0, 1.92, 0);
box(3.72, 0.22, 3.5, collectorTrim, 5.0, 3.82, 0);
box(3.25, 0.16, 3.02, collectorTrim, 5.0, 0.12, 0);
// The belt enters through an opaque slot.
box(0.13, 0.62, 1.78, panelMaterial, 3.22, 1.18, 0);
for (const z of [-1.12, 1.12]) {
box(0.25, 0.86, 0.25, darkMetal, 5.0, 0.39, z);
}
// -------------------------------------------------------------------------
// Canvas texture for the total-only display
// -------------------------------------------------------------------------
const counterCanvas = document.createElement("canvas");
counterCanvas.width = 1024;
counterCanvas.height = 512;
const counterContext = counterCanvas.getContext("2d");
const counterTexture = new THREE.CanvasTexture(counterCanvas);
counterTexture.colorSpace = THREE.SRGBColorSpace;
counterTexture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const screenFrame = box(
2.95,
1.62,
0.17,
collectorTrim,
5.0,
3.0,
1.72
);
screenFrame.material.emissive.set(0x17483d);
screenFrame.material.emissiveIntensity = 0.25;
const screen = new THREE.Mesh(
new THREE.PlaneGeometry(2.62, 1.31),
new THREE.MeshBasicMaterial({
map: counterTexture,
toneMapped: false
})
);
screen.position.set(5.0, 3.0, 1.815);
scene.add(screen);
const screenLight = new THREE.PointLight(0x58e8b8, 1.0, 5);
screenLight.position.set(5.0, 3.1, 2.7);
scene.add(screenLight);
let total = 0;
let counterPulse = 0;
function drawCounter() {
const ctx = counterContext;
const width = counterCanvas.width;
const height = counterCanvas.height;
ctx.fillStyle = "#061a17";
ctx.fillRect(0, 0, width, height);
ctx.strokeStyle = counterPulse > 0 ? "#a1ffda" : "#3f9f7e";
ctx.lineWidth = counterPulse > 0 ? 12 : 6;
ctx.strokeRect(18, 18, width - 36, height - 36);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#72dcb4";
ctx.font = '700 54px Arial, sans-serif';
ctx.fillText("TOTAL", width / 2, 102);
ctx.fillStyle = "#eafff5";
ctx.font = '700 225px "Courier New", monospace';
ctx.fillText(
String(total).padStart(3, "0"),
width / 2,
308
);
counterTexture.needsUpdate = true;
}
drawCounter();
// -------------------------------------------------------------------------
// Sealed envelope construction
//
// No labels, unique graphics, or contents are created. Every envelope is
// an identical opaque shell with a closed triangular flap and wax seal.
// -------------------------------------------------------------------------
let envelopeVariant = 0;
function createEnvelope() {
const group = new THREE.Group();
const bodyGeometry = new THREE.BoxGeometry(2.28, 0.12, 1.46);
const body = new THREE.Mesh(
bodyGeometry,
envelopeMaterials[envelopeVariant % envelopeMaterials.length]
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(bodyGeometry),
new THREE.LineBasicMaterial({
color: 0x9f7f52,
transparent: true,
opacity: 0.5
})
);
group.add(edges);
// Closed triangular flap lying on the top surface.
const flapGeometry = new THREE.BufferGeometry();
flapGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
-1.13, 0.066, 0.72,
1.13, 0.066, 0.72,
0.00, 0.066, 0.00
],
3
)
);
flapGeometry.setIndex([0, 1, 2]);
flapGeometry.computeVertexNormals();
const flap = new THREE.Mesh(
flapGeometry,
flapMaterials[envelopeVariant % flapMaterials.length]
);
flap.castShadow = true;
group.add(flap);
// Faceted wax seal.
const seal = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.19, 0.085, 8),
waxMaterial
);
seal.position.set(0, 0.105, 0);
seal.castShadow = true;
group.add(seal);
group.position.set(-6.0, 1.16, 0);
envelopeVariant++;
return group;
}
// -------------------------------------------------------------------------
// Feeder state
// -------------------------------------------------------------------------
let pendingEnvelopes = 0;
let activeEnvelope = null;
const feedDuration = 3.0;
const feedStart = -6.0;
const feedEnd = 3.55;
function startNextEnvelope() {
if (activeEnvelope || pendingEnvelopes <= 0) return;
pendingEnvelopes--;
const mesh = createEnvelope();
scene.add(mesh);
activeEnvelope = {
mesh,
progress: 0
};
}
function addEnvelope() {
pendingEnvelopes++;
startNextEnvelope();
}
function resetCounter() {
pendingEnvelopes = 0;
total = 0;
if (activeEnvelope) {
scene.remove(activeEnvelope.mesh);
activeEnvelope = null;
}
counterPulse = 0;
drawCounter();
document.querySelector("#announcement").textContent =
"The aggregate total has been reset.";
}
document
.querySelector("#add-envelope")
.addEventListener("click", addEnvelope);
document
.querySelector("#reset-total")
.addEventListener("click", resetCounter);
// Keyboard shortcut: Enter or Space adds an envelope.
window.addEventListener("keydown", (event) => {
if (
event.code === "Space" ||
event.code === "Enter"
) {
if (document.activeElement?.tagName === "BUTTON") return;
event.preventDefault();
addEnvelope();
}
});
// -------------------------------------------------------------------------
// Direct camera controls — no OrbitControls or other addons
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.targetTheta = THREE.MathUtils.clamp(
cameraState.targetTheta - dx * 0.005,
-0.9,
0.9
);
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi - dy * 0.005,
0.55,
1.34
);
});
function stopDragging(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"contextmenu",
(event) => event.preventDefault()
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius * Math.exp(event.deltaY * 0.001),
10,
27
);
},
{ passive: false }
);
function updateCamera(delta) {
const smoothing = 1 - Math.pow(0.001, delta);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraState.targetTheta,
smoothing
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraState.targetPhi,
smoothing
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.targetRadius,
smoothing
);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.phi),
cameraTarget.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const beltSpeed = 3.2;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateCamera(delta);
// Scroll the belt ribs to communicate movement.
for (const rib of movingRibs) {
rib.position.x += beltSpeed * delta;
if (rib.position.x > beltEnd + 0.15) {
rib.position.x = beltStart - 0.15;
}
}
if (activeEnvelope) {
activeEnvelope.progress += delta / feedDuration;
const progress = Math.min(activeEnvelope.progress, 1);
activeEnvelope.mesh.position.x = THREE.MathUtils.lerp(
feedStart,
feedEnd,
progress
);
activeEnvelope.mesh.rotation.y =
Math.sin(progress * Math.PI * 2) * 0.018;
if (activeEnvelope.progress >= 1) {
scene.remove(activeEnvelope.mesh);
activeEnvelope = null;
total++;
counterPulse = 0.5;
drawCounter();
document.querySelector("#announcement").textContent =
`The aggregate total is now ${total}.`;
startNextEnvelope();
}
}
if (counterPulse > 0) {
counterPulse = Math.max(0, counterPulse - delta);
const normalized = counterPulse / 0.5;
const pulse = Math.sin(normalized * Math.PI);
screenFrame.scale.setScalar(1 + pulse * 0.035);
screenFrame.material.emissiveIntensity = 0.25 + pulse * 0.85;
screenLight.intensity = 1 + pulse * 2.2;
} else {
screenFrame.scale.setScalar(1);
screenFrame.material.emissiveIntensity = 0.25;
screenLight.intensity = 1;
}
renderer.render(scene, camera);
}
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
animate();
</script>
</body>
</html>
```