Prompt specification
Build or customize the Three.js 3D scene "Shirt fold-line plan" 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: Shirt fold-line plan
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shirt-fold-line-plan-x0573
Scene Description Prompt:
Show a flat shirt with clear fold guides and a shallow suitcase compartment; mark sleeve and torso regions so their sequential movement remains understandable. Use Three.js from cdnjs in a single HTML file, with stylized solid shapes.
Working Three.js Starter (shirt-fold-line-plan-x0573):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Shirt Packing Sequence</title>
<style>
:root {
--ink: #21313c;
--muted: #697780;
--paper: #eeece6;
--sleeve: #e9a83d;
--torso: #e66f61;
--panel: rgba(250, 249, 245, 0.92);
--line: rgba(33, 49, 60, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.header {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 3.6vw, 52px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 310px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.toolbar {
position: fixed;
top: 28px;
right: 30px;
z-index: 10;
display: flex;
align-items: center;
gap: 8px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 12px;
padding: 10px 14px;
background: var(--panel);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 7px 20px rgba(34, 45, 52, 0.07);
backdrop-filter: blur(12px);
transition:
transform 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(33, 49, 60, 0.34);
}
button.primary {
border-color: var(--ink);
background: var(--ink);
color: white;
}
.camera-help {
position: fixed;
right: 30px;
bottom: 30px;
z-index: 5;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
}
.legend {
position: fixed;
left: 30px;
bottom: 30px;
z-index: 5;
display: flex;
align-items: center;
gap: 18px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.dash-sample {
width: 29px;
border-top: 2px dashed var(--ink);
}
.arrow-sample {
color: var(--ink);
font-size: 19px;
line-height: 0;
}
.sequence-wrap {
position: fixed;
left: 50%;
bottom: 26px;
z-index: 12;
transform: translateX(-50%);
padding: 8px;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 12px 35px rgba(34, 45, 52, 0.11);
backdrop-filter: blur(14px);
}
.sequence {
display: flex;
align-items: center;
gap: 5px;
}
.step {
min-width: 102px;
padding: 9px 12px;
border: 0;
border-radius: 10px;
background: transparent;
box-shadow: none;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.03em;
}
.step span {
margin-right: 5px;
font-weight: 900;
}
.step.active {
background: var(--ink);
color: white;
}
.step.done:not(.active) {
background: rgba(33, 49, 60, 0.08);
color: var(--ink);
}
.connector {
width: 16px;
height: 1px;
background: var(--line);
}
.region-tag,
.tray-tag {
position: fixed;
top: 0;
left: 0;
z-index: 4;
pointer-events: none;
white-space: nowrap;
will-change: transform, opacity;
}
.region-tag {
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px 6px 6px;
border: 1px solid rgba(33, 49, 60, 0.13);
border-radius: 999px;
background: rgba(255, 255, 255, 0.9);
color: var(--ink);
box-shadow: 0 7px 18px rgba(34, 45, 52, 0.09);
backdrop-filter: blur(8px);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.06em;
}
.region-tag .number {
display: grid;
width: 23px;
height: 23px;
place-items: center;
border-radius: 50%;
background: var(--tag-color);
color: #fff;
font-size: 10px;
font-weight: 900;
}
.region-tag .detail {
display: block;
margin-top: 1px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.02em;
}
.tray-tag {
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.phase {
position: fixed;
top: 132px;
left: 30px;
z-index: 5;
display: inline-flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(250, 249, 245, 0.72);
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
pointer-events: none;
}
.phase-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--sleeve);
box-shadow: 0 0 0 4px rgba(233, 168, 61, 0.15);
}
@media (max-width: 760px) {
.header {
top: 20px;
left: 20px;
}
.subtitle,
.camera-help,
.legend {
display: none;
}
.phase {
top: 112px;
left: 20px;
}
.toolbar {
top: 20px;
right: 20px;
}
#resetCamera {
display: none;
}
.sequence-wrap {
bottom: 16px;
width: calc(100% - 32px);
}
.sequence {
width: 100%;
}
.step {
flex: 1;
min-width: 0;
padding-inline: 5px;
}
.connector {
width: 7px;
}
.region-tag .detail {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<header class="header">
<div class="eyebrow">Packing Motion Study</div>
<h1>Fold the shirt.</h1>
<p class="subtitle">
Two marked regions, one clear sequence: sleeves inward first, then the
lower torso over the center.
</p>
</header>
<div class="phase">
<span class="phase-dot"></span>
<span id="phaseText">READY · FLAT SHIRT</span>
</div>
<div class="toolbar">
<button id="resetCamera" type="button">Reset view</button>
<button id="play" class="primary" type="button">Play sequence</button>
</div>
<div class="legend">
<div class="legend-item">
<span class="dash-sample"></span>
<span>Fold guide</span>
</div>
<div class="legend-item">
<span class="arrow-sample">→</span>
<span>Motion</span>
</div>
</div>
<div class="camera-help">Drag to orbit · Scroll to zoom</div>
<div class="sequence-wrap">
<div class="sequence">
<button class="step active" data-step="0" type="button">
<span>00</span>Flat
</button>
<div class="connector"></div>
<button class="step" data-step="1" type="button">
<span>01</span>Sleeves
</button>
<div class="connector"></div>
<button class="step" data-step="2" type="button">
<span>02</span>Torso
</button>
</div>
</div>
<div
id="leftSleeveTag"
class="region-tag"
style="--tag-color: var(--sleeve)"
>
<span class="number">01</span>
<span>SLEEVES<span class="detail">fold inward</span></span>
</div>
<div
id="rightSleeveTag"
class="region-tag"
style="--tag-color: var(--sleeve)"
>
<span class="number">01</span>
</div>
<div
id="torsoTag"
class="region-tag"
style="--tag-color: var(--torso)"
>
<span class="number">02</span>
<span>TORSO<span class="detail">lower half folds up</span></span>
</div>
<div id="trayTag" class="tray-tag">Shallow compartment</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeeece6);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
// The shirt lies in the XY plane, so Z is the visual vertical axis.
const cameraTarget = new THREE.Vector3(0, -0.05, 0.15);
let cameraAzimuth = 0.18;
let cameraElevation = 0.84;
let cameraRadius = 15.2;
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x82796d, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff6e9, 3.2);
keyLight.position.set(-5, -4, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xdcecff, 1.15);
fillLight.position.set(7, 5, 7);
scene.add(fillLight);
const background = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0xeeece6,
roughness: 1
})
);
background.position.z = -0.39;
background.receiveShadow = true;
scene.add(background);
function traceRoundedRectangle(path, width, height, radius, clockwise = false) {
const hw = width / 2;
const hh = height / 2;
if (!clockwise) {
path.moveTo(-hw + radius, -hh);
path.lineTo(hw - radius, -hh);
path.quadraticCurveTo(hw, -hh, hw, -hh + radius);
path.lineTo(hw, hh - radius);
path.quadraticCurveTo(hw, hh, hw - radius, hh);
path.lineTo(-hw + radius, hh);
path.quadraticCurveTo(-hw, hh, -hw, hh - radius);
path.lineTo(-hw, -hh + radius);
path.quadraticCurveTo(-hw, -hh, -hw + radius, -hh);
} else {
path.moveTo(-hw + radius, -hh);
path.lineTo(-hw, -hh + radius);
path.quadraticCurveTo(-hw, -hh, -hw + radius, -hh);
path.lineTo(hw - radius, -hh);
path.quadraticCurveTo(hw, -hh, hw, -hh + radius);
path.lineTo(hw, hh - radius);
path.quadraticCurveTo(hw, hh, hw - radius, hh);
path.lineTo(-hw + radius, hh);
path.quadraticCurveTo(-hw, hh, -hw, hh - radius);
}
path.closePath();
}
function roundedRectangleShape(width, height, radius) {
const shape = new THREE.Shape();
traceRoundedRectangle(shape, width, height, radius);
return shape;
}
// Suitcase: solid base, inner floor, and a raised hollow rim.
const suitcaseBase = new THREE.Mesh(
new THREE.ExtrudeGeometry(
roundedRectangleShape(6.72, 7.42, 0.46),
{
depth: 0.2,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.025,
bevelThickness: 0.025
}
),
new THREE.MeshStandardMaterial({
color: 0x293c4b,
roughness: 0.72,
metalness: 0.05
})
);
suitcaseBase.position.z = -0.34;
suitcaseBase.castShadow = true;
suitcaseBase.receiveShadow = true;
scene.add(suitcaseBase);
const rimShape = roundedRectangleShape(6.72, 7.42, 0.46);
const rimHole = new THREE.Path();
traceRoundedRectangle(rimHole, 6.02, 6.72, 0.34, true);
rimShape.holes.push(rimHole);
const suitcaseRim = new THREE.Mesh(
new THREE.ExtrudeGeometry(rimShape, {
depth: 0.28,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.025,
bevelThickness: 0.025
}),
new THREE.MeshStandardMaterial({
color: 0x354c5d,
roughness: 0.66,
metalness: 0.08
})
);
suitcaseRim.position.z = -0.1;
suitcaseRim.castShadow = true;
suitcaseRim.receiveShadow = true;
scene.add(suitcaseRim);
const trayFloor = new THREE.Mesh(
new THREE.ExtrudeGeometry(
roundedRectangleShape(6.02, 6.72, 0.34),
{
depth: 0.1,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.015,
bevelThickness: 0.015
}
),
new THREE.MeshStandardMaterial({
color: 0xd9ddd8,
roughness: 0.95
})
);
trayFloor.position.z = -0.12;
trayFloor.receiveShadow = true;
scene.add(trayFloor);
// Small suitcase handle.
const handleMaterial = new THREE.MeshStandardMaterial({
color: 0x20313e,
roughness: 0.65
});
const handle = new THREE.Mesh(
new THREE.BoxGeometry(1.45, 0.18, 0.18),
handleMaterial
);
handle.position.set(0, -3.93, -0.04);
handle.castShadow = true;
scene.add(handle);
for (const x of [-0.64, 0.64]) {
const connector = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.36, 0.18),
handleMaterial
);
connector.position.set(x, -3.75, -0.04);
connector.castShadow = true;
scene.add(connector);
}
// Dashed target footprint inside the shallow compartment.
const footprintGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-2.45, -2.87, 0.015),
new THREE.Vector3(2.45, -2.87, 0.015),
new THREE.Vector3(2.45, 2.87, 0.015),
new THREE.Vector3(-2.45, 2.87, 0.015),
new THREE.Vector3(-2.45, -2.87, 0.015)
]);
const footprint = new THREE.Line(
footprintGeometry,
new THREE.LineDashedMaterial({
color: 0x7b898f,
dashSize: 0.16,
gapSize: 0.12,
transparent: true,
opacity: 0.55
})
);
footprint.computeLineDistances();
scene.add(footprint);
const shirtRoot = new THREE.Group();
shirtRoot.position.z = 0.045;
scene.add(shirtRoot);
const sleeveMaterial = new THREE.MeshStandardMaterial({
color: 0xe9a83d,
roughness: 0.88
});
const torsoMaterial = new THREE.MeshStandardMaterial({
color: 0xe66f61,
roughness: 0.88
});
const lowerTorsoMaterial = new THREE.MeshStandardMaterial({
color: 0xd95d55,
roughness: 0.9
});
const outlineMaterial = new THREE.LineBasicMaterial({
color: 0x743d37,
transparent: true,
opacity: 0.48
});
const guideMaterial = new THREE.LineDashedMaterial({
color: 0x21313c,
dashSize: 0.14,
gapSize: 0.095,
transparent: true,
opacity: 0.88
});
function addPanel(parent, shape, material, outlineZ = 0.17) {
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.13,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.035,
bevelThickness: 0.03,
curveSegments: 16
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
const points = shape.getPoints(18).map(
(point) => new THREE.Vector3(point.x, point.y, outlineZ)
);
const outline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
outlineMaterial
);
parent.add(outline);
return mesh;
}
function createUpperTorsoShape() {
const shape = new THREE.Shape();
shape.moveTo(-0.78, 3.05);
shape.lineTo(-2.05, 2.72);
shape.lineTo(-2.05, 1.02);
shape.lineTo(-2.05, -0.38);
shape.lineTo(2.05, -0.38);
shape.lineTo(2.05, 1.02);
shape.lineTo(2.05, 2.72);
shape.lineTo(0.78, 3.05);
shape.quadraticCurveTo(0, 2.47, -0.78, 3.05);
shape.closePath();
return shape;
}
function createLowerTorsoShape() {
const shape = new THREE.Shape();
shape.moveTo(-2.05, 0);
shape.lineTo(2.05, 0);
shape.lineTo(2.07, -2.28);
shape.quadraticCurveTo(1.4, -2.53, 0, -2.5);
shape.quadraticCurveTo(-1.4, -2.53, -2.07, -2.28);
shape.closePath();
return shape;
}
function createLeftSleeveShape() {
const shape = new THREE.Shape();
shape.moveTo(0, 2.72);
shape.lineTo(-1.55, 1.83);
shape.lineTo(-1.12, 0.72);
shape.lineTo(0, 1.02);
shape.closePath();
return shape;
}
function createRightSleeveShape() {
const shape = new THREE.Shape();
shape.moveTo(0, 2.72);
shape.lineTo(1.55, 1.83);
shape.lineTo(1.12, 0.72);
shape.lineTo(0, 1.02);
shape.closePath();
return shape;
}
const torsoGroup = new THREE.Group();
shirtRoot.add(torsoGroup);
addPanel(torsoGroup, createUpperTorsoShape(), torsoMaterial);
const lowerTorsoPivot = new THREE.Group();
lowerTorsoPivot.position.y = -0.38;
shirtRoot.add(lowerTorsoPivot);
addPanel(lowerTorsoPivot, createLowerTorsoShape(), lowerTorsoMaterial);
const leftSleevePivot = new THREE.Group();
leftSleevePivot.position.x = -2.05;
shirtRoot.add(leftSleevePivot);
const rightSleevePivot = new THREE.Group();
rightSleevePivot.position.x = 2.05;
shirtRoot.add(rightSleevePivot);
addPanel(leftSleevePivot, createLeftSleeveShape(), sleeveMaterial);
addPanel(rightSleevePivot, createRightSleeveShape(), sleeveMaterial);
// Collar binding.
const collarPoints = [];
for (let i = 0; i <= 24; i++) {
const t = i / 24;
const x = 0.78 - 1.56 * t;
const y =
3.05 * (1 - t) * (1 - t) +
2.47 * 2 * (1 - t) * t +
3.05 * t * t;
collarPoints.push(new THREE.Vector3(x, y, 0.19));
}
const collar = new THREE.Mesh(
new THREE.TubeGeometry(
new THREE.CatmullRomCurve3(collarPoints),
32,
0.045,
8,
false
),
new THREE.MeshStandardMaterial({
color: 0xa94640,
roughness: 0.9
})
);
collar.castShadow = true;
torsoGroup.add(collar);
function createDashedGuide(parent, points) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => new THREE.Vector3(...point))
);
const line = new THREE.Line(geometry, guideMaterial.clone());
line.computeLineDistances();
parent.add(line);
return line;
}
// Crease guides remain attached to the torso while the sleeves move.
createDashedGuide(torsoGroup, [
[-2.05, 0.85, 0.205],
[-2.05, 2.77, 0.205]
]);
createDashedGuide(torsoGroup, [
[2.05, 0.85, 0.205],
[2.05, 2.77, 0.205]
]);
const torsoCrease = createDashedGuide(lowerTorsoPivot, [
[-2.05, 0, 0.205],
[2.05, 0, 0.205]
]);
function createArrow(parent, origin, direction, length) {
const arrow = new THREE.ArrowHelper(
direction,
new THREE.Vector3(...origin),
length,
0x21313c,
0.25,
0.15
);
arrow.line.material.transparent = true;
arrow.cone.material.transparent = true;
arrow.line.material.opacity = 0.88;
arrow.cone.material.opacity = 0.88;
parent.add(arrow);
return arrow;
}
const leftArrow = createArrow(
leftSleevePivot,
[-1.38, 1.38, 0.24],
new THREE.Vector3(1, -0.16, 0).normalize(),
1.12
);
const rightArrow = createArrow(
rightSleevePivot,
[1.38, 1.38, 0.24],
new THREE.Vector3(-1, -0.16, 0).normalize(),
1.12
);
const torsoArrow = createArrow(
lowerTorsoPivot,
[1.35, -2.18, 0.24],
new THREE.Vector3(0, 1, 0),
1.34
);
// Fold state.
const state = {
stage: 0,
sleeve: 0,
targetSleeve: 0,
torso: 0,
targetTorso: 0
};
const phaseText = document.getElementById("phaseText");
const stepButtons = [...document.querySelectorAll(".step")];
function updateStepUI() {
stepButtons.forEach((button, index) => {
button.classList.toggle("active", index === state.stage);
button.classList.toggle("done", index < state.stage);
});
const labels = [
"READY · FLAT SHIRT",
"STEP 01 · SLEEVES INWARD",
"STEP 02 · TORSO FOLDED"
];
phaseText.textContent = labels[state.stage];
}
function setStage(stage) {
state.stage = stage;
state.targetSleeve = stage >= 1 ? 1 : 0;
state.targetTorso = stage >= 2 ? 1 : 0;
updateStepUI();
}
stepButtons.forEach((button) => {
button.addEventListener("click", () => {
clearPlayTimers();
setStage(Number(button.dataset.step));
});
});
let playTimers = [];
function clearPlayTimers() {
playTimers.forEach((timer) => clearTimeout(timer));
playTimers = [];
}
document.getElementById("play").addEventListener("click", () => {
clearPlayTimers();
setStage(0);
playTimers.push(
setTimeout(() => {
if (state.stage === 0) setStage(1);
}, 650)
);
playTimers.push(
setTimeout(() => {
if (state.stage <= 1) setStage(2);
}, 3300)
);
});
// Custom orbit controls implemented directly in this file.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraAzimuth -= deltaX * 0.006;
cameraElevation = THREE.MathUtils.clamp(
cameraElevation + deltaY * 0.005,
0.38,
1.35
);
});
function stopDragging(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
9,
22
);
},
{ passive: false }
);
document.getElementById("resetCamera").addEventListener("click", () => {
cameraAzimuth = 0.18;
cameraElevation = 0.84;
cameraRadius = 15.2;
});
function updateCamera() {
const horizontal = cameraRadius * Math.cos(cameraElevation);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraAzimuth),
cameraTarget.y + horizontal * Math.cos(cameraAzimuth),
cameraTarget.z + cameraRadius * Math.sin(cameraElevation)
);
camera.up.set(0, 0, 1);
camera.lookAt(cameraTarget);
}
// Project HTML annotations onto their corresponding 3D regions.
const leftTag = document.getElementById("leftSleeveTag");
const rightTag = document.getElementById("rightSleeveTag");
const torsoTag = document.getElementById("torsoTag");
const trayTag = document.getElementById("trayTag");
function placeTag(element, object, localPosition) {
object.updateWorldMatrix(true, false);
const worldPosition = object.localToWorld(
new THREE.Vector3(...localPosition)
);
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform =
`translate(-50%, -50%) translate(${x}px, ${y}px)`;
element.style.opacity = visible ? "1" : "0";
}
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const easing = 1 - Math.exp(-delta * 5.4);
state.sleeve +=
(state.targetSleeve - state.sleeve) * easing;
state.torso +=
(state.targetTorso - state.torso) * easing;
const sleeveAngle = THREE.MathUtils.degToRad(150);
const torsoAngle = THREE.MathUtils.degToRad(145);
leftSleevePivot.rotation.y = state.sleeve * sleeveAngle;
rightSleevePivot.rotation.y = -state.sleeve * sleeveAngle;
lowerTorsoPivot.rotation.x = -state.torso * torsoAngle;
const arrowOpacity = 1 - state.sleeve * 0.48;
for (const arrow of [leftArrow, rightArrow]) {
arrow.line.material.opacity = arrowOpacity;
arrow.cone.material.opacity = arrowOpacity;
}
torsoArrow.line.material.opacity = 1 - state.torso * 0.48;
torsoArrow.cone.material.opacity = 1 - state.torso * 0.48;
torsoCrease.material.opacity = 0.88 - state.torso * 0.28;
updateCamera();
placeTag(leftTag, leftSleevePivot, [-0.9, 1.48, 0.38]);
placeTag(rightTag, rightSleevePivot, [0.9, 1.48, 0.38]);
placeTag(torsoTag, lowerTorsoPivot, [0.48, -1.35, 0.4]);
placeTag(trayTag, scene, [3.42, 3.25, 0.24]);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateStepUI();
animate();
</script>
</body>
</html>
```