A virtual tour is simple geometry and a memory problem
A virtual property tour looks like a 3D graphics problem. In most cases it is not: each room is a 360-degree panoramic photo, the "scene" is a sphere with that photo inside it, and the camera sits still at the centre and rotates. The mathematical part is short and fits in twenty lines. The real problems are two others: knowing where to put the clickable points (the doors to the next room) so that they stay anchored to the photo when the user rotates, and not exhausting the graphics card's memory, especially on phones.
This article shows both with code run in Node 24: the projection that links the pixels of a panorama to directions in space, and the memory count. I do not show Three.js code or a complete viewer because they were not available on the test machine: I prefer to explain what those components compute inside, which is what you need in order to fix them when they break. The actual drawing is done by a library; the Three.js documentation is the place to look for its perspective camera.
From pixel to direction: the equirectangular projection
360-degree cameras almost always produce equirectangular images: a rectangle twice as wide as it is tall, where the horizontal coordinate is the rotation angle (from -180 to +180 degrees) and the vertical one is the inclination (from +90 at the top to -90 at the bottom). Every pixel therefore corresponds to a direction. To place a door you need to know which direction its pixel corresponds to, and to know whether it is visible at the moment you need to know where it falls on the screen.
// Equirectangular panorama: the horizontal axis is the rotation angle (yaw, -180..180 degrees),
// the vertical one is the inclination (pitch, +90 at the top .. -90 at the bottom).
const rad = (g: number) => (g * Math.PI) / 180;
const gradi = (r: number) => (r * 180) / Math.PI;
// Pixel -> direction in space (unit vector). z axis forward, x to the right, y up.
function direzioneDaPixel(px: number, py: number, larghezza: number, altezza: number) {
const yaw = (px / larghezza - 0.5) * 2 * Math.PI;
const pitch = (0.5 - py / altezza) * Math.PI;
return { x: Math.cos(pitch) * Math.sin(yaw), y: Math.sin(pitch), z: Math.cos(pitch) * Math.cos(yaw) };
}
// Direction -> pixel (the inverse operation, to place a hotspot).
function pixelDaDirezione(d: { x: number; y: number; z: number }, larghezza: number, altezza: number) {
const yaw = Math.atan2(d.x, d.z);
const pitch = Math.asin(d.y);
return { px: (yaw / (2 * Math.PI) + 0.5) * larghezza, py: (0.5 - pitch / Math.PI) * altezza };
}
// Direction -> position on screen, for a camera fixed at (yawCam, pitchCam) with vertical field of view fov.
function suSchermo(d: { x: number; y: number; z: number }, yawCam: number, pitchCam: number, fov: number, aspetto: number) {
const cy = Math.cos(rad(-yawCam)), sy = Math.sin(rad(-yawCam));
const x1 = d.x * cy + d.z * sy, z1 = -d.x * sy + d.z * cy; // rotate around y
const cp = Math.cos(rad(-pitchCam)), sp = Math.sin(rad(-pitchCam));
const y2 = d.y * cp - z1 * sp, z2 = d.y * sp + z1 * cp; // rotate around x
if (z2 <= 0) return null; // behind the camera
const t = Math.tan(rad(fov) / 2);
const nx = x1 / z2 / (t * aspetto), ny = y2 / z2 / t; // -1..1 on screen
return Math.abs(nx) > 1 || Math.abs(ny) > 1 ? null : { x: (nx + 1) / 2, y: (1 - ny) / 2 };
}
const W = 8192, H = 4096;
// 1) round trip: a pixel becomes a direction and returns to the same pixel
const d = direzioneDaPixel(6144, 1024, W, H);
const ritorno = pixelDaDirezione(d, W, H);
console.log('andata e ritorno:', ritorno.px.toFixed(3), ritorno.py.toFixed(3));
// 2) a hotspot at yaw 90 degrees, pitch 0 (a door) is visible if you look right, not if you look straight ahead
const porta = { x: Math.sin(rad(90)), y: 0, z: Math.cos(rad(90)) };
console.log('porta, camera yaw 0 :', suSchermo(porta, 0, 0, 70, 16 / 9));
console.log('porta, camera yaw 90:', suSchermo(porta, 90, 0, 70, 16 / 9));
console.log('porta, camera yaw 180 (alle spalle):', suSchermo(porta, 180, 0, 70, 16 / 9));
// 3) waste at the poles: one degree of rotation (yaw) covers an ever shorter arc as you go up.
// At the poles there are many horizontal pixels for each degree of arc actually seen.
for (const pitch of [0, 60, 80]) {
const pixelPerGradoDArco = W / 360 / Math.cos(rad(pitch));
console.log(`pitch ${String(pitch).padStart(2)}: ${pixelPerGradoDArco.toFixed(1)} pixel orizzontali per grado d'arco`);
}
// Output:
// andata e ritorno: 6144.000 1024.000
// porta, camera yaw 0 : null
// porta, camera yaw 90: { x: 0.5, y: 0.5 }
// porta, camera yaw 180 (alle spalle): null
// pitch 0: 22.8 pixel orizzontali per grado d'arco
// pitch 60: 45.5 pixel orizzontali per grado d'arco
// pitch 80: 131.0 pixel orizzontali per grado d'arco
The two functions direzioneDaPixel and pixelDaDirezione are the inverse of each
other: the first turns the pixel into a unit vector with the sine and cosine of the angle and inclination,
the second uses atan2 and asin to go back. The output
6144.000 1024.000 confirms that the round trip returns the same pixel: it is the minimal test
worth always doing when you write a projection, because a wrong sign produces mirrored or upside-down
hotspots that to the eye look "almost right". The suSchermo function rotates the direction
according to the camera and projects it with the tangent of the field of view; if the depth is negative,
the point is behind the camera and must not be drawn.
The example with the door at 90 degrees shows it: with the camera straight ahead (yaw 0) the door is not
visible (null), because it lies outside the 70-degree vertical field of view with a 16:9
ratio; with the camera at 90 degrees it falls exactly in the centre of the screen (0.5, 0.5); with the
camera at 180 it is behind, so null again. The "behind" case is the classic defect of anyone who
uses only the first part of the formula: without the depth check, a hotspot behind the camera is projected
anyway, mirrored, and appears on screen where it should not.
The last three lines of the output explain why equirectangular photos are awkward: at pitch 0 each degree of arc has 22.8 horizontal pixels, at 60 degrees it has 45.5 and at 80 degrees 131.0. Going up towards the ceiling the image contains many more pixels than the scene actually shows: wasted pixels precisely where there is usually less to see. The cube format (six square faces) distributes pixels more evenly, at the cost of a conversion and of seams to handle at the face edges.
Memory: the count nobody does before publishing
An uncompressed texture occupies width times height times four bytes (one byte per red, green, blue and alpha channel). With mipmaps, the reduced versions the GPU uses when the image is distant or small, about a third is added: the MDN WebGL best practices guide indicates a cost of 33% for square textures, which for the series 1 + 1/4 + 1/16 + ... equals 4/3 for power-of-two rectangular ones as well.
// GPU memory of an uncompressed texture: width x height x 4 bytes (RGBA).
// With mipmaps (levels reduced to half the side) about a third is added: 1 + 1/4 + 1/16 + ... = 4/3.
const MiB = 1024 * 1024;
function memoria(w: number, h: number, mipmap: boolean): number {
const base = w * h * 4;
return mipmap ? base * (4 / 3) : base;
}
console.log('panorama equirettangolare (2:1)');
for (const w of [2048, 4096, 8192, 16384]) {
const h = w / 2;
console.log(` ${w}x${h}: ${(memoria(w, h, false) / MiB).toFixed(0)} MiB, con mipmap ${(memoria(w, h, true) / MiB).toFixed(0)} MiB`);
}
// One room = one panorama. A tour of N rooms, if you keep ALL of them in GPU memory:
const stanze = 12;
const per8k = memoria(8192, 4096, true) * stanze;
console.log(`12 stanze a 8192x4096 con mipmap, tutte caricate: ${(per8k / 1024 / MiB).toFixed(2)} GiB`);
// The side of an equivalent cube face has the same angular resolution at the horizon: width / 4.
console.log('faccia cubica equivalente a 8192 di larghezza:', 8192 / 4, 'pixel di lato');
// Output:
// panorama equirettangolare (2:1)
// 2048x1024: 8 MiB, con mipmap 11 MiB
// 4096x2048: 32 MiB, con mipmap 43 MiB
// 8192x4096: 128 MiB, con mipmap 171 MiB
// 16384x8192: 512 MiB, con mipmap 683 MiB
// 12 stanze a 8192x4096 con mipmap, tutte caricate: 2.00 GiB
// faccia cubica equivalente a 8192 di larghezza: 2048 pixel di lato
The numbers say two things. Going from 4096 to 8192 pixels of width does not double the memory, it
quadruples it: from 32 to 128 MiB, which become 171 with mipmaps. And a tour of twelve rooms, if you keep
them all loaded in graphics memory, takes 2.00 GiB: well beyond what an average phone tolerates before the
browser loses the graphics context and shows a black screen. The exact limit depends on the device and I do
not know it: the WebGL specification exposes the maximum size of a texture as a parameter to query with
getParameter, and the total memory available cannot be queried reliably, so you design with a
margin instead of trying to measure it.
The standard strategies are three, and they combine. The first is to load only the current room plus those linked by the visible doors, and release the others. The second is to start with a small version (2048 wide, 8 MiB without mipmaps) and replace it with a large one only when the user stays still or zooms in. The third is to use compressed texture formats: MDN notes that compressed formats are smaller in GPU memory, with lower quality than JPG and PNG, a compromise to assess on your own images. Which resolution to choose depends on the audience: a portal used mostly from phones tolerates fewer pixels than one for desktop workstations, and this decision is made with the data of the people who use your site, not here.
Virtual reality: an optional extension, never a requirement
The W3C defines the WebXR API, and its isSessionSupported method is for asking the browser
whether an immersive mode (for example immersive-vr) is available before showing the button.
The tour must work perfectly well without it: the on-screen visit is the one almost everyone will use, and
headset mode is an addition for those with the hardware. The block that follows is a schema to
adapt: it uses browser functions, does not run in Node and I did not run it.
// SCHEMA TO ADAPT: uses browser APIs (navigator.xr), so it does not run in Node and was not run.
export async function modalitaVrDisponibile(): Promise<boolean> {
const xr = (navigator as Navigator & { xr?: { isSessionSupported(m: string): Promise<boolean> } }).xr;
if (!xr) return false; // browser without WebXR: the tour stays in 2D
try {
return await xr.isSessionSupported('immersive-vr');
} catch {
return false; // permissions or site policy: no error shown to the user
}
}
The block does two things that matter. If the browser has no navigator.xr it returns false
without errors, so the button does not appear and the tour stays in 2D. And it wraps the call in
try/catch, because the request can be denied by a site policy or a permission: to the user it
must be indistinguishable from "not available", not an error message about a feature they did not ask for.
As with the device checks, the test must be done with a real headset.
What is not here, and where to look for it
There are no conversion or dwell-time metrics here: I have no primary source that supports them and I do not report them. Server-side processing of the photos (stitching the shots, generating the multi-resolution versions) is pipeline work that follows the pattern of the article on the platform architecture. To place the tour on a page together with the map and the search by zone, see geospatial search, and to link the rooms of the tour to those of the building model, the BIM model.
What you can do now
You can go from a pixel of a panorama to a direction and back, and you can decide with a calculation whether a hotspot is visible and where to draw it, remembering the depth check. You can estimate the memory of a tour before publishing it and you have three strategies to keep it under control. You can treat virtual reality as an optional feature with a silent fallback. What remains to be done, with a real device, is to measure the limits of your users' phones and choose resolutions accordingly.
In this series, the next article is PropTech Compliance: Fair Housing and Algorithmic Bias.
Sources
- Khronos, WebGL Specification 1.0 - the MAX_TEXTURE_SIZE parameter and querying limits with getParameter, accessed on 2026-11-12
- MDN, WebGL best practices - the memory cost of mipmaps (about 33%) and the trade-off of compressed texture formats, accessed on 2026-11-12
- W3C, WebXR Device API - the isSessionSupported method for checking an immersive mode, accessed on 2026-11-12
- three.js, PerspectiveCamera - the perspective camera that implements the projection described in the text, accessed on 2026-11-12
The two TypeScript listings were run with Node 24 on 2026-11-12. The WebXR block is a schema to adapt and was not run. The memory figures are arithmetic declared in the listing, not measurements on a device.

Commenti
Caricamento commenti...
Sign in to comment