Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ arrow keys to look around, and use the wheel to zoom. Arrows inside the photogra
heading. The minimap remains available while the photo panel is open. The generated HTML embeds the photographs.

Use **Enlarge** to expand a panorama. Pick a minimap size, drag the plan to pan it and use the wheel or the zoom buttons to change its scale.
The blue spheres mark camera positions in the 3D view. Click a sphere to open its panorama. Use **Panorama spheres in 3D**
on the minimap to hide or show the spheres. The spheres follow the selected height band and the model's visibility.
The **+** beside the level list starts a level from two clicks in a panorama, lower elevation first. Each elevation comes from the
sampled scan point at that location. Selecting a level filters the map points and stations to that height range. Clear station groups
separated vertically by more than 2 m can create levels automatically. Use **All heights** to return to the full plan. Level ranges
Expand Down
380 changes: 190 additions & 190 deletions src/IOViewer/Viewer/dist/viewer.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/IOViewer/Viewer/src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const dictionaries = {
'scanMap.plan': 'План облака точек',
'scanMap.metres': 'м',
'scanMap.choosePhoto': 'Открыть фотопанораму…',
'scanMap.spheres': 'Сферы панорам в 3D',
'scanMap.photo': 'Фотопанорама',
'scanMap.goToStation': 'Перейти к станции {name}',
'scanMap.photoControls': 'Фотопанорама. Стрелки поворачивают камеру, колесо меняет масштаб.',
Expand Down Expand Up @@ -174,6 +175,7 @@ const dictionaries = {
'scanMap.plan': 'Point cloud floor plan',
'scanMap.metres': 'm',
'scanMap.choosePhoto': 'Open photo panorama…',
'scanMap.spheres': 'Panorama spheres in 3D',
'scanMap.photo': 'Photo panorama',
'scanMap.goToStation': 'Move to station {name}',
'scanMap.photoControls': 'Photo panorama. Arrow keys turn the camera, the wheel zooms.',
Expand Down
11 changes: 10 additions & 1 deletion src/IOViewer/Viewer/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { mountClashes } from './ui/clashesPanel.js';
import { mountTimeliner } from './ui/timeliner.js';
import { mountLinks } from './ui/linksPanel.js';
import { mountScanMap } from './ui/scanMap.js';
import { createPanoramaSpheres } from './ui/panoramaSpheres.js';

document.documentElement.lang = lang;
const canvas = document.getElementById('ioviewer-canvas');
Expand Down Expand Up @@ -89,6 +90,8 @@ function start(data, context) {
const motionDetail = new MotionDetail(scene, requestRender, Math.min(scene.totalCost, 20e6));
world.add(scene.root);
world.add(points.root);
const panoramaSpheres = points.count ? createPanoramaSpheres(data.meta.panoramas) : null;
if (panoramaSpheres) world.add(panoramaSpheres.mesh);
const visibleBox = () => scene.visibleBox();
// Sections never change which elements are shown, so they leave the bounds (orbit pivot, near/far) as they are.
const sections = new Sections(scene, visibleBox(), data.meta.sections);
Expand Down Expand Up @@ -138,6 +141,7 @@ function start(data, context) {
if (contextLost) return;
const rect = canvas.getBoundingClientRect();
controls.camera.updateMatrixWorld(); // the screen labels project with it before render() would update it
if (scanMap) panoramaSpheres?.update(controls.camera, rect, scanMap.showSphere);
sectionGizmo.update(controls.camera);
measure.update(controls.camera, rect);
grids.update(controls.camera, rect);
Expand Down Expand Up @@ -264,6 +268,11 @@ function start(data, context) {
if (target) measure.add(target.point);
return;
}
const station = !ctrl && !shift ? panoramaSpheres?.pick(x, y) : undefined;
if (station !== undefined) {
scanMap.open(station);
return;
}
const hit = picker.pick(x, y);
const element = hit?.element ?? -1;
if (ctrl) {
Expand Down Expand Up @@ -294,7 +303,7 @@ function start(data, context) {
renderer.setSize(window.innerWidth, window.innerHeight, false);
controls.resize(); // also schedules the first frame for an empty model
controls.fitBox(visibleBox(), false);
mountScanMap(uiRoot, data, points, scene, controls);
const scanMap = mountScanMap(uiRoot, data, points, scene, controls, requestRender);
const viewCube = new ViewCube(document.getElementById('ioviewer-ui'), camera, controls); // home = this load view

// The canvas and the view cube take no focus, so a press on them takes it from a panel field or a toolbar button:
Expand Down
56 changes: 56 additions & 0 deletions src/IOViewer/Viewer/src/ui/panoramaSpheres.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as THREE from 'three';

const radiusPixels = 7;

export function createPanoramaSpheres(panoramas) {
if (!panoramas?.length) return null;
const positions = panoramas.map(({ position }) => new THREE.Vector3(...position));
// Keep camera stations discoverable inside rooms and behind dense point clouds.
const material = new THREE.MeshPhongMaterial({ color: '#72bfff', depthTest: false, depthWrite: false });
const mesh = new THREE.InstancedMesh(new THREE.SphereGeometry(1, 12, 8), material, panoramas.length);
mesh.count = 0;
mesh.frustumCulled = false;
mesh.renderOrder = 10;
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);

const screen = [];
const matrix = new THREE.Matrix4();
const point = new THREE.Vector3();
const view = new THREE.Vector2();

return {
mesh,
update(camera, rect, visible) {
mesh.count = 0;
screen.length = 0;
if (rect.width <= 0 || rect.height <= 0) return;
for (const [index, position] of positions.entries()) {
if (!visible(panoramas[index].element, position.z)) continue;
const depth = -point.copy(position).applyMatrix4(camera.matrixWorldInverse).z;
if (depth <= camera.near || depth >= camera.far) continue;
point.copy(position).project(camera);
if (!Number.isFinite(point.x) || !Number.isFinite(point.y)) continue;
const x = (point.x + 1) * rect.width / 2;
const y = (1 - point.y) * rect.height / 2;
if (x < -radiusPixels || x > rect.width + radiusPixels ||
y < -radiusPixels || y > rect.height + radiusPixels) continue;

const height = camera.isOrthographicCamera
? (camera.top - camera.bottom) / camera.zoom
: camera.getViewSize(depth, view).y;
const radius = radiusPixels * height / rect.height;
mesh.setMatrixAt(mesh.count++, matrix.makeScale(radius, radius, radius).setPosition(position));
screen.push({ index, depth, x: x + rect.left, y: y + rect.top });
}
mesh.instanceMatrix.needsUpdate = mesh.count > 0;
},
pick(x, y) {
let nearest;
for (const station of screen) {
if ((!nearest || station.depth < nearest.depth) &&
Math.hypot(station.x - x, station.y - y) <= radiusPixels) nearest = station;
}
return nearest?.index;
},
};
}
14 changes: 13 additions & 1 deletion src/IOViewer/Viewer/src/ui/scanMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function pickPhotoElevation(camera, origin, objects, x, y, width, height)
return undefined;
}

export function mountScanMap(root, data, points, scene, controls) {
export function mountScanMap(root, data, points, scene, controls, requestRender) {
if (!points.count) return;
const bounds = new THREE.Box3().setFromObject(points.root);
if (bounds.isEmpty()) return;
Expand Down Expand Up @@ -72,6 +72,7 @@ export function mountScanMap(root, data, points, scene, controls) {
}
let levels = saved ?? autoLevels();
let selectedLevel = -1;
let showSpheres = true;
const inLevel = (z) => levelContains(levels[selectedLevel], z + offsetZ);

const panel = document.createElement('details');
Expand Down Expand Up @@ -227,6 +228,7 @@ export function mountScanMap(root, data, points, scene, controls) {
removeLevel.disabled = selectedLevel < 0;
for (const [i, position] of positions.entries()) selector.options[i + 1].hidden = !inLevel(position.z);
redraw();
requestRender();
}
levelSelect.addEventListener('change', () => {
selectedLevel = Number(levelSelect.value);
Expand Down Expand Up @@ -261,6 +263,15 @@ export function mountScanMap(root, data, points, scene, controls) {
refreshLevels();
});
levelControls.append(levelSelect, addLevel, auto, removeLevel);
if (panoramas.length) {
const spheres = mapButton(t('scanMap.spheres'), '◉', () => {
showSpheres = !showSpheres;
spheres.setAttribute('aria-pressed', String(showSpheres));
requestRender();
});
spheres.setAttribute('aria-pressed', 'true');
levelControls.append(spheres);
}
panel.append(levelControls, levelStatus);
const photo = panoramas.length ? photoPanel(root, data, points, show, (pose) => {
photoPose = pose;
Expand Down Expand Up @@ -304,6 +315,7 @@ export function mountScanMap(root, data, points, scene, controls) {
// Selecting the same station again should open its photo.
selector.value = '';
}
return { open: show, showSphere: (element, z) => showSpheres && inLevel(z) && scene.isVisible(element) };
}

function photoPanel(root, data, points, show, onPose, onLevel) {
Expand Down
4 changes: 4 additions & 0 deletions src/IOViewer/Viewer/styles/viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ input:focus-visible {
cursor: pointer;
}

.scan-map-controls button[aria-pressed='true'] {
color: #72bfff;
}

.scan-map-controls button:disabled {
opacity: .48;
cursor: default;
Expand Down
34 changes: 34 additions & 0 deletions src/IOViewer/Viewer/test/unit/scanMap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,40 @@ import assert from 'node:assert/strict';
import * as THREE from 'three';
import { photoDirection, photoDrag, pickPhotoElevation } from '../../src/ui/scanMap.js';
import { detectScanLevels, levelContains, mapZoom } from '../../src/ui/scanLevels.js';
import { createPanoramaSpheres } from '../../src/ui/panoramaSpheres.js';

test('panorama spheres pick the nearest station, respect visibility and stay small when zooming', () => {
const stations = createPanoramaSpheres([
{ position: [0, 0, -4], element: 0 },
{ position: [0, 0, -10], element: 1 },
{ position: [0, 0, 4], element: 2 },
]);
const rect = { left: 50, top: 20, width: 800, height: 600 };
const camera = new THREE.PerspectiveCamera(45, 4 / 3, .1, 20);
camera.updateMatrixWorld();
stations.update(camera, rect, () => true);
assert.equal(stations.mesh.count, 2);
assert.equal(stations.pick(450, 320), 0);
assert.equal(stations.pick(458, 320), undefined);

camera.zoom = 2;
camera.updateProjectionMatrix();
stations.update(camera, rect, (element) => element !== 0);
assert.equal(stations.mesh.count, 1);
assert.equal(stations.pick(456, 320), 1);
assert.equal(stations.pick(458, 320), undefined);

stations.update(camera, rect, () => false);
assert.equal(stations.mesh.count, 0);
assert.equal(stations.pick(450, 320), undefined);

const ortho = new THREE.OrthographicCamera(-4, 4, 3, -3, .1, 20);
ortho.updateMatrixWorld();
stations.update(ortho, rect, () => true);
assert.equal(stations.mesh.count, 2);
assert.equal(stations.pick(450, 320), 0);
assert.equal(createPanoramaSpheres([]), null);
});

test('a panorama feature follows the pointer on both screen axes', () => {
const camera = new THREE.PerspectiveCamera(72, 1.5, .1, 20);
Expand Down