Prompt specification
Build or customize the Three.js 3D scene "Worn Handle and Replacement Grip" 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: Worn Handle and Replacement Grip
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/worn-handle-and-replacement-grip-x3289
Scene Description Prompt:
Model a low-poly tool handle with wear concentrated where hands grip, alongside a fitted replacement grip. One HTML file using Three.js from cdnjs.
Working Three.js Starter (worn-handle-and-replacement-grip-x3289):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Grip Renewal — Low-Poly Tool Handle Study</title>
<style>
:root {
color-scheme: dark;
--text: #f1f4f5;
--muted: #9aa5ad;
--line: rgba(255, 255, 255, 0.13);
--panel: rgba(17, 22, 27, 0.78);
--orange: #d7682f;
--teal: #48c4b5;
--tan: #c4a17b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 28%, #2a333d 0%, #171d23 38%, #090c0f 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body::after {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(5, 7, 9, 0.22), transparent 24%),
linear-gradient(0deg, rgba(5, 7, 9, 0.45), transparent 30%);
z-index: 2;
}
#stage {
position: fixed;
inset: 0;
z-index: 1;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
header {
position: fixed;
z-index: 4;
top: 30px;
left: 34px;
max-width: 440px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 10px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(27px, 3.1vw, 46px);
font-weight: 720;
letter-spacing: -0.045em;
line-height: 1.02;
}
header p {
max-width: 370px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.specs {
position: fixed;
z-index: 4;
top: 32px;
right: 34px;
display: flex;
gap: 8px;
pointer-events: none;
}
.spec {
min-width: 106px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(15, 20, 25, 0.55);
backdrop-filter: blur(12px);
}
.spec span {
display: block;
margin-bottom: 4px;
color: #75818a;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.spec strong {
font-size: 12px;
font-weight: 650;
}
.model-tag {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 9px;
width: max-content;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(13, 18, 22, 0.78);
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(12px);
pointer-events: none;
opacity: 0;
transition: opacity 180ms ease;
}
.model-tag.visible {
opacity: 1;
}
.model-tag b {
display: grid;
place-items: center;
width: 25px;
height: 25px;
border-radius: 6px;
background: rgba(215, 104, 47, 0.16);
color: #ed9660;
font-size: 10px;
}
.model-tag.new b {
background: rgba(72, 196, 181, 0.16);
color: var(--teal);
}
.model-tag span {
font-size: 11px;
font-weight: 700;
}
.model-tag small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 500;
}
#oldTag {
transform: translate(calc(-100% - 28px), -50%);
}
#oldTag::after {
content: "";
position: absolute;
top: 50%;
left: 100%;
width: 28px;
height: 1px;
background: rgba(255, 255, 255, 0.35);
}
#newTag {
transform: translate(28px, -50%);
}
#newTag::after {
content: "";
position: absolute;
top: 50%;
right: 100%;
width: 28px;
height: 1px;
background: rgba(255, 255, 255, 0.35);
}
.caption {
position: fixed;
z-index: 4;
bottom: 27px;
width: 245px;
padding: 14px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
backdrop-filter: blur(16px);
pointer-events: none;
}
.caption.left {
left: 34px;
}
.caption.right {
right: 34px;
}
.caption-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
font-size: 12px;
font-weight: 750;
}
.caption-title i {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 4px rgba(215, 104, 47, 0.12);
}
.caption.right .caption-title i {
background: var(--teal);
box-shadow: 0 0 0 4px rgba(72, 196, 181, 0.12);
}
.caption p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.swatches {
display: flex;
gap: 5px;
margin-top: 10px;
}
.swatch {
width: 21px;
height: 5px;
border-radius: 4px;
}
.controls {
position: fixed;
z-index: 5;
left: 50%;
bottom: 27px;
display: flex;
align-items: center;
gap: 12px;
padding: 7px 8px 7px 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(13, 18, 22, 0.76);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(16px);
transform: translateX(-50%);
color: var(--muted);
font-size: 10px;
white-space: nowrap;
}
.controls kbd {
padding: 3px 6px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 5px;
background: rgba(255, 255, 255, 0.05);
color: #d7dde0;
font: inherit;
}
button {
border: 0;
border-radius: 999px;
padding: 8px 12px;
background: rgba(255, 255, 255, 0.09);
color: var(--text);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 700;
}
button:hover {
background: rgba(72, 196, 181, 0.17);
color: #9ce9df;
}
#loading {
position: fixed;
z-index: 10;
inset: 0;
display: grid;
place-items: center;
background: #11161b;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 350ms ease, visibility 350ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
#loading span::after {
content: "";
display: inline-block;
width: 5px;
height: 5px;
margin-left: 7px;
border-radius: 50%;
background: var(--teal);
animation: pulse 900ms infinite alternate;
}
@keyframes pulse {
to {
opacity: 0.25;
transform: scale(0.7);
}
}
@media (max-width: 920px) {
.model-tag,
.caption {
display: none;
}
.controls {
bottom: 18px;
}
.specs {
display: none;
}
}
@media (max-width: 560px) {
header {
top: 22px;
left: 22px;
max-width: 330px;
}
header p {
display: none;
}
.controls .desktop-only {
display: none;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive 3D tool handle comparison"></main>
<header>
<div class="eyebrow">Grip / Renewal 07</div>
<h1>Worn where it matters.</h1>
<p>
A faceted original handle with abrasion concentrated around the palm and
thumb zones, paired with a cleanly fitted replacement sleeve.
</p>
</header>
<div class="specs">
<div class="spec">
<span>Geometry</span>
<strong>12 facets</strong>
</div>
<div class="spec">
<span>Surface</span>
<strong>Procedural wear</strong>
</div>
</div>
<div class="model-tag" id="oldTag">
<b>01</b>
<span>Original grip<small>contact-zone abrasion + grime</small></span>
</div>
<div class="model-tag new" id="newTag">
<b>02</b>
<span>Fitted replacement<small>textured elastomer sleeve</small></span>
</div>
<aside class="caption left">
<div class="caption-title">
Original handle <i></i>
</div>
<p>
Rubber is polished away at the lower palm grip and upper thumb rest.
Dark grime remains in the recessed edges.
</p>
<div class="swatches" aria-hidden="true">
<span class="swatch" style="background:#d7682f"></span>
<span class="swatch" style="background:#c4a17b"></span>
<span class="swatch" style="background:#e2c49d"></span>
<span class="swatch" style="background:#4a3024"></span>
</div>
</aside>
<aside class="caption right">
<div class="caption-title">
Replacement grip <i></i>
</div>
<p>
A close-fit, low-profile sleeve with stepped traction ribs and teal
alignment collars at the neck and butt.
</p>
</aside>
<div class="controls">
<span class="desktop-only"><kbd>Drag</kbd> orbit</span>
<span class="desktop-only"><kbd>Scroll</kbd> zoom</span>
<button id="reset" type="button">Reset view</button>
</div>
<div id="loading"><span>Building grip study</span></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 oldTag = document.querySelector("#oldTag");
const newTag = document.querySelector("#newTag");
const resetButton = document.querySelector("#reset");
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x11161b, 0.025);
const camera = new THREE.PerspectiveCamera(
36,
innerWidth / innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.setClearColor(0x11161b, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xdbeeff, 0x312018, 1.65);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff1dc, 3.2);
key.position.set(-4.5, 7, 6.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -5;
key.shadow.camera.right = 5;
key.shadow.camera.top = 6;
key.shadow.camera.bottom = -4;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 20;
key.shadow.bias = -0.0006;
scene.add(key);
const rim = new THREE.DirectionalLight(0x8cd9e5, 1.55);
rim.position.set(5, 3.5, -4);
scene.add(rim);
const warmFill = new THREE.PointLight(0xff7c42, 18, 9, 2);
warmFill.position.set(-3, 0.8, 3);
scene.add(warmFill);
const coolFill = new THREE.PointLight(0x56e2d0, 12, 8, 2);
coolFill.position.set(3, -0.5, 3.5);
scene.add(coolFill);
/*
Builds an indexed, faceted loft around the Y axis.
The texture seam is placed behind the handle, keeping the front clean.
*/
function createLoftGeometry(profile, segments = 12, includeCaps = true) {
const positions = [];
const uvs = [];
const indices = [];
const yMin = profile[0][0];
const yMax = profile[profile.length - 1][0];
for (let i = 0; i < profile.length; i++) {
const [y, radius] = profile[i];
const v = (y - yMin) / (yMax - yMin);
for (let j = 0; j <= segments; j++) {
const u = j / segments;
const angle = -Math.PI + u * Math.PI * 2;
const x = Math.sin(angle) * radius;
const z = Math.cos(angle) * radius;
positions.push(x, y, z);
uvs.push(u, v);
}
}
for (let i = 0; i < profile.length - 1; i++) {
for (let j = 0; j < segments; j++) {
const a = i * (segments + 1) + j;
const b = a + 1;
const c = a + segments + 1;
const d = c + 1;
indices.push(a, b, c, b, d, c);
}
}
if (includeCaps) {
const bottomCenter = positions.length / 3;
positions.push(0, yMin, 0);
uvs.push(0.5, 0);
for (let j = 0; j < segments; j++) {
const a = j;
const b = j + 1;
indices.push(bottomCenter, b, a);
}
const topCenter = positions.length / 3;
positions.push(0, yMax, 0);
uvs.push(0.5, 1);
const topRing = (profile.length - 1) * (segments + 1);
for (let j = 0; j < segments; j++) {
const a = topRing + j;
const b = a + 1;
indices.push(topCenter, a, b);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (value * 1664525 + 1013904223) >>> 0;
return value / 4294967296;
};
}
/*
Procedural color map for the worn grip.
Wear clusters are positioned in UV space around the lower palm and
upper thumb contact areas.
*/
function createWearTexture() {
const size = 1024;
const canvas = document.createElement("canvas");
canvas.width = size;
canvas.height = size;
const ctx = canvas.getContext("2d");
const random = seededRandom(7319);
const base = ctx.createLinearGradient(0, 0, size, 0);
base.addColorStop(0, "#a94723");
base.addColorStop(0.23, "#c95a28");
base.addColorStop(0.5, "#df7135");
base.addColorStop(0.76, "#c65b29");
base.addColorStop(1, "#9e4321");
ctx.fillStyle = base;
ctx.fillRect(0, 0, size, size);
for (let i = 0; i < 1600; i++) {
const x = random() * size;
const y = random() * size;
const alpha = 0.025 + random() * 0.055;
ctx.fillStyle = random() > 0.45
? `rgba(255,205,150,${alpha})`
: `rgba(50,20,12,${alpha})`;
ctx.fillRect(x, y, 1 + random() * 2, 1 + random() * 3);
}
function blob(cx, cy, rx, ry, color, seed) {
const localRandom = seededRandom(seed);
const points = 15;
ctx.beginPath();
for (let i = 0; i <= points; i++) {
const angle = (i / points) * Math.PI * 2;
const radius = 0.72 + localRandom() * 0.38;
const x = cx + Math.cos(angle) * rx * radius;
const y = cy + Math.sin(angle) * ry * radius;
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.closePath();
ctx.fillStyle = color;
ctx.fill();
}
// Lower palm contact: broad grime, exposed substrate, rubbed edges.
blob(size * 0.49, size * 0.72, 175, 110, "rgba(55,31,20,.58)", 11);
blob(size * 0.49, size * 0.71, 111, 69, "rgba(174,130,88,.95)", 12);
blob(size * 0.47, size * 0.69, 74, 42, "rgba(222,190,150,.86)", 13);
blob(size * 0.37, size * 0.76, 66, 44, "rgba(66,38,24,.48)", 14);
blob(size * 0.61, size * 0.78, 73, 39, "rgba(55,30,19,.50)", 15);
blob(size * 0.61, size * 0.76, 36, 22, "rgba(189,148,103,.74)", 16);
// Upper thumb contact.
blob(size * 0.54, size * 0.29, 94, 54, "rgba(52,29,19,.55)", 17);
blob(size * 0.54, size * 0.28, 57, 32, "rgba(184,140,98,.88)", 18);
blob(size * 0.53, size * 0.27, 28, 15, "rgba(235,205,165,.85)", 19);
// Side-friction patches.
blob(size * 0.69, size * 0.58, 47, 61, "rgba(62,35,23,.42)", 20);
blob(size * 0.69, size * 0.58, 25, 33, "rgba(184,141,96,.66)", 21);
blob(size * 0.31, size * 0.65, 38, 51, "rgba(56,31,20,.42)", 22);
blob(size * 0.31, size * 0.65, 20, 27, "rgba(202,159,113,.67)", 23);
// Fine abrasion strokes, concentrated in the contact zones.
ctx.lineCap = "round";
const scratchZones = [
[0.49, 0.71, 0.13, 0.08],
[0.54, 0.28, 0.07, 0.045],
[0.69, 0.58, 0.045, 0.055]
];
let scratchIndex = 0;
for (const [ux, uy, rx, ry] of scratchZones) {
for (let i = 0; i < 90; i++) {
const x = size * (ux + (random() - 0.5) * rx);
const y = size * (uy + (random() - 0.5) * ry);
const length = 3 + random() * 22;
const angle = -0.5 + random() * 1.0;
ctx.strokeStyle = random() > 0.38
? `rgba(244,222,188,${0.18 + random() * 0.38})`
: `rgba(42,24,16,${0.15 + random() * 0.32})`;
ctx.lineWidth = 0.6 + random() * 1.6;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(
x + Math.cos(angle) * length,
y + Math.sin(angle) * length
);
ctx.stroke();
scratchIndex++;
}
}
// A few longer cuts across the lower contact area.
for (let i = 0; i < 18; i++) {
const x = size * (0.40 + random() * 0.20);
const y = size * (0.66 + random() * 0.13);
const length = 10 + random() * 36;
ctx.strokeStyle = `rgba(51,28,18,${0.22 + random() * 0.25})`;
ctx.lineWidth = 1 + random() * 1.2;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + length, y + (random() - 0.5) * 8);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
texture.wrapS = THREE.RepeatWrapping;
return texture;
}
const orangeMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
map: createWearTexture(),
roughness: 0.88,
metalness: 0.02,
flatShading: true
});
const darkRubber = new THREE.MeshStandardMaterial({
color: 0x20262a,
roughness: 0.8,
metalness: 0.02,
flatShading: true
});
const blackRubber = new THREE.MeshStandardMaterial({
color: 0x101518,
roughness: 0.72,
metalness: 0.025,
flatShading: true
});
const tealMaterial = new THREE.MeshStandardMaterial({
color: 0x43bbae,
emissive: 0x0b2523,
emissiveIntensity: 0.28,
roughness: 0.62,
metalness: 0.08,
flatShading: true
});
const oldSteel = new THREE.MeshStandardMaterial({
color: 0x686d6e,
roughness: 0.54,
metalness: 0.82,
flatShading: true
});
const newSteel = new THREE.MeshStandardMaterial({
color: 0xb9c3c8,
roughness: 0.25,
metalness: 0.92,
flatShading: true
});
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x171c21,
roughness: 0.96,
metalness: 0.02
});
const plinthMaterial = new THREE.MeshStandardMaterial({
color: 0x242b31,
roughness: 0.78,
metalness: 0.12,
flatShading: true
});
function mesh(geometry, material, parent, position = [0, 0, 0]) {
const object = new THREE.Mesh(geometry, material);
object.position.set(...position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
const oldGroup = new THREE.Group();
oldGroup.position.set(-1.18, 0, 0);
oldGroup.rotation.y = -0.13;
oldGroup.rotation.z = -0.025;
scene.add(oldGroup);
const newGroup = new THREE.Group();
newGroup.position.set(1.18, 0, 0);
newGroup.rotation.y = 0.13;
newGroup.rotation.z = 0.025;
scene.add(newGroup);
// Original worn handle.
const oldProfile = [
[-2.05, 0.14],
[-1.98, 0.33],
[-1.82, 0.50],
[-1.66, 0.56],
[-1.58, 0.52],
[-1.50, 0.56],
[-1.28, 0.60],
[-1.18, 0.56],
[-1.10, 0.60],
[-0.90, 0.61],
[-0.80, 0.57],
[-0.72, 0.60],
[-0.52, 0.56],
[-0.42, 0.51],
[-0.34, 0.55],
[-0.12, 0.49],
[-0.02, 0.44],
[0.08, 0.46],
[0.26, 0.37],
[0.42, 0.32],
[0.58, 0.27],
[0.65, 0.26]
];
mesh(createLoftGeometry(oldProfile), orangeMaterial, oldGroup);
mesh(
createLoftGeometry([
[-2.13, 0.08],
[-2.09, 0.16],
[-2.00, 0.31]
]),
darkRubber,
oldGroup
);
mesh(
new THREE.CylinderGeometry(0.25, 0.28, 0.2, 12, 1),
darkRubber,
oldGroup,
[0, 0.71, 0]
);
mesh(
new THREE.CylinderGeometry(0.255, 0.255, 0.19, 12, 1),
oldSteel,
oldGroup,
[0, 0.89, 0]
);
mesh(
new THREE.CylinderGeometry(0.095, 0.095, 1.15, 8, 1),
oldSteel,
oldGroup,
[0, 1.56, 0]
);
mesh(
new THREE.BoxGeometry(0.16, 0.28, 0.05),
oldSteel,
oldGroup,
[0, 2.17, 0]
);
// Fitted replacement grip.
const replacementProfile = [
[-1.98, 0.31],
[-1.92, 0.47],
[-1.78, 0.57],
[-1.62, 0.60],
[-1.52, 0.56],
[-1.44, 0.51],
[-1.35, 0.58],
[-1.15, 0.58],
[-1.07, 0.52],
[-0.99, 0.59],
[-0.79, 0.59],
[-0.71, 0.52],
[-0.63, 0.58],
[-0.43, 0.55],
[-0.35, 0.49],
[-0.27, 0.55],
[-0.07, 0.50],
[0.01, 0.44],
[0.09, 0.49],
[0.28, 0.40],
[0.42, 0.32],
[0.53, 0.28]
];
mesh(createLoftGeometry(replacementProfile), blackRubber, newGroup);
mesh(
createLoftGeometry([
[-2.07, 0.22],
[-2.03, 0.31],
[-1.91, 0.47]
]),
tealMaterial,
newGroup
);
mesh(
createLoftGeometry([
[0.47, 0.31],
[0.51, 0.34],
[0.68, 0.30],
[0.74, 0.25]
]),
tealMaterial,
newGroup
);
mesh(
new THREE.CylinderGeometry(0.25, 0.25, 0.18, 12, 1),
darkRubber,
newGroup,
[0, 0.77, 0]
);
mesh(
new THREE.CylinderGeometry(0.255, 0.255, 0.19, 12, 1),
newSteel,
newGroup,
[0, 0.94, 0]
);
mesh(
new THREE.CylinderGeometry(0.09, 0.09, 1.13, 8, 1),
newSteel,
newGroup,
[0, 1.58, 0]
);
mesh(
new THREE.BoxGeometry(0.15, 0.28, 0.045),
newSteel,
newGroup,
[0, 2.19, 0]
);
// Molded diamond badge on the front of the replacement sleeve.
const badge = mesh(
new THREE.OctahedronGeometry(0.13, 0),
tealMaterial,
newGroup,
[0, -0.44, 0.54]
);
badge.scale.set(1, 0.56, 0.25);
badge.rotation.y = Math.PI / 4;
// Fine collar seams.
for (const [y, radius] of [
[-1.88, 0.475],
[0.53, 0.335]
]) {
const seam = mesh(
new THREE.TorusGeometry(radius, 0.018, 4, 12),
darkRubber,
newGroup,
[0, y, 0]
);
seam.rotation.x = Math.PI / 2;
}
// Studio floor and low-poly display plinths.
const floor = mesh(
new THREE.PlaneGeometry(40, 40),
floorMaterial,
scene,
[0, -2.15, 0]
);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
for (const x of [-1.18, 1.18]) {
mesh(
new THREE.CylinderGeometry(0.66, 0.72, 0.09, 6),
plinthMaterial,
scene,
[x, -2.115, 0]
);
const inset = mesh(
new THREE.TorusGeometry(0.53, 0.012, 4, 6),
x < 0 ? oldSteel : tealMaterial,
scene,
[x, -2.063, 0]
);
inset.rotation.x = Math.PI / 2;
}
/*
Camera controls implemented directly:
pointer drag orbits, wheel/pinch zooms.
*/
const target = new THREE.Vector3(0, 0.02, 0);
let theta = 0;
let phi = 1.36;
let zoom = 1;
let baseDistance = 7.8;
let dragging = false;
let lastX = 0;
let lastY = 0;
let lastPinch = 0;
const pointers = new Map();
function updateCamera() {
const distance = baseDistance * zoom;
const horizontal = Math.sin(phi) * distance;
camera.position.set(
target.x + horizontal * Math.sin(theta),
target.y + Math.cos(phi) * distance,
target.z + horizontal * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetCamera() {
theta = 0;
phi = 1.36;
zoom = 1;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
}
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinch = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1 && dragging) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
theta -= dx * 0.006;
phi = THREE.MathUtils.clamp(phi + dy * 0.004, 0.72, 1.53);
lastX = event.clientX;
lastY = event.clientY;
}
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinch > 0 && distance > 0) {
zoom = THREE.MathUtils.clamp(
zoom * (lastPinch / distance),
0.68,
1.65
);
}
lastPinch = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
dragging = false;
}
if (pointers.size < 2) {
lastPinch = 0;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(event.deltaY * 0.001),
0.68,
1.65
);
},
{ passive: false }
);
resetButton.addEventListener("click", resetCamera);
addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetCamera();
});
function resize() {
const width = innerWidth;
const height = innerHeight;
const aspect = width / height;
camera.aspect = aspect;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
baseDistance = 7.8 * Math.max(1, 0.78 / aspect);
updateCamera();
}
addEventListener("resize", resize);
resize();
const oldAnchor = new THREE.Vector3();
const newAnchor = new THREE.Vector3();
const projected = new THREE.Vector3();
function placeTag(element, anchor, visible) {
projected.copy(anchor).project(camera);
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.classList.toggle(
"visible",
visible && projected.z > -1 && projected.z < 1
);
}
function animate() {
updateCamera();
scene.updateMatrixWorld(true);
oldGroup.localToWorld(oldAnchor.set(0, -0.55, 0.58));
newGroup.localToWorld(newAnchor.set(0, -0.55, 0.58));
placeTag(oldTag, oldAnchor, innerWidth > 920);
placeTag(newTag, newAnchor, innerWidth > 920);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```