Prompt specification
Build or customize the Three.js 3D scene "Water cask beside a shipboard storage rack" 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: Water cask beside a shipboard storage rack
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/water-cask-beside-a-shipboard-storage-rack-x2577
Scene Description Prompt:
A stylized water cask secured by lashings in a shipboard storage rack, with room to access it. Three.js from cdnjs, one HTML file.
Working Three.js Starter (water-cask-beside-a-shipboard-storage-rack-x2577):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Shipboard Water Cask</title>
<style>
:root {
color-scheme: dark;
--ink: #eef7f5;
--muted: #a9bec0;
--accent: #f2a24a;
--panel: rgba(12, 29, 35, 0.82);
--line: rgba(208, 231, 228, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #718f94;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
canvas {
width: 100%;
height: 100%;
display: block;
}
canvas {
outline: none;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 48%, rgba(7, 18, 23, 0.28) 100%),
linear-gradient(180deg, rgba(4, 16, 21, 0.12), transparent 28%);
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title {
position: absolute;
top: 24px;
left: 26px;
color: var(--ink);
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.35);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: #d4e4e2;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: var(--accent);
box-shadow: 0 0 10px rgba(242, 162, 74, 0.5);
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 42px);
font-weight: 720;
letter-spacing: -0.035em;
line-height: 1;
}
.subtitle {
margin-top: 10px;
color: #d1dfde;
font-size: 13px;
letter-spacing: 0.02em;
}
.status {
position: absolute;
top: 26px;
right: 26px;
display: flex;
align-items: center;
gap: 12px;
padding: 11px 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
color: var(--ink);
backdrop-filter: blur(12px);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.18);
}
.status-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #70d4a1;
box-shadow: 0 0 0 4px rgba(112, 212, 161, 0.12);
}
.status strong {
display: block;
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.specs {
position: absolute;
bottom: 26px;
left: 26px;
width: min(310px, calc(100vw - 52px));
padding: 16px 18px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
color: var(--ink);
backdrop-filter: blur(12px);
box-shadow: 0 18px 45px rgba(0, 0, 0, 0.2);
}
.specs-title {
margin-bottom: 12px;
color: #d8e7e5;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.spec-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 14px;
padding: 8px 0;
border-top: 1px solid rgba(208, 231, 228, 0.1);
font-size: 12px;
}
.spec-row:first-of-type {
border-top: 0;
}
.spec-row span:first-child {
color: var(--muted);
}
.spec-row span:last-child {
color: #f6faf9;
font-weight: 650;
text-align: right;
}
.hint {
position: absolute;
right: 26px;
bottom: 28px;
display: flex;
align-items: center;
gap: 11px;
color: rgba(239, 248, 246, 0.8);
font-size: 11px;
text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
}
.mouse {
position: relative;
width: 20px;
height: 29px;
border: 1.5px solid currentColor;
border-radius: 10px;
}
.mouse::before {
position: absolute;
top: 5px;
left: 8px;
width: 2px;
height: 6px;
content: "";
border-radius: 2px;
background: currentColor;
}
button {
position: absolute;
top: 94px;
right: 26px;
pointer-events: auto;
padding: 9px 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--panel);
color: var(--ink);
font: inherit;
font-size: 11px;
cursor: pointer;
backdrop-filter: blur(12px);
transition: background 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(27, 56, 62, 0.94);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #10242c;
color: #d8e6e4;
font-size: 12px;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 680px) {
.title {
top: 18px;
left: 18px;
}
.subtitle,
.hint {
display: none;
}
.status {
top: 18px;
right: 18px;
padding: 9px 10px;
}
.status span {
display: none;
}
button {
top: 72px;
right: 18px;
}
.specs {
left: 18px;
bottom: 18px;
width: calc(100vw - 36px);
padding: 12px 15px;
}
.spec-row {
padding: 6px 0;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="vignette"></div>
<div class="hud">
<div class="title">
<div class="eyebrow">Shipboard Storage · Deck 02</div>
<h1>Fresh Water Cask</h1>
<div class="subtitle">Secured stowage with forward service clearance</div>
</div>
<div class="status">
<div class="status-dot"></div>
<div>
<strong>Lashings secured</strong>
<span>Inspection status: ready</span>
</div>
</div>
<button id="resetView" type="button" aria-label="Reset camera view">
↺ Reset view
</button>
<div class="specs">
<div class="specs-title">Stowage Details</div>
<div class="spec-row">
<span>Container</span>
<span>200 L fresh water</span>
</div>
<div class="spec-row">
<span>Restraint</span>
<span>2 locked lashings</span>
</div>
<div class="spec-row">
<span>Service clearance</span>
<span>0.9 m minimum</span>
</div>
<div class="spec-row">
<span>Access</span>
<span>Open forward bay</span>
</div>
</div>
<div class="hint">
<span class="mouse"></span>
<span>Drag to orbit · Scroll to zoom · Arrow keys to inspect</span>
</div>
</div>
<div id="loading">Preparing stowage scene</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const app = document.getElementById("app");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D view of a lashed water cask in a shipboard rack"
);
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x8da8aa);
scene.fog = new THREE.Fog(0x8da8aa, 12, 29);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const hemisphere = new THREE.HemisphereLight(0xd9f1f4, 0x26383b, 1.75);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d9, 3.5);
keyLight.position.set(4.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x89c7d5, 1.4);
rimLight.position.set(-5, 4, -4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb866, 18, 11, 2);
warmLight.position.set(-2.8, 4.5, 1.8);
scene.add(warmLight);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
const materials = {
steel: new THREE.MeshStandardMaterial({
color: 0x31545b,
roughness: 0.62,
metalness: 0.42
}),
darkSteel: new THREE.MeshStandardMaterial({
color: 0x172f35,
roughness: 0.56,
metalness: 0.58
}),
rackEdge: new THREE.MeshStandardMaterial({
color: 0x10262c,
roughness: 0.72,
metalness: 0.35
}),
wood: new THREE.MeshStandardMaterial({
color: 0xb8753f,
roughness: 0.86,
metalness: 0.02
}),
woodDark: new THREE.MeshStandardMaterial({
color: 0x754327,
roughness: 0.9
}),
woodEnd: new THREE.MeshStandardMaterial({
color: 0xc58a4d,
roughness: 0.82
}),
iron: new THREE.MeshStandardMaterial({
color: 0x394346,
roughness: 0.42,
metalness: 0.72
}),
brass: new THREE.MeshStandardMaterial({
color: 0xb88c3f,
roughness: 0.34,
metalness: 0.68
}),
rope: new THREE.MeshStandardMaterial({
color: 0xdf6e35,
roughness: 0.95
}),
ropeLight: new THREE.MeshStandardMaterial({
color: 0xf3a05a,
roughness: 0.9
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x172124,
roughness: 0.95
}),
crate: new THREE.MeshStandardMaterial({
color: 0xb9b29a,
roughness: 0.88
}),
wall: new THREE.MeshStandardMaterial({
color: 0x9badae,
roughness: 0.9
}),
wallDark: new THREE.MeshStandardMaterial({
color: 0x70898b,
roughness: 0.82
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xe9b84f,
roughness: 0.75
}),
glass: new THREE.MeshStandardMaterial({
color: 0x4a9eb2,
emissive: 0x153e4b,
emissiveIntensity: 0.75,
roughness: 0.25,
metalness: 0.12
})
};
const UP = new THREE.Vector3(0, 1, 0);
function mesh(geometry, material, position, parent = scene) {
const object = new THREE.Mesh(geometry, material);
if (position) object.position.copy(position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(width, height, depth, material, position, parent = scene) {
return mesh(
new THREE.BoxGeometry(width, height, depth),
material,
new THREE.Vector3(...position),
parent
);
}
function beamBetween(start, end, width, depth, material, parent = scene) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const object = mesh(
new THREE.BoxGeometry(width, length, depth),
material,
a.clone().add(b).multiplyScalar(0.5),
parent
);
object.quaternion.setFromUnitVectors(UP, direction.normalize());
return object;
}
function cylinder(radiusTop, radiusBottom, height, material, position, parent = scene, segments = 20) {
return mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material,
new THREE.Vector3(...position),
parent
);
}
// ------------------------------------------------------------
// Procedural painted ship deck
// ------------------------------------------------------------
const deckCanvas = document.createElement("canvas");
deckCanvas.width = 512;
deckCanvas.height = 512;
const deckContext = deckCanvas.getContext("2d");
deckContext.fillStyle = "#526d6b";
deckContext.fillRect(0, 0, 512, 512);
for (let y = 0; y < 512; y += 64) {
deckContext.fillStyle = y % 128 === 0 ? "#57716e" : "#4d6765";
deckContext.fillRect(0, y, 512, 62);
deckContext.fillStyle = "rgba(18,40,42,0.36)";
deckContext.fillRect(0, y + 62, 512, 2);
deckContext.fillStyle = "rgba(212,231,221,0.05)";
deckContext.fillRect(0, y + 2, 512, 1);
}
for (let i = 0; i < 180; i++) {
const x = (i * 83) % 512;
const y = (i * 47) % 512;
deckContext.strokeStyle = i % 3 === 0
? "rgba(229,239,226,0.055)"
: "rgba(13,33,34,0.08)";
deckContext.beginPath();
deckContext.moveTo(x, y);
deckContext.lineTo(x + 18, y - 9);
deckContext.stroke();
}
const deckTexture = new THREE.CanvasTexture(deckCanvas);
deckTexture.colorSpace = THREE.SRGBColorSpace;
deckTexture.wrapS = deckTexture.wrapT = THREE.RepeatWrapping;
deckTexture.repeat.set(7, 7);
deckTexture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const deckMaterial = new THREE.MeshStandardMaterial({
map: deckTexture,
color: 0xd7e0da,
roughness: 0.93,
metalness: 0.06
});
const deck = mesh(
new THREE.PlaneGeometry(30, 30),
deckMaterial,
new THREE.Vector3(0, 0, 0)
);
deck.rotation.x = -Math.PI / 2;
deck.castShadow = false;
// ------------------------------------------------------------
// Ship bulkhead and background fittings
// ------------------------------------------------------------
box(12, 5.1, 0.18, materials.wall, [0, 2.45, -2.4]);
box(12, 0.18, 0.24, materials.wallDark, [0, 0.18, -2.28]);
box(12, 0.16, 0.25, materials.wallDark, [0, 4.35, -2.27]);
for (let x = -5; x <= 5; x += 1.5) {
box(0.025, 4.1, 0.025, materials.wallDark, [x, 2.4, -2.295]);
}
function makePorthole(x) {
const glass = mesh(
new THREE.CircleGeometry(0.48, 40),
materials.glass,
new THREE.Vector3(x, 2.55, -2.285)
);
glass.castShadow = false;
const ring = mesh(
new THREE.TorusGeometry(0.54, 0.075, 12, 44),
materials.darkSteel,
new THREE.Vector3(x, 2.55, -2.205)
);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
mesh(
new THREE.SphereGeometry(0.035, 8, 6),
materials.brass,
new THREE.Vector3(
x + Math.cos(angle) * 0.54,
2.55 + Math.sin(angle) * 0.54,
-2.11
)
);
}
}
makePorthole(-3.65);
makePorthole(3.45);
const overheadPipe = cylinder(
0.075,
0.075,
10.8,
materials.yellow,
[0, 3.83, -2.02],
scene,
18
);
overheadPipe.rotation.z = Math.PI / 2;
for (const x of [-4.5, -1.5, 1.5, 4.5]) {
box(0.12, 0.42, 0.12, materials.darkSteel, [x, 3.98, -2.08]);
}
// ------------------------------------------------------------
// Shipboard storage rack
// ------------------------------------------------------------
const rack = new THREE.Group();
rack.position.x = -0.25;
scene.add(rack);
box(4.55, 0.18, 2.28, materials.darkSteel, [0, 0.2, 0], rack);
box(4.35, 0.1, 2.08, materials.steel, [0, 2.56, 0], rack);
for (const x of [-2.05, 2.05]) {
for (const z of [-1.0, 1.0]) {
box(0.15, 2.92, 0.15, materials.steel, [x, 1.68, z], rack);
box(0.31, 0.055, 0.31, materials.rackEdge, [x, 0.055, z], rack);
}
}
for (const z of [-1.0, 1.0]) {
box(4.35, 0.16, 0.16, materials.steel, [0, 3.12, z], rack);
box(4.25, 0.1, 0.11, materials.darkSteel, [0, 0.43, z], rack);
}
for (const x of [-2.05, 2.05]) {
box(0.16, 0.16, 2.12, materials.steel, [x, 3.12, 0], rack);
box(0.11, 0.11, 2.08, materials.darkSteel, [x, 0.43, 0], rack);
}
// Rear diagonal braces keep the silhouette clearly industrial.
beamBetween([-1.98, 0.47, -1.02], [1.98, 2.49, -1.02], 0.08, 0.08, materials.darkSteel, rack);
beamBetween([1.98, 0.47, -1.02], [-1.98, 2.49, -1.02], 0.08, 0.08, materials.darkSteel, rack);
// Two lower V-cradles.
for (const x of [-1.38, 0.82]) {
beamBetween([x, 0.36, -0.92], [x, 0.65, -0.5], 0.16, 0.16, materials.darkSteel, rack);
beamBetween([x, 0.36, 0.92], [x, 0.65, 0.5], 0.16, 0.16, materials.darkSteel, rack);
mesh(
new THREE.SphereGeometry(0.085, 12, 8),
materials.rubber,
new THREE.Vector3(x, 0.66, -0.51),
rack
);
mesh(
new THREE.SphereGeometry(0.085, 12, 8),
materials.rubber,
new THREE.Vector3(x, 0.66, 0.51),
rack
);
}
// Upper-shelf supply crate.
box(1.02, 0.66, 0.76, materials.crate, [1.15, 2.94, -0.35], rack);
box(1.08, 0.08, 0.81, materials.woodDark, [1.15, 3.28, -0.35], rack);
for (const z of [-0.65, -0.35, -0.05]) {
box(0.98, 0.025, 0.025, materials.woodDark, [1.15, 2.94, z], rack);
}
// A spare coil of rope.
for (const radius of [0.25, 0.18]) {
const coil = mesh(
new THREE.TorusGeometry(radius, 0.045, 9, 32),
materials.ropeLight,
new THREE.Vector3(-1.35, 2.65, -0.3),
rack
);
coil.rotation.x = Math.PI / 2;
}
// ------------------------------------------------------------
// Water cask
// ------------------------------------------------------------
const cask = new THREE.Group();
cask.position.set(-0.25, 1.32, 0);
scene.add(cask);
const profile = [
[0.60, -1.62],
[0.67, -1.55],
[0.76, -1.31],
[0.83, -0.92],
[0.86, -0.40],
[0.87, 0.00],
[0.86, 0.40],
[0.83, 0.92],
[0.76, 1.31],
[0.67, 1.55],
[0.60, 1.62]
];
const bodyGeometry = new THREE.LatheGeometry(
profile.map(([radius, axial]) => new THREE.Vector2(radius, axial)),
36
);
bodyGeometry.rotateZ(Math.PI / 2);
mesh(bodyGeometry, materials.wood, null, cask);
function radiusAt(x) {
const a = Math.abs(x);
if (a < 0.4) return 0.865;
if (a < 0.92) return THREE.MathUtils.lerp(0.865, 0.83, (a - 0.4) / 0.52);
if (a < 1.31) return THREE.MathUtils.lerp(0.83, 0.76, (a - 0.92) / 0.39);
if (a < 1.55) return THREE.MathUtils.lerp(0.76, 0.67, (a - 1.31) / 0.24);
return 0.67;
}
// Longitudinal stave seams.
for (let stave = 0; stave < 16; stave++) {
const angle = (stave / 16) * Math.PI * 2;
const points = [];
for (const x of [-1.56, -1.4, -1.12, -0.68, -0.25, 0.25, 0.68, 1.12, 1.4, 1.56]) {
const radius = radiusAt(x) + 0.008;
points.push(
new THREE.Vector3(
x,
Math.cos(angle) * radius,
Math.sin(angle) * radius
)
);
}
const curve = new THREE.CatmullRomCurve3(points);
mesh(
new THREE.TubeGeometry(curve, 26, 0.011, 5, false),
materials.woodDark,
null,
cask
);
}
// Iron hoops around the bulging body.
for (const x of [-1.43, -0.93, -0.28, 0.28, 0.93, 1.43]) {
const hoop = mesh(
new THREE.TorusGeometry(radiusAt(x) + 0.018, 0.034, 8, 44),
materials.iron,
new THREE.Vector3(x, 0, 0),
cask
);
hoop.rotation.y = Math.PI / 2;
}
// End heads.
for (const side of [-1, 1]) {
const head = cylinder(
0.605,
0.605,
0.08,
materials.woodEnd,
[side * 1.655, 0, 0],
cask,
36
);
head.rotation.z = Math.PI / 2;
const rim = mesh(
new THREE.TorusGeometry(0.585, 0.032, 8, 40),
materials.iron,
new THREE.Vector3(side * 1.702, 0, 0),
cask
);
rim.rotation.y = Math.PI / 2;
const faceX = side * 1.704;
for (const z of [-0.43, -0.29, -0.145, 0, 0.145, 0.29, 0.43]) {
const extent = Math.sqrt(0.57 * 0.57 - z * z);
beamBetween(
[faceX, -extent, z],
[faceX, extent, z],
0.009,
0.009,
materials.woodDark,
cask
);
}
}
// Bung on the visible end.
const bung = cylinder(
0.085,
0.085,
0.045,
materials.woodDark,
[1.716, 0.1, 0.1],
cask,
16
);
bung.rotation.z = Math.PI / 2;
// Circular WATER label.
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 512;
const labelContext = labelCanvas.getContext("2d");
labelContext.clearRect(0, 0, 512, 512);
labelContext.fillStyle = "#e6d4a5";
labelContext.beginPath();
labelContext.arc(256, 256, 232, 0, Math.PI * 2);
labelContext.fill();
labelContext.strokeStyle = "#674329";
labelContext.lineWidth = 18;
labelContext.stroke();
labelContext.fillStyle = "#5c3b24";
labelContext.textAlign = "center";
labelContext.font = "bold 58px sans-serif";
labelContext.fillText("FRESH", 256, 205);
labelContext.font = "bold 44px sans-serif";
labelContext.fillText("WATER", 256, 263);
labelContext.font = "bold 35px sans-serif";
labelContext.fillText("200 L", 256, 326);
const labelTexture = new THREE.CanvasTexture(labelCanvas);
labelTexture.colorSpace = THREE.SRGBColorSpace;
const label = mesh(
new THREE.CircleGeometry(0.3, 40),
new THREE.MeshStandardMaterial({
map: labelTexture,
transparent: true,
roughness: 0.88,
side: THREE.DoubleSide
}),
new THREE.Vector3(1.715, 0, 0),
cask
);
label.rotation.y = Math.PI / 2;
label.castShadow = false;
// ------------------------------------------------------------
// Lashing ropes and ratchet hardware
// ------------------------------------------------------------
function makeLashing(x) {
const centerY = 1.32;
const radius = 0.895;
const points = [
new THREE.Vector3(x, 0.39, 1.03),
new THREE.Vector3(x, centerY + radius * Math.sin(-0.92), radius * Math.cos(-0.92)),
new THREE.Vector3(x, centerY + radius * Math.sin(-0.40), radius * Math.cos(-0.40)),
new THREE.Vector3(x, centerY + radius * Math.sin(0.20), radius * Math.cos(0.20)),
new THREE.Vector3(x, centerY + radius * Math.sin(0.80), radius * Math.cos(0.80)),
new THREE.Vector3(x, centerY + radius, 0),
new THREE.Vector3(x, centerY + radius * Math.sin(2.34), radius * Math.cos(2.34)),
new THREE.Vector3(x, centerY + radius * Math.sin(2.95), radius * Math.cos(2.95)),
new THREE.Vector3(x, centerY + radius * Math.sin(3.55), radius * Math.cos(3.55)),
new THREE.Vector3(x, centerY + radius * Math.sin(4.06), radius * Math.cos(4.06)),
new THREE.Vector3(x, 0.39, -1.03)
];
const curve = new THREE.CatmullRomCurve3(points, false, "centripetal");
mesh(
new THREE.TubeGeometry(curve, 72, 0.037, 8, false),
materials.rope
);
// A fine highlight strand gives the rope a braided appearance.
const highlightPoints = points.map((point) =>
point.clone().add(new THREE.Vector3(0.013, 0.008, 0))
);
const highlightCurve = new THREE.CatmullRomCurve3(
highlightPoints,
false,
"centripetal"
);
mesh(
new THREE.TubeGeometry(highlightCurve, 72, 0.008, 5, false),
materials.ropeLight
);
// Front ratchet and rear anchor.
box(0.22, 0.14, 0.13, materials.darkSteel, [x, 0.39, 1.035]);
box(0.29, 0.055, 0.075, materials.brass, [x, 0.47, 1.11]);
box(0.18, 0.11, 0.12, materials.iron, [x, 0.38, -1.035]);
}
makeLashing(-1.25);
makeLashing(0.65);
// ------------------------------------------------------------
// Spigot and drip tray
// ------------------------------------------------------------
const flange = cylinder(
0.105,
0.105,
0.055,
materials.brass,
[0.45, 0.92, 0.755]
);
flange.rotation.x = Math.PI / 2;
const spout = cylinder(
0.05,
0.05,
0.31,
materials.brass,
[0.45, 0.92, 0.89]
);
spout.rotation.x = Math.PI / 2;
cylinder(0.046, 0.046, 0.22, materials.brass, [0.45, 0.79, 1.025]);
const valveStem = cylinder(
0.035,
0.035,
0.24,
materials.iron,
[0.55, 0.94, 0.925]
);
valveStem.rotation.z = Math.PI / 2;
const valveWheel = mesh(
new THREE.TorusGeometry(0.105, 0.021, 8, 24),
materials.rope,
new THREE.Vector3(0.675, 0.94, 0.925)
);
valveWheel.rotation.y = Math.PI / 2;
box(0.58, 0.055, 0.4, materials.darkSteel, [0.45, 0.4, 1.05]);
for (let i = 0; i < 5; i++) {
box(0.035, 0.025, 0.33, materials.iron, [0.23 + i * 0.11, 0.44, 1.05]);
}
// ------------------------------------------------------------
// Forward service-clearance markings
// ------------------------------------------------------------
function floorDashLine(x1, z1, x2, z2) {
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const dashLength = 0.31;
const gap = 0.19;
const count = Math.max(1, Math.floor(length / (dashLength + gap)));
const angle = -Math.atan2(dz, dx);
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const dash = box(
dashLength,
0.012,
0.045,
materials.yellow,
[x1 + dx * t, 0.015, z1 + dz * t]
);
dash.rotation.y = angle;
dash.castShadow = false;
}
}
floorDashLine(-1.9, 1.45, 1.75, 1.45);
floorDashLine(-1.9, 3.25, 1.75, 3.25);
floorDashLine(-1.9, 1.45, -1.9, 3.25);
floorDashLine(1.75, 1.45, 1.75, 3.25);
const stencilCanvas = document.createElement("canvas");
stencilCanvas.width = 1024;
stencilCanvas.height = 256;
const stencilContext = stencilCanvas.getContext("2d");
stencilContext.clearRect(0, 0, 1024, 256);
stencilContext.fillStyle = "rgba(239,190,74,0.78)";
stencilContext.textAlign = "center";
stencilContext.font = "bold 94px sans-serif";
stencilContext.fillText("SERVICE ACCESS", 512, 112);
stencilContext.font = "bold 52px sans-serif";
stencilContext.fillText("KEEP CLEAR", 512, 188);
const stencilTexture = new THREE.CanvasTexture(stencilCanvas);
stencilTexture.colorSpace = THREE.SRGBColorSpace;
const stencil = mesh(
new THREE.PlaneGeometry(2.6, 0.65),
new THREE.MeshBasicMaterial({
map: stencilTexture,
transparent: true,
depthWrite: false,
opacity: 0.82,
side: THREE.DoubleSide
}),
new THREE.Vector3(-0.05, 0.024, 2.55)
);
stencil.rotation.x = -Math.PI / 2;
stencil.castShadow = false;
// Small rack identification plate.
const signCanvas = document.createElement("canvas");
signCanvas.width = 512;
signCanvas.height = 128;
const signContext = signCanvas.getContext("2d");
signContext.clearRect(0, 0, 512, 128);
signContext.fillStyle = "rgba(19,42,47,0.95)";
signContext.fillRect(0, 0, 512, 128);
signContext.strokeStyle = "#e6b451";
signContext.lineWidth = 8;
signContext.strokeRect(7, 7, 498, 114);
signContext.fillStyle = "#f1e7ca";
signContext.font = "bold 58px sans-serif";
signContext.textAlign = "center";
signContext.fillText("CASK 04", 256, 83);
const signTexture = new THREE.CanvasTexture(signCanvas);
signTexture.colorSpace = THREE.SRGBColorSpace;
const sign = mesh(
new THREE.PlaneGeometry(0.92, 0.23),
new THREE.MeshBasicMaterial({
map: signTexture,
transparent: true
}),
new THREE.Vector3(-0.25, 3.12, 1.091)
);
sign.castShadow = false;
// ------------------------------------------------------------
// Custom camera controls
// ------------------------------------------------------------
const target = new THREE.Vector3(-0.12, 1.38, 0);
const view = {
theta: 0.62,
phi: 1.13,
radius: 8.8
};
const desired = {
theta: view.theta,
phi: view.phi,
radius: view.radius
};
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
view.theta += (desired.theta - view.theta) * 0.12;
view.phi += (desired.phi - view.phi) * 0.12;
view.radius += (desired.radius - view.radius) * 0.12;
const sinPhi = Math.sin(view.phi);
camera.position.set(
target.x + view.radius * sinPhi * Math.sin(view.theta),
target.y + view.radius * Math.cos(view.phi),
target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(target);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(desired.phi - dy * 0.005, 0.55, 1.48);
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius + event.deltaY * 0.006,
5.2,
13
);
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
desired.theta += 0.08;
break;
case "ArrowRight":
desired.theta -= 0.08;
break;
case "ArrowUp":
desired.phi = THREE.MathUtils.clamp(desired.phi - 0.06, 0.55, 1.48);
break;
case "ArrowDown":
desired.phi = THREE.MathUtils.clamp(desired.phi + 0.06, 0.55, 1.48);
break;
case "+":
case "=":
desired.radius = Math.max(5.2, desired.radius - 0.4);
break;
case "-":
case "_":
desired.radius = Math.min(13, desired.radius + 0.4);
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
renderer.domElement.style.cursor = "grab";
document.getElementById("resetView").addEventListener("click", () => {
desired.theta = 0.62;
desired.phi = 1.13;
desired.radius = 8.8;
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
let firstFrame = true;
function animate() {
updateCamera();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
}
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```