Prompt specification
Build or customize the Three.js 3D scene "Ten Houses and a Shared Reserve Jar" 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: Ten Houses and a Shared Reserve Jar
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/ten-houses-and-a-shared-reserve-jar-x3189
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring pooled and individual reserves. Arrange ten identical house tokens beside one reserve jar and individual jars. Distinguish pooled resources from the total amount available without simulating real insurance pricing. Stylized solid forms.
Working Three.js Starter (ten-houses-and-a-shared-reserve-jar-x3189):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Reserves — Pooled vs. Individual</title>
<style>
:root {
--ink: #18333a;
--muted: #66777a;
--paper: #f5f0e6;
--panel: rgba(250, 247, 239, 0.9);
--pooled: #247d89;
--individual: #dc8158;
--gold: #d8a943;
--line: rgba(24, 51, 58, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9d4ca;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.topbar {
position: absolute;
top: 20px;
left: 22px;
right: 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 42px;
height: 42px;
flex: 0 0 auto;
border-radius: 14px;
background: var(--ink);
box-shadow: 0 9px 24px rgba(24, 51, 58, 0.18);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
border-radius: 50%;
background: var(--paper);
}
.brand-mark::before {
width: 9px;
height: 9px;
left: 9px;
top: 10px;
box-shadow: 15px 0 0 var(--gold);
}
.brand-mark::after {
width: 24px;
height: 4px;
left: 9px;
bottom: 9px;
border-radius: 2px;
opacity: 0.9;
}
.eyebrow {
margin: 0 0 2px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
overflow: hidden;
font-size: clamp(17px, 2vw, 24px);
line-height: 1.15;
font-weight: 750;
letter-spacing: -0.035em;
text-overflow: ellipsis;
white-space: nowrap;
}
.mode-panel {
pointer-events: auto;
display: flex;
align-items: center;
gap: 12px;
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 12px 35px rgba(47, 57, 54, 0.11);
backdrop-filter: blur(16px);
}
.mode-label {
padding: 0 4px 0 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.segment {
display: flex;
gap: 4px;
padding: 3px;
border-radius: 11px;
background: rgba(24, 51, 58, 0.07);
}
.segment button {
min-width: 102px;
padding: 10px 14px;
border: 0;
border-radius: 8px;
color: var(--muted);
background: transparent;
font-size: 13px;
font-weight: 750;
cursor: pointer;
transition:
color 180ms ease,
background 180ms ease,
box-shadow 180ms ease,
transform 180ms ease;
}
.segment button:hover {
color: var(--ink);
}
.segment button:active {
transform: scale(0.97);
}
.segment button[aria-pressed="true"] {
color: #fff;
background: var(--ink);
box-shadow: 0 5px 14px rgba(24, 51, 58, 0.2);
}
body[data-mode="pooled"] #pooledButton[aria-pressed="true"] {
background: var(--pooled);
}
body[data-mode="individual"] #individualButton[aria-pressed="true"] {
background: var(--individual);
}
.readout {
position: absolute;
left: 22px;
bottom: 22px;
width: min(355px, calc(100vw - 44px));
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(42, 49, 47, 0.14);
backdrop-filter: blur(18px);
}
.readout-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.readout-head .eyebrow {
margin: 0;
}
.scene-status {
color: var(--muted);
font-size: 11px;
font-weight: 700;
white-space: nowrap;
}
.metric {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 12px;
padding: 11px 0;
border-top: 1px solid var(--line);
}
.metric-name {
font-size: 13px;
font-weight: 750;
}
.metric-detail {
margin-top: 2px;
color: var(--muted);
font-size: 11px;
}
.metric-value {
font-size: 17px;
font-weight: 850;
letter-spacing: -0.03em;
white-space: nowrap;
}
.metric-value.pooled {
color: var(--pooled);
}
.metric-value.individual {
color: var(--individual);
}
.metric.total {
margin-top: 7px;
padding: 13px 14px;
border: 0;
border-radius: 12px;
background: var(--ink);
color: #fff;
}
.metric.total .metric-name,
.metric.total .metric-detail,
.metric.total .metric-value {
color: #fff;
}
.metric.total .metric-detail {
opacity: 0.66;
}
.readout-note {
margin: 12px 1px 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.readout-note strong {
color: var(--ink);
}
.camera-hint {
position: absolute;
right: 22px;
bottom: 22px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 12px;
color: rgba(24, 51, 58, 0.72);
background: rgba(250, 247, 239, 0.72);
font-size: 11px;
font-weight: 650;
backdrop-filter: blur(12px);
}
#worldLabels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
top: 0;
left: 0;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 10px;
color: #fff;
background: rgba(24, 51, 58, 0.86);
box-shadow: 0 8px 22px rgba(24, 51, 58, 0.17);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
transform-origin: center;
transition:
opacity 300ms ease,
background 300ms ease;
}
.world-label.pooled {
background: rgba(28, 111, 122, 0.9);
}
.world-label.individual {
background: rgba(190, 98, 58, 0.92);
}
.world-label.muted {
opacity: 0.44;
}
@media (max-width: 760px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
align-items: flex-start;
}
.brand-mark {
width: 38px;
height: 38px;
}
.brand .eyebrow {
display: none;
}
h1 {
max-width: 175px;
font-size: 16px;
}
.mode-panel {
gap: 4px;
}
.mode-label {
display: none;
}
.segment button {
min-width: 78px;
padding: 9px 10px;
font-size: 11px;
}
.readout {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.readout-head {
margin-bottom: 5px;
}
.metric {
padding: 7px 0;
}
.metric.total {
margin-top: 4px;
padding: 10px 12px;
}
.readout-note {
margin-top: 8px;
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body data-mode="pooled">
<div id="scene"></div>
<div id="worldLabels" aria-hidden="true">
<div id="sharedLabel" class="world-label pooled">Pooled reserve · 100</div>
<div id="individualLabel" class="world-label individual muted">
Individual jars · empty
</div>
</div>
<main class="ui">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<p class="eyebrow">Reserve study</p>
<h1>One total, two ways to hold it.</h1>
</div>
</div>
<div class="mode-panel">
<span class="mode-label">Reserve layout</span>
<div class="segment" role="group" aria-label="Reserve layout">
<button
id="pooledButton"
type="button"
aria-pressed="true"
>
Pooled
</button>
<button
id="individualButton"
type="button"
aria-pressed="false"
>
Individual
</button>
</div>
</div>
</header>
<section class="readout" aria-label="Resource totals">
<div class="readout-head">
<p class="eyebrow">Resource accounting</p>
<span id="sceneStatus" class="scene-status" aria-live="polite">
Pooled layout
</span>
</div>
<div class="metric">
<div>
<div class="metric-name">Pooled reserve</div>
<div id="pooledDetail" class="metric-detail">One shared jar</div>
</div>
<div id="pooledValue" class="metric-value pooled" aria-live="polite">
100 units
</div>
</div>
<div class="metric">
<div>
<div class="metric-name">Individual reserves</div>
<div id="individualDetail" class="metric-detail">10 jars × 10 units</div>
</div>
<div
id="individualValue"
class="metric-value individual"
aria-live="polite"
>
0 units
</div>
</div>
<div class="metric total">
<div>
<div class="metric-name">Total available</div>
<div class="metric-detail">An accounting sum, not another reserve</div>
</div>
<div class="metric-value">100 units</div>
</div>
<p class="readout-note">
The layout changes where the <strong>same 100 units</strong> are held.
This is a conceptual illustration only—no premiums, rates, claims, or
pricing model.
</p>
</section>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const pooledButton = document.querySelector("#pooledButton");
const individualButton = document.querySelector("#individualButton");
const pooledValue = document.querySelector("#pooledValue");
const individualValue = document.querySelector("#individualValue");
const pooledDetail = document.querySelector("#pooledDetail");
const individualDetail = document.querySelector("#individualDetail");
const sceneStatus = document.querySelector("#sceneStatus");
const sharedLabel = document.querySelector("#sharedLabel");
const individualLabel = document.querySelector("#individualLabel");
const prefersReducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9d4ca);
scene.fog = new THREE.Fog(0xd9d4ca, 48, 95);
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.12;
renderer.domElement.setAttribute(
"aria-label",
"Ten house tokens with one shared reserve jar and ten individual reserve jars"
);
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
140
);
const cameraTarget = new THREE.Vector3(2, 0.45, -0.25);
const spherical = new THREE.Spherical();
function resetCamera() {
const aspect = window.innerWidth / window.innerHeight;
const mobileScale = aspect < 0.9 ? 1.38 : 1;
const offset = new THREE.Vector3(7, 16, 31).multiplyScalar(mobileScale);
camera.position.copy(cameraTarget).add(offset);
spherical.setFromVector3(offset);
camera.lookAt(cameraTarget);
}
resetCamera();
// Lighting.
scene.add(new THREE.HemisphereLight(0xfff8e9, 0x72838a, 2.2));
const keyLight = new THREE.DirectionalLight(0xfff2d5, 3.1);
keyLight.position.set(-8, 20, 13);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -22;
keyLight.shadow.camera.right = 22;
keyLight.shadow.camera.top = 18;
keyLight.shadow.camera.bottom = -18;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 55;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xa9d7df, 1.1);
fillLight.position.set(15, 8, -10);
scene.add(fillLight);
// Materials.
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options
});
const groundMaterial = material(0xd9d4ca);
const platformMaterial = material(0xf1eadc);
const platformEdgeMaterial = material(0xcabfae);
const houseWallMaterial = material(0xf7f0df);
const houseRoofMaterial = material(0x24454c);
const houseBaseMaterial = material(0x2f5960);
const doorMaterial = material(0xd6a640);
const windowMaterial = material(0xb8dce0, {
emissive: 0x507f84,
emissiveIntensity: 0.12
});
const sharedBodyMaterial = material(0x247d89);
const sharedBandMaterial = material(0x155965);
const sharedPlaqueMaterial = material(0x173b42);
const personalBodyMaterial = material(0xb6b1a8);
const personalBandMaterial = material(0x9f9b94);
const personalPlaqueMaterial = material(0x633f32);
// Ground and raised diorama platform.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.77;
ground.receiveShadow = true;
scene.add(ground);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(14.2, 14.5, 0.42, 96),
platformMaterial
);
platform.position.set(2.1, -0.28, 0);
platform.scale.set(1.12, 1, 0.72);
platform.receiveShadow = true;
scene.add(platform);
const platformEdge = new THREE.Mesh(
new THREE.CylinderGeometry(14.35, 14.7, 0.3, 96),
platformEdgeMaterial
);
platformEdge.position.set(2.1, -0.56, 0);
platformEdge.scale.set(1.12, 1, 0.72);
platformEdge.receiveShadow = true;
scene.add(platformEdge);
// Shared geometries keep every house visually identical.
const houseBaseGeometry = new THREE.CylinderGeometry(0.61, 0.65, 0.13, 36);
const houseBodyGeometry = new THREE.BoxGeometry(0.66, 0.56, 0.58);
const houseRoofGeometry = new THREE.ConeGeometry(0.57, 0.4, 4);
const houseDoorGeometry = new THREE.BoxGeometry(0.16, 0.31, 0.035);
const houseWindowGeometry = new THREE.BoxGeometry(0.13, 0.13, 0.035);
const houseChimneyGeometry = new THREE.BoxGeometry(0.12, 0.24, 0.13);
const houseXs = [];
const personalPositions = [];
function addHouse(index, x) {
const house = new THREE.Group();
house.position.set(x, 0, -1.9);
scene.add(house);
const base = new THREE.Mesh(houseBaseGeometry, houseBaseMaterial);
base.position.y = 0;
base.castShadow = true;
base.receiveShadow = true;
house.add(base);
const body = new THREE.Mesh(houseBodyGeometry, houseWallMaterial);
body.position.y = 0.55;
body.castShadow = true;
body.receiveShadow = true;
house.add(body);
const roof = new THREE.Mesh(houseRoofGeometry, houseRoofMaterial);
roof.position.y = 1.01;
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.92;
roof.castShadow = true;
house.add(roof);
const door = new THREE.Mesh(houseDoorGeometry, doorMaterial);
door.position.set(0, 0.39, 0.307);
door.castShadow = true;
house.add(door);
for (const windowX of [-0.205, 0.205]) {
const windowMesh = new THREE.Mesh(
houseWindowGeometry,
windowMaterial
);
windowMesh.position.set(windowX, 0.61, 0.306);
house.add(windowMesh);
}
const chimney = new THREE.Mesh(
houseChimneyGeometry,
houseRoofMaterial
);
chimney.position.set(0.24, 1.04, -0.08);
chimney.castShadow = true;
house.add(chimney);
const number = createNumberSprite(String(index + 1).padStart(2, "0"));
number.position.set(0, 1.48, 0);
house.add(number);
houseXs.push(x);
}
for (let i = 0; i < 10; i++) {
const x = -7.2 + i * 1.6;
addHouse(i, x);
personalPositions.push(new THREE.Vector3(x, 0, 0.72));
}
function createNumberSprite(text) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 64;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(24, 51, 58, 0.88)";
context.beginPath();
context.arc(64, 32, 25, 0, Math.PI * 2);
context.fill();
context.fillStyle = "#ffffff";
context.font = "700 25px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 64, 33);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(0.48, 0.24, 1);
return sprite;
}
// One large shared reserve jar.
const sharedJar = new THREE.Group();
sharedJar.position.set(11.05, 0, -0.12);
scene.add(sharedJar);
const sharedBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.78, 0.94, 0.96, 40),
sharedBodyMaterial
);
sharedBody.position.y = 0.49;
sharedBody.castShadow = true;
sharedBody.receiveShadow = true;
sharedJar.add(sharedBody);
const sharedFoot = new THREE.Mesh(
new THREE.TorusGeometry(0.82, 0.075, 14, 48),
sharedBandMaterial
);
sharedFoot.rotation.x = Math.PI / 2;
sharedFoot.position.y = 0.09;
sharedFoot.castShadow = true;
sharedJar.add(sharedFoot);
const sharedLip = new THREE.Mesh(
new THREE.TorusGeometry(0.77, 0.085, 14, 48),
sharedBandMaterial
);
sharedLip.rotation.x = Math.PI / 2;
sharedLip.position.y = 0.97;
sharedLip.castShadow = true;
sharedJar.add(sharedLip);
const sharedPlaque = new THREE.Mesh(
new THREE.BoxGeometry(0.9, 0.31, 0.065),
sharedPlaqueMaterial
);
sharedPlaque.position.set(0, 0.54, 0.86);
sharedPlaque.castShadow = true;
sharedJar.add(sharedPlaque);
const sharedPlaqueMark = new THREE.Mesh(
new THREE.BoxGeometry(0.45, 0.055, 0.025),
doorMaterial
);
sharedPlaqueMark.position.set(0, 0.54, 0.906);
sharedJar.add(sharedPlaqueMark);
const sharedHaloMaterial = new THREE.MeshBasicMaterial({
color: 0x2e91a0,
transparent: true,
opacity: 0.68,
depthWrite: false
});
const sharedHalo = new THREE.Mesh(
new THREE.TorusGeometry(1.35, 0.035, 10, 80),
sharedHaloMaterial
);
sharedHalo.rotation.x = Math.PI / 2;
sharedHalo.position.set(11.05, -0.035, -0.12);
scene.add(sharedHalo);
// Ten smaller individual reserve jars.
const personalJars = [];
const personalHalos = [];
const personalBodyGeometry = new THREE.CylinderGeometry(
0.27,
0.31,
0.42,
28
);
const personalBandGeometry = new THREE.TorusGeometry(
0.275,
0.035,
10,
32
);
const personalPlaqueGeometry = new THREE.BoxGeometry(
0.17,
0.075,
0.025
);
for (const position of personalPositions) {
const jar = new THREE.Group();
jar.position.copy(position);
scene.add(jar);
const body = new THREE.Mesh(
personalBodyGeometry,
personalBodyMaterial
);
body.position.y = 0.22;
body.castShadow = true;
body.receiveShadow = true;
jar.add(body);
const band = new THREE.Mesh(
personalBandGeometry,
personalBandMaterial
);
band.rotation.x = Math.PI / 2;
band.position.y = 0.43;
band.castShadow = true;
jar.add(band);
const plaque = new THREE.Mesh(
personalPlaqueGeometry,
personalPlaqueMaterial
);
plaque.position.set(0, 0.25, 0.286);
jar.add(plaque);
const haloMaterial = new THREE.MeshBasicMaterial({
color: 0xdc8158,
transparent: true,
opacity: 0.06,
depthWrite: false
});
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.4, 0.018, 8, 40),
haloMaterial
);
halo.rotation.x = Math.PI / 2;
halo.position.set(position.x, -0.035, position.z);
scene.add(halo);
personalJars.push(jar);
personalHalos.push(halo);
}
// Conceptual relationship lines; no rates or pricing are represented.
const pooledLinePositions = [];
const personalLinePositions = [];
for (const x of houseXs) {
pooledLinePositions.push(
x, -0.045, -1.35,
11.05, -0.045, -0.12
);
personalLinePositions.push(
x, -0.045, -1.35,
x, -0.045, 0.36
);
}
const pooledLineGeometry = new THREE.BufferGeometry();
pooledLineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(pooledLinePositions, 3)
);
const personalLineGeometry = new THREE.BufferGeometry();
personalLineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(personalLinePositions, 3)
);
const pooledLineMaterial = new THREE.LineBasicMaterial({
color: 0x2b8290,
transparent: true,
opacity: 0.24,
depthWrite: false
});
const personalLineMaterial = new THREE.LineBasicMaterial({
color: 0xd17b53,
transparent: true,
opacity: 0.05,
depthWrite: false
});
scene.add(
new THREE.LineSegments(pooledLineGeometry, pooledLineMaterial)
);
scene.add(
new THREE.LineSegments(personalLineGeometry, personalLineMaterial)
);
// The same 100 resource tokens move between the two reserve layouts.
const resourceCount = 100;
const coinGeometry = new THREE.CylinderGeometry(
0.105,
0.105,
0.035,
20
);
const coinMaterial = material(0xd8a943, {
roughness: 0.48,
metalness: 0.12
});
const coinMesh = new THREE.InstancedMesh(
coinGeometry,
coinMaterial,
resourceCount
);
coinMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
coinMesh.castShadow = true;
coinMesh.receiveShadow = true;
scene.add(coinMesh);
const coinColors = [
new THREE.Color(0xd8a943),
new THREE.Color(0xe3b957),
new THREE.Color(0xc99635)
];
for (let i = 0; i < resourceCount; i++) {
coinMesh.setColorAt(i, coinColors[i % coinColors.length]);
}
coinMesh.instanceColor.needsUpdate = true;
const coins = Array.from({ length: resourceCount }, () => ({
position: new THREE.Vector3(),
from: new THREE.Vector3(),
to: new THREE.Vector3(),
delay: 0,
duration: 1,
angle: 0
}));
let mode = "pooled";
let transition = null;
function pooledTarget(index) {
const layer = Math.floor(index / 10);
const slot = index % 10;
const angle = (slot / 10) * Math.PI * 2 + layer * 0.31;
return new THREE.Vector3(
sharedJar.position.x + Math.cos(angle) * 0.46,
0.99 + layer * 0.037,
sharedJar.position.z + Math.sin(angle) * 0.46
);
}
function individualTarget(index) {
const home = Math.floor(index / 10);
const layer = index % 10;
const position = personalPositions[home];
return new THREE.Vector3(
position.x + Math.sin(layer * 2.1) * 0.012,
0.46 + layer * 0.036,
position.z + Math.cos(layer * 2.1) * 0.012
);
}
const coinDummy = new THREE.Object3D();
function writeCoinMatrix(index) {
const coin = coins[index];
coinDummy.position.copy(coin.position);
coinDummy.rotation.set(0, coin.angle, 0);
coinDummy.scale.setScalar(1);
coinDummy.updateMatrix();
coinMesh.setMatrixAt(index, coinDummy.matrix);
}
function updateReadout() {
const pooled = mode === "pooled";
pooledValue.textContent = pooled ? "100 units" : "0 units";
individualValue.textContent = pooled ? "0 units" : "100 units";
pooledDetail.textContent = pooled
? "One shared jar"
: "Shared jar is empty";
individualDetail.textContent = pooled
? "Ten jars are empty"
: "10 jars × 10 units";
sharedLabel.textContent = pooled
? "Pooled reserve · 100"
: "Shared jar · empty";
individualLabel.textContent = pooled
? "Individual jars · empty"
: "Individual reserves · 100";
sharedLabel.classList.toggle("muted", !pooled);
individualLabel.classList.toggle("muted", pooled);
}
function applyMode(nextMode, immediate = false) {
mode = nextMode;
document.body.dataset.mode = mode;
pooledButton.setAttribute("aria-pressed", String(mode === "pooled"));
individualButton.setAttribute(
"aria-pressed",
String(mode === "individual")
);
updateReadout();
const now = performance.now();
coins.forEach((coin, index) => {
coin.from.copy(coin.position);
coin.to.copy(
mode === "pooled"
? pooledTarget(index)
: individualTarget(index)
);
coin.angle = index * 0.37;
coin.delay =
(index % 10) * 0.018 + Math.floor(index / 10) * 0.006;
coin.duration = prefersReducedMotion ? 0.001 : 0.82;
});
if (immediate || prefersReducedMotion) {
coins.forEach((coin, index) => {
coin.position.copy(coin.to);
writeCoinMatrix(index);
});
coinMesh.instanceMatrix.needsUpdate = true;
transition = null;
sceneStatus.textContent =
mode === "pooled" ? "Pooled layout" : "Individual layout";
} else {
transition = {
start: now,
arcHeight:
mode === "pooled" ? 1.15 : 1.65
};
sceneStatus.textContent = "Moving 100 units…";
}
}
function updateCoins(now) {
if (!transition) {
coinMesh.instanceMatrix.needsUpdate = true;
return;
}
const elapsed = (now - transition.start) / 1000;
let complete = true;
coins.forEach((coin, index) => {
const localTime = elapsed - coin.delay;
const t = THREE.MathUtils.clamp(
localTime / coin.duration,
0,
1
);
if (t < 1) {
complete = false;
}
const eased =
t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
coin.position.lerpVectors(coin.from, coin.to, eased);
coin.position.y +=
Math.sin(Math.PI * t) * transition.arcHeight;
writeCoinMatrix(index);
});
coinMesh.instanceMatrix.needsUpdate = true;
if (complete) {
transition = null;
sceneStatus.textContent =
mode === "pooled" ? "Pooled layout" : "Individual layout";
}
}
applyMode("pooled", true);
pooledButton.addEventListener("click", () => {
if (mode !== "pooled") applyMode("pooled");
});
individualButton.addEventListener("click", () => {
if (mode !== "individual") applyMode("individual");
});
// Directly implemented camera controls: no Three.js examples/addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
spherical.theta -= deltaX * 0.0055;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi + deltaY * 0.0045,
0.3,
1.36
);
});
function endDrag(event) {
dragging = false;
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();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
18,
68
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
function updateCamera() {
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
function placeWorldLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
if (
projected.z < -1 ||
projected.z > 1 ||
projected.x < -1.2 ||
projected.x > 1.2 ||
projected.y < -1.2 ||
projected.y > 1.2
) {
element.style.visibility = "hidden";
return;
}
element.style.visibility = "visible";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -50%)`;
}
const sharedLabelPosition = new THREE.Vector3(11.05, 1.9, -0.12);
const individualLabelPosition = new THREE.Vector3(0, 1.35, 1.45);
const pooledColorActive = new THREE.Color(0x247d89);
const pooledColorInactive = new THREE.Color(0xa5afac);
const individualColorActive = new THREE.Color(0xdc8158);
const individualColorInactive = new THREE.Color(0xb6b1a8);
let lastTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
updateCamera();
updateCoins(now);
const colorLerp = 1 - Math.pow(0.0001, delta);
sharedBodyMaterial.color.lerp(
mode === "pooled" ? pooledColorActive : pooledColorInactive,
colorLerp
);
sharedBandMaterial.color.lerp(
mode === "pooled"
? new THREE.Color(0x155965)
: new THREE.Color(0x899491),
colorLerp
);
personalBodyMaterial.color.lerp(
mode === "individual"
? individualColorActive
: individualColorInactive,
colorLerp
);
personalBandMaterial.color.lerp(
mode === "individual"
? new THREE.Color(0xb85f39)
: new THREE.Color(0x9f9b94),
colorLerp
);
sharedHaloMaterial.opacity = THREE.MathUtils.lerp(
sharedHaloMaterial.opacity,
mode === "pooled" ? 0.68 : 0.07,
colorLerp
);
personalLineMaterial.opacity = THREE.MathUtils.lerp(
personalLineMaterial.opacity,
mode === "individual" ? 0.48 : 0.05,
colorLerp
);
pooledLineMaterial.opacity = THREE.MathUtils.lerp(
pooledLineMaterial.opacity,
mode === "pooled" ? 0.24 : 0.04,
colorLerp
);
for (const halo of personalHalos) {
halo.material.opacity = THREE.MathUtils.lerp(
halo.material.opacity,
mode === "individual" ? 0.64 : 0.05,
colorLerp
);
}
placeWorldLabel(sharedLabel, sharedLabelPosition);
placeWorldLabel(individualLabel, individualLabelPosition);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```