Prompt specification
Build or customize the Three.js 3D scene "Traveling Material Sample Box" 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: Traveling Material Sample Box
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/traveling-material-sample-box-x3293
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a portable collection of materials with provenance tags. Arrange three material samples in a portable box with neutral origin tags and route slots. Show provenance as metadata rather than inferring culture from appearance. Low-poly.
Working Three.js Starter (traveling-material-sample-box-x3293):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Portable Materials — Provenance Study</title>
<style>
:root {
--ink: #263735;
--muted: #68736f;
--paper: #f4efe4;
--paper-solid: #eee7d9;
--line: rgba(38, 55, 53, 0.18);
--green: #304541;
--ochre: #c4953e;
--sage: #66817a;
--clay: #b66f58;
--shadow: 0 18px 50px rgba(30, 42, 39, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7e3d9;
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%;
cursor: grab;
outline: none;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.brand {
position: fixed;
top: 26px;
left: 28px;
z-index: 5;
max-width: min(440px, calc(100vw - 390px));
pointer-events: none;
}
.eyebrow,
.record-kicker,
.controls-label {
font-family:
ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--green);
}
.eyebrow::before {
width: 26px;
height: 3px;
content: "";
background: var(--ochre);
}
.brand h1 {
margin: 0;
font-size: clamp(25px, 3vw, 42px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 0.98;
}
.brand p {
max-width: 410px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.policy-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid rgba(48, 69, 65, 0.18);
border-radius: 999px;
background: rgba(244, 239, 228, 0.64);
color: var(--green);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.policy-badge::before {
width: 7px;
height: 7px;
content: "";
border-radius: 50%;
background: var(--ochre);
box-shadow: 0 0 0 4px rgba(196, 149, 62, 0.14);
}
.controls {
position: fixed;
top: 24px;
right: 26px;
z-index: 10;
display: flex;
align-items: center;
gap: 7px;
padding: 7px;
border: 1px solid rgba(38, 55, 53, 0.13);
border-radius: 13px;
background: rgba(244, 239, 228, 0.83);
box-shadow: 0 10px 30px rgba(30, 42, 39, 0.1);
backdrop-filter: blur(14px);
}
.controls button {
min-width: 36px;
height: 35px;
padding: 0 11px;
border: 1px solid transparent;
border-radius: 8px;
background: transparent;
color: var(--ink);
cursor: pointer;
font-size: 12px;
font-weight: 650;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.controls button:hover,
.controls button:focus-visible {
border-color: var(--line);
background: rgba(48, 69, 65, 0.08);
outline: none;
}
.controls button:active {
transform: translateY(1px);
}
.controls .icon {
font-size: 19px;
line-height: 1;
}
.control-separator {
width: 1px;
height: 23px;
background: var(--line);
}
.record {
position: fixed;
left: 26px;
bottom: 25px;
z-index: 8;
width: min(410px, calc(100vw - 52px));
max-height: calc(100vh - 170px);
overflow: auto;
padding: 19px;
border: 1px solid rgba(38, 55, 53, 0.14);
border-radius: 16px;
background: rgba(244, 239, 228, 0.91);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.record-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.record-kicker {
color: var(--muted);
}
.origin-chip {
flex: 0 0 auto;
padding: 5px 8px;
border: 1px solid rgba(182, 111, 88, 0.28);
border-radius: 999px;
background: rgba(182, 111, 88, 0.09);
color: #87513f;
font-family:
ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.record h2 {
margin: 12px 0 3px;
font-size: 25px;
font-weight: 650;
letter-spacing: -0.03em;
}
.record-subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
}
.sample-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin: 16px 0;
}
.sample-tab {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 11px;
font-weight: 700;
transition:
background 150ms ease,
border-color 150ms ease,
color 150ms ease;
}
.sample-tab::before {
width: 8px;
height: 8px;
flex: 0 0 auto;
content: "";
border-radius: 2px;
background: var(--tab-color);
}
.sample-tab:hover,
.sample-tab:focus-visible {
outline: none;
border-color: rgba(38, 55, 53, 0.4);
}
.sample-tab.active {
border-color: rgba(38, 55, 53, 0.28);
background: rgba(48, 69, 65, 0.08);
color: var(--ink);
}
.metadata-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 13px 18px;
margin: 0;
padding: 15px 0;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.metadata-grid div {
min-width: 0;
}
.metadata-grid dt {
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metadata-grid dd {
margin: 0;
font-size: 12px;
font-weight: 600;
line-height: 1.35;
}
.record-note {
margin: 14px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.hint {
position: fixed;
right: 27px;
bottom: 26px;
z-index: 6;
padding: 9px 12px;
border: 1px solid rgba(38, 55, 53, 0.12);
border-radius: 999px;
background: rgba(244, 239, 228, 0.72);
color: var(--muted);
font-family:
ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
backdrop-filter: blur(12px);
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #e7e3d9;
color: var(--green);
font-family:
ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 17px;
left: 17px;
max-width: calc(100vw - 155px);
}
.brand h1 {
font-size: 25px;
}
.brand p {
display: none;
}
.policy-badge {
margin-top: 9px;
padding: 6px 8px;
font-size: 8px;
}
.controls {
top: 14px;
right: 13px;
flex-wrap: wrap;
justify-content: flex-end;
max-width: 130px;
}
.controls button {
min-width: 32px;
height: 32px;
padding: 0 8px;
font-size: 10px;
}
.controls .wide {
display: none;
}
.control-separator {
display: none;
}
.record {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
max-height: 48vh;
padding: 15px;
}
.record h2 {
margin-top: 8px;
font-size: 21px;
}
.metadata-grid {
gap: 10px 13px;
padding: 12px 0;
}
.hint {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="loading">Loading portable collection…</div>
<header class="brand">
<div class="eyebrow">Provenance study / Case 03</div>
<h1>Portable<br />Materials</h1>
<p>
Three material samples in a portable field case. Material class is
illustrative; origin is shown only as recorded metadata.
</p>
<div class="policy-badge">No cultural attribution</div>
</header>
<nav class="controls" aria-label="Scene controls">
<button id="orbit-left" class="icon" aria-label="Rotate left">↶</button>
<button id="orbit-right" class="icon" aria-label="Rotate right">↷</button>
<div class="control-separator" aria-hidden="true"></div>
<button id="auto-orbit" aria-pressed="false">Auto orbit</button>
<button id="toggle-labels" aria-pressed="true" class="wide">Tags</button>
<button id="reset-view">Reset</button>
</nav>
<aside class="record" aria-label="Selected provenance record">
<div class="record-top">
<span class="record-kicker">Selected record</span>
<span class="origin-chip">Origin unrecorded</span>
</div>
<h2 id="record-title">Sample A</h2>
<p id="record-material" class="record-subtitle">Mineral aggregate</p>
<div class="sample-tabs" aria-label="Select a sample">
<button
class="sample-tab active"
data-sample="A"
style="--tab-color: var(--ochre)"
aria-pressed="true"
>
A
</button>
<button
class="sample-tab"
data-sample="B"
style="--tab-color: var(--sage)"
aria-pressed="false"
>
B
</button>
<button
class="sample-tab"
data-sample="C"
style="--tab-color: var(--clay)"
aria-pressed="false"
>
C
</button>
</div>
<dl class="metadata-grid">
<div>
<dt>Record ID</dt>
<dd id="record-id"></dd>
</div>
<div>
<dt>Recorded origin</dt>
<dd id="record-origin"></dd>
</div>
<div>
<dt>Source</dt>
<dd id="record-source"></dd>
</div>
<div>
<dt>Collection date</dt>
<dd id="record-date"></dd>
</div>
<div>
<dt>Custodian</dt>
<dd id="record-custodian"></dd>
</div>
<div>
<dt>Route slot</dt>
<dd id="record-route"></dd>
</div>
</dl>
<p id="record-note" class="record-note"></p>
</aside>
<div class="hint">
DRAG TO ORBIT · SCROLL TO ZOOM · CLICK A SAMPLE
</div>
<noscript>This experience requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* -------------------------------------------------------------------------
DATA
Material descriptions describe only the modeled visual class.
Origin and source are independent provenance fields.
------------------------------------------------------------------------- */
const samples = {
A: {
title: "Sample A",
material: "Mineral aggregate — illustrative geometry",
id: "PMC-03-A",
origin: "Not recorded",
source: "Accession register 03 / drawer 01",
date: "Not recorded",
custodian: "Portable reference collection",
route: "Route A",
accent: 0xc4953e,
note:
"The low-poly form and neutral color indicate only the modeled material class. They do not establish place, age, community, or cultural affiliation."
},
B: {
title: "Sample B",
material: "Woven fibre swatch — illustrative geometry",
id: "PMC-03-B",
origin: "Not recorded",
source: "Accession register 03 / drawer 02",
date: "Not recorded",
custodian: "Portable reference collection",
route: "Route B",
accent: 0x66817a,
note:
"The folded and striped surface is a generic representation of a fibre swatch. No cultural or geographic origin is inferred from the pattern."
},
C: {
title: "Sample C",
material: "Ceramic sherd — illustrative geometry",
id: "PMC-03-C",
origin: "Not recorded",
source: "Accession register 03 / drawer 03",
date: "Not recorded",
custodian: "Portable reference collection",
route: "Route C",
accent: 0xb66f58,
note:
"The irregular ceramic form is deliberately undecorated. Its provenance remains limited to the supplied collection record."
}
};
/* -------------------------------------------------------------------------
RENDERER AND SCENE
------------------------------------------------------------------------- */
const sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7e3d9);
scene.fog = new THREE.Fog(0xe7e3d9, 16, 31);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly portable collection with three provenance-tagged samples"
);
renderer.domElement.setAttribute("tabindex", "0");
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfffaf0, 0x7c8880, 2.35);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4dd, 3.4);
keyLight.position.set(-5.5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00045;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc8d8d4, 1.15);
fillLight.position.set(7, 4, -6);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffd69b, 0.85);
rimLight.position.set(-3, 5, -7);
scene.add(rimLight);
/* -------------------------------------------------------------------------
MATERIALS AND HELPERS
------------------------------------------------------------------------- */
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
const materials = {
case: standard(0x304541, { roughness: 0.7 }),
caseEdge: standard(0x3b514c, { roughness: 0.62 }),
foam: standard(0x303b39, { roughness: 1 }),
liner: standard(0x87928b, { roughness: 0.95 }),
tray: standard(0xd9d0bd, { roughness: 1 }),
slot: standard(0x1f2927, { roughness: 1 }),
metal: standard(0x69736e, {
roughness: 0.42,
metalness: 0.55
}),
stone: standard(0xaaa497, { roughness: 1 }),
stoneDark: standard(0x8f8c82, { roughness: 1 }),
clay: standard(0xb66f58, { roughness: 0.94 }),
plinth: standard(0xd4d0c5, { roughness: 1 })
};
function addBox(parent, width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createLabelTexture(lines, accentHex = "#c4953e") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 512;
const context = canvas.getContext("2d");
context.fillStyle = "#f4efe4";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "#2b3c39";
context.lineWidth = 7;
context.strokeRect(4, 4, canvas.width - 8, canvas.height - 8);
context.fillStyle = accentHex;
context.fillRect(7, 7, 19, canvas.height - 14);
let y = 93;
for (const line of lines) {
const size = line.size ?? 30;
const weight = line.weight ?? 600;
context.font = `${weight} ${size}px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`;
context.fillStyle = line.color ?? "#263735";
context.textBaseline = "top";
context.fillText(line.text, 58, y, 900);
y += size * 1.32 + (line.gap ?? 10);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
texture.minFilter = THREE.LinearMipmapLinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function createLabelPlane(
width,
height,
lines,
accentHex,
parent,
x,
y,
z,
horizontal = false
) {
const texture = createLabelTexture(lines, accentHex);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
})
);
mesh.position.set(x, y, z);
if (horizontal) mesh.rotation.x = -Math.PI / 2;
mesh.renderOrder = 2;
parent.add(mesh);
return mesh;
}
/* -------------------------------------------------------------------------
STUDIO BASE AND PORTABLE CASE
------------------------------------------------------------------------- */
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
standard(0xe1ddd3, { roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.17;
ground.receiveShadow = true;
scene.add(ground);
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(5.15, 5.45, 0.18, 12),
materials.plinth
);
plinth.position.y = -0.08;
plinth.receiveShadow = true;
plinth.castShadow = true;
scene.add(plinth);
const caseRoot = new THREE.Group();
scene.add(caseRoot);
const worldLabels = new THREE.Group();
const lidLabels = new THREE.Group();
scene.add(worldLabels);
// Lower shell and insert.
addBox(caseRoot, 7.6, 0.38, 4.8, materials.case, 0, 0.28, 0);
addBox(caseRoot, 7.08, 0.16, 4.28, materials.liner, 0, 0.53, 0);
addBox(caseRoot, 6.9, 0.18, 4.08, materials.foam, 0, 0.68, 0);
// Perimeter walls. The front is lower so the contents remain readable.
addBox(caseRoot, 7.6, 0.55, 0.18, materials.caseEdge, 0, 0.72, 2.38);
addBox(caseRoot, 7.6, 0.88, 0.18, materials.caseEdge, 0, 0.79, -2.38);
addBox(caseRoot, 0.18, 0.68, 4.6, materials.caseEdge, -3.71, 0.76, 0);
addBox(caseRoot, 0.18, 0.68, 4.6, materials.caseEdge, 3.71, 0.76, 0);
// Foam separators.
addBox(caseRoot, 0.08, 0.16, 2.9, materials.foam, -1.14, 0.85, -0.12);
addBox(caseRoot, 0.08, 0.16, 2.9, materials.foam, 1.14, 0.85, -0.12);
// Hinges.
for (const x of [-2.55, 2.55]) {
const hinge = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.72, 10),
materials.metal
);
hinge.rotation.z = Math.PI / 2;
hinge.position.set(x, 1.12, -2.37);
hinge.castShadow = true;
caseRoot.add(hinge);
}
// Front latches and handle.
for (const x of [-2.72, 2.72]) {
addBox(caseRoot, 0.48, 0.34, 0.18, materials.metal, x, 0.84, 2.49);
addBox(caseRoot, 0.31, 0.11, 0.12, materials.case, x, 0.98, 2.55);
}
addBox(caseRoot, 0.12, 0.12, 0.18, materials.metal, -0.58, 0.77, 2.54);
addBox(caseRoot, 0.12, 0.12, 0.18, materials.metal, 0.58, 0.77, 2.54);
addBox(caseRoot, 1.28, 0.12, 0.18, materials.metal, 0, 0.77, 2.54);
// Open lid, pivoted around the rear edge.
const lidPivot = new THREE.Group();
lidPivot.position.set(0, 1.17, -2.38);
lidPivot.rotation.x = -1.04;
caseRoot.add(lidPivot);
lidPivot.add(lidLabels);
addBox(lidPivot, 7.6, 0.24, 4.55, materials.case, 0, 0, 2.275);
addBox(lidPivot, 7.05, 0.08, 4.0, materials.liner, 0, 0.145, 2.275);
// Lid rim.
addBox(lidPivot, 0.2, 0.32, 4.12, materials.caseEdge, -3.48, 0.19, 2.275);
addBox(lidPivot, 0.2, 0.32, 4.12, materials.caseEdge, 3.48, 0.19, 2.275);
addBox(lidPivot, 6.96, 0.32, 0.2, materials.caseEdge, 0, 0.19, 0.32);
addBox(lidPivot, 6.96, 0.32, 0.2, materials.caseEdge, 0, 0.19, 4.23);
createLabelPlane(
5.25,
1.02,
[
{
text: "PROVENANCE INDEX",
size: 48,
weight: 750
},
{
text: "ORIGIN DATA IS READ FROM RECORDS — NOT APPEARANCE",
size: 23,
weight: 600,
color: "#4f5f5a"
},
{
text: "CASE 03 / ALL RECORDED ORIGINS: NOT RECORDED",
size: 20,
weight: 600,
color: "#68736f"
}
],
"#c4953e",
lidLabels,
0,
0.238,
1.1,
true
);
/* -------------------------------------------------------------------------
SAMPLE GROUPS AND ROUTE SLOTS
------------------------------------------------------------------------- */
const sampleMeshes = [];
const selectionOutlines = {};
const sampleX = {
A: -2.28,
B: 0,
C: 2.28
};
function registerSample(group, id) {
group.traverse((object) => {
if (object.isMesh) {
object.userData.sampleId = id;
sampleMeshes.push(object);
}
});
}
function createSelectionOutline(parent, id, accent) {
const geometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(1.95, 0.075, 1.78)
);
const material = new THREE.LineBasicMaterial({
color: accent,
transparent: true,
opacity: 0.18
});
const outline = new THREE.LineSegments(geometry, material);
outline.position.y = 0.045;
outline.scale.setScalar(1.02);
parent.add(outline);
selectionOutlines[id] = outline;
}
// Sample A: faceted mineral aggregate.
const groupA = new THREE.Group();
groupA.position.set(sampleX.A, 0.78, -0.05);
caseRoot.add(groupA);
addBox(groupA, 1.82, 0.07, 1.68, materials.tray, 0, 0.045, 0);
const stone = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.68, 1),
materials.stone
);
stone.scale.set(1, 0.76, 0.88);
stone.rotation.set(0.22, 0.36, -0.18);
stone.position.set(-0.08, 0.51, 0.03);
stone.castShadow = true;
stone.receiveShadow = true;
groupA.add(stone);
const stoneChip = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.27, 0),
materials.stoneDark
);
stoneChip.scale.set(1.2, 0.75, 0.9);
stoneChip.position.set(0.48, 0.3, 0.2);
stoneChip.rotation.set(0.4, 0.7, 0.2);
stoneChip.castShadow = true;
groupA.add(stoneChip);
createSelectionOutline(groupA, "A", samples.A.accent);
registerSample(groupA, "A");
// Sample B: generic folded woven fibre swatch.
const groupB = new THREE.Group();
groupB.position.set(sampleX.B, 0.78, -0.03);
caseRoot.add(groupB);
addBox(groupB, 1.82, 0.07, 1.68, materials.tray, 0, 0.045, 0);
const fibreGeometry = new THREE.BufferGeometry();
const fibrePositions = [];
const fibreColors = [];
const nx = 8;
const nz = 6;
const width = 1.48;
const depth = 1.08;
const colorA = new THREE.Color(0x6f8982);
const colorB = new THREE.Color(0xb9b09e);
for (let iz = 0; iz <= nz; iz++) {
for (let ix = 0; ix <= nx; ix++) {
const x = (ix / nx - 0.5) * width;
const z = (iz / nz - 0.5) * depth;
const fold =
Math.abs(Math.sin((ix / nx) * Math.PI * 2.2)) * 0.11 +
Math.cos((iz / nz) * Math.PI * 2) * 0.035;
const y = 0.15 + fold + (ix % 2) * 0.018;
fibrePositions.push(x, y, z);
const color = Math.floor(ix / 2) % 2 === 0 ? colorA : colorB;
fibreColors.push(color.r, color.g, color.b);
}
}
const indices = [];
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const a = iz * (nx + 1) + ix;
const b = a + 1;
const c = a + nx + 1;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
fibreGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(fibrePositions, 3)
);
fibreGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(fibreColors, 3)
);
fibreGeometry.setIndex(indices);
fibreGeometry.computeVertexNormals();
const fibre = new THREE.Mesh(
fibreGeometry,
standard(0xffffff, {
vertexColors: true,
side: THREE.DoubleSide,
roughness: 1
})
);
fibre.castShadow = true;
fibre.receiveShadow = true;
groupB.add(fibre);
createSelectionOutline(groupB, "B", samples.B.accent);
registerSample(groupB, "B");
// Sample C: undecorated irregular ceramic sherd.
const groupC = new THREE.Group();
groupC.position.set(sampleX.C, 0.78, -0.05);
caseRoot.add(groupC);
addBox(groupC, 1.82, 0.07, 1.68, materials.tray, 0, 0.045, 0);
const shardShape = new THREE.Shape();
shardShape.moveTo(-0.67, -0.33);
shardShape.lineTo(-0.53, 0.34);
shardShape.lineTo(-0.12, 0.54);
shardShape.lineTo(0.54, 0.25);
shardShape.lineTo(0.69, -0.15);
shardShape.lineTo(0.35, -0.48);
shardShape.lineTo(-0.23, -0.5);
shardShape.closePath();
const shardGeometry = new THREE.ExtrudeGeometry(shardShape, {
depth: 0.18,
bevelEnabled: false,
steps: 1,
curveSegments: 1
});
shardGeometry.rotateX(-Math.PI / 2);
shardGeometry.computeVertexNormals();
const shard = new THREE.Mesh(shardGeometry, materials.clay);
shard.position.y = 0.11;
shard.rotation.y = -0.13;
shard.castShadow = true;
shard.receiveShadow = true;
groupC.add(shard);
createSelectionOutline(groupC, "C", samples.C.accent);
registerSample(groupC, "C");
/* -------------------------------------------------------------------------
NEUTRAL ORIGIN TAGS AND LID ROUTE CARDS
------------------------------------------------------------------------- */
const accents = {
A: "#c4953e",
B: "#66817a",
C: "#b66f58"
};
for (const id of ["A", "B", "C"]) {
const x = sampleX[id];
// Route channel from the sample area to its front slot.
addBox(
caseRoot,
0.11,
0.035,
1.65,
materials.slot,
x,
0.795,
0.72
);
// Physical slot at the front of each sample compartment.
addBox(
caseRoot,
1.52,
0.05,
0.22,
materials.slot,
x,
0.85,
1.65
);
const tagGroup = new THREE.Group();
tagGroup.position.set(x, 1.18, 1.66);
tagGroup.rotation.x = -0.08;
worldLabels.add(tagGroup);
addBox(
tagGroup,
1.46,
0.68,
0.045,
materials.case,
0,
0,
-0.025
);
createLabelPlane(
1.37,
0.61,
[
{
text: "ORIGIN: NOT RECORDED",
size: 38,
weight: 750
},
{
text: `SAMPLE ${id} / ROUTE ${id}`,
size: 26,
weight: 650,
color: "#53625d"
},
{
text: "NEUTRAL FIELD TAG",
size: 20,
weight: 600,
color: "#78817c"
}
],
accents[id],
tagGroup,
0,
0,
0.006
);
}
// Small front identification plate.
const frontPlate = new THREE.Group();
frontPlate.position.set(0, 0.72, 2.49);
worldLabels.add(frontPlate);
addBox(
frontPlate,
2.9,
0.34,
0.035,
materials.case,
0,
0,
-0.015
);
createLabelPlane(
2.78,
0.28,
[
{
text: "PORTABLE MATERIALS / CASE 03",
size: 28,
weight: 700
}
],
"#c4953e",
frontPlate,
0,
0,
0.008
);
// Three route slots and cards mounted in the open lid.
for (const id of ["A", "B", "C"]) {
const x = sampleX[id];
addBox(
lidPivot,
1.94,
0.055,
0.27,
materials.slot,
x,
0.215,
2.72
);
addBox(
lidPivot,
0.18,
0.055,
0.3,
standard(samples[id].accent),
x,
0.255,
2.94
);
createLabelPlane(
1.78,
0.74,
[
{
text: `ROUTE ${id}`,
size: 48,
weight: 750
},
{
text: `SAMPLE ${id} / ORIGIN: NOT RECORDED`,
size: 24,
weight: 650,
color: "#53625d"
},
{
text: "SOURCE: ACCESSION REGISTER 03",
size: 19,
weight: 600,
color: "#78817c"
}
],
accents[id],
lidLabels,
x,
0.258,
2.72,
true
);
}
/* -------------------------------------------------------------------------
METADATA PANEL
------------------------------------------------------------------------- */
const recordTitle = document.getElementById("record-title");
const recordMaterial = document.getElementById("record-material");
const recordId = document.getElementById("record-id");
const recordOrigin = document.getElementById("record-origin");
const recordSource = document.getElementById("record-source");
const recordDate = document.getElementById("record-date");
const recordCustodian = document.getElementById("record-custodian");
const recordRoute = document.getElementById("record-route");
const recordNote = document.getElementById("record-note");
const tabs = [...document.querySelectorAll(".sample-tab")];
let selectedSample = "A";
function selectSample(id) {
selectedSample = id;
const data = samples[id];
recordTitle.textContent = data.title;
recordMaterial.textContent = data.material;
recordId.textContent = data.id;
recordOrigin.textContent = data.origin;
recordSource.textContent = data.source;
recordDate.textContent = data.date;
recordCustodian.textContent = data.custodian;
recordRoute.textContent = data.route;
recordNote.textContent = data.note;
for (const tab of tabs) {
const active = tab.dataset.sample === id;
tab.classList.toggle("active", active);
tab.setAttribute("aria-pressed", String(active));
}
for (const sampleId of Object.keys(selectionOutlines)) {
selectionOutlines[sampleId].material.opacity =
sampleId === id ? 0.95 : 0.16;
}
}
for (const tab of tabs) {
tab.addEventListener("click", () => selectSample(tab.dataset.sample));
}
selectSample("A");
/* -------------------------------------------------------------------------
CUSTOM CAMERA CONTROLS
------------------------------------------------------------------------- */
const view = {
azimuth: 0.48,
elevation: 0.64,
radius: window.innerWidth < 760 ? 15.2 : 10.7,
targetAzimuth: 0.48,
targetElevation: 0.64,
targetRadius: window.innerWidth < 760 ? 15.2 : 10.7,
target: new THREE.Vector3(0, 1.32, 0),
dragging: false,
pointerId: null,
lastX: 0,
lastY: 0,
downX: 0,
downY: 0,
moved: false,
autoRotate: false
};
function defaultRadius() {
return window.innerWidth < 760 ? 15.2 : 10.7;
}
function updateCamera(delta = 1) {
const smoothing = 1 - Math.exp(-delta * 8);
view.azimuth += (view.targetAzimuth - view.azimuth) * smoothing;
view.elevation += (view.targetElevation - view.elevation) * smoothing;
view.radius += (view.targetRadius - view.radius) * smoothing;
const horizontalRadius =
view.radius * Math.sin(view.elevation);
camera.position.set(
view.target.x +
horizontalRadius * Math.sin(view.azimuth),
view.target.y + view.radius * Math.cos(view.elevation),
view.target.z +
horizontalRadius * Math.cos(view.azimuth)
);
camera.lookAt(view.target);
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pickSample(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(sampleMeshes, false);
if (hits.length) {
selectSample(hits[0].object.userData.sampleId);
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
view.dragging = true;
view.pointerId = event.pointerId;
view.lastX = event.clientX;
view.lastY = event.clientY;
view.downX = event.clientX;
view.downY = event.clientY;
view.moved = false;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!view.dragging || event.pointerId !== view.pointerId) return;
const dx = event.clientX - view.lastX;
const dy = event.clientY - view.lastY;
if (
Math.abs(event.clientX - view.downX) +
Math.abs(event.clientY - view.downY) >
4
) {
view.moved = true;
}
view.targetAzimuth -= dx * 0.006;
view.targetElevation = THREE.MathUtils.clamp(
view.targetElevation + dy * 0.005,
0.28,
1.12
);
view.lastX = event.clientX;
view.lastY = event.clientY;
});
function endPointer(event) {
if (event.pointerId !== view.pointerId) return;
if (!view.moved) pickSample(event);
view.dragging = false;
view.pointerId = null;
renderer.domElement.classList.remove("dragging");
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.targetRadius = THREE.MathUtils.clamp(
view.targetRadius + event.deltaY * 0.008,
7.5,
20
);
},
{ passive: false }
);
document.getElementById("orbit-left").addEventListener("click", () => {
view.targetAzimuth -= 0.28;
});
document.getElementById("orbit-right").addEventListener("click", () => {
view.targetAzimuth += 0.28;
});
document.getElementById("reset-view").addEventListener("click", () => {
view.targetAzimuth = 0.48;
view.targetElevation = 0.64;
view.targetRadius = defaultRadius();
});
const autoOrbitButton = document.getElementById("auto-orbit");
autoOrbitButton.addEventListener("click", () => {
view.autoRotate = !view.autoRotate;
autoOrbitButton.setAttribute(
"aria-pressed",
String(view.autoRotate)
);
autoOrbitButton.textContent = view.autoRotate
? "Pause orbit"
: "Auto orbit";
});
const labelsButton = document.getElementById("toggle-labels");
labelsButton.addEventListener("click", () => {
const visible = !worldLabels.visible;
worldLabels.visible = visible;
lidLabels.visible = visible;
labelsButton.setAttribute("aria-pressed", String(visible));
labelsButton.textContent = visible ? "Tags" : "Tags off";
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
view.targetAzimuth -= 0.16;
} else if (event.key === "ArrowRight") {
view.targetAzimuth += 0.16;
} else if (event.key === "1") {
selectSample("A");
} else if (event.key === "2") {
selectSample("B");
} else if (event.key === "3") {
selectSample("C");
} else if (event.key.toLowerCase() === "r") {
view.targetAzimuth = 0.48;
view.targetElevation = 0.64;
view.targetRadius = defaultRadius();
}
});
/* -------------------------------------------------------------------------
RESIZE AND ANIMATION
------------------------------------------------------------------------- */
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (view.autoRotate && !view.dragging) {
view.targetAzimuth += delta * 0.12;
}
updateCamera(delta);
const pulse = 1 + Math.sin(performance.now() * 0.0025) * 0.012;
const activeOutline = selectionOutlines[selectedSample];
activeOutline.scale.setScalar(pulse);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera(1);
renderer.render(scene, camera);
requestAnimationFrame(animate);
document.getElementById("loading").classList.add("hidden");
</script>
</body>
</html>
```