Prompt specification
Build or customize the Three.js 3D scene "Garment measurement pattern card" 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: Garment measurement pattern card
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/garment-measurement-pattern-card-x0549
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: garment measurement pattern card. Show a simple shirt panel beside a measurement card with width and length arrows; matching reference points must be visible on both the garment and diagram.
Working Three.js Starter (garment-measurement-pattern-card-x0549):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Garment Measurement Pattern Card</title>
<style>
:root {
--ink: #173d3c;
--paper: #fbf8f1;
--coral: #e56750;
--gold: #e3a83b;
--muted: #6f7f78;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee8df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.brand {
position: absolute;
top: 28px;
left: 32px;
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
border-radius: 12px;
background: var(--coral);
color: white;
box-shadow: 0 9px 25px rgba(91, 55, 43, 0.16);
}
.brand-mark svg {
width: 25px;
height: 25px;
}
.eyebrow {
margin: 0 0 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(18px, 2vw, 25px);
line-height: 1;
letter-spacing: -0.045em;
}
.legend {
position: absolute;
top: 29px;
right: 30px;
display: flex;
align-items: center;
gap: 18px;
padding: 11px 14px;
border: 1px solid rgba(23, 61, 60, 0.12);
border-radius: 999px;
background: rgba(251, 248, 241, 0.72);
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04);
}
.swatch.coral {
background: var(--coral);
}
.swatch.gold {
background: var(--gold);
}
.specs {
position: absolute;
left: 32px;
bottom: 29px;
display: flex;
gap: 9px;
}
.spec {
min-width: 104px;
padding: 12px 14px;
border: 1px solid rgba(23, 61, 60, 0.11);
border-radius: 14px;
background: rgba(251, 248, 241, 0.76);
backdrop-filter: blur(12px);
box-shadow: 0 12px 35px rgba(46, 53, 46, 0.08);
}
.spec strong {
display: block;
margin-bottom: 2px;
font-size: 18px;
line-height: 1;
letter-spacing: -0.04em;
}
.spec span {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.controls {
position: absolute;
right: 30px;
bottom: 29px;
display: flex;
align-items: center;
gap: 11px;
}
.hint {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
}
button {
pointer-events: auto;
border: 1px solid rgba(23, 61, 60, 0.16);
border-radius: 999px;
padding: 10px 14px;
background: rgba(251, 248, 241, 0.86);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition: transform 160ms ease, background 160ms ease;
}
button:hover {
transform: translateY(-2px);
background: white;
}
@media (max-width: 760px) {
.brand {
top: 18px;
left: 18px;
}
.brand-mark {
width: 37px;
height: 37px;
}
.legend {
top: 70px;
left: 18px;
right: auto;
gap: 12px;
padding: 9px 12px;
}
.specs {
left: 18px;
bottom: 18px;
}
.spec {
min-width: 88px;
padding: 10px 11px;
}
.spec strong {
font-size: 16px;
}
.controls {
right: 18px;
bottom: 18px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Stylized shirt garment beside a measurement pattern card"
tabindex="0"
></canvas>
<div class="hud">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M5 3v18M19 3v18M3 8h18M3 16h18"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"/>
<path d="m5 8-3 3m3-3 3 3m13 5-3-3m3 3-3 3"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"
stroke-linejoin="round"/>
</svg>
</div>
<div>
<p class="eyebrow">Garment specification / 04</p>
<h1>Measurement Pattern</h1>
</div>
</div>
<div class="legend">
<div class="legend-item">
<span class="swatch coral"></span>
Matched refs A–D
</div>
<div class="legend-item">
<span class="swatch gold"></span>
Dimensions
</div>
</div>
<div class="specs">
<div class="spec">
<strong>52 cm</strong>
<span>Panel width</span>
</div>
<div class="spec">
<strong>68 cm</strong>
<span>Panel length</span>
</div>
</div>
<div class="controls">
<span class="hint">Drag to orbit · Scroll to zoom</span>
<button id="reset" type="button">Reset view</button>
</div>
</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.querySelector("#scene");
const resetButton = document.querySelector("#reset");
const COLORS = {
ink: 0x173d3c,
teal: 0x2b8f88,
coral: 0xe56750,
gold: 0xe3a83b,
paper: 0xfbf8f1,
background: 0xeee8df
};
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(COLORS.background);
const camera = new THREE.PerspectiveCamera(
34,
window.innerWidth / window.innerHeight,
0.1,
100
);
const view = {
theta: 0.025,
phi: 1.47,
radius: 10.9
};
const goal = {
theta: 0.025,
phi: 1.47,
radius: 10.9
};
const cameraTarget = new THREE.Vector3(0, 0, 0);
// ---------------------------------------------------------------------
// Lighting and studio
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfffbf1, 0x8e9189, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4df, 3.4);
keyLight.position.set(-5, 8, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight, keyLight.target);
const fillLight = new THREE.DirectionalLight(0xbfe5df, 1.35);
fillLight.position.set(6, 3, 5);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0xe9e2d8,
roughness: 0.94,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.14;
floor.receiveShadow = true;
scene.add(floor);
const backdrop = new THREE.Mesh(
new THREE.CircleGeometry(5.55, 96),
new THREE.MeshBasicMaterial({ color: 0xe5ddd3 })
);
backdrop.position.set(0, 0.25, -3.2);
scene.add(backdrop);
const accentRing = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.025, 16, 72),
new THREE.MeshStandardMaterial({
color: COLORS.gold,
roughness: 0.42,
metalness: 0.22
})
);
accentRing.position.set(-4.28, 2.26, -0.8);
scene.add(accentRing);
const accentOrb = new THREE.Mesh(
new THREE.SphereGeometry(0.095, 24, 24),
new THREE.MeshStandardMaterial({
color: COLORS.coral,
roughness: 0.5
})
);
accentOrb.position.set(4.4, 2.12, -0.55);
scene.add(accentOrb);
// ---------------------------------------------------------------------
// Texture helpers
// ---------------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function createFabricTexture() {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = textureCanvas.height = 256;
const ctx = textureCanvas.getContext("2d");
ctx.fillStyle = "#2b9089";
ctx.fillRect(0, 0, 256, 256);
ctx.strokeStyle = "rgba(255,255,255,0.055)";
ctx.lineWidth = 1;
for (let i = -256; i < 512; i += 8) {
ctx.beginPath();
ctx.moveTo(i, 0);
ctx.lineTo(i + 256, 256);
ctx.stroke();
}
ctx.strokeStyle = "rgba(11,63,61,0.055)";
for (let y = 0; y < 256; y += 7) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(256, y);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(0.42, 0.42);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeTextSprite(text, options = {}) {
const {
width = 512,
height = 128,
background = "rgba(251,248,241,0.96)",
foreground = "#173d3c",
border = "rgba(23,61,60,0.13)",
fontSize = 58,
radius = 34
} = options;
const textureCanvas = document.createElement("canvas");
textureCanvas.width = width;
textureCanvas.height = height;
const ctx = textureCanvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
ctx.shadowColor = "rgba(18,39,37,0.12)";
ctx.shadowBlur = 16;
ctx.shadowOffsetY = 5;
roundedRect(
ctx,
8,
8,
width - 16,
height - 16,
radius
);
ctx.fillStyle = background;
ctx.fill();
ctx.shadowColor = "transparent";
ctx.strokeStyle = border;
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = `800 ${fontSize}px Arial, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 2);
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.renderOrder = 10;
return sprite;
}
function makeReferenceBadge(letter) {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = textureCanvas.height = 128;
const ctx = textureCanvas.getContext("2d");
ctx.clearRect(0, 0, 128, 128);
ctx.shadowColor = "rgba(18,39,37,0.22)";
ctx.shadowBlur = 12;
ctx.shadowOffsetY = 4;
ctx.beginPath();
ctx.arc(64, 64, 45, 0, Math.PI * 2);
ctx.fillStyle = "#e56750";
ctx.fill();
ctx.shadowColor = "transparent";
ctx.strokeStyle = "#fffaf0";
ctx.lineWidth = 6;
ctx.stroke();
ctx.fillStyle = "#ffffff";
ctx.font = "800 48px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(letter, 64, 66);
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(0.19, 0.19, 1);
sprite.renderOrder = 12;
return sprite;
}
// ---------------------------------------------------------------------
// Garment panel
// ---------------------------------------------------------------------
const garment = new THREE.Group();
garment.name = "Garment";
scene.add(garment);
const shirtShape = new THREE.Shape();
shirtShape.moveTo(-0.86, -1.65);
shirtShape.lineTo(0.86, -1.65);
shirtShape.lineTo(0.98, 0.62);
shirtShape.lineTo(1.68, 0.95);
shirtShape.lineTo(2.0, 0.45);
shirtShape.lineTo(1.52, -0.02);
shirtShape.lineTo(1.30, 1.35);
shirtShape.lineTo(0.50, 1.72);
shirtShape.lineTo(0.30, 1.50);
shirtShape.lineTo(0.0, 1.40);
shirtShape.lineTo(-0.30, 1.50);
shirtShape.lineTo(-0.50, 1.72);
shirtShape.lineTo(-1.30, 1.35);
shirtShape.lineTo(-1.52, -0.02);
shirtShape.lineTo(-2.0, 0.45);
shirtShape.lineTo(-1.68, 0.95);
shirtShape.lineTo(-0.98, 0.62);
shirtShape.closePath();
const shirtGeometry = new THREE.ShapeGeometry(shirtShape, 48);
const shirtPositions = shirtGeometry.attributes.position;
for (let i = 0; i < shirtPositions.count; i++) {
const x = shirtPositions.getX(i);
const y = shirtPositions.getY(i);
const z =
Math.sin(x * 2.45 + 0.4) * 0.035 +
Math.cos(y * 2.1) * 0.022;
shirtPositions.setZ(i, z);
}
shirtGeometry.computeVertexNormals();
const shirtMesh = new THREE.Mesh(
shirtGeometry,
new THREE.MeshStandardMaterial({
map: createFabricTexture(),
color: 0xffffff,
roughness: 0.86,
metalness: 0,
side: THREE.DoubleSide
})
);
shirtMesh.castShadow = true;
shirtMesh.receiveShadow = true;
garment.add(shirtMesh);
const outlinePoints = shirtShape.getPoints(96).map(
(point) => new THREE.Vector3(point.x, point.y, 0.11)
);
const shirtOutline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(outlinePoints),
new THREE.LineBasicMaterial({
color: 0x164c49,
transparent: true,
opacity: 0.72
})
);
garment.add(shirtOutline);
const centerSeam = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 1.36, 0.115),
new THREE.Vector3(0, -1.58, 0.115)
]),
new THREE.LineDashedMaterial({
color: 0xb8e0d9,
dashSize: 0.055,
gapSize: 0.04,
transparent: true,
opacity: 0.65
})
);
centerSeam.computeLineDistances();
garment.add(centerSeam);
const references = {
A: new THREE.Vector3(-0.98, 0.62, 0.17),
B: new THREE.Vector3(0.98, 0.62, 0.17),
C: new THREE.Vector3(0.86, -1.65, 0.17),
D: new THREE.Vector3(-0.86, -1.65, 0.17)
};
// ---------------------------------------------------------------------
// Three.js dimension arrows
// ---------------------------------------------------------------------
const upAxis = new THREE.Vector3(0, 1, 0);
function cylinderBetween(start, end, radius, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 16),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
upAxis,
direction.normalize()
);
return mesh;
}
function addDoubleArrow(parent, start, end, options = {}) {
const {
color = COLORS.gold,
radius = 0.012,
headLength = 0.15,
headRadius = 0.058
} = options;
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
direction.normalize();
const material = new THREE.MeshBasicMaterial({ color });
const shaftStart = start.clone().addScaledVector(direction, headLength * 0.85);
const shaftEnd = end.clone().addScaledVector(direction, -headLength * 0.85);
const shaft = cylinderBetween(shaftStart, shaftEnd, radius, material);
parent.add(shaft);
const startHead = new THREE.Mesh(
new THREE.ConeGeometry(headRadius, headLength, 24),
material
);
startHead.position.copy(start).addScaledVector(direction, headLength / 2);
startHead.quaternion.setFromUnitVectors(
upAxis,
direction.clone().negate()
);
parent.add(startHead);
const endHead = new THREE.Mesh(
new THREE.ConeGeometry(headRadius, headLength, 24),
material
);
endHead.position.copy(end).addScaledVector(direction, -headLength / 2);
endHead.quaternion.setFromUnitVectors(upAxis, direction);
parent.add(endHead);
}
addDoubleArrow(
garment,
references.A.clone().setZ(0.19),
references.B.clone().setZ(0.19),
{ headLength: 0.13, headRadius: 0.052 }
);
const lengthStart = new THREE.Vector3(-1.30, 0.62, 0.19);
const lengthEnd = new THREE.Vector3(-1.30, -1.65, 0.19);
addDoubleArrow(garment, lengthStart, lengthEnd, {
headLength: 0.14,
headRadius: 0.055
});
const extensionMaterial = new THREE.LineBasicMaterial({
color: COLORS.gold,
transparent: true,
opacity: 0.86
});
garment.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.98, 0.62, 0.18),
lengthStart.clone()
]),
extensionMaterial
),
new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.86, -1.65, 0.18),
lengthEnd.clone()
]),
extensionMaterial
)
);
Object.entries(references).forEach(([letter, point]) => {
const badge = makeReferenceBadge(letter);
badge.position.copy(point).setZ(0.25);
garment.add(badge);
});
const widthLabel = makeTextSprite("52 CM", {
background: "rgba(227,168,59,0.97)",
foreground: "#173d3c",
border: "rgba(255,255,255,0.4)",
fontSize: 57
});
widthLabel.position.set(0, 0.95, 0.28);
widthLabel.scale.set(0.72, 0.18, 1);
garment.add(widthLabel);
const lengthLabel = makeTextSprite("68 CM", {
background: "rgba(227,168,59,0.97)",
foreground: "#173d3c",
border: "rgba(255,255,255,0.4)",
fontSize: 57
});
lengthLabel.position.set(-1.51, -0.48, 0.27);
lengthLabel.scale.set(0.69, 0.17, 1);
garment.add(lengthLabel);
// ---------------------------------------------------------------------
// Measurement card texture
// ---------------------------------------------------------------------
const CARD_WIDTH = 3.65;
const CARD_HEIGHT = 4.62;
function createCardTexture() {
const textureCanvas = document.createElement("canvas");
const width = 1000;
const height = Math.round(width * CARD_HEIGHT / CARD_WIDTH);
textureCanvas.width = width;
textureCanvas.height = height;
const ctx = textureCanvas.getContext("2d");
const xPx = (x) => ((x + CARD_WIDTH / 2) / CARD_WIDTH) * width;
const yPx = (y) => ((CARD_HEIGHT / 2 - y) / CARD_HEIGHT) * height;
const localRect = (x, y, w, h, color) => {
ctx.fillStyle = color;
ctx.fillRect(
xPx(x),
yPx(y + h),
xPx(x + w) - xPx(x),
yPx(y) - yPx(y + h)
);
};
const localText = (
text,
x,
y,
size,
color = "#173d3c",
align = "left",
weight = 700
) => {
ctx.fillStyle = color;
ctx.font = `${weight} ${size}px Arial, sans-serif`;
ctx.textAlign = align;
ctx.textBaseline = "alphabetic";
ctx.fillText(text, xPx(x), yPx(y));
};
const localPath = (points) => {
ctx.beginPath();
points.forEach(([x, y], index) => {
if (index === 0) {
ctx.moveTo(xPx(x), yPx(y));
} else {
ctx.lineTo(xPx(x), yPx(y));
}
});
ctx.closePath();
};
const drawArrow = (a, b, color = "#e3a83b", headSize = 15) => {
const ax = xPx(a[0]);
const ay = yPx(a[1]);
const bx = xPx(b[0]);
const by = yPx(b[1]);
const angle = Math.atan2(by - ay, bx - ax);
const ux = Math.cos(angle);
const uy = Math.sin(angle);
const px = -uy;
const py = ux;
ctx.strokeStyle = color;
ctx.lineWidth = 4;
ctx.lineCap = "round";
ctx.beginPath();
ctx.moveTo(ax, ay);
ctx.lineTo(bx, by);
ctx.stroke();
ctx.fillStyle = color;
ctx.beginPath();
ctx.moveTo(ax, ay);
ctx.lineTo(
ax + ux * headSize + px * headSize * 0.55,
ay + uy * headSize + py * headSize * 0.55
);
ctx.lineTo(
ax + ux * headSize - px * headSize * 0.55,
ay + uy * headSize - py * headSize * 0.55
);
ctx.closePath();
ctx.fill();
ctx.beginPath();
ctx.moveTo(bx, by);
ctx.lineTo(
bx - ux * headSize + px * headSize * 0.55,
by - uy * headSize + py * headSize * 0.55
);
ctx.lineTo(
bx - ux * headSize - px * headSize * 0.55,
by - uy * headSize - py * headSize * 0.55
);
ctx.closePath();
ctx.fill();
};
// Paper
ctx.fillStyle = "#fbf8f1";
ctx.fillRect(0, 0, width, height);
for (let i = 0; i < 1600; i++) {
const x = (i * 83.17) % width;
const y = (i * 47.91) % height;
ctx.fillStyle = i % 3 === 0
? "rgba(23,61,60,0.022)"
: "rgba(255,255,255,0.22)";
ctx.fillRect(x, y, 1.3, 1.3);
}
// Fine border
roundedRect(ctx, 26, 26, width - 52, height - 52, 24);
ctx.strokeStyle = "rgba(23,61,60,0.16)";
ctx.lineWidth = 2;
ctx.stroke();
// Header
localRect(-1.56, 1.83, 0.09, 0.51, "#e56750");
localText("GARMENT SPECIFICATION", -1.35, 2.14, 19, "#738079", "left", 800);
localText("MEASUREMENT CARD", -1.35, 1.78, 36, "#173d3c", "left", 800);
localText("T—04", 1.53, 2.08, 34, "#e56750", "right", 800);
localText("FRONT / 01", 1.53, 1.80, 17, "#738079", "right", 700);
ctx.strokeStyle = "rgba(23,61,60,0.16)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(xPx(-1.55), yPx(1.48));
ctx.lineTo(xPx(1.55), yPx(1.48));
ctx.stroke();
// Subtle drafting grid
ctx.fillStyle = "rgba(23,61,60,0.085)";
for (let x = -1.5; x <= 1.51; x += 0.25) {
for (let y = -1.85; y <= 1.31; y += 0.25) {
ctx.beginPath();
ctx.arc(xPx(x), yPx(y), 1.5, 0, Math.PI * 2);
ctx.fill();
}
}
localText("FRONT PANEL / SCALE 1:4", -1.52, 1.29, 16, "#738079", "left", 800);
// Pattern silhouette
const patternPoints = [
[-0.86, -1.65],
[0.86, -1.65],
[0.98, 0.62],
[1.34, 0.92],
[1.65, 0.60],
[1.38, 0.12],
[1.24, 1.18],
[0.48, 1.45],
[0.22, 1.20],
[0.00, 1.46],
[-0.22, 1.20],
[-0.48, 1.45],
[-1.24, 1.18],
[-1.38, 0.12],
[-1.65, 0.60],
[-1.34, 0.92],
[-0.98, 0.62]
];
localPath(patternPoints);
ctx.fillStyle = "#dcece8";
ctx.fill();
ctx.strokeStyle = "#235f5b";
ctx.lineWidth = 3;
ctx.stroke();
// Center seam
ctx.setLineDash([8, 7]);
ctx.strokeStyle = "rgba(23,61,60,0.32)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(xPx(0), yPx(1.30));
ctx.lineTo(xPx(0), yPx(-1.57));
ctx.stroke();
ctx.setLineDash([]);
// Width dimension
drawArrow([-0.98, 0.62], [0.98, 0.62]);
// Length dimension with witness lines
ctx.strokeStyle = "#e3a83b";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(xPx(-0.98), yPx(0.62));
ctx.lineTo(xPx(-1.38), yPx(0.62));
ctx.moveTo(xPx(-0.86), yPx(-1.65));
ctx.lineTo(xPx(-1.38), yPx(-1.65));
ctx.stroke();
drawArrow([-1.38, 0.62], [-1.38, -1.65]);
// Dimension labels
roundedRect(
ctx,
xPx(-0.38),
yPx(0.94),
xPx(0.38) - xPx(-0.38),
yPx(0.70) - yPx(0.94),
15
);
ctx.fillStyle = "#e3a83b";
ctx.fill();
localText("52 CM", 0, 0.79, 20, "#173d3c", "center", 800);
ctx.save();
ctx.translate(xPx(-1.58), yPx(-0.50));
ctx.rotate(-Math.PI / 2);
roundedRect(ctx, -52, -24, 104, 48, 14);
ctx.fillStyle = "#e3a83b";
ctx.fill();
ctx.fillStyle = "#173d3c";
ctx.font = "800 20px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("68 CM", 0, 1);
ctx.restore();
// Matching reference points on the diagram
const diagramRefs = [
[-0.98, 0.62, "A"],
[0.98, 0.62, "B"],
[0.86, -1.65, "C"],
[-0.86, -1.65, "D"]
];
diagramRefs.forEach(([x, y, letter]) => {
ctx.beginPath();
ctx.arc(xPx(x), yPx(y), 18, 0, Math.PI * 2);
ctx.fillStyle = "#e56750";
ctx.fill();
ctx.strokeStyle = "#fffaf0";
ctx.lineWidth = 5;
ctx.stroke();
ctx.fillStyle = "#ffffff";
ctx.font = "800 19px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(letter, xPx(x), yPx(y) + 1);
});
// Footer
ctx.strokeStyle = "rgba(23,61,60,0.16)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(xPx(-1.55), yPx(-1.92));
ctx.lineTo(xPx(1.55), yPx(-1.92));
ctx.stroke();
localText("FINISHED GARMENT / FRONT VIEW", -1.52, -2.10, 16, "#738079", "left", 800);
localText("REF A—D", 1.52, -2.10, 16, "#e56750", "right", 800);
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
// ---------------------------------------------------------------------
// Measurement card object
// ---------------------------------------------------------------------
const card = new THREE.Group();
card.name = "MeasurementCard";
scene.add(card);
const cardBody = new THREE.Mesh(
new THREE.BoxGeometry(3.82, 4.82, 0.14),
new THREE.MeshStandardMaterial({
color: 0xe8dfd3,
roughness: 0.9
})
);
cardBody.castShadow = true;
cardBody.receiveShadow = true;
card.add(cardBody);
const cardFace = new THREE.Mesh(
new THREE.PlaneGeometry(CARD_WIDTH, CARD_HEIGHT),
new THREE.MeshBasicMaterial({
map: createCardTexture(),
toneMapped: false
})
);
cardFace.position.z = 0.077;
card.add(cardFace);
// ---------------------------------------------------------------------
// Dashed matching-point guides
// ---------------------------------------------------------------------
const connectorLines = [];
Object.entries(references).forEach(([letter, source]) => {
const line = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineDashedMaterial({
color: COLORS.coral,
dashSize: 0.085,
gapSize: 0.065,
transparent: true,
opacity: 0.32,
depthWrite: false
})
);
line.renderOrder = 1;
line.userData.letter = letter;
scene.add(line);
connectorLines.push(line);
});
function updateConnectors() {
scene.updateMatrixWorld(true);
connectorLines.forEach((line) => {
const letter = line.userData.letter;
const source = garment.localToWorld(references[letter].clone());
const target = card.localToWorld(references[letter].clone());
line.geometry.setFromPoints([source, target]);
line.computeLineDistances();
});
}
// ---------------------------------------------------------------------
// Direct camera controls
// ---------------------------------------------------------------------
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
let userAdjusted = false;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const deltaX = event.clientX - lastX;
const deltaY = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
goal.theta = THREE.MathUtils.clamp(
goal.theta - deltaX * 0.0055,
-0.72,
0.72
);
goal.phi = THREE.MathUtils.clamp(
goal.phi - deltaY * 0.0048,
1.02,
1.86
);
userAdjusted = true;
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
canvas.style.cursor = "grab";
if (canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
pointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
goal.radius = THREE.MathUtils.clamp(
goal.radius * Math.exp(event.deltaY * 0.001),
8.3,
18
);
userAdjusted = true;
},
{ passive: false }
);
canvas.style.cursor = "grab";
function resetView() {
goal.theta = 0.025;
goal.phi = 1.47;
goal.radius = isPortrait() ? 13.1 : 10.9;
userAdjusted = false;
}
resetButton.addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetView();
}
});
// ---------------------------------------------------------------------
// Responsive layout
// ---------------------------------------------------------------------
function isPortrait() {
return window.innerWidth / window.innerHeight < 0.9;
}
function applyLayout() {
const portrait = isPortrait();
if (portrait) {
garment.position.set(-0.82, 1.25, 0.15);
garment.scale.setScalar(0.72);
garment.rotation.set(0.015, 0.08, -0.025);
card.position.set(0.90, -0.58, -0.02);
card.scale.setScalar(0.72);
card.rotation.set(0.015, -0.11, 0.035);
cameraTarget.set(0, -0.02, 0);
if (!userAdjusted) {
goal.radius = 13.1;
}
} else {
garment.position.set(-2.28, -0.08, 0.12);
garment.scale.setScalar(1);
garment.rotation.set(0.012, 0.09, -0.03);
card.position.set(2.30, 0.13, -0.08);
card.scale.setScalar(1);
card.rotation.set(0.01, -0.10, 0.018);
cameraTarget.set(0, 0.02, 0);
if (!userAdjusted) {
goal.radius = 10.9;
}
}
updateConnectors();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
applyLayout();
}
window.addEventListener("resize", resize);
// ---------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
view.theta += (goal.theta - view.theta) * 0.085;
view.phi += (goal.phi - view.phi) * 0.085;
view.radius += (goal.radius - view.radius) * 0.075;
const sinPhi = Math.sin(view.phi);
camera.position.set(
cameraTarget.x + view.radius * sinPhi * Math.sin(view.theta),
cameraTarget.y + view.radius * Math.cos(view.phi),
cameraTarget.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(cameraTarget);
accentRing.rotation.z = elapsed * 0.12;
accentOrb.position.y = 2.12 + Math.sin(elapsed * 0.85) * 0.07;
renderer.render(scene, camera);
}
resize();
resetView();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```