Prompt specification
Build or customize the Three.js 3D scene "Pattern adjustment demonstration" 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: Pattern adjustment demonstration
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pattern-adjustment-demonstration-x0550
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows tailoring orders and measurements. Move the edges of a flat garment panel according to two labeled measurements; preserve seam allowances as separate strips so body dimensions and construction margins stay distinct. Voxel style.
Working Three.js Starter (pattern-adjustment-demonstration-x0550):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Atelier — Tailoring Orders</title>
<style>
:root {
--paper: #f3efe7;
--panel: #faf8f3;
--canvas: #d9d4ca;
--ink: #20282a;
--muted: #747b79;
--line: #d9d5cc;
--body: #426b83;
--body-dark: #294c60;
--seam: #d77c43;
--accent: #c85e3b;
--green: #527461;
--shadow: 0 12px 30px rgba(37, 42, 40, 0.09);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: var(--paper);
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
font-size: 14px;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.app {
display: grid;
grid-template-columns: 340px minmax(0, 1fr);
grid-template-rows: 68px minmax(0, 1fr);
width: 100%;
height: 100dvh;
}
.topbar {
z-index: 10;
grid-column: 1 / -1;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background: rgba(250, 248, 243, 0.96);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 235px;
}
.brand-mark {
display: grid;
grid-template-columns: repeat(3, 7px);
grid-template-rows: repeat(3, 7px);
gap: 3px;
transform: rotate(-8deg);
}
.brand-mark i {
display: block;
background: var(--body);
border-radius: 1px;
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(8) {
background: var(--seam);
}
.brand-mark i:nth-child(5) {
background: var(--accent);
}
.brand-name {
font-weight: 800;
letter-spacing: 0.13em;
font-size: 13px;
}
.brand-sub {
margin-top: 2px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.top-path {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 12px;
}
.top-path strong {
color: var(--ink);
font-weight: 650;
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
}
.sync-state {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 11px;
}
.sync-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(82, 116, 97, 0.12);
}
.export-button,
.view-button {
border: 1px solid var(--line);
border-radius: 8px;
background: var(--panel);
cursor: pointer;
font-weight: 700;
transition: 160ms ease;
}
.export-button {
padding: 9px 13px;
font-size: 12px;
}
.export-button:hover,
.view-button:hover {
border-color: #aaa69d;
background: #fff;
transform: translateY(-1px);
}
.sidebar {
z-index: 5;
min-height: 0;
overflow-y: auto;
padding: 20px 18px 28px;
border-right: 1px solid var(--line);
background: var(--panel);
scrollbar-width: thin;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.section-heading h2 {
margin: 0;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.count-badge {
display: inline-grid;
place-items: center;
min-width: 23px;
height: 21px;
padding: 0 6px;
border-radius: 20px;
background: #e9e5dc;
color: #656a67;
font-size: 10px;
font-weight: 800;
}
.order-list {
display: grid;
gap: 8px;
margin-bottom: 24px;
}
.order-card {
position: relative;
width: 100%;
padding: 13px 13px 12px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 10px;
background: #fffdf9;
text-align: left;
cursor: pointer;
transition: 160ms ease;
}
.order-card:hover {
border-color: #b9b4aa;
transform: translateY(-1px);
box-shadow: 0 6px 16px rgba(35, 40, 39, 0.06);
}
.order-card.active {
border-color: var(--body);
box-shadow: 0 0 0 1px rgba(66, 107, 131, 0.14);
}
.order-card.active::before {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 4px;
background: var(--body);
content: "";
}
.order-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 7px;
}
.order-id {
font-size: 10px;
font-weight: 850;
letter-spacing: 0.09em;
color: var(--body-dark);
}
.status {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 4px 7px;
border-radius: 20px;
background: #edf1eb;
color: #56705f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.status::before {
width: 5px;
height: 5px;
border-radius: 50%;
background: currentColor;
content: "";
}
.status.draft {
background: #eeeae2;
color: #82715d;
}
.status.review {
background: #f4e9e3;
color: #a45f45;
}
.order-client {
margin-bottom: 3px;
font-size: 14px;
font-weight: 750;
}
.order-garment {
overflow: hidden;
color: var(--muted);
font-size: 11px;
text-overflow: ellipsis;
white-space: nowrap;
}
.order-meta {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 11px;
padding-top: 9px;
border-top: 1px solid #ece8df;
color: var(--muted);
font-size: 10px;
}
.order-dims {
display: flex;
gap: 8px;
color: #515b5c;
font-weight: 700;
}
.spec-card {
padding: 16px;
border: 1px solid var(--line);
border-radius: 12px;
background: #fffdf9;
box-shadow: var(--shadow);
}
.spec-title {
margin-bottom: 4px;
font-size: 13px;
font-weight: 800;
}
.spec-help {
margin: 0 0 18px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.control {
padding: 14px 0;
border-top: 1px solid #ece8df;
}
.control:first-of-type {
border-top: 0;
padding-top: 8px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.control-label label {
font-size: 12px;
font-weight: 750;
}
.control-label output {
color: var(--body-dark);
font-variant-numeric: tabular-nums;
font-size: 13px;
font-weight: 850;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0;
appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 4px;
border-radius: 10px;
background: linear-gradient(
to right,
var(--body) 0%,
var(--body) var(--fill, 50%),
#dedbd3 var(--fill, 50%),
#dedbd3 100%
);
}
input[type="range"]::-moz-range-track {
height: 4px;
border-radius: 10px;
background: #dedbd3;
}
input[type="range"]::-moz-range-progress {
height: 4px;
border-radius: 10px;
background: var(--body);
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
margin-top: -6px;
appearance: none;
border: 3px solid #fff;
border-radius: 3px;
background: var(--body);
box-shadow: 0 0 0 1px var(--body), 0 2px 5px rgba(0, 0, 0, 0.16);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #fff;
border-radius: 3px;
background: var(--body);
box-shadow: 0 0 0 1px var(--body);
}
.range-limits {
display: flex;
justify-content: space-between;
margin-top: 3px;
color: #9a9b95;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.margin-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 5px;
padding-top: 14px;
border-top: 1px solid #ece8df;
}
.margin-title {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
font-weight: 750;
}
.margin-swatch {
width: 10px;
height: 10px;
border-radius: 2px;
background: var(--seam);
}
.margin-value {
color: var(--seam);
font-size: 12px;
font-weight: 850;
}
.switch {
position: relative;
display: inline-flex;
align-items: center;
margin-left: auto;
cursor: pointer;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch-track {
width: 33px;
height: 19px;
border-radius: 20px;
background: #cbc9c2;
transition: 160ms ease;
}
.switch-track::after {
position: absolute;
top: 3px;
left: 3px;
width: 13px;
height: 13px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
transition: 160ms ease;
content: "";
}
.switch input:checked + .switch-track {
background: var(--seam);
}
.switch input:checked + .switch-track::after {
transform: translateX(14px);
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: var(--canvas);
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.labels {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.measure-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
border: 1px solid rgba(42, 54, 57, 0.18);
border-radius: 6px;
background: rgba(250, 248, 243, 0.94);
box-shadow: 0 5px 14px rgba(37, 42, 40, 0.1);
color: #2c3b40;
font-size: 10px;
font-weight: 800;
white-space: nowrap;
transform: translate(-50%, -50%);
transition: opacity 120ms ease;
}
.measure-label .label-icon {
display: inline-grid;
place-items: center;
width: 19px;
height: 19px;
border-radius: 4px;
background: var(--body);
color: white;
font-size: 9px;
}
.measure-label.seam {
border-color: rgba(215, 124, 67, 0.32);
color: #9c512b;
}
.measure-label.seam .label-icon {
background: var(--seam);
}
.viewport-head {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.eyebrow {
display: block;
margin-bottom: 6px;
color: #68706e;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.viewport-head h1 {
max-width: 560px;
margin: 0;
font-size: clamp(17px, 2vw, 24px);
font-weight: 760;
letter-spacing: -0.025em;
}
.viewport-sub {
margin-top: 6px;
color: #727875;
font-size: 11px;
}
.live-badge {
display: flex;
align-items: center;
gap: 7px;
padding: 8px 10px;
border: 1px solid rgba(82, 116, 97, 0.22);
border-radius: 20px;
background: rgba(249, 248, 242, 0.72);
color: #4f6f5c;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(6px);
}
.live-badge::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: #5e876c;
box-shadow: 0 0 0 4px rgba(94, 135, 108, 0.12);
content: "";
}
.view-tools {
position: absolute;
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
}
.view-button {
padding: 9px 11px;
background: rgba(250, 248, 243, 0.85);
font-size: 10px;
backdrop-filter: blur(6px);
}
.legend {
position: absolute;
left: 22px;
bottom: 22px;
width: 190px;
padding: 13px;
border: 1px solid rgba(96, 95, 88, 0.15);
border-radius: 10px;
background: rgba(250, 248, 243, 0.84);
box-shadow: 0 8px 24px rgba(37, 42, 40, 0.07);
backdrop-filter: blur(8px);
pointer-events: none;
}
.legend-title {
margin-bottom: 10px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 8px;
color: #59615f;
font-size: 10px;
}
.legend-block {
width: 14px;
height: 14px;
border-radius: 3px;
background: var(--body);
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}
.legend-block.seam {
background: var(--seam);
}
.legend-note {
margin-top: 11px;
padding-top: 9px;
border-top: 1px solid rgba(96, 95, 88, 0.13);
color: #7c7f79;
font-size: 9px;
line-height: 1.45;
}
.camera-hint {
position: absolute;
right: 24px;
top: 50%;
color: rgba(60, 67, 65, 0.64);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
text-align: right;
text-transform: uppercase;
pointer-events: none;
transform: rotate(90deg) translateX(50%);
transform-origin: right center;
}
.loading {
position: absolute;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--canvas);
color: #58615f;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
body {
overflow: auto;
}
.app {
grid-template-columns: 1fr;
grid-template-rows: 62px minmax(520px, 65dvh) auto;
height: auto;
min-height: 100dvh;
}
.topbar {
position: sticky;
top: 0;
}
.top-path,
.sync-state {
display: none;
}
.viewport {
grid-row: 2;
}
.sidebar {
grid-row: 3;
overflow: visible;
border-top: 1px solid var(--line);
border-right: 0;
}
.order-list {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.camera-hint {
display: none;
}
}
@media (max-width: 580px) {
.brand {
min-width: 0;
}
.brand-sub {
display: none;
}
.export-button {
padding: 8px 10px;
}
.order-list {
grid-template-columns: 1fr;
}
.viewport-head {
top: 17px;
left: 17px;
right: 17px;
}
.live-badge {
display: none;
}
.legend {
left: 14px;
bottom: 14px;
width: 165px;
}
.view-tools {
right: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
<div class="brand-name">VOXEL ATELIER</div>
<div class="brand-sub">Pattern cutting workspace</div>
</div>
</div>
<div class="top-path">
<span>Orders</span>
<span>/</span>
<strong>Measurement draft</strong>
</div>
<div class="top-actions">
<div class="sync-state">
<span class="sync-dot"></span>
Local changes saved
</div>
<button id="exportButton" class="export-button" type="button">
Export spec
</button>
</div>
</header>
<aside class="sidebar">
<div class="section-heading">
<h2>Tailoring orders</h2>
<span id="orderCount" class="count-badge">4</span>
</div>
<div id="orderList" class="order-list"></div>
<section class="spec-card" aria-labelledby="specHeading">
<div id="specHeading" class="spec-title">Body measurements</div>
<p class="spec-help">
Drive the blue body edge. The orange construction margin remains a
separate strip and is excluded from both measurements.
</p>
<div class="control">
<div class="control-label">
<label for="widthSlider">Body width</label>
<output id="widthOutput" for="widthSlider">48 cm</output>
</div>
<input
id="widthSlider"
type="range"
min="38"
max="66"
step="1"
value="48"
/>
<div class="range-limits">
<span>38 cm</span>
<span>66 cm</span>
</div>
</div>
<div class="control">
<div class="control-label">
<label for="lengthSlider">Panel length</label>
<output id="lengthOutput" for="lengthSlider">72 cm</output>
</div>
<input
id="lengthSlider"
type="range"
min="50"
max="88"
step="1"
value="72"
/>
<div class="range-limits">
<span>50 cm</span>
<span>88 cm</span>
</div>
</div>
<div class="margin-row">
<div>
<div class="margin-title">
<span class="margin-swatch"></span>
Seam allowance
</div>
<div class="margin-value">1.5 cm fixed margin</div>
</div>
<label class="switch" title="Show or hide seam allowance">
<input id="seamToggle" type="checkbox" checked />
<span class="switch-track"></span>
</label>
</div>
</section>
</aside>
<main id="viewport" class="viewport">
<canvas id="scene" aria-label="Interactive three-dimensional garment panel"></canvas>
<div id="labels" class="labels" aria-hidden="true">
<div id="widthLabel" class="measure-label">
<span class="label-icon">W</span>
<span id="widthSceneLabel">48 cm body width</span>
</div>
<div id="lengthLabel" class="measure-label">
<span class="label-icon">L</span>
<span id="lengthSceneLabel">72 cm panel length</span>
</div>
<div id="seamLabel" class="measure-label seam">
<span class="label-icon">SA</span>
<span>1.5 cm seam allowance</span>
</div>
</div>
<div class="viewport-head">
<div>
<span class="eyebrow">Active cutting order</span>
<h1 id="viewportTitle">TA-2407 · Structured wool blazer</h1>
<div id="viewportSubtitle" class="viewport-sub">
Amelia Hart · Front bodice panel · Due today
</div>
</div>
<div class="live-badge">Live measurement preview</div>
</div>
<div class="camera-hint" aria-hidden="true">
Drag to orbit · Right drag to pan · Scroll to zoom
</div>
<div class="legend">
<div class="legend-title">Layer anatomy</div>
<div class="legend-row">
<span class="legend-block"></span>
<span>Body panel edge</span>
</div>
<div class="legend-row">
<span class="legend-block seam"></span>
<span>Separate seam strip</span>
</div>
<div class="legend-note">
Dimensions measure the blue body only. Orange voxels are the fixed
construction margin.
</div>
</div>
<div class="view-tools">
<button id="resetView" class="view-button" type="button">
Reset view
</button>
</div>
<div id="loading" class="loading">Preparing cutting workspace…</div>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const orders = [
{
id: "TA-2407",
client: "Amelia Hart",
garment: "Structured wool blazer",
width: 48,
length: 72,
due: "Today",
status: "Cutting"
},
{
id: "TA-2408",
client: "Noah Williams",
garment: "Soft linen vest",
width: 42,
length: 61,
due: "18 Jul",
status: "Draft"
},
{
id: "TA-2409",
client: "Mina Patel",
garment: "Cotton trench panel",
width: 56,
length: 79,
due: "21 Jul",
status: "Review"
},
{
id: "TA-2410",
client: "Elias Novak",
garment: "Linen summer jacket",
width: 51,
length: 68,
due: "24 Jul",
status: "Draft"
}
];
const state = {
activeOrder: 0,
width: orders[0].width,
length: orders[0].length,
seamVisible: true,
pendingBuild: false
};
const viewport = document.getElementById("viewport");
const canvas = document.getElementById("scene");
const orderList = document.getElementById("orderList");
const widthSlider = document.getElementById("widthSlider");
const lengthSlider = document.getElementById("lengthSlider");
const widthOutput = document.getElementById("widthOutput");
const lengthOutput = document.getElementById("lengthOutput");
const widthSceneLabel = document.getElementById("widthSceneLabel");
const lengthSceneLabel = document.getElementById("lengthSceneLabel");
const widthLabel = document.getElementById("widthLabel");
const lengthLabel = document.getElementById("lengthLabel");
const seamLabel = document.getElementById("seamLabel");
const loading = document.getElementById("loading");
const SCALE = 0.07;
const SEAM_WIDTH_CM = 1.5;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9d4ca);
scene.fog = new THREE.Fog(0xd9d4ca, 14, 28);
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
loading.textContent = "WebGL is required for this workspace";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.8));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const camera = new THREE.OrthographicCamera(-5, 5, 3.5, -3.5, 0.1, 100);
const target = new THREE.Vector3(0, 0, 2.35);
const cameraState = {
yaw: 0.58,
polar: 0.88,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xfff8e9, 0x776d60, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d9, 3.25);
keyLight.position.set(5, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc3dbe7, 1.1);
fillLight.position.set(-6, 5, 1);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0xd9d4ca,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.012;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(28, 56, 0xaaa69d, 0xc0bbb2);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.35;
scene.add(grid);
let panelGroup = null;
let dimensionGroup = null;
let bodyMesh = null;
let seamMesh = null;
const anchors = {
width: new THREE.Vector3(),
length: new THREE.Vector3(),
seam: new THREE.Vector3()
};
// A stylized front bodice outline in normalized panel coordinates.
// x spans -0.5..0.5 and y spans 0..1.
const garmentPolygon = [
[-0.50, 0.00],
[ 0.50, 0.00],
[ 0.50, 0.38],
[ 0.48, 0.55],
[ 0.39, 0.63],
[ 0.36, 0.75],
[ 0.38, 0.88],
[ 0.34, 1.00],
[ 0.13, 1.00],
[ 0.10, 0.93],
[ 0.065, 0.885],
[ 0.00, 0.855],
[-0.065, 0.885],
[-0.10, 0.93],
[-0.13, 1.00],
[-0.34, 1.00],
[-0.38, 0.88],
[-0.36, 0.75],
[-0.39, 0.63],
[-0.48, 0.55],
[-0.50, 0.38]
];
function pointInPolygon(x, y, polygon) {
let inside = false;
for (
let i = 0, j = polygon.length - 1;
i < polygon.length;
j = i++
) {
const xi = polygon[i][0];
const yi = polygon[i][1];
const xj = polygon[j][0];
const yj = polygon[j][1];
const crosses =
yi > y !== yj > y &&
x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
if (crosses) inside = !inside;
}
return inside;
}
function hashCell(ix, iz) {
const value = Math.sin(ix * 127.1 + iz * 311.7) * 43758.5453;
return value - Math.floor(value);
}
function disposeGroup(group) {
if (!group) return;
group.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach((material) => material.dispose());
} else {
object.material.dispose();
}
}
});
scene.remove(group);
}
function buildPanel() {
disposeGroup(panelGroup);
panelGroup = new THREE.Group();
scene.add(panelGroup);
const width = Math.round(state.width);
const length = Math.round(state.length);
const bodyCells = [];
const bodySet = new Set();
const seamSet = new Set();
const key = (ix, iz) => `${ix},${iz}`;
// The body occupies a one-centimetre logical grid.
for (let iz = 0; iz < length; iz++) {
for (let ix = -Math.floor(width / 2); ix < Math.floor(width / 2); ix++) {
const normalizedX = (ix + 0.5) / width;
const normalizedY = (iz + 0.5) / length;
if (pointInPolygon(normalizedX, normalizedY, garmentPolygon)) {
bodyCells.push({ ix, iz });
bodySet.add(key(ix, iz));
}
}
}
// Seam cells are outside the body set, never mixed into it.
const neighborDirections = [
[1, 0],
[-1, 0],
[0, 1],
[0, -1]
];
for (const cell of bodyCells) {
for (const [dx, dz] of neighborDirections) {
const seamKey = key(cell.ix + dx, cell.iz + dz);
if (!bodySet.has(seamKey)) seamSet.add(seamKey);
}
}
const bodyGeometry = new THREE.BoxGeometry(1, 1, 1);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88,
metalness: 0,
flatShading: true
});
bodyMesh = new THREE.InstancedMesh(
bodyGeometry,
bodyMaterial,
bodyCells.length
);
const dummy = new THREE.Object3D();
const bodyColor = new THREE.Color(0x426b83);
bodyCells.forEach((cell, index) => {
dummy.position.set(
(cell.ix + 0.5) * SCALE,
0.105,
(cell.iz + 0.5) * SCALE
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(SCALE * 0.91, 0.16, SCALE * 0.91);
dummy.updateMatrix();
bodyMesh.setMatrixAt(index, dummy.matrix);
const variation = hashCell(cell.ix, cell.iz);
const color = bodyColor.clone();
color.offsetHSL(
(variation - 0.5) * 0.012,
(variation - 0.5) * 0.035,
(variation - 0.5) * 0.055
);
bodyMesh.setColorAt(index, color);
});
bodyMesh.instanceMatrix.needsUpdate = true;
if (bodyMesh.instanceColor) bodyMesh.instanceColor.needsUpdate = true;
bodyMesh.castShadow = true;
bodyMesh.receiveShadow = true;
bodyMesh.computeBoundingSphere();
panelGroup.add(bodyMesh);
const seamGeometry = new THREE.BoxGeometry(1, 1, 1);
const seamMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95,
metalness: 0,
flatShading: true
});
const seamCells = Array.from(seamSet).map((seamKey) => {
const [ix, iz] = seamKey.split(",").map(Number);
return { ix, iz };
});
seamMesh = new THREE.InstancedMesh(
seamGeometry,
seamMaterial,
seamCells.length
);
const seamColor = new THREE.Color(0xd77c43);
seamCells.forEach((cell, index) => {
let outwardX = 0;
let outwardZ = 0;
// Find the body-facing direction so each strip extends outward.
for (const [dx, dz] of neighborDirections) {
if (bodySet.has(key(cell.ix + dx, cell.iz + dz))) {
outwardX -= dx;
outwardZ -= dz;
}
}
const outwardLength = Math.hypot(outwardX, outwardZ) || 1;
outwardX /= outwardLength;
outwardZ /= outwardLength;
const outwardOffset = SCALE * 0.25;
dummy.position.set(
(cell.ix + 0.5) * SCALE + outwardX * outwardOffset,
0.046,
(cell.iz + 0.5) * SCALE + outwardZ * outwardOffset
);
dummy.rotation.set(
0,
Math.atan2(outwardX, outwardZ),
0
);
// Tangential width is narrow; radial width is the true 1.5 cm margin.
dummy.scale.set(
SCALE * 0.86,
0.075,
SCALE * SEAM_WIDTH_CM
);
dummy.updateMatrix();
seamMesh.setMatrixAt(index, dummy.matrix);
const variation = hashCell(cell.ix + cell.iz * 7, cell.iz);
const color = seamColor.clone();
color.offsetHSL(0, 0, (variation - 0.5) * 0.055);
seamMesh.setColorAt(index, color);
});
seamMesh.instanceMatrix.needsUpdate = true;
if (seamMesh.instanceColor) seamMesh.instanceColor.needsUpdate = true;
seamMesh.castShadow = false;
seamMesh.receiveShadow = true;
seamMesh.visible = state.seamVisible;
seamMesh.computeBoundingSphere();
panelGroup.add(seamMesh);
updateDimensions(width, length);
}
function updateDimensions(width, length) {
disposeGroup(dimensionGroup);
dimensionGroup = new THREE.Group();
scene.add(dimensionGroup);
const xLeft = (-width / 2) * SCALE;
const xRight = (width / 2) * SCALE;
const zTop = length * SCALE;
const widthDimensionZ = -0.49;
const lengthDimensionX = xLeft - 0.5;
const y = 0.27;
const solidPositions = [
xLeft, y, widthDimensionZ,
xRight, y, widthDimensionZ,
xLeft, y, widthDimensionZ - 0.12,
xLeft, y, widthDimensionZ + 0.12,
xRight, y, widthDimensionZ - 0.12,
xRight, y, widthDimensionZ + 0.12,
lengthDimensionX, y, 0,
lengthDimensionX, y, zTop,
lengthDimensionX - 0.12, y, 0,
lengthDimensionX + 0.12, y, 0,
lengthDimensionX - 0.12, y, zTop,
lengthDimensionX + 0.12, y, zTop
];
const solidGeometry = new THREE.BufferGeometry();
solidGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(solidPositions, 3)
);
const solidLine = new THREE.LineSegments(
solidGeometry,
new THREE.LineBasicMaterial({
color: 0x33464d,
depthTest: false,
transparent: true,
opacity: 0.88
})
);
solidLine.renderOrder = 10;
dimensionGroup.add(solidLine);
const dashedPositions = [
xLeft, 0.15, 0,
xLeft, y, widthDimensionZ,
xRight, 0.15, 0,
xRight, y, widthDimensionZ,
xLeft, 0.15, zTop,
lengthDimensionX, y, zTop
];
const dashedGeometry = new THREE.BufferGeometry();
dashedGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(dashedPositions, 3)
);
const dashedLine = new THREE.LineSegments(
dashedGeometry,
new THREE.LineDashedMaterial({
color: 0x687574,
dashSize: 0.08,
gapSize: 0.065,
depthTest: false,
transparent: true,
opacity: 0.58
})
);
dashedLine.computeLineDistances();
dashedLine.renderOrder = 9;
dimensionGroup.add(dashedLine);
anchors.width.set(0, 0.43, widthDimensionZ);
anchors.length.set(lengthDimensionX, 0.43, zTop * 0.52);
anchors.seam.set(xRight + 0.48, 0.25, 0.78);
widthSceneLabel.textContent = `${width} cm body width`;
lengthSceneLabel.textContent = `${length} cm panel length`;
}
function updateCamera() {
const radius = 15;
const horizontal = Math.cos(cameraState.polar) * radius;
camera.position.set(
target.x + Math.sin(cameraState.yaw) * horizontal,
target.y + Math.sin(cameraState.polar) * radius,
target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.zoom = cameraState.zoom;
camera.lookAt(target);
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.yaw = 0.58;
cameraState.polar = 0.88;
cameraState.zoom = 1;
target.set(0, 0, state.length * SCALE * 0.46);
updateCamera();
}
function updateRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percentage = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
function renderOrders() {
orderList.innerHTML = "";
orders.forEach((order, index) => {
const card = document.createElement("button");
card.type = "button";
card.className = `order-card${index === state.activeOrder ? " active" : ""}`;
card.setAttribute(
"aria-pressed",
index === state.activeOrder ? "true" : "false"
);
const statusClass = order.status.toLowerCase();
card.innerHTML = `
<div class="order-top">
<span class="order-id">${order.id}</span>
<span class="status ${statusClass}">${order.status}</span>
</div>
<div class="order-client">${order.client}</div>
<div class="order-garment">${order.garment}</div>
<div class="order-meta">
<span class="order-dims">
<span>W ${order.width}</span>
<span>L ${order.length}</span>
<span>cm</span>
</span>
<span>Due ${order.due}</span>
</div>
`;
card.addEventListener("click", () => selectOrder(index));
orderList.appendChild(card);
});
}
function selectOrder(index) {
state.activeOrder = index;
const order = orders[index];
state.width = order.width;
state.length = order.length;
widthSlider.value = String(order.width);
lengthSlider.value = String(order.length);
updateRangeFill(widthSlider);
updateRangeFill(lengthSlider);
widthOutput.textContent = `${order.width} cm`;
lengthOutput.textContent = `${order.length} cm`;
document.getElementById("viewportTitle").textContent =
`${order.id} · ${order.garment}`;
document.getElementById("viewportSubtitle").textContent =
`${order.client} · Front bodice panel · Due ${order.due.toLowerCase()}`;
renderOrders();
queueBuild();
}
function queueBuild() {
if (state.pendingBuild) return;
state.pendingBuild = true;
requestAnimationFrame(() => {
state.pendingBuild = false;
widthOutput.textContent = `${Math.round(state.width)} cm`;
lengthOutput.textContent = `${Math.round(state.length)} cm`;
buildPanel();
const desiredTargetZ = state.length * SCALE * 0.46;
const shift = desiredTargetZ - target.z;
target.z = desiredTargetZ;
camera.position.z += shift;
updateCamera();
});
}
widthSlider.addEventListener("input", () => {
state.width = Number(widthSlider.value);
widthOutput.textContent = `${state.width} cm`;
updateRangeFill(widthSlider);
queueBuild();
});
lengthSlider.addEventListener("input", () => {
state.length = Number(lengthSlider.value);
lengthOutput.textContent = `${state.length} cm`;
updateRangeFill(lengthSlider);
queueBuild();
});
document.getElementById("seamToggle").addEventListener("change", (event) => {
state.seamVisible = event.target.checked;
if (seamMesh) seamMesh.visible = state.seamVisible;
});
document.getElementById("resetView").addEventListener("click", resetCamera);
document.getElementById("exportButton").addEventListener("click", () => {
const order = orders[state.activeOrder];
const specification = {
order: order.id,
client: order.client,
garment: order.garment,
status: order.status,
due: order.due,
measurements: {
bodyWidthCm: Math.round(state.width),
panelLengthCm: Math.round(state.length)
},
construction: {
seamAllowanceCm: SEAM_WIDTH_CM,
seamAllowanceIncludedInBodyMeasurements: false
}
};
const blob = new Blob([JSON.stringify(specification, null, 2)], {
type: "application/json"
});
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `${order.id.toLowerCase()}-cutting-spec.json`;
document.body.appendChild(link);
link.click();
link.remove();
URL.revokeObjectURL(url);
});
// Direct camera controls: no OrbitControls or addons are used.
let drag = null;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
drag = {
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY,
mode: event.button === 2 ? "pan" : "orbit"
};
});
canvas.addEventListener("pointermove", (event) => {
if (!drag || event.pointerId !== drag.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.mode === "orbit") {
cameraState.yaw -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + dy * 0.005,
0.28,
1.38
);
} else {
const worldPerPixel =
(camera.top - camera.bottom) / camera.zoom / viewport.clientHeight;
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0)
.setY(0)
.normalize();
const forward = new THREE.Vector3()
.subVectors(target, camera.position)
.setY(0)
.normalize();
target.addScaledVector(right, -dx * worldPerPixel);
target.addScaledVector(forward, -dy * worldPerPixel);
}
updateCamera();
});
function endDrag(event) {
if (drag && event.pointerId === drag.pointerId) drag = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("lostpointercapture", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.35
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
const aspect = width / Math.max(height, 1);
const viewSize = width < 700 ? 8.2 : 6.8;
renderer.setSize(width, height, false);
camera.left = (-viewSize * aspect) / 2;
camera.right = (viewSize * aspect) / 2;
camera.top = viewSize / 2;
camera.bottom = -viewSize / 2;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
function projectLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
if (
projected.z < -1 ||
projected.z > 1 ||
projected.x < -1.25 ||
projected.x > 1.25 ||
projected.y < -1.25 ||
projected.y > 1.25
) {
element.style.opacity = "0";
return;
}
element.style.left =
`${(projected.x * 0.5 + 0.5) * viewport.clientWidth}px`;
element.style.top =
`${(-projected.y * 0.5 + 0.5) * viewport.clientHeight}px`;
element.style.opacity = "1";
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
projectLabel(widthLabel, anchors.width);
projectLabel(lengthLabel, anchors.length);
if (state.seamVisible) {
projectLabel(seamLabel, anchors.seam);
} else {
seamLabel.style.opacity = "0";
}
}
document.getElementById("orderCount").textContent = String(orders.length);
renderOrders();
updateRangeFill(widthSlider);
updateRangeFill(lengthSlider);
selectOrder(0);
resize();
updateCamera();
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```