Prompt specification
Build or customize the Three.js 3D scene "Two Portal Frames With Local Axes" 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: Two Portal Frames With Local Axes
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-portal-frames-with-local-axes-x3481
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring paired portals and transformed reference frames. Model two original doorway frames at different orientations with visible local axes. Label the connection as fictional and keep entrance and exit coordinate frames inspectable. Stylized solid forms.
Working Three.js Starter (two-portal-frames-with-local-axes-x3481):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Paired Portals · Fictional Coordinate Bridge</title>
<style>
:root{
--a:#ff7a4d; --b:#37c8f0; --fg:#e7edf5; --dim:#8d99a9;
--panel:rgba(11,15,21,.86); --line:#232d3b;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:#0b0f15;color:var(--fg);overflow:hidden;
font:11.5px/1.5 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
#view{position:fixed;inset:0;display:block;touch-action:none}
#panel{position:fixed;top:12px;right:12px;width:352px;max-height:calc(100vh - 24px);
overflow-y:auto;background:var(--panel);backdrop-filter:blur(10px);
border:1px solid var(--line);border-radius:12px;padding:13px 14px 16px;
box-shadow:0 22px 60px rgba(0,0,0,.55);scrollbar-width:thin;
scrollbar-color:#2b3646 transparent}
#panel::-webkit-scrollbar{width:7px}
#panel::-webkit-scrollbar-thumb{background:#2b3646;border-radius:4px}
.badge{display:inline-block;padding:2px 8px;border:1px solid #b4472a;color:#ff9c74;
border-radius:99px;font-size:9.5px;letter-spacing:.16em;background:rgba(180,71,42,.12)}
h1{margin:7px 0 3px;font-size:15px;letter-spacing:.11em;font-weight:600}
.sub{margin:0 0 4px;color:var(--dim);font-size:10.5px}
.sub b{color:#c9d4e2;font-weight:600}
section{border-top:1px solid var(--line);margin-top:11px;padding-top:9px}
section>h2{margin:0 0 7px;font-size:9.5px;letter-spacing:.19em;color:var(--dim);font-weight:600}
.pose{border-left:2px solid #2b3646;padding-left:8px;margin-bottom:9px}
.pose.a{border-left-color:var(--a)} .pose.b{border-left-color:var(--b)}
.pose .pt{font-size:10px;letter-spacing:.13em;margin-bottom:3px}
.pose.a .pt{color:var(--a)} .pose.b .pt{color:var(--b)}
.row{display:flex;justify-content:space-between;align-items:center;gap:6px}
.slider{display:grid;grid-template-columns:1fr auto;gap:2px 6px;margin:5px 0}
.slider label{color:#a9b5c4}
.slider .val{color:#dfe7f1;text-align:right;font-variant-numeric:tabular-nums}
.slider input{grid-column:1/3;width:100%;height:3px;-webkit-appearance:none;appearance:none;
background:#25303e;border-radius:3px;outline:none;margin:2px 0 0}
.slider input::-webkit-slider-thumb{-webkit-appearance:none;width:11px;height:11px;border-radius:50%;
background:#cfd9e6;cursor:pointer;border:2px solid #0b0f15}
.slider input::-moz-range-thumb{width:11px;height:11px;border-radius:50%;background:#cfd9e6;cursor:pointer}
.pose.a input::-webkit-slider-thumb{background:var(--a)}
.pose.b input::-webkit-slider-thumb{background:var(--b)}
.chk{display:flex;align-items:center;gap:6px;margin:4px 0;color:#b7c3d2;cursor:pointer}
.chk input{accent-color:var(--b)}
pre{margin:0;padding:8px 9px;background:#0a0e14;border:1px solid #1c2532;border-radius:7px;
color:#c6d2e0;white-space:pre;font-size:10.5px;overflow-x:auto;line-height:1.45}
pre .k{color:#6d7d90} pre .m{color:#ffd28a} pre .n{color:#8be0ff}
.btns{display:flex;flex-wrap:wrap;gap:6px;margin-top:9px}
button{flex:1 1 auto;min-width:88px;padding:6px 8px;background:#141b25;color:#cfd9e6;
border:1px solid #2a3646;border-radius:6px;font:inherit;font-size:10px;cursor:pointer;letter-spacing:.05em}
button:hover{background:#1b2431;border-color:#3b4a5d}
button.on{background:var(--b);color:#06222c;border-color:var(--b);font-weight:700}
.probe{display:grid;grid-template-columns:repeat(3,1fr);gap:6px;margin:6px 0}
.probe label{display:block;color:#8d99a9;font-size:9.5px}
.probe input{width:100%;padding:4px 5px;background:#0a0e14;color:#dfe7f1;border:1px solid #1c2532;
border-radius:5px;font:inherit;font-size:10.5px}
#legend{position:fixed;left:12px;bottom:12px;background:rgba(11,15,21,.78);border:1px solid var(--line);
border-radius:9px;padding:9px 11px;color:#8d99a9;font-size:10px;line-height:1.7;pointer-events:none}
#legend b{color:#cfd9e6;font-weight:600}
.sw{display:inline-block;width:8px;height:8px;border-radius:2px;margin-right:5px;vertical-align:1px}
@media (max-width:820px){#panel{width:min(352px,calc(100vw - 24px))}#legend{display:none}}
</style>
</head>
<body>
<canvas id="view"></canvas>
<aside id="panel">
<div class="badge">FICTIONAL</div>
<h1>PAIRED PORTALS</h1>
<p class="sub">Two stylized doorway frames in different orientations. The link between them is a
<b>coordinate transform</b> (T = B⁻¹·A), not a physical passage. Every pose here is invented.</p>
<div id="panel-body"></div>
</aside>
<div id="legend">
<b>LOCAL AXES</b> <span class="sw" style="background:#ff4d5a"></span>X
<span class="sw" style="background:#7bd06a;margin-left:8px"></span>Y
<span class="sw" style="background:#4d9dff;margin-left:8px"></span>Z<br>
<b>DRAG</b> orbit · <b>SHIFT/ RIGHT-DRAG</b> pan · <b>WHEEL</b> zoom
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ─────────────────────────── scene ─────────────────────────── */
const canvas = document.getElementById('view');
const renderer = new THREE.WebGLRenderer({ canvas, antialias:true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b0f15);
scene.fog = new THREE.Fog(0x0b0f15, 34, 78);
const camera = new THREE.PerspectiveCamera(46, innerWidth/innerHeight, 0.1, 220);
scene.add(new THREE.HemisphereLight(0xa8c6ff, 0x241d16, 0.85));
const key = new THREE.DirectionalLight(0xffffff, 1.75);
key.position.set(7, 13, 6); key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
const sc = key.shadow.camera;
sc.left=-16; sc.right=16; sc.top=16; sc.bottom=-16; sc.near=1; sc.far=42;
key.shadow.bias = -0.0008;
scene.add(key);
const fill = new THREE.DirectionalLight(0x6fa8ff, 0.5);
fill.position.set(-9, 6, -7); scene.add(fill);
/* ground: stylized solid slab + block set */
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
new THREE.MeshStandardMaterial({ color:0x232b38, roughness:0.96, metalness:0 })
);
ground.rotation.x = -Math.PI/2; ground.receiveShadow = true; scene.add(ground);
const blockMat = new THREE.MeshStandardMaterial({ color:0x2c3644, roughness:0.9, flatShading:true });
[[-1.5,0.45,7.5,1.6,0.9,1.2],[2.6,0.3,-8.5,2.0,0.6,1.4],[-9,0.22,7.2,1.4,0.44,1.0],[8.8,0.26,-7.6,1.2,0.52,1.2]]
.forEach(([x,y,z,w,h,d])=>{
const m = new THREE.Mesh(new THREE.BoxGeometry(w,h,d), blockMat);
m.position.set(x,y,z); m.castShadow=true; m.receiveShadow=true; scene.add(m);
});
/* ───────────────────── helpers: text sprites ───────────────────── */
function roundRect(ctx,x,y,w,h,r){
ctx.beginPath();
ctx.moveTo(x+r,y); ctx.arcTo(x+w,y,x+w,y+h,r); ctx.arcTo(x+w,y+h,x,y+h,r);
ctx.arcTo(x,y+h,x,y,r); ctx.arcTo(x,y,x+w,y,r); ctx.closePath();
}
function makeTextSprite(text, opts={}){
const dpr = 2, fs = opts.fs || 30;
const font = opts.font || `600 ${fs}px ui-monospace, Menlo, Consolas, monospace`;
const lines = String(text).split('\n');
const m = document.createElement('canvas').getContext('2d');
m.font = font;
const widths = lines.map(l => Math.ceil(m.measureText(l).width));
const tw = Math.max(...widths), lh = Math.ceil(fs*1.35);
const padX = 16, padY = 10;
const W = tw + padX*2, H = lines.length*lh + padY*2;
const c = document.createElement('canvas');
c.width = W*dpr; c.height = H*dpr;
const ctx = c.getContext('2d'); ctx.scale(dpr,dpr);
if (opts.bg !== null){
ctx.fillStyle = opts.bg || 'rgba(9,12,18,0.78)';
roundRect(ctx,0,0,W,H,9); ctx.fill();
}
if (opts.border){ ctx.strokeStyle=opts.border; ctx.lineWidth=2; roundRect(ctx,1,1,W-2,H-2,9); ctx.stroke(); }
ctx.font = font; ctx.textAlign='center'; ctx.textBaseline='middle';
ctx.fillStyle = opts.color || '#eef2f8';
lines.forEach((l,i)=> ctx.fillText(l, W/2, padY + lh*i + lh/2));
const tex = new THREE.CanvasTexture(c);
tex.colorSpace = THREE.SRGBColorSpace; tex.anisotropy = 4;
const sp = new THREE.Sprite(new THREE.SpriteMaterial({
map:tex, transparent:true, depthTest:false, depthWrite:false
}));
const h = opts.size || 0.42;
sp.scale.set(h * (W/H), h, 1);
sp.renderOrder = 20;
sp.userData.isLabel = true;
return sp;
}
/* ─────────────────────────── axes / triads ─────────────────────────── */
const AX = [0xff4d5a, 0x7bd06a, 0x4d9dff]; // X, Y, Z
const YAX = new THREE.Vector3(0,1,0);
function arrowMesh(color, len, opacity=1){
const mat = new THREE.MeshBasicMaterial({ color, transparent:opacity<1, opacity });
const holder = new THREE.Group();
const shaftLen = len*0.74, headLen = len*0.26;
const shaft = new THREE.Mesh(new THREE.CylinderGeometry(0.036,0.036,shaftLen,12), mat);
shaft.position.y = shaftLen/2;
const head = new THREE.Mesh(new THREE.ConeGeometry(0.105, headLen, 14), mat);
head.position.y = len - headLen/2;
holder.add(shaft, head);
return holder;
}
class Triad {
constructor(parent, names, len=1.6, opacity=1){
this.len = len; this.group = new THREE.Group(); parent.add(this.group);
this.holders = []; this.labels = []; this.names = names;
for (let i=0;i<3;i++){
const h = arrowMesh(AX[i], len, opacity);
this.group.add(h); this.holders.push(h);
const sp = makeTextSprite(names[i], {
color:'#'+new THREE.Color(AX[i]).getHexString(), bg:'rgba(8,11,16,0.55)', size:0.3, fs:34
});
this.group.add(sp); this.labels.push(sp);
}
this.setDirs([new THREE.Vector3(1,0,0), new THREE.Vector3(0,1,0), new THREE.Vector3(0,0,1)]);
}
setDirs(dirs){
for (let i=0;i<3;i++){
const d = dirs[i].clone().normalize();
this.holders[i].quaternion.setFromUnitVectors(YAX, d);
this.labels[i].position.copy(d).multiplyScalar(this.len + 0.26);
}
}
setLabelsVisible(v){ this.labels.forEach(l=>l.visible=v); }
}
/* ─────────────────────────── portal geometry ─────────────────────────── */
function buildPortal(accentHex, title, tag){
const g = new THREE.Group();
const shell = new THREE.MeshStandardMaterial({ color:0xd9d3c4, roughness:.82, metalness:.06, flatShading:true });
const trim = new THREE.MeshStandardMaterial({ color:0x2a3240, roughness:.9, flatShading:true });
const field = new THREE.MeshStandardMaterial({
color:accentHex, emissive:accentHex, emissiveIntensity:.5, roughness:.55, metalness:0
});
const core = new THREE.MeshBasicMaterial({ color:0xf4fbff });
const ringM = new THREE.MeshBasicMaterial({ color:accentHex });
const addBox = (w,h,d,x,y,z,mat)=>{
const m = new THREE.Mesh(new THREE.BoxGeometry(w,h,d), mat);
m.position.set(x,y,z); m.castShadow=true; m.receiveShadow=true; g.add(m); return m;
};
// posts, lintel, feet
addBox(0.42, 2.95, 0.52, -1.28, 1.475, 0, shell);
addBox(0.42, 2.95, 0.52, 1.28, 1.475, 0, shell);
addBox(3.0, 0.44, 0.52, 0, 3.17, 0, shell);
addBox(0.78, 0.16, 0.86, -1.28, 0.08, 0, trim);
addBox(0.78, 0.16, 0.86, 1.28, 0.08, 0, trim);
addBox(3.4, 0.1, 0.34, 0, 0.05, 0, trim);
// portal field + stylized disc
const plane = new THREE.Mesh(new THREE.PlaneGeometry(2.12, 2.72), field);
plane.position.set(0, 1.47, 0.01); g.add(plane);
const disc = new THREE.Mesh(new THREE.CircleGeometry(0.58, 40), core);
disc.position.set(0, 1.47, 0.03); g.add(disc);
const ring = new THREE.Mesh(new THREE.RingGeometry(0.72, 0.86, 48), ringM);
ring.position.set(0, 1.47, 0.02); g.add(ring);
// frame tag + title
const tagSp = makeTextSprite(tag, {
color:'#'+new THREE.Color(accentHex).getHexString(), bg:'rgba(8,11,16,0.8)',
border:'#'+new THREE.Color(accentHex).getHexString(), size:0.36, fs:30
});
tagSp.position.set(0, 3.02, 0.34); g.add(tagSp);
const titleSp = makeTextSprite(title, {
color:'#eef2f8', bg:'rgba(8,11,16,0.8)', border:'#'+new THREE.Color(accentHex).getHexString(), size:0.46, fs:30
});
titleSp.position.set(0, 3.72, 0); g.add(titleSp);
// origin marker
const org = new THREE.Mesh(new THREE.SphereGeometry(0.1, 18, 14),
new THREE.MeshStandardMaterial({ color:0xffffff, roughness:.35, emissive:0x222222 }));
org.position.set(0,0,0); g.add(org);
return { group:g, titleSp, tagSp };
}
/* ─────────────────────────── state ─────────────────────────── */
const D = Math.PI/180;
const state = {
A:{ pos:new THREE.Vector3(-4.6,0,0.6), yaw:24*D, pitch:0, roll:0 },
B:{ pos:new THREE.Vector3( 4.4,0,-1.4), yaw:-60*D, pitch:6*D, roll:10*D },
showAxes:true, showGhost:true, showGhostInv:true, showLines:true, showLabels:true,
sweep:false, sweepT:0
};
const frames = state;
const groups = { A:{}, B:{} };
const portalA = buildPortal(0xff7a4d, 'PORTAL A · ENTRANCE', 'FRAME A');
const portalB = buildPortal(0x37c8f0, 'PORTAL B · EXIT', 'FRAME B');
groups.A = portalA.group; groups.B = portalB.group;
scene.add(groups.A, groups.B);
// local triads
const triadA = new Triad(groups.A, ['X','Y','Z'], 1.6);
const triadB = new Triad(groups.B, ['X','Y','Z'], 1.6);
// ghost (transformed) reference frames
const ghostB = new Triad(groups.B, ['A·X','A·Y','A·Z'], 1.6, 0.42);
const ghostA = new Triad(groups.A, ['B·X','B·Y','B·Z'], 1.6, 0.42);
// probe: solid marker in frame A, wireframe cage read in frame B
const probeBall = new THREE.Mesh(new THREE.SphereGeometry(0.11, 20, 16),
new THREE.MeshStandardMaterial({ color:0xfff1b8, emissive:0xffc94d, emissiveIntensity:.7, roughness:.3 }));
scene.add(probeBall);
const probeCage = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.OctahedronGeometry(0.3, 0)),
new THREE.LineBasicMaterial({ color:0x37c8f0, transparent:true, opacity:.85 })
);
groups.B.add(probeCage);
// dashed correspondence lines
function dashedLine(color, opacity=1){
const geo = new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(), new THREE.Vector3()]);
const line = new THREE.Line(geo, new THREE.LineDashedMaterial({
color, dashSize:.26, gapSize:.18, transparent:true, opacity }));
line.computeLineDistances();
scene.add(line);
return line;
}
const chordX = dashedLine(AX[0]), chordY = dashedLine(AX[1]), chordZ = dashedLine(AX[2]);
const chordT = dashedLine(0xffffff, .55);
const probeLine = dashedLine(0xffc94d, .8);
function setLine(line, a, b){
const p = line.geometry.attributes.position;
p.setXYZ(0, a.x, a.y, a.z); p.setXYZ(1, b.x, b.y, b.z);
p.needsUpdate = true; line.geometry.computeBoundingSphere(); line.computeLineDistances();
}
const deltaRotLabel = makeTextSprite('Δ ROTATION', { color:'#ffd28a', bg:'rgba(8,11,16,0.72)', size:0.34 });
const deltaTrLabel = makeTextSprite('Δ TRANSLATION', { color:'#cfd9e6', bg:'rgba(8,11,16,0.72)', size:0.34 });
scene.add(deltaRotLabel, deltaTrLabel);
const linkLabel = makeTextSprite('FICTIONAL PORTAL LINK\nno physical connection exists', {
color:'#ffb08a', bg:'rgba(8,11,16,0.7)', border:'#7a3a22', size:0.42, fs:28 });
linkLabel.position.set(0, 4.3, 0); scene.add(linkLabel);
/* ───────────────────── frame maths ───────────────────── */
const ONE = new THREE.Vector3(1,1,1);
const m3 = new THREE.Matrix3();
function frameMatrix(f){
const q = new THREE.Quaternion().setFromEuler(new THREE.Euler(f.pitch, f.yaw, f.roll, 'XYZ'));
f.quat = q;
f.mat = new THREE.Matrix4().compose(f.pos, q, ONE);
return f.mat;
}
function colsOf(matrix4){
m3.setFromMatrix4(matrix4);
return [
new THREE.Vector3(m3.elements[0], m3.elements[1], m3.elements[2]),
new THREE.Vector3(m3.elements[3], m3.elements[4], m3.elements[5]),
new THREE.Vector3(m3.elements[6], m3.elements[7], m3.elements[8])
];
}
const T = new THREE.Matrix4(); // A-local → B-local
const Tinv = new THREE.Matrix4(); // B-local → A-local
const probeLocal = new THREE.Vector3(0, 1.35, -2.4);
function updateScene(){
frameMatrix(state.A); frameMatrix(state.B);
groups.A.position.copy(state.A.pos); groups.A.quaternion.copy(state.A.quat);
groups.B.position.copy(state.B.pos); groups.B.quaternion.copy(state.B.quat);
T.copy(state.B.mat).invert().multiply(state.A.mat);
Tinv.copy(state.A.mat).invert().multiply(state.B.mat);
// ghost frames: A's axes expressed in B's space (and vice-versa)
ghostB.setDirs(colsOf(T));
ghostA.setDirs(colsOf(Tinv));
// visibility
triadA.group.visible = state.showAxes; triadB.group.visible = state.showAxes;
ghostB.group.visible = state.showGhost; ghostA.group.visible = state.showGhostInv;
triadA.setLabelsVisible(state.showLabels); triadB.setLabelsVisible(state.showLabels);
ghostB.setLabelsVisible(state.showLabels); ghostA.setLabelsVisible(state.showLabels);
portalA.titleSp.visible = portalA.tagSp.visible = state.showLabels;
portalB.titleSp.visible = portalB.tagSp.visible = state.showLabels;
linkLabel.visible = state.showLabels;
deltaRotLabel.visible = deltaTrLabel.visible = state.showLabels;
// correspondence chords: B's own axes vs the transported A axes (world space)
const L = 1.6;
const chords = [chordX, chordY, chordZ];
for (let i=0;i<3;i++){
const e = new THREE.Vector3(); e.setComponent(i, 1);
const bTip = e.clone().multiplyScalar(L).applyMatrix4(state.B.mat);
const gTip = colsOf(T)[i].clone().multiplyScalar(L).applyMatrix4(state.B.mat);
setLine(chords[i], bTip, gTip);
}
setLine(chordT, state.A.pos, state.B.pos);
deltaRotLabel.position.copy(state.B.pos).add(
new THREE.Vector3(0.55,1.35,0).applyQuaternion(state.B.quat));
deltaTrLabel.position.copy(state.A.pos).lerp(state.B.pos, .5).add(new THREE.Vector3(0,0.35,0));
updateProbe();
}
function updateProbe(){
const pWorld = probeLocal.clone().applyMatrix4(state.A.mat);
const pB = probeLocal.clone().applyMatrix4(T);
probeBall.position.copy(pWorld);
probeCage.position.copy(pB);
setLine(probeLine, state.A.pos, pWorld);
}
/* ───────────────────── panel construction ───────────────────── */
const body = document.getElementById('panel-body');
function section(title){
const s = document.createElement('section');
const h = document.createElement('h2'); h.textContent = title;
const c = document.createElement('div'); s.append(h, c); body.appendChild(s);
return c;
}
function addCheck(parent, label, checked, onChange){
const l = document.createElement('label'); l.className='chk';
const i = document.createElement('input'); i.type='checkbox'; i.checked=checked;
i.addEventListener('change', ()=>onChange(i.checked));
const s = document.createElement('span'); s.textContent=label;
l.append(i,s); parent.appendChild(l); return i;
}
function addSlider(parent, label, min, max, step, value, onInput){
const row = document.createElement('div'); row.className='slider';
const l = document.createElement('label'); l.textContent=label;
const v = document.createElement('span'); v.className='val'; v.textContent=value.toFixed(1)+'°';
const i = document.createElement('input');
i.type='range'; i.min=min; i.max=max; i.step=step; i.value=value;
i.addEventListener('input', ()=>{ onInput(parseFloat(i.value)); v.textContent=parseFloat(i.value).toFixed(1)+'°'; });
row.append(l, v, i); parent.appendChild(row);
return { input:i, set(nv){ i.value=nv; v.textContent=nv.toFixed(1)+'°'; } };
}
function pre(parent, id){
const p = document.createElement('pre'); p.id=id; parent.appendChild(p); return p;
}
/* display toggles */
const disp = section('DISPLAY');
addCheck(disp, 'Local axis triads (A & B)', true, v=>state.showAxes=v);
addCheck(disp, 'Ghost frame at B (A axes in B space)', true, v=>state.showGhost=v);
addCheck(disp, 'Ghost frame at A (B axes in A space)', true, v=>state.showGhostInv=v);
addCheck(disp, 'Correspondence chords', true, v=>state.showLines=v);
addCheck(disp, 'Labels', true, v=>state.showLabels=v);
/* pose controls */
const poseSec = section('POSE');
const boxA = document.createElement('div'); boxA.className='pose a';
const boxB = document.createElement('div'); boxB.className='pose b';
const tA = document.createElement('div'); tA.className='pt'; tA.textContent='FRAME A · ENTRANCE';
const tB = document.createElement('div'); tB.className='pt'; tB.textContent='FRAME B · EXIT';
boxA.append(tA); boxB.append(tB); poseSec.append(boxA, boxB);
const sliders = { A:[], B:[] };
[['yaw','Yaw'],['pitch','Pitch'],['roll','Roll']].forEach(([k,lbl])=>{
sliders.A.push(addSlider(boxA, lbl+' A', -180, 180, 1, state.A[k]/D, v=>{ state.A[k]=v*D; updateScene(); refresh(); }));
sliders.B.push(addSlider(boxB, lbl+' B', -180, 180, 1, state.B[k]/D, v=>{ state.B[k]=v*D; updateScene(); refresh(); }));
});
// separation slider for the exit portal
addSlider(boxB, 'Exit X', -8, 8, 0.1, state.B.pos.x, v=>{ state.B.pos.x=v; updateScene(); refresh(); });
/* frame readouts */
const frSec = section('FRAMES');
const preA = pre(frSec, 'preA'), preB = pre(frSec, 'preB');
const trSec = section('TRANSFORM A → B');
const preT = pre(trSec, 'preT');
/* probe */
const pbSec = section('PROBE (coordinates in frame A)');
const probeRow = document.createElement('div'); probeRow.className='probe';
const probeInputs = {};
['x','y','z'].forEach((k,i)=>{
const l = document.createElement('label'); l.textContent = k.toUpperCase();
const inp = document.createElement('input'); inp.type='number'; inp.step='0.1';
inp.value = probeLocal.getComponent(i).toFixed(2);
inp.addEventListener('input', ()=>{
state.sweep=false; sweepBtn.classList.remove('on');
probeLocal.setComponent(i, parseFloat(inp.value)||0);
updateScene(); refresh();
});
l.appendChild(inp); probeRow.appendChild(l); probeInputs[k]=inp;
});
pbSec.appendChild(probeRow);
const preP = pre(pbSec, 'preP');
/* buttons */
const btnRow = document.createElement('div'); btnRow.className='btns';
function mkBtn(label, fn, cls){
const b = document.createElement('button'); b.textContent=label;
if (cls) b.className=cls;
b.addEventListener('click', fn); btnRow.appendChild(b); return b;
}
const sweepBtn = mkBtn('SWEEP PROBE', ()=>{
state.sweep=!state.sweep; sweepBtn.classList.toggle('on', state.sweep);
});
mkBtn('RESET POSE', ()=>{
Object.assign(state.A, { yaw:24*D, pitch:0, roll:0 });
Object.assign(state.B, { yaw:-60*D, pitch:6*D, roll:10*D });
state.B.pos.set(4.4,0,-1.4);
sliders.A.forEach((s,i)=>s.set([24,0,0][i]));
sliders.B.forEach((s,i)=>s.set([-60,6,10][i]));
updateScene(); refresh();
});
mkBtn('RANDOMIZE B', ()=>{
state.B.yaw=(Math.random()*360-180)*D; state.B.pitch=(Math.random()*30-15)*D; state.B.roll=(Math.random()*40-20)*D;
sliders.B[0].set(state.B.yaw/D); sliders.B[1].set(state.B.pitch/D); sliders.B[2].set(state.B.roll/D);
updateScene(); refresh();
});
mkBtn('FOCUS A', ()=>{ cam.panT.copy(state.A.pos).add(new THREE.Vector3(0,1.4,0)); });
mkBtn('FOCUS B', ()=>{ cam.panT.copy(state.B.pos).add(new THREE.Vector3(0,1.4,0)); });
pbSec.appendChild(btnRow);
/* ───────────────────── readout formatting ───────────────────── */
const f3 = n => (n>=0?' ':'-') + Math.abs(n).toFixed(3);
const v3s = v => `${f3(v.x)}, ${f3(v.y)}, ${f3(v.z)}`;
function matText(m){
const e = m.elements, out = [];
for (let r=0;r<4;r++){
const row = [e[r], e[4+r], e[8+r], e[12+r]].map(n => (n>=0?' ':'-')+Math.abs(n).toFixed(3));
out.push('[ ' + row.join(' ') + ' ]');
}
return out.join('\n');
}
function frameText(f, name){
const bx = new THREE.Vector3(1,0,0).applyQuaternion(f.quat);
const by = new THREE.Vector3(0,1,0).applyQuaternion(f.quat);
const bz = new THREE.Vector3(0,0,1).applyQuaternion(f.quat);
const q = f.quat;
return `${name} origin ${v3s(f.pos)}
basis X ${v3s(bx)}
basis Y ${v3s(by)}
basis Z ${v3s(bz)}
quat ${f3(q.x)} ${f3(q.y)} ${f3(q.z)} ${f3(q.w)}`;
}
function refresh(){
preA.textContent = frameText(frames.A, 'A');
preB.textContent = frameText(frames.B, 'B');
const rot = new THREE.Matrix4().extractRotation(T);
const q = new THREE.Quaternion().setFromRotationMatrix(rot);
const e = new THREE.Euler().setFromQuaternion(q, 'XYZ');
const t = new THREE.Vector3(T.elements[12], T.elements[13], T.elements[14]);
preT.textContent =
`T = B⁻¹ · A (A-local → B-local)
${matText(T)}
rot euler° ${(e.x/D).toFixed(1)} ${(e.y/D).toFixed(1)} ${(e.z/D).toFixed(1)}
trans (in B) ${v3s(t)}
T⁻¹ (B→A) origin ${v3s(new THREE.Vector3(Tinv.elements[12],Tinv.elements[13],Tinv.elements[14]))}`;
const pW = probeLocal.clone().applyMatrix4(frames.A.mat);
const pB = probeLocal.clone().applyMatrix4(T);
preP.textContent =
`A-local ${v3s(probeLocal)}
world ${v3s(pW)}
B-local ${v3s(pB)}`;
}
/* ───────────────────── custom camera controls ───────────────────── */
const cam = {
target:new THREE.Vector3(0,1.5,0), panT:new THREE.Vector3(0,1.5,0),
sph:new THREE.Spherical(17, Math.PI*0.47, Math.PI*0.30),
sphT:new THREE.Spherical(17, Math.PI*0.47, Math.PI*0.30)
};
const pointers = new Map();
let mode = 'orbit', lastX=0, lastY=0, pinchDist=0;
canvas.addEventListener('contextmenu', e=>e.preventDefault());
canvas.addEventListener('pointerdown', e=>{
canvas.setPointerCapture(e.pointerId);
pointers.set(e.pointerId, {x:e.clientX, y:e.clientY});
if (pointers.size===2){
const p=[...pointers.values()];
pinchDist = Math.hypot(p[0].x-p[1].x, p[0].y-p[1].y);
} else {
mode = (e.button===2 || e.button===1 || e.shiftKey) ? 'pan' : 'orbit';
lastX=e.clientX; lastY=e.clientY;
}
});
canvas.addEventListener('pointermove', e=>{
if (!pointers.has(e.pointerId)) return;
pointers.set(e.pointerId, {x:e.clientX, y:e.clientY});
if (pointers.size===2){
const p=[...pointers.values()];
const d = Math.hypot(p[0].x-p[1].x, p[0].y-p[1].y);
if (pinchDist>0) cam.sphT.radius = THREE.MathUtils.clamp(cam.sphT.radius*(pinchDist/d), 4, 48);
pinchDist = d; return;
}
const dx = e.clientX-lastX, dy = e.clientY-lastY;
lastX=e.clientX; lastY=e.clientY;
if (mode==='orbit'){
cam.sphT.theta -= dx*0.0055;
cam.sphT.phi = THREE.MathUtils.clamp(cam.sphT.phi - dy*0.0045, 0.08, 1.48);
} else {
const right = new THREE.Vector3(1,0,0).applyQuaternion(camera.quaternion);
const up = new THREE.Vector3(0,1,0).applyQuaternion(camera.quaternion);
const k = cam.sphT.radius*0.0013;
cam.panT.addScaledVector(right, -dx*k).addScaledVector(up, dy*k);
}
});
const release = e=>{ pointers.delete(e.pointerId); if (pointers.size<2) pinchDist=0; };
canvas.addEventListener('pointerup', release);
canvas.addEventListener('pointercancel', release);
canvas.addEventListener('wheel', e=>{
e.preventDefault();
cam.sphT.radius = THREE.MathUtils.clamp(cam.sphT.radius*Math.exp(e.deltaY*0.0011), 4, 48);
}, {passive:false});
/* ───────────────────── loop ───────────────────── */
function onResize(){
camera.aspect = innerWidth/innerHeight; camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
}
addEventListener('resize', onResize);
updateScene(); refresh();
let last = performance.now(), lastReadout = 0;
function animate(){
requestAnimationFrame(animate);
const now = performance.now(), dt = Math.min((now-last)/1000, .05); last = now;
if (state.sweep){
state.sweepT += dt*0.42;
if (state.sweepT > 1) state.sweepT -= 1;
const s = state.sweepT*2-1; // -1 → 1
const z = -3.6 + (s*0.5+0.5)*7.2;
probeLocal.set(0, 1.35, z);
probeInputs.x.value = probeLocal.x.toFixed(2);
probeInputs.y.value = probeLocal.y.toFixed(2);
probeInputs.z.value = probeLocal.z.toFixed(2);
updateProbe();
if (now-lastReadout > 120){ refresh(); lastReadout = now; }
}
// camera damping
cam.sph.radius += (cam.sphT.radius - cam.sph.radius)*0.14;
cam.sph.theta += (cam.sphT.theta - cam.sph.theta)*0.16;
cam.sph.phi += (cam.sphT.phi - cam.sph.phi )*0.16;
cam.target.lerp(cam.panT, 0.18);
camera.position.setFromSpherical(cam.sph).add(cam.target);
camera.lookAt(cam.target);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```