Prompt specification
Build or customize the Three.js 3D scene "Tall Narrow and Short Wide Containers" 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: Tall Narrow and Short Wide Containers
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/tall-narrow-and-short-wide-containers-x3365
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing comparison and ordering by object attributes. Place containers whose height and volume rankings differ. Use visible measurements so bigger cannot silently stand for taller, heavier, and more capacious at once. Stylized solid forms.
Working Three.js Starter (tall-narrow-and-short-wide-containers-x3365):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Container Attribute Comparison</title>
<style>
:root {
--ink: #182635;
--muted: #647386;
--line: #dce4e9;
--panel: #ffffff;
--stage: #eaf1f3;
--orion: #ef8354;
--atlas: #20a39e;
--mesa: #6c63a8;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--stage);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
.app {
min-height: 100vh;
display: flex;
flex-direction: column;
}
.topbar {
min-height: 82px;
padding: 16px 24px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
background: rgba(255, 255, 255, 0.94);
border-bottom: 1px solid var(--line);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 39px;
height: 39px;
flex: 0 0 auto;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 3px;
padding: 4px;
border-radius: 11px;
background: var(--ink);
transform: rotate(-4deg);
}
.brand-mark i {
display: block;
border-radius: 2px;
}
.brand-mark i:nth-child(1) {
background: var(--orion);
}
.brand-mark i:nth-child(2) {
background: var(--atlas);
}
.brand-mark i:nth-child(3) {
background: var(--mesa);
}
.brand-mark i:nth-child(4) {
background: #f4c95d;
}
.brand h1 {
margin: 0;
font-size: clamp(1.05rem, 2vw, 1.35rem);
line-height: 1.15;
letter-spacing: -0.025em;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 0.78rem;
}
.top-note {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 999px;
color: #48596a;
background: #f7f9fa;
font-size: 0.76rem;
white-space: nowrap;
}
.top-note::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: #29a36a;
box-shadow: 0 0 0 4px rgba(41, 163, 106, 0.12);
}
.layout {
flex: 1;
min-height: 0;
display: grid;
grid-template-columns: minmax(0, 1fr) 365px;
}
.stage {
position: relative;
min-width: 0;
min-height: 650px;
overflow: hidden;
isolation: isolate;
background:
radial-gradient(circle at 24% 18%, rgba(255, 255, 255, 0.92), transparent 34%),
linear-gradient(180deg, #f4f8f9 0%, #e4edef 100%);
}
#viewport,
#annotations {
position: absolute;
inset: 0;
}
#viewport {
z-index: 1;
}
#viewport canvas {
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#viewport canvas.dragging {
cursor: grabbing;
}
#annotations {
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.stage-top {
position: absolute;
z-index: 5;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
pointer-events: none;
}
.scale-badge,
.view-controls {
pointer-events: auto;
background: rgba(255, 255, 255, 0.86);
border: 1px solid rgba(193, 207, 214, 0.88);
box-shadow: 0 8px 28px rgba(35, 57, 72, 0.08);
backdrop-filter: blur(10px);
}
.scale-badge {
padding: 9px 12px;
border-radius: 10px;
color: #506172;
font-size: 0.72rem;
line-height: 1.4;
}
.scale-badge strong {
display: block;
color: var(--ink);
font-size: 0.76rem;
letter-spacing: 0.02em;
}
.view-controls {
display: flex;
align-items: center;
gap: 5px;
padding: 5px;
border-radius: 11px;
}
.view-controls button {
width: 31px;
height: 31px;
display: grid;
place-items: center;
border: 0;
border-radius: 7px;
background: transparent;
color: #344658;
cursor: pointer;
font-size: 1.1rem;
}
.view-controls button:hover {
background: #edf2f4;
}
.view-controls button.reset {
width: auto;
padding: 0 10px;
font-size: 0.72rem;
font-weight: 700;
}
.orbit-hint {
position: absolute;
z-index: 4;
top: 74px;
right: 22px;
color: rgba(61, 78, 92, 0.72);
font-size: 0.67rem;
pointer-events: none;
}
.object-tag {
position: absolute;
width: 196px;
padding: 9px 10px 8px;
transform: translate(-50%, calc(-100% - 14px));
border: 1px solid rgba(190, 203, 211, 0.92);
border-radius: 12px;
background: rgba(255, 255, 255, 0.94);
box-shadow: 0 10px 28px rgba(31, 51, 65, 0.12);
backdrop-filter: blur(8px);
}
.object-tag::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
height: 14px;
border-left: 1px solid rgba(92, 110, 122, 0.68);
}
.tag-head {
display: flex;
align-items: center;
gap: 7px;
}
.tag-swatch {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 3px;
background: var(--object-color);
}
.tag-head strong {
font-size: 0.74rem;
letter-spacing: 0.055em;
}
.rank-chip {
margin-left: auto;
padding: 3px 5px;
border-radius: 5px;
color: #586879;
background: #edf2f4;
font-size: 0.54rem;
font-weight: 800;
white-space: nowrap;
}
.tag-measures {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 4px;
margin-top: 7px;
}
.tag-measures span {
padding: 4px 5px;
border-radius: 6px;
background: #f1f5f6;
color: #2f4253;
font-size: 0.63rem;
font-weight: 750;
white-space: nowrap;
}
.tag-measures small {
color: #84919d;
font-size: 0.55rem;
font-weight: 700;
}
.tag-secondary {
display: flex;
justify-content: space-between;
gap: 8px;
margin-top: 6px;
color: #6a7886;
font-size: 0.6rem;
font-weight: 650;
}
.dimension-label {
position: absolute;
transform: translate(-50%, -50%);
padding: 3px 6px;
border: 1px solid rgba(124, 143, 154, 0.6);
border-radius: 5px;
background: rgba(255, 255, 255, 0.92);
color: #334858;
box-shadow: 0 3px 10px rgba(36, 57, 70, 0.08);
font-size: 0.59rem;
font-weight: 800;
white-space: nowrap;
}
.stage-bottom {
position: absolute;
z-index: 5;
left: 20px;
right: 20px;
bottom: 18px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.winner-strip {
display: flex;
flex-wrap: wrap;
gap: 7px;
max-width: 650px;
padding: 9px;
border: 1px solid rgba(193, 207, 214, 0.9);
border-radius: 12px;
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 8px 25px rgba(35, 57, 72, 0.08);
backdrop-filter: blur(10px);
}
.winner-strip span {
padding: 5px 8px;
border-radius: 7px;
background: #f1f5f6;
color: #566675;
font-size: 0.66rem;
font-weight: 700;
}
.winner-strip b {
margin-left: 4px;
color: var(--ink);
}
.loading {
position: absolute;
z-index: 9;
inset: 0;
display: grid;
place-items: center;
background: #eaf1f3;
color: #60717e;
font-size: 0.82rem;
transition: opacity 300ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.panel {
height: calc(100vh - 82px);
overflow-y: auto;
padding: 22px;
background: var(--panel);
border-left: 1px solid var(--line);
}
.panel-block + .panel-block {
margin-top: 22px;
padding-top: 21px;
border-top: 1px solid var(--line);
}
.eyebrow {
margin: 0 0 5px;
color: #85929d;
font-size: 0.63rem;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 1.12rem;
letter-spacing: -0.025em;
}
.panel-intro {
margin: 7px 0 15px;
color: var(--muted);
font-size: 0.77rem;
line-height: 1.5;
}
.segmented {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 4px;
padding: 4px;
border-radius: 11px;
background: #edf2f4;
}
.segmented button {
min-height: 36px;
padding: 7px 4px;
border: 0;
border-radius: 8px;
background: transparent;
color: #657483;
cursor: pointer;
font-size: 0.72rem;
font-weight: 750;
}
.segmented button.active {
color: var(--ink);
background: #ffffff;
box-shadow: 0 2px 8px rgba(33, 54, 68, 0.1);
}
.ranking-head {
display: flex;
align-items: center;
justify-content: space-between;
margin: 18px 0 10px;
color: #788692;
font-size: 0.64rem;
font-weight: 750;
}
.ranking-head strong {
color: var(--ink);
font-size: 0.72rem;
}
.rank-list {
display: grid;
gap: 9px;
}
.rank-row {
display: grid;
grid-template-columns: 25px minmax(0, 1fr);
align-items: center;
gap: 9px;
}
.rank-number {
width: 25px;
height: 25px;
display: grid;
place-items: center;
border-radius: 7px;
background: #eef3f5;
color: #60717f;
font-size: 0.68rem;
font-weight: 850;
}
.rank-row:first-child .rank-number {
color: #ffffff;
background: var(--ink);
}
.rank-title {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 10px;
margin-bottom: 5px;
}
.rank-title strong {
font-size: 0.7rem;
letter-spacing: 0.045em;
}
.rank-title span {
color: #526372;
font-size: 0.72rem;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
.rank-track {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: #edf1f3;
}
.rank-track i {
display: block;
height: 100%;
border-radius: inherit;
transition: width 420ms cubic-bezier(0.22, 1, 0.36, 1);
}
.insight {
padding: 13px;
border: 1px solid #dce6e9;
border-radius: 12px;
background: linear-gradient(135deg, #f4f9fa, #f9fbfc);
color: #425565;
font-size: 0.78rem;
line-height: 1.55;
}
.insight strong {
color: var(--ink);
}
.table-scroll {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.68rem;
font-variant-numeric: tabular-nums;
}
th,
td {
padding: 10px 5px;
border-bottom: 1px solid #e6ecef;
text-align: left;
vertical-align: middle;
}
th {
color: #82909b;
font-size: 0.58rem;
letter-spacing: 0.06em;
text-transform: uppercase;
}
td:first-child {
font-weight: 800;
letter-spacing: 0.04em;
}
td b {
color: #243646;
font-size: 0.72rem;
}
.rank-pill {
display: inline-grid;
place-items: center;
min-width: 22px;
height: 17px;
margin-left: 3px;
border-radius: 5px;
background: #edf2f4;
color: #798894;
font-size: 0.54rem;
font-weight: 850;
}
.rank-pill.first {
color: #ffffff;
background: #263b4c;
}
.table-note {
margin: 10px 0 0;
color: #84919b;
font-size: 0.63rem;
line-height: 1.45;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 980px) {
.layout {
grid-template-columns: 1fr;
}
.stage {
min-height: 610px;
}
.panel {
height: auto;
border-top: 1px solid var(--line);
border-left: 0;
}
.top-note {
display: none;
}
}
@media (max-width: 600px) {
.topbar {
padding: 14px 16px;
}
.brand p {
max-width: 245px;
font-size: 0.7rem;
}
.stage {
min-height: 540px;
}
.stage-top {
top: 12px;
left: 12px;
right: 12px;
}
.scale-badge {
padding: 7px 9px;
}
.orbit-hint {
display: none;
}
.stage-bottom {
left: 12px;
right: 12px;
bottom: 12px;
}
.winner-strip {
gap: 4px;
padding: 6px;
}
.winner-strip span {
padding: 4px 6px;
font-size: 0.57rem;
}
.object-tag {
width: 156px;
padding: 7px;
}
.tag-measures span {
padding: 3px;
font-size: 0.55rem;
}
.tag-secondary {
font-size: 0.52rem;
}
.dimension-label {
padding: 2px 4px;
font-size: 0.5rem;
}
.panel {
padding: 19px 16px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i>
</div>
<div>
<h1>Same scene. Different winners.</h1>
<p>A measured comparison of height, capacity, and mass.</p>
</div>
</div>
<div class="top-note">Three intentionally non-conforming rankings</div>
</header>
<main class="layout">
<section class="stage" aria-label="Interactive three-dimensional container comparison">
<div id="viewport"></div>
<div id="annotations" aria-hidden="true"></div>
<div class="stage-top">
<div class="scale-badge">
<strong>TRUE-SCALE MODEL</strong>
1 scene unit = 1 metre
</div>
<div class="view-controls" aria-label="Camera controls">
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button id="resetView" class="reset" type="button">Reset view</button>
</div>
</div>
<div class="orbit-hint">Drag to orbit · Scroll to zoom</div>
<div class="stage-bottom">
<div class="winner-strip" aria-label="Attribute winners">
<span>Tallest <b style="color: var(--orion)">ORION</b></span>
<span>Most capacious <b style="color: var(--atlas)">ATLAS</b></span>
<span>Heaviest <b style="color: var(--mesa)">MESA</b></span>
</div>
</div>
<div id="loading" class="loading">Preparing measured containers…</div>
</section>
<aside class="panel" aria-label="Comparison controls and rankings">
<section class="panel-block">
<p class="eyebrow">Compare & order</p>
<h2>Choose the attribute</h2>
<p class="panel-intro">
The containers rearrange from left to right in descending order.
Their geometry stays to scale.
</p>
<div class="segmented" role="group" aria-label="Order containers by attribute">
<button type="button" data-metric="height" class="active" aria-pressed="true">
Height
</button>
<button type="button" data-metric="volume" aria-pressed="false">
Capacity
</button>
<button type="button" data-metric="mass" aria-pressed="false">
Mass
</button>
</div>
<div class="ranking-head">
<strong id="rankingMetric">Height ranking</strong>
<span>Highest → lowest</span>
</div>
<div id="rankingList" class="rank-list"></div>
<div id="sortAnnounce" class="sr-only" aria-live="polite"></div>
</section>
<section class="panel-block">
<p class="eyebrow">Why rankings differ</p>
<div id="insight" class="insight"></div>
</section>
<section class="panel-block">
<p class="eyebrow">Measured values</p>
<h2>Attribute matrix</h2>
<p class="panel-intro">
Capacity is calculated as height × width × depth. Rank pills are
calculated independently within each column.
</p>
<div class="table-scroll">
<table>
<thead>
<tr>
<th>Container</th>
<th>Height</th>
<th>Capacity</th>
<th>Mass</th>
</tr>
</thead>
<tbody id="comparisonRows"></tbody>
</table>
</div>
<p class="table-note">
A larger-looking object is not automatically taller, heavier, or more
capacious. Every winner here is visible in the measurements.
</p>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const OBJECTS = [
{
id: "orion",
name: "ORION",
color: "#ef8354",
h: 5.4,
w: 2.1,
d: 2.1,
mass: 1.4
},
{
id: "atlas",
name: "ATLAS",
color: "#20a39e",
h: 2.6,
w: 4.6,
d: 4.2,
mass: 2.7
},
{
id: "mesa",
name: "MESA",
color: "#6c63a8",
h: 3.5,
w: 3.2,
d: 3.8,
mass: 3.3
}
];
const metricConfig = {
height: {
label: "Height",
short: "HEIGHT",
unit: "m",
insight:
"<strong>ORION ranks #1 by height</strong>, but it ranks #3 by capacity. Its narrow footprint keeps the total volume comparatively small."
},
volume: {
label: "Capacity",
short: "CAPACITY",
unit: "m³",
insight:
"<strong>ATLAS ranks #1 by capacity</strong>, but it ranks #3 by height. Its broad footprint creates more usable volume without making it taller."
},
mass: {
label: "Mass",
short: "MASS",
unit: "t",
insight:
"<strong>MESA ranks #1 by mass</strong>, yet it ranks #2 by both height and capacity. Weight is therefore a separate attribute, not a synonym for size."
}
};
const annotations = document.getElementById("annotations");
const viewport = document.getElementById("viewport");
const rankingList = document.getElementById("rankingList");
const rankingMetric = document.getElementById("rankingMetric");
const comparisonRows = document.getElementById("comparisonRows");
const insight = document.getElementById("insight");
const sortAnnounce = document.getElementById("sortAnnounce");
const loading = document.getElementById("loading");
const state = {
metric: "height",
yaw: 0.43,
pitch: 0.38,
zoom: 1,
baseDistance: 16,
dragging: false,
pointerX: 0,
pointerY: 0
};
const slots = [-4.8, 0, 4.8];
const cameraTarget = new THREE.Vector3(0, 2.1, 0);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xeaf1f3, 19, 48);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
renderer.domElement.setAttribute("role", "img");
renderer.domElement.setAttribute(
"aria-label",
"Three containers shown at true relative scale. ORION is tallest, ATLAS has the most capacity, and MESA is heaviest."
);
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x8297a3, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.0);
keyLight.position.set(-7, 12, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbfe7f0, 1.0);
fillLight.position.set(9, 6, -7);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0xe5edef,
roughness: 0.95,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(40, 40, 0xaebdc4, 0xc8d4d9);
grid.position.y = -0.018;
grid.material.transparent = true;
grid.material.opacity = 0.5;
scene.add(grid);
function volumeOf(object) {
return object.h * object.w * object.d;
}
function metricValue(object, metric) {
if (metric === "height") return object.h;
if (metric === "volume") return volumeOf(object);
return object.mass;
}
function formatMetric(value, metric) {
if (metric === "mass") return `${value.toFixed(1)} t`;
if (metric === "volume") return `${value.toFixed(1)} m³`;
return `${value.toFixed(1)} m`;
}
function getRankedObjects(metric) {
return [...OBJECTS].sort(
(a, b) => metricValue(b, metric) - metricValue(a, metric)
);
}
function createPlaqueTexture(object) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 180;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(255,255,255,0.96)";
context.fillRect(8, 8, 496, 164);
context.strokeStyle = object.color;
context.lineWidth = 10;
context.strokeRect(8, 8, 496, 164);
context.fillStyle = "#203342";
context.font = "800 60px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(object.name, 256, 90);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addSegment(points, a, b) {
points.push(a.x, a.y, a.z, b.x, b.y, b.z);
}
function createDimensionLines(object, group) {
const points = [];
const { h, w, d } = object;
const heightX = -w / 2 - 0.34;
addSegment(points, { x: heightX, y: 0.03, z: 0 }, { x: heightX, y: h + 0.03, z: 0 });
addSegment(points, { x: heightX - 0.1, y: 0.03, z: 0 }, { x: heightX + 0.1, y: 0.03, z: 0 });
addSegment(points, { x: heightX - 0.1, y: h + 0.03, z: 0 }, { x: heightX + 0.1, y: h + 0.03, z: 0 });
const widthZ = d / 2 + 0.34;
addSegment(points, { x: -w / 2, y: 0.025, z: widthZ }, { x: w / 2, y: 0.025, z: widthZ });
addSegment(points, { x: -w / 2, y: 0.025, z: widthZ - 0.09 }, { x: -w / 2, y: 0.025, z: widthZ + 0.09 });
addSegment(points, { x: w / 2, y: 0.025, z: widthZ - 0.09 }, { x: w / 2, y: 0.025, z: widthZ + 0.09 });
const depthX = w / 2 + 0.34;
addSegment(points, { x: depthX, y: 0.025, z: -d / 2 }, { x: depthX, y: 0.025, z: d / 2 });
addSegment(points, { x: depthX - 0.09, y: 0.025, z: -d / 2 }, { x: depthX + 0.09, y: 0.025, z: -d / 2 });
addSegment(points, { x: depthX - 0.09, y: 0.025, z: d / 2 }, { x: depthX + 0.09, y: 0.025, z: d / 2 });
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(points, 3));
const lines = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color: 0x526a79,
transparent: true,
opacity: 0.72
})
);
group.add(lines);
}
function createObject(object, initialX) {
const group = new THREE.Group();
group.position.set(initialX, 0, 0);
scene.add(group);
const bodyHeight = object.h - 0.12;
const bodyGeometry = new THREE.BoxGeometry(object.w, bodyHeight, object.d);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: object.color,
roughness: 0.66,
metalness: 0.08
});
const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
body.position.y = bodyHeight / 2;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(bodyGeometry),
new THREE.LineBasicMaterial({
color: 0x233746,
transparent: true,
opacity: 0.34
})
);
body.add(edges);
const lid = new THREE.Mesh(
new THREE.BoxGeometry(object.w, 0.12, object.d),
new THREE.MeshStandardMaterial({
color: new THREE.Color(object.color).multiplyScalar(0.76),
roughness: 0.6,
metalness: 0.1
})
);
lid.position.y = object.h - 0.06;
lid.castShadow = true;
group.add(lid);
const ribMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(object.color).multiplyScalar(0.72),
roughness: 0.74,
metalness: 0.06
});
for (const ratio of [-0.3, 0.3]) {
const rib = new THREE.Mesh(
new THREE.BoxGeometry(0.055, bodyHeight * 0.78, 0.025),
ribMaterial
);
rib.position.set(object.w * ratio, bodyHeight * 0.5, object.d / 2 + 0.015);
rib.castShadow = true;
group.add(rib);
}
for (const ratio of [-0.3, 0, 0.3]) {
const sideRib = new THREE.Mesh(
new THREE.BoxGeometry(0.025, bodyHeight * 0.78, 0.055),
ribMaterial
);
sideRib.position.set(object.w / 2 + 0.015, bodyHeight * 0.5, object.d * ratio);
sideRib.castShadow = true;
group.add(sideRib);
}
const seamGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.18, object.d / 2 + 0.035),
new THREE.Vector3(0, object.h - 0.18, object.d / 2 + 0.035)
]);
const seam = new THREE.Line(
seamGeometry,
new THREE.LineBasicMaterial({ color: 0x263d4c, transparent: true, opacity: 0.62 })
);
group.add(seam);
const handle = new THREE.Mesh(
new THREE.BoxGeometry(0.06, 0.28, 0.07),
new THREE.MeshStandardMaterial({ color: 0x273b49, roughness: 0.45, metalness: 0.28 })
);
handle.position.set(0.12, object.h * 0.47, object.d / 2 + 0.055);
handle.castShadow = true;
group.add(handle);
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(Math.min(1.38, object.w * 0.57), 0.43),
new THREE.MeshBasicMaterial({
map: createPlaqueTexture(object),
transparent: true,
toneMapped: false
})
);
plaque.position.set(0, Math.min(object.h * 0.56, 1.7), object.d / 2 + 0.04);
group.add(plaque);
createDimensionLines(object, group);
const tag = document.createElement("div");
tag.className = "object-tag";
tag.style.setProperty("--object-color", object.color);
tag.innerHTML = `
<div class="tag-head">
<span class="tag-swatch"></span>
<strong>${object.name}</strong>
<span class="rank-chip">#1 ${metricConfig[state.metric].short}</span>
</div>
<div class="tag-measures">
<span><small>H</small> ${object.h.toFixed(1)} m</span>
<span><small>W</small> ${object.w.toFixed(1)} m</span>
<span><small>D</small> ${object.d.toFixed(1)} m</span>
</div>
<div class="tag-secondary">
<span>${volumeOf(object).toFixed(1)} m³</span>
<span>${object.mass.toFixed(1)} t</span>
</div>
`;
annotations.appendChild(tag);
const dimensions = {};
for (const [key, text, anchor] of [
["h", `H ${object.h.toFixed(1)} m`, new THREE.Vector3(-object.w / 2 - 0.34, object.h * 0.55, 0)],
["w", `W ${object.w.toFixed(1)} m`, new THREE.Vector3(0, 0.07, object.d / 2 + 0.34)],
["d", `D ${object.d.toFixed(1)} m`, new THREE.Vector3(object.w / 2 + 0.34, 0.07, 0)]
]) {
const label = document.createElement("span");
label.className = "dimension-label";
label.textContent = text;
annotations.appendChild(label);
dimensions[key] = { element: label, anchor };
}
return {
...object,
group,
tag,
dimensions,
targetX: initialX
};
}
const initialOrder = getRankedObjects("height");
const models = initialOrder.map((object, index) => createObject(object, slots[index]));
function updateRankingUI() {
const ranked = getRankedObjects(state.metric);
const config = metricConfig[state.metric];
const maximum = Math.max(...ranked.map((object) => metricValue(object, state.metric)));
rankingMetric.textContent = `${config.label} ranking`;
rankingList.innerHTML = ranked
.map((object, index) => {
const value = metricValue(object, state.metric);
const width = (value / maximum) * 100;
return `
<div class="rank-row">
<div class="rank-number">${index + 1}</div>
<div>
<div class="rank-title">
<strong>${object.name}</strong>
<span>${formatMetric(value, state.metric)}</span>
</div>
<div class="rank-track">
<i style="width:${width}%;background:${object.color}"></i>
</div>
</div>
</div>
`;
})
.join("");
insight.innerHTML = config.insight;
const ranks = {};
ranked.forEach((object, index) => {
ranks[object.id] = index + 1;
});
models.forEach((model) => {
model.tag.querySelector(".rank-chip").textContent =
`#${ranks[model.id]} ${config.short}`;
});
sortAnnounce.textContent =
`Containers reordered by ${config.label.toLowerCase()}: ` +
ranked.map((object) => object.name).join(", ");
}
function buildComparisonTable() {
const rankSets = {};
for (const metric of Object.keys(metricConfig)) {
const ranks = {};
getRankedObjects(metric).forEach((object, index) => {
ranks[object.id] = index + 1;
});
rankSets[metric] = ranks;
}
comparisonRows.innerHTML = OBJECTS.map((object) => {
const heightRank = rankSets.height[object.id];
const volumeRank = rankSets.volume[object.id];
const massRank = rankSets.mass[object.id];
return `
<tr>
<td style="color:${object.color}">${object.name}</td>
<td>
<b>${object.h.toFixed(1)}</b> m
<span class="rank-pill ${heightRank === 1 ? "first" : ""}">#${heightRank}</span>
</td>
<td>
<b>${volumeOf(object).toFixed(1)}</b> m³
<span class="rank-pill ${volumeRank === 1 ? "first" : ""}">#${volumeRank}</span>
</td>
<td>
<b>${object.mass.toFixed(1)}</b> t
<span class="rank-pill ${massRank === 1 ? "first" : ""}">#${massRank}</span>
</td>
</tr>
`;
}).join("");
}
function setMetric(metric, immediate = false) {
state.metric = metric;
document.querySelectorAll("[data-metric]").forEach((button) => {
const active = button.dataset.metric === metric;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
const ranked = getRankedObjects(metric);
ranked.forEach((object, index) => {
const model = models.find((item) => item.id === object.id);
model.targetX = slots[index];
if (immediate) model.group.position.x = model.targetX;
});
updateRankingUI();
}
document.querySelectorAll("[data-metric]").forEach((button) => {
button.addEventListener("click", () => setMetric(button.dataset.metric));
});
buildComparisonTable();
setMetric("height", true);
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
const verticalFov = THREE.MathUtils.degToRad(camera.fov);
const horizontalFov = 2 * Math.atan(Math.tan(verticalFov / 2) * camera.aspect);
state.baseDistance = Math.max(15.8, 8.2 / Math.tan(horizontalFov / 2));
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
function updateCamera() {
const distance = state.baseDistance * state.zoom;
const horizontalDistance = Math.cos(state.pitch) * distance;
camera.position.set(
cameraTarget.x + Math.sin(state.yaw) * horizontalDistance,
cameraTarget.y + Math.sin(state.pitch) * distance,
cameraTarget.z + Math.cos(state.yaw) * horizontalDistance
);
camera.lookAt(cameraTarget);
}
function resetView() {
state.yaw = 0.43;
state.pitch = 0.38;
state.zoom = 1;
}
document.getElementById("resetView").addEventListener("click", resetView);
document.getElementById("zoomIn").addEventListener("click", () => {
state.zoom = THREE.MathUtils.clamp(state.zoom * 0.88, 0.62, 1.55);
});
document.getElementById("zoomOut").addEventListener("click", () => {
state.zoom = THREE.MathUtils.clamp(state.zoom * 1.12, 0.62, 1.55);
});
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
state.dragging = true;
state.pointerX = event.clientX;
state.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!state.dragging) return;
const deltaX = event.clientX - state.pointerX;
const deltaY = event.clientY - state.pointerY;
state.pointerX = event.clientX;
state.pointerY = event.clientY;
state.yaw -= deltaX * 0.006;
state.pitch = THREE.MathUtils.clamp(
state.pitch + deltaY * 0.005,
0.13,
0.82
);
});
function endDrag(event) {
state.dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
state.zoom = THREE.MathUtils.clamp(
state.zoom * Math.exp(event.deltaY * 0.001),
0.62,
1.55
);
},
{ passive: false }
);
const projected = new THREE.Vector3();
function placeElement(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const width = viewport.clientWidth;
const height = viewport.clientHeight;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.visibility =
projected.z > -1 && projected.z < 1 ? "visible" : "hidden";
}
function updateAnnotations() {
models.forEach((model) => {
const tagAnchor = new THREE.Vector3(0, model.h + 0.18, 0);
model.group.localToWorld(tagAnchor);
placeElement(model.tag, tagAnchor);
for (const dimension of Object.values(model.dimensions)) {
const world = model.group.localToWorld(dimension.anchor.clone());
placeElement(dimension.element, world);
}
});
}
const clock = new THREE.Clock();
let firstFrame = true;
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-7 * delta);
models.forEach((model) => {
model.group.position.x = THREE.MathUtils.lerp(
model.group.position.x,
model.targetX,
smoothing
);
});
updateCamera();
renderer.render(scene, camera);
updateAnnotations();
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
}
});
</script>
</body>
</html>
```