Prompt specification
Build or customize the Three.js 3D scene "Knitted-cover warming bottle" 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: Knitted-cover warming bottle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/knitted-cover-warming-bottle-x0037
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: knitted-cover warming bottle. Model a soft rectangular bottle with narrowed neck, screw cap, and partly removed knitted cover; separate the flexible vessel from its insulating sleeve clearly. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (knitted-cover-warming-bottle-x0037):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Knitted Warming Bottle</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee6da;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
top: 22px;
left: 22px;
width: min(320px, calc(100vw - 44px));
padding: 20px;
border: 1px solid rgba(81, 67, 52, 0.18);
border-radius: 18px;
background: rgba(255, 250, 242, 0.82);
box-shadow: 0 18px 50px rgba(79, 61, 40, 0.13);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
user-select: none;
}
.eyebrow {
margin-bottom: 7px;
color: #a05a3d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #293b3e;
font-size: 23px;
font-weight: 760;
letter-spacing: -0.035em;
line-height: 1.08;
}
.subtitle {
margin: 9px 0 19px;
color: #6b716e;
font-size: 12px;
line-height: 1.5;
}
.control-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
color: #394a4c;
font-size: 12px;
font-weight: 700;
}
output {
min-width: 42px;
padding: 3px 7px;
border-radius: 8px;
background: #e9d8c4;
color: #875139;
font-variant-numeric: tabular-nums;
text-align: center;
}
input[type="range"] {
width: 100%;
margin: 0 0 7px;
accent-color: #c66e48;
cursor: pointer;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-bottom: 17px;
color: #8a8d87;
font-size: 10px;
}
.legend {
display: grid;
gap: 8px;
padding-top: 14px;
border-top: 1px solid rgba(83, 69, 54, 0.12);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #58615f;
font-size: 11px;
}
.swatch {
width: 12px;
height: 12px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.vessel {
background: #d36f68;
}
.sleeve {
background: #d98b4f;
}
.cap {
background: #294b50;
}
button {
width: 100%;
margin-top: 16px;
padding: 9px 12px;
border: 1px solid rgba(73, 86, 84, 0.18);
border-radius: 10px;
background: rgba(255, 255, 255, 0.58);
color: #3c5354;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: #fffaf2;
transform: translateY(-1px);
}
.hint {
position: fixed;
right: 22px;
bottom: 20px;
padding: 9px 12px;
border: 1px solid rgba(70, 64, 54, 0.12);
border-radius: 999px;
background: rgba(255, 250, 242, 0.72);
color: #67716e;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
pointer-events: none;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
@media (max-width: 640px) {
.panel {
top: 12px;
left: 12px;
width: min(285px, calc(100vw - 24px));
padding: 16px;
}
h1 {
font-size: 20px;
}
.subtitle {
margin-bottom: 14px;
}
.hint {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<section class="panel">
<div class="eyebrow">Object Study 01</div>
<h1>Knitted warming bottle</h1>
<p class="subtitle">
A soft voxel vessel, exposed beneath a partially peeled, honey-colored
knitted insulating sleeve.
</p>
<label class="control-label" for="peel">
<span>Sleeve peel</span>
<output id="peelValue" for="peel">78%</output>
</label>
<input id="peel" type="range" min="0" max="100" value="78" />
<div class="range-ends">
<span>Covered</span>
<span>Peeled aside</span>
</div>
<div class="legend">
<div class="legend-row">
<span class="swatch vessel"></span>
Flexible silicone vessel
</div>
<div class="legend-row">
<span class="swatch sleeve"></span>
Knitted insulating sleeve
</div>
<div class="legend-row">
<span class="swatch cap"></span>
Ribbed screw cap
</div>
</div>
<button id="reset" type="button">Reset camera</button>
</section>
<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(0xeee6da);
scene.fog = new THREE.Fog(0xeee6da, 11, 20);
const camera = new THREE.PerspectiveCamera(
36,
innerWidth / innerHeight,
0.1,
40
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance",
});
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;
document.body.prepend(renderer.domElement);
const target = new THREE.Vector3(0.18, 1.82, 0);
const desired = {
theta: -0.63,
phi: 1.16,
radius: 7.35,
};
const current = { ...desired };
const hemisphere = new THREE.HemisphereLight(0xfff4df, 0x77746e, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d9, 3.1);
keyLight.position.set(-4.5, 8.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xa9d9d4, 1.35);
rimLight.position.set(5, 5, -6);
scene.add(rimLight);
const warmGlow = new THREE.PointLight(0xff9b61, 0.38, 3.2, 2);
warmGlow.position.set(-0.4, 1.65, 0.15);
scene.add(warmGlow);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
function createColorInstances(entries, material, parent, castShadow = true) {
const mesh = new THREE.InstancedMesh(unitBox, material, entries.length);
const color = new THREE.Color();
entries.forEach((entry, index) => {
dummy.position.set(...entry.position);
dummy.rotation.set(
entry.rotation?.[0] ?? 0,
entry.rotation?.[1] ?? 0,
entry.rotation?.[2] ?? 0
);
dummy.scale.set(...entry.scale);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
color.set(entry.color ?? 0xffffff);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
mesh.computeBoundingSphere();
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Voxel tiled ground
// ---------------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.98,
metalness: 0,
});
const tileEntries = [];
const tileColors = [0xe8dfd2, 0xeee6da, 0xe3d9cc, 0xf0e8de];
const tileCount = 17;
const tileSize = 0.72;
for (let x = 0; x < tileCount; x++) {
for (let z = 0; z < tileCount; z++) {
const jitter = ((x * 17 + z * 31) % 7) * 0.0015;
tileEntries.push({
position: [
(x - (tileCount - 1) / 2) * tileSize,
-0.085 - jitter,
(z - (tileCount - 1) / 2) * tileSize,
],
scale: [tileSize - 0.025, 0.16, tileSize - 0.025],
color: tileColors[(x + z * 3) % tileColors.length],
});
}
}
createColorInstances(tileEntries, groundMaterial, scene, false);
// ---------------------------------------------------------------------
// Product root
// ---------------------------------------------------------------------
const product = new THREE.Group();
product.position.x = -0.42;
scene.add(product);
// ---------------------------------------------------------------------
// Flexible vessel: a softly shouldered rectangular grid of voxels
// ---------------------------------------------------------------------
const vesselMaterial = new THREE.MeshPhysicalMaterial({
color: 0xffffff,
roughness: 0.48,
metalness: 0,
clearcoat: 0.15,
clearcoatRoughness: 0.72,
emissive: 0x2b0907,
emissiveIntensity: 0.09,
});
const vesselBase = new THREE.Color(0xd36f68);
const vesselLight = new THREE.Color(0xef9588);
const vesselDark = new THREE.Color(0xb85856);
const vesselEntries = [];
const voxelSize = 0.28;
const rows = [
[6, 4], // rounded foot
[8, 5],
[8, 5],
[8, 5],
[8, 5],
[8, 5],
[8, 5],
[8, 5],
[8, 5],
[8, 5],
[8, 5],
[7, 4], // shoulder
[6, 4],
[4, 3], // neck
];
rows.forEach(([columns, depth], row) => {
for (let ix = 0; ix < columns; ix++) {
for (let iz = 0; iz < depth; iz++) {
let x = (ix - (columns - 1) / 2) * voxelSize;
const z = (iz - (depth - 1) / 2) * voxelSize;
const y = voxelSize / 2 + row * voxelSize;
let scale = voxelSize * 0.958;
// A shallow compression around the middle edges gives the vessel
// a soft, flexible silhouette rather than a hard rectangular block.
if (row >= 3 && row <= 8 && Math.abs(x) > 0.8 && Math.abs(z) > 0.3) {
scale *= 0.92;
x += Math.sign(x) * -0.018;
}
const edge = Math.max(Math.abs(x) / 1.15, Math.abs(z) / 0.72);
const color = vesselBase.clone();
color.lerp(vesselLight, Math.max(0, 0.42 - edge * 0.27));
color.lerp(vesselDark, Math.max(0, edge - 0.45) * 0.34);
const variation = (((ix * 13 + iz * 7 + row * 5) % 9) - 4) * 0.004;
color.offsetHSL(0, 0, variation);
vesselEntries.push({
position: [x, y, z],
scale: [scale, scale, scale],
color: color.getHex(),
});
}
}
});
createColorInstances(vesselEntries, vesselMaterial, product);
// Thin embossed front seam suggests a flexible, sewn or molded vessel.
const seamEntries = [];
for (let y = 0.42; y < 3.12; y += 0.14) {
seamEntries.push({
position: [0, y, 0.708],
scale: [0.035, 0.085, 0.026],
color: (Math.round(y * 10) % 2) ? 0xf0b1a5 : 0xe59a90,
});
}
const seamMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.62,
});
createColorInstances(seamEntries, seamMaterial, product);
// ---------------------------------------------------------------------
// Screw cap: stacked voxel cylinder with a ridged grip
// ---------------------------------------------------------------------
const capEntries = [];
const capColors = [0x294b50, 0x345b60, 0x3e6669, 0x213f44];
for (let layer = 0; layer < 3; layer++) {
const radius = layer === 0 ? 3.15 : layer === 1 ? 3.35 : 3.05;
const y = 4.08 + layer * 0.18;
for (let x = -3; x <= 3; x++) {
for (let z = -3; z <= 3; z++) {
if (x * x + z * z > radius * radius) continue;
capEntries.push({
position: [x * 0.19, y, z * 0.19],
scale: [0.184, 0.174, 0.184],
color: capColors[(x + z * 2 + layer + 9) % capColors.length],
});
}
}
}
// Grip blocks around the cap's middle layer.
for (let x = -3; x <= 3; x++) {
for (let z = -3; z <= 3; z++) {
const radial = x * x + z * z;
if (radial < 7 || radial > 10) continue;
capEntries.push({
position: [x * 0.205, 4.265, z * 0.205],
scale: [0.125, 0.16, 0.125],
color: 0x1d383d,
});
}
}
const capMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.58,
metalness: 0.05,
});
createColorInstances(capEntries, capMaterial, product);
// Small pixel-like cap top detail.
const capTopEntries = [];
for (const [x, z] of [
[-0.075, -0.075],
[0.075, -0.075],
[-0.075, 0.075],
[0.075, 0.075],
]) {
capTopEntries.push({
position: [x, 4.455, z],
scale: [0.105, 0.045, 0.105],
color: 0x547a7b,
});
}
createColorInstances(capTopEntries, capMaterial, product);
// ---------------------------------------------------------------------
// Knitted sleeve
// ---------------------------------------------------------------------
const yarnPalette = [0xd8884f, 0xefa866, 0xb9623e, 0xf5bd7d];
const yarnMaterials = yarnPalette.map(
(color) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.96,
metalness: 0,
flatShading: true,
})
);
function createYarn(entries, parent) {
const buckets = yarnPalette.map(() => []);
entries.forEach((entry) => {
buckets[entry.colorIndex % yarnPalette.length].push(entry);
});
buckets.forEach((bucket, paletteIndex) => {
if (!bucket.length) return;
const mesh = new THREE.InstancedMesh(
unitBox,
yarnMaterials[paletteIndex],
bucket.length
);
bucket.forEach((entry, index) => {
dummy.position.set(...entry.position);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(...entry.scale);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.computeBoundingSphere();
parent.add(mesh);
});
}
// A regular grid of offset courses and vertical wales creates the
// chunky, unmistakably knitted surface from individual yarn voxels.
function knitXY(entries, xMin, xMax, yMin, yMax, z) {
const columns = Math.max(4, Math.round((xMax - xMin) / 0.205));
const rowsCount = Math.max(3, Math.round((yMax - yMin) / 0.205));
const columnStep = (xMax - xMin) / columns;
const rowStep = (yMax - yMin) / rowsCount;
for (let row = 0; row < rowsCount; row++) {
const y = yMin + (row + 0.5) * rowStep;
const shift = row % 2 === 0 ? -columnStep * 0.16 : columnStep * 0.16;
for (let column = 0; column < columns; column++) {
const x = THREE.MathUtils.clamp(
xMin + (column + 0.5) * columnStep + shift,
xMin + 0.04,
xMax - 0.04
);
entries.push({
position: [x, y, z],
scale: [columnStep * 0.78, rowStep * 0.60, 0.135],
colorIndex: (row * 2 + column) % yarnPalette.length,
});
}
}
for (let row = 0; row < rowsCount; row++) {
for (let column = 0; column < columns; column += 2) {
const x = xMin + (column + 0.5) * columnStep;
const y = yMin + (row + 0.5) * rowStep;
entries.push({
position: [x, y, z + 0.008],
scale: [0.075, rowStep * 0.93, 0.115],
colorIndex: (row + column + 1) % yarnPalette.length,
});
}
}
}
function knitZY(entries, x, zMin, zMax, yMin, yMax) {
const columns = Math.max(4, Math.round((zMax - zMin) / 0.205));
const rowsCount = Math.max(3, Math.round((yMax - yMin) / 0.205));
const columnStep = (zMax - zMin) / columns;
const rowStep = (yMax - yMin) / rowsCount;
for (let row = 0; row < rowsCount; row++) {
const y = yMin + (row + 0.5) * rowStep;
const shift = row % 2 === 0 ? -columnStep * 0.16 : columnStep * 0.16;
for (let column = 0; column < columns; column++) {
const z = THREE.MathUtils.clamp(
zMin + (column + 0.5) * columnStep + shift,
zMin + 0.04,
zMax - 0.04
);
entries.push({
position: [x, y, z],
scale: [0.135, rowStep * 0.60, columnStep * 0.78],
colorIndex: (row * 2 + column + 2) % yarnPalette.length,
});
}
}
for (let row = 0; row < rowsCount; row++) {
for (let column = 0; column < columns; column += 2) {
const z = zMin + (column + 0.5) * columnStep;
const y = yMin + (row + 0.5) * rowStep;
entries.push({
position: [x + 0.008, y, z],
scale: [0.115, rowStep * 0.93, 0.075],
colorIndex: (row + column) % yarnPalette.length,
});
}
}
}
const sleeveEntries = [];
// Back and side walls remain wrapped around the bottle.
knitXY(sleeveEntries, -1.23, 1.23, 0.02, 2.62, -0.79);
knitZY(sleeveEntries, -1.23, -0.79, 0.79, 0.02, 2.62);
knitZY(sleeveEntries, 1.23, -0.79, 0.79, 0.02, 2.62);
// The lower front band stays attached.
knitXY(sleeveEntries, -1.23, 1.23, 0.02, 0.79, 0.79);
// Chunky upper cuff on the portions still wrapped around the vessel.
for (let x = -1.12; x <= 1.13; x += 0.205) {
sleeveEntries.push({
position: [x, 2.62, -0.79],
scale: [0.19, 0.22, 0.19],
colorIndex: Math.round((x + 2) * 5) % yarnPalette.length,
});
}
for (let z = -0.69; z <= 0.7; z += 0.205) {
sleeveEntries.push({
position: [-1.23, 2.62, z],
scale: [0.19, 0.22, 0.19],
colorIndex: Math.round((z + 2) * 7) % yarnPalette.length,
});
sleeveEntries.push({
position: [1.23, 2.62, z],
scale: [0.19, 0.22, 0.19],
colorIndex: Math.round((z + 3) * 6) % yarnPalette.length,
});
}
createYarn(sleeveEntries, product);
// Upper front panel is hinged at the sleeve's right edge. Pulling the
// slider rotates it aside, revealing the flexible vessel underneath.
const flap = new THREE.Group();
flap.position.set(1.23, 0, 0.79);
product.add(flap);
const flapEntries = [];
knitXY(flapEntries, -2.46, -0.03, 0.79, 2.62, 0);
// A short loose yarn end emphasizes that the knitted cover is being removed.
for (let i = 0; i < 5; i++) {
flapEntries.push({
position: [-2.52 - i * 0.09, 1.62 + i * 0.045, 0],
scale: [0.105, 0.105, 0.11],
colorIndex: i % yarnPalette.length,
});
}
createYarn(flapEntries, flap);
// ---------------------------------------------------------------------
// Direct camera controls
// ---------------------------------------------------------------------
const canvas = renderer.domElement;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let activePointer = null;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
activePointer = event.pointerId;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(desired.phi - dy * 0.005, 0.56, 1.43);
});
function stopDragging(event) {
if (event && event.pointerId !== activePointer) return;
dragging = false;
activePointer = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("lostpointercapture", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius + event.deltaY * 0.0045,
4.3,
10.5
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
desired.theta = -0.63;
desired.phi = 1.16;
desired.radius = 7.35;
});
const peelSlider = document.querySelector("#peel");
const peelOutput = document.querySelector("#peelValue");
let targetPeel = Number(peelSlider.value) / 100;
let currentPeel = targetPeel;
peelSlider.addEventListener("input", () => {
targetPeel = Number(peelSlider.value) / 100;
peelOutput.value = `${peelSlider.value}%`;
});
document.querySelector("#reset").addEventListener("click", () => {
desired.theta = -0.63;
desired.phi = 1.16;
desired.radius = 7.35;
});
// ---------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
renderer.setAnimationLoop(() => {
current.theta = THREE.MathUtils.lerp(current.theta, desired.theta, 0.075);
current.phi = THREE.MathUtils.lerp(current.phi, desired.phi, 0.075);
current.radius = THREE.MathUtils.lerp(current.radius, desired.radius, 0.075);
currentPeel = THREE.MathUtils.lerp(currentPeel, targetPeel, 0.085);
flap.rotation.y =
currentPeel * THREE.MathUtils.degToRad(135);
const sinPhi = Math.sin(current.phi);
camera.position.set(
target.x + current.radius * sinPhi * Math.sin(current.theta),
target.y + current.radius * Math.cos(current.phi),
target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(target);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```