Prompt specification
Build or customize the Three.js 3D scene "Changing Limb Count Changes the Gait" 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: Changing Limb Count Changes the Gait
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/changing-limb-count-changes-the-gait-x3724
Scene Description Prompt:
Create a fictional creature builder with several authored limb layouts. Pair each with a consistent support cycle and reject configurations lacking the game's required support conditions. Build this with Three.js from cdnjs as a voxel scene in one self-contained HTML file.
Working Three.js Starter (changing-limb-count-changes-the-gait-x3724):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Support Lab — Creature Builder</title>
<style>
:root {
color-scheme: dark;
--bg: #091019;
--panel: rgba(13, 22, 32, 0.94);
--panel-2: #121e2a;
--line: rgba(161, 193, 216, 0.15);
--text: #eaf4fb;
--muted: #8ea4b5;
--mint: #67f0ac;
--amber: #ffb45c;
--red: #ff6978;
--blue: #73b8ff;
--purple: #bd8cff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
width: 100%;
height: 100%;
}
header {
position: fixed;
inset: 0 0 auto 0;
height: 68px;
z-index: 20;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 22px;
background: rgba(8, 15, 23, 0.93);
border-bottom: 1px solid var(--line);
backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 32px;
height: 32px;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 3px;
transform: rotate(-8deg);
}
.brand-mark i {
background: var(--mint);
border-radius: 2px;
box-shadow: 0 0 14px rgba(103, 240, 172, 0.25);
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(7) {
opacity: 0.38;
}
.brand h1 {
margin: 0;
font-size: 15px;
letter-spacing: 0.16em;
white-space: nowrap;
}
.brand p {
margin: 3px 0 0;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.header-meta {
display: flex;
align-items: center;
gap: 9px;
}
.pill {
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
white-space: nowrap;
}
.pill.live {
color: var(--mint);
border-color: rgba(103, 240, 172, 0.25);
background: rgba(103, 240, 172, 0.06);
}
.pill.live::before {
content: "";
display: inline-block;
width: 6px;
height: 6px;
margin-right: 7px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 10px var(--mint);
}
#stage {
position: fixed;
inset: 68px 0 0 350px;
overflow: hidden;
background:
radial-gradient(circle at 68% 28%, rgba(58, 102, 135, 0.2), transparent 34%),
linear-gradient(180deg, #0b1722 0%, #081018 100%);
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
#panel {
position: fixed;
z-index: 15;
inset: 68px auto 0 0;
width: 350px;
overflow-y: auto;
padding: 18px 17px 24px;
background: var(--panel);
border-right: 1px solid var(--line);
box-shadow: 15px 0 45px rgba(0, 0, 0, 0.18);
scrollbar-width: thin;
scrollbar-color: #314558 transparent;
}
.section {
padding: 0 0 19px;
margin-bottom: 18px;
border-bottom: 1px solid var(--line);
}
.section:last-child {
margin-bottom: 0;
border-bottom: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
}
.section-title h2 {
margin: 0;
color: #d8e7f1;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.section-title span {
color: #63798a;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
}
#planCards {
display: grid;
gap: 8px;
}
.plan-card {
position: relative;
width: 100%;
display: grid;
grid-template-columns: 42px 1fr auto;
align-items: center;
gap: 10px;
padding: 11px;
text-align: left;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition: 150ms ease;
}
.plan-card:hover {
background: rgba(255, 255, 255, 0.05);
border-color: rgba(161, 193, 216, 0.3);
}
.plan-card.selected {
border-color: rgba(103, 240, 172, 0.58);
background: rgba(103, 240, 172, 0.075);
box-shadow: inset 3px 0 var(--mint);
}
.plan-icon {
width: 39px;
height: 39px;
display: grid;
place-items: center;
color: var(--mint);
font-size: 24px;
font-weight: 900;
}
.plan-name {
display: block;
margin-bottom: 4px;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.04em;
}
.plan-meta {
display: block;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.plan-count {
color: #7690a3;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
}
.control {
margin-top: 13px;
}
.control:first-of-type {
margin-top: 0;
}
.control-label {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 7px;
color: #b7c8d5;
font-size: 10px;
font-weight: 700;
}
.control-label output {
color: var(--mint);
font-variant-numeric: tabular-nums;
font-size: 10px;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 999px;
outline: none;
background: linear-gradient(90deg, var(--mint) var(--fill, 50%), #263746 var(--fill, 50%));
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 2px solid #dff9ed;
border-radius: 3px;
background: var(--mint);
box-shadow: 0 0 12px rgba(103, 240, 172, 0.32);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #dff9ed;
border-radius: 3px;
background: var(--mint);
}
.range-extents {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: #506778;
font-size: 8px;
letter-spacing: 0.08em;
}
.inline-actions {
display: flex;
gap: 8px;
margin-top: 12px;
}
.small-button,
.secondary-button {
border: 1px solid var(--line);
border-radius: 7px;
background: #142330;
cursor: pointer;
transition: 140ms ease;
}
.small-button {
padding: 7px 9px;
color: #b8cbd8;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
}
.small-button:hover,
.secondary-button:hover {
border-color: rgba(103, 240, 172, 0.4);
color: var(--mint);
}
.small-button {
flex: 1;
}
#legRoster {
display: grid;
gap: 6px;
}
.leg-row {
width: 100%;
display: grid;
grid-template-columns: 34px 1fr auto 22px;
align-items: center;
gap: 8px;
padding: 7px 9px;
border: 1px solid rgba(161, 193, 216, 0.1);
border-radius: 7px;
background: rgba(255, 255, 255, 0.018);
text-align: left;
cursor: pointer;
}
.leg-row:hover {
background: rgba(255, 255, 255, 0.05);
}
.leg-row.off {
opacity: 0.42;
}
.leg-code {
color: var(--text);
font-size: 10px;
font-weight: 900;
}
.leg-side {
color: var(--muted);
font-size: 9px;
}
.leg-group {
padding: 3px 6px;
border-radius: 4px;
color: #8fb7d1;
background: rgba(115, 184, 255, 0.1);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.08em;
}
.toggle {
position: relative;
width: 20px;
height: 11px;
border-radius: 20px;
background: #334654;
}
.toggle::after {
content: "";
position: absolute;
top: 2px;
left: 2px;
width: 7px;
height: 7px;
border-radius: 50%;
background: #8ca0ae;
transition: 140ms ease;
}
.leg-row:not(.off) .toggle {
background: rgba(103, 240, 172, 0.35);
}
.leg-row:not(.off) .toggle::after {
left: 11px;
background: var(--mint);
}
.palette-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 12px;
}
.swatch {
width: 25px;
height: 25px;
border: 2px solid transparent;
border-radius: 6px;
cursor: pointer;
box-shadow: inset 0 -7px 12px rgba(0, 0, 0, 0.18);
}
.swatch.selected {
border-color: white;
outline: 2px solid rgba(255, 255, 255, 0.18);
}
.crest-toggle {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 13px;
color: #aebfcd;
font-size: 10px;
}
.crest-toggle input {
accent-color: var(--mint);
}
.validation-box {
padding: 13px;
border: 1px solid rgba(103, 240, 172, 0.28);
border-radius: 9px;
background: rgba(103, 240, 172, 0.065);
transition: 180ms ease;
}
.validation-box.invalid {
border-color: rgba(255, 105, 120, 0.36);
background: rgba(255, 105, 120, 0.07);
}
.validation-heading {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--mint);
font-size: 11px;
font-weight: 950;
letter-spacing: 0.11em;
}
.invalid .validation-heading {
color: var(--red);
}
.status-light {
width: 8px;
height: 8px;
border-radius: 2px;
background: currentColor;
box-shadow: 0 0 11px currentColor;
}
.validation-text {
margin: 0;
color: #a9bdca;
font-size: 10px;
line-height: 1.55;
}
.rule-list {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 10px;
}
.rule {
padding: 4px 6px;
border: 1px solid var(--line);
border-radius: 4px;
color: #7f98aa;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.04em;
}
#deployBtn {
width: 100%;
margin-top: 11px;
padding: 12px;
border: 0;
border-radius: 8px;
background: var(--mint);
color: #062318;
font-size: 10px;
font-weight: 950;
letter-spacing: 0.12em;
cursor: pointer;
box-shadow: 0 8px 25px rgba(103, 240, 172, 0.12);
}
#deployBtn:hover:not(:disabled) {
transform: translateY(-1px);
filter: brightness(1.07);
}
#deployBtn:disabled {
color: #6e7e89;
background: #25313a;
box-shadow: none;
cursor: not-allowed;
}
.scene-heading {
position: absolute;
z-index: 3;
top: 22px;
left: 24px;
pointer-events: none;
}
.scene-heading .eyebrow {
color: var(--mint);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.scene-heading h2 {
margin: 5px 0 0;
font-size: clamp(18px, 2vw, 28px);
font-weight: 850;
letter-spacing: -0.03em;
}
.scene-heading p {
margin: 5px 0 0;
color: #708697;
font-size: 10px;
}
.legend {
position: absolute;
z-index: 3;
left: 24px;
bottom: 24px;
display: flex;
gap: 14px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(9, 18, 27, 0.78);
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: #8fa4b4;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--mint);
}
.legend-dot.swing {
background: var(--amber);
}
.legend-dot.com {
background: var(--purple);
}
.cycle-card {
position: absolute;
z-index: 4;
top: 22px;
right: 22px;
width: 284px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(10, 19, 28, 0.86);
backdrop-filter: blur(14px);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18);
}
.cycle-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.cycle-top h3 {
margin: 0 0 4px;
font-size: 10px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.cycle-top p {
margin: 0;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.phase-box {
flex: 0 0 auto;
padding: 6px 8px;
border: 1px solid rgba(115, 184, 255, 0.25);
border-radius: 6px;
color: var(--blue);
background: rgba(115, 184, 255, 0.06);
font-size: 9px;
font-weight: 900;
font-variant-numeric: tabular-nums;
}
#activeSupport {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin: 12px 0 10px;
min-height: 20px;
}
.support-chip {
padding: 4px 6px;
border-radius: 4px;
color: #072418;
background: var(--mint);
font-size: 8px;
font-weight: 950;
}
.support-chip.empty {
color: #8498a7;
background: #263541;
}
#cycleBars {
display: grid;
gap: 5px;
}
.cycle-row {
display: grid;
grid-template-columns: 30px 1fr;
align-items: center;
gap: 7px;
opacity: 0.5;
transition: opacity 120ms ease;
}
.cycle-row.active {
opacity: 1;
}
.cycle-row > span {
color: #8ca2b2;
font-size: 8px;
font-weight: 900;
}
.cycle-track {
position: relative;
height: 9px;
overflow: hidden;
border-radius: 2px;
background: #1b2935;
}
.contact-window {
position: absolute;
top: 0;
height: 100%;
background: rgba(103, 240, 172, 0.48);
}
.phase-dot {
position: absolute;
z-index: 2;
top: -2px;
width: 2px;
height: 13px;
background: white;
box-shadow: 0 0 5px white;
}
.cycle-controls {
display: grid;
grid-template-columns: 34px 1fr;
align-items: center;
gap: 9px;
margin-top: 12px;
}
#playBtn {
height: 30px;
border: 1px solid rgba(103, 240, 172, 0.25);
border-radius: 6px;
background: rgba(103, 240, 172, 0.08);
color: var(--mint);
cursor: pointer;
font-size: 11px;
}
#phase {
--fill: 50%;
}
.camera-help {
position: absolute;
z-index: 3;
right: 22px;
bottom: 24px;
color: #617a8c;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
#toast {
position: fixed;
z-index: 50;
left: 50%;
top: 84px;
padding: 11px 16px;
border: 1px solid rgba(103, 240, 172, 0.35);
border-radius: 8px;
background: #10271f;
color: var(--mint);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.06em;
opacity: 0;
transform: translate(-50%, -12px);
transition: 180ms ease;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 820px) {
#panel {
width: 310px;
}
#stage {
left: 310px;
}
.cycle-card {
width: 250px;
}
.header-meta .pill:first-child {
display: none;
}
}
@media (max-width: 650px) {
header {
height: 58px;
padding: 0 13px;
}
.brand p,
.header-meta {
display: none;
}
#panel {
inset: auto 0 0 0;
width: 100%;
height: 43vh;
border-top: 1px solid var(--line);
border-right: 0;
}
#stage {
inset: 58px 0 43vh 0;
}
.cycle-card {
top: 14px;
right: 12px;
width: 210px;
}
.scene-heading {
top: 15px;
left: 14px;
}
.scene-heading p,
.legend,
.camera-help {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
</div>
<div>
<h1>VOXEL SUPPORT LAB</h1>
<p>Field creature fabrication terminal</p>
</div>
</div>
<div class="header-meta">
<span class="pill">THREE.JS / CORE R160</span>
<span class="pill live">SIMULATION ONLINE</span>
</div>
</header>
<aside id="panel">
<section class="section">
<div class="section-title">
<h2>Authored limb layout</h2>
<span>SELECT ONE</span>
</div>
<div id="planCards"></div>
</section>
<section class="section">
<div class="section-title">
<h2>Anatomy controls</h2>
<span>LIVE BUILD</span>
</div>
<div class="control">
<label class="control-label" for="bodyLength">
<span>Body length</span>
<output id="bodyLengthOut"></output>
</label>
<input id="bodyLength" type="range" min="3" max="7" step="1" value="5">
<div class="range-extents"><span>COMPACT</span><span>ELONGATED</span></div>
</div>
<div class="control">
<label class="control-label" for="stance">
<span>Support stance width</span>
<output id="stanceOut"></output>
</label>
<input id="stance" type="range" min="1.4" max="3.2" step="0.05" value="2.2">
<div class="range-extents"><span>NARROW</span><span>WIDE</span></div>
</div>
<div class="control">
<label class="control-label" for="massX">
<span>Mass bias · longitudinal</span>
<output id="massXOut"></output>
</label>
<input id="massX" type="range" min="-1.4" max="1.4" step="0.05" value="0">
</div>
<div class="control">
<label class="control-label" for="massZ">
<span>Mass bias · lateral</span>
<output id="massZOut"></output>
</label>
<input id="massZ" type="range" min="-1.1" max="1.1" step="0.05" value="0">
</div>
<div class="inline-actions">
<button class="small-button" id="stressBtn">STRESS CENTER OF MASS</button>
<button class="small-button" id="resetBuildBtn">RESET BUILD</button>
</div>
<div class="palette-row" id="palette"></div>
<label class="crest-toggle">
<span>Armor crest</span>
<input id="crestToggle" type="checkbox" checked>
</label>
</section>
<section class="section">
<div class="section-title">
<h2>Limb loadout</h2>
<span>CLICK TO RETIRE</span>
</div>
<div id="legRoster"></div>
</section>
<section class="section">
<div class="section-title">
<h2>Support verification</h2>
<span>FULL CYCLE</span>
</div>
<div class="validation-box" id="validationBox">
<div class="validation-heading">
<i class="status-light"></i>
<span id="validationTitle">STABLE BUILD</span>
</div>
<p class="validation-text" id="validationText"></p>
<div class="rule-list">
<span class="rule">2+ CONTACTS</span>
<span class="rule">BILATERAL</span>
<span class="rule">COM ENCLOSED</span>
</div>
</div>
<button id="deployBtn">AUTHORIZE FOR FIELD TRIALS</button>
</section>
</aside>
<main id="stage">
<div id="viewport"></div>
<div class="scene-heading">
<div class="eyebrow">Specimen bay / <span id="cycleState">Trot A</span></div>
<h2 id="topPlanName">Houndline</h2>
<p>Authored gait cycle and geometric support validation</p>
</div>
<div class="cycle-card">
<div class="cycle-top">
<div>
<h3 id="cycleTitle">Diagonal Trot</h3>
<p id="cycleDesc"></p>
</div>
<div class="phase-box" id="phaseReadout">000°</div>
</div>
<div id="activeSupport"></div>
<div id="cycleBars"></div>
<div class="cycle-controls">
<button id="playBtn" aria-label="Pause cycle">Ⅱ</button>
<input id="phase" type="range" min="0" max="1000" step="1" value="80">
</div>
</div>
<div class="legend">
<div class="legend-item"><i class="legend-dot"></i> Grounded</div>
<div class="legend-item"><i class="legend-dot swing"></i> Swing</div>
<div class="legend-item"><i class="legend-dot com"></i> Center of mass</div>
</div>
<div class="camera-help">Drag to orbit · Wheel to zoom · Double-click to reset</div>
</main>
<div id="toast" role="status" aria-live="polite"></div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Authored creature layouts.
//
// Every layout owns a fixed support cycle. Legs reference cycle groups by
// ID, so the rendered gait and the validator always use the same timing.
// -------------------------------------------------------------------------
const PLANS = [
{
id: "houndline",
name: "Houndline",
classification: "Quadruped",
icon: "◆",
bodyLength: 5,
description: "Two diagonal support pairs",
cycle: {
name: "Diagonal Trot",
description: "FL + RR transfers to FR + RL with a short overlap.",
duty: 0.58,
groups: [
{ id: "A", offset: 0.0, legs: ["fl", "rr"] },
{ id: "B", offset: 0.5, legs: ["fr", "rl"] }
]
},
legs: [
{ id: "fl", code: "FL", side: 1, x: 0.44, swing: 1 },
{ id: "fr", code: "FR", side: -1, x: 0.44, swing: 1 },
{ id: "rl", code: "RL", side: 1, x: -0.44, swing: -1 },
{ id: "rr", code: "RR", side: -1, x: -0.44, swing: -1 }
]
},
{
id: "skeinwalker",
name: "Skeinwalker",
classification: "Hexapod",
icon: "⬡",
bodyLength: 6,
description: "Alternating tripod support",
cycle: {
name: "Alternating Tripod",
description: "Opposing tripods exchange support with a stable overlap.",
duty: 0.58,
groups: [
{ id: "A", offset: 0.0, legs: ["fl", "mr", "rl"] },
{ id: "B", offset: 0.5, legs: ["fr", "ml", "rr"] }
]
},
legs: [
{ id: "fl", code: "FL", side: 1, x: 0.46, swing: 1 },
{ id: "ml", code: "ML", side: 1, x: 0.00, swing: 1 },
{ id: "rl", code: "RL", side: 1, x: -0.46, swing: -1 },
{ id: "fr", code: "FR", side: -1, x: 0.46, swing: 1 },
{ id: "mr", code: "MR", side: -1, x: 0.00, swing: 1 },
{ id: "rr", code: "RR", side: -1, x: -0.46, swing: -1 }
]
},
{
id: "ridgeback",
name: "Ridgeback",
classification: "Octopod",
icon: "✣",
bodyLength: 7,
description: "Four-limb metachronal wave",
cycle: {
name: "Metachronal Wave",
description: "Two opposed four-foot waves maintain a broad support hull.",
duty: 0.58,
groups: [
{
id: "A",
offset: 0.0,
legs: ["lf", "lmb", "rmf", "rb"]
},
{
id: "B",
offset: 0.5,
legs: ["rf", "lmf", "rmb", "lb"]
}
]
},
legs: [
{ id: "lf", code: "LF", side: 1, x: 0.46, swing: 1 },
{ id: "lmf", code: "LM+", side: 1, x: 0.16, swing: 1 },
{ id: "lmb", code: "LM−", side: 1, x: -0.16, swing: -1 },
{ id: "lb", code: "LB", side: 1, x: -0.46, swing: -1 },
{ id: "rf", code: "RF", side: -1, x: 0.46, swing: 1 },
{ id: "rmf", code: "RM+", side: -1, x: 0.16, swing: 1 },
{ id: "rmb", code: "RM−", side: -1, x: -0.16, swing: -1 },
{ id: "rb", code: "RB", side: -1, x: -0.46, swing: -1 }
]
}
];
const PALETTES = [
{ body: 0x52d6a0, accent: 0x1b6f63, detail: 0xb7ffe1 },
{ body: 0xff9b73, accent: 0x9c493f, detail: 0xffdfbd },
{ body: 0x9d82ef, accent: 0x4b3e8c, detail: 0xe0d2ff },
{ body: 0x64b8ef, accent: 0x285c88, detail: 0xc8edff }
];
const state = {
plan: PLANS[0],
bodyLength: PLANS[0].bodyLength,
stance: 2.2,
massX: 0,
massZ: 0,
palette: 0,
crest: true,
enabled: new Set(),
phase: 0.08,
playing: true
};
const $ = (selector) => document.querySelector(selector);
const viewport = $("#viewport");
const stage = $("#stage");
// -------------------------------------------------------------------------
// Three.js scene.
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0a141e);
scene.fog = new THREE.Fog(0x0a141e, 13, 28);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 60);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xb9dcff, 0x16201f, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0dc, 3.3);
keyLight.position.set(5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4f9dff, 1.8);
rimLight.position.set(-6, 5, -7);
scene.add(rimLight);
const mintLight = new THREE.PointLight(0x55ffb0, 12, 10, 2);
mintLight.position.set(0, 4, 4);
scene.add(mintLight);
// A tiled voxel floor.
const tileGeometry = new THREE.BoxGeometry(0.97, 0.12, 0.97);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.92,
metalness: 0.02
});
const tileCountX = 19;
const tileCountZ = 15;
const floorTiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileCountX * tileCountZ
);
floorTiles.receiveShadow = true;
const matrix = new THREE.Matrix4();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let x = 0; x < tileCountX; x++) {
for (let z = 0; z < tileCountZ; z++) {
const worldX = x - (tileCountX - 1) / 2;
const worldZ = z - (tileCountZ - 1) / 2;
matrix.makeTranslation(worldX, -0.07, worldZ);
floorTiles.setMatrixAt(tileIndex, matrix);
const checker = (x + z) % 2 === 0;
const distanceFade = Math.min(1, Math.hypot(worldX, worldZ) / 12);
tileColor.setHex(checker ? 0x20303b : 0x192a35);
tileColor.lerp(new THREE.Color(0x0d1821), distanceFade * 0.42);
floorTiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
floorTiles.instanceMatrix.needsUpdate = true;
floorTiles.instanceColor.needsUpdate = true;
scene.add(floorTiles);
// Environmental voxel pylons.
const pylonMaterial = new THREE.MeshStandardMaterial({
color: 0x223744,
roughness: 0.85
});
const pylonTopMaterial = new THREE.MeshStandardMaterial({
color: 0x67f0ac,
emissive: 0x174b39,
emissiveIntensity: 1.5,
roughness: 0.55
});
function addPylon(x, z, height) {
const group = new THREE.Group();
const base = new THREE.Mesh(
new THREE.BoxGeometry(0.8, 0.8, 0.8),
pylonMaterial
);
base.position.y = 0.35;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const column = new THREE.Mesh(
new THREE.BoxGeometry(0.48, height, 0.48),
pylonMaterial
);
column.position.y = 0.75 + height / 2;
column.castShadow = true;
group.add(column);
const cap = new THREE.Mesh(
new THREE.BoxGeometry(0.56, 0.22, 0.56),
pylonTopMaterial
);
cap.position.y = 0.78 + height;
cap.castShadow = true;
group.add(cap);
group.position.set(x, 0, z);
scene.add(group);
}
addPylon(-6.4, -4.6, 1.2);
addPylon(6.4, -4.6, 1.8);
addPylon(-7, 4.4, 2.1);
addPylon(6.8, 4.6, 1.1);
// Validation halo, assembled from individual cubes.
const validationRing = new THREE.Group();
const validationMaterial = new THREE.MeshStandardMaterial({
color: 0x67f0ac,
emissive: 0x1d6d4c,
emissiveIntensity: 1.5,
roughness: 0.6
});
for (let i = 0; i < 24; i++) {
const angle = (i / 24) * Math.PI * 2;
const block = new THREE.Mesh(
new THREE.BoxGeometry(0.2, 0.08, 0.2),
validationMaterial
);
block.position.set(
Math.cos(angle) * 3.35,
0.015,
Math.sin(angle) * 3.35
);
validationRing.add(block);
}
scene.add(validationRing);
let creature = null;
let bodyGroup = null;
let comMarker = null;
let legVisuals = [];
// -------------------------------------------------------------------------
// Direct camera controls. No examples or addons are used.
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 1.35, 0),
theta: 0.72,
phi: 1.10,
radius: 11.5
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = 0.72;
cameraState.phi = 1.10;
cameraState.radius = 11.5;
updateCamera();
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.006,
0.48,
1.43
);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.009,
6.8,
18
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
$("#resetView")?.addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Geometry helpers.
// -------------------------------------------------------------------------
function makeBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function disposeObject(object) {
const geometries = new Set();
const materials = new Set();
object.traverse((child) => {
if (!child.isMesh) return;
geometries.add(child.geometry);
if (Array.isArray(child.material)) {
child.material.forEach((material) => materials.add(material));
} else {
materials.add(child.material);
}
});
geometries.forEach((geometry) => geometry.dispose());
materials.forEach((material) => material.dispose());
}
const upAxis = new THREE.Vector3(0, 1, 0);
function setBone(mesh, start, end, thickness) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(upAxis, direction.normalize());
mesh.scale.set(thickness, length, thickness);
}
function legKey(leg) {
return `${state.plan.id}:${leg.id}`;
}
function isEnabled(leg) {
return state.enabled.has(legKey(leg));
}
function groupForLeg(leg) {
return state.plan.cycle.groups.find((group) =>
group.legs.includes(leg.id)
);
}
function contactAt(phase, leg) {
const group = groupForLeg(leg);
const local = (phase - group.offset + 1) % 1;
return local < state.plan.cycle.duty;
}
function bodySpan() {
return (state.bodyLength - 1) * 0.62 + 0.72;
}
function footPosition(leg) {
return {
x: leg.x * bodySpan(),
z: leg.side * state.stance / 2
};
}
// -------------------------------------------------------------------------
// Creature construction.
// -------------------------------------------------------------------------
function rebuildCreature() {
if (creature) {
scene.remove(creature);
disposeObject(creature);
}
creature = new THREE.Group();
scene.add(creature);
bodyGroup = new THREE.Group();
creature.add(bodyGroup);
const palette = PALETTES[state.palette];
const bodyMaterial = new THREE.MeshStandardMaterial({
color: palette.body,
roughness: 0.66,
metalness: 0.08
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: palette.accent,
roughness: 0.74,
metalness: 0.08
});
const detailMaterial = new THREE.MeshStandardMaterial({
color: palette.detail,
emissive: palette.detail,
emissiveIntensity: 0.16,
roughness: 0.5
});
const eyeMaterial = new THREE.MeshStandardMaterial({
color: 0x071018,
emissive: 0x8ee7ff,
emissiveIntensity: 1.4,
roughness: 0.25
});
const pitch = 0.62;
const halfLength = (state.bodyLength - 1) * pitch / 2;
// Three-block body cross-sections.
for (let i = 0; i < state.bodyLength; i++) {
const x = i * pitch - halfLength;
makeBox(
bodyGroup,
new THREE.Vector3(0.58, 0.52, 0.58),
new THREE.Vector3(x, 1.72, -0.29),
accentMaterial
);
makeBox(
bodyGroup,
new THREE.Vector3(0.58, 0.52, 0.58),
new THREE.Vector3(x, 1.72, 0.29),
accentMaterial
);
makeBox(
bodyGroup,
new THREE.Vector3(0.58, 0.52, 0.58),
new THREE.Vector3(x, 2.24, 0),
bodyMaterial
);
}
// Head and snout.
const headX = halfLength + 0.68;
makeBox(
bodyGroup,
new THREE.Vector3(0.68, 0.64, 0.72),
new THREE.Vector3(headX, 2.19, 0),
bodyMaterial
);
makeBox(
bodyGroup,
new THREE.Vector3(0.42, 0.38, 0.52),
new THREE.Vector3(headX + 0.43, 2.07, 0),
accentMaterial
);
makeBox(
bodyGroup,
new THREE.Vector3(0.12, 0.14, 0.14),
new THREE.Vector3(headX + 0.39, 2.38, -0.22),
eyeMaterial,
false
);
makeBox(
bodyGroup,
new THREE.Vector3(0.12, 0.14, 0.14),
new THREE.Vector3(headX + 0.39, 2.38, 0.22),
eyeMaterial,
false
);
// Dorsal armor.
if (state.crest) {
for (let i = 0; i < state.bodyLength - 1; i++) {
const x = -halfLength + 0.45 + i * pitch;
const height = i === Math.floor((state.bodyLength - 2) / 2) ? 0.48 : 0.28;
makeBox(
bodyGroup,
new THREE.Vector3(0.30, height, 0.34),
new THREE.Vector3(x, 2.76, 0),
detailMaterial
);
}
}
// Block tail.
makeBox(
bodyGroup,
new THREE.Vector3(0.45, 0.34, 0.36),
new THREE.Vector3(-halfLength - 0.24, 1.83, 0),
accentMaterial
);
makeBox(
bodyGroup,
new THREE.Vector3(0.34, 0.28, 0.30),
new THREE.Vector3(-halfLength - 0.55, 1.93, 0),
detailMaterial
);
// Center-of-mass indicator.
comMarker = new THREE.Group();
const comMaterial = new THREE.MeshBasicMaterial({
color: 0xbd8cff,
transparent: true,
opacity: 0.92
});
makeBox(
comMarker,
new THREE.Vector3(0.15, 0.15, 0.15),
new THREE.Vector3(0, 0, 0),
comMaterial,
false
);
makeBox(
comMarker,
new THREE.Vector3(0.30, 0.06, 0.06),
new THREE.Vector3(0, 0, 0),
comMaterial,
false
);
makeBox(
comMarker,
new THREE.Vector3(0.06, 0.30, 0.06),
new THREE.Vector3(0, 0, 0),
comMaterial,
false
);
comMarker.position.set(state.massX, 3.26, state.massZ);
creature.add(comMarker);
// Animated legs.
legVisuals = state.plan.legs.map((leg) => {
const root = new THREE.Group();
creature.add(root);
const legMaterial = new THREE.MeshStandardMaterial({
color: 0x36556a,
roughness: 0.64,
metalness: 0.05
});
const footMaterial = new THREE.MeshStandardMaterial({
color: 0x67f0ac,
emissive: 0x164b35,
emissiveIntensity: 1.0,
roughness: 0.56
});
const hip = makeBox(
root,
new THREE.Vector3(0.28, 0.25, 0.28),
new THREE.Vector3(0, 0, 0),
accentMaterial
);
const upper = makeBox(
root,
new THREE.Vector3(1, 1, 1),
new THREE.Vector3(0, 0, 0),
legMaterial
);
const lower = makeBox(
root,
new THREE.Vector3(1, 1, 1),
new THREE.Vector3(0, 0, 0),
legMaterial
);
const foot = makeBox(
root,
new THREE.Vector3(0.58, 0.18, 0.46),
new THREE.Vector3(0, 0, 0),
footMaterial
);
return {
leg,
root,
hip,
upper,
lower,
foot,
legMaterial,
footMaterial
};
});
updateComMarker();
animateCreature();
}
function updateComMarker() {
if (!comMarker) return;
comMarker.position.set(state.massX, 3.26, state.massZ);
}
function animateCreature() {
if (!creature || !bodyGroup) return;
bodyGroup.position.y = Math.sin(state.phase * Math.PI * 4) * 0.025;
for (const visual of legVisuals) {
const { leg } = visual;
const enabled = isEnabled(leg);
visual.root.visible = enabled;
if (!enabled) continue;
const base = footPosition(leg);
const group = groupForLeg(leg);
const local = (state.phase - group.offset + 1) % 1;
const grounded = local < state.plan.cycle.duty;
let footX = base.x;
let footY = 0.11;
if (!grounded) {
const swingProgress = (local - state.plan.cycle.duty) /
(1 - state.plan.cycle.duty);
footX += leg.swing * 0.34 * Math.sin(Math.PI * swingProgress);
footY += Math.sin(Math.PI * swingProgress) * 0.43;
}
const hipPosition = new THREE.Vector3(
base.x,
1.48,
leg.side * 0.56
);
const kneePosition = new THREE.Vector3(
(hipPosition.x + footX) * 0.5,
0.92 + (footY - 0.11) * 0.22,
THREE.MathUtils.lerp(hipPosition.z, base.z, 0.57) + leg.side * 0.10
);
const anklePosition = new THREE.Vector3(
footX,
footY + 0.12,
base.z
);
visual.hip.position.copy(hipPosition);
setBone(visual.upper, hipPosition, kneePosition, 0.23);
setBone(visual.lower, kneePosition, anklePosition, 0.20);
visual.foot.position.set(footX, footY, base.z);
const materialColor = grounded ? 0x67f0ac : 0xffb45c;
const emissiveColor = grounded ? 0x164b35 : 0x56300e;
visual.footMaterial.color.setHex(materialColor);
visual.footMaterial.emissive.setHex(emissiveColor);
visual.legMaterial.color.setHex(grounded ? 0x477568 : 0x6a5540);
}
}
// -------------------------------------------------------------------------
// Geometric support validation.
//
// Required game conditions:
// 1. At least two feet are grounded at every sampled cycle phase.
// 2. Grounded feet exist on both sides of the creature.
// 3. The center-of-mass projection is inside the convex hull of all
// grounded feet at every sampled cycle phase.
// -------------------------------------------------------------------------
function cross2(a, b, c) {
return (b.x - a.x) * (c.z - a.z) - (b.z - a.z) * (c.x - a.x);
}
function convexHull(points) {
const sorted = points
.slice()
.sort((a, b) => a.x - b.x || a.z - b.z);
if (sorted.length <= 2) return sorted;
const lower = [];
for (const point of sorted) {
while (
lower.length >= 2 &&
cross2(lower[lower.length - 2], lower[lower.length - 1], point) <= 0
) {
lower.pop();
}
lower.push(point);
}
const upper = [];
for (let i = sorted.length - 1; i >= 0; i--) {
const point = sorted[i];
while (
upper.length >= 2 &&
cross2(upper[upper.length - 2], upper[upper.length - 1], point) <= 0
) {
upper.pop();
}
upper.push(point);
}
lower.pop();
upper.pop();
return lower.concat(upper);
}
function pointOnSegment(point, a, b, epsilon = 0.0001) {
const ab = { x: b.x - a.x, z: b.z - a.z };
const ap = { x: point.x - a.x, z: point.z - a.z };
const lengthSquared = ab.x * ab.x + ab.z * ab.z;
if (lengthSquared === 0) return false;
const cross = Math.abs(ab.x * ap.z - ab.z * ap.x);
if (cross / Math.sqrt(lengthSquared) > epsilon) return false;
const dot = ap.x * ab.x + ap.z * ab.z;
return dot >= -epsilon && dot <= lengthSquared + epsilon;
}
function pointInsideHull(point, hull) {
if (hull.length < 2) return false;
if (hull.length === 2) {
return pointOnSegment(point, hull[0], hull[1]);
}
for (let i = 0; i < hull.length; i++) {
const a = hull[i];
const b = hull[(i + 1) % hull.length];
if (cross2(a, b, point) < -0.0001) return false;
}
return true;
}
function validateBuild() {
const sampleCount = 120;
const com = { x: state.massX, z: state.massZ };
let minimumContacts = Infinity;
let maximumContacts = 0;
let failure = null;
for (let sample = 0; sample < sampleCount; sample++) {
const phase = sample / sampleCount;
const active = state.plan.legs.filter((leg) =>
isEnabled(leg) && contactAt(phase, leg)
);
const count = active.length;
minimumContacts = Math.min(minimumContacts, count);
maximumContacts = Math.max(maximumContacts, count);
if (count < 2 && !failure) {
failure = {
phase,
reason: `Only ${count} foot contact${count === 1 ? "" : "s"} at phase ${Math.round(phase * 100)}%.`
};
break;
}
const hasLeft = active.some((leg) => leg.side > 0);
const hasRight = active.some((leg) => leg.side < 0);
if ((!hasLeft || !hasRight) && !failure) {
failure = {
phase,
reason: `Support becomes unilateral at phase ${Math.round(phase * 100)}%.`
};
break;
}
const points = active.map(footPosition);
const hull = convexHull(points);
if (!pointInsideHull(com, hull) && !failure) {
failure = {
phase,
reason: `Center of mass leaves the support polygon at phase ${Math.round(phase * 100)}%.`
};
break;
}
}
if (!Number.isFinite(minimumContacts)) minimumContacts = 0;
return {
valid: !failure,
failure,
minimumContacts,
maximumContacts
};
}
function updateValidation() {
const result = validateBuild();
const box = $("#validationBox");
box.classList.toggle("invalid", !result.valid);
if (result.valid) {
$("#validationTitle").textContent = "STABLE BUILD";
$("#validationText").textContent =
`Approved: ${result.minimumContacts}–${result.maximumContacts} grounded contacts, ` +
"bilateral support, and center-of-mass containment throughout the authored cycle.";
} else {
$("#validationTitle").textContent = "REJECTED BUILD";
$("#validationText").textContent =
`${result.failure.reason} The game requires at least two bilateral contacts ` +
"with the center of mass inside their support polygon.";
}
$("#deployBtn").disabled = !result.valid;
validationMaterial.color.setHex(result.valid ? 0x67f0ac : 0xff6978);
validationMaterial.emissive.setHex(result.valid ? 0x1d6d4c : 0x6d1c28);
}
// -------------------------------------------------------------------------
// Interface.
// -------------------------------------------------------------------------
function renderPlanCards() {
$("#planCards").innerHTML = PLANS.map((plan) => `
<button
class="plan-card ${plan.id === state.plan.id ? "selected" : ""}"
data-plan="${plan.id}"
>
<span class="plan-icon">${plan.icon}</span>
<span>
<span class="plan-name">${plan.name}</span>
<span class="plan-meta">${plan.classification} · ${plan.description}</span>
</span>
<span class="plan-count">${plan.legs.length}L</span>
</button>
`).join("");
}
function renderLegRoster() {
$("#legRoster").innerHTML = state.plan.legs.map((leg) => {
const group = groupForLeg(leg);
const enabled = isEnabled(leg);
return `
<button
class="leg-row ${enabled ? "" : "off"}"
data-leg="${leg.id}"
aria-pressed="${enabled}"
>
<span class="leg-code">${leg.code}</span>
<span class="leg-side">${leg.side > 0 ? "LEFT SIDE" : "RIGHT SIDE"}</span>
<span class="leg-group">GROUP ${group.id}</span>
<span class="toggle"></span>
</button>
`;
}).join("");
}
function renderPalette() {
$("#palette").innerHTML = PALETTES.map((palette, index) => `
<button
class="swatch ${index === state.palette ? "selected" : ""}"
data-palette="${index}"
title="Select palette ${index + 1}"
style="background:#${palette.body.toString(16).padStart(6, "0")}"
aria-label="Select palette ${index + 1}"
></button>
`).join("");
}
function contactSegments(offset, duty) {
const start = offset;
const end = offset + duty;
if (end <= 1) return [[start, end]];
return [[start, 1], [0, end - 1]];
}
function renderCycleBars() {
$("#cycleBars").innerHTML = state.plan.legs.map((leg) => {
const group = groupForLeg(leg);
const segments = contactSegments(group.offset, state.plan.cycle.duty);
const windows = segments.map(([start, end]) => `
<i
class="contact-window"
style="left:${start * 100}%;width:${(end - start) * 100}%"
></i>
`).join("");
return `
<div class="cycle-row" data-cycle-leg="${leg.id}">
<span>${leg.code}</span>
<div class="cycle-track">
${windows}
<i class="phase-dot"></i>
</div>
</div>
`;
}).join("");
}
function updateCycleUI() {
const active = state.plan.legs.filter((leg) =>
isEnabled(leg) && contactAt(state.phase, leg)
);
const activeGroups = state.plan.cycle.groups.filter((group) =>
group.legs.some((id) => {
const leg = state.plan.legs.find((candidate) => candidate.id === id);
return isEnabled(leg) && contactAt(state.phase, leg);
})
);
$("#phaseReadout").textContent =
`${String(Math.floor(state.phase * 360)).padStart(3, "0")}°`;
$("#cycleState").textContent = activeGroups.length
? activeGroups.map((group) => group.id).join(" + ")
: "NO SUPPORT";
$("#activeSupport").innerHTML = active.length
? active.map((leg) => `<span class="support-chip">${leg.code}</span>`).join("")
: `<span class="support-chip empty">NO CONTACT</span>`;
document.querySelectorAll("[data-cycle-leg]").forEach((row) => {
const leg = state.plan.legs.find(
(candidate) => candidate.id === row.dataset.cycleLeg
);
row.classList.toggle("active", active.includes(leg));
const dot = row.querySelector(".phase-dot");
dot.style.left = `${state.phase * 100}%`;
});
}
function updateRange(input) {
const minimum = Number(input.min);
const maximum = Number(input.max);
const percentage = ((Number(input.value) - minimum) / (maximum - minimum)) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
function updateControlReadouts() {
$("#bodyLengthOut").textContent = `${state.bodyLength} vox`;
$("#stanceOut").textContent = `${state.stance.toFixed(2)} m`;
$("#massXOut").textContent = `${state.massX >= 0 ? "+" : ""}${state.massX.toFixed(2)} m`;
$("#massZOut").textContent = `${state.massZ >= 0 ? "+" : ""}${state.massZ.toFixed(2)} m`;
$("#bodyLength").value = state.bodyLength;
$("#stance").value = state.stance;
$("#massX").value = state.massX;
$("#massZ").value = state.massZ;
document.querySelectorAll('input[type="range"]').forEach(updateRange);
}
function updateHeader() {
$("#topPlanName").textContent = state.plan.name;
$("#cycleTitle").textContent = state.plan.cycle.name;
$("#cycleDesc").textContent = state.plan.cycle.description;
}
function selectPlan(plan) {
state.plan = plan;
state.bodyLength = plan.bodyLength;
state.enabled = new Set(plan.legs.map(legKey));
renderPlanCards();
renderLegRoster();
renderCycleBars();
updateHeader();
updateControlReadouts();
rebuildCreature();
updateValidation();
updateCycleUI();
}
function resetBuild() {
state.bodyLength = state.plan.bodyLength;
state.stance = 2.2;
state.massX = 0;
state.massZ = 0;
state.palette = 0;
state.crest = true;
state.enabled = new Set(state.plan.legs.map(legKey));
$("#crestToggle").checked = true;
renderPalette();
renderLegRoster();
updateControlReadouts();
rebuildCreature();
updateValidation();
}
$("#planCards").addEventListener("click", (event) => {
const button = event.target.closest("[data-plan]");
if (!button) return;
const plan = PLANS.find((candidate) => candidate.id === button.dataset.plan);
if (plan) selectPlan(plan);
});
$("#legRoster").addEventListener("click", (event) => {
const button = event.target.closest("[data-leg]");
if (!button) return;
const leg = state.plan.legs.find(
(candidate) => candidate.id === button.dataset.leg
);
if (!leg) return;
const key = legKey(leg);
if (state.enabled.has(key)) {
state.enabled.delete(key);
} else {
state.enabled.add(key);
}
renderLegRoster();
animateCreature();
updateValidation();
updateCycleUI();
});
$("#palette").addEventListener("click", (event) => {
const button = event.target.closest("[data-palette]");
if (!button) return;
state.palette = Number(button.dataset.palette);
renderPalette();
rebuildCreature();
});
$("#bodyLength").addEventListener("input", (event) => {
state.bodyLength = Number(event.target.value);
updateControlReadouts();
rebuildCreature();
updateValidation();
});
$("#stance").addEventListener("input", (event) => {
state.stance = Number(event.target.value);
updateControlReadouts();
rebuildCreature();
updateValidation();
});
$("#massX").addEventListener("input", (event) => {
state.massX = Number(event.target.value);
updateControlReadouts();
updateComMarker();
updateValidation();
});
$("#massZ").addEventListener("input", (event) => {
state.massZ = Number(event.target.value);
updateControlReadouts();
updateComMarker();
updateValidation();
});
$("#crestToggle").addEventListener("change", (event) => {
state.crest = event.target.checked;
rebuildCreature();
});
$("#stressBtn").addEventListener("click", () => {
const centered = Math.abs(state.massX) < 0.05 && Math.abs(state.massZ) < 0.05;
state.massX = centered ? 1.15 : 0;
state.massZ = centered ? 0.25 : 0;
updateControlReadouts();
updateComMarker();
updateValidation();
});
$("#resetBuildBtn").addEventListener("click", resetBuild);
$("#playBtn").addEventListener("click", () => {
state.playing = !state.playing;
$("#playBtn").textContent = state.playing ? "Ⅱ" : "▶";
});
$("#phase").addEventListener("input", (event) => {
state.phase = Number(event.target.value) / 1000;
state.playing = false;
$("#playBtn").textContent = "▶";
updateRange(event.target);
animateCreature();
updateCycleUI();
});
$("#deployBtn").addEventListener("click", () => {
const toast = $("#toast");
toast.textContent =
`${state.plan.name.toUpperCase()} AUTHORIZED — ${state.plan.cycle.name.toUpperCase()} CYCLE LOCKED`;
toast.classList.add("show");
clearTimeout(toast.hideTimer);
toast.hideTimer = setTimeout(() => toast.classList.remove("show"), 2600);
});
document.addEventListener("keydown", (event) => {
const tag = event.target.tagName;
if (tag === "INPUT" || tag === "BUTTON") return;
if (event.code === "Space") {
event.preventDefault();
state.playing = !state.playing;
$("#playBtn").textContent = state.playing ? "Ⅱ" : "▶";
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// -------------------------------------------------------------------------
// Resize and render loop.
// -------------------------------------------------------------------------
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
let previousTime = performance.now();
function render(now) {
requestAnimationFrame(render);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (state.playing) {
state.phase = (state.phase + delta * 0.19) % 1;
$("#phase").value = Math.round(state.phase * 1000);
updateRange($("#phase"));
}
animateCreature();
updateCycleUI();
renderer.render(scene, camera);
}
// Initialize.
state.enabled = new Set(state.plan.legs.map(legKey));
renderPlanCards();
renderLegRoster();
renderPalette();
renderCycleBars();
updateHeader();
updateControlReadouts();
rebuildCreature();
updateValidation();
updateCycleUI();
resize();
updateCamera();
requestAnimationFrame(render);
</script>
</body>
</html>
```