Prompt specification
Build or customize the Three.js 3D scene "Rule Tablet and Two Test Objects" 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: Rule Tablet and Two Test Objects
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rule-tablet-and-two-test-objects-x3597
Scene Description Prompt:
A stylized rule tablet beside two objects: one visibly satisfies the fictional rule and the other violates it. One HTML file, Three.js from cdnjs.
Working Three.js Starter (rule-tablet-and-two-test-objects-x3597):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Blue Cube Law</title>
<style>
:root {
color-scheme: light;
--ink: #173a44;
--paper: #f5f0e5;
--blue: #2688ff;
--orange: #ef8354;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e3d7;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#intro {
position: fixed;
z-index: 10;
top: 24px;
left: 28px;
max-width: min(390px, calc(100vw - 56px));
color: var(--ink);
pointer-events: none;
user-select: none;
}
#intro .eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
padding: 7px 11px;
border: 1px solid rgba(23, 58, 68, 0.18);
border-radius: 999px;
background: rgba(245, 240, 229, 0.72);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
#intro .dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 4px rgba(239, 131, 84, 0.16);
}
#intro h1 {
margin: 0;
font-size: clamp(24px, 3vw, 42px);
line-height: 0.98;
letter-spacing: -0.055em;
}
#intro p {
margin: 10px 0 0;
max-width: 320px;
font-size: 13px;
line-height: 1.45;
color: rgba(23, 58, 68, 0.72);
}
#help {
position: fixed;
z-index: 10;
right: 24px;
bottom: 22px;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px 10px 15px;
border: 1px solid rgba(23, 58, 68, 0.14);
border-radius: 999px;
background: rgba(245, 240, 229, 0.8);
color: rgba(23, 58, 68, 0.76);
backdrop-filter: blur(12px);
box-shadow: 0 12px 35px rgba(36, 47, 50, 0.12);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.02em;
user-select: none;
}
#reset {
width: 30px;
height: 30px;
padding: 0;
border: 0;
border-radius: 50%;
background: var(--ink);
color: white;
cursor: pointer;
font-size: 16px;
line-height: 1;
transition: transform 160ms ease, background 160ms ease;
}
#reset:hover {
background: #225463;
transform: rotate(-25deg);
}
@media (max-width: 700px) {
#intro {
top: 16px;
left: 18px;
}
#intro p {
display: none;
}
#help {
right: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<div id="intro">
<div class="eyebrow">
<span class="dot"></span>
Interplanetary Ordinance Archive
</div>
<h1>The Blue Cube Law</h1>
<p>One Orbit-Bot carries the required cube. The other has left it behind.</p>
</div>
<div id="help">
Drag to orbit · Scroll to zoom
<button id="reset" title="Reset camera" aria-label="Reset camera">↻</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
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.08;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e3d7);
scene.fog = new THREE.Fog(0xe9e3d7, 15, 27);
const camera = new THREE.PerspectiveCamera(
35,
window.innerWidth / window.innerHeight,
0.1,
60
);
const target = new THREE.Vector3(0.35, 1.45, 0);
const hemisphere = new THREE.HemisphereLight(
0xfffbef,
0x8f9aa0,
2.25
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d8, 4.2);
keyLight.position.set(-5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x87bfff, 2.1);
rimLight.position.set(7, 5, -6);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0xffb27a, 20, 12, 2);
fillLight.position.set(-5, 4, 4);
scene.add(fillLight);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const materials = {
navy: new THREE.MeshStandardMaterial({
color: 0x173a44,
roughness: 0.62,
metalness: 0.08
}),
dark: new THREE.MeshStandardMaterial({
color: 0x26343a,
roughness: 0.72
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf4eee1,
roughness: 0.64
}),
peach: new THREE.MeshStandardMaterial({
color: 0xef8354,
roughness: 0.58
}),
sage: new THREE.MeshStandardMaterial({
color: 0x8eb29f,
roughness: 0.63
}),
orange: new THREE.MeshStandardMaterial({
color: 0xffa85d,
roughness: 0.42
}),
blue: new THREE.MeshStandardMaterial({
color: 0x2688ff,
roughness: 0.24,
metalness: 0.12,
emissive: 0x0a3f82,
emissiveIntensity: 0.38
}),
eye: new THREE.MeshBasicMaterial({
color: 0xb9f5ff
}),
platform: new THREE.MeshStandardMaterial({
color: 0xd8d0c0,
roughness: 0.92
})
};
// ------------------------------------------------------------
// Ground and display platform
// ------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0xe9e3d7,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.28;
floor.receiveShadow = true;
scene.add(floor);
const mainPlatform = new THREE.Mesh(
new THREE.CylinderGeometry(6.15, 6.35, 0.24, 96),
materials.platform
);
mainPlatform.position.set(0.25, -0.15, 0);
mainPlatform.receiveShadow = true;
mainPlatform.castShadow = true;
scene.add(mainPlatform);
const platformInset = new THREE.Mesh(
new THREE.CylinderGeometry(5.82, 5.94, 0.035, 96),
new THREE.MeshStandardMaterial({
color: 0xe4ddcf,
roughness: 0.95
})
);
platformInset.position.set(0.25, -0.012, 0);
platformInset.receiveShadow = true;
scene.add(platformInset);
// ------------------------------------------------------------
// Canvas helpers
// ------------------------------------------------------------
function roundedRect(ctx, x, y, w, h, r, fill, stroke = null) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
if (fill) {
ctx.fillStyle = fill;
ctx.fill();
}
if (stroke) {
ctx.strokeStyle = stroke;
ctx.lineWidth = 5;
ctx.stroke();
}
}
function drawCheck(ctx, cx, cy, radius, color) {
ctx.beginPath();
ctx.arc(cx, cy, radius, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();
ctx.beginPath();
ctx.moveTo(cx - radius * 0.45, cy);
ctx.lineTo(cx - radius * 0.1, cy + radius * 0.34);
ctx.lineTo(cx + radius * 0.5, cy - radius * 0.38);
ctx.strokeStyle = "#ffffff";
ctx.lineWidth = radius * 0.19;
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.stroke();
}
function drawCross(ctx, cx, cy, radius, color) {
ctx.beginPath();
ctx.arc(cx, cy, radius, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();
const d = radius * 0.4;
ctx.beginPath();
ctx.moveTo(cx - d, cy - d);
ctx.lineTo(cx + d, cy + d);
ctx.moveTo(cx + d, cy - d);
ctx.lineTo(cx - d, cy + d);
ctx.strokeStyle = "#ffffff";
ctx.lineWidth = radius * 0.18;
ctx.lineCap = "round";
ctx.stroke();
}
function drawCubeIcon(ctx, x, y, size) {
const top = [
[x, y - size * 0.42],
[x + size * 0.5, y - size * 0.18],
[x, y + size * 0.08],
[x - size * 0.5, y - size * 0.18]
];
const left = [
[x - size * 0.5, y - size * 0.18],
[x, y + size * 0.08],
[x, y + size * 0.62],
[x - size * 0.5, y + size * 0.35]
];
const right = [
[x + size * 0.5, y - size * 0.18],
[x, y + size * 0.08],
[x, y + size * 0.62],
[x + size * 0.5, y + size * 0.35]
];
ctx.beginPath();
top.forEach((p, i) =>
i === 0 ? ctx.moveTo(...p) : ctx.lineTo(...p)
);
ctx.closePath();
ctx.fillStyle = "#70b7ff";
ctx.fill();
ctx.beginPath();
left.forEach((p, i) =>
i === 0 ? ctx.moveTo(...p) : ctx.lineTo(...p)
);
ctx.closePath();
ctx.fillStyle = "#1473df";
ctx.fill();
ctx.beginPath();
right.forEach((p, i) =>
i === 0 ? ctx.moveTo(...p) : ctx.lineTo(...p)
);
ctx.closePath();
ctx.fillStyle = "#2688ff";
ctx.fill();
}
// ------------------------------------------------------------
// Rule tablet texture
// ------------------------------------------------------------
function createTabletTexture() {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 1024;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f6f1e6";
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Subtle paper grain.
for (let i = 0; i < 2600; i++) {
const alpha = Math.random() * 0.035;
ctx.fillStyle = `rgba(23,58,68,${alpha})`;
ctx.fillRect(
Math.random() * canvas.width,
Math.random() * canvas.height,
1 + Math.random() * 2,
1 + Math.random() * 2
);
}
roundedRect(
ctx,
48,
44,
672,
100,
24,
"#f5d7c4",
"#e6b99f"
);
ctx.fillStyle = "#173a44";
ctx.font = "800 20px Arial, sans-serif";
ctx.letterSpacing = "3px";
ctx.fillText("COUNCIL OF TINY MACHINES", 78, 83);
ctx.fillStyle = "#ef8354";
ctx.font = "900 28px Arial, sans-serif";
ctx.textAlign = "right";
ctx.fillText("LAW 07", 690, 116);
ctx.textAlign = "left";
ctx.fillStyle = "#173a44";
ctx.font = "900 66px Arial, sans-serif";
ctx.fillText("EVERY", 58, 255);
ctx.fillText("ORBIT-BOT", 58, 327);
ctx.fillText("MUST CARRY", 58, 399);
ctx.fillStyle = "#2688ff";
ctx.fillText("ONE BLUE", 58, 471);
ctx.fillText("CUBE.", 58, 543);
ctx.strokeStyle = "#b7c2c1";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(58, 587);
ctx.lineTo(710, 587);
ctx.stroke();
ctx.fillStyle = "#52666d";
ctx.font = "500 30px Arial, sans-serif";
ctx.fillText("No exemptions. No substitutions.", 58, 638);
ctx.fillText("The cube must remain visible.", 58, 681);
// Example panel.
roundedRect(ctx, 48, 724, 672, 204, 26, "#e4ece8");
ctx.fillStyle = "#173a44";
ctx.font = "800 20px Arial, sans-serif";
ctx.letterSpacing = "2px";
ctx.fillText("COMPLIANCE EXAMPLES", 78, 764);
ctx.letterSpacing = "0px";
drawCheck(ctx, 132, 843, 42, "#258b68");
ctx.fillStyle = "#173a44";
ctx.font = "800 31px Arial, sans-serif";
ctx.fillText("CUBE", 188, 835);
ctx.fillStyle = "#527067";
ctx.font = "500 23px Arial, sans-serif";
ctx.fillText("present", 188, 866);
drawCross(ctx, 453, 843, 42, "#c75858");
ctx.fillStyle = "#173a44";
ctx.font = "800 31px Arial, sans-serif";
ctx.fillText("NO CUBE", 509, 852);
ctx.fillStyle = "#8d5d5d";
ctx.font = "500 23px Arial, sans-serif";
ctx.fillText("violation", 509, 883);
// Bottom seal.
ctx.save();
ctx.translate(628, 900);
ctx.rotate(-0.12);
ctx.strokeStyle = "#ef8354";
ctx.lineWidth = 6;
ctx.beginPath();
ctx.arc(0, 0, 63, 0, Math.PI * 2);
ctx.stroke();
ctx.fillStyle = "#ef8354";
ctx.font = "900 18px Arial, sans-serif";
ctx.textAlign = "center";
ctx.fillText("APPROVED", 0, -5);
ctx.fillText("UNIVERSALLY", 0, 20);
ctx.restore();
ctx.textAlign = "left";
ctx.fillStyle = "#789096";
ctx.font = "700 17px Arial, sans-serif";
ctx.fillText("ARCHIVE COPY · SECTOR 9", 58, 962);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
// ------------------------------------------------------------
// Tablet
// ------------------------------------------------------------
const tablet = new THREE.Group();
tablet.position.set(-3.3, 1.93, 0.05);
tablet.rotation.y = -0.055;
scene.add(tablet);
const tabletFrame = new THREE.Mesh(
new THREE.BoxGeometry(2.48, 3.3, 0.25),
materials.navy
);
tabletFrame.castShadow = true;
tabletFrame.receiveShadow = true;
tablet.add(tabletFrame);
const tabletScreen = new THREE.Mesh(
new THREE.PlaneGeometry(2.18, 2.96),
new THREE.MeshBasicMaterial({
map: createTabletTexture(),
toneMapped: false
})
);
tabletScreen.position.z = 0.131;
tablet.add(tabletScreen);
// Screen edge highlight.
const screenFrame = new THREE.Mesh(
new THREE.BoxGeometry(2.25, 3.03, 0.035),
new THREE.MeshBasicMaterial({
color: 0x071f27
})
);
screenFrame.position.z = 0.108;
tablet.add(screenFrame);
// Feet.
for (const side of [-1, 1]) {
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.32, 0.35, 0.72),
materials.dark
);
foot.position.set(side * 0.67, -1.73, 0.05);
foot.castShadow = true;
tablet.add(foot);
}
// Corner fasteners.
const screwMaterial = new THREE.MeshStandardMaterial({
color: 0xf2b275,
roughness: 0.35,
metalness: 0.45
});
for (const x of [-1.09, 1.09]) {
for (const y of [-1.48, 1.48]) {
const screw = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 16, 12),
screwMaterial
);
screw.position.set(x, y, 0.15);
tablet.add(screw);
}
}
// Small status light.
const tabletLight = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 20, 16),
new THREE.MeshBasicMaterial({ color: 0x72e0b2 })
);
tabletLight.position.set(0, -1.56, 0.15);
tablet.add(tabletLight);
// ------------------------------------------------------------
// Utility geometry
// ------------------------------------------------------------
function cylinderBetween(a, b, radius, material, radialSegments = 16) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeBadgeTexture(pass) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 190;
const ctx = canvas.getContext("2d");
roundedRect(
ctx,
10,
10,
620,
170,
40,
pass ? "#216b59" : "#8d3d46",
pass ? "#78c8ac" : "#e59191"
);
if (pass) {
drawCheck(ctx, 80, 95, 37, "#7de1bc");
} else {
drawCross(ctx, 80, 95, 37, "#ff9b9b");
}
ctx.fillStyle = "#ffffff";
ctx.font = "900 42px Arial, sans-serif";
ctx.fillText(pass ? "UNIT A · PASS" : "UNIT B · FAIL", 138, 88);
ctx.globalAlpha = 0.8;
ctx.font = "700 25px Arial, sans-serif";
ctx.fillText(
pass ? "BLUE CUBE PRESENT" : "BLUE CUBE MISSING",
138,
129
);
ctx.globalAlpha = 1;
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addBadge(parent, pass, y) {
const badge = new THREE.Sprite(
new THREE.SpriteMaterial({
map: makeBadgeTexture(pass),
transparent: true,
depthTest: false,
toneMapped: false
})
);
badge.position.set(0, y, 0.15);
badge.scale.set(1.9, 0.57, 1);
badge.renderOrder = 20;
parent.add(badge);
}
// ------------------------------------------------------------
// Orbit-Bot construction
// ------------------------------------------------------------
function createRobot({
x,
shellMaterial,
compliant,
badgeY = 3.55
}) {
const robot = new THREE.Group();
robot.position.set(x, 0.07, 0);
scene.add(robot);
// Individual display pad.
const pad = new THREE.Mesh(
new THREE.CylinderGeometry(0.98, 1.04, 0.13, 48),
new THREE.MeshStandardMaterial({
color: compliant ? 0xc8ddd4 : 0xdac5c3,
roughness: 0.86
})
);
pad.position.y = 0.02;
pad.receiveShadow = true;
pad.castShadow = true;
robot.add(pad);
const padRing = new THREE.Mesh(
new THREE.TorusGeometry(0.83, 0.025, 8, 64),
new THREE.MeshBasicMaterial({
color: compliant ? 0x48b18c : 0xd27474
})
);
padRing.rotation.x = Math.PI / 2;
padRing.position.y = 0.092;
robot.add(padRing);
// Feet.
for (const side of [-1, 1]) {
const leg = cylinderBetween(
new THREE.Vector3(side * 0.27, 0.69, 0),
new THREE.Vector3(side * 0.3, 0.27, 0.02),
0.115,
materials.dark
);
robot.add(leg);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.42, 0.2, 0.58),
materials.navy
);
foot.position.set(side * 0.3, 0.18, 0.12);
foot.castShadow = true;
robot.add(foot);
}
// Torso.
const torso = new THREE.Mesh(
new THREE.SphereGeometry(0.58, 32, 24),
shellMaterial
);
torso.scale.set(1, 1.12, 0.76);
torso.position.y = 1.36;
torso.castShadow = true;
torso.receiveShadow = true;
robot.add(torso);
// Chest plate.
const chest = new THREE.Mesh(
new THREE.CircleGeometry(0.225, 32),
materials.cream
);
chest.position.set(0, 1.38, 0.43);
robot.add(chest);
const chestDot = new THREE.Mesh(
new THREE.CircleGeometry(0.065, 24),
compliant ? materials.blue : materials.orange
);
chestDot.position.set(0, 1.38, 0.437);
robot.add(chestDot);
// Neck.
robot.add(
cylinderBetween(
new THREE.Vector3(0, 1.87, 0),
new THREE.Vector3(0, 2.05, 0),
0.13,
materials.dark
)
);
// Head.
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.59, 32, 24),
materials.cream
);
head.scale.set(1, 0.83, 0.88);
head.position.y = 2.37;
head.castShadow = true;
robot.add(head);
// Face panel.
const face = new THREE.Mesh(
new THREE.BoxGeometry(0.76, 0.37, 0.08),
materials.navy
);
face.position.set(0, 2.39, 0.46);
face.castShadow = true;
robot.add(face);
// Eyes.
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.068, 20, 14),
materials.eye
);
eye.position.set(side * 0.17, 2.43, 0.515);
robot.add(eye);
}
// Mouth.
const mouth = new THREE.Mesh(
new THREE.BoxGeometry(0.19, 0.035, 0.025),
new THREE.MeshBasicMaterial({ color: 0x8ee8d4 })
);
mouth.position.set(0, 2.28, 0.515);
robot.add(mouth);
// Antenna.
robot.add(
cylinderBetween(
new THREE.Vector3(0, 2.73, 0),
new THREE.Vector3(0, 3.08, 0),
0.035,
materials.dark
)
);
const antennaTip = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 20, 16),
compliant ? materials.blue : materials.orange
);
antennaTip.position.set(0, 3.12, 0);
antennaTip.castShadow = true;
robot.add(antennaTip);
// Left arm.
robot.add(
cylinderBetween(
new THREE.Vector3(-0.53, 1.65, 0),
new THREE.Vector3(-0.78, 1.22, 0.08),
0.105,
materials.dark
)
);
robot.add(
cylinderBetween(
new THREE.Vector3(-0.78, 1.22, 0.08),
new THREE.Vector3(-0.82, 0.88, 0.34),
0.095,
shellMaterial
)
);
const leftHand = new THREE.Mesh(
new THREE.SphereGeometry(0.14, 20, 14),
materials.dark
);
leftHand.position.set(-0.82, 0.86, 0.36);
robot.add(leftHand);
// Right arm bends forward to make the gripper clearly visible.
const shoulder = new THREE.Vector3(0.53, 1.64, 0.02);
const elbow = new THREE.Vector3(0.82, 1.29, 0.24);
const wrist = new THREE.Vector3(0.88, 0.97, 0.58);
robot.add(
cylinderBetween(shoulder, elbow, 0.11, materials.dark)
);
robot.add(
cylinderBetween(elbow, wrist, 0.1, shellMaterial)
);
const wristJoint = new THREE.Mesh(
new THREE.SphereGeometry(0.145, 20, 14),
materials.dark
);
wristJoint.position.copy(wrist);
robot.add(wristJoint);
// Open gripper fingers.
for (const side of [-1, 1]) {
const finger = new THREE.Mesh(
new THREE.BoxGeometry(0.085, 0.42, 0.11),
materials.dark
);
finger.position.set(
0.88 + side * 0.21,
1.14,
0.67
);
finger.rotation.z = side * -0.12;
finger.castShadow = true;
robot.add(finger);
}
let cube = null;
let cubeLight = null;
if (compliant) {
cube = new THREE.Mesh(
new THREE.BoxGeometry(0.58, 0.58, 0.58),
materials.blue
);
cube.position.set(0.88, 1.3, 0.68);
cube.castShadow = true;
cube.receiveShadow = true;
robot.add(cube);
const cubeEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(cube.geometry),
new THREE.LineBasicMaterial({
color: 0xc8edff,
transparent: true,
opacity: 0.95
})
);
cubeEdges.scale.setScalar(1.006);
cube.add(cubeEdges);
cubeLight = new THREE.PointLight(0x328fff, 5, 2.2, 2);
cubeLight.position.set(0.88, 1.32, 0.88);
robot.add(cubeLight);
}
addBadge(robot, compliant, badgeY);
return {
group: robot,
cube,
cubeLight,
antennaTip
};
}
const compliantRobot = createRobot({
x: 0.82,
shellMaterial: materials.peach,
compliant: true
});
const violatingRobot = createRobot({
x: 3.65,
shellMaterial: materials.sage,
compliant: false
});
// ------------------------------------------------------------
// Small decorative orbital markers
// ------------------------------------------------------------
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xef8354,
roughness: 0.45
});
const decorativeMarkers = [];
const markerData = [
[-4.85, 3.8, -0.6, 0.09],
[-1.9, 4.5, -1.2, 0.065],
[4.9, 4.2, -0.9, 0.085],
[5.25, 1.0, -0.5, 0.055]
];
for (const [x, y, z, radius] of markerData) {
const marker = new THREE.Mesh(
new THREE.SphereGeometry(radius, 16, 12),
markerMaterial
);
marker.position.set(x, y, z);
scene.add(marker);
decorativeMarkers.push(marker);
}
// ------------------------------------------------------------
// Custom camera controls — no Three.js addons
// ------------------------------------------------------------
const controls = {
desired: {
theta: 0.43,
phi: 1.18,
radius: 12.4
},
current: {
theta: 0.43,
phi: 1.18,
radius: 12.4
}
};
const spherical = new THREE.Spherical();
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
spherical.set(
controls.current.radius,
controls.current.phi,
controls.current.theta
);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
function resetCamera() {
controls.desired.theta = 0.43;
controls.desired.phi = 1.18;
controls.desired.radius = 12.4;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
controls.desired.theta -= deltaX * 0.0055;
controls.desired.phi = THREE.MathUtils.clamp(
controls.desired.phi - deltaY * 0.0045,
0.48,
1.42
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.desired.radius = THREE.MathUtils.clamp(
controls.desired.radius + event.deltaY * 0.008,
8.2,
17
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Resize
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = width / height;
if (width / height < 0.85) {
camera.fov = 48;
controls.desired.radius = Math.max(
controls.desired.radius,
14.5
);
} else {
camera.fov = 35;
}
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const damping = 0.085;
controls.current.theta = THREE.MathUtils.lerp(
controls.current.theta,
controls.desired.theta,
damping
);
controls.current.phi = THREE.MathUtils.lerp(
controls.current.phi,
controls.desired.phi,
damping
);
controls.current.radius = THREE.MathUtils.lerp(
controls.current.radius,
controls.desired.radius,
damping
);
updateCamera();
if (compliantRobot.cube) {
compliantRobot.cube.rotation.y = elapsed * 0.65;
compliantRobot.cube.rotation.x = Math.sin(elapsed * 0.7) * 0.08;
compliantRobot.cube.position.y =
1.3 + Math.sin(elapsed * 1.7) * 0.025;
if (compliantRobot.cubeLight) {
compliantRobot.cubeLight.intensity =
4.5 + Math.sin(elapsed * 2.2) * 0.8;
}
}
compliantRobot.antennaTip.position.y =
3.12 + Math.sin(elapsed * 2.1) * 0.035;
violatingRobot.antennaTip.position.y =
3.12 + Math.sin(elapsed * 2.1 + 1.7) * 0.035;
decorativeMarkers.forEach((marker, index) => {
marker.position.y +=
Math.sin(elapsed * 0.7 + index * 1.4) * 0.0015;
});
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```