Prompt specification
Build or customize the Three.js 3D scene "Container corner casting and lifting fitting" 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: Container corner casting and lifting fitting
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/container-corner-casting-and-lifting-fitting-x2529
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this stylized scene: Model a shipping-container corner with a referenced casting and matching lifting connection. Show their geometric compatibility without turning the scene into load-rating guidance.
Working Three.js Starter (container-corner-casting-and-lifting-fitting-x2529):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Corner & Lift — Geometric Compatibility Study</title>
<style>
:root {
--ink: #172326;
--muted: #637174;
--paper: #eeece5;
--panel: rgba(250, 249, 244, 0.84);
--line: rgba(23, 35, 38, 0.14);
--accent: #ed8b43;
--accent-soft: #f7d9bd;
--green: #4b8a73;
--steel: #384347;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene:active {
cursor: grabbing;
}
.masthead {
position: fixed;
top: 26px;
left: 28px;
z-index: 5;
pointer-events: none;
max-width: 430px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 54px);
font-weight: 650;
letter-spacing: -0.055em;
line-height: 0.95;
}
.masthead p {
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.status-chip {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 15px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(250, 249, 244, 0.7);
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.status-chip::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px var(--accent-soft);
transition: background 180ms ease, box-shadow 180ms ease;
}
.status-chip.seated::before {
background: var(--green);
box-shadow: 0 0 0 4px rgba(75, 138, 115, 0.16);
}
.reference-card {
position: fixed;
top: 26px;
right: 26px;
z-index: 5;
width: 292px;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.64);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(41, 49, 47, 0.09);
backdrop-filter: blur(16px);
}
.reference-card h2 {
margin: 0 0 14px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.spec-row {
display: grid;
grid-template-columns: 82px 1fr;
gap: 12px;
padding: 9px 0;
border-top: 1px solid var(--line);
font-size: 11px;
line-height: 1.4;
}
.spec-row:first-of-type {
border-top: 0;
padding-top: 0;
}
.spec-row span:first-child {
color: var(--muted);
}
.spec-row strong {
display: block;
font-weight: 720;
}
.fit-diagram {
position: relative;
height: 66px;
margin: 13px 0 5px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background:
linear-gradient(90deg, transparent 49.7%, rgba(23, 35, 38, 0.1) 50%, transparent 50.3%),
linear-gradient(transparent 49.7%, rgba(23, 35, 38, 0.1) 50%, transparent 50.3%),
rgba(255, 255, 255, 0.34);
}
.fit-hole {
position: absolute;
left: 50%;
top: 50%;
width: 84px;
height: 44px;
border: 5px solid var(--steel);
border-radius: 50%;
transform: translate(-50%, -50%);
}
.fit-pilot {
position: absolute;
left: 50%;
top: 8px;
width: 44px;
height: 50px;
border-radius: 45% 45% 38% 38% / 28% 28% 72% 72%;
background: var(--accent);
transform: translateX(-50%);
box-shadow: 0 5px 12px rgba(237, 139, 67, 0.25);
}
.fit-pilot::after {
content: "";
position: absolute;
left: 50%;
top: -9px;
width: 1px;
height: 68px;
background: var(--green);
transform: translateX(-50%);
}
.fit-caption {
position: absolute;
right: 8px;
bottom: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scope-note {
margin: 12px 0 0;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9.5px;
line-height: 1.5;
}
.scope-note strong {
color: var(--ink);
}
.controls {
position: fixed;
left: 50%;
bottom: 24px;
z-index: 7;
width: min(620px, calc(100vw - 32px));
padding: 13px 14px 12px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(41, 49, 47, 0.13);
backdrop-filter: blur(16px);
transform: translateX(-50%);
}
.control-row {
display: flex;
align-items: center;
gap: 8px;
}
.control-row + .control-row {
margin-top: 10px;
}
button {
min-height: 36px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.55);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 720;
transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}
button:hover {
border-color: rgba(23, 35, 38, 0.25);
background: rgba(255, 255, 255, 0.9);
transform: translateY(-1px);
}
button.primary {
border-color: var(--ink);
background: var(--ink);
color: #f9f7ef;
}
button.active {
border-color: rgba(237, 139, 67, 0.6);
background: var(--accent-soft);
}
.travel {
display: flex;
flex: 1;
align-items: center;
gap: 10px;
min-width: 0;
}
.travel label {
flex: 0 0 auto;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
min-width: 80px;
accent-color: var(--accent);
cursor: ew-resize;
}
.range-value {
width: 36px;
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
text-align: right;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 15px;
margin-left: auto;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--steel);
}
.swatch.pilot {
background: var(--accent);
}
.swatch.axis {
height: 2px;
border-radius: 0;
background: var(--green);
}
.orbit-hint {
position: fixed;
right: 27px;
bottom: 29px;
z-index: 4;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
pointer-events: none;
}
.scene-label {
position: fixed;
z-index: 3;
min-width: 132px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 9px;
background: rgba(248, 247, 241, 0.82);
box-shadow: 0 8px 24px rgba(33, 42, 41, 0.08);
backdrop-filter: blur(10px);
pointer-events: none;
transform: translate(12px, -50%);
}
.scene-label strong {
display: block;
font-size: 10px;
font-weight: 800;
}
.scene-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.04em;
}
.scene-label::before {
content: "";
position: absolute;
left: -20px;
top: 50%;
width: 19px;
height: 1px;
background: rgba(23, 35, 38, 0.42);
}
.scene-label.axis-label {
min-width: auto;
padding: 5px 8px;
transform: translate(-100%, -50%);
color: var(--green);
border-color: rgba(75, 138, 115, 0.28);
background: rgba(239, 247, 242, 0.82);
}
.scene-label.axis-label::before {
display: none;
}
@media (max-width: 920px) {
.reference-card {
display: none;
}
.masthead {
top: 18px;
left: 18px;
}
.masthead p {
max-width: 270px;
}
.orbit-hint {
display: none;
}
.legend {
display: none;
}
}
@media (max-width: 580px) {
h1 {
font-size: 34px;
}
.masthead p {
font-size: 11px;
}
.status-chip {
margin-top: 10px;
}
.controls {
bottom: 12px;
padding: 10px;
}
.control-row {
flex-wrap: wrap;
}
.control-row button {
flex: 1 1 auto;
}
.travel {
order: 3;
flex-basis: 100%;
}
.scene-label {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional model of a shipping-container corner casting and mating lifting connection"></canvas>
<header class="masthead">
<div class="eyebrow">Geometry study / 01</div>
<h1>Corner & lift</h1>
<p>
A stylized shipping-container corner with a reference casting and a
matching tapered lifting connection.
</p>
<div id="statusChip" class="status-chip" aria-live="polite">
Aligned / open
</div>
</header>
<aside class="reference-card">
<h2>Reference pair</h2>
<div class="spec-row">
<span>Form</span>
<strong>ISO-style corner casting</strong>
</div>
<div class="spec-row">
<span>Envelope</span>
<strong>178 × 162 × 118 mm</strong>
</div>
<div class="spec-row">
<span>Interface</span>
<strong>Oval aperture + tapered pilot</strong>
</div>
<div class="spec-row">
<span>Constraint</span>
<strong>Shared vertical insertion axis</strong>
</div>
<div class="fit-diagram" aria-hidden="true">
<div class="fit-hole"></div>
<div class="fit-pilot"></div>
<div class="fit-caption">schematic</div>
</div>
<p class="scope-note">
<strong>Visual geometry only.</strong> No load rating, working-load limit,
safety factor, material grade, retention method, certification, or lifting
approval is represented. The dimensions and interface are reference
proportions, not manufacturing or lifting guidance.
</p>
</aside>
<section class="controls" aria-label="Model controls">
<div class="control-row">
<button id="mateButton" class="primary">Seat connection</button>
<button id="xrayButton" aria-pressed="false">X-ray casting</button>
<button id="resetButton">Reset view</button>
<div class="legend" aria-hidden="true">
<span><i class="swatch"></i> Casting</span>
<span><i class="swatch pilot"></i> Pilot</span>
<span><i class="swatch axis"></i> Axis</span>
</div>
</div>
<div class="control-row">
<div class="travel">
<label for="mateRange">Mate travel</label>
<input id="mateRange" type="range" min="0" max="100" value="0" />
<output id="rangeValue" class="range-value">0%</output>
</div>
</div>
</section>
<div id="castingLabel" class="scene-label">
<strong>Corner casting</strong>
<small>reference envelope</small>
</div>
<div id="connectionLabel" class="scene-label">
<strong>Lifting connection</strong>
<small>tapered, coaxial pilot</small>
</div>
<div id="axisLabel" class="scene-label axis-label">
shared axis
</div>
<div class="orbit-hint">Drag to orbit · wheel to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeeece5);
scene.fog = new THREE.Fog(0xeeece5, 4.8, 9);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.02,
30
);
/* ---------------------------------------------------------------
Direct camera controls: orbit, zoom, inertia, touch support.
---------------------------------------------------------------- */
class OrbitControls {
constructor(domElement) {
this.domElement = domElement;
this.target = new THREE.Vector3(0.08, 0.36, 0.14);
this.desiredTarget = this.target.clone();
this.spherical = new THREE.Spherical(1.55, 1.10, -2.25);
this.desired = {
radius: this.spherical.radius,
phi: this.spherical.phi,
theta: this.spherical.theta
};
this.dragging = false;
this.pointerId = null;
this.lastX = 0;
this.lastY = 0;
this.onPointerDown = (event) => {
this.dragging = true;
this.pointerId = event.pointerId;
this.lastX = event.clientX;
this.lastY = event.clientY;
domElement.setPointerCapture(event.pointerId);
};
this.onPointerMove = (event) => {
if (!this.dragging || event.pointerId !== this.pointerId) return;
const dx = event.clientX - this.lastX;
const dy = event.clientY - this.lastY;
this.lastX = event.clientX;
this.lastY = event.clientY;
this.desired.theta -= dx * 0.006;
this.desired.phi = THREE.MathUtils.clamp(
this.desired.phi - dy * 0.005,
0.38,
1.48
);
};
this.onPointerUp = (event) => {
if (event.pointerId !== this.pointerId) return;
this.dragging = false;
if (domElement.hasPointerCapture(event.pointerId)) {
domElement.releasePointerCapture(event.pointerId);
}
};
this.onWheel = (event) => {
event.preventDefault();
this.desired.radius = THREE.MathUtils.clamp(
this.desired.radius * Math.exp(event.deltaY * 0.001),
0.68,
4.5
);
};
domElement.addEventListener("pointerdown", this.onPointerDown);
domElement.addEventListener("pointermove", this.onPointerMove);
domElement.addEventListener("pointerup", this.onPointerUp);
domElement.addEventListener("pointercancel", this.onPointerUp);
domElement.addEventListener("wheel", this.onWheel, { passive: false });
}
reset() {
this.desired.radius = 1.55;
this.desired.phi = 1.10;
this.desired.theta = -2.25;
this.desiredTarget.set(0.08, 0.36, 0.14);
}
update(dt) {
const damping = 1 - Math.exp(-10 * dt);
this.spherical.radius = THREE.MathUtils.lerp(
this.spherical.radius,
this.desired.radius,
damping
);
this.spherical.phi = THREE.MathUtils.lerp(
this.spherical.phi,
this.desired.phi,
damping
);
this.spherical.theta = THREE.MathUtils.lerp(
this.spherical.theta,
this.desired.theta,
damping
);
this.target.lerp(this.desiredTarget, damping);
camera.position.setFromSpherical(this.spherical).add(this.target);
camera.lookAt(this.target);
}
}
const controls = new OrbitControls(canvas);
/* ---------------------------------------------------------------
Lighting and environment.
---------------------------------------------------------------- */
scene.add(new THREE.HemisphereLight(0xffffff, 0x6d7773, 2.2));
const keyLight = new THREE.DirectionalLight(0xfff5df, 4.2);
keyLight.position.set(-3.2, 5.5, -3.8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -4;
keyLight.shadow.camera.right = 4;
keyLight.shadow.camera.top = 4;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.1;
keyLight.shadow.camera.far = 12;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xc8e4e8, 1.7);
rimLight.position.set(3.5, 3, 3.5);
scene.add(rimLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe7e4dc,
roughness: 0.94,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(14, 14),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.026;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(10, 40, 0x83908d, 0xa8afaa);
grid.position.y = -0.024;
grid.material.transparent = true;
grid.material.opacity = 0.17;
scene.add(grid);
/* ---------------------------------------------------------------
Materials.
---------------------------------------------------------------- */
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x315f66,
roughness: 0.59,
metalness: 0.2
});
const ribMaterial = new THREE.MeshStandardMaterial({
color: 0x396a70,
roughness: 0.54,
metalness: 0.22
});
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x202d31,
roughness: 0.46,
metalness: 0.45
});
const orangeMaterial = new THREE.MeshStandardMaterial({
color: 0xe9793f,
roughness: 0.44,
metalness: 0.25
});
const castMaterial = new THREE.MeshStandardMaterial({
color: 0x384347,
roughness: 0.39,
metalness: 0.72,
transparent: true,
opacity: 1
});
const linerMaterial = new THREE.MeshStandardMaterial({
color: 0x11191b,
roughness: 0.82,
metalness: 0.12,
side: THREE.DoubleSide,
transparent: true,
opacity: 1
});
const apertureMaterial = new THREE.MeshStandardMaterial({
color: 0x111719,
roughness: 0.9,
metalness: 0.05,
side: THREE.DoubleSide
});
const steelMaterial = new THREE.MeshStandardMaterial({
color: 0x7e898d,
roughness: 0.3,
metalness: 0.84
});
const pilotMaterial = new THREE.MeshStandardMaterial({
color: 0xeaa04e,
roughness: 0.29,
metalness: 0.68
});
const collarMaterial = new THREE.MeshStandardMaterial({
color: 0x455156,
roughness: 0.33,
metalness: 0.78
});
function addBox(size, position, material, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
/* ---------------------------------------------------------------
Stylized cutaway shipping-container corner.
Coordinates: +X and +Z extend into the container.
---------------------------------------------------------------- */
const container = new THREE.Group();
scene.add(container);
addBox([2.18, 1.34, 0.052], [1.265, 0.79, 0.026], bodyMaterial, container);
addBox([0.052, 1.34, 1.62], [0.026, 0.79, 0.972], bodyMaterial, container);
addBox([2.18, 0.052, 1.62], [1.265, 0.145, 0.972], railMaterial, container);
// Long-side corrugations.
for (let i = 0; i < 18; i++) {
addBox(
[0.035, 1.18, 0.048],
[0.245 + i * 0.118, 0.80, -0.017],
ribMaterial,
container
);
}
// End-wall corrugations.
for (let i = 0; i < 14; i++) {
addBox(
[0.048, 1.18, 0.035],
[-0.017, 0.80, 0.225 + i * 0.113],
ribMaterial,
container
);
}
// Corner post and cutaway rails.
addBox([0.09, 1.42, 0.09], [0.048, 0.79, 0.048], railMaterial, container);
addBox([2.20, 0.105, 0.095], [1.265, 0.174, 0.028], railMaterial, container);
addBox([0.095, 0.105, 1.64], [0.028, 0.174, 0.972], railMaterial, container);
addBox([2.20, 0.095, 0.10], [1.265, 1.46, 0.028], railMaterial, container);
addBox([0.10, 0.095, 1.64], [0.028, 1.46, 0.972], railMaterial, container);
// Orange cut-edge accents.
addBox([2.18, 0.012, 0.105], [1.265, 1.512, 0.028], orangeMaterial, container);
addBox([0.105, 0.012, 1.62], [0.028, 1.512, 0.972], orangeMaterial, container);
// Small locking-bar detail on the end panel.
addBox([0.032, 1.05, 0.032], [-0.06, 0.78, 1.22], railMaterial, container);
addBox([0.065, 0.055, 0.065], [-0.063, 0.78, 1.22], orangeMaterial, container);
// Painted identity plate made locally with a canvas texture.
const plateCanvas = document.createElement("canvas");
plateCanvas.width = 768;
plateCanvas.height = 220;
const plateContext = plateCanvas.getContext("2d");
plateContext.clearRect(0, 0, plateCanvas.width, plateCanvas.height);
plateContext.fillStyle = "rgba(244,240,224,0.91)";
plateContext.fillRect(0, 0, 768, 220);
plateContext.fillStyle = "#e9793f";
plateContext.fillRect(0, 0, 24, 220);
plateContext.fillStyle = "#263438";
plateContext.font = "800 55px sans-serif";
plateContext.fillText("CORNER STUDY", 58, 92);
plateContext.fillStyle = "#667376";
plateContext.font = "600 28px sans-serif";
plateContext.fillText("GEOMETRY / COAXIAL INTERFACE", 60, 154);
const plateTexture = new THREE.CanvasTexture(plateCanvas);
plateTexture.colorSpace = THREE.SRGBColorSpace;
const plate = new THREE.Mesh(
new THREE.PlaneGeometry(0.76, 0.22),
new THREE.MeshStandardMaterial({
map: plateTexture,
transparent: true,
roughness: 0.75,
metalness: 0
})
);
plate.position.set(0.72, 1.02, -0.056);
plate.rotation.y = Math.PI;
container.add(plate);
/* ---------------------------------------------------------------
Corner casting:
rounded rectangular casting with an actual oval through-opening.
---------------------------------------------------------------- */
function roundedRectangleShape(width, height, radius) {
const shape = new THREE.Shape();
const left = -width / 2;
const right = width / 2;
const bottom = -height / 2;
const top = height / 2;
shape.moveTo(left + radius, bottom);
shape.lineTo(right - radius, bottom);
shape.quadraticCurveTo(right, bottom, right, bottom + radius);
shape.lineTo(right, top - radius);
shape.quadraticCurveTo(right, top, right - radius, top);
shape.lineTo(left + radius, top);
shape.quadraticCurveTo(left, top, left, top - radius);
shape.lineTo(left, bottom + radius);
shape.quadraticCurveTo(left, bottom, left + radius, bottom);
return shape;
}
const castingWidth = 0.178;
const castingDepth = 0.162;
const castingHeight = 0.118;
const apertureRadiusX = 0.044;
const apertureRadiusZ = 0.032;
const castingShape = roundedRectangleShape(
castingWidth,
castingDepth,
0.011
);
const castingHole = new THREE.Path();
castingHole.absellipse(
0,
0,
apertureRadiusX,
apertureRadiusZ,
0,
Math.PI * 2,
true
);
castingShape.holes.push(castingHole);
const castingGeometry = new THREE.ExtrudeGeometry(castingShape, {
depth: castingHeight,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.0022,
bevelThickness: 0.0022,
curveSegments: 18,
steps: 1
});
const casting = new THREE.Mesh(castingGeometry, castMaterial);
casting.rotation.x = -Math.PI / 2;
casting.position.set(
-castingWidth / 2,
0,
-castingDepth / 2
);
casting.castShadow = true;
casting.receiveShadow = true;
scene.add(casting);
// Dark inner liner emphasizes the aperture without covering it.
const liner = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.112, 48, 1, true),
linerMaterial
);
liner.scale.set(1.22, 1, 0.91);
liner.position.set(
-castingWidth / 2,
castingHeight / 2,
-castingDepth / 2
);
scene.add(liner);
// Slightly highlighted top rim.
const topRim = new THREE.Mesh(
new THREE.TorusGeometry(0.038, 0.0027, 10, 64),
steelMaterial
);
topRim.rotation.x = Math.PI / 2;
topRim.scale.set(1.16, 0.86, 1);
topRim.position.set(
-castingWidth / 2,
castingHeight + 0.001,
-castingDepth / 2
);
scene.add(topRim);
// Stylized side apertures.
const sideApertureX = new THREE.Mesh(
new THREE.CircleGeometry(1, 48),
apertureMaterial
);
sideApertureX.scale.set(0.034, 0.018, 1);
sideApertureX.rotation.y = -Math.PI / 2;
sideApertureX.position.set(
-castingWidth - 0.001,
0.061,
-castingDepth / 2
);
scene.add(sideApertureX);
const sideApertureZ = new THREE.Mesh(
new THREE.CircleGeometry(1, 48),
apertureMaterial
);
sideApertureZ.scale.set(0.036, 0.019, 1);
sideApertureZ.rotation.y = Math.PI;
sideApertureZ.position.set(
-castingWidth / 2,
0.061,
-castingDepth - 0.001
);
scene.add(sideApertureZ);
// Subtle cast edges.
const castEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(castingGeometry, 28),
new THREE.LineBasicMaterial({
color: 0x98a2a3,
transparent: true,
opacity: 0.32
})
);
castEdges.rotation.copy(casting.rotation);
castEdges.position.copy(casting.position);
scene.add(castEdges);
// Reference envelope of the casting.
const referenceEnvelope = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(castingWidth, castingHeight, castingDepth)
),
new THREE.LineBasicMaterial({
color: 0xd27b41,
transparent: true,
opacity: 0.25,
depthWrite: false
})
);
referenceEnvelope.position.set(
-castingWidth / 2,
castingHeight / 2,
-castingDepth / 2
);
scene.add(referenceEnvelope);
/* ---------------------------------------------------------------
Shared insertion axis and aperture guide.
---------------------------------------------------------------- */
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(
-castingWidth / 2,
0.045,
-castingDepth / 2
),
new THREE.Vector3(
-castingWidth / 2,
0.73,
-castingDepth / 2
)
]);
const axisMaterial = new THREE.LineDashedMaterial({
color: 0x4b8a73,
dashSize: 0.018,
gapSize: 0.012,
transparent: true,
opacity: 0.72,
depthTest: false,
depthWrite: false
});
const axisLine = new THREE.Line(axisGeometry, axisMaterial);
axisLine.computeLineDistances();
axisLine.renderOrder = 8;
scene.add(axisLine);
const aperturePoints = [];
for (let i = 0; i < 72; i++) {
const angle = (i / 72) * Math.PI * 2;
aperturePoints.push(
new THREE.Vector3(
-castingWidth / 2 + Math.cos(angle) * apertureRadiusX,
castingHeight + 0.004,
-castingDepth / 2 + Math.sin(angle) * apertureRadiusZ
)
);
}
const apertureGuide = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(aperturePoints),
new THREE.LineBasicMaterial({
color: 0x4b8a73,
transparent: true,
opacity: 0.8,
depthTest: false,
depthWrite: false
})
);
apertureGuide.renderOrder = 8;
scene.add(apertureGuide);
/* ---------------------------------------------------------------
Matching lifting connection:
tapered pilot, shaft, collar, stem and lifting eye.
---------------------------------------------------------------- */
const connection = new THREE.Group();
connection.position.set(
-castingWidth / 2,
0.36,
-castingDepth / 2
);
scene.add(connection);
const pilot = new THREE.Mesh(
new THREE.CylinderGeometry(0.027, 0.021, 0.075, 48, 1, false),
pilotMaterial
);
pilot.scale.set(1.16, 1, 0.88);
pilot.castShadow = true;
connection.add(pilot);
const pilotBand = new THREE.Mesh(
new THREE.TorusGeometry(0.0265, 0.0032, 10, 48),
orangeMaterial
);
pilotBand.rotation.x = Math.PI / 2;
pilotBand.scale.set(1.16, 0.88, 1);
pilotBand.position.y = 0.034;
connection.add(pilotBand);
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.019, 0.019, 0.09, 40),
steelMaterial
);
shaft.position.y = 0.082;
shaft.castShadow = true;
connection.add(shaft);
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(0.044, 0.043, 0.04, 6),
collarMaterial
);
collar.scale.z = 0.86;
collar.position.y = 0.135;
collar.castShadow = true;
connection.add(collar);
const collarAccent = new THREE.Mesh(
new THREE.TorusGeometry(0.037, 0.004, 10, 48),
orangeMaterial
);
collarAccent.rotation.x = Math.PI / 2;
collarAccent.scale.y = 0.88;
collarAccent.position.y = 0.158;
connection.add(collarAccent);
const eyeStem = new THREE.Mesh(
new THREE.CylinderGeometry(0.015, 0.018, 0.085, 32),
steelMaterial
);
eyeStem.position.y = 0.196;
eyeStem.castShadow = true;
connection.add(eyeStem);
const eye = new THREE.Mesh(
new THREE.TorusGeometry(0.047, 0.011, 14, 56),
steelMaterial
);
eye.position.y = 0.265;
eye.castShadow = true;
connection.add(eye);
const eyeInset = new THREE.Mesh(
new THREE.TorusGeometry(0.047, 0.0065, 12, 56),
collarMaterial
);
eyeInset.position.y = 0.265;
eyeInset.scale.set(0.88, 0.88, 0.88);
connection.add(eyeInset);
/* ---------------------------------------------------------------
UI state and animation.
---------------------------------------------------------------- */
const mateRange = document.getElementById("mateRange");
const rangeValue = document.getElementById("rangeValue");
const mateButton = document.getElementById("mateButton");
const xrayButton = document.getElementById("xrayButton");
const resetButton = document.getElementById("resetButton");
const statusChip = document.getElementById("statusChip");
let targetMate = 0;
let currentMate = 0;
let autoMotion = false;
let autoDirection = 1;
let xrayEnabled = false;
function damp(current, target, lambda, dt) {
return THREE.MathUtils.lerp(
current,
target,
1 - Math.exp(-lambda * dt)
);
}
function smoothstep(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function updateButtonLabel() {
if (autoMotion) {
mateButton.textContent = "Pause motion";
} else if (targetMate > 0.5) {
mateButton.textContent = "Separate";
} else {
mateButton.textContent = "Seat connection";
}
}
mateButton.addEventListener("click", () => {
if (autoMotion) {
autoMotion = false;
} else {
if (currentMate > 0.94) {
targetMate = 0;
autoDirection = -1;
} else {
targetMate = 1;
autoDirection = 1;
}
autoMotion = true;
}
updateButtonLabel();
});
mateRange.addEventListener("input", () => {
autoMotion = false;
targetMate = Number(mateRange.value) / 100;
rangeValue.textContent = `${mateRange.value}%`;
updateButtonLabel();
});
xrayButton.addEventListener("click", () => {
xrayEnabled = !xrayEnabled;
xrayButton.classList.toggle("active", xrayEnabled);
xrayButton.setAttribute("aria-pressed", String(xrayEnabled));
xrayButton.textContent = xrayEnabled ? "Solid casting" : "X-ray casting";
});
resetButton.addEventListener("click", () => {
controls.reset();
});
canvas.addEventListener("dblclick", () => controls.reset());
/* ---------------------------------------------------------------
HTML labels projected from Three.js world positions.
---------------------------------------------------------------- */
const castingLabel = document.getElementById("castingLabel");
const connectionLabel = document.getElementById("connectionLabel");
const axisLabel = document.getElementById("axisLabel");
function projectLabel(element, worldPosition, offsetX = 0, offsetY = 0) {
const projected = worldPosition.clone().project(camera);
if (
projected.z < -1 ||
projected.z > 1 ||
projected.x < -1.2 ||
projected.x > 1.2 ||
projected.y < -1.2 ||
projected.y > 1.2
) {
element.style.visibility = "hidden";
return;
}
element.style.visibility = "visible";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth + offsetX}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight + offsetY}px`;
}
const castingAnchor = new THREE.Vector3(
-castingWidth - 0.015,
0.071,
-castingDepth
);
const connectionAnchor = new THREE.Vector3();
const axisAnchor = new THREE.Vector3(
-castingWidth / 2,
0.49,
-castingDepth / 2
);
function updateLabels() {
projectLabel(castingLabel, castingAnchor, -18, 25);
connectionAnchor.set(0.035, 0.265, 0);
connection.localToWorld(connectionAnchor);
projectLabel(connectionLabel, connectionAnchor, 17, -8);
projectLabel(axisLabel, axisAnchor, -10, -2);
}
/* ---------------------------------------------------------------
Main loop.
---------------------------------------------------------------- */
let previousTime = performance.now();
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
controls.update(dt);
if (autoMotion) {
targetMate += autoDirection * dt * 0.43;
if (targetMate >= 1) {
targetMate = 1;
autoDirection = -1;
} else if (targetMate <= 0) {
targetMate = 0;
autoDirection = 1;
}
mateRange.value = String(Math.round(targetMate * 100));
rangeValue.textContent = `${Math.round(targetMate * 100)}%`;
}
currentMate = damp(currentMate, targetMate, 7.5, dt);
const seating = smoothstep(currentMate);
// Exploded height to seated height. In the seated position, the
// tapered pilot enters the casting while its shoulder remains above.
connection.position.y = THREE.MathUtils.lerp(0.36, 0.112, seating);
const xrayAmount = damp(
xrayEnabled ? 1 : 0,
xrayEnabled ? 1 : 0,
8,
dt
);
castMaterial.opacity = THREE.MathUtils.lerp(1, 0.22, xrayAmount);
castMaterial.depthWrite = castMaterial.opacity > 0.82;
linerMaterial.opacity = THREE.MathUtils.lerp(1, 0.06, xrayAmount);
castEdges.material.opacity = THREE.MathUtils.lerp(0.32, 0.48, xrayAmount);
referenceEnvelope.material.opacity = THREE.MathUtils.lerp(0.25, 0.6, xrayAmount);
apertureGuide.material.opacity = THREE.MathUtils.lerp(0.8, 1, xrayAmount);
axisMaterial.opacity = THREE.MathUtils.lerp(0.72, 1, xrayAmount);
if (currentMate > 0.93) {
statusChip.textContent = xrayEnabled
? "Engagement visible / seated"
: "Seated / coaxial";
statusChip.classList.add("seated");
} else if (currentMate < 0.04) {
statusChip.textContent = xrayEnabled
? "X-ray / aligned"
: "Aligned / open";
statusChip.classList.remove("seated");
} else {
statusChip.textContent = xrayEnabled
? "X-ray / insertion"
: "Insertion travel";
statusChip.classList.remove("seated");
}
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
requestAnimationFrame(animate);
</script>
</body>
</html>
```