Prompt specification
Build or customize the Three.js 3D scene "Unlock Two Independent Workshop Skills" 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: Unlock Two Independent Workshop Skills
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/unlock-two-independent-workshop-skills-x3582
Scene Description Prompt:
Build a voxel workshop progression board with two independent skill branches and enforced prerequisites. Allow either completion order. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (unlock-two-independent-workshop-skills-x3582):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#172a29" />
<title>Dual Forge — Voxel Workshop</title>
<style>
:root {
--ink: #f7f0df;
--muted: #aebdb4;
--panel: rgba(20, 39, 38, 0.9);
--panel-border: rgba(226, 236, 216, 0.14);
--timber: #f2a85b;
--stone: #70c8d0;
--success: #83dc91;
--locked: #647570;
--shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #172a29;
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;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.ui-layer {
position: fixed;
inset: 0;
pointer-events: none;
}
.topbar {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.35);
}
.brand-mark {
position: relative;
width: 42px;
height: 42px;
flex: 0 0 auto;
transform: rotate(-3deg);
}
.brand-mark i {
position: absolute;
display: block;
width: 15px;
height: 15px;
border-radius: 3px;
background: var(--timber);
box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.14);
}
.brand-mark i:nth-child(1) { left: 0; top: 0; }
.brand-mark i:nth-child(2) { right: 0; top: 0; background: var(--stone); }
.brand-mark i:nth-child(3) { left: 13px; bottom: 0; background: #f6d793; }
.eyebrow {
margin: 0 0 4px;
color: #d6e2d9;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 8px 0 0;
color: #c3d0c8;
font-size: 12px;
line-height: 1.45;
}
.top-actions {
pointer-events: auto;
display: flex;
align-items: center;
gap: 12px;
padding: 10px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.total-progress {
width: 128px;
}
.progress-label {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: #dce7df;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.progress-track {
height: 6px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.1);
}
#totalFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--timber), #f4d17c, var(--stone));
transition: width 400ms ease;
}
.icon-button {
display: grid;
place-items: center;
width: 38px;
height: 38px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 11px;
background: rgba(255, 255, 255, 0.06);
color: var(--ink);
cursor: pointer;
transition: 160ms ease;
}
.icon-button:hover {
background: rgba(255, 255, 255, 0.13);
transform: rotate(-8deg);
}
.icon-button svg {
width: 17px;
height: 17px;
fill: none;
stroke: currentColor;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
.branch-card {
position: absolute;
bottom: 22px;
width: min(360px, calc(50vw - 34px));
padding: 15px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.branch-card.timber {
left: 24px;
--branch: var(--timber);
}
.branch-card.stone {
right: 24px;
--branch: var(--stone);
}
.branch-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.branch-name {
display: flex;
align-items: center;
gap: 9px;
font-size: 13px;
font-weight: 850;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.branch-icon {
width: 10px;
height: 10px;
border-radius: 3px;
background: var(--branch);
box-shadow: 4px 4px 0 color-mix(in srgb, var(--branch), #000 35%);
}
.branch-count {
color: var(--branch);
font-size: 11px;
font-weight: 850;
}
.branch-track {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
}
.step-button {
position: relative;
min-width: 0;
height: 38px;
padding: 0;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: #8f9e97;
cursor: pointer;
transition: 160ms ease;
}
.step-button:hover {
transform: translateY(-2px);
border-color: color-mix(in srgb, var(--branch), transparent 55%);
}
.step-button.available {
border-color: color-mix(in srgb, var(--branch), transparent 42%);
background: color-mix(in srgb, var(--branch), transparent 88%);
color: var(--branch);
box-shadow: 0 0 20px color-mix(in srgb, var(--branch), transparent 87%);
}
.step-button.complete {
border-color: color-mix(in srgb, var(--success), transparent 48%);
background: color-mix(in srgb, var(--success), transparent 88%);
color: var(--success);
}
.step-button.locked {
cursor: not-allowed;
opacity: 0.58;
}
.step-icon {
display: inline-grid;
place-items: center;
width: 22px;
height: 22px;
border-radius: 7px;
background: rgba(0, 0, 0, 0.16);
font-size: 11px;
font-weight: 900;
}
.step-name {
display: block;
overflow: hidden;
margin-top: 4px;
padding: 0 5px;
font-size: 9px;
font-weight: 700;
line-height: 1.1;
text-overflow: ellipsis;
white-space: nowrap;
}
.next-row {
display: flex;
align-items: center;
gap: 9px;
min-height: 27px;
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.next-label {
flex: 0 0 auto;
color: var(--branch);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.14em;
}
#timberNext,
#stoneNext {
overflow: hidden;
color: #dce5df;
font-size: 11px;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
}
.help {
position: absolute;
left: 50%;
bottom: 27px;
transform: translateX(-50%);
padding: 9px 14px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 99px;
background: rgba(15, 29, 29, 0.72);
color: #bdcbc3;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.03em;
white-space: nowrap;
backdrop-filter: blur(12px);
}
.marker-layer {
position: fixed;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.node-marker {
--node-color: #fff;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
gap: 2px;
width: 31px;
height: 31px;
border: 2px solid color-mix(in srgb, var(--node-color), #fff 18%);
border-radius: 10px;
background: rgba(20, 35, 34, 0.9);
color: var(--node-color);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.3);
font-size: 11px;
font-weight: 900;
transform: translate(-50%, -50%);
transition: 180ms ease;
}
.node-marker.available {
animation: markerPulse 1.7s ease-in-out infinite;
}
.node-marker.complete {
border-color: var(--success);
background: var(--success);
color: #183226;
}
.node-marker.locked {
border-color: #596863;
background: rgba(39, 55, 52, 0.92);
color: #81908a;
}
.node-marker.hovered {
transform: translate(-50%, -50%) scale(1.16);
}
@keyframes markerPulse {
0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--node-color), transparent 76%); }
50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--node-color), transparent 92%); }
}
.tiny-lock {
position: relative;
width: 7px;
height: 7px;
border-radius: 1px;
background: currentColor;
}
.tiny-lock::before {
content: "";
position: absolute;
left: 1px;
bottom: 5px;
width: 5px;
height: 5px;
border: 1px solid currentColor;
border-bottom: 0;
border-radius: 4px 4px 0 0;
}
.lane-label {
position: absolute;
padding: 5px 9px;
border: 1px solid color-mix(in srgb, var(--lane), transparent 45%);
border-radius: 7px;
background: rgba(20, 35, 34, 0.86);
color: var(--lane);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.14em;
transform: translate(-50%, -50%);
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.tooltip {
position: fixed;
z-index: 30;
max-width: 250px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
background: rgba(12, 25, 25, 0.94);
color: #edf3ec;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
font-size: 11px;
line-height: 1.4;
pointer-events: none;
opacity: 0;
transform: translateY(4px);
transition: opacity 120ms ease, transform 120ms ease;
}
.tooltip.visible {
opacity: 1;
transform: translateY(0);
}
.tooltip small {
display: block;
margin-bottom: 2px;
color: var(--tooltip-color, #fff);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.toast {
position: fixed;
z-index: 60;
left: 50%;
top: 94px;
max-width: min(440px, calc(100vw - 32px));
padding: 11px 16px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 12px;
background: rgba(16, 31, 30, 0.95);
color: #edf4ed;
box-shadow: var(--shadow);
font-size: 12px;
font-weight: 700;
text-align: center;
pointer-events: none;
opacity: 0;
transform: translate(-50%, -12px);
transition: 180ms ease;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.modal {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
padding: 20px;
background: rgba(6, 15, 15, 0.67);
backdrop-filter: blur(9px);
opacity: 1;
transition: opacity 180ms ease;
}
.modal.hidden {
display: none;
}
.modal-card {
--accent: var(--timber);
width: min(460px, 100%);
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 22px;
background: #1c302f;
box-shadow: 0 28px 100px rgba(0, 0, 0, 0.5);
transform: translateY(0) scale(1);
transition: transform 180ms ease;
}
.modal.hidden .modal-card {
transform: translateY(15px) scale(0.97);
}
.modal-banner {
position: relative;
height: 72px;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
background:
linear-gradient(135deg, color-mix(in srgb, var(--accent), transparent 72%), transparent),
#203735;
}
.modal-banner::before,
.modal-banner::after {
content: "";
position: absolute;
bottom: 13px;
width: 16px;
height: 16px;
border-radius: 4px;
background: var(--accent);
box-shadow: inset -4px -4px 0 rgba(0, 0, 0, 0.15);
}
.modal-banner::before { left: 24px; }
.modal-banner::after { left: 48px; opacity: 0.55; }
.modal-content {
padding: 24px;
}
.modal-content h2 {
margin: 6px 0 10px;
color: #fff7e7;
font-size: 27px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.modal-content p {
margin: 0 0 20px;
color: #bdcbc4;
font-size: 13px;
line-height: 1.65;
}
.requirement {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 20px;
padding: 11px 12px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 11px;
background: rgba(255, 255, 255, 0.04);
color: #dbe5df;
font-size: 11px;
line-height: 1.4;
}
.requirement strong {
display: block;
margin-bottom: 2px;
color: #84958e;
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.requirement-icon {
display: grid;
place-items: center;
width: 27px;
height: 27px;
flex: 0 0 auto;
border-radius: 8px;
background: color-mix(in srgb, var(--accent), transparent 78%);
color: var(--accent);
font-weight: 900;
}
.reward {
margin: 0 0 21px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
}
.modal-actions {
display: flex;
gap: 9px;
}
.button {
min-height: 43px;
padding: 0 17px;
border: 1px solid transparent;
border-radius: 11px;
cursor: pointer;
font-size: 12px;
font-weight: 850;
transition: 150ms ease;
}
.button.secondary {
border-color: rgba(255, 255, 255, 0.1);
background: rgba(255, 255, 255, 0.05);
color: #c9d4ce;
}
.button.primary {
flex: 1;
background: var(--accent);
color: #172928;
box-shadow: 0 8px 24px color-mix(in srgb, var(--accent), transparent 72%);
}
.button:hover {
transform: translateY(-2px);
filter: brightness(1.06);
}
.loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #172a29;
color: #edf4ec;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading-inner {
text-align: center;
}
.loading-cubes {
display: flex;
justify-content: center;
gap: 7px;
margin-bottom: 18px;
}
.loading-cubes i {
width: 15px;
height: 15px;
border-radius: 3px;
background: var(--timber);
animation: loadBounce 900ms ease-in-out infinite;
}
.loading-cubes i:nth-child(2) {
background: #f2d183;
animation-delay: 120ms;
}
.loading-cubes i:nth-child(3) {
background: var(--stone);
animation-delay: 240ms;
}
@keyframes loadBounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-9px); }
}
@media (max-width: 900px) {
.subtitle { display: none; }
.branch-card { width: min(320px, calc(50vw - 28px)); }
.help { display: none; }
}
@media (max-width: 640px) {
.topbar {
top: 14px;
left: 14px;
right: 14px;
}
.brand-mark {
width: 34px;
height: 34px;
transform: scale(0.82) rotate(-3deg);
transform-origin: left center;
}
.brand { gap: 5px; }
.eyebrow { font-size: 8px; }
h1 { font-size: 23px; }
.top-actions {
gap: 7px;
padding: 7px;
border-radius: 13px;
}
.total-progress { width: 78px; }
.progress-label { font-size: 8px; }
.icon-button { width: 32px; height: 32px; }
.branch-card {
bottom: 12px;
width: calc(50vw - 18px);
padding: 10px;
border-radius: 14px;
}
.branch-card.timber { left: 12px; }
.branch-card.stone { right: 12px; }
.branch-head { margin-bottom: 8px; }
.branch-name { gap: 6px; font-size: 10px; }
.branch-icon { width: 8px; height: 8px; }
.branch-count { font-size: 9px; }
.branch-track { gap: 4px; }
.step-button { height: 29px; }
.step-icon { width: 19px; height: 19px; }
.step-name { display: none; }
.next-row { margin-top: 7px; padding-top: 7px; min-height: 19px; }
.next-label { font-size: 7px; }
#timberNext, #stoneNext { font-size: 9px; }
.modal-content { padding: 19px; }
.modal-content h2 { font-size: 23px; }
.node-marker { width: 27px; height: 27px; border-radius: 8px; }
.lane-label { font-size: 7px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel workshop progression board"></canvas>
<div class="ui-layer">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i></div>
<div>
<p class="eyebrow">Voxel Guild · Workshop Board</p>
<h1>Dual Forge</h1>
<p class="subtitle">Two crafts. Two independent paths. Complete them in either order.</p>
</div>
</div>
<div class="top-actions">
<div class="total-progress">
<div class="progress-label">
<span>Workshop</span>
<span id="totalText">0 / 8</span>
</div>
<div class="progress-track"><div id="totalFill"></div></div>
</div>
<button id="resetButton" class="icon-button" title="Reset workshop" aria-label="Reset workshop">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 7v5h5"></path>
<path d="M5.5 16.5a8 8 0 1 0 .2-8.9L4 9"></path>
</svg>
</button>
</div>
</header>
<aside id="timberPanel" class="branch-card timber">
<div class="branch-head">
<div class="branch-name"><span class="branch-icon"></span>Timbercraft</div>
<div class="branch-count">0 / 4</div>
</div>
<div id="timberTrack" class="branch-track"></div>
<div class="next-row">
<span class="next-label">NEXT</span>
<strong id="timberNext">Plane the Plank</strong>
</div>
</aside>
<aside id="stonePanel" class="branch-card stone">
<div class="branch-head">
<div class="branch-name"><span class="branch-icon"></span>Stonecraft</div>
<div class="branch-count">0 / 4</div>
</div>
<div id="stoneTrack" class="branch-track"></div>
<div class="next-row">
<span class="next-label">NEXT</span>
<strong id="stoneNext">Dress the Block</strong>
</div>
</aside>
<div class="help">Drag to orbit · Scroll or pinch to zoom · Select a glowing station</div>
</div>
<div id="markerLayer" class="marker-layer"></div>
<div id="tooltip" class="tooltip"></div>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
<div id="taskModal" class="modal hidden" role="dialog" aria-modal="true" aria-labelledby="modalTitle">
<div class="modal-card" id="modalCard">
<div class="modal-banner"></div>
<div class="modal-content">
<p id="modalEyebrow" class="eyebrow">Timbercraft · Task 1</p>
<h2 id="modalTitle">Plane the Plank</h2>
<p id="modalDescription"></p>
<div class="requirement">
<span id="modalRequirementIcon" class="requirement-icon">✓</span>
<div>
<strong>Prerequisite</strong>
<span id="modalRequirement"></span>
</div>
</div>
<div id="modalReward" class="reward"></div>
<div class="modal-actions">
<button id="closeModalButton" class="button secondary">Not yet</button>
<button id="completeButton" class="button primary">Mark complete</button>
</div>
</div>
</div>
</div>
<div id="loading" class="loading">
<div class="loading-inner">
<div class="loading-cubes"><i></i><i></i><i></i></div>
<div class="eyebrow">Building the workshop</div>
</div>
</div>
<script>
setTimeout(() => {
if (!window.__voxelWorkshopReady) {
document.getElementById("loading").innerHTML =
'<div class="loading-inner"><div class="eyebrow">Unable to load the workshop</div></div>';
}
}, 10000);
</script>
<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.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#172a29");
scene.fog = new THREE.Fog("#172a29", 25, 48);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
theta: 0.27,
phi: 1.02,
radius: window.innerWidth < 650 ? 25 : 22.5
};
const desired = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius
};
const cameraTarget = new THREE.Vector3(0, 0.85, -0.35);
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xe8f5e8, 0x1c2927, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2b0, 3.1);
sun.position.set(9, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x79cbd1, 1.2);
rimLight.position.set(-10, 8, -8);
scene.add(rimLight);
const materialCache = new Map();
const geometryCache = new Map();
function material(color, options = {}) {
if (color?.isMaterial) return color;
const key = `${color}:${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
...options
})
);
}
return materialCache.get(key);
}
function cube(parent, sx, sy, sz, x, y, z, mat, rotation = null) {
const geometryKey = `${sx}:${sy}:${sz}`;
if (!geometryCache.has(geometryKey)) {
geometryCache.set(geometryKey, new THREE.BoxGeometry(sx, sy, sz));
}
const mesh = new THREE.Mesh(
geometryCache.get(geometryKey),
typeof mat === "string" ? material(mat) : mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
if (rotation) mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
parent.add(mesh);
return mesh;
}
const palette = {
ground: "#102321",
platform: "#304842",
floorA: "#3d534c",
floorB: "#425a51",
wall: "#2b413c",
wallTrim: "#53645c",
dark: "#1b302e",
darker: "#112421",
woodDark: "#68432e",
wood: "#9d633a",
woodLight: "#d19a5f",
woodPale: "#e0b77b",
stoneDark: "#6e7773",
stone: "#a9aea5",
stoneLight: "#d0d1c4",
metal: "#536064",
metalDark: "#303d3f",
timber: "#f2a85b",
stoneAccent: "#70c8d0",
success: "#83dc91",
locked: "#52645e",
cream: "#f1d89d",
fire: "#ff9e45",
fireLight: "#ffd06b"
};
// Ground and workshop platform.
cube(scene, 60, 0.7, 60, 0, -1.35, 0, palette.ground);
cube(scene, 13.7, 0.62, 11.7, 0, -0.45, 0, palette.platform);
for (let x = -6; x <= 6; x++) {
for (let z = -5; z <= 5; z++) {
const color = (x + z) % 2 === 0 ? palette.floorA : palette.floorB;
const tile = cube(scene, 0.95, 0.09, 0.95, x, -0.09, z, color);
tile.castShadow = false;
}
}
// Back wall and pegboard.
cube(scene, 13.7, 3.5, 0.42, 0, 1.3, -5.72, palette.wall);
cube(scene, 13.8, 0.18, 0.62, 0, 3.12, -5.72, palette.wallTrim);
cube(scene, 11.6, 2.15, 0.16, 0, 2.05, -5.42, palette.dark);
for (let x = -5; x <= 5; x += 0.55) {
cube(scene, 0.035, 2.0, 0.025, x, 2.05, -5.31, palette.wallTrim);
}
for (let y = 1.1; y <= 3; y += 0.48) {
cube(scene, 11.4, 0.035, 0.025, 0, y, -5.30, palette.wallTrim);
}
// Voxel tools on the pegboard.
cube(scene, 0.14, 1.1, 0.12, -4.5, 2.15, -5.15, palette.wood);
cube(scene, 0.65, 0.2, 0.18, -4.5, 2.7, -5.15, palette.metal);
cube(scene, 0.14, 0.85, 0.12, -2.9, 2.0, -5.15, palette.metalDark);
cube(scene, 0.6, 0.1, 0.12, -2.9, 2.46, -5.15, palette.metal);
cube(scene, 1.0, 0.12, 0.14, 2.9, 2.2, -5.15, palette.woodLight);
cube(scene, 0.55, 0.18, 0.16, 3.25, 2.2, -5.15, palette.metal);
// Shelves and supplies.
cube(scene, 3.6, 0.18, 0.72, -4.1, 3.45, -5.15, palette.wood);
cube(scene, 0.65, 0.65, 0.58, -5.2, 3.82, -5.12, palette.woodDark);
cube(scene, 0.55, 0.42, 0.5, -4.35, 3.73, -5.13, palette.stone);
cube(scene, 0.52, 0.8, 0.48, -3.65, 3.87, -5.12, palette.woodLight);
// Central voxel forge.
cube(scene, 2.25, 0.55, 1.4, 0, 0.25, -4.65, palette.dark);
cube(scene, 1.65, 1.2, 1.05, 0, 0.92, -4.75, palette.wallTrim);
cube(scene, 0.9, 0.72, 0.12, 0, 0.65, -4.14, palette.darker);
cube(scene, 1.25, 0.55, 1.05, 0, 1.72, -4.78, palette.metalDark);
cube(scene, 0.72, 1.7, 0.72, 0, 2.65, -4.93, palette.wallTrim);
cube(scene, 0.88, 0.16, 0.88, 0, 3.52, -4.93, palette.metalDark);
const forgeFlames = [];
forgeFlames.push(cube(scene, 0.28, 0.52, 0.2, -0.2, 0.67, -4.05, palette.fire));
forgeFlames.push(cube(scene, 0.28, 0.78, 0.2, 0.12, 0.73, -4.05, palette.fireLight));
forgeFlames.push(cube(scene, 0.2, 0.42, 0.18, 0.35, 0.61, -4.05, palette.fire));
const forgeLight = new THREE.PointLight(0xffa64d, 22, 7, 2);
forgeLight.position.set(0, 1.05, -3.75);
scene.add(forgeLight);
// Two independent craft lanes.
cube(scene, 2.05, 0.06, 9.55, -3.2, 0.015, -0.05, palette.woodDark);
cube(scene, 2.05, 0.06, 9.55, 3.2, 0.015, -0.05, palette.stoneDark);
for (const x of [-4.15, -2.25, 2.25, 4.15]) {
cube(scene, 0.07, 0.08, 9.45, x, 0.04, -0.05, x < 0 ? palette.wood : palette.stoneAccent);
}
const branches = {
timber: {
name: "Timbercraft",
color: palette.timber,
x: -3.2,
tasks: [
{
title: "Plane the Plank",
short: "Plane",
description: "Shave a rough board into a clean, even plank. Establish your first timbercraft technique.",
requirement: "No prerequisite — this task is ready.",
reward: "Unlocks: Cut the Mortise"
},
{
title: "Cut the Mortise",
short: "Mortise",
description: "Mark the joint carefully and chisel a square mortise into the workbench rail.",
requirement: "Complete “Plane the Plank” first.",
reward: "Unlocks: Fit the Tenon"
},
{
title: "Fit the Tenon",
short: "Tenon",
description: "Shape the tenon, test the fit, and refine it until the joint seats without forcing.",
requirement: "Complete “Cut the Mortise” first.",
reward: "Unlocks: Craft the Master Bench"
},
{
title: "Craft the Master Bench",
short: "Master",
description: "Assemble the finished bench and earn the title of Master Timberwright.",
requirement: "Complete “Fit the Tenon” first.",
reward: "Timbercraft mastery"
}
]
},
stone: {
name: "Stonecraft",
color: palette.stoneAccent,
x: 3.2,
tasks: [
{
title: "Dress the Block",
short: "Dress",
description: "Square the rough stone and remove uneven faces with steady, measured strikes.",
requirement: "No prerequisite — this task is ready.",
reward: "Unlocks: Lay the Course"
},
{
title: "Lay the Course",
short: "Course",
description: "Level the foundation and lay the first course so each block supports the next.",
requirement: "Complete “Dress the Block” first.",
reward: "Unlocks: Carve the Keystone"
},
{
title: "Carve the Keystone",
short: "Carve",
description: "Carve the keystone's profile and refine its details until it fits the arch perfectly.",
requirement: "Complete “Lay the Course” first.",
reward: "Unlocks: Raise the Master Pillar"
},
{
title: "Raise the Master Pillar",
short: "Master",
description: "Set the final blocks, raise the pillar, and earn the title of Master Mason.",
requirement: "Complete “Carve the Keystone” first.",
reward: "Stonecraft mastery"
}
]
}
};
const state = {
timber: Array(4).fill(false),
stone: Array(4).fill(false)
};
const nodeRoots = [];
const nodeVisuals = [];
const connectorMaterials = [];
const particles = [];
const markerLayer = document.getElementById("markerLayer");
const tooltip = document.getElementById("tooltip");
const toast = document.getElementById("toast");
const taskModal = document.getElementById("taskModal");
const modalCard = document.getElementById("modalCard");
const completeButton = document.getElementById("completeButton");
let selectedTask = null;
let hoveredNode = null;
let toastTimer = null;
function addLock(root) {
const lock = new THREE.Group();
cube(lock, 0.28, 0.24, 0.2, 0, 0, 0, palette.locked);
cube(lock, 0.07, 0.2, 0.08, -0.08, 0.19, 0, palette.locked);
cube(lock, 0.07, 0.2, 0.08, 0.08, 0.19, 0, palette.locked);
cube(lock, 0.23, 0.07, 0.08, 0, 0.29, 0, palette.locked);
lock.position.set(0, 1.9, 0.1);
root.add(lock);
return lock;
}
function createNode(branchKey, index, z) {
const branch = branches[branchKey];
const root = new THREE.Group();
root.position.set(branch.x, 0, z);
root.userData.nodeKey = `${branchKey}:${index}`;
root.userData.branch = branchKey;
root.userData.index = index;
scene.add(root);
nodeRoots.push(root);
const ringMaterial = material(branch.color, {
emissive: branch.color,
emissiveIntensity: 0.45,
roughness: 0.48
});
cube(root, 1.9, 0.16, 1.65, 0, 0.11, 0, palette.darker);
for (const x of [-0.82, 0.82]) {
for (const zz of [-0.67, 0.67]) {
cube(root, 0.16, 0.15, 0.16, x, 0.22, zz, ringMaterial);
}
}
if (branchKey === "timber") {
createTimberStation(root, index);
} else {
createStoneStation(root, index);
}
const lock = addLock(root);
lock.visible = true;
const marker = document.createElement("div");
marker.className = "node-marker";
markerLayer.appendChild(marker);
const visual = {
root,
branch: branchKey,
index,
marker,
ringMaterial,
lock,
anchor: new THREE.Vector3(0, 2.42, 0)
};
nodeVisuals.push(visual);
return visual;
}
function createTimberStation(root, index) {
if (index === 0) {
// Workbench and hand plane.
for (const x of [-0.65, 0.65]) {
for (const z of [-0.3, 0.3]) {
cube(root, 0.16, 0.78, 0.16, x, 0.58, z, palette.woodDark);
}
}
cube(root, 1.65, 0.18, 1.0, 0, 1.02, 0, palette.wood);
cube(root, 1.25, 0.11, 0.28, -0.12, 1.17, -0.05, palette.woodPale);
cube(root, 0.44, 0.22, 0.28, 0.45, 1.21, 0.13, palette.metal);
cube(root, 0.28, 0.1, 0.14, 0.45, 1.37, 0.13, palette.woodDark);
} else if (index === 1) {
// Sawhorse and clamped timber.
cube(root, 1.65, 0.18, 0.3, 0, 1.0, 0, palette.wood);
cube(root, 0.17, 0.95, 0.18, -0.5, 0.57, 0, palette.woodDark, [0, 0, -0.28]);
cube(root, 0.17, 0.95, 0.18, 0.5, 0.57, 0, palette.woodDark, [0, 0, 0.28]);
cube(root, 1.12, 0.12, 0.12, 0, 0.53, 0, palette.woodLight);
cube(root, 0.65, 0.18, 0.22, 0, 1.23, 0, palette.woodPale);
cube(root, 0.08, 0.38, 0.08, 0.67, 0.98, 0, palette.metal);
} else if (index === 2) {
// Voxel lathe and turning spindle.
cube(root, 1.45, 0.18, 0.9, 0, 0.28, 0, palette.woodDark);
cube(root, 0.16, 1.2, 0.18, -0.58, 0.86, 0, palette.wood);
cube(root, 0.16, 1.2, 0.18, 0.58, 0.86, 0, palette.wood);
cube(root, 0.2, 0.2, 1.4, 0, 1.12, 0, palette.metal);
cube(root, 0.52, 0.22, 0.22, 0, 1.12, -0.22, palette.woodLight);
cube(root, 0.18, 0.18, 0.18, 0, 1.12, 0.62, palette.woodPale);
} else {
// Master bench with drawers, tools, and canopy.
for (const x of [-0.78, 0.78]) {
for (const z of [-0.31, 0.31]) {
cube(root, 0.18, 0.9, 0.18, x, 0.63, z, palette.woodDark);
}
}
cube(root, 2.05, 0.22, 1.05, 0, 1.14, 0, palette.woodLight);
cube(root, 0.72, 0.42, 0.72, -0.42, 0.42, 0, palette.wood);
cube(root, 0.72, 0.42, 0.72, 0.42, 0.42, 0, palette.wood);
cube(root, 0.45, 0.07, 0.08, -0.42, 0.46, 0.39, palette.metal);
cube(root, 0.45, 0.07, 0.08, 0.42, 0.46, 0.39, palette.metal);
cube(root, 0.12, 0.85, 0.12, -0.84, 1.62, -0.34, palette.woodDark);
cube(root, 0.12, 0.85, 0.12, 0.84, 1.62, -0.34, palette.woodDark);
cube(root, 1.9, 0.16, 0.28, 0, 2.02, -0.34, palette.wood);
cube(root, 0.8, 0.08, 0.28, 0, 1.9, -0.34, palette.timber);
}
}
function createStoneStation(root, index) {
if (index === 0) {
// Crate of dressed blocks.
cube(root, 1.3, 0.18, 1.05, 0, 0.28, 0, palette.woodDark);
cube(root, 0.58, 0.48, 0.55, -0.28, 0.6, 0, palette.stone);
cube(root, 0.52, 0.68, 0.5, 0.25, 0.68, 0, palette.stoneLight);
cube(root, 0.45, 0.4, 0.42, -0.08, 1.06, 0.08, palette.stone);
for (const x of [-0.66, 0.66]) {
cube(root, 0.12, 0.68, 1.12, x, 0.58, 0, palette.wood);
}
cube(root, 1.42, 0.13, 0.14, 0, 0.72, 0.55, palette.woodLight);
} else if (index === 1) {
// Masonry wall courses.
for (let row = 0; row < 3; row++) {
const offset = row % 2 ? 0.28 : -0.28;
for (let col = 0; col < 3; col++) {
cube(
root,
0.52,
0.31,
0.62,
offset + (col - 1) * 0.55,
0.34 + row * 0.33,
0,
row % 2 ? palette.stone : palette.stoneLight
);
}
}
cube(root, 1.78, 0.16, 0.75, 0, 1.34, 0, palette.stoneDark);
cube(root, 0.16, 0.66, 0.16, -0.72, 0.75, 0.31, palette.wood);
cube(root, 0.16, 0.66, 0.16, 0.72, 0.75, 0.31, palette.wood);
} else if (index === 2) {
// Carving pedestal, block, and chisels.
cube(root, 1.35, 0.42, 1.0, 0, 0.34, 0, palette.stoneDark);
cube(root, 0.92, 0.52, 0.72, 0, 0.78, 0, palette.stone);
cube(root, 0.58, 0.56, 0.5, -0.08, 1.28, 0, palette.stoneLight);
cube(root, 0.08, 0.1, 0.55, 0.32, 1.44, 0, palette.metal);
cube(root, 0.2, 0.14, 0.2, 0.32, 1.48, -0.25, palette.woodLight);
cube(root, 0.55, 0.08, 0.12, 0.34, 1.05, 0.2, palette.woodLight, [0.25, 0, 0]);
} else {
// Master pillar with capital.
cube(root, 1.65, 0.26, 1.55, 0, 0.3, 0, palette.stoneDark);
cube(root, 1.1, 0.25, 1.1, 0, 0.55, 0, palette.stoneLight);
cube(root, 0.72, 0.52, 0.72, 0, 0.92, 0, palette.stone);
cube(root, 0.56, 0.48, 0.56, 0, 1.38, 0, palette.stoneLight);
cube(root, 0.72, 0.24, 0.72, 0, 1.71, 0, palette.stone);
cube(root, 1.1, 0.25, 1.1, 0, 1.94, 0, palette.stoneLight);
cube(root, 1.4, 0.16, 1.25, 0, 2.12, 0, palette.stone);
}
}
const rowZ = [3.15, 1.05, -1.05, -3.15];
for (const branchKey of ["timber", "stone"]) {
for (let i = 0; i < 4; i++) {
createNode(branchKey, i, rowZ[i]);
}
}
// Dependency stepping stones between stations.
for (const branchKey of ["timber", "stone"]) {
const branch = branches[branchKey];
for (let edge = 0; edge < 3; edge++) {
const centerZ = (rowZ[edge] + rowZ[edge + 1]) / 2;
for (let step = 0; step < 3; step++) {
const mat = material(branch.color, {
emissive: branch.color,
emissiveIntensity: 0,
roughness: 0.6
});
cube(
scene,
0.42,
0.075,
0.42,
branch.x,
0.08,
centerZ + (step - 1) * 0.32,
mat
);
connectorMaterials.push({
material: mat,
edge,
branch: branchKey
});
}
}
}
// Decorative crates, logs, blocks, and lanterns.
function crate(x, z, scale = 1) {
const root = new THREE.Group();
root.position.set(x, 0, z);
root.scale.setScalar(scale);
scene.add(root);
cube(root, 1.1, 0.14, 1.0, 0, 0.18, 0, palette.woodDark);
cube(root, 1.1, 0.14, 1.0, 0, 0.92, 0, palette.wood);
for (const xx of [-0.49, 0.49]) {
cube(root, 0.13, 0.82, 1.04, xx, 0.53, 0, palette.woodLight);
}
for (const zz of [-0.45, 0.45]) {
cube(root, 1.0, 0.12, 0.12, 0, 0.55, zz, palette.woodLight);
}
}
crate(-5.55, 3.85, 0.95);
crate(-5.15, 4.45, 0.66);
crate(5.35, 3.85, 0.92);
for (let i = 0; i < 4; i++) {
cube(scene, 0.42, 0.34, 0.42, 5.55, 0.3 + (i % 2) * 0.35, 3.8, palette.stone);
cube(scene, 0.62, 0.48, 0.62, 4.8, 0.32 + (i % 2) * 0.5, 4.5, palette.stoneLight);
}
function lantern(x, z) {
cube(scene, 0.12, 2.0, 0.12, x, 1.0, z, palette.metalDark);
cube(scene, 0.38, 0.45, 0.38, x, 2.1, z, palette.cream);
cube(scene, 0.48, 0.1, 0.48, x, 2.38, z, palette.metalDark);
cube(scene, 0.48, 0.1, 0.48, x, 1.82, z, palette.metalDark);
}
lantern(-6.05, -3.95);
lantern(6.05, -3.95);
const laneLabels = [];
for (const [key, x] of [["timber", -3.2], ["stone", 3.2]]) {
const el = document.createElement("div");
el.className = "lane-label";
el.textContent = key === "timber" ? "TIMBER" : "STONE";
el.style.setProperty("--lane", branches[key].color);
markerLayer.appendChild(el);
laneLabels.push({
element: el,
position: new THREE.Vector3(x, 0.55, 4.52)
});
}
function getNodeState(branchKey, index) {
if (state[branchKey][index]) return "complete";
if (index === 0 || state[branchKey][index - 1]) return "available";
return "locked";
}
function updateNodeVisuals() {
for (const visual of nodeVisuals) {
const branch = branches[visual.branch];
const nodeState = getNodeState(visual.branch, visual.index);
let color = branch.color;
let emissive = branch.color;
let intensity = 0.5;
if (nodeState === "complete") {
color = palette.success;
emissive = palette.success;
intensity = 0.45;
} else if (nodeState === "locked") {
color = palette.locked;
emissive = palette.locked;
intensity = 0.04;
}
visual.ringMaterial.color.set(color);
visual.ringMaterial.emissive.set(emissive);
visual.ringMaterial.emissiveIntensity = intensity;
visual.lock.visible = nodeState === "locked";
visual.marker.className = `node-marker ${nodeState}`;
visual.marker.style.setProperty("--node-color", branch.color);
visual.marker.innerHTML =
nodeState === "complete"
? "✓"
: `<b>${visual.index + 1}</b>${nodeState === "locked" ? '<span class="tiny-lock"></span>' : ""}`;
}
for (const item of connectorMaterials) {
const unlocked = state[item.branch][item.edge];
item.material.color.set(unlocked ? branches[item.branch].color : palette.floorB);
item.material.emissive.set(unlocked ? branches[item.branch].color : palette.floorB);
item.material.emissiveIntensity = unlocked ? 0.35 : 0;
}
}
function renderBranchPanel(branchKey) {
const branch = branches[branchKey];
const track = document.getElementById(`${branchKey}Track`);
const count = document.querySelector(`#${branchKey}Panel .branch-count`);
const next = document.getElementById(`${branchKey}Next`);
track.replaceChildren();
branch.tasks.forEach((task, index) => {
const nodeState = getNodeState(branchKey, index);
const button = document.createElement("button");
button.className = `step-button ${nodeState}`;
button.setAttribute("aria-label", `${task.title}: ${nodeState}`);
button.innerHTML = `
<span class="step-icon">${nodeState === "complete" ? "✓" : index + 1}</span>
<span class="step-name">${task.short}</span>
`;
button.addEventListener("click", () => handleNodeSelection(branchKey, index));
track.appendChild(button);
});
const completed = state[branchKey].filter(Boolean).length;
count.textContent = `${completed} / 4`;
next.textContent = completed === 4 ? "Branch mastered" : branch.tasks[completed].title;
}
function updateUI() {
renderBranchPanel("timber");
renderBranchPanel("stone");
updateNodeVisuals();
const total = Object.values(state).flat().filter(Boolean).length;
document.getElementById("totalText").textContent = `${total} / 8`;
document.getElementById("totalFill").style.width = `${(total / 8) * 100}%`;
}
function showToast(message) {
clearTimeout(toastTimer);
toast.textContent = message;
toast.classList.add("visible");
toastTimer = setTimeout(() => toast.classList.remove("visible"), 2800);
}
function handleNodeSelection(branchKey, index) {
const branch = branches[branchKey];
const task = branch.tasks[index];
const nodeState = getNodeState(branchKey, index);
if (nodeState === "locked") {
showToast(`Locked — complete “${branch.tasks[index - 1].title}” first.`);
return;
}
if (nodeState === "complete") {
showToast(`${task.title} is already complete.`);
return;
}
openTask(branchKey, index);
}
function openTask(branchKey, index) {
const branch = branches[branchKey];
const task = branch.tasks[index];
selectedTask = { branchKey, index };
modalCard.style.setProperty("--accent", branch.color);
document.getElementById("modalEyebrow").textContent = `${branch.name} · Task ${index + 1}`;
document.getElementById("modalTitle").textContent = task.title;
document.getElementById("modalDescription").textContent = task.description;
document.getElementById("modalRequirement").textContent = task.requirement;
document.getElementById("modalReward").textContent = task.reward;
document.getElementById("modalRequirementIcon").textContent = index === 0 ? "✓" : "↳";
taskModal.classList.remove("hidden");
completeButton.focus();
}
function closeTask() {
taskModal.classList.add("hidden");
selectedTask = null;
}
function spawnCelebration(branchKey, root) {
const color = branches[branchKey].color;
const origin = root.getWorldPosition(new THREE.Vector3());
origin.y += 1.25;
for (let i = 0; i < 26; i++) {
const size = 0.08 + Math.random() * 0.11;
const mesh = cube(
scene,
size,
size,
size,
origin.x + (Math.random() - 0.5) * 0.8,
origin.y + Math.random() * 0.5,
origin.z + (Math.random() - 0.5) * 0.8,
i % 3 === 0 ? palette.cream : color
);
particles.push({
mesh,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 3.3,
2.5 + Math.random() * 3,
(Math.random() - 0.5) * 3.3
),
spin: new THREE.Vector3(
Math.random() * 5,
Math.random() * 5,
Math.random() * 5
)
});
}
}
function completeSelectedTask() {
if (!selectedTask) return;
const { branchKey, index } = selectedTask;
const branch = branches[branchKey];
if (getNodeState(branchKey, index) !== "available") {
showToast("That task does not meet its prerequisite yet.");
closeTask();
return;
}
state[branchKey][index] = true;
updateUI();
const visual = nodeVisuals.find(
(node) => node.branch === branchKey && node.index === index
);
if (visual) spawnCelebration(branchKey, visual.root);
const allComplete = state[branchKey].every(Boolean);
showToast(
allComplete
? `${branch.name} mastered! The other branch remains independent.`
: `${branch.tasks[index].title} complete. ${branch.tasks[index].reward}.`
);
closeTask();
}
completeButton.addEventListener("click", completeSelectedTask);
document.getElementById("closeModalButton").addEventListener("click", closeTask);
taskModal.addEventListener("click", (event) => {
if (event.target === taskModal) closeTask();
});
document.getElementById("resetButton").addEventListener("click", () => {
state.timber.fill(false);
state.stone.fill(false);
closeTask();
updateUI();
for (const particle of particles) {
scene.remove(particle.mesh);
}
particles.length = 0;
showToast("Workshop reset. Both paths are ready for a new journey.");
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") closeTask();
});
// Custom camera controls: orbit, wheel zoom, and touch pinch.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const activePointers = new Map();
let pointerStart = null;
let dragDistance = 0;
let lastPinchDistance = 0;
function setRayFromEvent(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 pickNode(event) {
setRayFromEvent(event);
const hits = raycaster.intersectObjects(nodeRoots, true);
if (!hits.length) return null;
let object = hits[0].object;
while (object && !object.userData.nodeKey) object = object.parent;
return object || null;
}
function pointerDistance() {
const points = [...activePointers.values()];
if (points.length < 2) return 0;
return Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (activePointers.size === 1) {
pointerStart = { x: event.clientX, y: event.clientY };
dragDistance = 0;
}
if (activePointers.size === 2) {
lastPinchDistance = pointerDistance();
dragDistance = 999;
}
});
canvas.addEventListener("pointermove", (event) => {
if (activePointers.has(event.pointerId)) {
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
}
if (activePointers.size === 2) {
const distance = pointerDistance();
if (distance > 0 && lastPinchDistance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius * (lastPinchDistance / distance),
13,
34
);
}
lastPinchDistance = distance;
return;
}
if (activePointers.size === 1 && pointerStart) {
const dx = event.clientX - pointerStart.x;
const dy = event.clientY - pointerStart.y;
dragDistance = Math.max(dragDistance, Math.hypot(dx, dy));
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(desired.phi - dy * 0.005, 0.62, 1.38);
pointerStart = { x: event.clientX, y: event.clientY };
}
if (!activePointers.size) {
updateHover(event);
}
});
function endPointer(event) {
const wasClick = dragDistance < 6 && activePointers.size === 1;
activePointers.delete(event.pointerId);
if (wasClick) {
const node = pickNode(event);
if (node) {
handleNodeSelection(node.userData.branch, node.userData.index);
}
}
if (activePointers.size === 1) {
const remaining = [...activePointers.values()][0];
pointerStart = { x: remaining.x, y: remaining.y };
dragDistance = 999;
} else if (activePointers.size === 0) {
pointerStart = null;
dragDistance = 0;
lastPinchDistance = 0;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
13,
34
);
},
{ passive: false }
);
function updateHover(event) {
const node = pickNode(event);
const changedNode = node !== hoveredNode;
if (changedNode) {
if (hoveredNode) {
const oldVisual = nodeVisuals.find(
(visual) => visual.root === hoveredNode
);
if (oldVisual) oldVisual.marker.classList.remove("hovered");
}
hoveredNode = node;
if (hoveredNode) {
const visual = nodeVisuals.find((item) => item.root === hoveredNode);
if (visual) visual.marker.classList.add("hovered");
}
}
if (!node) {
canvas.style.cursor = "grab";
tooltip.classList.remove("visible");
return;
}
canvas.style.cursor = "pointer";
const branchKey = node.userData.branch;
const index = node.userData.index;
const branch = branches[branchKey];
const task = branch.tasks[index];
const nodeState = getNodeState(branchKey, index);
tooltip.style.setProperty("--tooltip-color", branch.color);
tooltip.innerHTML = `
<small>${branch.name} · ${nodeState}</small>
${task.title}
`;
tooltip.style.left = `${Math.min(event.clientX + 16, window.innerWidth - 270)}px`;
tooltip.style.top = `${Math.min(event.clientY + 16, window.innerHeight - 80)}px`;
tooltip.classList.add("visible");
}
canvas.addEventListener("pointerleave", () => {
if (!activePointers.size) {
hoveredNode = null;
tooltip.classList.remove("visible");
canvas.style.cursor = "grab";
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const projected = new THREE.Vector3();
function positionOverlay(element, worldPosition, visible = true) {
projected.copy(worldPosition).project(camera);
const onScreen =
visible &&
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
element.style.display = onScreen ? "flex" : "none";
if (!onScreen) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
orbit.theta = THREE.MathUtils.lerp(orbit.theta, desired.theta, 0.11);
orbit.phi = THREE.MathUtils.lerp(orbit.phi, desired.phi, 0.11);
orbit.radius = THREE.MathUtils.lerp(orbit.radius, desired.radius, 0.1);
updateCamera();
for (const visual of nodeVisuals) {
const nodeState = getNodeState(visual.branch, visual.index);
const isHovered = visual.root === hoveredNode;
const targetScale = isHovered ? 1.035 : 1;
const nextScale = THREE.MathUtils.lerp(visual.root.scale.x, targetScale, 0.14);
visual.root.scale.setScalar(nextScale);
if (nodeState === "available") {
visual.ringMaterial.emissiveIntensity = 0.55 + Math.sin(elapsed * 3.2) * 0.22;
}
const worldAnchor = visual.root.localToWorld(visual.anchor.clone());
positionOverlay(visual.marker, worldAnchor);
}
for (const label of laneLabels) {
positionOverlay(label.element, label.position);
}
forgeFlames.forEach((flame, index) => {
const flicker = 1 + Math.sin(elapsed * 9 + index * 2.1) * 0.16;
flame.scale.y = flicker;
flame.material.emissive?.set(palette.fire);
});
forgeLight.intensity = 20 + Math.sin(elapsed * 8) * 3 + Math.sin(elapsed * 13) * 1.5;
for (let i = particles.length - 1; i >= 0; i--) {
const particle = particles[i];
particle.velocity.y -= 7.5 * dt;
particle.mesh.position.addScaledVector(particle.velocity, dt);
particle.mesh.rotation.x += particle.spin.x * dt;
particle.mesh.rotation.y += particle.spin.y * dt;
particle.mesh.rotation.z += particle.spin.z * dt;
if (particle.mesh.position.y < -1.2) {
scene.remove(particle.mesh);
particles.splice(i, 1);
}
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateUI();
updateCamera();
renderer.render(scene, camera);
animate();
window.__voxelWorkshopReady = true;
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
setTimeout(() => document.getElementById("loading").remove(), 400);
});
</script>
</body>
</html>
```