Prompt specification
Build or customize the Three.js 3D scene "Shared Workbench Time Negotiation" 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: Shared Workbench Time Negotiation
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shared-workbench-time-negotiation-x3166
Scene Description Prompt:
Shared workbench time negotiation. Show two makers requesting overlapping use of one bench. Move schedule blocks until a feasible agreement appears, keeping each maker's stated time constraints visible. Please build this with Three.js from cdnjs in one self-contained HTML file, using stylized solid shapes.
Working Three.js Starter (shared-workbench-time-negotiation-x3166):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Shared Workbench — Time Negotiation</title>
<style>
:root {
--ink: #26312f;
--muted: #66706c;
--paper: #f3efe7;
--card: rgba(255, 253, 248, 0.92);
--mara: #dc673b;
--mara-soft: #f8e1d6;
--noah: #3977c9;
--noah-soft: #dce8f8;
--green: #258661;
--green-soft: #dff2e8;
--red: #c74b45;
--line: rgba(38, 49, 47, 0.13);
--shadow: 0 18px 55px rgba(61, 52, 40, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.masthead {
position: fixed;
top: 24px;
left: 26px;
z-index: 5;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--green);
box-shadow: 0 0 0 4px rgba(37, 134, 97, 0.11);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 1;
}
.subtitle {
margin-top: 9px;
color: var(--muted);
font-size: 13px;
}
.status {
position: fixed;
top: 26px;
left: 50%;
z-index: 8;
min-width: 148px;
padding: 10px 15px;
border: 1px solid rgba(199, 75, 69, 0.2);
border-radius: 999px;
background: rgba(255, 247, 245, 0.92);
box-shadow: 0 8px 28px rgba(67, 46, 40, 0.08);
color: var(--red);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.09em;
text-align: center;
text-transform: uppercase;
transform: translateX(-50%);
transition:
color 180ms ease,
background 180ms ease,
border-color 180ms ease;
pointer-events: none;
}
.status.valid {
border-color: rgba(37, 134, 97, 0.2);
background: rgba(244, 252, 247, 0.94);
color: var(--green);
}
.status.agreed {
border-color: rgba(37, 134, 97, 0.28);
background: var(--green-soft);
color: var(--green);
}
.request-card {
position: fixed;
top: 126px;
z-index: 6;
width: 258px;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 20px;
background: var(--card);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.request-card.mara {
left: 26px;
}
.request-card.noah {
right: 26px;
}
.maker-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 15px;
}
.maker-name {
display: flex;
align-items: center;
gap: 10px;
}
.maker-dot {
width: 12px;
height: 12px;
flex: 0 0 auto;
border-radius: 4px;
background: var(--maker);
box-shadow: 0 0 0 5px var(--maker-soft);
}
.mara {
--maker: var(--mara);
--maker-soft: var(--mara-soft);
}
.noah {
--maker: var(--noah);
--maker-soft: var(--noah-soft);
}
.maker-name strong {
display: block;
font-size: 16px;
letter-spacing: -0.02em;
}
.maker-name small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.duration {
padding: 6px 8px;
border-radius: 8px;
background: var(--maker-soft);
color: var(--maker);
font-size: 10px;
font-weight: 850;
white-space: nowrap;
}
.current-time {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
padding: 13px 0 12px;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.current-time span:first-child {
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#time-a,
#time-b {
font-size: 20px;
font-weight: 780;
letter-spacing: -0.035em;
}
.constraint-title {
margin: 15px 0 9px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.constraint {
display: flex;
align-items: center;
gap: 8px;
margin-top: 6px;
color: #4e5955;
font-size: 12px;
}
.constraint::before {
width: 6px;
height: 6px;
flex: 0 0 auto;
border: 2px solid var(--maker);
border-radius: 50%;
content: "";
}
.mini-track {
position: relative;
height: 35px;
margin-top: 10px;
border-radius: 9px;
background:
repeating-linear-gradient(
90deg,
rgba(38, 49, 47, 0.12) 0,
rgba(38, 49, 47, 0.12) 1px,
transparent 1px,
transparent 12.5%
),
rgba(38, 49, 47, 0.035);
overflow: hidden;
}
.allowed-window,
.request-window {
position: absolute;
top: 0;
bottom: 0;
}
.allowed-window {
background: var(--maker-soft);
}
.request-window {
top: 9px;
bottom: 9px;
border-radius: 5px;
background: var(--maker);
box-shadow: 0 3px 8px color-mix(in srgb, var(--maker) 30%, transparent);
transition:
left 100ms ease,
width 100ms ease;
}
.mini-labels {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: #87908c;
font-size: 9px;
font-weight: 700;
}
.request-state {
min-height: 17px;
margin-top: 12px;
color: var(--green);
font-size: 11px;
font-weight: 760;
}
.request-state.bad {
color: var(--red);
}
.nudges {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 9px;
}
.nudges button {
min-height: 35px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.7);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition:
transform 120ms ease,
border-color 120ms ease,
background 120ms ease;
}
.nudges button:hover {
border-color: var(--maker);
background: var(--maker-soft);
transform: translateY(-1px);
}
.nudges button:active {
transform: translateY(1px);
}
.nudges button:focus-visible,
#reset:focus-visible {
outline: 3px solid color-mix(in srgb, var(--maker) 30%, transparent);
outline-offset: 2px;
}
.agreement {
position: fixed;
top: 87px;
left: 50%;
z-index: 9;
width: min(430px, calc(100vw - 32px));
padding: 14px 18px;
border: 1px solid rgba(37, 134, 97, 0.25);
border-radius: 16px;
background: rgba(239, 250, 244, 0.95);
box-shadow: 0 14px 42px rgba(37, 99, 75, 0.16);
opacity: 0;
transform: translate(-50%, -14px);
transition:
opacity 300ms ease,
transform 300ms ease;
pointer-events: none;
}
.agreement.show {
opacity: 1;
transform: translate(-50%, 0);
}
.agreement strong {
display: block;
color: var(--green);
font-size: 14px;
}
.agreement span {
display: block;
margin-top: 3px;
color: #4f7163;
font-size: 12px;
}
.dock {
position: fixed;
right: 26px;
bottom: 22px;
left: 26px;
z-index: 7;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.instructions {
display: flex;
align-items: center;
gap: 13px;
max-width: calc(100vw - 190px);
padding: 10px 14px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 13px;
background: rgba(255, 253, 248, 0.82);
box-shadow: 0 8px 28px rgba(61, 52, 40, 0.08);
color: var(--muted);
font-size: 11px;
backdrop-filter: blur(12px);
}
.instructions b {
color: var(--ink);
font-weight: 750;
}
.legend {
display: flex;
gap: 12px;
white-space: nowrap;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--swatch);
}
#reset {
flex: 0 0 auto;
min-height: 42px;
padding: 0 17px;
border: 1px solid rgba(38, 49, 47, 0.15);
border-radius: 12px;
background: var(--ink);
box-shadow: 0 8px 24px rgba(38, 49, 47, 0.18);
color: white;
cursor: pointer;
font-size: 11px;
font-weight: 800;
pointer-events: auto;
transition:
transform 120ms ease,
background 120ms ease;
}
#reset:hover {
background: #35423f;
transform: translateY(-1px);
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--paper);
color: var(--muted);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
.loading.hide {
opacity: 0;
pointer-events: none;
}
@media (max-width: 980px) {
.request-card {
width: 225px;
padding: 15px;
}
.request-card.mara {
left: 16px;
}
.request-card.noah {
right: 16px;
}
.masthead {
left: 18px;
}
.status {
top: 105px;
}
.agreement {
top: 153px;
}
.instructions .legend {
display: none;
}
}
@media (max-width: 700px) {
.masthead {
top: 17px;
left: 17px;
}
.subtitle {
display: none;
}
.request-card {
top: auto;
bottom: 78px;
width: calc(50% - 21px);
padding: 12px;
border-radius: 16px;
}
.request-card.mara {
left: 12px;
}
.request-card.noah {
right: 12px;
}
.maker-head {
margin-bottom: 10px;
}
.maker-name small,
.constraint-title,
.constraint,
.mini-track,
.mini-labels,
.duration {
display: none;
}
.current-time {
padding: 9px 0;
}
.current-time span:first-child {
font-size: 9px;
}
#time-a,
#time-b {
font-size: 16px;
}
.request-state {
min-height: 28px;
margin-top: 7px;
font-size: 9px;
}
.nudges {
gap: 5px;
margin-top: 5px;
}
.nudges button {
min-height: 30px;
padding: 0 5px;
font-size: 9px;
}
.status {
top: 72px;
min-width: 132px;
padding: 8px 12px;
font-size: 9px;
}
.agreement {
top: 112px;
padding: 10px 13px;
}
.agreement strong {
font-size: 12px;
}
.agreement span {
font-size: 10px;
}
.dock {
right: 12px;
bottom: 12px;
left: 12px;
gap: 8px;
}
.instructions {
max-width: none;
flex: 1;
padding: 9px 10px;
font-size: 9px;
}
.instructions .desktop-hint {
display: none;
}
#reset {
min-height: 38px;
padding: 0 12px;
font-size: 10px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive 3D schedule for two makers sharing one workbench. Drag the colored request blocks along the timeline."
></canvas>
<header class="masthead">
<div class="eyebrow">Shared workbench</div>
<h1>Find a fair handoff.</h1>
<div class="subtitle">Two makers. One bench. A schedule that works for both.</div>
</header>
<div id="status" class="status" aria-live="polite">Checking schedule</div>
<section class="request-card mara" aria-labelledby="mara-name">
<div class="maker-head">
<div class="maker-name">
<i class="maker-dot"></i>
<div>
<strong id="mara-name">Mara</strong>
<small>Maker 01</small>
</div>
</div>
<div class="duration">3 hours</div>
</div>
<div class="current-time">
<span>Requested</span>
<strong id="time-a">10:00–13:00</strong>
</div>
<div class="constraint-title">Stated constraints</div>
<div class="constraint">Start no earlier than 10:00</div>
<div class="constraint">Finish by 14:00</div>
<div class="mini-track" aria-hidden="true">
<div class="allowed-window" style="left:12.5%;width:50%"></div>
<div id="segment-a" class="request-window" style="left:12.5%;width:37.5%"></div>
</div>
<div class="mini-labels" aria-hidden="true">
<span>9 AM</span>
<span>5 PM</span>
</div>
<div id="request-state-a" class="request-state" aria-live="polite"></div>
<div class="nudges" aria-label="Move Mara's request">
<button type="button" data-maker="a" data-direction="-1">← 30 min</button>
<button type="button" data-maker="a" data-direction="1">30 min →</button>
</div>
</section>
<section class="request-card noah" aria-labelledby="noah-name">
<div class="maker-head">
<div class="maker-name">
<i class="maker-dot"></i>
<div>
<strong id="noah-name">Noah</strong>
<small>Maker 02</small>
</div>
</div>
<div class="duration">3 hours</div>
</div>
<div class="current-time">
<span>Requested</span>
<strong id="time-b">12:00–15:00</strong>
</div>
<div class="constraint-title">Stated constraints</div>
<div class="constraint">Start no earlier than 12:00</div>
<div class="constraint">Finish by 16:00</div>
<div class="mini-track" aria-hidden="true">
<div class="allowed-window" style="left:37.5%;width:50%"></div>
<div id="segment-b" class="request-window" style="left:37.5%;width:37.5%"></div>
</div>
<div class="mini-labels" aria-hidden="true">
<span>9 AM</span>
<span>5 PM</span>
</div>
<div id="request-state-b" class="request-state" aria-live="polite"></div>
<div class="nudges" aria-label="Move Noah's request">
<button type="button" data-maker="b" data-direction="-1">← 30 min</button>
<button type="button" data-maker="b" data-direction="1">30 min →</button>
</div>
</section>
<div id="agreement" class="agreement" aria-live="polite">
<strong>Agreement reached — the bench is covered.</strong>
<span id="agreement-detail"></span>
</div>
<div class="dock">
<div class="instructions">
<span><b>Drag</b> a colored block along the bench</span>
<span class="desktop-hint">·</span>
<span class="desktop-hint"><b>Drag background</b> to orbit</span>
<span class="desktop-hint">·</span>
<span class="desktop-hint"><b>Scroll</b> to zoom</span>
</div>
<button id="reset" type="button">Reset overlap</button>
</div>
<div id="loading" class="loading">Preparing the workbench…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.04;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf0ece4);
scene.fog = new THREE.Fog(0xf0ece4, 22, 43);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
const cameraState = {
theta: 0.43,
phi: 0.78,
radius: 18.2
};
function updateCamera() {
const { theta, phi, radius } = cameraState;
const horizontal = Math.sin(phi) * radius;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(theta),
cameraTarget.y + Math.cos(phi) * radius,
cameraTarget.z + horizontal * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff8eb, 0x81796e, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d9, 3.4);
sun.position.set(-7, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xcbdfff, 0.75);
fill.position.set(10, 6, -8);
scene.add(fill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xe7e1d7,
roughness: 0.96,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const floorInset = new THREE.Mesh(
new THREE.CircleGeometry(8.8, 64),
new THREE.MeshStandardMaterial({
color: 0xeee8df,
roughness: 1
})
);
floorInset.rotation.x = -Math.PI / 2;
floorInset.position.y = -0.005;
floorInset.receiveShadow = true;
scene.add(floorInset);
const wood = new THREE.MeshStandardMaterial({
color: 0xb98250,
roughness: 0.78,
metalness: 0.02
});
const darkWood = new THREE.MeshStandardMaterial({
color: 0x795238,
roughness: 0.88
});
const benchTop = new THREE.Mesh(
new THREE.BoxGeometry(13.4, 0.42, 5.4),
wood
);
benchTop.position.y = 1.29;
benchTop.castShadow = true;
benchTop.receiveShadow = true;
scene.add(benchTop);
const frontApron = new THREE.Mesh(
new THREE.BoxGeometry(12.7, 0.52, 0.28),
darkWood
);
frontApron.position.set(0, 0.98, 2.28);
frontApron.castShadow = true;
scene.add(frontApron);
const backApron = frontApron.clone();
backApron.position.z = -2.28;
scene.add(backApron);
for (const x of [-5.8, 5.8]) {
for (const z of [-2.0, 2.0]) {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.48, 1.15, 0.48),
darkWood
);
leg.position.set(x, 0.575, z);
leg.castShadow = true;
leg.receiveShadow = true;
scene.add(leg);
}
}
const lowerShelf = new THREE.Mesh(
new THREE.BoxGeometry(11.8, 0.22, 3.9),
wood
);
lowerShelf.position.set(0, 0.38, 0);
lowerShelf.castShadow = true;
lowerShelf.receiveShadow = true;
scene.add(lowerShelf);
const TIME_START = 9;
const TIME_END = 17;
const HOURS = TIME_END - TIME_START;
const SCALE = 1.5;
const DURATION = 3;
const SNAP = 0.5;
const BLOCK_Y = 1.82;
const schedule = {
a: {
name: "Mara",
start: 10,
end: 13,
minStart: 10,
maxEnd: 14,
color: 0xdc673b,
css: "#dc673b",
laneZ: -0.92
},
b: {
name: "Noah",
start: 12,
end: 15,
minStart: 12,
maxEnd: 16,
color: 0x3977c9,
css: "#3977c9",
laneZ: 0.92
}
};
function timeToX(time) {
return (time - 13) * SCALE;
}
function xToTime(x) {
return 13 + x / SCALE;
}
function formatHour(value) {
const hours = Math.floor(value);
const minutes = Math.round((value - hours) * 60);
const suffix = hours >= 12 ? "PM" : "AM";
const displayHour = hours % 12 || 12;
return `${displayHour}:${String(minutes).padStart(2, "0")} ${suffix}`;
}
function compactTime(value) {
const hours = Math.floor(value);
const minutes = Math.round((value - hours) * 60);
const suffix = hours >= 12 ? "PM" : "AM";
const displayHour = hours % 12 || 12;
return minutes
? `${displayHour}:${String(minutes).padStart(2, "0")} ${suffix}`
: `${displayHour} ${suffix}`;
}
function formatRange(request) {
return `${compactTime(request.start)}–${compactTime(request.end)}`;
}
function makeTexture(width, height, draw) {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = width;
textureCanvas.height = height;
const context = textureCanvas.getContext("2d");
draw(context, width, height);
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
texture.needsUpdate = true;
return texture;
}
function makeTimeTickTexture(text) {
return makeTexture(256, 96, (ctx, width, height) => {
ctx.clearRect(0, 0, width, height);
ctx.fillStyle = "#3f4946";
ctx.font = "700 48px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 2);
});
}
function makeBlockLabelTexture(request) {
return makeTexture(1024, 256, (ctx, width, height) => {
ctx.clearRect(0, 0, width, height);
ctx.fillStyle = "rgba(255,255,255,0.96)";
ctx.font = "850 66px system-ui, sans-serif";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText(request.name.toUpperCase(), 42, 70);
ctx.globalAlpha = 0.86;
ctx.font = "700 50px system-ui, sans-serif";
ctx.fillText(formatRange(request), 42, 164);
ctx.globalAlpha = 1;
});
}
function makeHorizontalLabel(texture, width, height) {
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
mesh.rotation.x = -Math.PI / 2;
mesh.renderOrder = 2;
return mesh;
}
const timelineRail = new THREE.Mesh(
new THREE.BoxGeometry(12.15, 0.035, 0.055),
new THREE.MeshStandardMaterial({
color: 0x725e4c,
roughness: 0.9
})
);
timelineRail.position.set(0, 1.52, 0);
timelineRail.receiveShadow = true;
scene.add(timelineRail);
const laneMaterials = {
a: new THREE.MeshStandardMaterial({
color: 0xd99172,
roughness: 0.9
}),
b: new THREE.MeshStandardMaterial({
color: 0x79a0d1,
roughness: 0.9
})
};
for (const key of ["a", "b"]) {
const lane = new THREE.Mesh(
new THREE.BoxGeometry(12.15, 0.026, 0.035),
laneMaterials[key]
);
lane.position.set(0, 1.525, schedule[key].laneZ);
scene.add(lane);
const request = schedule[key];
const allowedWidth =
(request.maxEnd - request.minStart) * SCALE;
const band = new THREE.Mesh(
new THREE.PlaneGeometry(allowedWidth, 0.52),
new THREE.MeshBasicMaterial({
color: request.color,
transparent: true,
opacity: 0.14,
depthWrite: false
})
);
band.rotation.x = -Math.PI / 2;
band.position.set(
timeToX((request.minStart + request.maxEnd) / 2),
1.515,
request.laneZ + Math.sign(request.laneZ) * 0.68
);
scene.add(band);
}
for (let hour = TIME_START; hour <= TIME_END; hour++) {
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 0.035, 0.28),
new THREE.MeshStandardMaterial({
color: 0x735f4c,
roughness: 0.95
})
);
tick.position.set(timeToX(hour), 1.525, 1.72);
scene.add(tick);
const label = makeHorizontalLabel(
makeTimeTickTexture(compactTime(hour)),
1.12,
0.42
);
label.position.set(timeToX(hour), 1.532, 2.18);
scene.add(label);
}
const blockGroups = {};
const pickMeshes = [];
function createBlock(key) {
const request = schedule[key];
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: request.color,
roughness: 0.64,
metalness: 0.02,
emissive: 0x000000,
emissiveIntensity: 0
});
const body = new THREE.Mesh(
new THREE.BoxGeometry(DURATION * SCALE, 0.6, 0.86),
bodyMaterial
);
body.castShadow = true;
body.receiveShadow = true;
body.userData.maker = key;
group.add(body);
pickMeshes.push(body);
const lowerTrim = new THREE.Mesh(
new THREE.BoxGeometry(DURATION * SCALE - 0.14, 0.08, 0.88),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.75,
transparent: true,
opacity: 0.18
})
);
lowerTrim.position.y = -0.24;
group.add(lowerTrim);
const label = makeHorizontalLabel(
makeBlockLabelTexture(request),
4.05,
1.01
);
label.position.y = 0.314;
group.add(label);
group.position.set(
timeToX((request.start + request.end) / 2),
BLOCK_Y,
request.laneZ
);
scene.add(group);
blockGroups[key] = { group, body, label };
}
createBlock("a");
createBlock("b");
const conflictGroup = new THREE.Group();
scene.add(conflictGroup);
const conflictMaterial = new THREE.MeshBasicMaterial({
color: 0xd95750,
transparent: true,
opacity: 0.22,
depthWrite: false
});
const conflictPanel = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.92, 0.05),
conflictMaterial
);
conflictPanel.position.y = 1.99;
conflictGroup.add(conflictPanel);
const conflictTop = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.075, 0.09),
new THREE.MeshStandardMaterial({
color: 0xd95750,
roughness: 0.65
})
);
conflictTop.position.y = 2.47;
conflictGroup.add(conflictTop);
const agreementGroup = new THREE.Group();
agreementGroup.position.set(0, 3.05, -1.55);
agreementGroup.visible = false;
scene.add(agreementGroup);
const agreementRing = new THREE.Mesh(
new THREE.TorusGeometry(0.54, 0.075, 12, 48),
new THREE.MeshStandardMaterial({
color: 0x258661,
roughness: 0.48
})
);
agreementRing.castShadow = true;
agreementGroup.add(agreementRing);
const checkTexture = makeTexture(256, 256, (ctx, width, height) => {
ctx.clearRect(0, 0, width, height);
ctx.fillStyle = "#258661";
ctx.beginPath();
ctx.arc(width / 2, height / 2, 104, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = "white";
ctx.lineWidth = 23;
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.beginPath();
ctx.moveTo(65, 132);
ctx.lineTo(112, 178);
ctx.lineTo(194, 82);
ctx.stroke();
});
const checkSprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: checkTexture,
transparent: true,
depthTest: false,
toneMapped: false
})
);
checkSprite.scale.set(1.18, 1.18, 1);
checkSprite.renderOrder = 10;
agreementGroup.add(checkSprite);
const statusElement = document.querySelector("#status");
const agreementElement = document.querySelector("#agreement");
const agreementDetail = document.querySelector("#agreement-detail");
function withinWindow(request) {
return (
request.start >= request.minStart - 0.001 &&
request.end <= request.maxEnd + 0.001
);
}
function getOverlap() {
const start = Math.max(schedule.a.start, schedule.b.start);
const end = Math.min(schedule.a.end, schedule.b.end);
return {
start,
end,
duration: Math.max(0, end - start)
};
}
function updateBlockVisual(key) {
const request = schedule[key];
const visual = blockGroups[key];
visual.group.position.x = timeToX((request.start + request.end) / 2);
const oldTexture = visual.label.material.map;
visual.label.material.map = makeBlockLabelTexture(request);
visual.label.material.needsUpdate = true;
oldTexture.dispose();
const valid = withinWindow(request);
const overlap = getOverlap();
if (!valid) {
visual.body.material.emissive.setHex(0xb73535);
visual.body.material.emissiveIntensity = 0.16;
} else if (
overlap.duration > 0 &&
request.start < overlap.end &&
request.end > overlap.start
) {
visual.body.material.emissive.setHex(0xd95750);
visual.body.material.emissiveIntensity = 0.1;
} else {
visual.body.material.emissive.setHex(0x258661);
visual.body.material.emissiveIntensity = 0.025;
}
}
function updateConflictVisual() {
const overlap = getOverlap();
if (overlap.duration > 0.001) {
const width = overlap.duration * SCALE;
const center = timeToX((overlap.start + overlap.end) / 2);
conflictGroup.visible = true;
conflictGroup.position.x = center;
conflictPanel.scale.x = width;
conflictTop.scale.x = width;
} else {
conflictGroup.visible = false;
}
}
function updateUI() {
const overlap = getOverlap();
const aValid = withinWindow(schedule.a);
const bValid = withinWindow(schedule.b);
const agreed = overlap.duration <= 0.001 && aValid && bValid;
for (const key of ["a", "b"]) {
const request = schedule[key];
const valid = withinWindow(request);
document.querySelector(`#time-${key}`).textContent = formatRange(request);
const segment = document.querySelector(`#segment-${key}`);
segment.style.left =
`${((request.start - TIME_START) / HOURS) * 100}%`;
segment.style.width = `${(DURATION / HOURS) * 100}%`;
const requestState = document.querySelector(`#request-state-${key}`);
requestState.classList.toggle("bad", !valid);
if (!valid) {
requestState.textContent = "Outside the stated window";
} else if (
overlap.duration > 0 &&
request.start < overlap.end &&
request.end > overlap.start
) {
requestState.textContent =
key === "a" ? "Overlaps Noah" : "Overlaps Mara";
} else {
requestState.textContent = "Inside the stated window";
}
}
statusElement.classList.remove("valid", "agreed");
if (agreed) {
statusElement.textContent = "Agreement reached";
statusElement.classList.add("agreed");
agreementElement.classList.add("show");
agreementDetail.textContent =
`${schedule.a.name}: ${formatRange(schedule.a)} · ` +
`${schedule.b.name}: ${formatRange(schedule.b)}`;
} else {
agreementElement.classList.remove("show");
if (overlap.duration > 0.001) {
const minutes = Math.round(overlap.duration * 60);
statusElement.textContent = `${minutes / 60} hour overlap`;
statusElement.classList.add("valid");
} else if (!aValid || !bValid) {
statusElement.textContent = "Outside a stated window";
statusElement.classList.add("valid");
} else {
statusElement.textContent = "No overlap";
statusElement.classList.add("valid");
}
}
}
function updateSchedule() {
updateBlockVisual("a");
updateBlockVisual("b");
updateConflictVisual();
updateUI();
}
function setStart(key, start) {
const request = schedule[key];
request.start = Math.round(start / SNAP) * SNAP;
request.start = THREE.MathUtils.clamp(
request.start,
TIME_START,
TIME_END - DURATION
);
request.end = request.start + DURATION;
updateSchedule();
}
function nudge(key, direction) {
setStart(key, schedule[key].start + direction * 0.5);
}
document.querySelectorAll("[data-maker]").forEach((button) => {
button.addEventListener("click", () => {
nudge(button.dataset.maker, Number(button.dataset.direction));
});
});
document.querySelector("#reset").addEventListener("click", () => {
setStart("a", 10);
setStart("b", 12);
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(
new THREE.Vector3(0, 1, 0),
-BLOCK_Y
);
const planeHit = new THREE.Vector3();
let draggedMaker = null;
let dragOffset = 0;
let orbiting = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
canvas.addEventListener("pointerdown", (event) => {
updatePointer(event);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (event.button === 0) {
const hits = raycaster.intersectObjects(pickMeshes, false);
if (hits.length) {
draggedMaker = hits[0].object.userData.maker;
if (raycaster.ray.intersectPlane(dragPlane, planeHit)) {
dragOffset =
blockGroups[draggedMaker].group.position.x - planeHit.x;
} else {
dragOffset = 0;
}
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
event.preventDefault();
return;
}
}
orbiting = true;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
updatePointer(event);
if (draggedMaker) {
if (raycaster.ray.intersectPlane(dragPlane, planeHit)) {
const desiredX = planeHit.x + dragOffset;
const desiredCenterTime = xToTime(desiredX);
const desiredStart = desiredCenterTime - DURATION / 2;
setStart(draggedMaker, desiredStart);
}
return;
}
if (orbiting) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.43,
1.12
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
}
});
function endPointerInteraction(event) {
draggedMaker = null;
orbiting = false;
canvas.style.cursor = "default";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointerInteraction);
canvas.addEventListener("pointercancel", endPointerInteraction);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
12.5,
24
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("pointermove", (event) => {
if (draggedMaker || orbiting) return;
updatePointer(event);
const hovering = raycaster.intersectObjects(pickMeshes, false).length > 0;
canvas.style.cursor = hovering ? "grab" : "default";
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateSchedule();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
if (conflictGroup.visible) {
conflictMaterial.opacity = 0.18 + Math.sin(elapsed * 3.2) * 0.045;
}
agreementGroup.quaternion.copy(camera.quaternion);
const pulse = 1 + Math.sin(elapsed * 2.8) * 0.035;
agreementGroup.scale.setScalar(pulse);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hide");
});
</script>
</body>
</html>
```