Prompt specification
Build or customize the Three.js 3D scene "Robot With Idle Carry and Recharge States" 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: Robot With Idle Carry and Recharge States
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/robot-with-idle-carry-and-recharge-states-x3521
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Model one robot beside three state symbols and a battery meter. Distinguish internal state from body position and show which action is available in each state.
Working Three.js Starter (robot-with-idle-carry-and-recharge-states-x3521):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>State / Body — Stylized Robot Scene</title>
<style>
:root {
--state: #8fffbd;
--cyan: #67d9ff;
--panel: rgba(9, 20, 33, 0.78);
--border: rgba(177, 218, 241, 0.16);
--text: #eef8ff;
--muted: #91a9ba;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111d;
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
.hud {
position: fixed;
top: 25px;
left: 28px;
z-index: 10;
max-width: 430px;
pointer-events: none;
}
.kicker {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(26px, 3.2vw, 45px);
font-weight: 750;
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 390px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.readouts {
position: fixed;
top: 25px;
right: 28px;
z-index: 10;
display: grid;
grid-template-columns: repeat(3, minmax(125px, 1fr));
gap: 9px;
pointer-events: none;
}
.readout {
min-width: 130px;
padding: 12px 14px;
border: 1px solid var(--border);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(12px);
}
.readout span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.readout strong {
display: block;
font-size: 15px;
letter-spacing: 0.03em;
}
#internalState {
color: var(--state);
}
.dock {
position: fixed;
z-index: 20;
left: 50%;
bottom: 22px;
display: flex;
align-items: stretch;
gap: 0;
width: min(790px, calc(100% - 28px));
padding: 12px;
transform: translateX(-50%);
border: 1px solid var(--border);
border-radius: 18px;
background: rgba(7, 17, 29, 0.86);
box-shadow: 0 18px 70px rgba(0, 0, 0, 0.38);
backdrop-filter: blur(18px);
}
.control-group {
flex: 1;
min-width: 0;
padding: 2px 16px;
}
.control-group + .control-group {
border-left: 1px solid var(--border);
}
.control-label {
display: block;
margin-bottom: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.button-row {
display: flex;
gap: 7px;
}
button {
border: 0;
color: var(--text);
font: inherit;
cursor: pointer;
}
.position-button {
flex: 1;
padding: 9px 11px;
border: 1px solid rgba(160, 204, 230, 0.15);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.05em;
transition:
background 160ms ease,
border-color 160ms ease,
color 160ms ease,
transform 160ms ease;
}
.position-button:hover {
transform: translateY(-1px);
border-color: rgba(103, 217, 255, 0.45);
background: rgba(103, 217, 255, 0.08);
}
.position-button.active {
border-color: rgba(103, 217, 255, 0.7);
color: var(--cyan);
background: rgba(103, 217, 255, 0.13);
box-shadow: inset 0 0 18px rgba(103, 217, 255, 0.05);
}
#actionButton {
width: 100%;
padding: 10px 15px;
border: 1px solid color-mix(in srgb, var(--state) 65%, transparent);
border-radius: 10px;
color: #07111d;
background: var(--state);
box-shadow: 0 0 25px color-mix(in srgb, var(--state) 22%, transparent);
font-size: 12px;
font-weight: 900;
letter-spacing: 0.11em;
transition:
transform 160ms ease,
filter 160ms ease;
}
#actionButton:hover {
transform: translateY(-1px);
filter: brightness(1.08);
}
#actionButton:active {
transform: translateY(1px);
}
#actionHint {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 10px;
}
.hint {
position: fixed;
z-index: 10;
right: 28px;
bottom: 25px;
color: rgba(177, 198, 213, 0.62);
font-size: 10px;
line-height: 1.7;
text-align: right;
pointer-events: none;
}
.toast {
position: fixed;
z-index: 30;
left: 50%;
bottom: 132px;
max-width: calc(100% - 30px);
padding: 10px 15px;
transform:
translate(-50%, 12px)
scale(0.97);
border: 1px solid rgba(103, 217, 255, 0.3);
border-radius: 10px;
opacity: 0;
color: #dff6ff;
background: rgba(8, 22, 35, 0.92);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
font-size: 11px;
pointer-events: none;
transition:
opacity 180ms ease,
transform 180ms ease;
}
.toast.show {
opacity: 1;
transform:
translate(-50%, 0)
scale(1);
}
@media (max-width: 900px) {
.hud {
top: 18px;
left: 18px;
}
.subtitle {
max-width: 290px;
font-size: 11px;
}
.readouts {
top: 18px;
right: 18px;
grid-template-columns: 1fr;
}
.readout {
min-width: 130px;
padding: 8px 11px;
}
.readout span {
margin-bottom: 2px;
font-size: 8px;
}
.readout strong {
font-size: 12px;
}
.hint {
display: none;
}
}
@media (max-width: 650px) {
.hud {
max-width: calc(100% - 36px);
}
.subtitle {
display: none;
}
.readouts {
top: auto;
right: 14px;
bottom: 142px;
left: 14px;
grid-template-columns: repeat(3, 1fr);
}
.readout {
min-width: 0;
}
.dock {
bottom: 12px;
flex-wrap: wrap;
width: calc(100% - 20px);
padding: 9px;
}
.control-group {
flex-basis: 50%;
padding: 4px 8px;
}
.control-group + .control-group {
border-left: 0;
}
.control-group:last-child {
border-top: 1px solid var(--border);
padding-top: 10px;
}
.position-button {
padding: 8px 5px;
font-size: 9px;
}
.toast {
bottom: 225px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="hud">
<div class="kicker">Robotics / State Visualization</div>
<h1>STATE / BODY</h1>
<p class="subtitle">
One robot, two independent axes. The illuminated program state controls
behavior; the floor position controls only where the robot stands.
</p>
</header>
<aside class="readouts">
<div class="readout">
<span>Internal State</span>
<strong id="internalState">READY</strong>
</div>
<div class="readout">
<span>Body Position</span>
<strong id="bodyPosition">CENTER</strong>
</div>
<div class="readout">
<span>Battery</span>
<strong id="batteryValue">72%</strong>
</div>
</aside>
<section class="dock">
<div class="control-group">
<span class="control-label">Body Position / Spatial Only</span>
<div class="button-row">
<button class="position-button" data-position="0">LEFT</button>
<button class="position-button active" data-position="1">CENTER</button>
<button class="position-button" data-position="2">RIGHT</button>
</div>
</div>
<div class="control-group">
<span class="control-label">Available Action / Current State</span>
<button id="actionButton">EXECUTE</button>
<small id="actionHint">READY → WORKING</small>
</div>
</section>
<div class="hint">
Drag to orbit · Scroll to zoom<br />
Click a state symbol · 1/2/3 state · ←/→ position · Space action
</div>
<div id="toast" class="toast"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111d);
scene.fog = new THREE.Fog(0x07111d, 20, 48);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0.72, 1.48, 0);
const orbit = {
yaw: 0.18,
pitch: 0.36,
radius: 9.8
};
let responsiveCameraScale = 1;
function updateCamera() {
const radius = orbit.radius * responsiveCameraScale;
const horizontal = Math.cos(orbit.pitch) * radius;
camera.position.set(
cameraTarget.x + Math.sin(orbit.yaw) * horizontal,
cameraTarget.y + Math.sin(orbit.pitch) * radius,
cameraTarget.z + Math.cos(orbit.yaw) * horizontal
);
camera.lookAt(cameraTarget);
}
// -------------------------------------------------------------------------
// Lighting and environment
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb9dcff, 0x071018, 1.8));
const keyLight = new THREE.DirectionalLight(0xe9f6ff, 3.2);
keyLight.position.set(-4, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5677ff, 2.2);
rimLight.position.set(6, 4, -4);
scene.add(rimLight);
const stateLight = new THREE.PointLight(0x8fffbd, 7, 7, 2);
stateLight.position.set(-1.35, 2.2, 1.5);
scene.add(stateLight);
const blueLight = new THREE.PointLight(0x39bfff, 5, 8, 2);
blueLight.position.set(2.2, 1.0, 2.2);
scene.add(blueLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0b1824,
roughness: 0.8,
metalness: 0.15
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 32),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x31516a, 0x173043);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.2;
scene.add(grid);
const backWall = new THREE.Mesh(
new THREE.PlaneGeometry(32, 16),
new THREE.MeshStandardMaterial({
color: 0x08131f,
roughness: 0.95
})
);
backWall.position.set(0, 7, -5.7);
backWall.receiveShadow = true;
scene.add(backWall);
const decorativeRing = new THREE.Mesh(
new THREE.TorusGeometry(2.42, 0.012, 6, 96),
new THREE.MeshBasicMaterial({
color: 0x3c91bd,
transparent: true,
opacity: 0.24
})
);
decorativeRing.position.set(1.55, 1.9, -1.08);
scene.add(decorativeRing);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x06101a,
transparent: true,
opacity: 0.72
});
function addBox(parent, size, material, position, withEdges = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
if (withEdges) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
edgeMaterial
);
mesh.add(edges);
}
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
material,
position,
segments = 20
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addSphere(parent, radius, material, position, scale = null) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 24, 16),
material
);
mesh.position.set(position[0], position[1], position[2]);
if (scale) {
mesh.scale.set(scale[0], scale[1], scale[2]);
}
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Canvas-based labels; no external fonts or texture assets
// -------------------------------------------------------------------------
function createCanvasTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.clearRect(0, 0, width, height);
draw(context, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function drawText(
context,
width,
height,
text,
color,
fontSize = 62,
alignY = 0.52
) {
context.fillStyle = color;
context.font = `800 ${fontSize}px system-ui, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, width / 2, height * alignY);
}
function makeTextPlane(
text,
worldWidth,
worldHeight,
color = "#eef8ff",
fontSize = 62
) {
const texture = createCanvasTexture(512, 128, (ctx, w, h) => {
drawText(ctx, w, h, text, color, fontSize);
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(worldWidth, worldHeight),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
return mesh;
}
function updateTextPlane(
mesh,
text,
color = "#eef8ff",
fontSize = 62
) {
const oldTexture = mesh.material.map;
const texture = createCanvasTexture(512, 128, (ctx, w, h) => {
drawText(ctx, w, h, text, color, fontSize);
});
mesh.material.map = texture;
mesh.material.needsUpdate = true;
oldTexture.dispose();
}
function makeActionPlane(action, color) {
const texture = createCanvasTexture(512, 220, (ctx, w, h) => {
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#8299aa";
ctx.font = "800 25px system-ui, sans-serif";
ctx.fillText("AVAILABLE ACTION", w / 2, 53);
ctx.fillStyle = color;
ctx.font = "850 49px system-ui, sans-serif";
ctx.fillText(action, w / 2, 135);
ctx.strokeStyle = color;
ctx.globalAlpha = 0.38;
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(82, 181);
ctx.lineTo(430, 181);
ctx.stroke();
});
return new THREE.Mesh(
new THREE.PlaneGeometry(1.01, 0.49),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
}
function makeSpriteText(text, color = "#bdd4e4", width = 0.7) {
const texture = createCanvasTexture(512, 128, (ctx, w, h) => {
drawText(ctx, w, h, text, color, 58);
});
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(width, width / 4, 1);
return sprite;
}
// -------------------------------------------------------------------------
// Robot
// -------------------------------------------------------------------------
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0xdde8ec,
roughness: 0.38,
metalness: 0.24
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x132330,
roughness: 0.46,
metalness: 0.48
});
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0x526877,
roughness: 0.32,
metalness: 0.72
});
const visorMaterial = new THREE.MeshStandardMaterial({
color: 0x07121c,
roughness: 0.2,
metalness: 0.58
});
const coreMaterial = new THREE.MeshStandardMaterial({
color: 0x8fffbd,
emissive: 0x8fffbd,
emissiveIntensity: 1.45,
roughness: 0.2
});
const eyeMaterial = new THREE.MeshStandardMaterial({
color: 0x8fffbd,
emissive: 0x8fffbd,
emissiveIntensity: 2.1,
roughness: 0.2
});
const robot = new THREE.Group();
robot.position.set(-1.35, 0, 0.36);
scene.add(robot);
const robotVisual = new THREE.Group();
robot.add(robotVisual);
// Backpack and torso.
addBox(
robotVisual,
[0.78, 0.72, 0.28],
darkMaterial,
[0, 1.55, -0.48]
);
addBox(
robotVisual,
[1.16, 1.02, 0.72],
shellMaterial,
[0, 1.55, 0]
);
addBox(
robotVisual,
[0.84, 0.28, 0.08],
darkMaterial,
[0, 1.88, 0.395],
false
);
const robotId = makeTextPlane(
"R-07",
0.47,
0.14,
"#9fd8ec",
66
);
robotId.position.set(0, 1.89, 0.442);
robotVisual.add(robotId);
// Pelvis and legs.
addBox(
robotVisual,
[0.82, 0.31, 0.54],
darkMaterial,
[0, 1.02, 0]
);
for (const side of [-1, 1]) {
const leg = new THREE.Group();
leg.position.set(side * 0.32, 0, 0);
robotVisual.add(leg);
addCylinder(leg, 0.14, 0.16, 0.5, shellMaterial, [0, 0.72, 0]);
addSphere(leg, 0.17, jointMaterial, [0, 0.43, 0]);
addCylinder(leg, 0.13, 0.15, 0.38, shellMaterial, [0, 0.22, 0]);
addSphere(
leg,
0.25,
darkMaterial,
[0, 0.105, 0.13],
[1.55, 0.56, 1.12]
);
}
// Head, visor, eyes, ears, and antenna.
addCylinder(
robotVisual,
0.22,
0.25,
0.2,
jointMaterial,
[0, 2.07, 0]
);
addBox(
robotVisual,
[1.16, 0.78, 0.74],
shellMaterial,
[0, 2.47, 0]
);
addBox(
robotVisual,
[0.91, 0.37, 0.09],
visorMaterial,
[0, 2.49, 0.405],
false
);
addSphere(
robotVisual,
0.11,
eyeMaterial,
[-0.2, 2.49, 0.47],
[1, 0.78, 0.28]
);
addSphere(
robotVisual,
0.11,
eyeMaterial,
[0.2, 2.49, 0.47],
[1, 0.78, 0.28]
);
for (const side of [-1, 1]) {
const ear = addCylinder(
robotVisual,
0.18,
0.18,
0.16,
darkMaterial,
[side * 0.66, 2.48, 0]
);
ear.rotation.z = Math.PI / 2;
}
addCylinder(
robotVisual,
0.035,
0.045,
0.45,
jointMaterial,
[0, 3.04, 0],
12
);
addSphere(
robotVisual,
0.12,
coreMaterial,
[0, 3.29, 0]
);
// Chest state core.
addCylinder(
robotVisual,
0.22,
0.22,
0.1,
darkMaterial,
[0, 1.46, 0.4],
32
);
const chestCore = new THREE.Mesh(
new THREE.TorusGeometry(0.145, 0.038, 10, 32),
coreMaterial
);
chestCore.position.set(0, 1.46, 0.465);
robotVisual.add(chestCore);
// Arms.
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.74, 1.78, 0);
rightArm.position.set(0.74, 1.78, 0);
robotVisual.add(leftArm, rightArm);
for (const arm of [leftArm, rightArm]) {
addSphere(arm, 0.19, jointMaterial, [0, 0, 0]);
addCylinder(arm, 0.13, 0.15, 0.5, shellMaterial, [0, -0.28, 0]);
addSphere(arm, 0.15, jointMaterial, [0, -0.56, 0]);
addCylinder(arm, 0.12, 0.14, 0.4, shellMaterial, [0, -0.8, 0]);
addSphere(arm, 0.15, darkMaterial, [0, -1.07, 0]);
}
leftArm.rotation.z = -0.1;
rightArm.rotation.z = 0.1;
// -------------------------------------------------------------------------
// Floor positions
// -------------------------------------------------------------------------
const positionDefinitions = [
{ label: "LEFT", x: -2.85 },
{ label: "CENTER", x: -1.35 },
{ label: "RIGHT", x: 0.15 }
];
const pads = [];
const padMaterial = new THREE.MeshStandardMaterial({
color: 0x112432,
emissive: 0x1c89b5,
emissiveIntensity: 0.12,
roughness: 0.55,
metalness: 0.35
});
for (let i = 0; i < positionDefinitions.length; i++) {
const definition = positionDefinitions[i];
const pad = new THREE.Mesh(
new THREE.CylinderGeometry(0.67, 0.7, 0.045, 48),
padMaterial.clone()
);
pad.position.set(definition.x, 0.01, 0.36);
pad.receiveShadow = true;
scene.add(pad);
pads.push(pad);
const tag = makeSpriteText(
["L", "C", "R"][i],
"#8eb4c8",
0.46
);
tag.position.set(definition.x, 0.12, 1.12);
scene.add(tag);
}
const positionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.73, 0.025, 8, 64),
new THREE.MeshBasicMaterial({
color: 0x67d9ff,
transparent: true,
opacity: 0.85
})
);
positionRing.rotation.x = Math.PI / 2;
positionRing.position.set(
positionDefinitions[1].x,
0.055,
0.36
);
scene.add(positionRing);
const bodyTag = makeSpriteText(
"BODY POSITION",
"#67d9ff",
1.55
);
bodyTag.position.set(-1.35, 0.19, 1.47);
scene.add(bodyTag);
// -------------------------------------------------------------------------
// Internal-state panel and three state symbols
// -------------------------------------------------------------------------
const stateDefinitions = {
IDLE: {
label: "IDLE",
action: "WAKE",
next: "READY",
color: "#60d8ff"
},
READY: {
label: "READY",
action: "EXECUTE",
next: "WORKING",
color: "#8fffbd"
},
WORKING: {
label: "WORKING",
action: "PAUSE",
next: "IDLE",
color: "#ffb45f"
}
};
const panel = new THREE.Group();
panel.position.set(1.55, 1.9, -0.75);
scene.add(panel);
const panelMaterial = new THREE.MeshStandardMaterial({
color: 0x0c1c2a,
roughness: 0.48,
metalness: 0.42
});
addBox(
panel,
[4.2, 2.7, 0.22],
panelMaterial,
[0, 0, 0]
);
addBox(
panel,
[0.15, 1.15, 0.16],
darkMaterial,
[-1.55, -1.86, 0.01]
);
addBox(
panel,
[0.15, 1.15, 0.16],
darkMaterial,
[1.55, -1.86, 0.01]
);
const panelHeader = makeTextPlane(
"INTERNAL STATE",
3.45,
0.36,
"#d8edf8",
60
);
panelHeader.position.set(0, 1.48, 0.125);
panel.add(panelHeader);
addBox(
panel,
[3.65, 0.025, 0.025],
new THREE.MeshBasicMaterial({ color: 0x3aa6ce }),
[0, 1.2, 0.125],
false
);
const stateCards = [];
function createStateCard(key, index) {
const definition = stateDefinitions[key];
const group = new THREE.Group();
group.position.set((index - 1) * 1.28, -0.05, 0.2);
group.userData.state = key;
panel.add(group);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x102331,
emissive: definition.color,
emissiveIntensity: 0.035,
roughness: 0.42,
metalness: 0.38
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(1.08, 1.92, 0.1),
baseMaterial
);
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const border = new THREE.LineSegments(
new THREE.EdgesGeometry(base.geometry),
new THREE.LineBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0.35
})
);
group.add(border);
const title = makeTextPlane(
definition.label,
1.01,
0.3,
definition.color,
57
);
title.position.set(0, 0.64, 0.058);
group.add(title);
const action = makeActionPlane(
definition.action,
definition.color
);
action.position.set(0, -0.48, 0.059);
group.add(action);
const symbolMaterial = new THREE.MeshStandardMaterial({
color: definition.color,
emissive: definition.color,
emissiveIntensity: 0.72,
roughness: 0.24,
metalness: 0.12
});
const symbol = new THREE.Group();
symbol.position.set(0, 0.23, 0.11);
group.add(symbol);
if (key === "IDLE") {
addBox(
symbol,
[0.09, 0.33, 0.08],
symbolMaterial,
[-0.1, 0, 0],
false
);
addBox(
symbol,
[0.09, 0.33, 0.08],
symbolMaterial,
[0.1, 0, 0],
false
);
} else if (key === "READY") {
const shape = new THREE.Shape();
shape.moveTo(-0.17, -0.14);
shape.lineTo(0.19, 0);
shape.lineTo(-0.17, 0.14);
shape.closePath();
const triangle = new THREE.Mesh(
new THREE.ShapeGeometry(shape),
symbolMaterial
);
symbol.add(triangle);
} else {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(
0.17,
0.035,
8,
32,
Math.PI * 1.62
),
symbolMaterial
);
symbol.add(ring);
const end = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 16, 10),
symbolMaterial
);
end.position.set(
Math.cos(Math.PI * 1.62) * 0.17,
Math.sin(Math.PI * 1.62) * 0.17,
0
);
symbol.add(end);
}
stateCards.push({
key,
group,
base,
baseMaterial,
border,
symbol,
symbolMaterial,
baseZ: 0.2,
hover: false
});
}
createStateCard("IDLE", 0);
createStateCard("READY", 1);
createStateCard("WORKING", 2);
// -------------------------------------------------------------------------
// 3D battery meter
// -------------------------------------------------------------------------
const batteryGroup = new THREE.Group();
batteryGroup.position.set(4.45, 1.9, -0.7);
scene.add(batteryGroup);
addBox(
batteryGroup,
[1.28, 2.7, 0.22],
panelMaterial,
[0, 0, 0]
);
const batteryHeader = makeTextPlane(
"BATTERY",
1.06,
0.28,
"#d8edf8",
56
);
batteryHeader.position.set(0, 1.2, 0.125);
batteryGroup.add(batteryHeader);
const batteryLitMaterial = new THREE.MeshStandardMaterial({
color: 0x72f6ba,
emissive: 0x43d99c,
emissiveIntensity: 0.72,
roughness: 0.3
});
const batteryEmptyMaterial = new THREE.MeshStandardMaterial({
color: 0x172a37,
emissive: 0x02070a,
emissiveIntensity: 0.08,
roughness: 0.7
});
const batterySegments = [];
for (let i = 0; i < 10; i++) {
const segment = addBox(
batteryGroup,
[0.65, 0.115, 0.09],
batteryEmptyMaterial,
[0, 0.78 - i * 0.16, 0.145],
false
);
batterySegments.push(segment);
}
// Thin rails around the segmented cells.
for (const x of [-0.41, 0.41]) {
addBox(
batteryGroup,
[0.025, 1.72, 0.025],
new THREE.MeshBasicMaterial({ color: 0x4a7187 }),
[x, 0.06, 0.16],
false
);
}
const batteryPercent = makeTextPlane(
"72%",
0.98,
0.32,
"#9fffd0",
72
);
batteryPercent.position.set(0, -0.98, 0.13);
batteryGroup.add(batteryPercent);
// -------------------------------------------------------------------------
// UI state
// -------------------------------------------------------------------------
let currentState = "READY";
let currentPosition = 1;
let battery = 72;
let lastBatteryPercent = -1;
let targetRobotX = positionDefinitions[currentPosition].x;
let toastTimer;
const internalStateElement = document.querySelector("#internalState");
const bodyPositionElement = document.querySelector("#bodyPosition");
const batteryValueElement = document.querySelector("#batteryValue");
const actionButton = document.querySelector("#actionButton");
const actionHint = document.querySelector("#actionHint");
const toast = document.querySelector("#toast");
const positionButtons = [
...document.querySelectorAll("[data-position]")
];
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.classList.remove("show");
}, 2400);
}
function refreshStateUI() {
const definition = stateDefinitions[currentState];
document.documentElement.style.setProperty(
"--state",
definition.color
);
internalStateElement.textContent = definition.label;
internalStateElement.style.color = definition.color;
actionButton.textContent = definition.action;
actionHint.textContent = `${definition.label} → ${definition.next}`;
coreMaterial.color.set(definition.color);
coreMaterial.emissive.set(definition.color);
eyeMaterial.color.set(definition.color);
eyeMaterial.emissive.set(definition.color);
stateLight.color.set(definition.color);
for (const card of stateCards) {
card.baseMaterial.emissive.set(
stateDefinitions[card.key].color
);
}
}
function setState(key, announce = true) {
if (!stateDefinitions[key]) return;
currentState = key;
refreshStateUI();
if (announce) {
showToast(
`Internal state: ${key} · body remains ${positionDefinitions[currentPosition].label}`
);
}
}
function refreshPositionUI() {
const definition = positionDefinitions[currentPosition];
bodyPositionElement.textContent = definition.label;
targetRobotX = definition.x;
positionButtons.forEach((button, index) => {
button.classList.toggle("active", index === currentPosition);
});
for (let i = 0; i < pads.length; i++) {
pads[i].material.emissiveIntensity =
i === currentPosition ? 0.4 : 0.08;
}
}
function setPosition(index, announce = true) {
if (index < 0 || index >= positionDefinitions.length) return;
currentPosition = index;
refreshPositionUI();
if (announce) {
showToast(
`Body moved to ${positionDefinitions[index].label} · internal state remains ${currentState}`
);
}
}
function refreshBatteryDisplay(force = false) {
const percentage = Math.round(battery);
if (!force && percentage === lastBatteryPercent) return;
lastBatteryPercent = percentage;
batteryValueElement.textContent = `${percentage}%`;
const low = percentage <= 25;
const color = low ? "#ff7187" : "#9fffd0";
updateTextPlane(
batteryPercent,
`${percentage}%`,
color,
72
);
batteryLitMaterial.color.set(low ? 0xff657a : 0x72f6ba);
batteryLitMaterial.emissive.set(low ? 0xd8294c : 0x43d99c);
const litCount = Math.ceil((percentage / 100) * batterySegments.length);
batterySegments.forEach((segment, index) => {
segment.material =
index < litCount
? batteryLitMaterial
: batteryEmptyMaterial;
});
}
function runAvailableAction() {
const definition = stateDefinitions[currentState];
if (currentState === "READY") {
battery = Math.max(0, battery - 7);
}
setState(definition.next, false);
const energyMessage =
currentState === "WORKING"
? " · energy −7%"
: "";
showToast(
`${definition.action} accepted${energyMessage} · body remains ${positionDefinitions[currentPosition].label}`
);
}
positionButtons.forEach((button) => {
button.addEventListener("click", () => {
setPosition(Number(button.dataset.position));
});
});
actionButton.addEventListener("click", runAvailableAction);
refreshStateUI();
refreshPositionUI();
refreshBatteryDisplay(true);
// -------------------------------------------------------------------------
// Manual camera controls and state-symbol picking
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerIsDown = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousPointerX = 0;
let previousPointerY = 0;
let pointerTravel = 0;
function pickStateCard(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(
stateCards.map((card) => card.group),
true
);
if (!intersections.length) return null;
let object = intersections[0].object;
while (object && !object.userData.state) {
object = object.parent;
}
return object?.userData.state ?? null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerIsDown = true;
pointerTravel = 0;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerIsDown) {
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
pointerTravel += Math.hypot(deltaX, deltaY);
orbit.yaw = THREE.MathUtils.clamp(
orbit.yaw - deltaX * 0.0055,
-0.85,
0.85
);
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + deltaY * 0.0045,
0.18,
0.76
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
} else {
const hoveredState = pickStateCard(event);
stateCards.forEach((card) => {
card.hover = card.key === hoveredState;
});
renderer.domElement.style.cursor = hoveredState
? "pointer"
: "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasClick =
pointerTravel < 7 &&
Math.hypot(
event.clientX - pointerStartX,
event.clientY - pointerStartY
) < 7;
if (wasClick) {
const pickedState = pickStateCard(event);
if (pickedState) {
setState(pickedState);
}
}
pointerIsDown = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerIsDown = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.005,
7,
13
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.yaw = 0.18;
orbit.pitch = 0.36;
orbit.radius = 9.8;
});
window.addEventListener("keydown", (event) => {
if (
document.activeElement &&
["BUTTON", "INPUT", "TEXTAREA"].includes(
document.activeElement.tagName
)
) {
return;
}
if (event.key === "1") setState("IDLE");
if (event.key === "2") setState("READY");
if (event.key === "3") setState("WORKING");
if (event.key === "ArrowLeft") {
setPosition(currentPosition - 1);
}
if (event.key === "ArrowRight") {
setPosition(currentPosition + 1);
}
if (event.code === "Space") {
event.preventDefault();
runAvailableAction();
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
responsiveCameraScale =
camera.aspect < 1 ? 1.12 / camera.aspect : 1;
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
const smooth = 1 - Math.exp(-delta * 7);
// The robot's spatial position is independent of its internal state.
robot.position.x = THREE.MathUtils.lerp(
robot.position.x,
targetRobotX,
1 - Math.exp(-delta * 5)
);
robotVisual.position.y = Math.sin(time * 1.8) * 0.018;
robotVisual.rotation.z = Math.sin(time * 0.75) * 0.012;
let rightArmTarget = 0.02;
let leftArmTarget = -0.02;
if (currentState === "READY") {
rightArmTarget = -0.12;
leftArmTarget = 0.12;
} else if (currentState === "WORKING") {
rightArmTarget = -0.58 + Math.sin(time * 5.2) * 0.28;
leftArmTarget = 0.58 - Math.sin(time * 5.2) * 0.28;
}
rightArm.rotation.x = THREE.MathUtils.lerp(
rightArm.rotation.x,
rightArmTarget,
smooth
);
leftArm.rotation.x = THREE.MathUtils.lerp(
leftArm.rotation.x,
leftArmTarget,
smooth
);
robotVisual.rotation.y = Math.sin(time * 0.55) * 0.025;
const corePulse = 1 + Math.sin(time * 4.2) * 0.08;
chestCore.scale.setScalar(corePulse);
// State cards animate independently.
for (const card of stateCards) {
const active = card.key === currentState;
const targetZ =
card.baseZ + (active ? 0.095 : 0) + (card.hover ? 0.025 : 0);
const targetY = -0.05 + (active ? 0.035 : 0);
const targetScale = active ? 1.035 : 1;
card.group.position.z = THREE.MathUtils.lerp(
card.group.position.z,
targetZ,
smooth
);
card.group.position.y = THREE.MathUtils.lerp(
card.group.position.y,
targetY,
smooth
);
const scale = THREE.MathUtils.lerp(
card.group.scale.x,
targetScale,
smooth
);
card.group.scale.setScalar(scale);
const targetEmissive = active ? 0.34 : card.hover ? 0.14 : 0.035;
card.baseMaterial.emissiveIntensity = THREE.MathUtils.lerp(
card.baseMaterial.emissiveIntensity,
targetEmissive,
smooth
);
card.border.material.opacity = THREE.MathUtils.lerp(
card.border.material.opacity,
active ? 1 : 0.35,
smooth
);
card.symbolMaterial.emissiveIntensity = active
? 1.1
: 0.58;
if (card.key === "WORKING") {
card.symbol.rotation.z += delta * 1.7;
} else if (card.key === "READY") {
const pulse = 1 + Math.sin(time * 3.1) * 0.04;
card.symbol.scale.setScalar(pulse);
}
}
// The battery charges while idle and slowly drains while working.
if (currentState === "IDLE") {
battery = Math.min(100, battery + delta * 0.65);
} else if (currentState === "WORKING") {
battery = Math.max(0, battery - delta * 0.2);
}
refreshBatteryDisplay();
batteryLitMaterial.emissiveIntensity =
0.65 + Math.sin(time * 3.4) * 0.12;
positionRing.material.opacity =
0.72 + Math.sin(time * 3) * 0.15;
stateLight.intensity = 6.4 + Math.sin(time * 3.2) * 0.7;
decorativeRing.rotation.z = time * 0.018;
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```