Prompt specification
Build or customize the Three.js 3D scene "Carved printing block and registration corners" 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: Carved printing block and registration corners
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/carved-printing-block-and-registration-corners-x2341
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a wooden printing block and its registration corners, using stylized solid geometry. Put an original asymmetric relief motif on the block so its raised shapes and mirrored impression would be distinguishable. Two registration stops meet at adjacent edges, with a blank sheet resting beside them. Use warm matte wood, darker ink on the relief, and visible paper thickness. Leave the printing surface unobstructed, with enough clearance to see how a sheet would align against both stops.
Working Three.js Starter (carved-printing-block-and-registration-corners-x2341):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Woodblock Registration Study</title>
<style>
:root {
color-scheme: light;
--ink: #352820;
--paper: #f5efe2;
--muted: #7d6e5d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8dece;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.card {
position: fixed;
z-index: 2;
pointer-events: none;
border: 1px solid rgba(72, 50, 34, 0.15);
background: rgba(247, 240, 226, 0.84);
box-shadow: 0 14px 35px rgba(70, 48, 29, 0.11);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title {
top: 24px;
left: 24px;
max-width: 330px;
padding: 17px 19px 16px;
border-radius: 4px;
}
.eyebrow {
margin: 0 0 7px;
color: #9a6540;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(23px, 3vw, 31px);
font-weight: 500;
line-height: 1.08;
letter-spacing: -0.025em;
}
#title p:last-child {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
#legend {
left: 24px;
bottom: 24px;
display: flex;
flex-wrap: wrap;
gap: 9px;
padding: 10px 12px;
border-radius: 4px;
}
.chip {
display: inline-flex;
align-items: center;
gap: 7px;
color: #685746;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
}
.swatch {
width: 12px;
height: 12px;
border-radius: 2px;
border: 1px solid rgba(53, 40, 32, 0.12);
}
.wood {
background: #b97843;
}
.ink {
background: #352820;
}
.paper {
background: #f3ead8;
}
#controls {
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 7px;
padding: 7px;
border-radius: 4px;
pointer-events: auto;
}
button {
border: 0;
border-radius: 2px;
padding: 9px 11px;
background: transparent;
color: #594a3b;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
background: rgba(105, 73, 44, 0.09);
color: #30251d;
}
button:focus-visible {
outline: 2px solid #9a6540;
outline-offset: 1px;
}
.divider {
width: 1px;
height: 20px;
margin: 0 2px;
background: rgba(72, 50, 34, 0.15);
}
#hint {
position: fixed;
right: 24px;
top: 24px;
z-index: 2;
padding: 9px 11px;
border-radius: 3px;
color: #756654;
font-size: 10px;
letter-spacing: 0.035em;
pointer-events: none;
}
@media (max-width: 700px) {
#title {
top: 14px;
left: 14px;
max-width: 260px;
padding: 13px 14px;
}
#title p:last-child {
display: none;
}
#hint {
display: none;
}
#legend {
left: 14px;
bottom: 14px;
}
#controls {
right: 14px;
bottom: 14px;
}
#controls .optional {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D woodblock printing scene"></canvas>
<section id="title" class="card">
<p class="eyebrow">Registration Study No. 04</p>
<h1>Woodblock & Impression</h1>
<p>
An asymmetric inked relief, adjacent wooden stops, and a thick blank sheet
parked at the registration datum.
</p>
</section>
<section id="legend" class="card" aria-label="Material legend">
<span class="chip"><i class="swatch wood"></i>Warm wood</span>
<span class="chip"><i class="swatch ink"></i>Inked relief</span>
<span class="chip"><i class="swatch paper"></i>Blank paper</span>
</section>
<div id="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<nav id="controls" class="card" aria-label="Camera controls">
<button id="reset" type="button" title="Reset camera">Reset</button>
<button id="top" type="button" title="View from above">Top</button>
<span class="divider"></span>
<button id="close" class="optional" type="button" title="Closer view">Close</button>
</nav>
<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 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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.03;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e8dece");
scene.fog = new THREE.Fog("#e8dece", 22, 42);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0.55, 0.55, -0.05);
let desiredTarget = target.clone();
const orbit = {
theta: 0.59,
phi: 1.01,
radius: 13.7,
desiredTheta: 0.59,
desiredPhi: 1.01,
desiredRadius: 13.7
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
updateCamera();
// --- Lighting -------------------------------------------------------
scene.add(new THREE.HemisphereLight("#fff6e5", "#8f7158", 1.75));
const key = new THREE.DirectionalLight("#fff1d6", 3.15);
key.position.set(-4.5, 9, 6.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -11;
key.shadow.camera.right = 11;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -10;
key.shadow.camera.near = 1;
key.shadow.camera.far = 28;
key.shadow.bias = -0.0004;
key.shadow.normalBias = 0.025;
key.shadow.radius = 3;
scene.add(key);
const fill = new THREE.DirectionalLight("#dce8ef", 0.72);
fill.position.set(7, 4, -6);
scene.add(fill);
const warmBounce = new THREE.PointLight("#d79761", 18, 16, 2);
warmBounce.position.set(-4, 2.5, -4);
scene.add(warmBounce);
// --- Procedural textures -------------------------------------------
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (1664525 * value + 1013904223) >>> 0;
return value / 4294967296;
};
}
function makeWoodTexture() {
const size = 1024;
const textureCanvas = document.createElement("canvas");
textureCanvas.width = textureCanvas.height = size;
const ctx = textureCanvas.getContext("2d");
const random = seededRandom(7319);
const base = ctx.createLinearGradient(0, 0, size, size);
base.addColorStop(0, "#bd7d43");
base.addColorStop(0.42, "#c68a4e");
base.addColorStop(1, "#a96536");
ctx.fillStyle = base;
ctx.fillRect(0, 0, size, size);
for (let i = 0; i < 240; i++) {
const y = random() * size;
const wave = 5 + random() * 24;
const alpha = 0.025 + random() * 0.08;
ctx.beginPath();
ctx.moveTo(-30, y);
ctx.bezierCurveTo(
size * 0.22,
y + Math.sin(random() * Math.PI) * wave,
size * 0.68,
y - Math.cos(random() * Math.PI) * wave,
size + 30,
y + (random() - 0.5) * 12
);
ctx.strokeStyle = random() > 0.52
? `rgba(76, 38, 17, ${alpha})`
: `rgba(255, 213, 148, ${alpha * 0.72})`;
ctx.lineWidth = 0.7 + random() * 2.2;
ctx.stroke();
}
const knots = [
[180, 310, 72, 26],
[735, 655, 96, 31],
[880, 180, 45, 17]
];
for (const [cx, cy, rx, ry] of knots) {
for (let ring = 0; ring < 9; ring++) {
ctx.beginPath();
ctx.ellipse(
cx,
cy,
rx + ring * 7,
ry + ring * 2.8,
-0.18,
0,
Math.PI * 2
);
ctx.strokeStyle = `rgba(75, 37, 18, ${0.045 + ring * 0.006})`;
ctx.lineWidth = 1.4;
ctx.stroke();
}
}
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makePaperTexture() {
const size = 768;
const textureCanvas = document.createElement("canvas");
textureCanvas.width = textureCanvas.height = size;
const ctx = textureCanvas.getContext("2d");
const random = seededRandom(9921);
ctx.fillStyle = "#f2ead9";
ctx.fillRect(0, 0, size, size);
const wash = ctx.createLinearGradient(0, 0, size, size);
wash.addColorStop(0, "rgba(255,255,250,0.25)");
wash.addColorStop(1, "rgba(194,174,139,0.08)");
ctx.fillStyle = wash;
ctx.fillRect(0, 0, size, size);
for (let i = 0; i < 4200; i++) {
const x = random() * size;
const y = random() * size;
const alpha = 0.018 + random() * 0.045;
ctx.fillStyle = random() > 0.48
? `rgba(105,87,61,${alpha})`
: `rgba(255,255,255,${alpha * 1.7})`;
ctx.fillRect(x, y, 0.6 + random(), 0.6 + random());
}
for (let i = 0; i < 36; i++) {
const y = random() * size;
ctx.beginPath();
ctx.moveTo(0, y);
ctx.bezierCurveTo(
size * 0.3,
y + (random() - 0.5) * 8,
size * 0.7,
y + (random() - 0.5) * 8,
size,
y + (random() - 0.5) * 4
);
ctx.strokeStyle = "rgba(130,108,76,0.025)";
ctx.lineWidth = 0.7;
ctx.stroke();
}
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeGroundTexture() {
const size = 512;
const textureCanvas = document.createElement("canvas");
textureCanvas.width = textureCanvas.height = size;
const ctx = textureCanvas.getContext("2d");
const random = seededRandom(2187);
ctx.fillStyle = "#d7c6ae";
ctx.fillRect(0, 0, size, size);
for (let i = 0; i < 6500; i++) {
const shade = random() > 0.5 ? 255 : 76;
ctx.fillStyle = `rgba(${shade},${shade},${shade},${0.012 + random() * 0.025})`;
ctx.fillRect(random() * size, random() * size, 1, 1);
}
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(9, 9);
return texture;
}
const woodTexture = makeWoodTexture();
const sideWoodTexture = woodTexture.clone();
sideWoodTexture.repeat.set(2.2, 1.15);
sideWoodTexture.needsUpdate = true;
const paperTexture = makePaperTexture();
const groundTexture = makeGroundTexture();
const woodTopMaterial = new THREE.MeshStandardMaterial({
map: woodTexture,
color: "#e5b77f",
roughness: 0.88,
metalness: 0
});
const woodSideMaterial = new THREE.MeshStandardMaterial({
map: sideWoodTexture,
color: "#c78b51",
roughness: 0.93,
metalness: 0
});
const stopMaterial = new THREE.MeshStandardMaterial({
color: "#955b32",
roughness: 0.91,
metalness: 0
});
const stopTopMaterial = new THREE.MeshStandardMaterial({
color: "#a8693b",
roughness: 0.87,
metalness: 0
});
const inkMaterial = new THREE.MeshStandardMaterial({
color: "#302720",
roughness: 0.82,
metalness: 0.01
});
const registrationMaterial = new THREE.MeshStandardMaterial({
color: "#69422d",
roughness: 0.96,
metalness: 0
});
const paperTopMaterial = new THREE.MeshStandardMaterial({
map: paperTexture,
color: "#fffaf0",
roughness: 0.98,
metalness: 0
});
const paperEdgeMaterial = new THREE.MeshStandardMaterial({
color: "#d8c9ad",
roughness: 1,
metalness: 0
});
// --- Geometry helpers ----------------------------------------------
function roundedRectangleShape(width, height, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
shape.closePath();
return shape;
}
function makeExtrudedSlab(shape, depth, bevelSize, bevelThickness) {
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
curveSegments: 16,
bevelEnabled: true,
bevelSegments: 3,
bevelSize,
bevelThickness
});
geometry.rotateX(-Math.PI / 2);
geometry.computeBoundingBox();
return geometry;
}
// --- Ground ---------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
map: groundTexture,
color: "#d7c5aa",
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.008;
ground.receiveShadow = true;
scene.add(ground);
// --- Wooden printing block ----------------------------------------
const BLOCK_W = 5.4;
const BLOCK_D = 3.8;
const blockGroup = new THREE.Group();
blockGroup.position.x = -1.45;
scene.add(blockGroup);
const blockGeometry = makeExtrudedSlab(
roundedRectangleShape(BLOCK_W, BLOCK_D, 0.13),
0.78,
0.055,
0.055
);
const block = new THREE.Mesh(blockGeometry, [
woodTopMaterial,
woodSideMaterial
]);
block.position.y = -blockGeometry.boundingBox.min.y + 0.012;
block.castShadow = true;
block.receiveShadow = true;
blockGroup.add(block);
const blockTopY =
blockGeometry.boundingBox.max.y + block.position.y;
const blockTop = new THREE.Mesh(
new THREE.PlaneGeometry(BLOCK_W - 0.13, BLOCK_D - 0.13),
woodTopMaterial
);
blockTop.rotation.x = -Math.PI / 2;
blockTop.position.y = blockTopY + 0.003;
blockTop.receiveShadow = true;
blockGroup.add(blockTop);
// Two adjacent physical registration stops forming an L-shaped corner.
const stopHeight = 0.3;
const stopDepth = 0.24;
const rearStop = new THREE.Mesh(
new THREE.BoxGeometry(BLOCK_W + 0.22, stopHeight, stopDepth),
[stopMaterial, stopMaterial, stopTopMaterial, stopMaterial, stopMaterial, stopMaterial]
);
rearStop.position.set(
0,
blockTopY + stopHeight / 2,
-BLOCK_D / 2 + stopDepth / 2
);
rearStop.castShadow = true;
rearStop.receiveShadow = true;
blockGroup.add(rearStop);
const rightStop = new THREE.Mesh(
new THREE.BoxGeometry(stopDepth, stopHeight, BLOCK_D),
[stopMaterial, stopMaterial, stopTopMaterial, stopMaterial, stopMaterial, stopMaterial]
);
rightStop.position.set(
BLOCK_W / 2 - stopDepth / 2,
blockTopY + stopHeight / 2,
0
);
rightStop.castShadow = true;
rightStop.receiveShadow = true;
blockGroup.add(rightStop);
// Flat printed registration corner marks on the two open front corners.
function addRegistrationCorner(x, z, flipX) {
const group = new THREE.Group();
const length = 0.54;
const thickness = 0.052;
const horizontal = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.012, thickness),
registrationMaterial
);
horizontal.position.x = flipX * length * 0.5;
group.add(horizontal);
const vertical = new THREE.Mesh(
new THREE.BoxGeometry(thickness, 0.012, length),
registrationMaterial
);
vertical.position.z = -length * 0.5;
group.add(vertical);
group.position.set(x, blockTopY + 0.009, z);
group.children.forEach((mesh) => {
mesh.receiveShadow = true;
});
blockGroup.add(group);
}
addRegistrationCorner(-BLOCK_W / 2 + 0.28, BLOCK_D / 2 - 0.28, 1);
addRegistrationCorner(BLOCK_W / 2 - 0.28, BLOCK_D / 2 - 0.28, -1);
// --- Original asymmetric inked relief -------------------------------
const motif = new THREE.Group();
motif.rotation.x = -Math.PI / 2;
motif.position.y = blockTopY + 0.009;
blockGroup.add(motif);
function addRelief(shape) {
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.13,
steps: 1,
curveSegments: 28,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: 0.018,
bevelThickness: 0.018
});
const mesh = new THREE.Mesh(geometry, inkMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
motif.add(mesh);
}
// Off-center seed form: intentionally non-symmetrical.
const seed = new THREE.Shape();
seed.moveTo(-1.72, 0.38);
seed.bezierCurveTo(-1.55, 0.92, -0.92, 1.18, -0.42, 0.91);
seed.bezierCurveTo(0.02, 0.68, 0.12, 0.14, -0.25, -0.30);
seed.bezierCurveTo(-0.62, -0.75, -1.20, -0.69, -1.48, -0.27);
seed.bezierCurveTo(-1.70, 0.02, -1.82, 0.18, -1.72, 0.38);
seed.closePath();
addRelief(seed);
// Directional sweeping stroke, giving the stamp a clear mirror image.
const sweep = new THREE.Shape();
sweep.moveTo(-0.18, -1.28);
sweep.bezierCurveTo(-0.04, -0.72, 0.24, -0.18, 0.66, 0.23);
sweep.bezierCurveTo(0.94, 0.51, 1.29, 0.61, 1.60, 0.43);
sweep.lineTo(1.44, 0.05);
sweep.bezierCurveTo(1.12, 0.23, 0.89, 0.08, 0.68, -0.26);
sweep.bezierCurveTo(0.30, -0.82, 0.17, -1.17, 0.10, -1.50);
sweep.closePath();
addRelief(sweep);
// Counterweight dot.
const dot = new THREE.Shape();
dot.absarc(1.66, 1.02, 0.17, 0, Math.PI * 2, false);
addRelief(dot);
// Counterweight wedge.
const wedge = new THREE.Shape();
wedge.moveTo(-1.76, -1.30);
wedge.lineTo(-1.17, -0.96);
wedge.lineTo(-1.53, -0.51);
wedge.closePath();
addRelief(wedge);
// Small directional dash completes the unbalanced composition.
const dash = new THREE.Shape();
dash.moveTo(-1.93, 1.20);
dash.lineTo(-1.38, 1.34);
dash.lineTo(-1.44, 1.18);
dash.lineTo(-1.96, 1.04);
dash.closePath();
addRelief(dash);
// --- Blank paper ----------------------------------------------------
const paperGroup = new THREE.Group();
paperGroup.position.set(3.78, 0, -0.08);
scene.add(paperGroup);
const PAPER_W = 5.2;
const PAPER_D = 4.0;
const paperGeometry = makeExtrudedSlab(
roundedRectangleShape(PAPER_W, PAPER_D, 0.055),
0.072,
0.012,
0.012
);
const paper = new THREE.Mesh(paperGeometry, [
paperTopMaterial,
paperEdgeMaterial
]);
paper.position.y = -paperGeometry.boundingBox.min.y + 0.015;
paper.castShadow = true;
paper.receiveShadow = true;
paperGroup.add(paper);
const paperTopY =
paperGeometry.boundingBox.max.y + paper.position.y;
const paperTop = new THREE.Mesh(
new THREE.PlaneGeometry(PAPER_W - 0.035, PAPER_D - 0.035),
paperTopMaterial
);
paperTop.rotation.x = -Math.PI / 2;
paperTop.position.y = paperTopY + 0.002;
paperTop.receiveShadow = true;
paperGroup.add(paperTop);
// The sheet's back-left corner sits just outside the common stop corner,
// making both registration axes easy to read without covering the block.
const datumGuideMaterial = new THREE.MeshBasicMaterial({
color: "#9a7655",
transparent: true,
opacity: 0.22,
depthWrite: false
});
const datumGuide = new THREE.Mesh(
new THREE.PlaneGeometry(0.018, 0.58),
datumGuideMaterial
);
datumGuide.rotation.x = -Math.PI / 2;
datumGuide.position.set(1.42, 0.012, -1.57);
scene.add(datumGuide);
// --- Direct camera controls ----------------------------------------
const pointers = new Map();
let mode = "orbit";
let lastX = 0;
let lastY = 0;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
mode = event.shiftKey || event.button === 2 ? "pan" : "orbit";
lastX = event.clientX;
lastY = event.clientY;
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (mode === "orbit") {
orbit.desiredTheta -= dx * 0.005;
orbit.desiredPhi = THREE.MathUtils.clamp(
orbit.desiredPhi - dy * 0.005,
0.08,
Math.PI / 2.05
);
} else {
camera.updateMatrixWorld();
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0)
.setY(0)
.normalize();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const scale = orbit.radius * 0.00125;
desiredTarget.addScaledVector(right, -dx * scale);
desiredTarget.addScaledVector(forward, -dy * scale);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
mode = "orbit";
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.desiredRadius = THREE.MathUtils.clamp(
orbit.desiredRadius + event.deltaY * 0.009,
6.5,
21
);
},
{ passive: false }
);
function resetCamera() {
orbit.desiredTheta = 0.59;
orbit.desiredPhi = 1.01;
orbit.desiredRadius = 13.7;
desiredTarget.set(0.55, 0.55, -0.05);
}
function topCamera() {
orbit.desiredTheta = 0.03;
orbit.desiredPhi = 0.08;
orbit.desiredRadius = 13.2;
desiredTarget.set(0.55, 0.25, -0.05);
}
function closeCamera() {
orbit.desiredTheta = 0.49;
orbit.desiredPhi = 0.95;
orbit.desiredRadius = 9.7;
desiredTarget.set(-0.15, 0.55, -0.05);
}
document.querySelector("#reset").addEventListener("click", resetCamera);
document.querySelector("#top").addEventListener("click", topCamera);
document.querySelector("#close").addEventListener("click", closeCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetCamera();
if (event.key.toLowerCase() === "t") topCamera();
});
// --- Resize and animation ------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
function animate() {
const damping = 0.09;
orbit.theta = THREE.MathUtils.damp(
orbit.theta,
orbit.desiredTheta,
damping,
performance.now()
);
orbit.phi = THREE.MathUtils.damp(
orbit.phi,
orbit.desiredPhi,
damping,
performance.now()
);
orbit.radius = THREE.MathUtils.damp(
orbit.radius,
orbit.desiredRadius,
damping,
performance.now()
);
target.x = THREE.MathUtils.damp(target.x, desiredTarget.x, damping, performance.now());
target.y = THREE.MathUtils.damp(target.y, desiredTarget.y, damping, performance.now());
target.z = THREE.MathUtils.damp(target.z, desiredTarget.z, damping, performance.now());
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```