Prompt specification
Build or customize the Three.js 3D scene "Conditional Gate With Two Symbol Slots" 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: Conditional Gate With Two Symbol Slots
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/conditional-gate-with-two-symbol-slots-x3261
Scene Description Prompt:
Make a stylized toy gate that opens only when both badge and opening-hours tokens are present. One HTML file, Three.js from cdnjs.
Working Three.js Starter (conditional-gate-with-two-symbol-slots-x3261):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Toy Gate — Two-Token Access</title>
<style>
:root {
--ink: #173f43;
--muted: #6d8583;
--cream: #fffaf0;
--mint: #d9eee7;
--coral: #ef7568;
--gold: #f4c65b;
--blue: #55a9c6;
--green: #48ad83;
--shadow: rgba(23, 63, 67, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
color: var(--ink);
background:
radial-gradient(circle at 50% 36%, #fffdf6 0%, #edf5ef 56%, #dcece7 100%);
}
button {
font: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.masthead {
position: absolute;
top: 26px;
left: 30px;
display: flex;
align-items: flex-start;
gap: 14px;
max-width: min(460px, calc(100vw - 60px));
}
.brand-mark {
display: grid;
place-items: center;
width: 48px;
height: 48px;
flex: 0 0 auto;
border-radius: 16px;
color: white;
background: var(--ink);
box-shadow: 0 10px 24px var(--shadow);
}
.brand-mark svg {
width: 27px;
height: 27px;
}
.eyebrow {
margin: 0 0 3px;
color: var(--coral);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 36px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.4;
}
.top-actions {
position: absolute;
top: 27px;
right: 28px;
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.lock-chip,
.reset-button {
height: 42px;
border: 1px solid rgba(23, 63, 67, 0.12);
border-radius: 15px;
background: rgba(255, 255, 255, 0.78);
box-shadow: 0 8px 24px rgba(23, 63, 67, 0.09);
backdrop-filter: blur(12px);
}
.lock-chip {
display: flex;
align-items: center;
gap: 8px;
padding: 0 15px;
font-size: 11px;
font-weight: 900;
letter-spacing: 0.08em;
}
.lock-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 4px rgba(244, 198, 91, 0.18);
transition: 0.3s ease;
}
.lock-chip.open {
color: #287b5c;
}
.lock-chip.open .lock-dot {
background: var(--green);
box-shadow: 0 0 0 4px rgba(72, 173, 131, 0.18);
}
.reset-button {
display: grid;
place-items: center;
width: 42px;
padding: 0;
color: var(--ink);
cursor: pointer;
transition: transform 0.2s ease, background 0.2s ease;
}
.reset-button:hover {
transform: rotate(-12deg) scale(1.05);
background: white;
}
.reset-button svg {
width: 19px;
height: 19px;
}
.control-dock {
position: absolute;
left: 50%;
bottom: 22px;
width: min(690px, calc(100vw - 28px));
padding: 13px;
transform: translateX(-50%);
border: 1px solid rgba(23, 63, 67, 0.11);
border-radius: 24px;
background: rgba(255, 253, 247, 0.87);
box-shadow: 0 18px 50px rgba(23, 63, 67, 0.15);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.instructions {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
margin: 0 0 10px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
}
.instructions b {
color: var(--ink);
}
.step-number {
display: inline-grid;
place-items: center;
width: 19px;
height: 19px;
border-radius: 7px;
color: white;
background: var(--ink);
font-size: 10px;
}
.token-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.token-button {
display: flex;
align-items: center;
min-width: 0;
gap: 12px;
padding: 12px 14px;
border: 1px solid rgba(23, 63, 67, 0.1);
border-radius: 17px;
color: var(--ink);
background: white;
text-align: left;
cursor: pointer;
box-shadow: 0 5px 14px rgba(23, 63, 67, 0.06);
transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.token-button:hover:not(:disabled) {
transform: translateY(-2px);
border-color: rgba(23, 63, 67, 0.24);
}
.token-button:disabled {
cursor: default;
}
.token-button[data-state="picked"] {
border-color: rgba(244, 198, 91, 0.7);
background: #fffaf0;
}
.token-button[data-state="inserted"] {
border-color: rgba(72, 173, 131, 0.35);
background: #effaf5;
}
.token-icon {
display: grid;
place-items: center;
width: 44px;
height: 44px;
flex: 0 0 auto;
border-radius: 14px;
}
.token-icon.badge {
color: #267793;
background: #dff3fa;
}
.token-icon.hours {
color: #2e786b;
background: #dff2e9;
}
.token-icon svg {
width: 25px;
height: 25px;
}
.token-copy {
min-width: 0;
flex: 1;
}
.token-name {
display: block;
overflow: hidden;
font-size: 13px;
font-weight: 900;
text-overflow: ellipsis;
white-space: nowrap;
}
.token-action {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.token-button[data-state="inserted"] .token-action {
color: #348264;
}
.toast {
position: absolute;
left: 50%;
bottom: 151px;
max-width: min(520px, calc(100vw - 36px));
padding: 10px 15px;
transform: translate(-50%, 10px);
border-radius: 13px;
color: white;
background: rgba(23, 63, 67, 0.92);
box-shadow: 0 9px 26px var(--shadow);
font-size: 12px;
font-weight: 750;
text-align: center;
opacity: 0;
transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show {
transform: translate(-50%, 0);
opacity: 1;
}
.success {
position: absolute;
top: 19%;
left: 50%;
display: flex;
align-items: center;
gap: 13px;
min-width: 270px;
padding: 15px 19px;
transform: translate(-50%, -12px) scale(0.94);
border: 1px solid rgba(72, 173, 131, 0.2);
border-radius: 21px;
background: rgba(255, 255, 255, 0.94);
box-shadow: 0 18px 45px rgba(23, 63, 67, 0.18);
opacity: 0;
transition: opacity 0.45s ease, transform 0.45s cubic-bezier(.2, .8, .2, 1);
}
.success.show {
transform: translate(-50%, 0) scale(1);
opacity: 1;
}
.success-icon {
display: grid;
place-items: center;
width: 42px;
height: 42px;
flex: 0 0 auto;
border-radius: 50%;
color: white;
background: var(--green);
}
.success-icon svg {
width: 23px;
height: 23px;
}
.success strong {
display: block;
font-size: 15px;
}
.success span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 11px;
}
.orbit-note {
position: absolute;
right: 28px;
bottom: 24px;
color: rgba(23, 63, 67, 0.55);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
}
@media (max-width: 700px) {
.masthead {
top: 18px;
left: 18px;
}
.brand-mark {
width: 41px;
height: 41px;
border-radius: 14px;
}
.subtitle {
display: none;
}
.top-actions {
top: 18px;
right: 18px;
}
.lock-chip {
padding: 0 11px;
}
.control-dock {
bottom: 12px;
padding: 10px;
border-radius: 20px;
}
.instructions {
margin-bottom: 8px;
font-size: 10px;
}
.token-button {
gap: 8px;
padding: 9px;
}
.token-icon {
width: 36px;
height: 36px;
border-radius: 12px;
}
.token-icon svg {
width: 21px;
height: 21px;
}
.token-name {
font-size: 11px;
}
.token-action {
font-size: 9px;
}
.toast {
bottom: 137px;
}
.orbit-note {
display: none;
}
}
@media (max-width: 430px) {
h1 {
font-size: 21px;
}
.eyebrow {
font-size: 8px;
}
.brand-mark {
display: none;
}
.lock-chip {
height: 38px;
font-size: 9px;
}
.reset-button {
width: 38px;
height: 38px;
}
.token-button {
flex-direction: column;
align-items: flex-start;
}
.token-name {
white-space: normal;
}
}
</style>
</head>
<body>
<main id="app">
<div id="scene"></div>
<div class="ui">
<header class="masthead">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M4 20V9a8 8 0 0 1 16 0v11" stroke="currentColor" stroke-width="2.3" stroke-linecap="round"/>
<path d="M8 20V10a4 4 0 0 1 8 0v10M3 20h18" stroke="currentColor" stroke-width="2.3" stroke-linecap="round"/>
</svg>
</div>
<div>
<p class="eyebrow">Access Lab · Toy 01</p>
<h1>The Two-Token Gate</h1>
<p class="subtitle">A tiny checkpoint for a very important rabbit.</p>
</div>
</header>
<div class="top-actions">
<div class="lock-chip" id="lockChip" aria-live="polite">
<span class="lock-dot"></span>
<span id="lockText">LOCKED · 0/2</span>
</div>
<button class="reset-button" id="resetButton" title="Reset gate" aria-label="Reset gate">
<svg viewBox="0 0 24 24" fill="none">
<path d="M4 10a8 8 0 1 1 2.3 7.7" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/>
<path d="M4 4v6h6" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<section class="success" id="success" aria-live="polite">
<div class="success-icon">
<svg viewBox="0 0 24 24" fill="none">
<path d="m5 12 4.2 4.2L19 6.5" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
<div>
<strong>Access granted</strong>
<span>Badge and opening-hours tokens verified.</span>
</div>
</section>
<section class="control-dock" aria-label="Token controls">
<p class="instructions">
<span class="step-number">1</span>
<b>Pick up</b>
a token
<span>→</span>
<span class="step-number">2</span>
<b>Place</b>
it in the matching socket
</p>
<div class="token-buttons">
<button class="token-button" data-token="badge" data-state="available">
<span class="token-icon badge" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<rect x="5" y="3" width="14" height="18" rx="3" stroke="currentColor" stroke-width="2"/>
<path d="M9 3.5h6v3H9z" fill="currentColor"/>
<path d="m12 9 1.25 2.55 2.82.4-2.04 1.98.48 2.8L12 15.2l-2.51 1.53.48-2.8-2.04-1.98 2.82-.4L12 9Z" fill="currentColor"/>
</svg>
</span>
<span class="token-copy">
<span class="token-name">Badge token</span>
<span class="token-action">Pick up</span>
</span>
</button>
<button class="token-button" data-token="hours" data-state="available">
<span class="token-icon hours" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<circle cx="12" cy="12" r="8.5" stroke="currentColor" stroke-width="2"/>
<path d="M12 7v5l3.5 2" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</span>
<span class="token-copy">
<span class="token-name">Opening hours</span>
<span class="token-action">Pick up</span>
</span>
</button>
</div>
</section>
<div class="orbit-note">DRAG TO ORBIT · SCROLL TO ZOOM</div>
</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------
const sceneContainer = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xeaf3ed, 13, 26);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 60);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0xeaf3ed, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive three-dimensional toy gate");
renderer.domElement.tabIndex = 0;
sceneContainer.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff8e8, 0x83aaa5, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.4);
sun.position.set(-5, 9, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.0003;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8e6ff, 1.25);
fill.position.set(6, 4, -4);
scene.add(fill);
// ------------------------------------------------------------
// Palette and reusable materials
// ------------------------------------------------------------
const palette = {
ink: 0x173f43,
inkSoft: 0x285d60,
cream: 0xfff4d9,
paper: 0xfffdf4,
mint: 0xb9dcd2,
mintDark: 0x4b8c83,
coral: 0xef7568,
coralDark: 0xc8524b,
gold: 0xf4c65b,
goldDark: 0xc99230,
blue: 0x55a9c6,
blueDark: 0x2c7893,
green: 0x48ad83,
ground: 0xd7e9e3
};
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.02,
...options
});
}
const materials = {
ink: standard(palette.ink),
inkSoft: standard(palette.inkSoft),
cream: standard(palette.cream),
paper: standard(palette.paper),
mint: standard(palette.mint),
mintDark: standard(palette.mintDark),
coral: standard(palette.coral),
coralDark: standard(palette.coralDark),
gold: standard(palette.gold, { roughness: 0.5 }),
goldDark: standard(palette.goldDark),
blue: standard(palette.blue),
blueDark: standard(palette.blueDark),
green: standard(palette.green),
ground: standard(palette.ground),
white: standard(0xffffff)
};
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function roundedRectShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const r = Math.min(radius, width / 2, height / 2);
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + height - r);
shape.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
shape.lineTo(x + r, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
return shape;
}
function roundedMesh(width, height, depth, radius, material) {
const geometry = new THREE.ExtrudeGeometry(
roundedRectShape(width, height, radius),
{
depth,
steps: 1,
curveSegments: 10,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: Math.min(0.045, radius * 0.45),
bevelThickness: Math.min(0.045, depth * 0.3)
}
);
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function addMesh(parent, geometry, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, width, height, depth, material, x = 0, y = 0, z = 0) {
return addMesh(parent, new THREE.BoxGeometry(width, height, depth), material, x, y, z);
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
material,
x = 0,
y = 0,
z = 0,
segments = 48
) {
return addMesh(
parent,
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material,
x,
y,
z
);
}
function createStarShape(outerRadius = 0.22, innerRadius = 0.1, points = 5) {
const shape = new THREE.Shape();
for (let i = 0; i < points * 2; i++) {
const radius = i % 2 === 0 ? outerRadius : innerRadius;
const angle = -Math.PI / 2 + (i * Math.PI) / points;
const x = Math.cos(angle) * radius;
const y = Math.sin(angle) * radius;
if (i === 0) shape.moveTo(x, y);
else shape.lineTo(x, y);
}
shape.closePath();
return shape;
}
function createLabelTexture(text, background = "#173f43", foreground = "#fffaf0") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
const x = 8;
const y = 8;
const width = 496;
const height = 112;
const radius = 34;
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
context.fillStyle = background;
context.fill();
context.fillStyle = foreground;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "900 44px Arial Rounded MT Bold, Arial, sans-serif";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function addSpriteLabel(parent, text, options = {}) {
const {
width = 1.7,
height = 0.34,
background = "#173f43",
foreground = "#fffaf0",
x = 0,
y = 0,
z = 0
} = options;
const texture = createLabelTexture(text, background, foreground);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.position.set(x, y, z);
parent.add(sprite);
return sprite;
}
// ------------------------------------------------------------
// Toy diorama
// ------------------------------------------------------------
const world = new THREE.Group();
scene.add(world);
const floor = addMesh(
world,
new THREE.PlaneGeometry(50, 50),
standard(0xeaf3ed, { roughness: 1 }),
0,
-0.53,
0
);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
const base = addCylinder(
world,
5.45,
5.65,
0.45,
materials.mint,
0,
-0.28,
0,
80
);
const baseTop = addCylinder(
world,
5.18,
5.25,
0.12,
standard(0xe4f0e9),
0,
-0.01,
0,
80
);
const path = roundedMesh(2.55, 5.6, 0.055, 0.35, materials.cream);
path.rotation.x = -Math.PI / 2;
path.position.set(0, 0.055, 2.65);
world.add(path);
for (let i = 0; i < 5; i++) {
const stone = addCylinder(
world,
0.19,
0.19,
0.035,
i % 2 ? materials.paper : standard(0xf1e2c4),
0,
0.095,
4.45 - i * 0.72,
32
);
stone.scale.x = 1.25;
}
// Small side gardens.
function createFlowerPot(x, z, flowerColor) {
const group = new THREE.Group();
group.position.set(x, 0.06, z);
world.add(group);
addCylinder(group, 0.42, 0.31, 0.5, materials.coralDark, 0, 0.25, 0, 32);
addCylinder(group, 0.44, 0.44, 0.12, materials.coral, 0, 0.5, 0, 32);
addCylinder(group, 0.035, 0.045, 0.75, materials.green, 0, 0.92, 0, 12);
const petalMaterial = standard(flowerColor);
const centerMaterial = materials.gold;
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const petal = addMesh(
group,
new THREE.SphereGeometry(0.14, 20, 12),
petalMaterial,
Math.cos(angle) * 0.19,
1.29,
Math.sin(angle) * 0.19
);
petal.scale.set(1, 0.58, 0.8);
}
addMesh(group, new THREE.SphereGeometry(0.13, 20, 12), centerMaterial, 0, 1.31, 0);
}
createFlowerPot(-4.25, -0.65, 0xf7d667);
createFlowerPot(4.25, -0.65, 0xf2a0ae);
// ------------------------------------------------------------
// Gate and doors
// ------------------------------------------------------------
const gate = new THREE.Group();
world.add(gate);
const leftPost = roundedMesh(0.5, 2.75, 0.52, 0.13, materials.coral);
leftPost.position.set(-1.9, 1.43, 0);
gate.add(leftPost);
const rightPost = leftPost.clone();
rightPost.position.x = 1.9;
gate.add(rightPost);
const arch = addMesh(
gate,
new THREE.TorusGeometry(1.9, 0.235, 20, 88, Math.PI),
materials.coral,
0,
2.65,
0
);
arch.castShadow = true;
addMesh(gate, new THREE.SphereGeometry(0.285, 28, 18), materials.gold, -1.9, 2.68, 0);
addMesh(gate, new THREE.SphereGeometry(0.285, 28, 18), materials.gold, 1.9, 2.68, 0);
// Sign above the arch.
const signBack = roundedMesh(2.35, 0.62, 0.17, 0.16, materials.ink);
signBack.position.set(0, 4.67, 0.04);
gate.add(signBack);
const signTexture = createLabelTexture("TINY ACCESS", "#173f43", "#fff4d9");
const signFace = addMesh(
gate,
new THREE.PlaneGeometry(2.18, 0.47),
new THREE.MeshBasicMaterial({ map: signTexture, transparent: true }),
0,
4.67,
0.14
);
signFace.castShadow = false;
const statusLampMaterials = [];
for (const x of [-0.34, 0.34]) {
const lampMaterial = standard(palette.gold, {
emissive: palette.gold,
emissiveIntensity: 0.32
});
const lamp = addMesh(
gate,
new THREE.SphereGeometry(0.105, 24, 16),
lampMaterial,
x,
4.68,
0.3
);
lamp.castShadow = false;
statusLampMaterials.push(lampMaterial);
}
function createDoor(side) {
const pivot = new THREE.Group();
pivot.position.set(side < 0 ? -1.76 : 1.76, 0, 0.04);
gate.add(pivot);
const direction = side < 0 ? 1 : -1;
const panel = roundedMesh(1.72, 2.52, 0.18, 0.12, materials.mintDark);
panel.position.set(direction * 0.86, 1.48, 0);
pivot.add(panel);
// Vertical toy slats.
for (let i = 0; i < 5; i++) {
const slat = roundedMesh(0.12, 2.08, 0.075, 0.045, materials.cream);
slat.position.set(direction * (0.24 + i * 0.31), 1.48, 0.13);
pivot.add(slat);
}
const railTop = roundedMesh(1.58, 0.15, 0.08, 0.05, materials.gold);
railTop.position.set(direction * 0.86, 2.5, 0.16);
pivot.add(railTop);
const railBottom = railTop.clone();
railBottom.position.y = 0.47;
pivot.add(railBottom);
const handle = addMesh(
pivot,
new THREE.SphereGeometry(0.12, 24, 16),
materials.gold,
direction * 1.46,
1.45,
0.22
);
handle.scale.set(1, 1, 0.72);
return pivot;
}
const leftDoor = createDoor(-1);
const rightDoor = createDoor(1);
// ------------------------------------------------------------
// Interactive sockets
// ------------------------------------------------------------
const interactiveMeshes = [];
function markInteractive(object, action) {
object.traverse((child) => {
if (child.isMesh) {
child.userData.action = action;
interactiveMeshes.push(child);
}
});
}
const badgeSocketMaterial = standard(palette.ink, {
emissive: palette.blue,
emissiveIntensity: 0.03
});
const badgeSocket = roundedMesh(0.72, 0.9, 0.13, 0.16, badgeSocketMaterial);
badgeSocket.position.set(-1.9, 1.45, 0.38);
gate.add(badgeSocket);
const badgeSocketLabel = addSpriteLabel(
gate,
"BADGE",
{
width: 0.9,
height: 0.22,
background: "#55a9c6",
foreground: "#173f43",
x: -1.9,
y: 2.04,
z: 0.52
}
);
const hoursSocketMaterial = standard(palette.ink, {
emissive: palette.green,
emissiveIntensity: 0.03
});
const hoursSocket = addCylinder(
gate,
0.43,
0.43,
0.15,
hoursSocketMaterial,
1.9,
1.45,
0.38,
48
);
hoursSocket.rotation.x = Math.PI / 2;
const hoursSocketRing = addMesh(
gate,
new THREE.TorusGeometry(0.34, 0.055, 14, 48),
materials.cream,
1.9,
1.45,
0.5
);
addSpriteLabel(
gate,
"HOURS",
{
width: 0.94,
height: 0.22,
background: "#48ad83",
foreground: "#fffaf0",
x: 1.9,
y: 2.04,
z: 0.52
}
);
markInteractive(badgeSocket, { type: "socket", token: "badge" });
markInteractive(hoursSocket, { type: "socket", token: "hours" });
markInteractive(hoursSocketRing, { type: "socket", token: "hours" });
// ------------------------------------------------------------
// Token pedestals and tokens
// ------------------------------------------------------------
function createPedestal(x, label, labelColor) {
const group = new THREE.Group();
group.position.set(x, 0.06, 2.35);
world.add(group);
addCylinder(group, 0.79, 0.88, 0.28, materials.inkSoft, 0, 0.14, 0, 48);
addCylinder(group, 0.7, 0.73, 0.12, materials.cream, 0, 0.31, 0, 48);
const ringMaterial = new THREE.MeshBasicMaterial({
color: labelColor,
transparent: true,
opacity: 0.16,
depthWrite: false
});
const ring = addMesh(
group,
new THREE.RingGeometry(0.47, 0.62, 48),
ringMaterial,
0,
0.379,
0
);
ring.rotation.x = -Math.PI / 2;
ring.castShadow = false;
ring.receiveShadow = false;
addSpriteLabel(
group,
label,
{
width: label === "BADGE" ? 1.25 : 1.85,
height: 0.28,
background: labelColor,
foreground: "#173f43",
x: 0,
y: 0.5,
z: 0.64
}
);
return { group, ring, ringMaterial };
}
const badgePedestal = createPedestal(-3.05, "BADGE", "#55a9c6");
const hoursPedestal = createPedestal(3.05, "OPENING HOURS", "#48ad83");
// Badge token.
const badgeToken = new THREE.Group();
badgeToken.position.set(-3.05, 1.52, 2.35);
world.add(badgeToken);
const badgeOuter = roundedMesh(0.8, 0.98, 0.14, 0.13, materials.blue);
badgeToken.add(badgeOuter);
const badgeInner = roundedMesh(0.61, 0.68, 0.045, 0.09, materials.paper);
badgeInner.position.set(0, -0.035, 0.09);
badgeToken.add(badgeInner);
const badgeClip = roundedMesh(0.37, 0.13, 0.09, 0.045, materials.gold);
badgeClip.position.set(0, 0.48, 0.06);
badgeToken.add(badgeClip);
const starGeometry = new THREE.ExtrudeGeometry(createStarShape(0.19, 0.09), {
depth: 0.04,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.018,
bevelThickness: 0.012
});
starGeometry.center();
const badgeStar = addMesh(
badgeToken,
starGeometry,
materials.gold,
0,
0.07,
0.135
);
const badgeStripe = roundedMesh(0.39, 0.075, 0.035, 0.025, materials.blueDark);
badgeStripe.position.set(0, -0.25, 0.135);
badgeToken.add(badgeStripe);
badgeToken.userData.home = badgeToken.position.clone();
badgeToken.userData.phase = 0.3;
markInteractive(badgeToken, { type: "token", token: "badge" });
// Opening-hours clock token.
const hoursToken = new THREE.Group();
hoursToken.position.set(3.05, 1.38, 2.35);
world.add(hoursToken);
const clockOuter = addCylinder(
hoursToken,
0.47,
0.47,
0.18,
materials.mintDark,
0,
0,
0,
64
);
clockOuter.rotation.x = Math.PI / 2;
const clockFace = addMesh(
hoursToken,
new THREE.CircleGeometry(0.385, 64),
materials.paper,
0,
0,
0.103
);
clockFace.castShadow = false;
const clockRim = addMesh(
hoursToken,
new THREE.TorusGeometry(0.39, 0.055, 16, 64),
materials.gold,
0,
0,
0.125
);
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const tick = addBox(
hoursToken,
0.025,
i % 3 === 0 ? 0.095 : 0.065,
0.025,
materials.ink,
Math.sin(angle) * 0.31,
Math.cos(angle) * 0.31,
0.135
);
tick.rotation.z = -angle;
}
const hourHand = addBox(hoursToken, 0.045, 0.25, 0.025, materials.ink, -0.09, 0.025, 0.16);
hourHand.rotation.z = -0.18;
const minuteHand = addBox(hoursToken, 0.035, 0.32, 0.025, materials.coralDark, 0, 0.11, 0.17);
minuteHand.rotation.z = 0.13;
addMesh(hoursToken, new THREE.SphereGeometry(0.065, 20, 12), materials.gold, 0, 0, 0.19);
const openPlaque = roundedMesh(0.52, 0.19, 0.06, 0.055, materials.green);
openPlaque.position.set(0, -0.61, 0);
hoursToken.add(openPlaque);
hoursToken.userData.home = hoursToken.position.clone();
hoursToken.userData.phase = 2.2;
markInteractive(hoursToken, { type: "token", token: "hours" });
// ------------------------------------------------------------
// State and UI
// ------------------------------------------------------------
const state = {
picked: new Set(),
inserted: new Set(),
unlocked: false,
gateOpenTarget: 0,
gateProgress: 0
};
const tokenButtons = [...document.querySelectorAll(".token-button")];
const lockChip = document.querySelector("#lockChip");
const lockText = document.querySelector("#lockText");
const toast = document.querySelector("#toast");
const success = document.querySelector("#success");
const resetButton = document.querySelector("#resetButton");
let toastTimer = 0;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2800);
}
function updateUI() {
for (const button of tokenButtons) {
const id = button.dataset.token;
const action = button.querySelector(".token-action");
if (state.inserted.has(id)) {
button.dataset.state = "inserted";
button.disabled = true;
action.textContent = "Verified ✓";
} else if (state.picked.has(id)) {
button.dataset.state = "picked";
button.disabled = false;
action.textContent = "Place in socket";
} else {
button.dataset.state = "available";
button.disabled = false;
action.textContent = "Pick up";
}
}
const count = state.inserted.size;
lockText.textContent = state.unlocked ? "OPEN · 2/2" : `LOCKED · ${count}/2`;
lockChip.classList.toggle("open", state.unlocked);
}
function pickToken(id) {
if (state.inserted.has(id)) return;
if (!state.picked.has(id)) {
state.picked.add(id);
updateUI();
const name = id === "badge" ? "Badge" : "Opening-hours";
showToast(`${name} token collected. Place it in the glowing ${id === "badge" ? "BADGE" : "HOURS"} socket.`);
} else {
showToast("Now click the matching glowing socket on the gate.");
}
}
function insertToken(id) {
if (state.inserted.has(id)) return;
if (!state.picked.has(id)) {
showToast(`Pick up the ${id === "badge" ? "badge" : "opening-hours"} token first.`);
return;
}
state.inserted.add(id);
const token = id === "badge" ? badgeToken : hoursToken;
const target = id === "badge"
? new THREE.Vector3(-1.9, 1.45, 0.54)
: new THREE.Vector3(1.9, 1.45, 0.56);
const targetScale = id === "badge" ? 0.57 : 0.66;
token.userData.motion = {
from: token.position.clone(),
to: target,
startScale: token.scale.x,
targetScale,
startTime: performance.now(),
duration: 850
};
updateUI();
if (state.inserted.size === 2) {
state.unlocked = true;
state.gateOpenTarget = 1;
showToast("Both tokens verified. Opening the gate!");
spawnConfetti();
setTimeout(() => {
if (state.unlocked) success.classList.add("show");
}, 650);
} else {
showToast(`${id === "badge" ? "Badge" : "Opening-hours"} token accepted. One more token is required.`);
}
}
function handleAction(action) {
if (!action) return;
if (action.type === "token") {
pickToken(action.token);
} else if (action.type === "socket") {
insertToken(action.token);
}
}
tokenButtons.forEach((button) => {
button.addEventListener("click", () => {
const id = button.dataset.token;
if (!state.picked.has(id)) {
pickToken(id);
} else {
insertToken(id);
}
});
});
// ------------------------------------------------------------
// Custom camera controls — no addons
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.55, 0.35);
let cameraYaw = 0.28;
let cameraPitch = 0.34;
let cameraRadius = 10.6;
function updateCamera() {
const horizontal = Math.cos(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pointerToNDC(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;
}
function getActionAtPointer(event) {
pointerToNDC(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactiveMeshes, false);
return hits.length ? hits[0].object.userData.action : null;
}
let pointerDown = false;
let pointerMoved = false;
let downAction = null;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
downAction = getActionAtPointer(event);
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.abs(event.clientX - (pointerDown ? lastX : lastX)) > 0) {
pointerMoved = pointerMoved || Math.abs(dx) + Math.abs(dy) > 5;
}
if (!downAction) {
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + dy * 0.0045, 0.15, 0.72);
updateCamera();
}
lastX = event.clientX;
lastY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (pointerDown && !pointerMoved && downAction) {
handleAction(downAction);
}
pointerDown = false;
downAction = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
downAction = null;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.008,
7.4,
13.8
);
updateCamera();
}, { passive: false });
// ------------------------------------------------------------
// Confetti
// ------------------------------------------------------------
const confetti = [];
const confettiGeometry = new THREE.BoxGeometry(0.09, 0.18, 0.035);
const confettiMaterials = [
standard(palette.coral),
standard(palette.gold),
standard(palette.blue),
standard(palette.green),
standard(0xf29db1)
];
function spawnConfetti() {
for (let i = 0; i < 52; i++) {
const piece = new THREE.Mesh(
confettiGeometry,
confettiMaterials[i % confettiMaterials.length]
);
piece.position.set(
(Math.random() - 0.5) * 4.4,
4.2 + Math.random() * 1.7,
(Math.random() - 0.5) * 1.6
);
piece.rotation.set(
Math.random() * Math.PI,
Math.random() * Math.PI,
Math.random() * Math.PI
);
piece.castShadow = true;
scene.add(piece);
confetti.push({
mesh: piece,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 2.5,
0.4 + Math.random() * 2.2,
(Math.random() - 0.5) * 2
),
spin: new THREE.Vector3(
Math.random() * 5,
Math.random() * 5,
Math.random() * 5
)
});
}
}
function updateConfetti(dt) {
for (let i = confetti.length - 1; i >= 0; i--) {
const piece = confetti[i];
piece.velocity.y -= 3.8 * dt;
piece.mesh.position.addScaledVector(piece.velocity, dt);
piece.mesh.rotation.x += piece.spin.x * dt;
piece.mesh.rotation.y += piece.spin.y * dt;
piece.mesh.rotation.z += piece.spin.z * dt;
if (piece.mesh.position.y < -0.5) {
scene.remove(piece.mesh);
confetti.splice(i, 1);
}
}
}
// ------------------------------------------------------------
// Reset
// ------------------------------------------------------------
function resetScene() {
state.picked.clear();
state.inserted.clear();
state.unlocked = false;
state.gateOpenTarget = 0;
state.gateProgress = 0;
for (const token of [badgeToken, hoursToken]) {
token.userData.motion = null;
token.position.copy(token.userData.home);
token.rotation.set(0, 0, 0);
token.scale.setScalar(1);
}
while (confetti.length) {
scene.remove(confetti[confetti.length - 1].mesh);
confetti.pop();
}
success.classList.remove("show");
updateUI();
showToast("Gate reset. Collect both tokens to unlock it.");
}
resetButton.addEventListener("click", resetScene);
// ------------------------------------------------------------
// Responsive renderer
// ------------------------------------------------------------
function resize() {
const width = sceneContainer.clientWidth;
const height = sceneContainer.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animateToken(token, time) {
const motion = token.userData.motion;
if (motion) {
const progress = THREE.MathUtils.clamp(
(performance.now() - motion.startTime) / motion.duration,
0,
1
);
const eased = 1 - Math.pow(1 - progress, 3);
token.position.lerpVectors(motion.from, motion.to, eased);
const scale = THREE.MathUtils.lerp(
motion.startScale,
motion.targetScale,
eased
);
token.scale.setScalar(scale);
token.rotation.y = Math.sin(eased * Math.PI) * 0.45;
token.rotation.z = Math.sin(eased * Math.PI) * 0.12;
if (progress >= 1) {
token.position.copy(motion.to);
token.scale.setScalar(motion.targetScale);
token.rotation.set(0, 0, 0);
token.userData.motion = null;
}
} else if (!state.inserted.has(token === badgeToken ? "badge" : "hours")) {
const id = token === badgeToken ? "badge" : "hours";
const picked = state.picked.has(id);
const phase = token.userData.phase;
token.position.x = token.userData.home.x;
token.position.z = token.userData.home.z;
token.position.y =
token.userData.home.y +
Math.sin(time * (picked ? 2.5 : 1.7) + phase) * (picked ? 0.13 : 0.055);
token.rotation.z = Math.sin(time * 1.5 + phase) * (picked ? 0.07 : 0.025);
token.rotation.y = Math.sin(time * 0.9 + phase) * (picked ? 0.13 : 0.045);
}
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
// Smooth gate opening.
const gateEase = 1 - Math.exp(-dt * 3.4);
state.gateProgress = THREE.MathUtils.lerp(
state.gateProgress,
state.gateOpenTarget,
gateEase
);
leftDoor.rotation.y = state.gateProgress * 1.22;
rightDoor.rotation.y = -state.gateProgress * 1.22;
animateToken(badgeToken, time);
animateToken(hoursToken, time);
// Socket glow.
const badgeReady = state.picked.has("badge") && !state.inserted.has("badge");
const hoursReady = state.picked.has("hours") && !state.inserted.has("hours");
badgeSocketMaterial.emissiveIntensity = state.inserted.has("badge")
? 0.75
: badgeReady
? 0.5 + Math.sin(time * 5) * 0.25
: 0.03;
hoursSocketMaterial.emissiveIntensity = state.inserted.has("hours")
? 0.75
: hoursReady
? 0.5 + Math.sin(time * 5) * 0.25
: 0.03;
badgeSocketMaterial.emissive.set(state.inserted.has("badge") ? palette.green : palette.blue);
hoursSocketMaterial.emissive.set(state.inserted.has("hours") ? palette.green : palette.green);
// Pedestal rings.
for (const [id, pedestal] of [
["badge", badgePedestal],
["hours", hoursPedestal]
]) {
const isPicked = state.picked.has(id) && !state.inserted.has(id);
const isInserted = state.inserted.has(id);
const pulse = 1 + Math.sin(time * 3.2) * (isPicked ? 0.1 : 0.025);
pedestal.ring.scale.setScalar(pulse);
pedestal.ringMaterial.opacity = isInserted ? 0.4 : isPicked ? 0.3 : 0.14;
}
// Top status lamps.
statusLampMaterials.forEach((material, index) => {
const verified = index === 0
? state.inserted.has("badge")
: state.inserted.has("hours");
material.color.set(verified ? palette.green : palette.gold);
material.emissive.set(verified ? palette.green : palette.gold);
material.emissiveIntensity = verified
? 1.05
: 0.32 + Math.sin(time * 2.2 + index) * 0.12;
});
updateConfetti(dt);
renderer.render(scene, camera);
}
updateUI();
animate();
</script>
</body>
</html>
```