Prompt specification
Build or customize the Three.js 3D scene "Volcanic cone sectional specimen" 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: Volcanic cone sectional specimen
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/volcanic-cone-sectional-specimen-x1189
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: volcanic cone sectional specimen. Cut a cone-shaped volcano to reveal alternating deposit layers and a central conduit; keep the interior physically separated from a small removable surface sector. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (volcanic-cone-sectional-specimen-x1189):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Volcanic Cone — Sectional Specimen</title>
<style>
:root {
--ink: #292724;
--muted: #6e675f;
--paper: #eee8dc;
--accent: #b45738;
--line: rgba(58, 51, 45, 0.36);
}
* { 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;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.title-panel {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
pointer-events: none;
max-width: 360px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 2px;
background: currentColor;
}
h1 {
margin: 9px 0 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4.1vw, 58px);
line-height: 0.95;
font-weight: 500;
letter-spacing: -0.045em;
}
.subtitle {
margin: 12px 0 0;
max-width: 310px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.toolbar {
position: fixed;
top: 26px;
right: 28px;
z-index: 10;
display: flex;
gap: 8px;
}
button {
appearance: none;
border: 1px solid rgba(51, 45, 40, 0.22);
border-radius: 2px;
background: rgba(247, 243, 234, 0.8);
color: var(--ink);
padding: 10px 13px;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(10px);
transition:
background 160ms ease,
transform 160ms ease,
border-color 160ms ease;
}
button:hover {
background: rgba(255, 252, 245, 0.98);
border-color: rgba(51, 45, 40, 0.45);
transform: translateY(-1px);
}
button:active { transform: translateY(0); }
.spec-panel {
position: fixed;
left: 30px;
bottom: 28px;
z-index: 5;
pointer-events: none;
width: 265px;
}
.spec-label {
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 16px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 10px;
color: #514b45;
}
.swatch {
width: 14px;
height: 10px;
border: 1px solid rgba(35, 30, 26, 0.16);
transform: skewY(-8deg);
}
.controls-hint {
position: fixed;
right: 30px;
bottom: 29px;
z-index: 5;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.035em;
text-align: right;
pointer-events: none;
}
.controls-hint strong {
color: var(--ink);
font-weight: 750;
}
#leaders {
position: fixed;
inset: 0;
z-index: 4;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leaders line {
stroke: rgba(65, 57, 50, 0.48);
stroke-width: 1;
stroke-dasharray: 3 4;
}
#leaders circle {
fill: var(--paper);
stroke: var(--accent);
stroke-width: 1.5;
}
.annotation {
position: fixed;
z-index: 6;
transform: translate(-50%, -100%);
padding: 7px 9px 6px;
border-left: 2px solid var(--accent);
background: rgba(244, 239, 228, 0.9);
color: #443d37;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
line-height: 1.25;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(7px);
box-shadow: 0 4px 15px rgba(55, 45, 36, 0.07);
}
.annotation small {
display: block;
margin-top: 3px;
color: #847a70;
font-size: 7px;
font-weight: 650;
letter-spacing: 0.09em;
}
@media (max-width: 760px) {
.title-panel { top: 20px; left: 20px; }
.subtitle { display: none; }
.toolbar { top: 18px; right: 16px; }
.toolbar button { padding: 9px 10px; font-size: 8px; }
.spec-panel { left: 20px; bottom: 20px; width: 220px; }
.legend { gap: 6px 10px; }
.controls-hint { display: none; }
.annotation { font-size: 7px; }
}
@media (max-width: 480px) {
h1 { font-size: 30px; }
.spec-panel { display: none; }
.toolbar { top: auto; bottom: 16px; right: 16px; }
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="title-panel">
<div class="eyebrow">Volcanology / Sectional study</div>
<h1>Layered Cone</h1>
<p class="subtitle">
An exploded low-poly specimen exposing alternating volcanic deposits,
a central magma conduit, and a physically separated removable sector.
</p>
</header>
<nav class="toolbar" aria-label="Scene controls">
<button id="liftSector" type="button">Lift sector</button>
<button id="resetView" type="button">Reset view</button>
</nav>
<aside class="spec-panel">
<div class="spec-label">Deposit key / 260° interior + 100° sector</div>
<div class="legend">
<div class="legend-item"><i class="swatch" style="background:#d0ad78"></i>Ash fall</div>
<div class="legend-item"><i class="swatch" style="background:#a9573d"></i>Scoria</div>
<div class="legend-item"><i class="swatch" style="background:#57443e"></i>Lava-rich</div>
<div class="legend-item"><i class="swatch" style="background:#86634d"></i>Tephra</div>
</div>
</aside>
<svg id="leaders" aria-hidden="true">
<line id="strataLine"></line>
<line id="conduitLine"></line>
<line id="sectorLine"></line>
<circle id="strataDot" r="3"></circle>
<circle id="conduitDot" r="3"></circle>
<circle id="sectorDot" r="3"></circle>
</svg>
<div id="strataLabel" class="annotation">
Alternating strata
<small>Cut deposit surfaces</small>
</div>
<div id="conduitLabel" class="annotation">
Central conduit
<small>Sectioned magma path</small>
</div>
<div id="sectorLabel" class="annotation">
Removable sector
<small>Separated surface section</small>
</div>
<div class="controls-hint">
<strong>Drag</strong> orbit · <strong>Scroll / pinch</strong> zoom<br />
<strong>Arrow keys</strong> rotate
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee8dc);
scene.fog = new THREE.Fog(0xeee8dc, 25, 48);
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 cutaway model of a layered volcanic cone"
);
stage.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xfff6e4, 0x75695e, 2.15);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff7e8, 3.25);
keyLight.position.set(7, 12, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 32;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xcbd8df, 1.05);
fillLight.position.set(-8, 5, -7);
scene.add(fillLight);
const magmaLight = new THREE.PointLight(0xff5b1f, 16, 4.8, 2);
magmaLight.position.set(0, 1.25, 0.05);
scene.add(magmaLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe8e1d4,
roughness: 1,
flatShading: true
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.015;
ground.receiveShadow = true;
scene.add(ground);
const plinthMaterial = new THREE.MeshStandardMaterial({
color: 0xf2ecdf,
roughness: 0.93,
flatShading: true
});
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(7.25, 7.4, 0.18, 48),
plinthMaterial
);
plinth.position.set(1.2, 0.075, 0);
plinth.receiveShadow = true;
plinth.castShadow = true;
scene.add(plinth);
const plinthRing = new THREE.Mesh(
new THREE.RingGeometry(6.98, 7.015, 64),
new THREE.MeshBasicMaterial({
color: 0xb8aa96,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.55
})
);
plinthRing.rotation.x = -Math.PI / 2;
plinthRing.position.set(1.2, 0.171, 0);
scene.add(plinthRing);
const BASE_Y = 0.18;
const TOP_Y = 3.78;
const BASE_RADIUS = 3.35;
const TOP_RADIUS = 0.82;
const GAP_CENTER = THREE.MathUtils.degToRad(25);
const GAP_SIZE = THREE.MathUtils.degToRad(100);
const GAP_START = GAP_CENTER - GAP_SIZE / 2;
const GAP_END = GAP_CENTER + GAP_SIZE / 2;
const MAIN_START = GAP_END;
const MAIN_END = GAP_START + Math.PI * 2;
const profileRadius = (y) => {
const t = THREE.MathUtils.clamp(
(y - BASE_Y) / (TOP_Y - BASE_Y),
0,
1
);
return THREE.MathUtils.lerp(BASE_RADIUS, TOP_RADIUS, t);
};
const conduitOuterRadius = (y) => {
const t = THREE.MathUtils.clamp(
(y - BASE_Y) / (TOP_Y - BASE_Y),
0,
1
);
return THREE.MathUtils.lerp(0.42, 0.5, t);
};
const conduitInnerRadius = (y) => {
const t = THREE.MathUtils.clamp(
(y - BASE_Y) / (TOP_Y - BASE_Y),
0,
1
);
return THREE.MathUtils.lerp(0.2, 0.28, t);
};
const levels = [
0.18, 0.52, 0.86, 1.20, 1.54, 1.88,
2.22, 2.56, 2.90, 3.22, 3.54, 3.78
];
const layerPalette = [
{ cut: 0xd0ad78, outer: 0x6b5948 },
{ cut: 0xa9573d, outer: 0x50372f },
{ cut: 0x57443e, outer: 0x322a28 },
{ cut: 0x86634d, outer: 0x554238 },
{ cut: 0xd8b983, outer: 0x74604d },
{ cut: 0xa9573d, outer: 0x4b332c },
{ cut: 0x493d39, outer: 0x2c2928 },
{ cut: 0xb47c54, outer: 0x61483a },
{ cut: 0xa9573d, outer: 0x4c342d },
{ cut: 0x57443e, outer: 0x302927 },
{ cut: 0xc8a46f, outer: 0x685747 }
];
const standardMaterial = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.93,
metalness: 0,
flatShading: true,
...extra
});
const cutMaterials = layerPalette.map((entry) =>
standardMaterial(entry.cut)
);
const outerMaterials = layerPalette.map((entry) =>
standardMaterial(entry.outer)
);
const pipeOuterMaterial = standardMaterial(0x302b29);
const pipeInnerMaterial = standardMaterial(0x351713, {
emissive: 0x64180a,
emissiveIntensity: 0.28,
roughness: 0.82
});
const pipeCutMaterial = standardMaterial(0x75665b, {
emissive: 0x431108,
emissiveIntensity: 0.14
});
const lavaMaterial = standardMaterial(0xff5b1b, {
emissive: 0xff3308,
emissiveIntensity: 2.55,
roughness: 0.55
});
function polar(radius, y, angle) {
return new THREE.Vector3(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
);
}
function geometryFromTriangles(triangles) {
const positions = [];
for (const triangle of triangles) {
for (const vertex of triangle) {
positions.push(vertex.x, vertex.y, vertex.z);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
function outerSurfaceGeometry(
radiusBottom,
radiusTop,
yBottom,
yTop,
start,
end,
segments
) {
const triangles = [];
for (let i = 0; i < segments; i++) {
const a0 = THREE.MathUtils.lerp(start, end, i / segments);
const a1 = THREE.MathUtils.lerp(start, end, (i + 1) / segments);
const bottom0 = polar(radiusBottom, yBottom, a0);
const bottom1 = polar(radiusBottom, yBottom, a1);
const top0 = polar(radiusTop, yTop, a0);
const top1 = polar(radiusTop, yTop, a1);
triangles.push(
[bottom0, top0, top1],
[bottom0, top1, bottom1]
);
}
return geometryFromTriangles(triangles);
}
function innerSurfaceGeometry(
radiusBottom,
radiusTop,
yBottom,
yTop,
start,
end,
segments
) {
const triangles = [];
for (let i = 0; i < segments; i++) {
const a0 = THREE.MathUtils.lerp(start, end, i / segments);
const a1 = THREE.MathUtils.lerp(start, end, (i + 1) / segments);
const bottom0 = polar(radiusBottom, yBottom, a0);
const bottom1 = polar(radiusBottom, yBottom, a1);
const top0 = polar(radiusTop, yTop, a0);
const top1 = polar(radiusTop, yTop, a1);
triangles.push(
[bottom0, bottom1, top1],
[bottom0, top1, top0]
);
}
return geometryFromTriangles(triangles);
}
function annularSurfaceGeometry(
innerRadiusBottom,
innerRadiusTop,
outerRadiusBottom,
outerRadiusTop,
yBottom,
yTop,
start,
end,
segments,
topFace = false
) {
const triangles = [];
for (let i = 0; i < segments; i++) {
const a0 = THREE.MathUtils.lerp(start, end, i / segments);
const a1 = THREE.MathUtils.lerp(start, end, (i + 1) / segments);
const innerBottom0 = polar(innerRadiusBottom, yBottom, a0);
const innerBottom1 = polar(innerRadiusBottom, yBottom, a1);
const outerBottom0 = polar(outerRadiusBottom, yBottom, a0);
const outerBottom1 = polar(outerRadiusBottom, yBottom, a1);
const innerTop0 = polar(innerRadiusTop, yTop, a0);
const innerTop1 = polar(innerRadiusTop, yTop, a1);
const outerTop0 = polar(outerRadiusTop, yTop, a0);
const outerTop1 = polar(outerRadiusTop, yTop, a1);
if (topFace) {
triangles.push(
[innerTop0, innerTop1, outerTop1],
[innerTop0, outerTop1, outerTop0]
);
} else {
triangles.push(
[innerBottom0, outerBottom0, outerBottom1],
[innerBottom0, outerBottom1, innerBottom1]
);
}
}
return geometryFromTriangles(triangles);
}
function radialCutGeometry(
innerBottomRadius,
innerTopRadius,
outerBottomRadius,
outerTopRadius,
yBottom,
yTop,
start,
end
) {
const triangles = [];
const startInnerBottom = polar(innerBottomRadius, yBottom, start);
const startOuterBottom = polar(outerBottomRadius, yBottom, start);
const startInnerTop = polar(innerTopRadius, yTop, start);
const startOuterTop = polar(outerTopRadius, yTop, start);
triangles.push(
[startInnerBottom, startInnerTop, startOuterTop],
[startInnerBottom, startOuterTop, startOuterBottom]
);
const endInnerBottom = polar(innerBottomRadius, yBottom, end);
const endOuterBottom = polar(outerBottomRadius, yBottom, end);
const endInnerTop = polar(innerTopRadius, yTop, end);
const endOuterTop = polar(outerTopRadius, yTop, end);
triangles.push(
[endInnerBottom, endOuterBottom, endOuterTop],
[endInnerBottom, endOuterTop, endInnerTop]
);
return geometryFromTriangles(triangles);
}
function addMesh(group, geometry, material, castsShadow = true) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = castsShadow;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function createDepositLayer(index, yBottom, yTop, start, end, segments) {
const group = new THREE.Group();
const outerBottom = profileRadius(yBottom);
const outerTop = profileRadius(yTop);
const innerBottom = conduitOuterRadius(yBottom);
const innerTop = conduitOuterRadius(yTop);
addMesh(
group,
outerSurfaceGeometry(
outerBottom,
outerTop,
yBottom,
yTop,
start,
end,
segments
),
outerMaterials[index]
);
addMesh(
group,
annularSurfaceGeometry(
innerBottom,
innerTop,
outerBottom,
outerTop,
yBottom,
yTop,
start,
end,
segments,
true
),
cutMaterials[index]
);
addMesh(
group,
annularSurfaceGeometry(
innerBottom,
innerTop,
outerBottom,
outerTop,
yBottom,
yTop,
start,
end,
segments,
false
),
cutMaterials[index]
);
addMesh(
group,
radialCutGeometry(
innerBottom,
innerTop,
outerBottom,
outerTop,
yBottom,
yTop,
start,
end
),
cutMaterials[index]
);
return group;
}
function createConduitSegment(start, end, segments) {
const group = new THREE.Group();
const outerBottom = conduitOuterRadius(BASE_Y);
const outerTop = conduitOuterRadius(TOP_Y);
const innerBottom = conduitInnerRadius(BASE_Y);
const innerTop = conduitInnerRadius(TOP_Y);
addMesh(
group,
outerSurfaceGeometry(
outerBottom,
outerTop,
BASE_Y,
TOP_Y,
start,
end,
segments
),
pipeOuterMaterial
);
addMesh(
group,
innerSurfaceGeometry(
innerBottom,
innerTop,
BASE_Y,
TOP_Y,
start,
end,
segments
),
pipeInnerMaterial
);
addMesh(
group,
annularSurfaceGeometry(
innerBottom,
innerTop,
outerBottom,
outerTop,
BASE_Y,
TOP_Y,
start,
end,
segments,
true
),
pipeCutMaterial
);
addMesh(
group,
annularSurfaceGeometry(
innerBottom,
innerTop,
outerBottom,
outerTop,
BASE_Y,
TOP_Y,
start,
end,
segments,
false
),
pipeCutMaterial
);
addMesh(
group,
radialCutGeometry(
innerBottom,
innerTop,
outerBottom,
outerTop,
BASE_Y,
TOP_Y,
start,
end
),
pipeCutMaterial
);
return group;
}
function createLavaSector(start, end, segments) {
const triangles = [];
const radiusBottom = 0.18;
const radiusTop = 0.255;
for (let i = 0; i < segments; i++) {
const a0 = THREE.MathUtils.lerp(start, end, i / segments);
const a1 = THREE.MathUtils.lerp(start, end, (i + 1) / segments);
const bottom0 = polar(radiusBottom, BASE_Y, a0);
const bottom1 = polar(radiusBottom, BASE_Y, a1);
const top0 = polar(radiusTop, TOP_Y, a0);
const top1 = polar(radiusTop, TOP_Y, a1);
triangles.push(
[bottom0, top0, top1],
[bottom0, top1, bottom1]
);
const centerBottom = new THREE.Vector3(0, BASE_Y, 0);
const centerTop = new THREE.Vector3(0, TOP_Y, 0);
triangles.push(
[centerTop, top1, top0],
[centerBottom, bottom0, bottom1]
);
}
const startBottomAxis = new THREE.Vector3(0, BASE_Y, 0);
const startTopAxis = new THREE.Vector3(0, TOP_Y, 0);
const startBottom = polar(radiusBottom, BASE_Y, start);
const startTop = polar(radiusTop, TOP_Y, start);
triangles.push(
[startBottomAxis, startTopAxis, startTop],
[startBottomAxis, startTop, startBottom]
);
const endBottomAxis = new THREE.Vector3(0, BASE_Y, 0);
const endTopAxis = new THREE.Vector3(0, TOP_Y, 0);
const endBottom = polar(radiusBottom, BASE_Y, end);
const endTop = polar(radiusTop, TOP_Y, end);
triangles.push(
[endBottomAxis, endBottom, endTop],
[endBottomAxis, endTop, endTopAxis]
);
const geometry = geometryFromTriangles(triangles);
const mesh = new THREE.Mesh(geometry, lavaMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
const mainSpecimen = new THREE.Group();
scene.add(mainSpecimen);
const mainSegments = 38;
for (let i = 0; i < levels.length - 1; i++) {
mainSpecimen.add(
createDepositLayer(
i,
levels[i],
levels[i + 1],
MAIN_START,
MAIN_END,
mainSegments
)
);
}
mainSpecimen.add(
createConduitSegment(MAIN_START, MAIN_END, mainSegments)
);
mainSpecimen.add(
createLavaSector(MAIN_START, MAIN_END, mainSegments)
);
const craterGlow = new THREE.Mesh(
new THREE.OctahedronGeometry(0.205, 0),
lavaMaterial
);
craterGlow.position.set(0, TOP_Y - 0.01, 0);
craterGlow.rotation.set(0.2, 0.4, 0.15);
mainSpecimen.add(craterGlow);
const removableSector = new THREE.Group();
removableSector.position.set(5.15, 0, -0.75);
removableSector.rotation.y = -0.18;
scene.add(removableSector);
const sectorSegments = 15;
for (let i = 0; i < levels.length - 1; i++) {
removableSector.add(
createDepositLayer(
i,
levels[i],
levels[i + 1],
GAP_START,
GAP_END,
sectorSegments
)
);
}
removableSector.add(
createConduitSegment(GAP_START, GAP_END, sectorSegments)
);
// Dashed footprint showing the sector's original position.
const ghostPoints = [];
const ghostRadius = BASE_RADIUS + 0.035;
for (let i = 0; i < 28; i++) {
const a = THREE.MathUtils.lerp(GAP_START, GAP_END, i / 28);
const b = THREE.MathUtils.lerp(GAP_START, GAP_END, (i + 1) / 28);
ghostPoints.push(
polar(ghostRadius, BASE_Y + 0.012, a),
polar(ghostRadius, BASE_Y + 0.012, b)
);
}
ghostPoints.push(
new THREE.Vector3(0, BASE_Y + 0.012, 0),
polar(ghostRadius, BASE_Y + 0.012, GAP_START),
new THREE.Vector3(0, BASE_Y + 0.012, 0),
polar(ghostRadius, BASE_Y + 0.012, GAP_END)
);
const ghostGeometry = new THREE.BufferGeometry().setFromPoints(ghostPoints);
const ghostLine = new THREE.LineSegments(
ghostGeometry,
new THREE.LineDashedMaterial({
color: 0xb35c3d,
dashSize: 0.12,
gapSize: 0.08,
transparent: true,
opacity: 0.42
})
);
ghostLine.computeLineDistances();
scene.add(ghostLine);
// Custom orbit controls, implemented without external addons.
const controls = {
target: new THREE.Vector3(1.0, 1.4, 0),
azimuth: 0.66,
elevation: 0.46,
distance: 15.6,
desiredAzimuth: 0.66,
desiredElevation: 0.46,
desiredDistance: 15.6
};
function updateCamera() {
const horizontal = Math.cos(controls.elevation) * controls.distance;
camera.position.set(
controls.target.x + Math.sin(controls.azimuth) * horizontal,
controls.target.y + Math.sin(controls.elevation) * controls.distance,
controls.target.z + Math.cos(controls.azimuth) * horizontal
);
camera.lookAt(controls.target);
}
updateCamera();
const pointers = new Map();
let lastPointer = { x: 0, y: 0 };
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
lastPointer = { x: event.clientX, y: event.clientY };
if (pointers.size === 2) {
const values = [...pointers.values()];
pinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (pinchDistance > 0 && distance > 0) {
controls.desiredDistance = THREE.MathUtils.clamp(
controls.desiredDistance * (pinchDistance / distance),
8.5,
25
);
}
pinchDistance = distance;
} else {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
controls.desiredAzimuth -= dx * 0.006;
controls.desiredElevation = THREE.MathUtils.clamp(
controls.desiredElevation + dy * 0.005,
0.12,
1.25
);
}
lastPointer = { x: event.clientX, y: event.clientY };
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.desiredDistance = THREE.MathUtils.clamp(
controls.desiredDistance * Math.exp(event.deltaY * 0.001),
8.5,
25
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const step = 0.09;
if (event.key === "ArrowLeft") controls.desiredAzimuth += step;
if (event.key === "ArrowRight") controls.desiredAzimuth -= step;
if (event.key === "ArrowUp") {
controls.desiredElevation = THREE.MathUtils.clamp(
controls.desiredElevation + step * 0.6,
0.12,
1.25
);
}
if (event.key === "ArrowDown") {
controls.desiredElevation = THREE.MathUtils.clamp(
controls.desiredElevation - step * 0.6,
0.12,
1.25
);
}
if (event.key === "+" || event.key === "=") {
controls.desiredDistance = Math.max(8.5, controls.desiredDistance - 0.7);
}
if (event.key === "-") {
controls.desiredDistance = Math.min(25, controls.desiredDistance + 0.7);
}
});
document.getElementById("resetView").addEventListener("click", () => {
controls.desiredAzimuth = 0.66;
controls.desiredElevation = 0.46;
controls.desiredDistance = 15.6;
});
const liftButton = document.getElementById("liftSector");
let sectorLifted = false;
const sectorTargetPosition = new THREE.Vector3();
let sectorTargetRotation = removableSector.rotation.y;
liftButton.addEventListener("click", () => {
sectorLifted = !sectorLifted;
sectorTargetPosition.set(
sectorLifted ? 5.65 : 5.15,
sectorLifted ? 0.72 : 0,
sectorLifted ? -0.95 : -0.75
);
sectorTargetRotation = sectorLifted ? 0.08 : -0.18;
liftButton.textContent = sectorLifted ? "Lower sector" : "Lift sector";
});
sectorTargetPosition.copy(removableSector.position);
// Screen-space annotation system.
const annotationData = [
{
anchor: polar(1.65, 1.72, GAP_END),
label: document.getElementById("strataLabel"),
line: document.getElementById("strataLine"),
dot: document.getElementById("strataDot"),
offset: new THREE.Vector2(-58, -20)
},
{
anchor: new THREE.Vector3(0, 1.38, 0.12),
label: document.getElementById("conduitLabel"),
line: document.getElementById("conduitLine"),
dot: document.getElementById("conduitDot"),
offset: new THREE.Vector2(76, 9)
},
{
anchor: polar(2.4, 1.9, GAP_CENTER),
localToSector: true,
label: document.getElementById("sectorLabel"),
line: document.getElementById("sectorLine"),
dot: document.getElementById("sectorDot"),
offset: new THREE.Vector2(30, -14)
}
];
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const item of annotationData) {
const world = item.localToSector
? removableSector.localToWorld(item.anchor.clone())
: item.anchor.clone();
const projected = world.project(camera);
const visible = projected.z > -1 && projected.z < 1;
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const labelX = anchorX + item.offset.x;
const labelY = anchorY + item.offset.y;
item.label.style.left = `${labelX}px`;
item.label.style.top = `${labelY}px`;
item.label.style.opacity = visible ? "1" : "0";
item.line.setAttribute("x1", anchorX);
item.line.setAttribute("y1", anchorY);
item.line.setAttribute("x2", labelX);
item.line.setAttribute("y2", labelY);
item.line.style.opacity = visible ? "1" : "0";
item.dot.setAttribute("cx", anchorX);
item.dot.setAttribute("cy", anchorY);
item.dot.style.opacity = visible ? "1" : "0";
}
}
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();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.exp(-dt * 9);
controls.azimuth = THREE.MathUtils.lerp(
controls.azimuth,
controls.desiredAzimuth,
damping
);
controls.elevation = THREE.MathUtils.lerp(
controls.elevation,
controls.desiredElevation,
damping
);
controls.distance = THREE.MathUtils.lerp(
controls.distance,
controls.desiredDistance,
damping
);
removableSector.position.lerp(sectorTargetPosition, damping);
removableSector.rotation.y = THREE.MathUtils.lerp(
removableSector.rotation.y,
sectorTargetRotation,
damping
);
updateCamera();
scene.updateMatrixWorld();
renderer.render(scene, camera);
updateAnnotations();
});
</script>
</body>
</html>
```