Prompt specification
Build or customize the Three.js 3D scene "Borrow and Return Token Track" 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: Borrow and Return Token Track
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/borrow-and-return-token-track-x3253
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: borrow and return token track. Place a shared tool between two household models with separate borrowed and returned markers. Show that a return closes an obligation without creating another physical tool.
Working Three.js Starter (borrow-and-return-token-track-x3253):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Borrow / Return — Shared Tool</title>
<style>
:root {
--ink: #203043;
--muted: #687789;
--paper: #f7f5ed;
--panel: rgba(255, 255, 255, 0.78);
--border: rgba(32, 48, 67, 0.12);
--orange: #f07b49;
--orange-soft: #fff0e6;
--green: #20a77d;
--green-soft: #e4f7ef;
--blue: #466b87;
--shadow: 0 18px 55px rgba(38, 53, 67, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
color: var(--ink);
background:
radial-gradient(circle at 50% 35%, #fbfaf4 0%, #edf1eb 48%, #dfe7e1 100%);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
width: 100%;
height: 100dvh;
display: grid;
grid-template-rows: 74px minmax(0, 1fr);
}
header {
position: relative;
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 26px;
border-bottom: 1px solid rgba(32, 48, 67, 0.09);
background: rgba(250, 250, 246, 0.72);
backdrop-filter: blur(18px);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border-radius: 12px;
background: var(--ink);
box-shadow: 0 7px 18px rgba(32, 48, 67, 0.18);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
width: 13px;
height: 13px;
border: 3px solid #fff;
border-radius: 50%;
}
.brand-mark::before {
top: 7px;
left: 7px;
}
.brand-mark::after {
right: 6px;
bottom: 7px;
border-color: #f4aa69;
}
.brand-title {
font-size: 14px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.brand-subtitle {
margin-top: 2px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.04em;
}
.header-meta {
display: flex;
align-items: center;
gap: 9px;
}
.meta-pill {
padding: 8px 11px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(255, 255, 255, 0.62);
color: #536477;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
}
.meta-pill strong {
color: var(--ink);
}
#stage {
position: relative;
min-height: 0;
overflow: hidden;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.glass {
border: 1px solid rgba(255, 255, 255, 0.8);
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(125%);
}
.intro {
position: absolute;
z-index: 3;
top: 24px;
left: 24px;
width: 286px;
padding: 21px;
border-radius: 22px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 9px;
color: var(--orange);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(32px, 3vw, 44px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.04em;
}
.intro p {
margin: 15px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.facts {
display: flex;
gap: 18px;
margin-top: 18px;
padding-top: 15px;
border-top: 1px solid var(--border);
}
.fact strong {
display: block;
font-size: 20px;
line-height: 1;
}
.fact span {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.ledger {
position: absolute;
z-index: 3;
top: 24px;
right: 24px;
width: 270px;
padding: 18px;
border-radius: 22px;
}
.ledger-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
}
.ledger-title {
font-size: 10px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.state-badge {
padding: 6px 9px;
border-radius: 999px;
background: #edf1f3;
color: var(--blue);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
transition: 220ms ease;
}
.state-badge.open {
background: var(--orange-soft);
color: #b94f25;
}
.state-badge.closed {
background: var(--green-soft);
color: #147b5c;
}
.ledger-row {
display: flex;
align-items: center;
justify-content: space-between;
min-height: 38px;
border-top: 1px solid rgba(32, 48, 67, 0.08);
color: var(--muted);
font-size: 12px;
}
.ledger-row strong {
color: var(--ink);
font-size: 12px;
}
.ledger-row strong small {
margin-left: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
}
.fixed-count {
display: inline-flex;
align-items: center;
gap: 6px;
}
.fixed-count::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(32, 167, 125, 0.12);
}
.marker-key {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 13px 0 0;
}
.key {
padding: 10px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(255, 255, 255, 0.48);
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.key::before {
content: "";
display: inline-block;
width: 8px;
height: 8px;
margin-right: 7px;
border-radius: 50%;
vertical-align: 1px;
}
.key.borrow::before {
background: var(--orange);
}
.key.return::before {
background: var(--green);
}
.proof {
margin-top: 12px;
padding: 11px 12px;
border-radius: 12px;
background: rgba(70, 107, 135, 0.07);
color: #52677b;
font-size: 11px;
line-height: 1.45;
}
.proof strong {
color: var(--ink);
}
.controls {
position: absolute;
z-index: 4;
left: 50%;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border-radius: 18px;
transform: translateX(-50%);
}
.action {
min-width: 138px;
height: 48px;
padding: 0 20px;
border: 0;
border-radius: 12px;
color: white;
background: var(--ink);
cursor: pointer;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.025em;
box-shadow: 0 8px 20px rgba(32, 48, 67, 0.16);
transition:
transform 160ms ease,
opacity 160ms ease,
box-shadow 160ms ease;
}
.action:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 12px 25px rgba(32, 48, 67, 0.2);
}
.action:active:not(:disabled) {
transform: translateY(0);
}
.action:disabled {
opacity: 0.34;
cursor: not-allowed;
box-shadow: none;
}
.action.return {
background: var(--green);
}
.action.reset {
min-width: 48px;
width: 48px;
padding: 0;
background: #e8ece8;
color: var(--ink);
box-shadow: none;
font-size: 20px;
}
.orbit-hint {
position: absolute;
z-index: 2;
left: 50%;
bottom: 91px;
transform: translateX(-50%);
color: rgba(32, 48, 67, 0.58);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
pointer-events: none;
}
.loading {
position: absolute;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #edf1eb;
color: var(--muted);
font-size: 12px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
#app {
grid-template-rows: 64px minmax(0, 1fr);
}
header {
padding: 0 14px;
}
.header-meta {
display: none;
}
.intro {
top: 10px;
left: 10px;
right: 10px;
width: auto;
padding: 13px 15px;
border-radius: 16px;
}
.intro .eyebrow {
margin-bottom: 5px;
font-size: 8px;
}
h1 {
font-size: 25px;
line-height: 1;
}
.intro p,
.facts {
display: none;
}
.ledger {
top: auto;
right: 10px;
bottom: 86px;
left: 10px;
width: auto;
padding: 12px;
border-radius: 16px;
}
.ledger-head {
margin-bottom: 5px;
}
.ledger-row {
min-height: 29px;
}
.marker-key,
.proof {
display: none;
}
.controls {
bottom: 12px;
width: calc(100% - 20px);
justify-content: center;
}
.action {
min-width: 0;
flex: 1;
height: 44px;
padding: 0 10px;
}
.action.reset {
flex: 0 0 44px;
}
.orbit-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="brand-title">Borrow / Return</div>
<div class="brand-subtitle">A shared-resource ledger</div>
</div>
</div>
<div class="header-meta">
<div class="meta-pill"><strong>1</strong> physical tool</div>
<div class="meta-pill"><strong>1</strong> custody token</div>
<div class="meta-pill">2 households</div>
</div>
</header>
<main id="stage">
<canvas
id="scene"
aria-label="Interactive 3D scene showing a shared drill between two households and a borrow-and-return custody token track"
></canvas>
<section class="intro glass">
<div class="eyebrow">Shared resource / scenario 01</div>
<h1>One tool.<br />Two households.</h1>
<p>
The token records custody. Returning it closes the same obligation —
it never creates a second physical tool.
</p>
<div class="facts">
<div class="fact">
<strong>01</strong>
<span>Object</span>
</div>
<div class="fact">
<strong>01</strong>
<span>Token</span>
</div>
<div class="fact">
<strong>02</strong>
<span>Homes</span>
</div>
</div>
</section>
<aside class="ledger glass">
<div class="ledger-head">
<div class="ledger-title">Token ledger</div>
<div id="stateBadge" class="state-badge">READY</div>
</div>
<div class="ledger-row">
<span>Physical tools</span>
<strong class="fixed-count">1 <small>fixed</small></strong>
</div>
<div class="ledger-row">
<span>Obligation</span>
<strong id="obligationValue">None</strong>
</div>
<div class="ledger-row">
<span>Token marker</span>
<strong id="tokenValue">Ready</strong>
</div>
<div class="marker-key">
<div class="key borrow">Borrowed</div>
<div class="key return">Returned</div>
</div>
<div id="proof" class="proof" aria-live="polite">
<strong>The tool is available.</strong> Borrowing will open one obligation.
</div>
</aside>
<div class="orbit-hint">Drag to orbit · Scroll to zoom · Double-click to reset view</div>
<div class="controls glass">
<button id="borrowButton" class="action" type="button">Borrow tool</button>
<button id="returnButton" class="action return" type="button" disabled>
Return tool
</button>
<button
id="resetButton"
class="action reset"
type="button"
title="Reset the token track"
aria-label="Reset the token track"
>
↺
</button>
</div>
<div id="loading" class="loading">Building the shared-resource scene…</div>
</main>
</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, camera, and direct camera controls
// ---------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x000000, 0);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe9eee7, 15, 27);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 60);
const cameraRig = {
target: new THREE.Vector3(0, 0.8, 0),
radius: window.innerWidth < 760 ? 15.8 : 11.8,
theta: 0.2,
phi: 1.1
};
function updateCamera() {
const { target, radius, theta, phi } = cameraRig;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
let dragging = false;
let dragX = 0;
let dragY = 0;
let dragTheta = cameraRig.theta;
let dragPhi = cameraRig.phi;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
dragTheta = cameraRig.theta;
dragPhi = cameraRig.phi;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - dragX;
const dy = event.clientY - dragY;
cameraRig.theta = dragTheta - dx * 0.006;
cameraRig.phi = THREE.MathUtils.clamp(dragPhi - dy * 0.005, 0.65, 1.38);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRig.radius = THREE.MathUtils.clamp(
cameraRig.radius + event.deltaY * 0.008,
8,
18
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraRig.theta = 0.2;
cameraRig.phi = 1.1;
cameraRig.radius = window.innerWidth < 760 ? 15.8 : 11.8;
updateCamera();
});
// ---------------------------------------------------------------------
// Lighting and reusable helpers
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff8e9, 0x718394, 2.1));
const sun = new THREE.DirectionalLight(0xfff1d6, 3.4);
sun.position.set(5.5, 9, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 24;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaecbe0, 1.1);
fill.position.set(-6, 4, -4);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0,
...options
});
}
function addMesh(parent, geometry, mat, position, rotation) {
const mesh = new THREE.Mesh(geometry, mat);
if (position) mesh.position.set(...position);
if (rotation) mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabel(
text,
{
foreground = "#203043",
background = "rgba(255,255,255,0.88)",
border = "rgba(32,48,67,0.14)",
width = 2.1,
height = 0.48,
fontSize = 38
} = {}
) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 768;
labelCanvas.height = 176;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, labelCanvas.width, labelCanvas.height);
roundedRect(ctx, 7, 7, 754, 162, 34);
ctx.fillStyle = background;
ctx.fill();
ctx.lineWidth = 3;
ctx.strokeStyle = border;
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = `800 ${fontSize}px Inter, system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 384, 91);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 20;
return sprite;
}
// ---------------------------------------------------------------------
// Diorama platform
// ---------------------------------------------------------------------
const base = addMesh(
scene,
new THREE.CylinderGeometry(6.25, 6.48, 0.34, 96),
material(0xcbd6d0),
[0, -0.32, 0]
);
addMesh(
scene,
new THREE.CylinderGeometry(6.18, 6.18, 0.1, 96),
material(0xf1f2e9),
[0, -0.1, 0]
);
const platformRing = addMesh(
scene,
new THREE.TorusGeometry(5.73, 0.025, 8, 120),
material(0xb9c9c1),
[0, -0.035, 0],
[Math.PI / 2, 0, 0]
);
platformRing.castShadow = false;
// Subtle concentric platform guides.
for (const radius of [2.55, 4.45]) {
const guide = addMesh(
scene,
new THREE.TorusGeometry(radius, 0.014, 6, 100),
material(0xd3dcd4),
[0, -0.025, 0],
[Math.PI / 2, 0, 0]
);
guide.castShadow = false;
}
// ---------------------------------------------------------------------
// Household models: small houses and stylized residents
// ---------------------------------------------------------------------
function makePerson(shirtColor, skinColor, hairColor, scale = 1) {
const group = new THREE.Group();
group.scale.setScalar(scale);
const shirt = material(shirtColor);
const skin = material(skinColor);
const hair = material(hairColor);
const shoes = material(0x354454);
addMesh(
group,
new THREE.CapsuleGeometry(0.19, 0.38, 5, 12),
shirt,
[0, 0.78, 0]
);
addMesh(group, new THREE.SphereGeometry(0.205, 18, 14), skin, [0, 1.35, 0]);
const hairCap = addMesh(
group,
new THREE.SphereGeometry(0.212, 18, 12, 0, Math.PI * 2, 0, Math.PI * 0.52),
hair,
[0, 1.39, -0.01]
);
hairCap.scale.y = 0.58;
addMesh(
group,
new THREE.CylinderGeometry(0.075, 0.075, 0.46, 10),
material(0x4d6072),
[-0.11, 0.3, 0]
);
addMesh(
group,
new THREE.CylinderGeometry(0.075, 0.075, 0.46, 10),
material(0x4d6072),
[0.11, 0.3, 0]
);
addMesh(
group,
new THREE.BoxGeometry(0.19, 0.11, 0.3),
shoes,
[-0.11, 0.06, 0.05]
);
addMesh(
group,
new THREE.BoxGeometry(0.19, 0.11, 0.3),
shoes,
[0.11, 0.06, 0.05]
);
const armGeometry = new THREE.CylinderGeometry(0.058, 0.065, 0.46, 10);
addMesh(
group,
armGeometry,
shirt,
[-0.25, 0.78, 0],
[0, 0, -0.18]
);
addMesh(
group,
armGeometry,
shirt,
[0.25, 0.78, 0],
[0, 0, 0.18]
);
addMesh(group, new THREE.SphereGeometry(0.067, 10, 8), skin, [-0.29, 0.54, 0]);
addMesh(group, new THREE.SphereGeometry(0.067, 10, 8), skin, [0.29, 0.54, 0]);
// Tiny eyes give the miniature a friendly expression.
const eyeMaterial = material(0x253342);
addMesh(group, new THREE.SphereGeometry(0.018, 8, 6), eyeMaterial, [-0.07, 1.37, 0.188]);
addMesh(group, new THREE.SphereGeometry(0.018, 8, 6), eyeMaterial, [0.07, 1.37, 0.188]);
return group;
}
function makeHouse({
x,
accent,
roof,
wall,
label,
shirt,
skin,
hair,
personOffset
}) {
const house = new THREE.Group();
house.position.set(x, 0, -0.62);
addMesh(
house,
new THREE.CylinderGeometry(1.25, 1.32, 0.13, 48),
material(0xe1e6dd),
[0, 0.015, 0]
);
const houseRing = addMesh(
house,
new THREE.TorusGeometry(1.17, 0.027, 8, 64),
material(accent),
[0, 0.085, 0],
[Math.PI / 2, 0, 0]
);
houseRing.castShadow = false;
addMesh(
house,
new THREE.BoxGeometry(1.78, 1.42, 1.42),
material(wall),
[0, 0.73, 0]
);
const roofShape = new THREE.Shape();
roofShape.moveTo(-1.12, 0);
roofShape.lineTo(1.12, 0);
roofShape.lineTo(0, 0.72);
roofShape.closePath();
const roofGeometry = new THREE.ExtrudeGeometry(roofShape, {
depth: 1.66,
bevelEnabled: false
});
roofGeometry.translate(0, 0, -0.83);
addMesh(house, roofGeometry, material(roof), [0, 1.44, 0]);
// Door.
addMesh(
house,
new THREE.BoxGeometry(0.42, 0.84, 0.07),
material(accent),
[0.22, 0.47, 0.745]
);
addMesh(
house,
new THREE.SphereGeometry(0.035, 10, 8),
material(0xf8d27e),
[0.36, 0.47, 0.795]
);
// Window and frame.
addMesh(
house,
new THREE.BoxGeometry(0.57, 0.53, 0.065),
material(0xf5f7ef),
[-0.52, 0.9, 0.745]
);
addMesh(
house,
new THREE.BoxGeometry(0.44, 0.4, 0.075),
material(0x91b8ca, { roughness: 0.38 }),
[-0.52, 0.9, 0.79]
);
addMesh(
house,
new THREE.BoxGeometry(0.045, 0.42, 0.09),
material(0xf7f5e9),
[-0.52, 0.9, 0.84]
);
addMesh(
house,
new THREE.BoxGeometry(0.46, 0.045, 0.09),
material(0xf7f5e9),
[-0.52, 0.9, 0.84]
);
// Chimney.
addMesh(
house,
new THREE.BoxGeometry(0.23, 0.49, 0.25),
material(roof),
[0.52, 1.9, -0.16]
);
// Resident.
const person = makePerson(shirt, skin, hair, 0.94);
person.position.set(personOffset, 0.08, 1.03);
house.add(person);
const nameLabel = makeLabel(label, {
foreground: accent,
background: "rgba(255,255,255,0.91)",
width: 2.0,
height: 0.43,
fontSize: 36
});
nameLabel.position.set(0, 2.55, 0);
house.add(nameLabel);
scene.add(house);
return house;
}
makeHouse({
x: -3.55,
accent: "#e66e42",
roof: "#c95738",
wall: "#f5dfc9",
label: "MAPLE HOME",
shirt: "#e8794c",
skin: "#a9694e",
hair: "#342d2b",
personOffset: 0.62
});
makeHouse({
x: 3.55,
accent: "#269d7b",
roof: "#247c68",
wall: "#dce9df",
label: "CEDAR HOME",
shirt: "#2aa27f",
skin: "#e2b18e",
hair: "#614536",
personOffset: -0.62
});
// Small trees and shrubs around the miniature platform.
function makeTree(x, z, scale, tint) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
addMesh(
tree,
new THREE.CylinderGeometry(0.09, 0.12, 0.8, 9),
material(0x7d6250),
[0, 0.39, 0]
);
addMesh(
tree,
new THREE.ConeGeometry(0.48, 1.25, 10),
material(tint),
[0, 1.18, 0]
);
addMesh(
tree,
new THREE.ConeGeometry(0.36, 1.0, 10),
material(tint),
[0, 1.7, 0]
);
scene.add(tree);
}
makeTree(-4.75, -1.7, 0.72, 0x779c83);
makeTree(4.78, -1.62, 0.7, 0x628e7b);
makeTree(-1.95, -2.55, 0.53, 0x86a88c);
makeTree(2.02, -2.58, 0.5, 0x759d82);
for (const [x, z, sx, color] of [
[-2.4, 1.55, 0.22, 0x8dad87],
[2.35, 1.62, 0.24, 0x789f80],
[-5.0, 0.35, 0.2, 0x98b18d],
[5.05, 0.42, 0.22, 0x87a681]
]) {
const bush = addMesh(
scene,
new THREE.SphereGeometry(0.55, 12, 9),
material(color),
[x, 0.18, z]
);
bush.scale.set(1.2, 0.65, 1);
}
// ---------------------------------------------------------------------
// The one and only physical shared tool
// ---------------------------------------------------------------------
addMesh(
scene,
new THREE.CylinderGeometry(0.86, 0.94, 0.2, 48),
material(0xd8dfd8),
[0, 0.06, -0.16]
);
addMesh(
scene,
new THREE.CylinderGeometry(0.74, 0.78, 0.07, 48),
material(0xf8f7ef),
[0, 0.19, -0.16]
);
const toolHaloMaterial = new THREE.MeshBasicMaterial({
color: 0x9bb5c1,
transparent: true,
opacity: 0.45,
depthWrite: false
});
const toolHalo = addMesh(
scene,
new THREE.TorusGeometry(0.66, 0.035, 10, 72),
toolHaloMaterial,
[0, 0.235, -0.16],
[Math.PI / 2, 0, 0]
);
toolHalo.castShadow = false;
// This exact group is the physical object. It is never cloned.
const physicalTool = new THREE.Group();
physicalTool.name = "PHYSICAL_TOOL_SINGLETON";
physicalTool.userData.physicalCount = 1;
physicalTool.position.set(0, 0.49, -0.16);
physicalTool.rotation.y = -0.28;
const coral = material(0xf27850, { roughness: 0.48 });
const navy = material(0x2f4253, { roughness: 0.55 });
const yellow = material(0xf5c85c, { roughness: 0.48 });
const steel = material(0xb8c5cb, {
roughness: 0.28,
metalness: 0.72
});
// Rounded drill motor.
addMesh(
physicalTool,
new THREE.CapsuleGeometry(0.22, 0.53, 6, 18),
coral,
[0, 0.39, 0],
[0, 0, Math.PI / 2]
);
addMesh(
physicalTool,
new THREE.CylinderGeometry(0.215, 0.215, 0.12, 18),
navy,
[-0.6, 0.39, 0],
[0, 0, Math.PI / 2]
);
// Handle and battery.
addMesh(
physicalTool,
new THREE.BoxGeometry(0.29, 0.58, 0.27),
navy,
[-0.17, 0.03, 0],
[0, 0, -0.17]
);
addMesh(
physicalTool,
new THREE.BoxGeometry(0.43, 0.16, 0.33),
navy,
[-0.24, -0.25, 0]
);
addMesh(
physicalTool,
new THREE.BoxGeometry(0.13, 0.19, 0.18),
yellow,
[0.01, 0.16, 0],
[0, 0, -0.14]
);
// Chuck and bit.
addMesh(
physicalTool,
new THREE.CylinderGeometry(0.15, 0.18, 0.32, 18),
navy,
[0.58, 0.39, 0],
[0, 0, Math.PI / 2]
);
addMesh(
physicalTool,
new THREE.CylinderGeometry(0.065, 0.065, 0.43, 14),
steel,
[0.91, 0.39, 0],
[0, 0, Math.PI / 2]
);
addMesh(
physicalTool,
new THREE.ConeGeometry(0.066, 0.18, 12),
steel,
[1.18, 0.39, 0],
[0, 0, -Math.PI / 2]
);
// Small side detailing.
addMesh(
physicalTool,
new THREE.CylinderGeometry(0.095, 0.095, 0.025, 18),
yellow,
[0.1, 0.39, 0.211],
[Math.PI / 2, 0, 0]
);
scene.add(physicalTool);
const toolCountLabel = makeLabel("1 PHYSICAL TOOL", {
foreground: "#32485b",
background: "rgba(255,255,255,0.94)",
border: "rgba(50,72,91,0.16)",
width: 2.15,
height: 0.45,
fontSize: 36
});
toolCountLabel.position.set(0, 1.55, -0.16);
scene.add(toolCountLabel);
// Green pulse is an effect around the existing tool, not another object.
const returnPulseMaterial = new THREE.MeshBasicMaterial({
color: 0x20a77d,
transparent: true,
opacity: 0,
depthWrite: false
});
const returnPulse = addMesh(
scene,
new THREE.TorusGeometry(0.68, 0.04, 10, 72),
returnPulseMaterial,
[0, 0.26, -0.16],
[Math.PI / 2, 0, 0]
);
returnPulse.castShadow = false;
returnPulse.visible = false;
// ---------------------------------------------------------------------
// Borrow / return token track and two separate markers
// ---------------------------------------------------------------------
const trackZ = 1.38;
const borrowedX = -1.55;
const returnedX = 1.55;
addMesh(
scene,
new THREE.BoxGeometry(3.55, 0.045, 0.31),
material(0xe1e6de),
[0, 0.005, trackZ]
);
for (let i = 0; i <= 16; i++) {
const x = THREE.MathUtils.lerp(borrowedX, returnedX, i / 16);
const dot = addMesh(
scene,
new THREE.CylinderGeometry(0.032, 0.032, 0.025, 10),
material(i < 8 ? 0xe4a06e : 0x83bca7),
[x, 0.043, trackZ]
);
dot.castShadow = false;
}
// A left chevron for borrowing and a right chevron for returning.
const borrowArrow = addMesh(
scene,
new THREE.ConeGeometry(0.105, 0.27, 3),
material(0xe99562),
[-0.72, 0.09, trackZ],
[0, 0, Math.PI / 2]
);
borrowArrow.castShadow = false;
const returnArrow = addMesh(
scene,
new THREE.ConeGeometry(0.105, 0.27, 3),
material(0x65ae93),
[0.72, 0.09, trackZ],
[0, 0, -Math.PI / 2]
);
returnArrow.castShadow = false;
function makeMarker(x, color, title, borderColor) {
const group = new THREE.Group();
group.position.set(x, 0, trackZ);
addMesh(
group,
new THREE.CylinderGeometry(0.4, 0.45, 0.12, 40),
material(0xf8f7ef),
[0, 0.08, 0]
);
const ringMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.22,
roughness: 0.4
});
const ring = addMesh(
group,
new THREE.TorusGeometry(0.27, 0.065, 10, 48),
ringMaterial,
[0, 0.17, 0],
[Math.PI / 2, 0, 0]
);
const coreMaterial = new THREE.MeshStandardMaterial({
color: 0xfaf8ee,
emissive: color,
emissiveIntensity: 0.06,
roughness: 0.55
});
const core = addMesh(
group,
new THREE.CylinderGeometry(0.18, 0.18, 0.08, 32),
coreMaterial,
[0, 0.17, 0]
);
const label = makeLabel(title, {
foreground: borderColor,
background: "rgba(255,255,255,0.93)",
border: borderColor,
width: 1.85,
height: 0.42,
fontSize: 35
});
label.position.set(0, 0.69, 0.16);
group.add(label);
scene.add(group);
return { group, ring, core, ringMaterial, coreMaterial };
}
const borrowedMarker = makeMarker(
borrowedX,
0xf1834e,
"BORROWED",
"#d86637"
);
const returnedMarker = makeMarker(
returnedX,
0x2aa47d,
"RETURNED",
"#238363"
);
const trackLabel = makeLabel("CUSTODY TOKEN TRACK", {
foreground: "#6e7e8d",
background: "rgba(247,247,239,0.82)",
width: 2.35,
height: 0.34,
fontSize: 29
});
trackLabel.position.set(0, 0.22, trackZ + 0.48);
scene.add(trackLabel);
// A single token moves between the two separate markers.
const token = new THREE.Group();
token.position.set(0, 0.42, trackZ);
const tokenMaterial = new THREE.MeshStandardMaterial({
color: 0xf9f5e8,
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.3,
metalness: 0.06
});
const tokenFace = addMesh(
token,
new THREE.CylinderGeometry(0.255, 0.255, 0.1, 40),
tokenMaterial,
[0, 0, 0],
[Math.PI / 2, 0, 0]
);
const tokenRimMaterial = new THREE.MeshStandardMaterial({
color: 0x647587,
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.3,
metalness: 0.3
});
addMesh(
token,
new THREE.TorusGeometry(0.225, 0.035, 9, 40),
tokenRimMaterial,
[0, 0, 0.055]
);
const tokenDotMaterial = material(0x6d7e8c);
addMesh(
token,
new THREE.SphereGeometry(0.043, 10, 8),
tokenDotMaterial,
[0, 0, 0.11]
);
scene.add(token);
const tokenLabel = makeLabel("CUSTODY TOKEN", {
foreground: "#41576a",
background: "rgba(255,255,255,0.91)",
width: 1.75,
height: 0.36,
fontSize: 29
});
tokenLabel.position.set(0, 1.02, trackZ);
scene.add(tokenLabel);
// ---------------------------------------------------------------------
// Obligation link: visible while open, removed when the return closes it
// ---------------------------------------------------------------------
const obligationMaterial = new THREE.MeshBasicMaterial({
color: 0xf0824e,
transparent: true,
opacity: 0,
depthWrite: false
});
const obligationBeads = [];
for (let i = 0; i < 15; i++) {
const bead = addMesh(
scene,
new THREE.SphereGeometry(0.043, 9, 7),
obligationMaterial,
[0, 0, 0]
);
bead.castShadow = false;
obligationBeads.push(bead);
}
const obligationLabel = makeLabel("OPEN OBLIGATION", {
foreground: "#bb5c30",
background: "rgba(255,244,233,0.94)",
border: "#e69a70",
width: 1.9,
height: 0.38,
fontSize: 31
});
obligationLabel.position.set(-0.65, 1.08, 0.66);
obligationLabel.material.opacity = 0;
scene.add(obligationLabel);
const closedLabel = makeLabel("✓ OBLIGATION CLOSED", {
foreground: "#187b5d",
background: "rgba(232,249,241,0.95)",
border: "#74bea1",
width: 2.15,
height: 0.42,
fontSize: 31
});
closedLabel.position.set(returnedX, 1.12, trackZ);
closedLabel.material.opacity = 0;
scene.add(closedLabel);
function updateObligationBeads() {
for (let i = 0; i < obligationBeads.length; i++) {
const t = i / (obligationBeads.length - 1);
const bead = obligationBeads[i];
bead.position.set(
THREE.MathUtils.lerp(borrowedX, 0, t),
0.38 + Math.sin(t * Math.PI) * 0.58,
THREE.MathUtils.lerp(trackZ, -0.16, t)
);
bead.scale.setScalar(0.7 + Math.sin(t * Math.PI) * 0.55);
}
}
updateObligationBeads();
// ---------------------------------------------------------------------
// State machine: borrow -> open obligation -> return -> closed obligation
// ---------------------------------------------------------------------
const borrowButton = document.querySelector("#borrowButton");
const returnButton = document.querySelector("#returnButton");
const resetButton = document.querySelector("#resetButton");
const stateBadge = document.querySelector("#stateBadge");
const obligationValue = document.querySelector("#obligationValue");
const tokenValue = document.querySelector("#tokenValue");
const proof = document.querySelector("#proof");
let phase = "idle";
let tokenX = 0;
let transition = null;
let visualBorrowed = 0;
let visualReturned = 0;
let tetherOpacity = 0;
let closedOpacity = 0;
let pulseAge = null;
const neutralColor = new THREE.Color(0xf9f5e8);
const orangeColor = new THREE.Color(0xf58a4c);
const greenColor = new THREE.Color(0x36b98c);
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function beginTokenTransition(to, duration, onComplete) {
transition = {
from: tokenX,
to,
start: performance.now(),
duration,
onComplete
};
}
function setBadge(text, className) {
stateBadge.textContent = text;
stateBadge.className = `state-badge ${className}`;
}
function renderUI() {
borrowButton.disabled = !["idle", "returned"].includes(phase);
returnButton.disabled = phase !== "borrowed";
if (phase === "idle") {
setBadge("READY", "");
obligationValue.textContent = "None";
tokenValue.textContent = "Ready";
proof.innerHTML =
"<strong>The tool is available.</strong> Borrowing will open one obligation.";
} else if (phase === "borrowing") {
setBadge("BORROWING", "open");
obligationValue.textContent = "Opening";
tokenValue.textContent = "Borrowed";
proof.innerHTML =
"<strong>One custody token</strong> is moving to the BORROWED marker.";
} else if (phase === "borrowed") {
setBadge("OPEN", "open");
obligationValue.textContent = "Open";
tokenValue.textContent = "Borrowed";
proof.innerHTML =
"<strong>One obligation is open.</strong> The physical tool count remains 1.";
} else if (phase === "returning") {
setBadge("RETURNING", "closed");
obligationValue.textContent = "Closing";
tokenValue.textContent = "Returned";
proof.innerHTML =
"<strong>The same token is moving to RETURNED.</strong> The open link is being closed.";
} else if (phase === "returned") {
setBadge("CLOSED", "closed");
obligationValue.textContent = "Closed";
tokenValue.textContent = "Returned";
proof.innerHTML =
"<strong>Return recorded.</strong> The same single tool remains. No second tool was created.";
} else if (phase === "resetting") {
setBadge("RESETTING", "");
obligationValue.textContent = "None";
tokenValue.textContent = "Ready";
proof.innerHTML =
"<strong>Resetting the ledger.</strong> The physical tool count is still 1.";
}
}
borrowButton.addEventListener("click", () => {
if (!["idle", "returned"].includes(phase)) return;
phase = "borrowing";
beginTokenTransition(borrowedX, 900, () => {
phase = "borrowed";
renderUI();
});
renderUI();
});
returnButton.addEventListener("click", () => {
if (phase !== "borrowed") return;
phase = "returning";
pulseAge = 0;
beginTokenTransition(returnedX, 1000, () => {
phase = "returned";
renderUI();
});
renderUI();
});
resetButton.addEventListener("click", () => {
if (phase === "idle" && tokenX === 0) return;
phase = "resetting";
beginTokenTransition(0, 650, () => {
phase = "idle";
renderUI();
});
renderUI();
});
renderUI();
// ---------------------------------------------------------------------
// Responsive sizing
// ---------------------------------------------------------------------
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
resize();
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const now = performance.now();
const time = clock.elapsedTime;
if (transition) {
const raw = THREE.MathUtils.clamp(
(now - transition.start) / transition.duration,
0,
1
);
const eased = easeInOutCubic(raw);
tokenX = THREE.MathUtils.lerp(transition.from, transition.to, eased);
token.position.y = 0.42 + Math.sin(raw * Math.PI) * 0.48;
if (raw >= 1) {
const completed = transition;
transition = null;
tokenX = completed.to;
token.position.y = 0.42;
completed.onComplete();
}
} else {
token.position.y = 0.42 + Math.sin(time * 2.2) * 0.035;
}
token.position.x = tokenX;
token.rotation.y += dt * 0.65;
tokenLabel.position.x = tokenX;
// Marker activation smoothly responds to the current phase.
const borrowedTarget =
phase === "borrowed" ? 1 : phase === "borrowing" ? 0.45 : 0;
const returnedTarget =
phase === "returned" ? 1 : phase === "returning" ? 0.55 : 0;
const tetherTarget = phase === "borrowed" ? 1 : 0;
const closedTarget = phase === "returned" ? 1 : 0;
visualBorrowed = THREE.MathUtils.lerp(
visualBorrowed,
borrowedTarget,
1 - Math.exp(-dt * 8)
);
visualReturned = THREE.MathUtils.lerp(
visualReturned,
returnedTarget,
1 - Math.exp(-dt * 8)
);
tetherOpacity = THREE.MathUtils.lerp(
tetherOpacity,
tetherTarget,
1 - Math.exp(-dt * 9)
);
closedOpacity = THREE.MathUtils.lerp(
closedOpacity,
closedTarget,
1 - Math.exp(-dt * 8)
);
borrowedMarker.ring.scale.setScalar(1 + visualBorrowed * 0.12);
borrowedMarker.core.scale.setScalar(1 + visualBorrowed * 0.08);
borrowedMarker.ringMaterial.emissiveIntensity = 0.18 + visualBorrowed * 1.1;
borrowedMarker.coreMaterial.emissiveIntensity = 0.04 + visualBorrowed * 0.65;
returnedMarker.ring.scale.setScalar(1 + visualReturned * 0.12);
returnedMarker.core.scale.setScalar(1 + visualReturned * 0.08);
returnedMarker.ringMaterial.emissiveIntensity = 0.18 + visualReturned * 1.1;
returnedMarker.coreMaterial.emissiveIntensity = 0.04 + visualReturned * 0.65;
obligationMaterial.opacity = tetherOpacity * 0.9;
obligationLabel.material.opacity = tetherOpacity;
closedLabel.material.opacity = closedOpacity;
// Token color communicates its marker without replacing the token.
const targetTokenColor =
phase === "borrowing" || phase === "borrowed"
? orangeColor
: phase === "returning" || phase === "returned"
? greenColor
: neutralColor;
tokenMaterial.color.lerp(
targetTokenColor,
1 - Math.exp(-dt * 8)
);
tokenRimMaterial.color.lerp(
targetTokenColor,
1 - Math.exp(-dt * 8)
);
tokenRimMaterial.emissive.copy(tokenMaterial.color);
tokenRimMaterial.emissiveIntensity = phase === "idle" ? 0 : 0.22;
// Halo around the existing tool reflects the ledger state.
const targetHaloColor =
phase === "borrowed"
? orangeColor
: phase === "returned"
? greenColor
: new THREE.Color(0x9bb5c1);
toolHaloMaterial.color.lerp(
targetHaloColor,
1 - Math.exp(-dt * 7)
);
toolHaloMaterial.opacity = 0.35 + visualBorrowed * 0.2 + visualReturned * 0.2;
toolHalo.scale.setScalar(1 + Math.sin(time * 2) * 0.012);
// A single expanding pulse confirms the return of the same object.
if (pulseAge !== null) {
pulseAge += dt;
const t = THREE.MathUtils.clamp(pulseAge / 1.2, 0, 1);
returnPulse.visible = t < 1;
returnPulse.scale.setScalar(1 + t * 1.8);
returnPulseMaterial.opacity = (1 - t) * 0.7;
toolCountLabel.scale.set(
2.15 * (1 + Math.sin(t * Math.PI) * 0.08),
0.45 * (1 + Math.sin(t * Math.PI) * 0.08),
1
);
if (t >= 1) {
pulseAge = null;
returnPulse.visible = false;
}
} else {
toolCountLabel.scale.set(2.15, 0.45, 1);
}
renderer.render(scene, camera);
}
animate();
document.querySelector("#loading").classList.add("hidden");
setTimeout(() => {
document.querySelector("#loading").remove();
}, 400);
</script>
</body>
</html>
```