Prompt specification
Build or customize the Three.js 3D scene "Renaissance-style perspective drawing table" 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: Renaissance-style perspective drawing table
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/renaissance-style-perspective-drawing-table-x2386
Scene Description Prompt:
Show projected points at a low-poly Renaissance-style artist's table with viewing frame and geometric solids. Label the construction simplified. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (renaissance-style-perspective-drawing-table-x2386):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Renaissance Perspective Table</title>
<style>
:root {
color-scheme: dark;
--ink: #17130f;
--parchment: #e8d6aa;
--muted: #b8aa8d;
--gold: #d3ad62;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
body::after {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 52% 43%, transparent 35%, rgba(5, 4, 3, 0.38) 100%),
linear-gradient(180deg, rgba(255, 220, 160, 0.025), transparent 35%);
z-index: 3;
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#scene:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.title-card {
position: absolute;
top: clamp(20px, 4vw, 48px);
left: clamp(20px, 4vw, 52px);
width: min(330px, calc(100vw - 40px));
color: var(--parchment);
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.7);
}
.eyebrow {
margin: 0 0 12px;
color: var(--gold);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.23em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(36px, 5vw, 66px);
font-weight: 400;
line-height: 0.88;
letter-spacing: -0.055em;
}
h1 em {
color: var(--gold);
font-weight: 400;
}
.subtitle {
max-width: 280px;
margin: 18px 0 0;
color: #c8bba1;
font-size: 13px;
line-height: 1.55;
}
.simplified {
display: inline-flex;
align-items: center;
gap: 9px;
margin-top: 19px;
padding: 8px 11px;
border: 1px solid rgba(220, 185, 112, 0.42);
border-radius: 2px;
background: rgba(19, 15, 11, 0.68);
color: #f0dda9;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.simplified::before {
content: "";
width: 6px;
height: 6px;
border: 1px solid var(--gold);
border-radius: 50%;
box-shadow: 0 0 9px rgba(211, 173, 98, 0.8);
}
.legend {
position: absolute;
bottom: clamp(22px, 4vw, 42px);
left: clamp(20px, 4vw, 52px);
display: grid;
gap: 8px;
color: #cbbda1;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
letter-spacing: 0.07em;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
}
.swatch {
width: 17px;
height: 3px;
border-radius: 2px;
box-shadow: 0 0 8px currentColor;
}
.swatch.object {
color: #a0beb4;
background: currentColor;
}
.swatch.projected {
color: #ffd889;
background: currentColor;
}
.swatch.ray {
width: 22px;
height: 1px;
color: #bca879;
background: repeating-linear-gradient(
90deg,
currentColor 0 4px,
transparent 4px 7px
);
}
.controls {
position: absolute;
right: clamp(18px, 3vw, 38px);
bottom: clamp(20px, 3vw, 36px);
display: flex;
align-items: center;
gap: 12px;
color: #9f927b;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
letter-spacing: 0.06em;
}
#reset {
pointer-events: auto;
border: 1px solid rgba(219, 191, 130, 0.35);
border-radius: 2px;
padding: 8px 10px;
background: rgba(18, 14, 10, 0.7);
color: #d8c69e;
font: inherit;
cursor: pointer;
backdrop-filter: blur(8px);
}
#reset:hover {
border-color: rgba(219, 191, 130, 0.75);
color: #fff0c5;
}
.world-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
white-space: nowrap;
padding: 6px 8px;
border: 1px solid rgba(222, 195, 134, 0.3);
border-radius: 2px;
background: rgba(18, 14, 10, 0.76);
color: #d9c69a;
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(7px);
transition: opacity 150ms ease;
}
#label-viewpoint {
border-color: rgba(255, 211, 120, 0.5);
color: #ffdc8a;
}
#label-projection {
border-color: rgba(154, 225, 210, 0.42);
color: #a9e2d7;
}
@media (max-width: 700px) {
.title-card {
width: 245px;
}
.subtitle {
display: none;
}
.simplified {
margin-top: 13px;
font-size: 9px;
}
.legend {
display: none;
}
.controls span {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive low-poly Renaissance perspective construction"
></canvas>
<div class="hud">
<section class="title-card">
<p class="eyebrow">Renaissance perspective study · No. 03</p>
<h1>Points in<br><em>projection</em></h1>
<p class="subtitle">
A fixed viewpoint, geometric solids, and their traced image points
arranged across an artist’s viewing frame.
</p>
<div class="simplified">Construction simplified</div>
</section>
<div class="legend" aria-hidden="true">
<div class="legend-row">
<i class="swatch object"></i>
Solid vertices
</div>
<div class="legend-row">
<i class="swatch projected"></i>
Projected points
</div>
<div class="legend-row">
<i class="swatch ray"></i>
Sight lines
</div>
</div>
<div class="controls">
<span>Drag to orbit · Scroll to zoom · Arrow keys to pan</span>
<button id="reset" type="button">Reset view</button>
</div>
<div id="label-viewpoint" class="world-label">Fixed viewpoint</div>
<div id="label-projection" class="world-label">Projected image</div>
</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.querySelector("#scene");
const resetButton = document.querySelector("#reset");
const viewpointLabel = document.querySelector("#label-viewpoint");
const projectionLabel = document.querySelector("#label-projection");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x17130f);
scene.fog = new THREE.Fog(0x17130f, 17, 34);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
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 camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
// ------------------------------------------------------------
// Lighting and materials
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xe4d5ad, 0x21170f, 1.7));
const keyLight = new THREE.DirectionalLight(0xffdfae, 3.2);
keyLight.position.set(4.5, 8.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x7892a0, 1.15);
fillLight.position.set(-6, 4, 2);
scene.add(fillLight);
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x272018,
roughness: 1,
metalness: 0
}),
table: new THREE.MeshStandardMaterial({
color: 0x654128,
roughness: 0.82,
metalness: 0.02,
flatShading: true
}),
tableEdge: new THREE.MeshStandardMaterial({
color: 0x3f281b,
roughness: 0.9,
flatShading: true
}),
frame: new THREE.MeshStandardMaterial({
color: 0x4a2c1c,
roughness: 0.78,
flatShading: true
}),
parchment: new THREE.MeshStandardMaterial({
color: 0xd6c18e,
roughness: 0.96,
metalness: 0
}),
ink: new THREE.MeshStandardMaterial({
color: 0x1a1815,
roughness: 0.48,
flatShading: true
}),
brass: new THREE.MeshStandardMaterial({
color: 0xb68a43,
roughness: 0.42,
metalness: 0.7,
flatShading: true
})
};
function addBox(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Ground and artist's table
// ------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
addBox(8.4, 0.30, 4.6, materials.table, 0, 0.75, 0.35);
addBox(8.5, 0.12, 4.7, materials.tableEdge, 0, 0.56, 0.35);
const legPositions = [
[-3.35, -1.25],
[3.35, -1.25],
[-3.35, 1.95],
[3.35, 1.95]
];
for (const [x, z] of legPositions) {
addBox(0.46, 0.58, 0.46, materials.tableEdge, x, 0.29, z);
}
addBox(0.34, 0.32, 3.4, materials.tableEdge, -3.25, 0.28, 0.35);
addBox(0.34, 0.32, 3.4, materials.tableEdge, 3.25, 0.28, 0.35);
addBox(6.4, 0.25, 0.28, materials.tableEdge, 0, 0.30, -1.18);
addBox(6.4, 0.25, 0.28, materials.tableEdge, 0, 0.30, 1.88);
// A sheet of prepared drawing paper.
const sheet = addBox(
1.65,
0.018,
1.05,
materials.parchment,
-3.05,
0.912,
1.50
);
sheet.rotation.y = -0.14;
// Small inkwell.
const inkwell = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.26, 0.32, 8),
materials.ink
);
inkwell.position.set(-3.12, 1.06, 0.15);
inkwell.castShadow = true;
scene.add(inkwell);
// Pair of brass dividers.
function cylinderBetween(a, b, radius, material) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), 6),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
cylinderBetween(
[-3.40, 0.94, 1.58],
[-2.63, 0.94, 1.72],
0.025,
materials.brass
);
cylinderBetween(
[-3.40, 0.94, 1.58],
[-3.00, 0.94, 2.10],
0.025,
materials.brass
);
// ------------------------------------------------------------
// Upright viewing frame
// ------------------------------------------------------------
const frameZ = -2.53;
const frameCenterY = 1.40;
const innerWidth = 7.20;
const innerHeight = 2.80;
addBox(
innerWidth,
innerHeight,
0.08,
materials.parchment,
0,
frameCenterY,
frameZ - 0.05
);
addBox(
0.23,
3.06,
0.23,
materials.frame,
-3.70,
frameCenterY,
frameZ + 0.02
);
addBox(
0.23,
3.06,
0.23,
materials.frame,
3.70,
frameCenterY,
frameZ + 0.02
);
addBox(
7.62,
0.23,
0.23,
materials.frame,
0,
-0.02,
frameZ + 0.02
);
addBox(
7.62,
0.23,
0.23,
materials.frame,
0,
2.82,
frameZ + 0.02
);
// Small inner gold strips around the drawing surface.
const innerTrimMaterial = new THREE.MeshStandardMaterial({
color: 0x9e793c,
roughness: 0.65,
metalness: 0.25
});
addBox(
innerWidth + 0.08,
0.035,
0.035,
innerTrimMaterial,
0,
0.015,
frameZ + 0.012
);
addBox(
innerWidth + 0.08,
0.035,
0.035,
innerTrimMaterial,
0,
2.785,
frameZ + 0.012
);
// A restrained construction grid on the picture plane.
const gridPositions = [];
const gridZ = frameZ - 0.002;
for (let x = -3.5; x <= 3.5; x += 0.5) {
gridPositions.push(x, 0, gridZ, x, 2.8, gridZ);
}
for (let y = 0; y <= 2.8; y += 0.4) {
gridPositions.push(-3.6, y, gridZ, 3.6, y, gridZ);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
scene.add(
new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x6d5934,
transparent: true,
opacity: 0.19,
depthWrite: false
})
)
);
// ------------------------------------------------------------
// Low-poly solids
// ------------------------------------------------------------
const solids = [];
const cubeCenter = new THREE.Vector3(-1.75, 1.58, 0.42);
const cubeSize = 1.36;
const cubeHalf = cubeSize / 2;
const cubeVertices = [
[-cubeHalf, -cubeHalf, -cubeHalf],
[ cubeHalf, -cubeHalf, -cubeHalf],
[ cubeHalf, cubeHalf, -cubeHalf],
[-cubeHalf, cubeHalf, -cubeHalf],
[-cubeHalf, -cubeHalf, cubeHalf],
[ cubeHalf, -cubeHalf, cubeHalf],
[ cubeHalf, cubeHalf, cubeHalf],
[-cubeHalf, cubeHalf, cubeHalf]
];
const cubeEdges = [
[0, 1], [1, 2], [2, 3], [3, 0],
[4, 5], [5, 6], [6, 7], [7, 4],
[0, 4], [1, 5], [2, 6], [3, 7]
];
solids.push({
name: "Cube",
center: cubeCenter,
vertices: cubeVertices,
edges: cubeEdges,
geometry: new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize),
material: new THREE.MeshStandardMaterial({
color: 0x58766c,
roughness: 0.72,
metalness: 0.05,
flatShading: true
}),
pointColor: 0x8de0d0
});
const octaCenter = new THREE.Vector3(0.02, 1.68, 0.48);
const octaRadius = 0.78;
const octaVertices = [
[0, octaRadius, 0],
[octaRadius, 0, 0],
[0, 0, octaRadius],
[-octaRadius, 0, 0],
[0, 0, -octaRadius],
[0, -octaRadius, 0]
];
const octaEdges = [
[0, 1], [0, 2], [0, 3], [0, 4],
[5, 1], [5, 2], [5, 3], [5, 4],
[1, 2], [2, 3], [3, 4], [4, 1]
];
solids.push({
name: "Octahedron",
center: octaCenter,
vertices: octaVertices,
edges: octaEdges,
geometry: new THREE.OctahedronGeometry(octaRadius, 0),
material: new THREE.MeshStandardMaterial({
color: 0xb96349,
roughness: 0.68,
metalness: 0.03,
flatShading: true
}),
pointColor: 0xffa076
});
const pyramidCenter = new THREE.Vector3(1.78, 0.91, 0.46);
const pyramidHalf = 0.68;
const pyramidHeight = 1.55;
const pyramidVertices = [
[-pyramidHalf, 0, -pyramidHalf],
[ pyramidHalf, 0, -pyramidHalf],
[ pyramidHalf, 0, pyramidHalf],
[-pyramidHalf, 0, pyramidHalf],
[0, pyramidHeight, 0]
];
const pyramidEdges = [
[0, 1], [1, 2], [2, 3], [3, 0],
[0, 4], [1, 4], [2, 4], [3, 4]
];
const pyramidGeometry = new THREE.BufferGeometry();
pyramidGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
pyramidVertices.flat(),
3
)
);
pyramidGeometry.setIndex([
0, 1, 2, 3,
1, 0, 4,
2, 1, 4,
3, 2, 4,
0, 3, 4
]);
pyramidGeometry.computeVertexNormals();
solids.push({
name: "Pyramid",
center: pyramidCenter,
vertices: pyramidVertices,
edges: pyramidEdges,
geometry: pyramidGeometry,
material: new THREE.MeshStandardMaterial({
color: 0xc3a05c,
roughness: 0.6,
metalness: 0.12,
flatShading: true
}),
pointColor: 0xffdf83
});
for (const solid of solids) {
const mesh = new THREE.Mesh(solid.geometry, solid.material);
mesh.position.copy(solid.center);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const edgeLines = new THREE.LineSegments(
new THREE.EdgesGeometry(solid.geometry, 18),
new THREE.LineBasicMaterial({
color: 0x191511,
transparent: true,
opacity: 0.55
})
);
edgeLines.position.copy(solid.center);
scene.add(edgeLines);
}
// ------------------------------------------------------------
// Perspective projection
// ------------------------------------------------------------
const eye = new THREE.Vector3(0, 2.65, 8.20);
const picturePlaneZ = frameZ;
function projectToFrame(worldPoint) {
const t =
(picturePlaneZ - eye.z) /
(worldPoint.z - eye.z);
return new THREE.Vector3(
eye.x + (worldPoint.x - eye.x) * t,
eye.y + (worldPoint.y - eye.y) * t,
picturePlaneZ
);
}
for (const solid of solids) {
const worldVertices = solid.vertices.map(
vertex =>
new THREE.Vector3(
vertex[0],
vertex[1],
vertex[2]
).add(solid.center)
);
const projectedVertices = worldVertices.map(projectToFrame);
// Faint sight lines from the fixed viewpoint through each vertex.
const rayPositions = [];
for (const projected of projectedVertices) {
rayPositions.push(
eye.x, eye.y, eye.z,
projected.x, projected.y, projected.z
);
}
const rayGeometry = new THREE.BufferGeometry();
rayGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(rayPositions, 3)
);
const rays = new THREE.LineSegments(
rayGeometry,
new THREE.LineDashedMaterial({
color: solid.pointColor,
dashSize: 0.12,
gapSize: 0.11,
transparent: true,
opacity: 0.19,
depthWrite: false
})
);
rays.computeLineDistances();
scene.add(rays);
// Projected edges on the picture plane.
const projectedEdgePositions = [];
for (const [a, b] of solid.edges) {
projectedEdgePositions.push(
projectedVertices[a].x,
projectedVertices[a].y,
projectedVertices[a].z + 0.022,
projectedVertices[b].x,
projectedVertices[b].y,
projectedVertices[b].z + 0.022
);
}
const projectedEdgeGeometry = new THREE.BufferGeometry();
projectedEdgeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(projectedEdgePositions, 3)
);
const projectedEdges = new THREE.LineSegments(
projectedEdgeGeometry,
new THREE.LineBasicMaterial({
color: solid.pointColor,
transparent: true,
opacity: 0.82,
depthWrite: false
})
);
scene.add(projectedEdges);
// Bright dots and thin halos at the projected points.
for (const projected of projectedVertices) {
const point = new THREE.Mesh(
new THREE.SphereGeometry(0.057, 8, 6),
new THREE.MeshBasicMaterial({
color: solid.pointColor,
toneMapped: false
})
);
point.position.set(
projected.x,
projected.y,
projected.z + 0.03
);
scene.add(point);
const halo = new THREE.Mesh(
new THREE.RingGeometry(0.085, 0.115, 12),
new THREE.MeshBasicMaterial({
color: solid.pointColor,
transparent: true,
opacity: 0.62,
side: THREE.DoubleSide,
depthWrite: false,
toneMapped: false
})
);
halo.position.set(
projected.x,
projected.y,
projected.z + 0.035
);
scene.add(halo);
}
}
// Stylized marker for the fixed artist's viewpoint.
const eyeOrb = new THREE.Mesh(
new THREE.SphereGeometry(0.095, 10, 7),
new THREE.MeshBasicMaterial({
color: 0xffdc8c,
toneMapped: false
})
);
eyeOrb.position.copy(eye);
scene.add(eyeOrb);
const eyeRing = new THREE.Mesh(
new THREE.TorusGeometry(0.21, 0.032, 6, 16),
new THREE.MeshStandardMaterial({
color: 0xd7a74c,
emissive: 0x5b3910,
emissiveIntensity: 0.45,
roughness: 0.35,
metalness: 0.75,
flatShading: true
})
);
eyeRing.position.copy(eye);
scene.add(eyeRing);
// ------------------------------------------------------------
// Direct camera controls — no external control add-ons
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 1.25, 0.05);
const initialView = {
radius: 12.8,
theta: 0.55,
phi: 1.10
};
const desired = { ...initialView };
const current = { ...initialView };
let dragging = false;
let lastX = 0;
let lastY = 0;
function updateCamera() {
current.radius += (desired.radius - current.radius) * 0.085;
current.theta += (desired.theta - current.theta) * 0.12;
current.phi += (desired.phi - current.phi) * 0.12;
const sinPhi = Math.sin(current.phi);
camera.position.set(
target.x +
current.radius * sinPhi * Math.sin(current.theta),
target.y +
current.radius * Math.cos(current.phi),
target.z +
current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(target);
}
canvas.addEventListener("pointerdown", event => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus();
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.35,
1.48
);
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
6.6,
19
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
Object.assign(desired, initialView);
});
window.addEventListener("keydown", event => {
switch (event.key) {
case "ArrowLeft":
desired.theta += 0.09;
break;
case "ArrowRight":
desired.theta -= 0.09;
break;
case "ArrowUp":
desired.phi = THREE.MathUtils.clamp(
desired.phi - 0.07,
0.35,
1.48
);
break;
case "ArrowDown":
desired.phi = THREE.MathUtils.clamp(
desired.phi + 0.07,
0.35,
1.48
);
break;
case "+":
case "=":
desired.radius = Math.max(6.6, desired.radius - 0.6);
break;
case "-":
desired.radius = Math.min(19, desired.radius + 0.6);
break;
default:
return;
}
event.preventDefault();
});
resetButton.addEventListener("click", () => {
Object.assign(desired, initialView);
});
// ------------------------------------------------------------
// World-anchored labels
// ------------------------------------------------------------
const projectedAnchor = new THREE.Vector3(2.72, 2.56, frameZ);
const eyeAnchor = eye.clone().add(new THREE.Vector3(0, 0.38, 0));
function placeLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
element.style.opacity = visible ? "1" : "0";
element.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
function animate() {
updateCamera();
placeLabel(viewpointLabel, eyeAnchor);
placeLabel(projectionLabel, projectedAnchor);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```