Prompt specification
Build or customize the Three.js 3D scene "Reusable attachment workshop" 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: Reusable attachment workshop
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/reusable-attachment-workshop-x0596
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows hook-and-loop fasteners. Create a modular costume board with removable patches and straps; users position attachments for repeated scene changes while a contact overlay shows which surfaces actually engage. Low-poly.
Working Three.js Starter (reusable-attachment-workshop-x0596):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tactile — Modular Costume Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #0c1112;
--panel: #12191a;
--panel-2: #182122;
--panel-3: #202a2b;
--line: #2a3737;
--line-strong: #3a4948;
--text: #edf0e9;
--muted: #8d9a95;
--muted-2: #5e6b67;
--orange: #f47642;
--orange-2: #ffad72;
--teal: #55b8ae;
--green: #b9ed62;
--amber: #e9b75d;
--red: #e16d62;
--radius: 12px;
--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
--sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: var(--sans);
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible {
outline: 2px solid var(--orange);
outline-offset: 2px;
}
#app {
width: 100%;
height: 100%;
display: grid;
grid-template-rows: 68px minmax(0, 1fr);
}
header {
display: flex;
align-items: center;
gap: 22px;
padding: 0 18px;
border-bottom: 1px solid var(--line);
background: #111718;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 11px;
flex: 0 0 auto;
}
.brand-mark {
width: 34px;
height: 34px;
border: 1px solid #86472f;
border-radius: 8px;
background:
radial-gradient(circle at 35% 35%, var(--orange-2) 0 2px, transparent 2.5px),
radial-gradient(circle at 68% 35%, var(--orange-2) 0 2px, transparent 2.5px),
radial-gradient(circle at 35% 68%, var(--orange-2) 0 2px, transparent 2.5px),
radial-gradient(circle at 68% 68%, var(--orange-2) 0 2px, transparent 2.5px),
#38241d;
box-shadow: inset 0 0 14px #0008;
}
.brand-name {
font-size: 13px;
font-weight: 800;
letter-spacing: .16em;
}
.brand-sub {
margin-top: 3px;
color: var(--muted);
font: 9px var(--mono);
letter-spacing: .12em;
text-transform: uppercase;
}
.header-divider {
height: 30px;
width: 1px;
background: var(--line);
}
.project {
display: flex;
align-items: center;
gap: 10px;
min-width: 210px;
}
.project label {
color: var(--muted-2);
font: 9px var(--mono);
letter-spacing: .12em;
}
#projectName {
width: 165px;
border: 0;
border-bottom: 1px solid transparent;
background: transparent;
color: var(--text);
font-size: 13px;
font-weight: 650;
padding: 6px 0;
}
#projectName:hover,
#projectName:focus { border-bottom-color: var(--line-strong); }
.header-spacer { flex: 1; }
.header-status {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font: 10px var(--mono);
letter-spacing: .08em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 10px #b9ed6255;
}
.icon-btn {
width: 34px;
height: 34px;
display: inline-grid;
place-items: center;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--panel-2);
cursor: pointer;
transition: .16s ease;
}
.icon-btn:hover:not(:disabled) {
border-color: var(--line-strong);
background: var(--panel-3);
transform: translateY(-1px);
}
.icon-btn:disabled {
opacity: .3;
cursor: default;
}
.icon-btn svg {
width: 16px;
height: 16px;
fill: none;
stroke: currentColor;
stroke-width: 1.7;
stroke-linecap: round;
stroke-linejoin: round;
}
.workspace {
min-height: 0;
display: grid;
grid-template-columns: 238px minmax(0, 1fr) 294px;
}
aside {
min-height: 0;
background: var(--panel);
overflow: auto;
scrollbar-width: thin;
scrollbar-color: var(--line-strong) transparent;
}
.left-panel {
border-right: 1px solid var(--line);
}
.right-panel {
border-left: 1px solid var(--line);
}
.panel-section {
padding: 18px 16px;
border-bottom: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
}
.eyebrow {
color: var(--muted);
font: 9px var(--mono);
font-weight: 700;
letter-spacing: .14em;
text-transform: uppercase;
}
.count-badge {
min-width: 21px;
height: 18px;
padding: 0 6px;
display: grid;
place-items: center;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--muted);
font: 9px var(--mono);
}
.part-list {
display: grid;
gap: 8px;
}
.part-card {
position: relative;
display: grid;
grid-template-columns: 48px 1fr 25px;
align-items: center;
gap: 10px;
min-height: 67px;
padding: 8px 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: #151d1e;
cursor: grab;
user-select: none;
transition: border-color .16s ease, background .16s ease, transform .16s ease;
}
.part-card:hover {
border-color: #4a5b59;
background: #192223;
transform: translateY(-1px);
}
.part-card:active { cursor: grabbing; }
.part-icon {
position: relative;
height: 46px;
border-radius: 7px;
overflow: hidden;
background: #0d1314;
border: 1px solid #273131;
}
.part-icon::before,
.part-icon::after {
content: "";
position: absolute;
}
.part-icon.hook::before {
inset: 11px 8px;
border-radius: 3px;
background: #a84f31;
border: 1px solid var(--orange-2);
}
.part-icon.hook::after {
width: 4px;
height: 4px;
left: 14px;
top: 15px;
border-radius: 50%;
background: #ffd1aa;
box-shadow: 8px 0 #ffd1aa, 16px 0 #ffd1aa, 0 8px #ffd1aa, 8px 8px #ffd1aa, 16px 8px #ffd1aa;
}
.part-icon.loop::before {
inset: 11px 8px;
border-radius: 50% 50% 4px 4px;
background: #2f7773;
border: 1px solid #78d3c8;
}
.part-icon.loop::after {
inset: 16px 13px;
background-image: radial-gradient(circle, #a1e0d9 0 1px, transparent 1.5px);
background-size: 5px 5px;
}
.part-icon.strap::before {
width: 37px;
height: 10px;
left: 6px;
top: 19px;
border-radius: 2px;
background: #b5a67a;
transform: rotate(-12deg);
border: 1px solid #e0d4aa;
}
.part-icon.strap::after {
width: 8px;
height: 15px;
left: 7px;
top: 16px;
border: 2px solid #7f897f;
border-radius: 50%;
transform: rotate(-12deg);
}
.part-name {
font-size: 12px;
font-weight: 700;
margin-bottom: 5px;
}
.part-meta {
color: var(--muted);
font: 9px var(--mono);
line-height: 1.45;
text-transform: uppercase;
letter-spacing: .04em;
}
.add-symbol {
color: var(--muted);
font-size: 20px;
font-weight: 300;
text-align: center;
}
.hint {
display: flex;
gap: 9px;
margin-top: 13px;
padding: 10px;
border: 1px dashed #354241;
border-radius: 8px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.hint b { color: var(--text); font-weight: 600; }
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
min-height: 30px;
color: var(--muted);
font-size: 11px;
}
.switch {
position: relative;
width: 34px;
height: 19px;
display: inline-block;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
inset: 0;
border-radius: 20px;
background: #2b3635;
border: 1px solid #394746;
cursor: pointer;
transition: .2s;
}
.slider::before {
content: "";
position: absolute;
width: 13px;
height: 13px;
left: 2px;
top: 2px;
border-radius: 50%;
background: #82908c;
transition: .2s;
}
.switch input:checked + .slider {
background: #563321;
border-color: #865034;
}
.switch input:checked + .slider::before {
transform: translateX(15px);
background: var(--orange);
}
.material-key {
display: grid;
gap: 9px;
}
.key-row {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 10px;
}
.key-swatch {
width: 24px;
height: 15px;
border-radius: 3px;
border: 1px solid #44504f;
}
.key-swatch.hook { background: #b85834; }
.key-swatch.loop { background: #347f79; }
.key-swatch.strap { background: #b6a77b; }
.key-swatch.contact { background: #b9ed62; box-shadow: 0 0 10px #b9ed6233; }
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #101617;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.viewport-top {
position: absolute;
z-index: 2;
top: 16px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.rig-label {
padding: 9px 11px;
border-left: 2px solid var(--orange);
background: #111819cc;
backdrop-filter: blur(10px);
}
.rig-label strong {
display: block;
font: 10px var(--mono);
letter-spacing: .11em;
margin-bottom: 4px;
}
.rig-label span {
color: var(--muted);
font: 9px var(--mono);
text-transform: uppercase;
letter-spacing: .08em;
}
.view-tools {
display: flex;
gap: 6px;
pointer-events: auto;
}
.view-btn {
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 7px;
background: #111819d9;
backdrop-filter: blur(10px);
color: var(--muted);
font: 9px var(--mono);
text-transform: uppercase;
letter-spacing: .08em;
cursor: pointer;
}
.view-btn:hover,
.view-btn.active {
color: var(--text);
border-color: #52615f;
background: #1c2727e8;
}
.viewport-bottom {
position: absolute;
z-index: 2;
left: 18px;
right: 18px;
bottom: 16px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.contact-legend {
display: flex;
align-items: center;
gap: 12px;
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 8px;
background: #111819d9;
backdrop-filter: blur(10px);
color: var(--muted);
font: 9px var(--mono);
letter-spacing: .04em;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-dot {
width: 7px;
height: 7px;
border-radius: 50%;
}
.legend-dot.engaged { background: var(--green); }
.legend-dot.partial { background: var(--amber); }
.legend-dot.open { background: var(--red); }
.control-hint {
padding: 8px 10px;
border-radius: 7px;
background: #111819b8;
color: #71807b;
font: 9px var(--mono);
text-align: right;
}
.control-hint kbd {
color: #b7c1bc;
font: inherit;
}
.empty-inspector {
padding: 17px 12px;
border: 1px dashed #354241;
border-radius: 9px;
text-align: center;
color: var(--muted);
}
.empty-inspector .empty-mark {
width: 34px;
height: 34px;
margin: 0 auto 10px;
display: grid;
place-items: center;
border: 1px solid #3d4b49;
border-radius: 9px;
color: var(--orange);
font-size: 17px;
}
.empty-inspector strong {
display: block;
color: #c8d0cb;
font-size: 11px;
margin-bottom: 6px;
}
.empty-inspector span {
font-size: 10px;
line-height: 1.5;
}
.selected-title {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 15px;
}
.selected-badge {
width: 34px;
height: 34px;
display: grid;
place-items: center;
border-radius: 8px;
font: 10px var(--mono);
font-weight: 800;
}
.selected-badge.hook { color: #ffc6a6; background: #542d20; border: 1px solid #87472e; }
.selected-badge.loop { color: #9de1d9; background: #1c4644; border: 1px solid #326e69; }
.selected-badge.strap { color: #e8dbb2; background: #3d3827; border: 1px solid #6e6241; }
.selected-name {
font-size: 12px;
font-weight: 750;
}
.selected-id {
margin-top: 3px;
color: var(--muted);
font: 9px var(--mono);
letter-spacing: .07em;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
min-height: 35px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
}
.status-row strong {
color: var(--text);
font: 10px var(--mono);
text-transform: uppercase;
}
.status-row strong.good { color: var(--green); }
.status-row strong.warn { color: var(--amber); }
.status-row strong.bad { color: var(--red); }
.position-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 9px 0 12px;
}
.field label {
display: block;
color: var(--muted-2);
font: 8px var(--mono);
letter-spacing: .1em;
margin-bottom: 5px;
}
.field input {
width: 100%;
height: 31px;
border: 1px solid var(--line);
border-radius: 6px;
background: #0f1617;
color: var(--text);
padding: 0 8px;
font: 10px var(--mono);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.small-btn {
min-height: 31px;
border: 1px solid var(--line);
border-radius: 6px;
background: var(--panel-2);
color: var(--muted);
font: 9px var(--mono);
text-transform: uppercase;
letter-spacing: .05em;
cursor: pointer;
}
.small-btn:hover {
color: var(--text);
border-color: var(--line-strong);
background: var(--panel-3);
}
.small-btn.danger:hover {
color: #ffaaa2;
border-color: #70413d;
}
.engagement-head {
display: flex;
align-items: center;
gap: 13px;
margin-bottom: 14px;
}
.score-ring {
--score: 0deg;
width: 63px;
height: 63px;
flex: 0 0 auto;
display: grid;
place-items: center;
border-radius: 50%;
background: conic-gradient(var(--green) var(--score), #273231 0);
position: relative;
}
.score-ring::after {
content: "";
position: absolute;
inset: 6px;
border-radius: 50%;
background: var(--panel);
}
.score-ring span {
position: relative;
z-index: 1;
font: 14px var(--mono);
font-weight: 700;
}
.engagement-copy strong {
display: block;
font-size: 11px;
margin-bottom: 5px;
}
.engagement-copy p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.contact-list {
display: grid;
gap: 5px;
max-height: 190px;
overflow: auto;
}
.contact-item {
width: 100%;
display: grid;
grid-template-columns: 8px 1fr auto;
align-items: center;
gap: 8px;
padding: 8px 7px;
border: 1px solid transparent;
border-radius: 6px;
background: transparent;
text-align: left;
cursor: pointer;
}
.contact-item:hover {
border-color: var(--line);
background: var(--panel-2);
}
.contact-item .dot {
width: 7px;
height: 7px;
border-radius: 50%;
}
.contact-item .dot.good { background: var(--green); }
.contact-item .dot.warn { background: var(--amber); }
.contact-item .dot.bad { background: var(--red); }
.contact-name {
color: #c8d1cc;
font-size: 10px;
font-weight: 650;
}
.contact-source {
margin-top: 3px;
color: var(--muted-2);
font: 8px var(--mono);
text-transform: uppercase;
}
.contact-pct {
color: var(--muted);
font: 9px var(--mono);
}
.scene-slots {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-bottom: 9px;
}
.scene-slot {
min-width: 0;
padding: 10px 5px;
border: 1px solid var(--line);
border-radius: 7px;
background: var(--panel-2);
cursor: pointer;
text-align: center;
}
.scene-slot:hover { border-color: var(--line-strong); }
.scene-slot.active {
border-color: #a15536;
background: #2b201b;
}
.slot-letter {
display: block;
color: var(--orange);
font: 11px var(--mono);
font-weight: 800;
margin-bottom: 4px;
}
.slot-name {
display: block;
overflow: hidden;
color: var(--muted);
font: 7px var(--mono);
text-overflow: ellipsis;
white-space: nowrap;
letter-spacing: .05em;
}
.scene-actions {
display: grid;
grid-template-columns: 1fr 1.2fr;
gap: 7px;
}
.primary-btn {
min-height: 32px;
border: 1px solid #9c5436;
border-radius: 6px;
background: var(--orange);
color: #1b100c;
font: 9px var(--mono);
font-weight: 800;
text-transform: uppercase;
letter-spacing: .05em;
cursor: pointer;
}
.primary-btn:hover { background: #ff8956; }
#toast {
position: fixed;
z-index: 100;
left: 50%;
bottom: 25px;
max-width: 90vw;
padding: 10px 14px;
border: 1px solid #485654;
border-radius: 8px;
background: #1a2424ed;
box-shadow: 0 12px 35px #0008;
color: #dce2dd;
font: 10px var(--mono);
opacity: 0;
pointer-events: none;
transform: translate(-50%, 8px);
transition: .2s ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: absolute;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #101617;
color: var(--muted);
font: 10px var(--mono);
letter-spacing: .12em;
}
#loading::before {
content: "";
width: 24px;
height: 24px;
margin-right: 10px;
border: 2px solid #34413f;
border-top-color: var(--orange);
border-radius: 50%;
animation: spin .8s linear infinite;
}
#loading {
justify-content: center;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 1080px) {
.workspace { grid-template-columns: 208px minmax(0, 1fr) 258px; }
.part-card { grid-template-columns: 42px 1fr 20px; }
.control-hint { display: none; }
.header-status { display: none; }
}
@media (max-width: 820px) {
.workspace { grid-template-columns: 190px minmax(0, 1fr); }
.right-panel { display: none; }
.project { display: none; }
.contact-legend { flex-wrap: wrap; }
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark"></div>
<div>
<div class="brand-name">TACTILE</div>
<div class="brand-sub">Costume systems lab</div>
</div>
</div>
<div class="header-divider"></div>
<div class="project">
<label>PROJECT</label>
<input id="projectName" value="Night Runner / Rig 04" aria-label="Project name">
</div>
<div class="header-spacer"></div>
<div class="header-status">
<span class="status-dot"></span>
<span id="headerContact">Contact 0%</span>
</div>
<button class="icon-btn" id="undoBtn" title="Undo (Ctrl/Cmd+Z)" aria-label="Undo">
<svg viewBox="0 0 24 24"><path d="M9 7 4 12l5 5"/><path d="M5 12h8a6 6 0 0 1 6 6"/></svg>
</button>
<button class="icon-btn" id="redoBtn" title="Redo (Ctrl/Cmd+Shift+Z)" aria-label="Redo">
<svg viewBox="0 0 24 24"><path d="m15 7 5 5-5 5"/><path d="M19 12h-8a6 6 0 0 0-6 6"/></svg>
</button>
<button class="icon-btn" id="resetBtn" title="Reset the current board" aria-label="Reset">
<svg viewBox="0 0 24 24"><path d="M4 4v6h6"/><path d="M5.5 15a8 8 0 1 0 .5-7.5L4 10"/></svg>
</button>
</header>
<div class="workspace">
<aside class="left-panel">
<section class="panel-section">
<div class="section-heading">
<span class="eyebrow">Attachment library</span>
<span class="count-badge">03</span>
</div>
<div class="part-list">
<div class="part-card" draggable="true" data-add="hook" tabindex="0" role="button" aria-label="Add hook patch">
<div class="part-icon hook"></div>
<div>
<div class="part-name">Hook patch</div>
<div class="part-meta">80 × 55 mm<br>Hook-facing module</div>
</div>
<div class="add-symbol">+</div>
</div>
<div class="part-card" draggable="true" data-add="loop" tabindex="0" role="button" aria-label="Add loop patch">
<div class="part-icon loop"></div>
<div>
<div class="part-name">Loop patch</div>
<div class="part-meta">62 × 44 mm<br>Receiver module</div>
</div>
<div class="add-symbol">+</div>
</div>
<div class="part-card" draggable="true" data-add="strap" tabindex="0" role="button" aria-label="Add bridge strap">
<div class="part-icon strap"></div>
<div>
<div class="part-name">Bridge strap</div>
<div class="part-meta">180 mm span<br>Dual anchor</div>
</div>
<div class="add-symbol">+</div>
</div>
</div>
<div class="hint">
<span>↳</span>
<div><b>Click</b> to add, or drag onto the board. Loop patches snap over hook patches.</div>
</div>
</section>
<section class="panel-section">
<div class="section-heading">
<span class="eyebrow">Behavior</span>
</div>
<label class="toggle-row">
<span>Magnetic snap</span>
<span class="switch">
<input id="snapToggle" type="checkbox" checked>
<span class="slider"></span>
</span>
</label>
<label class="toggle-row">
<span>25 mm grid</span>
<span class="switch">
<input id="gridToggle" type="checkbox" checked>
<span class="slider"></span>
</span>
</label>
<label class="toggle-row">
<span>Contact overlay</span>
<span class="switch">
<input id="contactToggle" type="checkbox" checked>
<span class="slider"></span>
</span>
</label>
</section>
<section class="panel-section">
<div class="section-heading">
<span class="eyebrow">Surface key</span>
</div>
<div class="material-key">
<div class="key-row"><span class="key-swatch hook"></span>Hook-facing patch</div>
<div class="key-row"><span class="key-swatch loop"></span>Loop-facing patch</div>
<div class="key-row"><span class="key-swatch strap"></span>Flexible webbing</div>
<div class="key-row"><span class="key-swatch contact"></span>Actual contact area</div>
</div>
</section>
</aside>
<main id="viewport">
<div id="loading">INITIALIZING RIG</div>
<div class="viewport-top">
<div class="rig-label">
<strong>COSTUME BOARD / 04</strong>
<span id="sceneReadout">Scene A · Base kit</span>
</div>
<div class="view-tools">
<button class="view-btn active" data-view="front">Front</button>
<button class="view-btn" data-view="angle">Angled</button>
</div>
</div>
<div class="viewport-bottom">
<div class="contact-legend">
<span class="legend-item"><i class="legend-dot engaged"></i>Engaged</span>
<span class="legend-item"><i class="legend-dot partial"></i>Partial</span>
<span class="legend-item"><i class="legend-dot open"></i>Open</span>
</div>
<div class="control-hint">
Drag attachments · Drag strap ends · <kbd>Right-drag</kbd> orbit · <kbd>Wheel</kbd> zoom
</div>
</div>
</main>
<aside class="right-panel">
<section class="panel-section">
<div class="section-heading">
<span class="eyebrow">Selection</span>
<span class="count-badge" id="partCount">00</span>
</div>
<div id="inspector"></div>
</section>
<section class="panel-section">
<div class="section-heading">
<span class="eyebrow">Engagement report</span>
</div>
<div class="engagement-head">
<div class="score-ring" id="scoreRing"><span id="contactScore">0%</span></div>
<div class="engagement-copy">
<strong id="contactTitle">No attachments</strong>
<p id="contactSummary">Add a module to begin contact analysis.</p>
</div>
</div>
<div class="contact-list" id="contactList"></div>
</section>
<section class="panel-section">
<div class="section-heading">
<span class="eyebrow">Scene states</span>
</div>
<div class="scene-slots">
<button class="scene-slot active" data-slot="A"><span class="slot-letter">A</span><span class="slot-name">BASE KIT</span></button>
<button class="scene-slot" data-slot="B"><span class="slot-letter">B</span><span class="slot-name">ACTION</span></button>
<button class="scene-slot" data-slot="C"><span class="slot-letter">C</span><span class="slot-name">CEREMONY</span></button>
</div>
<div class="scene-actions">
<button class="small-btn" id="saveScene">Save state</button>
<button class="primary-btn" id="playSequence">▶ Play sequence</button>
</div>
</section>
</aside>
</div>
</div>
<div id="toast"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* --------------------------------------------------------------------------
DOM and state
--------------------------------------------------------------------------- */
const viewport = document.getElementById("viewport");
const inspector = document.getElementById("inspector");
const contactList = document.getElementById("contactList");
const toast = document.getElementById("toast");
const TYPE_META = {
hook: { name: "Hook patch", prefix: "H", color: 0xd86d3f, css: "hook" },
loop: { name: "Loop patch", prefix: "L", color: 0x438f88, css: "loop" },
strap: { name: "Bridge strap", prefix: "S", color: 0xc5b17d, css: "strap" }
};
const ZONES = [
{ id: "chest", name: "Chest loop field", x: 0.00, y: 1.02, w: 2.15, h: 1.20 },
{ id: "lshoulder",name: "Left shoulder loop", x: -1.34, y: 1.83, w: 1.12, h: 0.68 },
{ id: "rshoulder",name: "Right shoulder loop",x: 1.34, y: 1.83, w: 1.12, h: 0.68 },
{ id: "lrib", name: "Left rib loop", x: -1.50, y: -0.02, w: 1.04, h: 2.12 },
{ id: "rrib", name: "Right rib loop", x: 1.50, y: -0.02, w: 1.04, h: 2.12 },
{ id: "waist", name: "Waist loop field", x: 0.00, y: -0.45, w: 1.90, h: 0.78 },
{ id: "lower", name: "Lower loop field", x: 0.00, y: -1.88, w: 2.28, h: 1.02 }
];
const DEFAULT_SLOTS = {
A: {
name: "BASE KIT",
parts: [
{ id: "h1", type: "hook", x: -0.62, y: 1.12, w: .80, h: .56, rot: 0 },
{ id: "l1", type: "loop", x: -0.62, y: 1.12, w: .62, h: .44, rot: 0 },
{ id: "h2", type: "hook", x: 0.68, y: 0.98, w: .80, h: .56, rot: 0 },
{ id: "h3", type: "hook", x: 0.00, y: -0.67, w: .80, h: .56, rot: 0 },
{
id: "s1", type: "strap", x: 0, y: 0, w: .18, h: .18, rot: 0,
anchors: [
{ x: .68, y: .98 },
{ x: 0, y: -.67 }
]
}
]
},
B: {
name: "ACTION",
parts: [
{ id: "h1", type: "hook", x: -1.30, y: 1.78, w: .80, h: .56, rot: 0 },
{ id: "l1", type: "loop", x: -1.30, y: 1.78, w: .62, h: .44, rot: 0 },
{ id: "h2", type: "hook", x: 1.30, y: 1.78, w: .80, h: .56, rot: 0 },
{ id: "l2", type: "loop", x: 1.30, y: 1.78, w: .62, h: .44, rot: 0 },
{ id: "h3", type: "hook", x: -1.42, y: -0.58, w: .80, h: .56, rot: 0 },
{ id: "h4", type: "hook", x: 1.42, y: -0.58, w: .80, h: .56, rot: 0 },
{
id: "s1", type: "strap", x: 0, y: 0, w: .18, h: .18, rot: 0,
anchors: [
{ x: -1.30, y: 1.78 },
{ x: 1.30, y: 1.78 }
]
},
{
id: "s2", type: "strap", x: 0, y: 0, w: .18, h: .18, rot: 0,
anchors: [
{ x: -1.42, y: -.58 },
{ x: 1.42, y: -.58 }
]
}
]
},
C: {
name: "CEREMONY",
parts: [
{ id: "h1", type: "hook", x: 0, y: 1.28, w: .80, h: .56, rot: 0 },
{ id: "l1", type: "loop", x: 0, y: 1.28, w: .62, h: .44, rot: 0 },
{ id: "h2", type: "hook", x: -.78, y: -1.02, w: .80, h: .56, rot: 1 },
{ id: "h3", type: "hook", x: .78, y: -1.02, w: .80, h: .56, rot: 1 },
{ id: "h4", type: "hook", x: 0, y: -1.92, w: .80, h: .56, rot: 0 },
{
id: "s1", type: "strap", x: 0, y: 0, w: .18, h: .18, rot: 0,
anchors: [
{ x: -.78, y: -1.02 },
{ x: .78, y: -1.02 }
]
},
{
id: "s2", type: "strap", x: 0, y: 0, w: .18, h: .18, rot: 0,
anchors: [
{ x: 0, y: 1.28 },
{ x: 0, y: -1.92 }
]
}
]
}
};
const STORAGE_KEY = "tactile-costume-scenes-v1";
let slots = loadSlots();
let activeSlot = "A";
let selectedId = null;
let parts = [];
let idCounter = 100;
let snapEnabled = true;
let gridEnabled = true;
let overlayEnabled = true;
const undoStack = [];
const redoStack = [];
/* --------------------------------------------------------------------------
Three.js scene
--------------------------------------------------------------------------- */
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101617);
scene.fog = new THREE.Fog(0x101617, 10, 19);
const camera = new THREE.PerspectiveCamera(38, 1, .1, 50);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
viewport.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xd7e1db, 0x20221d, 2.25);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff2d8, 3.4);
key.position.set(4.5, 6.5, 7);
key.castShadow = true;
key.shadow.mapSize.set(1024, 1024);
key.shadow.camera.left = -5;
key.shadow.camera.right = 5;
key.shadow.camera.top = 5;
key.shadow.camera.bottom = -5;
key.shadow.camera.near = .5;
key.shadow.camera.far = 20;
key.shadow.bias = -.0004;
scene.add(key);
const rim = new THREE.DirectionalLight(0x76c8c1, 1.25);
rim.position.set(-5, 2, 4);
scene.add(rim);
const warm = new THREE.PointLight(0xf17845, 12, 10, 2);
warm.position.set(-3.8, 1.5, 3.6);
scene.add(warm);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({ color: 0x0c1112, roughness: .92, metalness: .08 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.set(0, -3.05, -1.5);
floor.receiveShadow = true;
scene.add(floor);
const boardGroup = new THREE.Group();
const partsGroup = new THREE.Group();
const overlayGroup = new THREE.Group();
scene.add(boardGroup, partsGroup, overlayGroup);
const cameraState = {
theta: -0.07,
phi: Math.PI / 2,
radius: 9.0,
target: new THREE.Vector3(0, 0, 0)
};
const cameraGoal = {
theta: cameraState.theta,
phi: cameraState.phi,
radius: cameraState.radius,
target: cameraState.target.clone()
};
buildBoard();
/* --------------------------------------------------------------------------
Geometry helpers
--------------------------------------------------------------------------- */
function roundedRectShape(w, h, r) {
const s = new THREE.Shape();
const x = -w / 2;
const y = -h / 2;
r = Math.min(r, w / 2, h / 2);
s.moveTo(x + r, y);
s.lineTo(x + w - r, y);
s.quadraticCurveTo(x + w, y, x + w, y + r);
s.lineTo(x + w, y + h - r);
s.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
s.lineTo(x + r, y + h);
s.quadraticCurveTo(x, y + h, x, y + h - r);
s.lineTo(x, y + r);
s.quadraticCurveTo(x, y, x + r, y);
return s;
}
function makeLabel(text, color = "#edf0e9") {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 64;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 256, 64);
ctx.fillStyle = "rgba(10,15,16,.83)";
ctx.fillRect(0, 0, 256, 64);
ctx.strokeStyle = "rgba(255,255,255,.12)";
ctx.strokeRect(1, 1, 254, 62);
ctx.fillStyle = color;
ctx.font = "700 25px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 128, 33);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.scale.set(.48, .12, 1);
sprite.renderOrder = 8;
sprite.userData.isLabel = true;
return sprite;
}
function buildBoard() {
const bodyShape = roundedRectShape(4.72, 5.56, .22);
const bodyGeometry = new THREE.ExtrudeGeometry(bodyShape, {
depth: .24,
bevelEnabled: true,
bevelThickness: .06,
bevelSize: .075,
bevelSegments: 1,
curveSegments: 1,
steps: 1
});
const body = new THREE.Mesh(
bodyGeometry,
new THREE.MeshStandardMaterial({
color: 0x26302f,
roughness: .7,
metalness: .32,
flatShading: true
})
);
body.position.z = -.16;
body.castShadow = true;
body.receiveShadow = true;
boardGroup.add(body);
const insetShape = roundedRectShape(4.30, 5.12, .14);
const insetGeometry = new THREE.ExtrudeGeometry(insetShape, {
depth: .05,
bevelEnabled: true,
bevelThickness: .018,
bevelSize: .025,
bevelSegments: 1,
curveSegments: 1,
steps: 1
});
const inset = new THREE.Mesh(
insetGeometry,
new THREE.MeshStandardMaterial({
color: 0x3c4742,
roughness: .95,
metalness: .02,
flatShading: true
})
);
inset.position.z = .085;
inset.castShadow = true;
inset.receiveShadow = true;
boardGroup.add(inset);
const zoneMaterial = new THREE.MeshStandardMaterial({
color: 0x778078,
roughness: 1,
transparent: true,
opacity: .46,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -1
});
for (const zone of ZONES) {
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(zone.w, zone.h), zoneMaterial);
mesh.position.set(zone.x, zone.y, .148);
boardGroup.add(mesh);
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.PlaneGeometry(zone.w, zone.h)),
new THREE.LineBasicMaterial({ color: 0xa2aaa3, transparent: true, opacity: .17 })
);
edge.position.set(zone.x, zone.y, .151);
boardGroup.add(edge);
}
const gridVertices = [];
for (let x = -2; x <= 2.001; x += .25) {
gridVertices.push(x, -2.42, .153, x, 2.42, .153);
}
for (let y = -2.25; y <= 2.251; y += .25) {
gridVertices.push(-2.05, y, .153, 2.05, y, .153);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute("position", new THREE.Float32BufferAttribute(gridVertices, 3));
boardGroup.add(new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({ color: 0xb7c1b9, transparent: true, opacity: .075 })
));
const holeGeometry = new THREE.CylinderGeometry(.068, .068, .035, 10);
holeGeometry.rotateX(Math.PI / 2);
const holeMaterial = new THREE.MeshStandardMaterial({ color: 0x111718, roughness: .55, metalness: .7 });
for (const [x, y] of [
[-2.08, -2.48], [2.08, -2.48], [-2.08, 2.48], [2.08, 2.48],
[0, -2.49], [0, 2.49]
]) {
const hole = new THREE.Mesh(holeGeometry, holeMaterial);
hole.position.set(x, y, .155);
boardGroup.add(hole);
}
const plaque = makeLabel("COSTUME RIG / 04", "#f0a277");
plaque.position.set(0, 2.47, .2);
plaque.scale.set(.95, .24, 1);
boardGroup.add(plaque);
}
/* --------------------------------------------------------------------------
Attachment construction
--------------------------------------------------------------------------- */
function createPart(data) {
const p = {
id: data.id || `${TYPE_META[data.type].prefix.toLowerCase()}${++idCounter}`,
type: data.type,
x: data.x ?? 0,
y: data.y ?? 0,
tx: data.x ?? 0,
ty: data.y ?? 0,
w: data.w ?? (data.type === "hook" ? .80 : data.type === "loop" ? .62 : .18),
h: data.h ?? (data.type === "hook" ? .56 : data.type === "loop" ? .44 : .18),
rot: data.rot ?? 0,
group: null,
overlay: null,
selection: null,
spawn: performance.now()
};
if (data.type === "strap") {
const sourceAnchors = data.anchors || [
{ x: p.x - .9, y: p.y },
{ x: p.x + .9, y: p.y }
];
p.anchors = sourceAnchors.map(a => ({ x: a.x, y: a.y, tx: a.x, ty: a.y }));
}
p.group = data.type === "strap" ? createStrap(p) : createTile(p);
p.group.userData.partId = p.id;
p.group.traverse(obj => {
if (obj.isMesh || obj.isLineSegments) obj.userData.partId = p.id;
});
partsGroup.add(p.group);
parts.push(p);
updatePartTransform(p);
return p;
}
function createTile(p) {
const group = new THREE.Group();
const meta = TYPE_META[p.type];
const shape = roundedRectShape(p.w, p.h, .065);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: .08,
bevelEnabled: true,
bevelThickness: .018,
bevelSize: .023,
bevelSegments: 1,
curveSegments: 1,
steps: 1
});
const body = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: meta.color,
roughness: p.type === "loop" ? .98 : .76,
metalness: .02,
flatShading: true
})
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
if (p.type === "hook") {
const hookGeometry = new THREE.CylinderGeometry(.019, .012, .026, 3);
hookGeometry.rotateX(Math.PI / 2);
const hookMaterial = new THREE.MeshStandardMaterial({
color: 0xffd0a9,
roughness: .58,
metalness: .25,
flatShading: true
});
const cols = 6;
const rows = 3;
for (let iy = 0; iy < rows; iy++) {
for (let ix = 0; ix < cols; ix++) {
const hook = new THREE.Mesh(hookGeometry, hookMaterial);
hook.position.set(
(ix - (cols - 1) / 2) * (p.w / (cols + 1)),
(iy - (rows - 1) / 2) * (p.h / (rows + 1)),
.109
);
group.add(hook);
}
}
} else {
const fuzzGeometry = new THREE.OctahedronGeometry(.022, 0);
fuzzGeometry.scale(1, 1, .28);
const fuzzMaterial = new THREE.MeshStandardMaterial({
color: 0xa8e0d8,
roughness: 1,
flatShading: true
});
for (let iy = 0; iy < 3; iy++) {
for (let ix = 0; ix < 5; ix++) {
const fuzz = new THREE.Mesh(fuzzGeometry, fuzzMaterial);
fuzz.position.set(
(ix - 2) * .105,
(iy - 1) * .105,
.103
);
fuzz.rotation.z = Math.PI / 4;
group.add(fuzz);
}
}
}
const label = makeLabel(p.id.toUpperCase(), p.type === "hook" ? "#ffd2b5" : "#b4eee7");
label.position.set(0, p.h / 2 + .105, .14);
group.add(label);
const selectionGeometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(p.w + .09, p.h + .09, .14)
);
const selection = new THREE.LineSegments(
selectionGeometry,
new THREE.LineBasicMaterial({ color: 0xffb17d, transparent: true, opacity: .95 })
);
selection.position.z = .075;
selection.visible = false;
group.add(selection);
p.selection = selection;
p.overlay = new THREE.Group();
group.add(p.overlay);
return group;
}
function createStrap(p) {
const group = new THREE.Group();
p.ribbon = new THREE.Mesh(
new THREE.BufferGeometry(),
new THREE.MeshStandardMaterial({
color: 0xb9aa78,
roughness: .94,
side: THREE.DoubleSide,
flatShading: true
})
);
p.ribbon.castShadow = true;
group.add(p.ribbon);
p.connectors = [];
for (let i = 0; i < 2; i++) {
const connector = new THREE.Mesh(
new THREE.TorusGeometry(.087, .024, 4, 10),
new THREE.MeshStandardMaterial({
color: 0x8e9587,
roughness: .45,
metalness: .65,
flatShading: true
})
);
connector.castShadow = true;
connector.userData.partId = p.id;
connector.userData.endpoint = i;
group.add(connector);
p.connectors.push(connector);
}
const buckle = new THREE.Mesh(
new THREE.BoxGeometry(.24, .17, .07),
new THREE.MeshStandardMaterial({
color: 0x59625d,
roughness: .4,
metalness: .7,
flatShading: true
})
);
buckle.castShadow = true;
group.add(buckle);
p.buckle = buckle;
const label = makeLabel(p.id.toUpperCase(), "#e9dbad");
group.add(label);
p.label = label;
p.overlay = new THREE.Group();
group.add(p.overlay);
return group;
}
function updatePartTransform(p) {
if (!p.group) return;
if (p.type === "strap") {
updateStrapGeometry(p);
p.selection = null;
return;
}
p.group.position.set(p.x, p.y, .17);
p.group.rotation.z = p.rot * Math.PI / 2;
p.selection.visible = p.id === selectedId;
}
function updateStrapGeometry(p) {
if (!p.anchors) return;
const a = p.anchors[0];
const b = p.anchors[1];
const segments = 12;
const width = p.w;
const vertices = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const x = THREE.MathUtils.lerp(a.x, b.x, t);
const y = THREE.MathUtils.lerp(a.y, b.y, t);
const dx = b.x - a.x;
const dy = b.y - a.y;
const len = Math.hypot(dx, dy) || 1;
const nx = -dy / len * width * .5;
const ny = dx / len * width * .5;
const z = .355 + Math.sin(t * Math.PI) * .20;
vertices.push(x + nx, y + ny, z);
vertices.push(x - nx, y - ny, z);
if (i < segments) {
const k = i * 2;
indices.push(k, k + 1, k + 2, k + 1, k + 3, k + 2);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
p.ribbon.geometry.dispose();
p.ribbon.geometry = geometry;
p.connectors.forEach((connector, i) => {
const point = p.anchors[i];
connector.position.set(point.x, point.y, .365);
});
const midX = (a.x + b.x) * .5;
const midY = (a.y + b.y) * .5;
p.buckle.position.set(midX, midY, .58);
p.buckle.rotation.z = Math.atan2(b.y - a.y, b.x - a.x);
p.label.position.set(midX, midY + .17, .67);
}
/* --------------------------------------------------------------------------
Contact analysis
--------------------------------------------------------------------------- */
function dimensions(p) {
return p.rot ? { w: p.h, h: p.w } : { w: p.w, h: p.h };
}
function rectOverlap(a, b) {
const x1 = Math.max(a.x - a.w / 2, b.x - b.w / 2);
const x2 = Math.min(a.x + a.w / 2, b.x + b.w / 2);
const y1 = Math.max(a.y - a.h / 2, b.y - b.h / 2);
const y2 = Math.min(a.y + a.h / 2, b.y + b.h / 2);
if (x2 <= x1 || y2 <= y1) return null;
return { x: (x1 + x2) / 2, y: (y1 + y2) / 2, w: x2 - x1, h: y2 - y1 };
}
function pointInRect(x, y, rect) {
return Math.abs(x - rect.x) <= rect.w / 2 && Math.abs(y - rect.y) <= rect.h / 2;
}
function computeContacts() {
const result = new Map();
for (const p of parts) {
const dims = dimensions(p);
const footprint = { x: p.x, y: p.y, w: dims.w, h: dims.h };
const area = Math.max(.0001, dims.w * dims.h);
const contact = {
percent: 0,
sources: [],
rects: [],
anchors: []
};
if (p.type === "hook") {
let total = 0;
for (const zone of ZONES) {
const overlap = rectOverlap(footprint, zone);
if (overlap) {
total += overlap.w * overlap.h;
contact.sources.push(zone.name);
contact.rects.push({ ...overlap, source: zone.id });
}
}
contact.percent = Math.min(100, total / area * 100);
}
if (p.type === "loop") {
let total = 0;
for (const hook of parts.filter(item => item.type === "hook")) {
const hookDims = dimensions(hook);
const overlap = rectOverlap(footprint, {
x: hook.x, y: hook.y, w: hookDims.w, h: hookDims.h
});
if (overlap) {
total += overlap.w * overlap.h;
contact.sources.push(`Hook ${hook.id.toUpperCase()}`);
contact.rects.push({ ...overlap, source: hook.id });
}
}
contact.percent = Math.min(100, total / area * 100);
}
if (p.type === "strap") {
for (const anchor of p.anchors) {
let source = null;
const hook = parts.find(item => {
if (item.type !== "hook") return false;
const d = dimensions(item);
return pointInRect(anchor.x, anchor.y, { x: item.x, y: item.y, w: d.w, h: d.h });
});
if (hook) source = `Hook ${hook.id.toUpperCase()}`;
else {
const zone = ZONES.find(z => pointInRect(anchor.x, anchor.y, z));
if (zone) source = zone.name;
}
contact.anchors.push({ x: anchor.x, y: anchor.y, source });
if (source) contact.sources.push(source);
}
contact.percent = contact.anchors.filter(a => a.source).length / 2 * 100;
}
result.set(p.id, contact);
}
return result;
}
function clearGroup(group) {
if (!group) return;
while (group.children.length) {
const child = group.children.pop();
child.traverse(obj => {
if (obj.geometry) obj.geometry.dispose();
if (obj.material) {
const materials = Array.isArray(obj.material) ? obj.material : [obj.material];
for (const material of materials) {
if (material.map) material.map.dispose();
material.dispose();
}
}
});
}
}
function contactPlane(rect, parentRotation) {
const angle = parentRotation * Math.PI / 2;
const dx = rect.x;
const dy = rect.y;
const localX = Math.cos(angle) * dx + Math.sin(angle) * dy;
const localY = -Math.sin(angle) * dx + Math.cos(angle) * dy;
const geometry = new THREE.PlaneGeometry(rect.w, rect.h);
const material = new THREE.MeshBasicMaterial({
color: 0xb9ed62,
transparent: true,
opacity: .42,
depthWrite: false,
side: THREE.DoubleSide,
polygonOffset: true,
polygonOffsetFactor: -3
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(localX, localY, .119);
mesh.rotation.z = -angle;
return mesh;
}
function renderContactOverlays(contacts) {
for (const p of parts) {
if (!p.overlay) continue;
clearGroup(p.overlay);
p.overlay.visible = overlayEnabled;
const contact = contacts.get(p.id);
if (p.type !== "strap") {
for (const rect of contact.rects) p.overlay.add(contactPlane(rect, p.rot));
} else {
for (const anchor of contact.anchors) {
if (!anchor.source) continue;
const ring = new THREE.Mesh(
new THREE.RingGeometry(.095, .127, 18),
new THREE.MeshBasicMaterial({
color: 0xb9ed62,
transparent: true,
opacity: .78,
depthWrite: false,
side: THREE.DoubleSide
})
);
ring.position.set(anchor.x, anchor.y, .388);
p.overlay.add(ring);
}
}
}
}
function updateContactUI(contacts) {
if (!parts.length) {
contactList.innerHTML = `<div class="empty-inspector"><span>No surface contacts to report.</span></div>`;
setContactScore(0, "No attachments", "Add a module to begin contact analysis.");
return;
}
let total = 0;
let engaged = 0;
let partial = 0;
const rows = parts.map(p => {
const contact = contacts.get(p.id);
const pct = contact.percent;
total += pct;
if (pct >= 80) engaged++;
else if (pct > 0) partial++;
const cls = pct >= 80 ? "good" : pct > 0 ? "warn" : "bad";
const source = contact.sources.length
? contact.sources.join(" + ")
: p.type === "loop" ? "No hook beneath" : "No matching surface";
return `
<button class="contact-item" data-contact-id="${p.id}">
<i class="dot ${cls}"></i>
<span>
<span class="contact-name">${p.id.toUpperCase()} · ${TYPE_META[p.type].name}</span>
<span class="contact-source">${source}</span>
</span>
<span class="contact-pct">${Math.round(pct)}%</span>
</button>`;
}).join("");
contactList.innerHTML = rows;
contactList.querySelectorAll("[data-contact-id]").forEach(button => {
button.addEventListener("click", () => {
selectPart(button.dataset.contactId);
});
});
const score = total / parts.length;
const title = engaged === parts.length
? "All modules engaged"
: partial
? `${partial} partial contact${partial === 1 ? "" : "s"}`
: `${engaged} of ${parts.length} engaged`;
setContactScore(score, title, "Green areas represent actual hook-to-loop overlap and anchored strap ends.");
}
function setContactScore(score, title, summary) {
const rounded = Math.round(score);
document.getElementById("contactScore").textContent = `${rounded}%`;
document.getElementById("scoreRing").style.setProperty("--score", `${rounded * 3.6}deg`);
document.getElementById("contactTitle").textContent = title;
document.getElementById("contactSummary").textContent = summary;
document.getElementById("headerContact").textContent = `Contact ${rounded}%`;
}
/* --------------------------------------------------------------------------
Inspector and mutations
--------------------------------------------------------------------------- */
function selectPart(id) {
selectedId = id;
for (const p of parts) {
if (p.selection) p.selection.visible = p.id === id;
}
renderInspector();
}
function renderInspector() {
const p = parts.find(item => item.id === selectedId);
if (!p) {
inspector.innerHTML = `
<div class="empty-inspector">
<div class="empty-mark">⌖</div>
<strong>No module selected</strong>
<span>Select an attachment on the board to inspect its position and surface engagement.</span>
</div>`;
return;
}
const contact = computeContacts().get(p.id);
const status = contact.percent >= 80 ? "good" : contact.percent > 0 ? "warn" : "bad";
const source = contact.sources.length ? contact.sources.join(" + ") : "No matching surface";
const positionFields = p.type === "strap" ? "" : `
<div class="position-grid">
<div class="field">
<label>X POSITION</label>
<input id="posX" type="number" step="0.05" value="${p.tx.toFixed(2)}">
</div>
<div class="field">
<label>Y POSITION</label>
<input id="posY" type="number" step="0.05" value="${p.ty.toFixed(2)}">
</div>
</div>`;
inspector.innerHTML = `
<div class="selected-title">
<div class="selected-badge ${TYPE_META[p.type].css}">${p.id.toUpperCase()}</div>
<div>
<div class="selected-name">${TYPE_META[p.type].name}</div>
<div class="selected-id">${p.type === "strap" ? "DUAL ANCHOR MODULE" : "REMOVABLE MODULE"}</div>
</div>
</div>
<div class="status-row"><span>Engagement</span><strong class="${status}">${Math.round(contact.percent)}%</strong></div>
<div class="status-row"><span>Contact source</span><strong>${source}</strong></div>
${positionFields}
<div class="button-row">
${p.type !== "strap" ? `<button class="small-btn" id="rotatePart">Rotate 90°</button>` : `<button class="small-btn" id="rotatePart">Shift span</button>`}
<button class="small-btn" id="duplicatePart">Duplicate</button>
<button class="small-btn danger" id="removePart">Remove</button>
<button class="small-btn" id="focusPart">Focus</button>
</div>`;
document.getElementById("removePart")?.addEventListener("click", () => removePart(p.id));
document.getElementById("duplicatePart")?.addEventListener("click", () => duplicatePart(p.id));
document.getElementById("focusPart")?.addEventListener("click", () => focusPart(p));
document.getElementById("rotatePart")?.addEventListener("click", () => {
const before = snapshot();
if (p.type === "strap") {
p.anchors.forEach(a => {
a.x += .10;
a.tx += .10;
});
} else {
p.rot = p.rot ? 0 : 1;
}
pushHistory(before);
afterMutation();
});
document.getElementById("posX")?.addEventListener("change", event => {
const before = snapshot();
p.tx = Number(event.target.value) || 0;
p.x = p.tx;
pushHistory(before);
afterMutation();
});
document.getElementById("posY")?.addEventListener("change", event => {
const before = snapshot();
p.ty = Number(event.target.value) || 0;
p.y = p.ty;
pushHistory(before);
afterMutation();
});
}
function addPart(type, x = 0, y = .15) {
const before = snapshot();
const data = { type, x, y };
if (type === "strap") {
data.anchors = [
{ x: x - .85, y },
{ x: x + .85, y }
];
}
const p = createPart(data);
selectedId = p.id;
pushHistory(before);
afterMutation();
showToast(`${TYPE_META[type].name} added`);
}
function removePart(id) {
const before = snapshot();
const p = parts.find(item => item.id === id);
if (!p) return;
disposePart(p);
parts = parts.filter(item => item.id !== id);
if (selectedId === id) selectedId = null;
pushHistory(before);
afterMutation();
}
function duplicatePart(id) {
const source = parts.find(item => item.id === id);
if (!source) return;
const before = snapshot();
const copy = {
...source,
id: `${source.type[0]}${++idCounter}`,
x: source.tx + .18,
y: source.ty + .18,
anchors: source.anchors?.map(a => ({ x: a.x + .18, y: a.y + .18 }))
};
delete copy.group;
delete copy.overlay;
delete copy.selection;
delete copy.ribbon;
delete copy.connectors;
delete copy.buckle;
delete copy.label;
delete copy.spawn;
const p = createPart(copy);
selectedId = p.id;
pushHistory(before);
afterMutation();
}
function focusPart(p) {
cameraGoal.target.set(p.x * .35, p.y * .35, 0);
cameraGoal.radius = 7.4;
cameraGoal.theta = -.08;
cameraGoal.phi = Math.PI / 2;
}
function afterMutation() {
document.getElementById("partCount").textContent = String(parts.length).padStart(2, "0");
updateAllParts();
renderInspector();
updateContactUI(computeContacts());
updateHistoryButtons();
}
function updateAllParts() {
for (const p of parts) updatePartTransform(p);
}
function disposePart(p) {
if (!p.group) return;
partsGroup.remove(p.group);
const geometries = new Set();
const materials = new Set();
const textures = new Set();
p.group.traverse(obj => {
if (obj.geometry) geometries.add(obj.geometry);
if (obj.material) {
const list = Array.isArray(obj.material) ? obj.material : [obj.material];
for (const material of list) {
materials.add(material);
if (material.map) textures.add(material.map);
}
}
});
geometries.forEach(g => g.dispose());
materials.forEach(m => m.dispose());
textures.forEach(t => t.dispose());
}
/* --------------------------------------------------------------------------
History
--------------------------------------------------------------------------- */
function snapshot() {
return JSON.stringify(parts.map(p => {
const data = {
id: p.id,
type: p.type,
x: p.tx,
y: p.ty,
w: p.w,
h: p.h,
rot: p.rot
};
if (p.anchors) data.anchors = p.anchors.map(a => ({ x: a.tx, y: a.ty }));
return data;
}));
}
function pushHistory(previous) {
undoStack.push(previous);
if (undoStack.length > 60) undoStack.shift();
redoStack.length = 0;
updateHistoryButtons();
}
function applySnapshot(data) {
const parsed = JSON.parse(data);
for (const p of parts) disposePart(p);
parts = [];
selectedId = null;
for (const item of parsed) createPart(item);
afterMutation();
}
function undo() {
if (!undoStack.length) return;
redoStack.push(snapshot());
applySnapshot(undoStack.pop());
}
function redo() {
if (!redoStack.length) return;
undoStack.push(snapshot());
applySnapshot(redoStack.pop());
}
function updateHistoryButtons() {
document.getElementById("undoBtn").disabled = !undoStack.length;
document.getElementById("redoBtn").disabled = !redoStack.length;
}
/* --------------------------------------------------------------------------
Scene states
--------------------------------------------------------------------------- */
function loadSlots() {
try {
const saved = JSON.parse(localStorage.getItem(STORAGE_KEY));
if (saved && saved.A && saved.B && saved.C) return saved;
} catch {}
return structuredClone(DEFAULT_SLOTS);
}
function saveSlots() {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(slots));
} catch {}
}
function loadSlot(slot, announce = true) {
activeSlot = slot;
const desired = slots[slot].parts;
const desiredIds = new Set(desired.map(p => p.id));
for (const existing of [...parts]) {
if (!desiredIds.has(existing.id)) {
disposePart(existing);
parts = parts.filter(p => p.id !== existing.id);
}
}
for (const data of desired) {
let existing = parts.find(p => p.id === data.id);
if (existing && existing.type !== data.type) {
disposePart(existing);
parts = parts.filter(p => p.id !== data.id);
existing = null;
}
if (existing) {
existing.tx = data.x;
existing.ty = data.y;
existing.w = data.w;
existing.h = data.h;
existing.rot = data.rot ?? 0;
if (data.anchors) {
data.anchors.forEach((a, i) => {
existing.anchors[i].tx = a.x;
existing.anchors[i].ty = a.y;
});
}
} else {
createPart(data);
}
}
selectedId = null;
document.querySelectorAll(".scene-slot").forEach(button => {
button.classList.toggle("active", button.dataset.slot === slot);
const name = button.querySelector(".slot-name");
if (name) name.textContent = slots[slot].name;
});
document.getElementById("sceneReadout").textContent = `Scene ${slot} · ${slots[slot].name}`;
afterMutation();
if (announce) showToast(`Scene ${slot}: ${slots[slot].name}`);
}
function saveActiveScene() {
slots[activeSlot] = {
name: slots[activeSlot].name,
parts: JSON.parse(snapshot())
};
saveSlots();
showToast(`Scene ${activeSlot} saved locally`);
}
let sequenceTimer = null;
let sequenceIndex = 0;
function toggleSequence() {
const button = document.getElementById("playSequence");
if (sequenceTimer) {
clearInterval(sequenceTimer);
sequenceTimer = null;
button.textContent = "▶ Play sequence";
return;
}
button.textContent = "■ Stop sequence";
sequenceIndex = 0;
loadSlot("A", false);
sequenceTimer = setInterval(() => {
sequenceIndex = (sequenceIndex + 1) % 3;
loadSlot(["A", "B", "C"][sequenceIndex], false);
}, 1700);
showToast("Playing saved scene sequence");
}
/* --------------------------------------------------------------------------
Pointer placement and camera controls
--------------------------------------------------------------------------- */
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 0, 1), -.22);
const dragPoint = new THREE.Vector3();
let pointerMode = null;
let dragState = null;
let orbiting = false;
let lastPointer = { x: 0, y: 0 };
function setPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pointerToBoard(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
return raycaster.ray.intersectPlane(dragPlane, dragPoint);
}
function findPartHit(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(partsGroup.children, true);
for (const hit of hits) {
if (hit.object.userData.isLabel) continue;
const id = hit.object.userData.partId;
if (!id) continue;
const part = parts.find(p => p.id === id);
if (!part) continue;
return {
part,
endpoint: hit.object.userData.endpoint,
point: hit.point
};
}
return null;
}
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
if (event.button === 2 || event.button === 1) {
pointerMode = event.button === 2 ? "orbit" : "pan";
orbiting = true;
lastPointer = { x: event.clientX, y: event.clientY };
return;
}
const hit = findPartHit(event);
if (!hit) {
selectPart(null);
return;
}
selectPart(hit.part.id);
const point = pointerToBoard(event);
if (!point) return;
const p = hit.part;
dragState = {
partId: p.id,
endpoint: hit.endpoint,
startX: p.tx,
startY: p.ty,
offsetX: p.tx - point.x,
offsetY: p.ty - point.y,
before: snapshot(),
moved: false
};
pointerMode = "drag";
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerMode === "orbit") {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
lastPointer = { x: event.clientX, y: event.clientY };
cameraState.theta -= dx * .006;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - dy * .005, .65, 2.15);
cameraGoal.theta = cameraState.theta;
cameraGoal.phi = cameraState.phi;
return;
}
if (pointerMode === "pan") {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
lastPointer = { x: event.clientX, y: event.clientY };
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
cameraState.target.addScaledVector(right, -dx * .006);
cameraState.target.addScaledVector(up, dy * .006);
cameraGoal.target.copy(cameraState.target);
return;
}
if (pointerMode !== "drag" || !dragState) return;
const point = pointerToBoard(event);
if (!point) return;
const p = parts.find(item => item.id === dragState.partId);
if (!p) return;
dragState.moved = true;
if (dragState.endpoint !== undefined) {
let x = point.x;
let y = point.y;
if (snapEnabled) {
const hook = parts.find(item => {
if (item.type !== "hook") return false;
return Math.hypot(item.x - x, item.y - y) < .23;
});
if (hook) {
x = hook.x;
y = hook.y;
}
}
const anchor = p.anchors[dragState.endpoint];
anchor.x = anchor.tx = x;
anchor.y = anchor.ty = y;
} else if (p.type === "strap") {
const dx = point.x + dragState.offsetX - dragState.startX;
const dy = point.y + dragState.offsetY - dragState.startY;
p.x = p.tx = dragState.startX + dx;
p.y = p.ty = dragState.startY + dy;
p.anchors.forEach(a => {
a.x = a.tx += dx;
a.y = a.ty += dy;
});
} else {
let x = point.x + dragState.offsetX;
let y = point.y + dragState.offsetY;
if (gridEnabled) {
x = Math.round(x * 20) / 20;
y = Math.round(y * 20) / 20;
}
if (snapEnabled && p.type === "loop") {
const hook = parts.find(item => {
if (item.type !== "hook") return false;
return Math.hypot(item.x - x, item.y - y) < .18;
});
if (hook) {
x = hook.x;
y = hook.y;
}
}
p.x = p.tx = THREE.MathUtils.clamp(x, -2.02, 2.02);
p.y = p.ty = THREE.MathUtils.clamp(y, -2.35, 2.35);
}
updateAllParts();
const contacts = computeContacts();
renderContactOverlays(contacts);
updateContactUI(contacts);
refreshInspectorValues();
});
function endPointer(event) {
if (pointerMode === "drag" && dragState) {
if (dragState.moved) pushHistory(dragState.before);
dragState = null;
}
pointerMode = null;
orbiting = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
afterMutation();
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
const factor = Math.exp(event.deltaY * .001);
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius * factor, 6.2, 13);
cameraGoal.radius = cameraState.radius;
}, { passive: false });
function refreshInspectorValues() {
const p = parts.find(item => item.id === selectedId);
if (!p) return;
const xInput = document.getElementById("posX");
const yInput = document.getElementById("posY");
if (xInput && document.activeElement !== xInput) xInput.value = p.tx.toFixed(2);
if (yInput && document.activeElement !== yInput) yInput.value = p.ty.toFixed(2);
}
/* --------------------------------------------------------------------------
UI events
--------------------------------------------------------------------------- */
document.querySelectorAll("[data-add]").forEach(card => {
const add = () => {
const type = card.dataset.add;
const offset = (parts.length % 3 - 1) * .12;
addPart(type, offset, .25 + offset);
};
card.addEventListener("click", add);
card.addEventListener("keydown", event => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
add();
}
});
card.addEventListener("dragstart", event => {
event.dataTransfer.setData("text/plain", card.dataset.add);
event.dataTransfer.effectAllowed = "copy";
});
});
viewport.addEventListener("dragover", event => {
event.preventDefault();
event.dataTransfer.dropEffect = "copy";
});
viewport.addEventListener("drop", event => {
event.preventDefault();
const type = event.dataTransfer.getData("text/plain");
if (!TYPE_META[type]) return;
const rect = renderer.domElement.getBoundingClientRect();
const fakeEvent = {
clientX: event.clientX,
clientY: event.clientY
};
const point = pointerToBoard(fakeEvent);
if (!point) return;
addPart(type, point.x, point.y);
});
document.getElementById("snapToggle").addEventListener("change", event => {
snapEnabled = event.target.checked;
});
document.getElementById("gridToggle").addEventListener("change", event => {
gridEnabled = event.target.checked;
});
document.getElementById("contactToggle").addEventListener("change", event => {
overlayEnabled = event.target.checked;
const contacts = computeContacts();
renderContactOverlays(contacts);
});
document.getElementById("undoBtn").addEventListener("click", undo);
document.getElementById("redoBtn").addEventListener("click", redo);
document.getElementById("resetBtn").addEventListener("click", () => {
const before = snapshot();
parts.forEach(disposePart);
parts = [];
selectedId = null;
pushHistory(before);
afterMutation();
showToast("Board cleared");
});
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => {
document.querySelectorAll("[data-view]").forEach(b => b.classList.remove("active"));
button.classList.add("active");
if (button.dataset.view === "front") {
cameraGoal.theta = 0;
cameraGoal.phi = Math.PI / 2;
cameraGoal.radius = 9;
cameraGoal.target.set(0, 0, 0);
} else {
cameraGoal.theta = -.30;
cameraGoal.phi = 1.40;
cameraGoal.radius = 9.2;
cameraGoal.target.set(0, 0, 0);
}
});
});
document.querySelectorAll("[data-slot]").forEach(button => {
button.addEventListener("click", () => loadSlot(button.dataset.slot));
});
document.getElementById("saveScene").addEventListener("click", saveActiveScene);
document.getElementById("playSequence").addEventListener("click", toggleSequence);
document.getElementById("projectName").addEventListener("change", event => {
try {
localStorage.setItem("tactile-project-name", event.target.value);
} catch {}
showToast("Project name updated");
});
try {
const savedName = localStorage.getItem("tactile-project-name");
if (savedName) document.getElementById("projectName").value = savedName;
} catch {}
window.addEventListener("keydown", event => {
const target = event.target;
if (target instanceof HTMLInputElement) return;
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "z") {
event.preventDefault();
event.shiftKey ? redo() : undo();
return;
}
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "d") {
event.preventDefault();
if (selectedId) duplicatePart(selectedId);
return;
}
if ((event.key === "Delete" || event.key === "Backspace") && selectedId) {
event.preventDefault();
removePart(selectedId);
return;
}
const p = parts.find(item => item.id === selectedId);
if (!p || p.type === "strap") return;
const step = event.shiftKey ? .25 : .05;
let handled = true;
const before = snapshot();
if (event.key === "ArrowLeft") p.tx -= step;
else if (event.key === "ArrowRight") p.tx += step;
else if (event.key === "ArrowUp") p.ty += step;
else if (event.key === "ArrowDown") p.ty -= step;
else handled = false;
if (handled) {
event.preventDefault();
p.x = p.tx;
p.y = p.ty;
pushHistory(before);
afterMutation();
}
});
/* --------------------------------------------------------------------------
Feedback and rendering
--------------------------------------------------------------------------- */
let toastTimer;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 1800);
}
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(1, height);
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(viewport);
resize();
function animate() {
requestAnimationFrame(animate);
const lerp = .12;
cameraState.theta = THREE.MathUtils.lerp(cameraState.theta, cameraGoal.theta, lerp);
cameraState.phi = THREE.MathUtils.lerp(cameraState.phi, cameraGoal.phi, lerp);
cameraState.radius = THREE.MathUtils.lerp(cameraState.radius, cameraGoal.radius, lerp);
cameraState.target.lerp(cameraGoal.target, lerp);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
let contactsChanged = false;
for (const p of parts) {
const dx = p.tx - p.x;
const dy = p.ty - p.y;
if (Math.abs(dx) > .0005 || Math.abs(dy) > .0005) {
p.x += dx * .17;
p.y += dy * .17;
contactsChanged = true;
}
if (p.anchors) {
for (const anchor of p.anchors) {
const ax = anchor.tx - anchor.x;
const ay = anchor.ty - anchor.y;
if (Math.abs(ax) > .0005 || Math.abs(ay) > .0005) {
anchor.x += ax * .17;
anchor.y += ay * .17;
contactsChanged = true;
}
}
}
const age = performance.now() - p.spawn;
const scale = age < 330 ? THREE.MathUtils.smoothstep(age / 330, 0, 1) : 1;
p.group.scale.setScalar(scale);
updatePartTransform(p);
if (p.type === "loop") {
const overlapsHook = parts.some(item => {
if (item.type !== "hook") return false;
const d = dimensions(item);
return !!rectOverlap(
{ x: p.x, y: p.y, w: dimensions(p).w, h: dimensions(p).h },
{ x: item.x, y: item.y, w: d.w, h: d.h }
);
});
p.group.position.z = overlapsHook ? .29 : .17;
}
}
if (contactsChanged) {
const contacts = computeContacts();
renderContactOverlays(contacts);
updateContactUI(contacts);
}
renderer.render(scene, camera);
}
/* --------------------------------------------------------------------------
Start
--------------------------------------------------------------------------- */
loadSlot("A", false);
updateHistoryButtons();
animate();
requestAnimationFrame(() => {
document.getElementById("loading").remove();
showToast("Drag a module onto the board to begin");
});
</script>
</body>
</html>
```