Prompt specification
Build or customize the Three.js 3D scene "Same point different origins" 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: Same point different origins
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/same-point-different-origins-x1690
Scene Description Prompt:
One stylized point has different coordinates in two translated frames while its world position stays fixed. Three.js from cdnjs, one HTML file.
Working Three.js Starter (same-point-different-origins-x1690):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>One Point, Two Translated Frames</title>
<style>
:root {
color-scheme: dark;
--background: #07101d;
--panel: rgba(12, 24, 42, 0.78);
--panel-border: rgba(170, 205, 255, 0.15);
--text: #edf5ff;
--muted: #8fa4bd;
--frame-a: #ffb454;
--frame-b: #ff64a5;
--world: #64e6ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--background);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.glass {
background: var(--panel);
border: 1px solid var(--panel-border);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
header {
position: fixed;
top: 22px;
left: 22px;
z-index: 10;
width: min(470px, calc(100vw - 44px));
padding: 20px 22px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--world);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 34px);
line-height: 1.08;
letter-spacing: -0.035em;
}
header p {
margin: 12px 0 0;
max-width: 430px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.equation {
display: inline-block;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid rgba(100, 230, 255, 0.17);
border-radius: 8px;
background: rgba(100, 230, 255, 0.07);
color: #ccefff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
}
.readouts {
position: fixed;
top: 22px;
right: 22px;
z-index: 10;
display: grid;
grid-template-columns: repeat(3, minmax(160px, 1fr));
gap: 10px;
width: min(650px, calc(100vw - 44px));
pointer-events: none;
}
.card {
min-width: 0;
padding: 15px;
overflow: hidden;
border-radius: 15px;
}
.card::before {
content: "";
display: block;
width: 28px;
height: 3px;
margin-bottom: 12px;
border-radius: 99px;
background: var(--world);
}
.card.frame-a::before {
background: var(--frame-a);
}
.card.frame-b::before {
background: var(--frame-b);
}
.card-label {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.card-title {
margin-top: 4px;
font-size: 15px;
font-weight: 750;
}
.card-title span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 500;
}
.origin {
margin-top: 10px;
overflow: hidden;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.coordinate-caption {
margin-top: 13px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.coordinates {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-top: 7px;
}
.coordinate {
min-width: 0;
padding: 7px 6px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
text-align: center;
}
.coordinate span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
}
.coordinate strong {
display: block;
margin-top: 3px;
overflow: hidden;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
text-overflow: ellipsis;
}
.world-card .coordinate:nth-child(1) strong {
color: #ff7d7d;
}
.world-card .coordinate:nth-child(2) strong {
color: #6ee7a0;
}
.world-card .coordinate:nth-child(3) strong {
color: #70adff;
}
.controls {
position: fixed;
bottom: 22px;
left: 22px;
z-index: 10;
width: 370px;
max-width: calc(100vw - 44px);
padding: 17px;
border-radius: 17px;
}
.controls-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.controls-heading strong {
font-size: 13px;
}
.controls-heading span {
color: var(--muted);
font-size: 10px;
}
.control-group {
padding: 11px 12px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.control-group + .control-group {
margin-top: 9px;
}
.control-title {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 9px;
font-size: 11px;
font-weight: 750;
}
.swatch {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--world);
}
.swatch.a {
background: var(--frame-a);
}
.swatch.b {
background: var(--frame-b);
}
.slider-row {
display: grid;
grid-template-columns: 15px 1fr 52px;
align-items: center;
gap: 9px;
min-height: 27px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.slider-row output {
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 99px;
outline: none;
appearance: none;
-webkit-appearance: none;
background: rgba(255, 255, 255, 0.12);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
border: 2px solid #dff7ff;
border-radius: 50%;
appearance: none;
-webkit-appearance: none;
background: #243b53;
box-shadow: 0 0 0 4px rgba(100, 230, 255, 0.08);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #dff7ff;
border-radius: 50%;
background: #243b53;
}
.options {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 12px;
}
.toggle {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
cursor: pointer;
}
.toggle input {
accent-color: var(--world);
}
button {
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
background: rgba(255, 255, 255, 0.06);
color: var(--text);
font: inherit;
font-size: 10px;
cursor: pointer;
}
button:hover {
background: rgba(255, 255, 255, 0.12);
}
.hint {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 5;
padding: 9px 12px;
border-radius: 10px;
color: var(--muted);
font-size: 10px;
pointer-events: none;
}
@media (max-width: 950px) {
header {
width: 400px;
}
.readouts {
top: auto;
right: 18px;
bottom: 80px;
width: 510px;
}
}
@media (max-width: 700px) {
header {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
header p,
.equation {
display: none;
}
.readouts {
top: 103px;
right: 12px;
bottom: auto;
left: 12px;
width: auto;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 6px;
}
.card {
padding: 10px;
}
.card-title {
font-size: 12px;
}
.origin,
.coordinate-caption {
display: none;
}
.coordinates {
gap: 3px;
margin-top: 9px;
}
.coordinate {
padding: 5px 2px;
}
.coordinate strong {
font-size: 9px;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-width: none;
max-height: 42vh;
overflow-y: auto;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D visualization of two translated coordinate frames"></canvas>
<header class="glass">
<div class="eyebrow">Coordinate Frames</div>
<h1>One point.<br>Two coordinate systems.</h1>
<p>
Move either translated frame. The stylized point stays fixed in world space,
while its local coordinates change with the frame origin.
</p>
<div class="equation">p_world = t_A + p_A = t_B + p_B</div>
</header>
<section class="readouts" aria-label="Coordinate readouts">
<article class="card glass frame-a">
<div class="card-label">Translated frame</div>
<div class="card-title">
Frame A
<span>parallel world-aligned axes</span>
</div>
<div class="origin">origin <span id="aOrigin"></span></div>
<div class="coordinate-caption">Local coordinates</div>
<div class="coordinates">
<div class="coordinate"><span>X</span><strong id="aX">0.00</strong></div>
<div class="coordinate"><span>Y</span><strong id="aY">0.00</strong></div>
<div class="coordinate"><span>Z</span><strong id="aZ">0.00</strong></div>
</div>
</article>
<article class="card glass frame-b">
<div class="card-label">Translated frame</div>
<div class="card-title">
Frame B
<span>parallel world-aligned axes</span>
</div>
<div class="origin">origin <span id="bOrigin"></span></div>
<div class="coordinate-caption">Local coordinates</div>
<div class="coordinates">
<div class="coordinate"><span>X</span><strong id="bX">0.00</strong></div>
<div class="coordinate"><span>Y</span><strong id="bY">0.00</strong></div>
<div class="coordinate"><span>Z</span><strong id="bZ">0.00</strong></div>
</div>
</article>
<article class="card glass world-card">
<div class="card-label">World space</div>
<div class="card-title">
Fixed point
<span>unchanged by frame translation</span>
</div>
<div class="origin">position <span id="worldPosition"></span></div>
<div class="coordinate-caption">World coordinates</div>
<div class="coordinates">
<div class="coordinate"><span>X</span><strong id="wX"></strong></div>
<div class="coordinate"><span>Y</span><strong id="wY"></strong></div>
<div class="coordinate"><span>Z</span><strong id="wZ"></strong></div>
</div>
</article>
</section>
<aside class="controls glass">
<div class="controls-heading">
<strong>Translate the frames</strong>
<span>The point does not move</span>
</div>
<div class="control-group">
<div class="control-title">
<span class="swatch a"></span>
Frame A origin
</div>
<label class="slider-row">
<span>X</span>
<input id="aOriginX" type="range" min="-4.5" max="4.5" step="0.05" value="-3.2">
<output id="aOriginXValue">-3.20</output>
</label>
<label class="slider-row">
<span>Z</span>
<input id="aOriginZ" type="range" min="-3" max="3" step="0.05" value="-0.8">
<output id="aOriginZValue">-0.80</output>
</label>
</div>
<div class="control-group">
<div class="control-title">
<span class="swatch b"></span>
Frame B origin
</div>
<label class="slider-row">
<span>X</span>
<input id="bOriginX" type="range" min="-4.5" max="4.5" step="0.05" value="2.6">
<output id="bOriginXValue">2.60</output>
</label>
<label class="slider-row">
<span>Z</span>
<input id="bOriginZ" type="range" min="-3" max="3" step="0.05" value="1.4">
<output id="bOriginZValue">1.40</output>
</label>
</div>
<div class="options">
<label class="toggle">
<input id="showGuides" type="checkbox" checked>
Show coordinate guides
</label>
<div>
<button id="resetFrames" type="button">Reset frames</button>
<button id="resetCamera" type="button">Reset view</button>
</div>
</div>
</aside>
<div class="hint glass">
Drag to orbit · Shift/right-drag to pan · Scroll/pinch to zoom
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07101d);
scene.fog = new THREE.Fog(0x07101d, 18, 38);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
100
);
const GROUND_Y = -1.45;
const worldPoint = new THREE.Vector3(0.8, 1.35, -0.6);
const frameOrigins = {
A: new THREE.Vector3(-3.2, GROUND_Y, -0.8),
B: new THREE.Vector3(2.6, GROUND_Y, 1.4)
};
const axisColors = {
x: 0xff6b6b,
y: 0x62e6a7,
z: 0x70adff
};
// Lighting.
scene.add(new THREE.HemisphereLight(0x9ccfff, 0x08101c, 1.45));
const keyLight = new THREE.DirectionalLight(0xccecff, 2.1);
keyLight.position.set(4, 9, 6);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x6d7dff, 1.1);
rimLight.position.set(-7, 4, -5);
scene.add(rimLight);
// Ground.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0x081321,
roughness: 0.96,
metalness: 0.05
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = GROUND_Y - 0.025;
scene.add(ground);
const grid = new THREE.GridHelper(20, 20, 0x34506b, 0x1b3046);
grid.position.y = GROUND_Y + 0.008;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function makeLabel(text, color, width = 0.65) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 256;
labelCanvas.height = 96;
const ctx = labelCanvas.getContext("2d");
const cssColor = `#${new THREE.Color(color).getHexString()}`;
ctx.clearRect(0, 0, 256, 96);
roundedRect(ctx, 10, 14, 236, 68, 18);
ctx.fillStyle = "rgba(6, 15, 27, 0.86)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = cssColor;
ctx.stroke();
ctx.fillStyle = cssColor;
ctx.font = "700 42px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 128, 49);
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
})
);
sprite.scale.set(width, width * 0.375, 1);
sprite.renderOrder = 20;
return sprite;
}
function addArrow(parent, direction, length, color, label) {
const shaftLength = length - 0.28;
const directionVector = direction.clone().normalize();
const up = new THREE.Vector3(0, 1, 0);
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, shaftLength, 12),
new THREE.MeshBasicMaterial({ color })
);
shaft.position.copy(directionVector).multiplyScalar(shaftLength / 2);
shaft.quaternion.setFromUnitVectors(up, directionVector);
parent.add(shaft);
const tip = new THREE.Mesh(
new THREE.ConeGeometry(0.09, 0.28, 16),
new THREE.MeshBasicMaterial({ color })
);
tip.position.copy(directionVector).multiplyScalar(shaftLength + 0.14);
tip.quaternion.setFromUnitVectors(up, directionVector);
parent.add(tip);
if (label) {
const axisLabel = makeLabel(label, color, 0.52);
axisLabel.position.copy(directionVector).multiplyScalar(length + 0.28);
parent.add(axisLabel);
}
}
class CoordinateFrame {
constructor(name, color) {
this.name = name;
this.color = color;
this.group = new THREE.Group();
this.guides = new THREE.Group();
this.group.add(this.guides);
scene.add(this.group);
addArrow(this.group, new THREE.Vector3(1, 0, 0), 2.8, axisColors.x, "X");
addArrow(this.group, new THREE.Vector3(0, 1, 0), 3.05, axisColors.y, "Y");
addArrow(this.group, new THREE.Vector3(0, 0, 1), 2.8, axisColors.z, "Z");
const originRing = new THREE.Mesh(
new THREE.RingGeometry(0.2, 0.29, 40),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.8,
side: THREE.DoubleSide,
depthWrite: false
})
);
originRing.rotation.x = -Math.PI / 2;
originRing.position.y = 0.015;
this.group.add(originRing);
const badge = makeLabel(name, color, 0.95);
badge.position.set(0, 0.43, 0);
this.group.add(badge);
this.pathSegments = [];
for (let i = 0; i < 3; i++) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]);
const material = new THREE.LineDashedMaterial({
color,
transparent: true,
opacity: 0.88 - i * 0.16,
dashSize: 0.15,
gapSize: 0.09,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
this.guides.add(line);
this.pathSegments.push(line);
}
}
update(origin) {
this.group.position.copy(origin);
const local = worldPoint.clone().sub(origin);
const p0 = new THREE.Vector3(0, 0, 0);
const p1 = new THREE.Vector3(local.x, 0, 0);
const p2 = new THREE.Vector3(local.x, local.y, 0);
const p3 = local.clone();
const points = [p0, p1, p2, p3];
for (let i = 0; i < this.pathSegments.length; i++) {
const line = this.pathSegments[i];
line.geometry.dispose();
line.geometry = new THREE.BufferGeometry().setFromPoints([
points[i],
points[i + 1]
]);
line.computeLineDistances();
}
return local;
}
}
const frameA = new CoordinateFrame("A", 0xffb454);
const frameB = new CoordinateFrame("B", 0xff64a5);
// The single stylized world-space point.
const pointGroup = new THREE.Group();
pointGroup.position.copy(worldPoint);
scene.add(pointGroup);
const pointCore = new THREE.Mesh(
new THREE.SphereGeometry(0.19, 32, 24),
new THREE.MeshStandardMaterial({
color: 0xe9fbff,
emissive: 0x37dfff,
emissiveIntensity: 4,
roughness: 0.18,
metalness: 0.15
})
);
pointGroup.add(pointCore);
const pointShell = new THREE.Mesh(
new THREE.SphereGeometry(0.34, 24, 18),
new THREE.MeshBasicMaterial({
color: 0x43ddff,
transparent: true,
opacity: 0.12,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
pointGroup.add(pointShell);
const facetedShell = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.43, 1),
new THREE.MeshBasicMaterial({
color: 0x75eaff,
wireframe: true,
transparent: true,
opacity: 0.32,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
pointGroup.add(facetedShell);
const ring1 = new THREE.Mesh(
new THREE.TorusGeometry(0.52, 0.018, 10, 80),
new THREE.MeshBasicMaterial({
color: 0x64e6ff,
transparent: true,
opacity: 0.8,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
ring1.rotation.x = Math.PI / 2;
pointGroup.add(ring1);
const ring2 = new THREE.Mesh(
new THREE.TorusGeometry(0.4, 0.014, 10, 80),
new THREE.MeshBasicMaterial({
color: 0xa779ff,
transparent: true,
opacity: 0.7,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
ring2.rotation.y = Math.PI / 2;
pointGroup.add(ring2);
const pointLight = new THREE.PointLight(0x54ddff, 18, 7, 2);
pointGroup.add(pointLight);
// UI helpers.
const $ = (selector) => document.querySelector(selector);
function formatNumber(value) {
if (Math.abs(value) < 0.0001) value = 0;
return value.toFixed(2);
}
function formatVector(vector) {
return `(${formatNumber(vector.x)}, ${formatNumber(vector.y)}, ${formatNumber(vector.z)})`;
}
function updateReadout(prefix, origin, local) {
$(`#${prefix}Origin`).textContent = formatVector(origin);
$(`#${prefix}X`).textContent = formatNumber(local.x);
$(`#${prefix}Y`).textContent = formatNumber(local.y);
$(`#${prefix}Z`).textContent = formatNumber(local.z);
}
function updateFrames() {
const localA = frameA.update(frameOrigins.A);
const localB = frameB.update(frameOrigins.B);
updateReadout("a", frameOrigins.A, localA);
updateReadout("b", frameOrigins.B, localB);
$("#aOriginXValue").textContent = formatNumber(frameOrigins.A.x);
$("#aOriginZValue").textContent = formatNumber(frameOrigins.A.z);
$("#bOriginXValue").textContent = formatNumber(frameOrigins.B.x);
$("#bOriginZValue").textContent = formatNumber(frameOrigins.B.z);
}
$("#worldPosition").textContent = formatVector(worldPoint);
$("#wX").textContent = formatNumber(worldPoint.x);
$("#wY").textContent = formatNumber(worldPoint.y);
$("#wZ").textContent = formatNumber(worldPoint.z);
[
["aOriginX", "A", "x"],
["aOriginZ", "A", "z"],
["bOriginX", "B", "x"],
["bOriginZ", "B", "z"]
].forEach(([id, frame, axis]) => {
$(`#${id}`).addEventListener("input", (event) => {
frameOrigins[frame][axis] = Number(event.target.value);
updateFrames();
});
});
$("#showGuides").addEventListener("change", (event) => {
frameA.guides.visible = event.target.checked;
frameB.guides.visible = event.target.checked;
});
$("#resetFrames").addEventListener("click", () => {
frameOrigins.A.set(-3.2, GROUND_Y, -0.8);
frameOrigins.B.set(2.6, GROUND_Y, 1.4);
$("#aOriginX").value = -3.2;
$("#aOriginZ").value = -0.8;
$("#bOriginX").value = 2.6;
$("#bOriginZ").value = 1.4;
updateFrames();
});
updateFrames();
// Camera controls implemented directly, without Three.js addons.
const target = new THREE.Vector3(0, -0.15, 0);
let theta = 0.72;
let phi = 1.03;
let radius = 14.5;
const defaultCamera = {
target: target.clone(),
theta,
phi,
radius
};
function updateCamera() {
const offset = new THREE.Vector3().setFromSpherical(
new THREE.Spherical(radius, phi, theta)
);
camera.position.copy(target).add(offset);
camera.lookAt(target);
}
function resetCamera() {
target.copy(defaultCamera.target);
theta = defaultCamera.theta;
phi = defaultCamera.phi;
radius = defaultCamera.radius;
updateCamera();
}
$("#resetCamera").addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
const pointers = new Map();
let dragMode = "orbit";
let previousPinchDistance = 0;
let previousPointer = { x: 0, y: 0 };
function getPinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
previousPointer = { x: event.clientX, y: event.clientY };
} else if (pointers.size === 2) {
previousPinchDistance = getPinchDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
previousPointer = { x: event.clientX, y: event.clientY };
if (dragMode === "orbit") {
theta -= dx * 0.006;
phi = THREE.MathUtils.clamp(phi - dy * 0.006, 0.25, Math.PI - 0.25);
} else {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const panScale = radius * 0.0015;
target.addScaledVector(right, -dx * panScale);
target.addScaledVector(up, dy * panScale);
}
} else if (pointers.size >= 2) {
const currentDistance = getPinchDistance();
if (previousPinchDistance > 0 && currentDistance > 0) {
radius = THREE.MathUtils.clamp(
radius * (previousPinchDistance / currentDistance),
6,
28
);
}
previousPinchDistance = currentDistance;
}
updateCamera();
});
function removePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
previousPointer = { x: remaining.x, y: remaining.y };
}
previousPinchDistance = getPinchDistance();
}
canvas.addEventListener("pointerup", removePointer);
canvas.addEventListener("pointercancel", removePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
6,
28
);
updateCamera();
},
{ passive: false }
);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
pointGroup.rotation.y += delta * 0.28;
facetedShell.rotation.x += delta * 0.18;
facetedShell.rotation.z -= delta * 0.12;
ring1.rotation.z += delta * 0.55;
ring2.rotation.x += delta * 0.4;
const pulse = 1 + Math.sin(clock.elapsedTime * 2.4) * 0.08;
pointShell.scale.setScalar(pulse);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```