Prompt specification
Build or customize the Three.js 3D scene "Refill jar tare comparison" 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: Refill jar tare comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/refill-jar-tare-comparison-x0525
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts empty and filled refill jars. Display an empty jar and the same jar filled with symbolic grain beside mass indicators; distinguish container mass from contents using separate colored reference blocks. Voxel style.
Working Three.js Starter (refill-jar-tare-comparison-x0525):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Refill Jar — Mass Comparison</title>
<style>
:root {
--ink: #26383b;
--paper: #fffaf0;
--muted: #687779;
--container: #279b9e;
--contents: #e1a234;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #f1ece2;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.brand {
position: fixed;
top: 24px;
left: 26px;
z-index: 5;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}
.brand__eyebrow {
margin-bottom: 7px;
color: var(--container);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
}
.brand h1 {
margin: 0;
font-size: clamp(20px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.05em;
}
.brand p {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
}
.legend {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 5;
display: flex;
align-items: center;
gap: 22px;
width: max-content;
max-width: calc(100vw - 32px);
padding: 12px 16px;
border: 2px solid rgba(38, 56, 59, 0.18);
background: rgba(255, 250, 240, 0.9);
box-shadow: 0 8px 30px rgba(44, 56, 55, 0.1);
transform: translateX(-50%);
backdrop-filter: blur(8px);
pointer-events: none;
font-size: 12px;
}
.legend__item {
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
}
.legend__item strong {
letter-spacing: 0.03em;
}
.swatch {
width: 15px;
height: 15px;
border: 2px solid rgba(38, 56, 59, 0.25);
box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.2);
}
.swatch--container {
background: var(--container);
}
.swatch--contents {
background: var(--contents);
}
.controls {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 5;
padding: 8px 11px;
border: 1px solid rgba(38, 56, 59, 0.16);
background: rgba(255, 250, 240, 0.72);
color: var(--muted);
font-size: 10px;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #f1ece2;
color: var(--ink);
font-size: 13px;
letter-spacing: 0.08em;
}
@media (max-width: 760px) {
.brand {
top: 17px;
left: 17px;
}
.brand p {
max-width: 250px;
line-height: 1.45;
}
.legend {
left: 16px;
right: 16px;
bottom: 16px;
justify-content: space-between;
gap: 10px;
width: auto;
transform: none;
font-size: 10px;
}
.controls {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="brand">
<div class="brand__eyebrow">VOXEL REFILL LAB / 01</div>
<h1>EMPTY → FILLED</h1>
<p>Same container. Separate mass blocks reveal what the grain adds.</p>
</header>
<div class="legend" aria-label="Mass color legend">
<div class="legend__item">
<span class="swatch swatch--container"></span>
<span><strong>Container</strong> · 320 g</span>
</div>
<div class="legend__item">
<span class="swatch swatch--contents"></span>
<span><strong>Contents</strong> · 0 → 700 g</span>
</div>
</div>
<div class="controls">DRAG orbit · WHEEL zoom · DOUBLE-CLICK reset</div>
<div id="loading">BUILDING VOXEL REFILLS…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf1ece2);
scene.fog = new THREE.Fog(0xf1ece2, 25, 48);
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
} catch (error) {
loading.textContent = "WEBGL IS NOT AVAILABLE IN THIS BROWSER.";
throw error;
}
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.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel scene comparing an empty refill jar with a grain-filled jar."
);
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 2.25, 0);
const defaultView = {
theta: 0.25,
phi: 1.02,
radius: window.innerWidth < 760 ? 31 : 19
};
const view = { ...defaultView };
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
target.x + view.radius * sinPhi * Math.sin(view.theta),
target.y + view.radius * Math.cos(view.phi),
target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(target);
}
updateCamera();
// Lighting
scene.add(new THREE.HemisphereLight(0xfffbef, 0x82918e, 1.75));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.0);
keyLight.position.set(-7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9dfe1, 1.0);
fillLight.position.set(10, 7, -8);
scene.add(fillLight);
// Shared materials
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0xeee8dc,
roughness: 0.94
}),
platform: new THREE.MeshStandardMaterial({
color: 0xe4d8c3,
roughness: 0.85
}),
platformEdge: new THREE.MeshStandardMaterial({
color: 0xc9baa2,
roughness: 0.9
}),
ink: new THREE.MeshStandardMaterial({
color: 0x304548,
roughness: 0.75
}),
cream: new THREE.MeshStandardMaterial({
color: 0xfff8e9,
roughness: 0.8
}),
teal: new THREE.MeshStandardMaterial({
color: 0x279b9e,
roughness: 0.62
}),
tealLight: new THREE.MeshStandardMaterial({
color: 0x53b9b8,
roughness: 0.58
}),
amber: new THREE.MeshStandardMaterial({
color: 0xe1a234,
roughness: 0.68
}),
amberLight: new THREE.MeshStandardMaterial({
color: 0xf2c35d,
roughness: 0.62
}),
glass: new THREE.MeshPhysicalMaterial({
color: 0xa8dfe0,
transparent: true,
opacity: 0.24,
depthWrite: false,
roughness: 0.16,
metalness: 0,
clearcoat: 0.8,
clearcoatRoughness: 0.18,
side: THREE.DoubleSide
}),
rim: new THREE.MeshStandardMaterial({
color: 0x69b6b6,
roughness: 0.38,
metalness: 0.05
}),
highlight: new THREE.MeshBasicMaterial({
color: 0xf4ffff,
transparent: true,
opacity: 0.72,
depthWrite: false
}),
grain: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.78,
metalness: 0
})
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function addBox(parent, size, position, material, cast = true, receive = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function addInstances(parent, specs, material, castShadow = true, receiveShadow = true) {
const mesh = new THREE.InstancedMesh(unitBox, material, specs.length);
const dummy = new THREE.Object3D();
specs.forEach((spec, index) => {
dummy.position.set(spec.p[0], spec.p[1], spec.p[2]);
dummy.scale.set(
spec.s[0] ?? 1,
spec.s[1] ?? 1,
spec.s[2] ?? 1
);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (spec.c !== undefined) {
mesh.setColorAt(index, new THREE.Color(spec.c));
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
mesh.computeBoundingSphere();
parent.add(mesh);
return mesh;
}
function makeStationLabel(title, subtitle, accentColor) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#fffaf0";
ctx.fillRect(12, 12, 1000, 232);
ctx.strokeStyle = "#304548";
ctx.lineWidth = 8;
ctx.strokeRect(12, 12, 1000, 232);
ctx.fillStyle = accentColor;
ctx.fillRect(12, 12, 22, 232);
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillStyle = "#26383b";
ctx.font = "bold 64px monospace";
ctx.fillText(title, 64, 94);
ctx.fillStyle = "#687779";
ctx.font = "31px monospace";
ctx.fillText(subtitle, 64, 174);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(4.15, 1.04, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeTag(text, color) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = color;
ctx.fillRect(6, 6, 500, 116);
ctx.strokeStyle = "#26383b";
ctx.lineWidth = 7;
ctx.strokeRect(6, 6, 500, 116);
ctx.fillStyle = "#fffaf0";
ctx.font = "bold 39px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.48, 0.37, 1);
sprite.renderOrder = 21;
return sprite;
}
let randomSeed = 81723;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function createJar(parent, filled) {
const jar = new THREE.Group();
jar.position.x = -1.45;
parent.add(jar);
const cell = 0.52;
const baseY = 0.23;
const isCorner = (x, z) =>
Math.abs(x) === 3 && Math.abs(z) === 2;
const isBoundary = (x, z) => {
const edgeX = Math.abs(x) === 3;
const edgeZ = Math.abs(z) === 2;
return (edgeX || edgeZ) && !isCorner(x, z);
};
const glassSpecs = [];
const rimSpecs = [];
// Voxel bottom
for (let x = -3; x <= 3; x++) {
for (let z = -2; z <= 2; z++) {
if (!isCorner(x, z)) {
glassSpecs.push({
p: [x * cell, baseY + cell * 0.5, z * cell],
s: [cell * 0.96, cell * 0.5, cell * 0.96]
});
}
}
}
// Voxel walls
for (let level = 0; level < 10; level++) {
for (let x = -3; x <= 3; x++) {
for (let z = -2; z <= 2; z++) {
if (isBoundary(x, z)) {
glassSpecs.push({
p: [
x * cell,
baseY + cell * 0.5 + level * cell,
z * cell
],
s: [cell * 0.96, cell * 0.96, cell * 0.96]
});
}
}
}
}
// Open top rim
for (let x = -3; x <= 3; x++) {
for (let z = -2; z <= 2; z++) {
if (isBoundary(x, z)) {
rimSpecs.push({
p: [
x * cell,
baseY + cell * 0.5 + 10 * cell,
z * cell
],
s: [cell * 0.98, cell * 0.98, cell * 0.98]
});
}
}
}
addInstances(jar, glassSpecs, materials.glass, false, false);
addInstances(jar, rimSpecs, materials.rim, true, true);
// Darker foot makes the empty vessel silhouette easier to read.
addBox(
jar,
[3.38, 0.11, 2.38],
[0, baseY + 0.055, 0],
materials.rim,
false,
true
);
// Small square highlights in the glass.
[2, 4, 6].forEach((level) => {
addBox(
jar,
[0.1, 0.28, 0.07],
[-1.04, baseY + cell * 0.5 + level * cell, 1.315],
materials.highlight,
false,
false
);
});
addBox(
jar,
[0.07, 0.65, 0.09],
[1.83, baseY + 2.85, 0.52],
materials.highlight,
false,
false
);
if (filled) {
const grainSpecs = [];
const grainColors = [
0xd39120,
0xe2a72e,
0xefbd4b,
0xf4cc6c,
0xc9871c
];
// Ten irregular layers of square grain kernels.
for (let layer = 0; layer < 10; layer++) {
for (let gx = -2; gx <= 2; gx++) {
for (let gz = -1; gz <= 1; gz++) {
const corner = Math.abs(gx) === 2 && Math.abs(gz) === 1;
const probability =
layer < 3 ? 0.99 :
layer < 8 ? 0.91 :
corner ? 0.25 : 0.73;
if (random() > probability) continue;
const jitterX = (random() - 0.5) * 0.045;
const jitterZ = (random() - 0.5) * 0.045;
const size = 0.35 + random() * 0.055;
const color = grainColors[Math.floor(random() * grainColors.length)];
grainSpecs.push({
p: [
gx * 0.49 + jitterX,
baseY + 0.23 + layer * 0.39 + random() * 0.025,
gz * 0.49 + jitterZ
],
s: [size, size * 0.88, size],
c: color
});
}
}
}
// A few raised kernels make the fill read as loose grain.
for (let i = 0; i < 7; i++) {
grainSpecs.push({
p: [
(random() - 0.5) * 1.55,
baseY + 4.12 + random() * 0.12,
(random() - 0.5) * 0.7
],
s: [0.34, 0.29, 0.34],
c: grainColors[Math.floor(random() * grainColors.length)]
});
}
addInstances(jar, grainSpecs, materials.grain, true, true);
}
return jar;
}
function createMassIndicator(parent, filled) {
const indicator = new THREE.Group();
indicator.position.set(2.15, 0, 0.05);
parent.add(indicator);
// Dark measurement plinth.
addBox(
indicator,
[1.76, 0.12, 1.72],
[0, 0.29, 0],
materials.ink,
true,
true
);
// Container mass: identical teal block in both stations.
const containerBottom = 0.35;
const containerHeight = 1.05;
addBox(
indicator,
[1.3, containerHeight, 1.3],
[0, containerBottom + containerHeight * 0.5, 0],
materials.teal
);
addBox(
indicator,
[1.08, 0.07, 1.08],
[0, containerBottom + containerHeight + 0.035, 0],
materials.tealLight
);
const containerTag = makeTag("CONTAINER 320 g", "#279b9e");
containerTag.position.set(0, containerBottom + containerHeight * 0.5, 0.71);
indicator.add(containerTag);
if (filled) {
// Contents mass: a separate amber block, taller to represent 700 g.
const contentsBottom = containerBottom + containerHeight + 0.11;
const contentsHeight = 2.25;
addBox(
indicator,
[1.3, contentsHeight, 1.3],
[0, contentsBottom + contentsHeight * 0.5, 0],
materials.amber
);
addBox(
indicator,
[1.08, 0.07, 1.08],
[0, contentsBottom + contentsHeight + 0.035, 0],
materials.amberLight
);
const contentsTag = makeTag("CONTENTS 700 g", "#d99625");
contentsTag.position.set(
0,
contentsBottom + contentsHeight * 0.5,
0.71
);
indicator.add(contentsTag);
}
return indicator;
}
function createStation(x, filled) {
const station = new THREE.Group();
station.position.x = x;
scene.add(station);
addBox(
station,
[8.2, 0.3, 4.8],
[0, 0.08, 0],
materials.platform
);
addBox(
station,
[8.42, 0.12, 5.02],
[0, -0.08, 0],
materials.platformEdge
);
// Pixel-style connector from the jar to its mass indicator.
for (let i = 0; i < 6; i++) {
addBox(
station,
[0.12, 0.045, 0.12],
[0.25 + i * 0.23, 0.255, 1.58],
materials.ink,
false,
true
);
}
addBox(
station,
[0.12, 0.045, 0.12],
[1.62, 0.255, 1.72],
materials.ink,
false,
true
);
addBox(
station,
[0.12, 0.045, 0.12],
[1.48, 0.255, 1.72],
materials.ink,
false,
true
);
createJar(station, filled);
createMassIndicator(station, filled);
const label = makeStationLabel(
filled ? "FILLED JAR" : "EMPTY JAR",
filled
? "container 320 g · contents 700 g · total 1,020 g"
: "container 320 g · contents 0 g · total 320 g",
filled ? "#e1a234" : "#279b9e"
);
label.position.set(-1.45, 6.72, 0);
station.add(label);
return station;
}
// Ground
addBox(
scene,
[40, 0.45, 28],
[0, -0.3, 0],
materials.floor,
false,
true
);
// Quiet background voxel forms for depth.
const backgroundMaterial = new THREE.MeshStandardMaterial({
color: 0xe5ddce,
roughness: 0.95
});
[
[-12, 0.65, -6, 2.2],
[-10.6, 1.8, -6.2, 1.4],
[12, 0.7, -6.4, 2.5],
[13.1, 1.9, -6.5, 1.3]
].forEach(([x, y, z, size]) => {
addBox(
scene,
[size, y * 2, size],
[x, y, z],
backgroundMaterial,
true,
true
);
});
createStation(-4.4, false);
createStation(4.4, true);
// Custom camera controls — no OrbitControls or addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
view.theta -= deltaX * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi + deltaY * 0.005,
0.58,
1.34
);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.012,
11,
38
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
view.theta = defaultView.theta;
view.phi = defaultView.phi;
view.radius = defaultView.radius;
updateCamera();
});
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
view.theta += 0.09;
break;
case "ArrowRight":
view.theta -= 0.09;
break;
case "ArrowUp":
view.phi = Math.max(0.58, view.phi - 0.06);
break;
case "ArrowDown":
view.phi = Math.min(1.34, view.phi + 0.06);
break;
case "+":
case "=":
view.radius = Math.max(11, view.radius - 1);
break;
case "-":
view.radius = Math.min(38, view.radius + 1);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 760 ? 50 : 38;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
renderer.render(scene, camera);
loading.remove();
</script>
</body>
</html>
```