Prompt specification
Build or customize the Three.js 3D scene "Telescope Horizon Ring and Target Direction" 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: Telescope Horizon Ring and Target Direction
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/telescope-horizon-ring-and-target-direction-x3793
Scene Description Prompt:
Model a simple telescope on a base with a horizon ring and target arrow. Show altitude and azimuth geometrically without claiming real-time sky coordinates. Build this with Three.js from cdnjs as a stylized scene in one self-contained HTML file.
Working Three.js Starter (telescope-horizon-ring-and-target-direction-x3793):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stylized Telescope Geometry</title>
<style>
:root {
--cyan: #67e8d5;
--gold: #ffb765;
--ink: #07111f;
--muted: #91a7b8;
--panel: rgba(8, 21, 35, 0.76);
--line: rgba(151, 225, 224, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 72% 20%, rgba(48, 94, 122, 0.3), transparent 34%),
radial-gradient(circle at 18% 82%, rgba(35, 104, 99, 0.18), transparent 32%),
linear-gradient(145deg, #091827 0%, #050c16 58%, #07111f 100%);
color: #e8f5f5;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(0, 0, 0, 0.28),
inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-panel {
top: 22px;
left: 22px;
width: 286px;
padding: 18px 20px;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 7px;
font-size: 25px;
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.readout-panel {
top: 22px;
right: 22px;
display: grid;
grid-template-columns: 1fr 1fr;
min-width: 294px;
overflow: hidden;
}
.readout {
padding: 15px 18px;
}
.readout + .readout {
border-left: 1px solid var(--line);
}
.readout-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.readout-value {
margin-top: 3px;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 25px;
font-weight: 700;
}
.readout.altitude .readout-value {
color: var(--cyan);
}
.readout.azimuth .readout-value {
color: var(--gold);
}
.controls-panel {
bottom: 22px;
left: 22px;
width: 294px;
padding: 17px 18px 16px;
}
.control-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15px;
}
.control-head strong {
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.control-head span {
color: var(--muted);
font-size: 10px;
}
.control {
margin-top: 13px;
}
.control label {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: #c8d8df;
font-size: 11px;
}
.control output {
color: var(--cyan);
font-family: "SFMono-Regular", Consolas, monospace;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 999px;
appearance: none;
-webkit-appearance: none;
background: linear-gradient(90deg, rgba(103, 232, 213, 0.75), rgba(255, 183, 101, 0.6));
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid #0b1b2a;
border-radius: 50%;
appearance: none;
-webkit-appearance: none;
background: #dffff8;
box-shadow: 0 0 0 1px rgba(103, 232, 213, 0.75), 0 0 16px rgba(103, 232, 213, 0.4);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #0b1b2a;
border-radius: 50%;
background: #dffff8;
box-shadow: 0 0 0 1px rgba(103, 232, 213, 0.75), 0 0 16px rgba(103, 232, 213, 0.4);
}
.note-panel {
right: 22px;
bottom: 22px;
width: 292px;
padding: 14px 16px;
}
.note-title {
display: flex;
align-items: center;
gap: 8px;
color: var(--gold);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.note-title::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 12px rgba(255, 183, 101, 0.75);
content: "";
}
.note-panel p {
margin: 8px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.legend {
position: fixed;
left: 50%;
bottom: 24px;
z-index: 9;
display: flex;
gap: 17px;
transform: translateX(-50%);
color: #9db1be;
font-size: 10px;
pointer-events: none;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.dot {
width: 7px;
height: 7px;
border-radius: 50%;
}
.dot.cyan {
background: var(--cyan);
box-shadow: 0 0 9px rgba(103, 232, 213, 0.7);
}
.dot.gold {
background: var(--gold);
box-shadow: 0 0 9px rgba(255, 183, 101, 0.7);
}
.hint {
color: rgba(204, 221, 226, 0.55);
font-size: 9px;
}
@media (max-width: 760px) {
.title-panel {
top: 12px;
left: 12px;
width: 220px;
padding: 14px;
}
h1 {
font-size: 20px;
}
.readout-panel {
top: 12px;
right: 12px;
min-width: 190px;
}
.readout {
padding: 11px;
}
.readout-value {
font-size: 19px;
}
.controls-panel {
bottom: 12px;
left: 12px;
width: 225px;
}
.note-panel {
display: none;
}
.legend {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive stylized telescope geometry scene"></canvas>
<section class="panel title-panel">
<div class="eyebrow">Geometric Instrument Study</div>
<h1>Vector Telescope</h1>
<p class="subtitle">
A stylized model showing altitude, azimuth, and a directional target vector.
</p>
</section>
<section class="panel readout-panel" aria-live="polite">
<div class="readout altitude">
<div class="readout-label">Geometric Altitude</div>
<div class="readout-value" id="altitudeValue">34°</div>
</div>
<div class="readout azimuth">
<div class="readout-label">Geometric Azimuth</div>
<div class="readout-value" id="azimuthValue">52°</div>
</div>
</section>
<section class="panel controls-panel">
<div class="control-head">
<strong>Model Angles</strong>
<span>Drag scene to orbit</span>
</div>
<div class="control">
<label for="altitude">
Altitude
<output id="altitudeOutput">34°</output>
</label>
<input id="altitude" type="range" min="5" max="85" value="34" step="1" />
</div>
<div class="control">
<label for="azimuth">
Azimuth
<output id="azimuthOutput">52°</output>
</label>
<input id="azimuth" type="range" min="0" max="360" value="52" step="1" />
</div>
</section>
<section class="panel note-panel">
<div class="note-title">Illustrative geometry only</div>
<p>
These values describe this virtual instrument. They are not live sky coordinates,
celestial navigation data, or an observation pointing solution.
</p>
</section>
<div class="legend" aria-hidden="true">
<span><i class="dot cyan"></i>Altitude arc</span>
<span><i class="dot gold"></i>Azimuth sweep</span>
<span class="hint">Scroll to zoom</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x07111f, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07111f, 0.025);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
azimuth: 0.72,
elevation: 0.43,
distance: 10.2,
targetAzimuth: 0.72,
targetElevation: 0.43,
targetDistance: 10.2
};
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
function updateCamera() {
cameraState.azimuth +=
(cameraState.targetAzimuth - cameraState.azimuth) * 0.09;
cameraState.elevation +=
(cameraState.targetElevation - cameraState.elevation) * 0.09;
cameraState.distance +=
(cameraState.targetDistance - cameraState.distance) * 0.09;
const horizontal = Math.cos(cameraState.elevation) * cameraState.distance;
camera.position.set(
cameraTarget.x + Math.sin(cameraState.azimuth) * horizontal,
cameraTarget.y + Math.sin(cameraState.elevation) * cameraState.distance,
cameraTarget.z + Math.cos(cameraState.azimuth) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xa7e9ff, 0x07111f, 1.9);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe0b7, 3.2);
keyLight.position.set(5, 8, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0002;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x56e7dc, 2.1);
rimLight.position.set(-5, 4, -6);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffa85d, 16, 8, 2);
warmFill.position.set(2.4, 2.4, -2.5);
scene.add(warmFill);
// -------------------------------------------------------------------------
// Shared materials
// -------------------------------------------------------------------------
const material = {
platform: new THREE.MeshStandardMaterial({
color: 0x0b1b2a,
roughness: 0.82,
metalness: 0.18
}),
platformEdge: new THREE.MeshStandardMaterial({
color: 0x172f40,
roughness: 0.6,
metalness: 0.4
}),
darkMetal: new THREE.MeshStandardMaterial({
color: 0x182b39,
roughness: 0.34,
metalness: 0.72
}),
tube: new THREE.MeshStandardMaterial({
color: 0xe6e4d8,
roughness: 0.34,
metalness: 0.18
}),
tubeShade: new THREE.MeshStandardMaterial({
color: 0x9aaeb3,
roughness: 0.4,
metalness: 0.45
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x67e8d5,
emissive: 0x16796f,
emissiveIntensity: 0.7,
roughness: 0.3,
metalness: 0.35
}),
gold: new THREE.MeshStandardMaterial({
color: 0xffb765,
emissive: 0xa45116,
emissiveIntensity: 0.72,
roughness: 0.32,
metalness: 0.35
}),
lens: new THREE.MeshPhysicalMaterial({
color: 0x65d7e6,
emissive: 0x125466,
emissiveIntensity: 0.8,
transparent: true,
opacity: 0.86,
roughness: 0.12,
metalness: 0.05,
clearcoat: 1,
clearcoatRoughness: 0.1,
side: THREE.DoubleSide
})
};
// -------------------------------------------------------------------------
// Label helper using an in-memory canvas
// -------------------------------------------------------------------------
function makeLabel(text, color = "#67e8d5", width = 1.2) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 512, 128);
const radius = 22;
const x = 8;
const y = 14;
const w = 496;
const h = 100;
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + w - radius, y);
context.quadraticCurveTo(x + w, y, x + w, y + radius);
context.lineTo(x + w, y + h - radius);
context.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);
context.lineTo(x + radius, y + h);
context.quadraticCurveTo(x, y + h, x, y + h - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
context.fillStyle = "rgba(7, 17, 31, 0.86)";
context.fill();
context.strokeStyle = color;
context.globalAlpha = 0.7;
context.lineWidth = 3;
context.stroke();
context.globalAlpha = 1;
context.fillStyle = color;
context.font = "700 48px ui-monospace, SFMono-Regular, Consolas, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 64);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
})
);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 10;
return sprite;
}
// -------------------------------------------------------------------------
// Platform and horizon ring
// -------------------------------------------------------------------------
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(3.42, 3.56, 0.18, 96),
material.platform
);
platform.position.y = -0.1;
platform.receiveShadow = true;
scene.add(platform);
const platformTop = new THREE.Mesh(
new THREE.CircleGeometry(3.39, 96),
new THREE.MeshStandardMaterial({
color: 0x0a1826,
roughness: 0.9,
metalness: 0.08,
side: THREE.DoubleSide
})
);
platformTop.rotation.x = -Math.PI / 2;
platformTop.position.y = -0.005;
platformTop.receiveShadow = true;
scene.add(platformTop);
const horizonRing = new THREE.Mesh(
new THREE.TorusGeometry(3.18, 0.027, 10, 160),
material.cyan
);
horizonRing.rotation.x = Math.PI / 2;
horizonRing.position.y = 0.055;
scene.add(horizonRing);
const innerRing = new THREE.Mesh(
new THREE.TorusGeometry(2.52, 0.012, 8, 128),
new THREE.MeshBasicMaterial({
color: 0x4ab8b4,
transparent: true,
opacity: 0.35
})
);
innerRing.rotation.x = Math.PI / 2;
innerRing.position.y = 0.052;
scene.add(innerRing);
const tickMaterial = new THREE.MeshBasicMaterial({
color: 0x72c7c6,
transparent: true,
opacity: 0.55
});
for (let index = 0; index < 72; index++) {
const angle = (index / 72) * Math.PI * 2;
const major = index % 6 === 0;
const length = major ? 0.24 : 0.105;
const tick = new THREE.Mesh(
new THREE.BoxGeometry(major ? 0.043 : 0.022, 0.025, length),
tickMaterial
);
tick.position.set(
Math.sin(angle) * 3.03,
0.055,
Math.cos(angle) * 3.03
);
tick.rotation.y = angle;
scene.add(tick);
}
const cardinals = [
["N", 0],
["E", Math.PI / 2],
["S", Math.PI],
["W", (3 * Math.PI) / 2]
];
for (const [text, angle] of cardinals) {
const label = makeLabel(text, text === "N" ? "#ffb765" : "#a7c6cb", 0.46);
label.position.set(
Math.sin(angle) * 3.56,
0.21,
Math.cos(angle) * 3.56
);
scene.add(label);
}
// -------------------------------------------------------------------------
// Telescope pedestal
// -------------------------------------------------------------------------
const pedestal = new THREE.Group();
scene.add(pedestal);
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.9, 1.02, 0.2, 64),
material.darkMetal
);
foot.position.y = 0.1;
foot.castShadow = true;
foot.receiveShadow = true;
pedestal.add(foot);
const footTrim = new THREE.Mesh(
new THREE.TorusGeometry(0.88, 0.035, 10, 72),
material.cyan
);
footTrim.rotation.x = Math.PI / 2;
footTrim.position.y = 0.205;
pedestal.add(footTrim);
const column = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.49, 0.79, 48),
material.tubeShade
);
column.position.y = 0.58;
column.castShadow = true;
pedestal.add(column);
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(0.47, 0.47, 0.13, 48),
material.darkMetal
);
collar.position.y = 0.94;
collar.castShadow = true;
pedestal.add(collar);
const collarRing = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.026, 10, 64),
material.gold
);
collarRing.rotation.x = Math.PI / 2;
collarRing.position.y = 1.01;
pedestal.add(collarRing);
// -------------------------------------------------------------------------
// Azimuth and elevation assembly
// -------------------------------------------------------------------------
const pivot = new THREE.Vector3(0, 1.16, 0);
const forward = new THREE.Vector3(0, 0, 1);
const azimuthGroup = new THREE.Group();
azimuthGroup.position.copy(pivot);
scene.add(azimuthGroup);
const rotatingHub = new THREE.Mesh(
new THREE.CylinderGeometry(0.35, 0.39, 0.27, 48),
material.darkMetal
);
rotatingHub.position.y = -0.18;
rotatingHub.castShadow = true;
azimuthGroup.add(rotatingHub);
for (const side of [-1, 1]) {
const yoke = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.67, 0.23),
material.tubeShade
);
yoke.position.set(side * 0.49, -0.31, 0);
yoke.castShadow = true;
azimuthGroup.add(yoke);
const yokeCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.105, 0.17, 32),
material.darkMetal
);
yokeCap.rotation.z = Math.PI / 2;
yokeCap.position.set(side * 0.51, 0, 0);
azimuthGroup.add(yokeCap);
}
const elevationAxle = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.065, 1.08, 32),
material.gold
);
elevationAxle.rotation.z = Math.PI / 2;
elevationAxle.castShadow = true;
azimuthGroup.add(elevationAxle);
const elevationGroup = new THREE.Group();
azimuthGroup.add(elevationGroup);
const tube = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.31, 1.45, 48),
material.tube
);
tube.rotation.x = Math.PI / 2;
tube.position.z = 0.38;
tube.castShadow = true;
tube.receiveShadow = true;
elevationGroup.add(tube);
for (const z of [-0.22, 0.95]) {
const tubeBand = new THREE.Mesh(
new THREE.TorusGeometry(0.292, 0.032, 10, 48),
material.darkMetal
);
tubeBand.position.z = z;
elevationGroup.add(tubeBand);
}
const frontRing = new THREE.Mesh(
new THREE.CylinderGeometry(0.305, 0.28, 0.13, 48),
material.darkMetal
);
frontRing.rotation.x = Math.PI / 2;
frontRing.position.z = 1.13;
frontRing.castShadow = true;
elevationGroup.add(frontRing);
const lens = new THREE.Mesh(
new THREE.CircleGeometry(0.245, 48),
material.lens
);
lens.position.z = 1.199;
elevationGroup.add(lens);
const lensRim = new THREE.Mesh(
new THREE.TorusGeometry(0.255, 0.018, 8, 48),
material.cyan
);
lensRim.position.z = 1.203;
elevationGroup.add(lensRim);
const eyepiece = new THREE.Mesh(
new THREE.CylinderGeometry(0.115, 0.15, 0.38, 36),
material.darkMetal
);
eyepiece.rotation.x = Math.PI / 2;
eyepiece.position.z = -0.5;
eyepiece.castShadow = true;
elevationGroup.add(eyepiece);
const eyecup = new THREE.Mesh(
new THREE.CylinderGeometry(0.145, 0.12, 0.12, 36),
material.gold
);
eyecup.rotation.x = Math.PI / 2;
eyecup.position.z = -0.72;
elevationGroup.add(eyecup);
const finder = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.085, 0.57, 28),
material.tubeShade
);
finder.rotation.x = Math.PI / 2;
finder.position.set(0.17, 0.31, 0.37);
finder.castShadow = true;
elevationGroup.add(finder);
const finderLens = new THREE.Mesh(
new THREE.CircleGeometry(0.059, 24),
material.lens
);
finderLens.position.set(0.17, 0.31, 0.658);
elevationGroup.add(finderLens);
const focusKnob = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.1, 24),
material.gold
);
focusKnob.rotation.z = Math.PI / 2;
focusKnob.position.set(0.32, -0.13, 0.02);
elevationGroup.add(focusKnob);
// -------------------------------------------------------------------------
// Target arrow
// -------------------------------------------------------------------------
const targetArrow = new THREE.Group();
targetArrow.position.copy(pivot);
scene.add(targetArrow);
const arrowMaterial = material.gold.clone();
const arrowShaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.024, 0.024, 0.95, 16),
arrowMaterial
);
arrowShaft.rotation.x = Math.PI / 2;
arrowShaft.position.z = 2.15;
targetArrow.add(arrowShaft);
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.34, 20),
arrowMaterial
);
arrowHead.rotation.x = Math.PI / 2;
arrowHead.position.z = 2.74;
targetArrow.add(arrowHead);
const arrowTail = new THREE.Mesh(
new THREE.ConeGeometry(0.09, 0.26, 18),
arrowMaterial
);
arrowTail.rotation.x = -Math.PI / 2;
arrowTail.position.z = 1.53;
targetArrow.add(arrowTail);
for (const side of [-1, 1]) {
const fin = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 0.18, 0.28),
arrowMaterial
);
fin.position.set(side * 0.09, 0, 1.57);
fin.rotation.z = side * 0.2;
targetArrow.add(fin);
}
// -------------------------------------------------------------------------
// Geometric overlays
// -------------------------------------------------------------------------
const dashedCyan = new THREE.LineDashedMaterial({
color: 0x67e8d5,
dashSize: 0.09,
gapSize: 0.055,
transparent: true,
opacity: 0.82
});
const dashedGold = new THREE.LineDashedMaterial({
color: 0xffb765,
dashSize: 0.1,
gapSize: 0.055,
transparent: true,
opacity: 0.78
});
const dimCyan = new THREE.LineDashedMaterial({
color: 0x67e8d5,
dashSize: 0.055,
gapSize: 0.08,
transparent: true,
opacity: 0.34
});
const altitudeArc = new THREE.Line(
new THREE.BufferGeometry(),
dashedCyan
);
scene.add(altitudeArc);
const altitudeBaseline = new THREE.Line(
new THREE.BufferGeometry(),
dimCyan
);
scene.add(altitudeBaseline);
const targetRay = new THREE.Line(
new THREE.BufferGeometry(),
dashedGold
);
scene.add(targetRay);
const azimuthArc = new THREE.Line(
new THREE.BufferGeometry(),
dashedGold
);
scene.add(azimuthArc);
const azimuthRadius = new THREE.Line(
new THREE.BufferGeometry(),
dashedGold
);
scene.add(azimuthRadius);
const verticalAxis = new THREE.Line(
new THREE.BufferGeometry(),
dimCyan
);
verticalAxis.geometry.setFromPoints([
new THREE.Vector3(0, 0.06, 0),
pivot.clone()
]);
verticalAxis.computeLineDistances();
scene.add(verticalAxis);
const azimuthSector = new THREE.Mesh(
new THREE.BufferGeometry(),
new THREE.MeshBasicMaterial({
color: 0xffb765,
transparent: true,
opacity: 0.055,
depthWrite: false,
side: THREE.DoubleSide
})
);
scene.add(azimuthSector);
const altitudeLabel = makeLabel("ALTITUDE", "#67e8d5", 1.12);
scene.add(altitudeLabel);
const azimuthLabel = makeLabel("AZIMUTH", "#ffb765", 1.12);
scene.add(azimuthLabel);
// -------------------------------------------------------------------------
// Geometry updates
// -------------------------------------------------------------------------
const altitudeInput = document.querySelector("#altitude");
const azimuthInput = document.querySelector("#azimuth");
const altitudeValue = document.querySelector("#altitudeValue");
const azimuthValue = document.querySelector("#azimuthValue");
const altitudeOutput = document.querySelector("#altitudeOutput");
const azimuthOutput = document.querySelector("#azimuthOutput");
function replaceLinePoints(line, points) {
line.geometry.dispose();
line.geometry = new THREE.BufferGeometry().setFromPoints(points);
line.computeLineDistances();
}
function updateGeometry() {
const altitudeDegrees = Number(altitudeInput.value);
const azimuthDegrees = Number(azimuthInput.value);
const altitude = THREE.MathUtils.degToRad(altitudeDegrees);
const azimuth = THREE.MathUtils.degToRad(azimuthDegrees);
altitudeValue.textContent = `${altitudeDegrees}°`;
azimuthValue.textContent = `${azimuthDegrees}°`;
altitudeOutput.textContent = `${altitudeDegrees}°`;
azimuthOutput.textContent = `${azimuthDegrees}°`;
// Rotate the mount and telescope.
azimuthGroup.rotation.y = azimuth;
elevationGroup.rotation.x = -altitude;
const horizontalDirection = new THREE.Vector3(
Math.sin(azimuth),
0,
Math.cos(azimuth)
);
const targetDirection = new THREE.Vector3(
Math.sin(azimuth) * Math.cos(altitude),
Math.sin(altitude),
Math.cos(azimuth) * Math.cos(altitude)
).normalize();
targetArrow.quaternion.setFromUnitVectors(forward, targetDirection);
// Altitude arc: a circle in the current vertical aiming plane.
const altitudeRadius = 1.72;
const altitudePoints = [];
for (let index = 0; index <= 48; index++) {
const theta = altitude * (index / 48);
altitudePoints.push(
new THREE.Vector3(
pivot.x + horizontalDirection.x * Math.cos(theta) * altitudeRadius,
pivot.y + Math.sin(theta) * altitudeRadius,
pivot.z + horizontalDirection.z * Math.cos(theta) * altitudeRadius
)
);
}
replaceLinePoints(altitudeArc, altitudePoints);
replaceLinePoints(
altitudeBaseline,
[
pivot.clone(),
pivot.clone().addScaledVector(horizontalDirection, altitudeRadius)
]
);
const sideDirection = new THREE.Vector3(
Math.cos(azimuth),
0,
-Math.sin(azimuth)
);
altitudeLabel.position
.copy(
pivot.clone().addScaledVector(
horizontalDirection,
Math.cos(altitude * 0.5) * altitudeRadius
)
)
.add(new THREE.Vector3(0, Math.sin(altitude * 0.5) * altitudeRadius, 0))
.addScaledVector(sideDirection, 0.18);
altitudeLabel.position.y += 0.13;
// Dashed line toward the target vector.
replaceLinePoints(
targetRay,
[
pivot.clone(),
pivot.clone().addScaledVector(targetDirection, 3.08)
]
);
// Azimuth sweep on the horizontal plane.
const azimuthRadiusValue = 2.52;
const azimuthPoints = [];
const segmentCount = Math.max(2, Math.ceil((azimuth / (Math.PI * 2)) * 96));
for (let index = 0; index <= segmentCount; index++) {
const angle = azimuth * (index / segmentCount);
azimuthPoints.push(
new THREE.Vector3(
Math.sin(angle) * azimuthRadiusValue,
0.085,
Math.cos(angle) * azimuthRadiusValue
)
);
}
replaceLinePoints(azimuthArc, azimuthPoints);
replaceLinePoints(
azimuthRadius,
[
new THREE.Vector3(0, 0.088, 0),
new THREE.Vector3(
Math.sin(azimuth) * 2.78,
0.088,
Math.cos(azimuth) * 2.78
)
]
);
// Transparent triangular sector representing the azimuth sweep.
const sectorPositions = [0, 0.075, 0];
const sectorIndices = [];
for (let index = 0; index <= segmentCount; index++) {
const angle = azimuth * (index / segmentCount);
sectorPositions.push(
Math.sin(angle) * azimuthRadiusValue,
0.075,
Math.cos(angle) * azimuthRadiusValue
);
if (index < segmentCount) {
sectorIndices.push(0, index + 1, index + 2);
}
}
azimuthSector.geometry.dispose();
const sectorGeometry = new THREE.BufferGeometry();
sectorGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(sectorPositions, 3)
);
sectorGeometry.setIndex(sectorIndices);
azimuthSector.geometry = sectorGeometry;
const labelAngle = azimuth * 0.5;
azimuthLabel.position.set(
Math.sin(labelAngle) * 2.75,
0.24,
Math.cos(labelAngle) * 2.75
);
}
altitudeInput.addEventListener("input", updateGeometry);
azimuthInput.addEventListener("input", updateGeometry);
updateGeometry();
// -------------------------------------------------------------------------
// Direct camera controls, implemented without external examples/addons
// -------------------------------------------------------------------------
let dragging = false;
let dragPointerId = null;
let dragStartX = 0;
let dragStartY = 0;
let dragStartAzimuth = 0;
let dragStartElevation = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
dragPointerId = event.pointerId;
dragStartX = event.clientX;
dragStartY = event.clientY;
dragStartAzimuth = cameraState.targetAzimuth;
dragStartElevation = cameraState.targetElevation;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== dragPointerId) return;
const deltaX = event.clientX - dragStartX;
const deltaY = event.clientY - dragStartY;
cameraState.targetAzimuth = dragStartAzimuth - deltaX * 0.006;
cameraState.targetElevation = THREE.MathUtils.clamp(
dragStartElevation + deltaY * 0.0045,
0.12,
1.35
);
});
function endDrag(event) {
if (!dragging || event.pointerId !== dragPointerId) return;
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
dragPointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetDistance = THREE.MathUtils.clamp(
cameraState.targetDistance + event.deltaY * 0.008,
6.2,
15.5
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// 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);
});
function animate(time) {
requestAnimationFrame(animate);
updateCamera();
arrowMaterial.emissiveIntensity =
0.68 + Math.sin(time * 0.0022) * 0.12;
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```