Prompt specification
Build or customize the Three.js 3D scene "Dependency-aware scheduling explorer" 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: Dependency-aware scheduling explorer
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/dependency-aware-scheduling-explorer-x1904
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts task scheduling with dependencies. Let users rearrange a small valid schedule and vary resource count; reject precedence violations and compare completion time with a known optimum for the bounded instance. Low-poly.
Working Three.js Starter (dependency-aware-scheduling-explorer-x1904):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Dependency Lab — Task Scheduling</title>
<style>
:root {
--ink: #173638;
--muted: #627476;
--paper: rgba(248, 247, 239, 0.92);
--paper-strong: rgba(255, 255, 250, 0.97);
--line: rgba(23, 54, 56, 0.14);
--green: #21866f;
--red: #c64d49;
--gold: #d69d2d;
--shadow: 0 18px 45px rgba(25, 55, 55, 0.14);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce7e2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100vw;
height: 100vh;
touch-action: none;
outline: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
pointer-events: auto;
border: 1px solid rgba(255, 255, 255, 0.72);
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(1.15);
-webkit-backdrop-filter: blur(16px) saturate(1.15);
}
.brand {
top: 20px;
left: 20px;
width: 330px;
padding: 17px 18px 16px;
border-radius: 18px;
}
.eyebrow {
margin: 0 0 5px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 23px;
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.controls {
top: 164px;
left: 20px;
width: 330px;
padding: 16px;
border-radius: 18px;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.section-title small {
color: var(--muted);
font-size: 9px;
font-weight: 650;
letter-spacing: 0;
text-transform: none;
}
.resource-row {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-bottom: 13px;
}
.resource-button {
height: 39px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255,255,255,0.55);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 800;
transition: transform 140ms ease, background 140ms ease, color 140ms ease;
}
.resource-button:hover {
transform: translateY(-1px);
background: white;
}
.resource-button.active {
border-color: var(--ink);
background: var(--ink);
color: #fff;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.action {
min-height: 39px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255,255,255,0.62);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 800;
transition: transform 140ms ease, background 140ms ease;
}
.action:hover {
transform: translateY(-1px);
background: white;
}
.action.primary {
border-color: rgba(33, 134, 111, 0.25);
background: #dcefe8;
color: #176552;
}
.action.full {
grid-column: 1 / -1;
}
.validation {
min-height: 38px;
margin-top: 12px;
padding: 9px 10px;
border-radius: 10px;
background: rgba(33, 134, 111, 0.09);
color: var(--green);
font-size: 10px;
font-weight: 720;
line-height: 1.35;
}
.validation.invalid {
background: rgba(198, 77, 73, 0.1);
color: var(--red);
}
.metrics {
top: 20px;
right: 20px;
width: 282px;
padding: 17px;
border-radius: 18px;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 10px;
}
.metric {
min-height: 83px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255,255,255,0.48);
}
.metric-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-value {
margin-top: 3px;
font-size: 30px;
font-weight: 850;
line-height: 1;
letter-spacing: -0.06em;
}
.metric-value span {
margin-left: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0;
}
.gap-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 10px;
font-size: 11px;
font-weight: 750;
}
.gap-pill {
padding: 5px 8px;
border-radius: 999px;
background: rgba(214, 157, 45, 0.13);
color: #976713;
}
.gap-pill.optimal {
background: rgba(33, 134, 111, 0.12);
color: var(--green);
}
.bar-chart {
display: grid;
gap: 7px;
margin-top: 13px;
}
.bar-line {
display: grid;
grid-template-columns: 54px 1fr 25px;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
}
.bar-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(23,54,56,0.08);
}
.bar-fill {
height: 100%;
border-radius: inherit;
background: var(--gold);
transition: width 240ms ease;
}
.bar-fill.optimum {
background: var(--green);
}
.proof {
margin: 13px 0 0;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.proof strong {
color: var(--ink);
}
.task-panel {
right: 20px;
bottom: 20px;
width: 282px;
min-height: 184px;
padding: 16px;
border-radius: 18px;
}
.task-heading {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 11px;
}
.task-chip {
display: grid;
width: 38px;
height: 38px;
place-items: center;
border-radius: 11px;
color: white;
font-size: 15px;
font-weight: 900;
box-shadow: inset 0 -5px 10px rgba(0,0,0,0.08);
}
.task-name {
font-size: 16px;
font-weight: 850;
letter-spacing: -0.02em;
}
.task-meta {
color: var(--muted);
font-size: 10px;
font-weight: 650;
}
.detail-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-bottom: 10px;
}
.detail {
padding: 8px;
border-radius: 9px;
background: rgba(23,54,56,0.055);
}
.detail-label {
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.detail-value {
margin-top: 3px;
font-size: 11px;
font-weight: 800;
}
.dependency-line {
margin-top: 6px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.dependency-line strong {
color: var(--ink);
}
.hint {
position: absolute;
bottom: 20px;
left: 20px;
padding: 10px 13px;
border: 1px solid rgba(255,255,255,0.7);
border-radius: 999px;
background: rgba(248,247,239,0.83);
box-shadow: 0 10px 28px rgba(25,55,55,0.1);
color: var(--muted);
font-size: 10px;
font-weight: 700;
backdrop-filter: blur(12px);
}
.hint b { color: var(--ink); }
#toast {
position: absolute;
left: 50%;
bottom: 24px;
max-width: min(460px, calc(100vw - 40px));
padding: 11px 15px;
border-radius: 999px;
background: #173638;
box-shadow: 0 14px 40px rgba(23,54,56,0.24);
color: white;
font-size: 11px;
font-weight: 700;
text-align: center;
opacity: 0;
transform: translate(-50%, 12px);
transition: opacity 180ms ease, transform 180ms ease;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
#toast.error {
background: #a8413e;
}
@media (max-width: 820px) {
.brand {
top: 10px;
left: 10px;
width: calc(100% - 20px);
padding: 13px 15px;
}
h1 { font-size: 20px; }
.subtitle { display: none; }
.controls {
top: 91px;
left: 10px;
width: 225px;
padding: 12px;
}
.metrics {
top: 91px;
right: 10px;
width: 225px;
padding: 12px;
}
.metric { min-height: 68px; padding: 8px; }
.metric-value { font-size: 24px; }
.proof { display: none; }
.task-panel {
right: 10px;
bottom: 10px;
width: 225px;
min-height: 150px;
padding: 12px;
}
.hint { display: none; }
#toast { bottom: 12px; }
}
@media (max-width: 520px) {
.controls {
top: 86px;
width: calc(100% - 20px);
}
.metrics {
top: auto;
right: 10px;
bottom: 10px;
width: calc(100% - 20px);
}
.task-panel { display: none; }
.metric-grid { margin-top: 7px; }
.metric { min-height: 60px; }
.bar-chart { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional task scheduling board"></canvas>
<div id="hud">
<section class="panel brand">
<p class="eyebrow">Dependency Lab / Bounded Instance</p>
<h1>Workshop Flow</h1>
<p class="subtitle">
Rearrange the nine tasks, choose the number of workers, and compare the
resulting makespan against the certified optimum.
</p>
</section>
<section class="panel controls">
<div class="section-title">
<span>Workers</span>
<small>Changing count resets the board</small>
</div>
<div class="resource-row" id="resourceButtons">
<button class="resource-button" data-resource="1">1</button>
<button class="resource-button" data-resource="2">2</button>
<button class="resource-button active" data-resource="3">3</button>
<button class="resource-button" data-resource="4">4</button>
</div>
<div class="button-row">
<button id="optimalButton" class="action primary">Use optimum</button>
<button id="resetButton" class="action">Reset schedule</button>
<button id="cameraButton" class="action full">Recenter camera</button>
</div>
<div id="validation" class="validation">
Schedule valid. All precedence and capacity constraints are satisfied.
</div>
</section>
<section class="panel metrics">
<div class="section-title">
<span>Completion time</span>
<small>Time units</small>
</div>
<div class="metric-grid">
<div class="metric">
<div class="metric-label">Current</div>
<div class="metric-value" id="currentValue">9<span>slots</span></div>
</div>
<div class="metric">
<div class="metric-label">Optimum</div>
<div class="metric-value" id="optimumValue">8<span>slots</span></div>
</div>
</div>
<div class="gap-row">
<span id="scheduleStatus">One slot above optimum</span>
<span id="gapValue" class="gap-pill">+1</span>
</div>
<div class="bar-chart">
<div class="bar-line">
<span>Current</span>
<div class="bar-track"><div id="currentBar" class="bar-fill"></div></div>
<span id="currentBarValue">9</span>
</div>
<div class="bar-line">
<span>Optimum</span>
<div class="bar-track"><div id="optimumBar" class="bar-fill optimum"></div></div>
<span id="optimumBarValue">8</span>
</div>
</div>
<p class="proof" id="proof"></p>
</section>
<section class="panel task-panel">
<div class="task-heading">
<div id="taskChip" class="task-chip">A</div>
<div>
<div id="taskName" class="task-name">Kickoff</div>
<div id="taskMeta" class="task-meta"></div>
</div>
</div>
<div class="detail-grid">
<div class="detail">
<div class="detail-label">Start / finish</div>
<div id="taskTime" class="detail-value"></div>
</div>
<div class="detail">
<div class="detail-label">Worker</div>
<div id="taskResource" class="detail-value"></div>
</div>
</div>
<div id="taskDependencies" class="dependency-line"></div>
<div id="taskSuccessors" class="dependency-line"></div>
</section>
<div class="hint">
<b>Drag</b> a task · <b>drag empty space</b> to orbit · <b>scroll</b> to zoom · <b>1–4</b> workers
</div>
<div id="toast" role="status" aria-live="polite"></div>
</div>
<noscript>This scene requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Bounded scheduling instance
// -------------------------------------------------------------------------
const TASK_DEFS = [
{ id: "A", name: "Kickoff", duration: 3, deps: [], color: 0xf08a5d },
{ id: "B", name: "Draft", duration: 2, deps: [], color: 0x5b8ff9 },
{ id: "C", name: "Research", duration: 4, deps: [], color: 0x9b6dd7 },
{ id: "D", name: "Prototype",duration: 3, deps: ["A"], color: 0x2a9d8f },
{ id: "E", name: "Quality", duration: 2, deps: ["A"], color: 0xe9c46a },
{ id: "F", name: "Integrate",duration: 2, deps: ["B","C"],color: 0xe76f9a },
{ id: "G", name: "Review", duration: 1, deps: ["D","E"],color: 0x66c7a5 },
{ id: "H", name: "Handoff", duration: 1, deps: ["F"], color: 0xf4a261 },
{ id: "I", name: "Release", duration: 1, deps: ["G","H"],color: 0xdde8df }
];
const DEPENDENCY_EDGES = [];
for (const task of TASK_DEFS) {
for (const dep of task.deps) DEPENDENCY_EDGES.push([dep, task.id]);
}
const rowsToSchedule = rows =>
Object.fromEntries(rows.map(([id, start, resource]) => [id, { start, resource }]));
// All initial schedules are feasible and deliberately one slot above the
// corresponding exact optimum.
const INITIAL_SCHEDULES = {
1: rowsToSchedule([
["A",0,0], ["B",3,0], ["C",6,0], ["D",10,0], ["E",13,0],
["F",15,0], ["G",17,0], ["H",18,0], ["I",19,0]
]),
2: rowsToSchedule([
["A",0,0], ["D",3,0], ["E",6,0], ["G",8,0], ["I",10,0],
["C",0,1], ["B",4,1], ["F",6,1], ["H",9,1]
]),
3: rowsToSchedule([
["A",0,0], ["D",3,0], ["G",6,0], ["I",8,0],
["C",0,1], ["E",4,1],
["B",0,2], ["F",5,2], ["H",7,2]
]),
4: rowsToSchedule([
["A",0,0], ["D",3,0], ["G",6,0], ["I",8,0],
["C",0,1], ["E",4,1],
["B",0,2],
["F",5,3], ["H",7,3]
])
};
const OPTIMAL_SCHEDULES = {
1: rowsToSchedule([
["A",0,0], ["B",3,0], ["C",5,0], ["D",9,0], ["E",12,0],
["F",14,0], ["G",16,0], ["H",17,0], ["I",18,0]
]),
2: rowsToSchedule([
["A",0,0], ["D",3,0], ["E",6,0], ["G",8,0], ["I",9,0],
["C",0,1], ["B",4,1], ["F",6,1], ["H",8,1]
]),
3: rowsToSchedule([
["A",0,0], ["D",3,0], ["G",6,0], ["I",7,0],
["C",0,1], ["E",4,1],
["B",0,2], ["F",4,2], ["H",6,2]
]),
4: rowsToSchedule([
["A",0,0], ["D",3,0], ["G",6,0], ["I",7,0],
["C",0,1], ["E",4,1],
["B",0,2],
["F",4,3], ["H",6,3]
])
};
/*
Exact optima for this fixed nine-task instance:
r=1: 19. Total work is 19, and a feasible serial schedule attains it.
r=2: 10. Work lower bound ceil(19/2)=10, and a feasible schedule attains it.
r=3: 8. Critical path C→F→H→I has length 8, and a schedule attains it.
r=4: 8. The same critical-path lower bound applies, and it is attainable.
*/
const KNOWN_OPTIMA = { 1: 19, 2: 10, 3: 8, 4: 8 };
const PROOFS = {
1: "<strong>Certified:</strong> total work is 19, so one worker needs at least 19; the displayed optimum is attainable.",
2: "<strong>Certified:</strong> total work is 19, giving a lower bound of ceil(19/2) = 10; the optimum is attainable.",
3: "<strong>Certified:</strong> the critical path C → F → H → I has length 8; a feasible schedule attains that bound.",
4: "<strong>Certified:</strong> the critical path C → F → H → I has length 8; a feasible schedule attains that bound."
};
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const $ = id => document.getElementById(id);
const canvas = $("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce7e2);
scene.fog = new THREE.Fog(0xdce7e2, 28, 57);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
target: new THREE.Vector3(9.7, 0.1, 0),
radius: window.innerWidth < 800 ? 34 : 29,
theta: 0.30,
phi: 0.68
};
function updateCamera() {
const { radius, theta, phi, target } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf7fff5, 0x68807a, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d6, 3.2);
sun.position.set(5, 18, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x8dc7d0, 1.1);
rim.position.set(-10, 8, -12);
scene.add(rim);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
new THREE.MeshStandardMaterial({
color: 0xd7e3dd,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.34;
floor.receiveShadow = true;
scene.add(floor);
const boardGroup = new THREE.Group();
const taskGroup = new THREE.Group();
const dependencyGroup = new THREE.Group();
scene.add(boardGroup, taskGroup, dependencyGroup);
const UNIT = 1.05;
const LANE = 2.4;
const HORIZON = 20;
const BOARD_X_MIN = -1.2;
const BOARD_X_MAX = 21.2;
let resourceCount = 3;
let boardDepth = resourceCount * LANE + 0.7;
let selectedId = "A";
let drag = null;
let orbit = null;
let toastTimer = null;
const tasks = new Map();
const taskVisuals = new Map();
const dependencyVisuals = [];
// -------------------------------------------------------------------------
// Canvas labels and low-poly geometry helpers
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, w, h, r) {
r = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeTaskLabel(def) {
const c = document.createElement("canvas");
c.width = 320;
c.height = 104;
const ctx = c.getContext("2d");
const color = "#" + def.color.toString(16).padStart(6, "0");
roundedRect(ctx, 5, 5, 310, 94, 19);
ctx.fillStyle = "rgba(17, 43, 45, 0.93)";
ctx.fill();
ctx.strokeStyle = color;
ctx.lineWidth = 5;
ctx.stroke();
ctx.fillStyle = "#fffdf3";
ctx.font = "900 51px system-ui, sans-serif";
ctx.textBaseline = "middle";
ctx.fillText(def.id, 22, 53);
ctx.fillStyle = color;
ctx.font = "800 27px system-ui, sans-serif";
ctx.textAlign = "right";
ctx.fillText(def.duration + "t", 292, 53);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.renderOrder = 20;
return sprite;
}
function makeBoardLabel(text, {
foreground = "#173638",
background = "rgba(248,247,239,0.92)",
border = null,
fontSize = 38
} = {}) {
const c = document.createElement("canvas");
c.width = 256;
c.height = 80;
const ctx = c.getContext("2d");
if (background) {
roundedRect(ctx, 3, 3, 250, 74, 16);
ctx.fillStyle = background;
ctx.fill();
}
if (border) {
roundedRect(ctx, 3, 3, 250, 74, 16);
ctx.strokeStyle = border;
ctx.lineWidth = 4;
ctx.stroke();
}
ctx.fillStyle = foreground;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 128, 40);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.renderOrder = 15;
return sprite;
}
function disposeGroup(group) {
const materials = new Set();
group.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const list = Array.isArray(object.material)
? object.material
: [object.material];
for (const material of list) materials.add(material);
}
});
for (const material of materials) {
if (material.map) material.map.dispose();
material.dispose();
}
group.clear();
}
function laneZ(resource) {
return (resource - (resourceCount - 1) / 2) * LANE;
}
function createTaskVisual(def) {
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({
color: def.color,
roughness: 0.72,
metalness: 0.04,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.taskId = def.id;
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
new THREE.LineBasicMaterial({
color: 0x173638,
transparent: true,
opacity: 0.52
})
);
mesh.add(edge);
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.13, 0),
new THREE.MeshStandardMaterial({
color: def.color,
roughness: 0.55,
flatShading: true
})
);
marker.castShadow = true;
const label = makeTaskLabel(def);
const labelWidth = Math.min(2.35, Math.max(1.28, def.duration * UNIT * 0.55));
label.scale.set(labelWidth, labelWidth * 0.325, 1);
taskGroup.add(mesh, marker, label);
const visual = { mesh, edge, marker, label, baseColor: new THREE.Color(def.color) };
taskVisuals.set(def.id, visual);
return visual;
}
for (const def of TASK_DEFS) {
const task = {
...def,
start: 0,
resource: 0
};
tasks.set(def.id, task);
createTaskVisual(def);
}
function createDependencyVisuals() {
const lineMaterial = new THREE.LineBasicMaterial({
color: 0xe0a72c,
transparent: true,
opacity: 0.85
});
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xe0a72c,
roughness: 0.65,
flatShading: true
});
for (const [from, to] of DEPENDENCY_EDGES) {
const line = new THREE.Line(
new THREE.BufferGeometry(),
lineMaterial
);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.105, 0.28, 6),
arrowMaterial
);
dependencyGroup.add(line, arrow);
dependencyVisuals.push({ from, to, line, arrow });
}
}
createDependencyVisuals();
// -------------------------------------------------------------------------
// Board construction
// -------------------------------------------------------------------------
function rebuildBoard() {
disposeGroup(boardGroup);
boardDepth = resourceCount * LANE + 0.7;
const width = BOARD_X_MAX - BOARD_X_MIN;
const centerX = (BOARD_X_MAX + BOARD_X_MIN) / 2;
const base = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.28, boardDepth),
new THREE.MeshStandardMaterial({
color: 0x244b4a,
roughness: 0.88,
metalness: 0.02
})
);
base.position.set(centerX, -0.16, 0);
base.receiveShadow = true;
boardGroup.add(base);
const laneGeometry = new THREE.PlaneGeometry(width - 0.25, LANE * 0.82);
for (let resource = 0; resource < resourceCount; resource++) {
const lane = new THREE.Mesh(
laneGeometry,
new THREE.MeshStandardMaterial({
color: resource % 2 === 0 ? 0x315c58 : 0x2d5553,
roughness: 0.95,
transparent: true,
opacity: 0.72
})
);
lane.rotation.x = -Math.PI / 2;
lane.position.set(centerX, -0.005, laneZ(resource));
lane.receiveShadow = true;
boardGroup.add(lane);
const resourceLabel = makeBoardLabel("R" + (resource + 1), {
foreground: "#f7f3df",
background: "rgba(18,48,48,0.95)",
border: "rgba(255,255,255,0.18)",
fontSize: 40
});
resourceLabel.position.set(-1.85, 0.24, laneZ(resource));
resourceLabel.scale.set(1.12, 0.35, 1);
boardGroup.add(resourceLabel);
}
const gridPoints = [];
for (let time = 0; time <= HORIZON; time++) {
const x = time * UNIT;
gridPoints.push(
new THREE.Vector3(x, 0.018, -boardDepth / 2 + 0.18),
new THREE.Vector3(x, 0.018, boardDepth / 2 - 0.18)
);
if (time % 2 === 0) {
const label = makeBoardLabel("t" + time, {
foreground: "#496361",
background: "rgba(239,243,233,0.88)",
fontSize: 30
});
label.position.set(x, 0.16, boardDepth / 2 + 0.62);
label.scale.set(0.76, 0.24, 1);
boardGroup.add(label);
}
}
for (let boundary = 0; boundary <= resourceCount; boundary++) {
const z = (boundary - resourceCount / 2) * LANE;
gridPoints.push(
new THREE.Vector3(BOARD_X_MIN + 0.18, 0.02, z),
new THREE.Vector3(BOARD_X_MAX - 0.18, 0.02, z)
);
}
const grid = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(gridPoints),
new THREE.LineBasicMaterial({
color: 0xb7c8b8,
transparent: true,
opacity: 0.28
})
);
boardGroup.add(grid);
// Small low-poly markers give the board a crafted, tabletop appearance.
const markerGeometry = new THREE.ConeGeometry(0.18, 0.62, 5);
for (let i = 0; i < 7; i++) {
const marker = new THREE.Mesh(
markerGeometry,
new THREE.MeshStandardMaterial({
color: i % 2 ? 0x719b86 : 0x92ad8e,
roughness: 0.9,
flatShading: true
})
);
marker.position.set(-0.7 + i * 3.3, 0.18, -boardDepth / 2 - 0.55);
marker.rotation.y = i * 0.7;
marker.castShadow = true;
boardGroup.add(marker);
}
}
rebuildBoard();
// -------------------------------------------------------------------------
// Scheduling, validation, and metrics
// -------------------------------------------------------------------------
function loadSchedule(schedule) {
for (const def of TASK_DEFS) {
const item = schedule[def.id];
if (!item) continue;
const task = tasks.get(def.id);
task.start = item.start;
task.resource = item.resource;
}
}
function computeMakespan() {
let end = 0;
for (const task of tasks.values()) {
end = Math.max(end, task.start + task.duration);
}
return end;
}
function validateCandidate(taskId, start, resource) {
const task = tasks.get(taskId);
if (!Number.isInteger(start) || start < 0) {
return { valid: false, reason: "Start time must be a non-negative whole slot." };
}
if (start + task.duration > HORIZON) {
return { valid: false, reason: "The task must finish by the end of slot 20." };
}
if (resource < 0 || resource >= resourceCount) {
return { valid: false, reason: "Choose one of the available workers." };
}
for (const predecessorId of task.deps) {
const predecessor = tasks.get(predecessorId);
if (predecessor.start + predecessor.duration > start) {
return {
valid: false,
reason: `${predecessorId} must finish before ${task.id} starts.`
};
}
}
for (const [successorId, successor] of tasks) {
if (successorId === taskId) continue;
if (task.deps.includes(successorId)) continue;
if (successor.deps.includes(taskId) && start + task.duration > successor.start) {
return {
valid: false,
reason: `${task.id} must finish before ${successorId} starts.`
};
}
}
const candidateEnd = start + task.duration;
for (const [otherId, other] of tasks) {
if (otherId === taskId || other.resource !== resource) continue;
const overlaps = start < other.start + other.duration &&
candidateEnd > other.start;
if (overlaps) {
return {
valid: false,
reason: `Worker R${resource + 1} is already occupied by ${otherId}.`
};
}
}
return { valid: true, reason: "Move accepted." };
}
function validateWholeSchedule() {
for (const task of tasks.values()) {
const result = validateCandidate(
task.id,
task.start,
task.resource
);
if (!result.valid) return result;
}
return { valid: true, reason: "Schedule valid." };
}
function updateTaskVisual(def) {
const task = tasks.get(def.id);
const visual = taskVisuals.get(def.id);
const selected = selectedId === def.id;
visual.mesh.position.set(
(task.start + task.duration / 2) * UNIT,
0.42,
laneZ(task.resource)
);
visual.mesh.scale.set(
task.duration * UNIT * 0.82,
0.72,
1.38
);
visual.mesh.material.color.copy(visual.baseColor);
visual.mesh.material.emissive.setHex(selected ? 0xffffff : 0x000000);
visual.mesh.material.emissiveIntensity = selected ? 0.075 : 0;
visual.edge.material.color.setHex(selected ? 0xfff7df : 0x173638);
visual.edge.material.opacity = selected ? 0.95 : 0.52;
visual.marker.position.set(
(task.start + task.duration / 2) * UNIT,
0.94,
laneZ(task.resource)
);
visual.label.position.set(
(task.start + task.duration / 2) * UNIT,
1.39,
laneZ(task.resource)
);
}
function updateDependencies() {
const y = 1.03;
for (const visual of dependencyVisuals) {
const predecessor = tasks.get(visual.from);
const successor = tasks.get(visual.to);
const start = new THREE.Vector3(
(predecessor.start + predecessor.duration) * UNIT,
y,
laneZ(predecessor.resource)
);
const end = new THREE.Vector3(
successor.start * UNIT,
y,
laneZ(successor.resource)
);
const middle = start.clone().add(end).multiplyScalar(0.5);
middle.y += Math.min(0.72, 0.2 + start.distanceTo(end) * 0.055);
middle.z += predecessor.resource === successor.resource ? 0.22 : 0;
const curve = new THREE.QuadraticBezierCurve3(start, middle, end);
visual.line.geometry.setFromPoints(curve.getPoints(28));
const arrowPoint = curve.getPoint(0.965);
const tangent = curve.getTangent(0.965).normalize();
visual.arrow.position.copy(arrowPoint);
visual.arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
}
}
function updateMetrics() {
const current = computeMakespan();
const optimum = KNOWN_OPTIMA[resourceCount];
const gap = current - optimum;
$("currentValue").innerHTML = `${current}<span>slots</span>`;
$("optimumValue").innerHTML = `${optimum}<span>slots</span>`;
$("currentBarValue").textContent = current;
$("optimumBarValue").textContent = optimum;
$("currentBar").style.width = `${Math.min(100, current / HORIZON * 100)}%`;
$("optimumBar").style.width = `${Math.min(100, optimum / HORIZON * 100)}%`;
const gapPill = $("gapValue");
gapPill.classList.toggle("optimal", gap === 0);
gapPill.textContent = gap === 0 ? "optimal" : `+${gap}`;
if (gap === 0) {
$("scheduleStatus").textContent = "Certified optimal schedule";
} else {
$("scheduleStatus").textContent =
`${gap} slot${gap === 1 ? "" : "s"} above optimum`;
}
$("proof").innerHTML = PROOFS[resourceCount];
}
function updateTaskPanel() {
const task = tasks.get(selectedId);
if (!task) return;
const color = "#" + task.color.toString(16).padStart(6, "0");
$("taskChip").textContent = task.id;
$("taskChip").style.background = color;
$("taskName").textContent = task.name;
$("taskMeta").textContent = `${task.duration} time units · task ${task.id}`;
$("taskTime").textContent = `${task.start} → ${task.start + task.duration}`;
$("taskResource").textContent = `Worker R${task.resource + 1}`;
const predecessors = task.deps.length
? task.deps.map(id => {
const p = tasks.get(id);
return `${id} ${p.name}`;
}).join(", ")
: "None";
const successors = TASK_DEFS
.filter(candidate => candidate.deps.includes(task.id))
.map(candidate => {
const s = tasks.get(candidate.id);
return `${s.id} ${s.name}`;
})
.join(", ");
$("taskDependencies").innerHTML =
`<strong>Must follow:</strong> ${predecessors}`;
$("taskSuccessors").innerHTML =
`<strong>Must precede:</strong> ${successors || "None"}`;
}
function setValidation(message, invalid = false) {
const element = $("validation");
element.textContent = message;
element.classList.toggle("invalid", invalid);
}
function updateAll() {
for (const def of TASK_DEFS) updateTaskVisual(def);
updateDependencies();
updateMetrics();
updateTaskPanel();
const validation = validateWholeSchedule();
if (validation.valid) {
setValidation(
`Schedule valid. ${DEPENDENCY_EDGES.length} precedence links and all worker-capacity rules are satisfied.`
);
} else {
setValidation(`Invalid schedule: ${validation.reason}`, true);
}
}
function showToast(message, error = false) {
const toast = $("toast");
toast.textContent = message;
toast.classList.toggle("error", error);
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.classList.remove("visible");
}, 2800);
}
// -------------------------------------------------------------------------
// Direct camera and task-drag controls
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.48);
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);
}
function pickTask(event) {
updatePointer(event);
const hits = raycaster.intersectObjects(
[...taskVisuals.values()].map(visual => visual.mesh),
false
);
return hits.length ? hits[0] : null;
}
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
const hit = pickTask(event);
if (hit) {
const id = hit.object.userData.taskId;
const task = tasks.get(id);
selectedId = id;
const planePoint = new THREE.Vector3();
const hasPoint = raycaster.ray.intersectPlane(dragPlane, planePoint);
let offset = 0;
if (hasPoint) {
const grabbedStart = planePoint.x / UNIT - task.duration / 2;
offset = task.start - grabbedStart;
}
drag = {
id,
offset,
originalStart: task.start,
originalResource: task.resource,
valid: true,
reason: "Move accepted.",
moved: false
};
updateTaskPanel();
canvas.style.cursor = "grabbing";
return;
}
orbit = { x: event.clientX, y: event.clientY };
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", event => {
if (drag) {
updatePointer(event);
const planePoint = new THREE.Vector3();
if (!raycaster.ray.intersectPlane(dragPlane, planePoint)) return;
const task = tasks.get(drag.id);
const candidateStart = Math.round(
planePoint.x / UNIT - task.duration / 2 + drag.offset
);
const candidateResource = THREE.MathUtils.clamp(
Math.round(planePoint.z / LANE + (resourceCount - 1) / 2),
0,
resourceCount - 1
);
const validation = validateCandidate(
drag.id,
candidateStart,
candidateResource
);
drag.valid = validation.valid;
drag.reason = validation.reason;
drag.moved =
candidateStart !== drag.originalStart ||
candidateResource !== drag.originalResource;
task.start = candidateStart;
task.resource = candidateResource;
updateAll();
if (!drag.valid) {
taskVisuals.get(drag.id).mesh.material.color.setHex(0xef5b5b);
setValidation(`Invalid move: ${drag.reason}`, true);
}
return;
}
if (orbit) {
const dx = event.clientX - orbit.x;
const dy = event.clientY - orbit.y;
orbit.x = event.clientX;
orbit.y = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.25,
1.35
);
updateCamera();
return;
}
const hit = pickTask(event);
canvas.style.cursor = hit ? "grab" : "default";
});
function finishPointer(event) {
if (drag) {
const completedDrag = drag;
const task = tasks.get(completedDrag.id);
if (!completedDrag.valid) {
task.start = completedDrag.originalStart;
task.resource = completedDrag.originalResource;
updateAll();
showToast(
`Move rejected: ${completedDrag.reason}`,
true
);
} else {
updateAll();
if (completedDrag.moved) {
showToast(
`${task.id} moved to slot ${task.start} on Worker R${task.resource + 1}.`
);
}
}
drag = null;
}
orbit = null;
canvas.style.cursor = "default";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", finishPointer);
canvas.addEventListener("pointercancel", finishPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.018,
14,
43
);
updateCamera();
}, { passive: false });
canvas.addEventListener("contextmenu", event => event.preventDefault());
// -------------------------------------------------------------------------
// UI actions
// -------------------------------------------------------------------------
function setResourceCount(count) {
if (count === resourceCount) return;
resourceCount = count;
loadSchedule(INITIAL_SCHEDULES[resourceCount]);
rebuildBoard();
updateAll();
document.querySelectorAll(".resource-button").forEach(button => {
button.classList.toggle(
"active",
Number(button.dataset.resource) === resourceCount
);
});
showToast(
`${resourceCount} worker${resourceCount === 1 ? "" : "s"} selected. The board was reset to a valid one-slot-over-optimum schedule.`
);
}
document.querySelectorAll(".resource-button").forEach(button => {
button.addEventListener("click", () => {
setResourceCount(Number(button.dataset.resource));
});
});
$("optimalButton").addEventListener("click", () => {
loadSchedule(OPTIMAL_SCHEDULES[resourceCount]);
updateAll();
showToast(
`Certified optimum loaded: ${KNOWN_OPTIMA[resourceCount]} time units.`
);
});
$("resetButton").addEventListener("click", () => {
loadSchedule(INITIAL_SCHEDULES[resourceCount]);
updateAll();
showToast("Schedule reset.");
});
$("cameraButton").addEventListener("click", () => {
cameraState.radius = window.innerWidth < 800 ? 34 : 29;
cameraState.theta = 0.30;
cameraState.phi = 0.68;
updateCamera();
});
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement ||
event.target instanceof HTMLTextAreaElement) return;
if (["1", "2", "3", "4"].includes(event.key)) {
setResourceCount(Number(event.key));
} else if (event.key.toLowerCase() === "o") {
$("optimalButton").click();
} else if (event.key.toLowerCase() === "r") {
$("resetButton").click();
} else if (event.key.toLowerCase() === "c") {
$("cameraButton").click();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
});
// -------------------------------------------------------------------------
// Start
// -------------------------------------------------------------------------
loadSchedule(INITIAL_SCHEDULES[resourceCount]);
updateAll();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
for (const def of TASK_DEFS) {
const visual = taskVisuals.get(def.id);
visual.marker.rotation.y += 0.018;
visual.marker.rotation.x = Math.sin(elapsed * 0.8 + def.duration) * 0.08;
const selected = selectedId === def.id;
const pulse = selected ? 1.08 + Math.sin(elapsed * 3.2) * 0.055 : 1;
visual.marker.scale.setScalar(pulse);
}
renderer.render(scene, camera);
});
</script>
</body>
</html>
```