From bba52a5876dc4d5da09c34052d7ab80e63723b73 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Tue, 17 Nov 2026 16:12:31 +0100 Subject: [PATCH 01/34] feat(chrome_theme): let each app choose the theme of the floating chrome GlassCard panels used to force the dark theme. Apps now set ogwFront.chromeTheme in their app.config.ts: "dark" by default (unchanged for current apps), or "inherit" to follow the app's current theme. The ChromeTheme wrapper applies it to content outside a GlassCard (teleported overlays...). --- app/app.config.ts | 17 +++++++++++++++++ app/components/ChromeTheme.vue | 20 ++++++++++++++++++++ app/components/GlassCard.vue | 4 +++- app/composables/chrome_theme.ts | 19 +++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 app/app.config.ts create mode 100644 app/components/ChromeTheme.vue create mode 100644 app/composables/chrome_theme.ts diff --git a/app/app.config.ts b/app/app.config.ts new file mode 100644 index 000000000..cbc9c0c23 --- /dev/null +++ b/app/app.config.ts @@ -0,0 +1,17 @@ +declare module "nuxt/schema" { + interface AppConfigInput { + ogwFront?: { + chromeTheme?: string; + }; + } +} + +// Apps extending this layer override these values in their own app.config.ts. +// oxlint-disable-next-line import/no-default-export +export default defineAppConfig({ + ogwFront: { + // Vuetify theme forced on the floating chrome (GlassCard panels, loading screen...). + // "inherit" makes it follow the app's current theme instead. + chromeTheme: "dark", + }, +}); diff --git a/app/components/ChromeTheme.vue b/app/components/ChromeTheme.vue new file mode 100644 index 000000000..8e3d6a7c0 --- /dev/null +++ b/app/components/ChromeTheme.vue @@ -0,0 +1,20 @@ + + + + + diff --git a/app/components/GlassCard.vue b/app/components/GlassCard.vue index 65a4eb9fd..5925fb1e3 100644 --- a/app/components/GlassCard.vue +++ b/app/components/GlassCard.vue @@ -1,6 +1,7 @@ diff --git a/app/components/csv-preview/CsvTable.vue b/app/components/csv-preview/CsvTable.vue index e5aae8124..44fde07f4 100644 --- a/app/components/csv-preview/CsvTable.vue +++ b/app/components/csv-preview/CsvTable.vue @@ -47,7 +47,7 @@ function getColumnClass(key: string): string { diff --git a/app/utils/orientation_compass.ts b/app/utils/orientation_compass.ts new file mode 100644 index 000000000..3694103a9 --- /dev/null +++ b/app/utils/orientation_compass.ts @@ -0,0 +1,73 @@ +// Heading math of the compass overlay (Viewer/OrientationCompass.vue). Same convention as the VTK +// Compass of OpenGeodeWeb-Viewer (orientation_marker.py): north = world +Y, east = +X, up = +Z. +import type { CameraPose, Vec3, ViewBasis } from "@ogw_front/utils/orientation_gizmo"; + +const DEGREES_PER_HALF_TURN = 180; +const RADIANS_PER_DEGREE = Math.PI / DEGREES_PER_HALF_TURN; +// Under this horizontal length, the screen right is (nearly) vertical: no heading can be read +const MIN_HORIZONTAL_RIGHT = 1e-3; +// The dial is flattened with the camera elevation, down to this ratio so its letters stay readable +const MIN_COMPASS_TILT = 0.6; + +interface DialPoint { + x: number; + y: number; +} + +// Clockwise angle in degrees from north to the direction the camera looks at, on the ground plane. +// Read from the screen right vector, which stays horizontal both for side views and for views +// Straight down or up (where the view direction has no horizontal part). Undefined when the camera +// Is rolled until its right vector is vertical. +function compassHeading(basis: ViewBasis): number | undefined { + const [rightX, rightY] = basis.right; + if (Math.hypot(rightX, rightY) < MIN_HORIZONTAL_RIGHT) { + return undefined; + } + // The ground direction the camera looks at is the screen right turned by a quarter turn + return Math.atan2(-rightY, rightX) / RADIANS_PER_DEGREE; +} + +// Vertical scale of the dial: 1 seen from straight above or below, flatter towards the horizon +function compassTilt(basis: ViewBasis): number { + return Math.max(MIN_COMPASS_TILT, Math.abs(basis.toViewer[2])); +} + +// SVG position (y downwards) of the dial point at the given clockwise angle from north, once the +// Dial is turned by -heading and flattened by tilt +function compassDialPoint(angle: number, radius: number, heading: number, tilt: number): DialPoint { + const screenAngle = (angle - heading) * RADIANS_PER_DEGREE; + return { + x: radius * Math.sin(screenAngle), + y: -radius * Math.cos(screenAngle) * tilt, + }; +} + +function rotateAroundZ(vector: Vec3, angle: number): Vec3 { + const cosine = Math.cos(angle); + const sine = Math.sin(angle); + return [vector[0] * cosine - vector[1] * sine, vector[0] * sine + vector[1] * cosine, vector[2]]; +} + +// Same camera turned around the vertical axis through its focal point so that it looks north +// (keeps the elevation and the distance). Undefined when no heading can be read. +function northUpCameraPose(pose: CameraPose, basis: ViewBasis): CameraPose | undefined { + const heading = compassHeading(basis); + if (heading === undefined) { + return undefined; + } + // A counterclockwise turn by the heading brings the view direction back to north + const angle = heading * RADIANS_PER_DEGREE; + const [focalX, focalY, focalZ] = pose.focal_point; + const offset = rotateAroundZ( + [pose.position[0] - focalX, pose.position[1] - focalY, pose.position[2] - focalZ], + angle, + ); + return { + focal_point: pose.focal_point, + position: [focalX + offset[0], focalY + offset[1], focalZ + offset[2]], + view_up: rotateAroundZ(pose.view_up, angle), + }; +} + +export { MIN_COMPASS_TILT, compassDialPoint, compassHeading, compassTilt, northUpCameraPose }; +export type { DialPoint }; diff --git a/app/utils/orientation_gizmo.ts b/app/utils/orientation_gizmo.ts new file mode 100644 index 000000000..934ace8bf --- /dev/null +++ b/app/utils/orientation_gizmo.ts @@ -0,0 +1,73 @@ +// Camera frame of the orientation overlay (Viewer/OrientationGlobe.vue), drawn by the front over the +// Viewer image. Pure math on the camera pose (position, focal point, view up): no vtk.js nor Vue here. + +type Vec3 = readonly [number, number, number]; + +interface CameraPose { + position: Vec3; + focal_point: Vec3; + view_up: Vec3; +} + +// Camera frame in world coordinates: screen right, screen up, and the direction towards the viewer +interface ViewBasis { + right: Vec3; + upward: Vec3; + toViewer: Vec3; +} + +const EPSILON = 1e-9; +const VECTOR_SIZE = 3; + +function subtract(first: Vec3, second: Vec3): Vec3 { + return [first[0] - second[0], first[1] - second[1], first[2] - second[2]]; +} + +function cross(first: Vec3, second: Vec3): Vec3 { + return [ + first[1] * second[2] - first[2] * second[1], + first[2] * second[0] - first[0] * second[2], + first[0] * second[1] - first[1] * second[0], + ]; +} + +function normalize(vector: Vec3): Vec3 | undefined { + const length = Math.hypot(...vector); + if (length < EPSILON) { + return undefined; + } + return [vector[0] / length, vector[1] / length, vector[2] / length]; +} + +function isVec3(value: unknown): value is Vec3 { + return ( + Array.isArray(value) && + value.length === VECTOR_SIZE && + value.every((item) => typeof item === "number" && Number.isFinite(item)) + ); +} + +// Reads a pose from the loosely typed camera options of the hybrid viewer store +function toCameraPose(options: Record): CameraPose | undefined { + const { position, focal_point, view_up } = options; + if (!isVec3(position) || !isVec3(focal_point) || !isVec3(view_up)) { + return undefined; + } + return { position, focal_point, view_up }; +} + +// Undefined for a degenerate camera (position on the focal point, view up along the view direction) +function cameraViewBasis(pose: CameraPose): ViewBasis | undefined { + const toViewer = normalize(subtract(pose.position, pose.focal_point)); + if (!toViewer) { + return undefined; + } + const right = normalize(cross(pose.view_up, toViewer)); + if (!right) { + return undefined; + } + return { right, upward: cross(toViewer, right), toViewer }; +} + +export { cameraViewBasis, toCameraPose }; +export type { CameraPose, Vec3, ViewBasis }; From 494ce98d647341d09b3e979516a8a549fe969dce Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Wed, 18 Nov 2026 11:56:14 +0100 Subject: [PATCH 07/34] feat(OrientationGlobe): orientation axes on a globe crossed by horizontal strata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The X/Y/Z axes from the center of a sphere crossed by horizontal strata (latitude rings, horizontal in the world, so up and the tilt read at a glance; alternate tone-on-tone fills echo the slices of the Geode Solutions mark), north as the orange dot on the equator, labels in the brand font. A click on a label looks from that axis, a click on the globe shows the plan view; on hover, the view reads as azimuth and elevation (N 030° · 25°). --- app/components/Viewer/OrientationGlobe.vue | 349 ++++++++++++++++++ app/utils/orientation_globe.ts | 145 ++++++++ app/utils/orientation_strata.ts | 119 ++++++ .../unit/utils/orientation_gizmo.nuxt.test.ts | 200 ++++++++++ 4 files changed, 813 insertions(+) create mode 100644 app/components/Viewer/OrientationGlobe.vue create mode 100644 app/utils/orientation_globe.ts create mode 100644 app/utils/orientation_strata.ts create mode 100644 tests/unit/utils/orientation_gizmo.nuxt.test.ts diff --git a/app/components/Viewer/OrientationGlobe.vue b/app/components/Viewer/OrientationGlobe.vue new file mode 100644 index 000000000..c1d58e1cc --- /dev/null +++ b/app/components/Viewer/OrientationGlobe.vue @@ -0,0 +1,349 @@ + + + + + diff --git a/app/utils/orientation_globe.ts b/app/utils/orientation_globe.ts new file mode 100644 index 000000000..9e63dad8f --- /dev/null +++ b/app/utils/orientation_globe.ts @@ -0,0 +1,145 @@ +// Geometry of the orientation globe (Viewer/OrientationGlobe.vue): a sphere crossed by horizontal strata +// (latitude rings, horizontal in the world, so the tilt reads at a glance), the world axes from its +// Center and the north (+Y) on its equator. Pure math on the camera view basis: no vtk.js nor Vue here. +// SVG coordinates: origin at the globe center, y grows downwards. +import type { Vec3, ViewBasis } from "@ogw_front/utils/orientation_gizmo"; + +type GlobeAxis = "x" | "y" | "z"; + +interface GlobeLabel { + axis: GlobeAxis; + // Text drawn at the end of the axis: X, Y or Z + text: string; + // Key of the camera orientation looking from this end (see camera_helpers ORIENTATIONS) + key: string; + // Projected end of the axis, on the sphere + tipX: number; + tipY: number; + // Label position, outside the sphere along the projected axis + x: number; + y: number; + // Component towards the viewer: 1 points at the viewer, -1 away from it + depth: number; + // The axis points (nearly) at or away from the viewer: its label sits next to the center + foreshortened: boolean; +} + +interface RingPaths { + front: string; + back: string; +} + +const DEGREES_PER_HALF_TURN = 180; +const RADIANS_PER_DEGREE = Math.PI / DEGREES_PER_HALF_TURN; +const FULL_TURN_DEGREES = 360; +const RING_SEGMENTS = 96; +// Heights of the latitude rings (unit sphere), the equator in the middle +const STRATA_LINE_HEIGHT = 0.62; +const STRATA_LINES = [STRATA_LINE_HEIGHT, 0, -STRATA_LINE_HEIGHT] as const; +// Gap between the sphere and the labels, in SVG units +const LABEL_GAP = 11; +// Under this projected length (ratio of the radius), the axis points at the viewer +const FORESHORTENED_RATIO = 0.18; +const FORESHORTENED_OFFSET = 8; +const AXES: readonly { axis: GlobeAxis; vector: Vec3; key: string }[] = [ + { axis: "x", vector: [1, 0, 0], key: "xplus" }, + { axis: "y", vector: [0, 1, 0], key: "yplus" }, + { axis: "z", vector: [0, 0, 1], key: "zplus" }, +]; + +function dot(first: Vec3, second: Vec3): number { + return first[0] * second[0] + first[1] * second[1] + first[2] * second[2]; +} + +// Screen position of a point of the unit sphere (world coordinates) for a globe of the given radius +function projectOnGlobe(basis: ViewBasis, radius: number, point: Vec3): [number, number, number] { + return [ + radius * dot(point, basis.right), + -radius * dot(point, basis.upward), + dot(point, basis.toViewer), + ]; +} + +function pathPoint(previous: boolean | undefined, current: boolean, x: number, y: number): string { + const command = previous === current ? "L" : "M"; + return `${command}${x.toFixed(2)} ${y.toFixed(2)}`; +} + +// Latitude ring at the given height of the unit sphere, split into its half facing the viewer and its +// Hidden half (drawn fainter) +function latitudeRing(basis: ViewBasis, radius: number, height: number): RingPaths { + const ringRadius = Math.sqrt(Math.max(0, 1 - height * height)); + let front = ""; + let back = ""; + let previous: boolean | undefined = undefined; + for (let index = 0; index <= RING_SEGMENTS; index += 1) { + const angle = (2 * Math.PI * index) / RING_SEGMENTS; + const [x, y, depth] = projectOnGlobe(basis, radius, [ + ringRadius * Math.cos(angle), + ringRadius * Math.sin(angle), + height, + ]); + const facing = depth >= 0; + if (facing) { + front += pathPoint(previous, true, x, y); + } else { + back += pathPoint(previous === false ? false : undefined, false, x, y); + } + previous = facing; + } + return { front, back }; +} + +function strataRings(basis: ViewBasis, radius: number): (RingPaths & { equator: boolean })[] { + return STRATA_LINES.map((height) => { + const { front, back } = latitudeRing(basis, radius, height); + return { front, back, equator: height === 0 }; + }); +} + +// Axis labels, back to front so the nearest axis is drawn last +function globeLabels(basis: ViewBasis, radius: number): GlobeLabel[] { + const labels: GlobeLabel[] = []; + for (const { axis, vector, key } of AXES) { + const text = axis.toUpperCase(); + const [tipX, tipY, depth] = projectOnGlobe(basis, radius, vector); + const length = Math.hypot(tipX, tipY); + const foreshortened = length < radius * FORESHORTENED_RATIO; + const scale = foreshortened ? 0 : (radius + LABEL_GAP) / length; + labels.push({ + axis, + text, + key, + tipX, + tipY, + x: foreshortened ? FORESHORTENED_OFFSET : tipX * scale, + y: foreshortened ? -FORESHORTENED_OFFSET : tipY * scale, + depth, + foreshortened, + }); + } + return labels.toSorted((first, second) => first.depth - second.depth); +} + +// North (+Y) on the equator +function northPoint(basis: ViewBasis, radius: number): { x: number; y: number; depth: number } { + const [x, y, depth] = projectOnGlobe(basis, radius, [0, 1, 0]); + return { x, y, depth }; +} + +// Angle of the camera above the horizon, in degrees: 90 looking straight down +function cameraElevation(basis: ViewBasis): number { + return Math.asin(Math.max(-1, Math.min(1, basis.toViewer[2]))) / RADIANS_PER_DEGREE; +} + +// Geologist's reading of the view: azimuth of the view direction, then elevation ("N 030° · 25°") +function orientationReadout(heading: number, elevation: number): string { + const azimuth = Math.round( + ((heading % FULL_TURN_DEGREES) + FULL_TURN_DEGREES) % FULL_TURN_DEGREES, + ); + const padded = String(azimuth % FULL_TURN_DEGREES).padStart(3, "0"); + return `N ${padded}° · ${Math.round(elevation)}°`; +} + +export { cameraElevation, globeLabels, latitudeRing, northPoint, orientationReadout, strataRings }; +export type { GlobeAxis, GlobeLabel, RingPaths }; diff --git a/app/utils/orientation_strata.ts b/app/utils/orientation_strata.ts new file mode 100644 index 000000000..1e9874112 --- /dev/null +++ b/app/utils/orientation_strata.ts @@ -0,0 +1,119 @@ +// Strata fills of the orientation globe (Viewer/OrientationGlobe.vue): the sphere is cut by horizontal +// Planes of the world into alternate light and clear layers, like the slices of the Geode Solutions mark. +// Rasterized per pixel with supersampling for smooth edges. Pure math: no vtk.js nor Vue here. +import type { ViewBasis } from "@ogw_front/utils/orientation_gizmo"; + +interface Strata { + // World height range of the stratum on the unit sphere + bottom: number; + top: number; + // Fill opacity, 0 for the strata left clear + opacity: number; +} + +interface StrataSample { + coverage: number; + shade: number; +} + +// Same heights as the latitude rings of the globe (orientation_globe.ts) +const STRATA_LINE_HEIGHT = 0.62; +const LIGHT_OPACITY = 0.62; +const SHADOW_OPACITY = 0.38; +const STRATA: readonly Strata[] = [ + { bottom: STRATA_LINE_HEIGHT, top: 1, opacity: LIGHT_OPACITY }, + { bottom: 0, top: STRATA_LINE_HEIGHT, opacity: 0 }, + { bottom: -STRATA_LINE_HEIGHT, top: 0, opacity: SHADOW_OPACITY }, + { bottom: -1, top: -STRATA_LINE_HEIGHT, opacity: 0 }, +]; +const SUPERSAMPLING = 3; +const SAMPLE_CENTER = 0.5; +const SHADE_BASE = 0.85; +const SHADE_RANGE = 0.15; +const BYTES_PER_PIXEL = 4; +const MAX_CHANNEL = 255; +const RGB_CHANNELS = 3; +const HEX_BASE = 16; +const HEX_CHANNEL_LENGTH = 2; + +// World height of the visible sphere point under the given screen offset, as a ratio of the radius +// (x right, y down). Undefined outside the sphere. +function visibleHeight(basis: ViewBasis, x: number, y: number): number | undefined { + const squared = x * x + y * y; + if (squared > 1) { + return undefined; + } + const towardsViewer = Math.sqrt(1 - squared); + return x * basis.right[2] - y * basis.upward[2] + towardsViewer * basis.toViewer[2]; +} + +// Fill opacity of the stratum at this world height +function strataOpacity(height: number): number { + return STRATA.find(({ bottom, top }) => height >= bottom && height <= top)?.opacity ?? 0; +} + +// "#RRGGBB" to its red, green and blue channels +function hexChannels(color: string): number[] { + return Array.from({ length: RGB_CHANNELS }, (_item, channel) => { + const start = 1 + channel * HEX_CHANNEL_LENGTH; + return Number.parseInt(color.slice(start, start + HEX_CHANNEL_LENGTH), HEX_BASE); + }); +} + +// Coverage and lighting of one sample of the globe (x, y in radius units, y down) +function strataSample(basis: ViewBasis, x: number, y: number): StrataSample { + const height = visibleHeight(basis, x, y); + if (height === undefined) { + return { coverage: 0, shade: 0 }; + } + const coverage = strataOpacity(height); + const towardsViewer = Math.sqrt(Math.max(0, 1 - x * x - y * y)); + return { coverage, shade: coverage * (SHADE_BASE + SHADE_RANGE * towardsViewer) }; +} + +// Supersampled coverage and lighting of one canvas pixel +function strataPixel( + basis: ViewBasis, + column: number, + row: number, + pixelsPerRadius: number, +): StrataSample { + const total: StrataSample = { coverage: 0, shade: 0 }; + for (let index = 0; index < SUPERSAMPLING * SUPERSAMPLING; index += 1) { + const sampleColumn = index % SUPERSAMPLING; + const sampleRow = Math.floor(index / SUPERSAMPLING); + const x = (column + (sampleColumn + SAMPLE_CENTER) / SUPERSAMPLING) / pixelsPerRadius - 1; + const y = (row + (sampleRow + SAMPLE_CENTER) / SUPERSAMPLING) / pixelsPerRadius - 1; + const sample = strataSample(basis, x, y); + total.coverage += sample.coverage; + total.shade += sample.shade; + } + return total; +} + +// RGBA pixels of the strata fills for a square canvas of the given side covering the globe: +// Alternate light and clear layers, like the slices of the brand mark, lit a bit more towards the viewer +function strataPixels(basis: ViewBasis, side: number, color: string): Uint8ClampedArray { + const channels = hexChannels(color); + const pixels = new Uint8ClampedArray(side * side * BYTES_PER_PIXEL); + const pixelsPerRadius = side / 2; + const samples = SUPERSAMPLING * SUPERSAMPLING; + for (let index = 0; index < side * side; index += 1) { + const { coverage, shade } = strataPixel( + basis, + index % side, + Math.floor(index / side), + pixelsPerRadius, + ); + if (coverage > 0) { + const offset = index * BYTES_PER_PIXEL; + for (let channel = 0; channel < RGB_CHANNELS; channel += 1) { + pixels[offset + channel] = (channels[channel] ?? 0) * (shade / coverage); + } + pixels[offset + RGB_CHANNELS] = (MAX_CHANNEL * coverage) / samples; + } + } + return pixels; +} + +export { strataOpacity, strataPixels, visibleHeight }; diff --git a/tests/unit/utils/orientation_gizmo.nuxt.test.ts b/tests/unit/utils/orientation_gizmo.nuxt.test.ts new file mode 100644 index 000000000..f2884d928 --- /dev/null +++ b/tests/unit/utils/orientation_gizmo.nuxt.test.ts @@ -0,0 +1,200 @@ +import { describe, expect, test, vi } from "vitest"; + +import { + type CameraPose, + type Vec3, + type ViewBasis, + cameraViewBasis, + toCameraPose, +} from "@ogw_front/utils/orientation_gizmo"; +import { + type GlobeLabel, + cameraElevation, + globeLabels, + latitudeRing, + northPoint, + orientationReadout, +} from "@ogw_front/utils/orientation_globe"; +import { + MIN_COMPASS_TILT, + compassDialPoint, + compassHeading, + compassTilt, + northUpCameraPose, +} from "@ogw_front/utils/orientation_compass"; +import { strataOpacity, visibleHeight } from "@ogw_front/utils/orientation_strata"; +import { assertDefined } from "@ogw_tests/utils"; + +vi.setConfig({ testTimeout: 10_000 }); + +const RADIUS = 30; +const LABEL_DISTANCE = 41; +const QUARTER_TURN = 90; +const ISO_HEADING = 30; +const ISO_ELEVATION = 25; +const FLAT = 1e-6; +const HALF_TURN = 180; +const LETTER_RADIUS = 26; +const HALF_TILT = 0.5; +const UPPER_STRATUM = 0.9; +const MIDDLE_STRATUM = 0.3; +const DISTANCE = 10; +const PRECISION = 6; +const EAST_HEADING = 90; +const WEST_HEADING = -90; +const ELEVATION_HEIGHT = 5; +const ORIGIN: Vec3 = [0, 0, 0]; +const UP_X: Vec3 = [1, 0, 0]; +const UP_Y: Vec3 = [0, 1, 0]; +const UP_Z: Vec3 = [0, 0, 1]; +const ABOVE: Vec3 = [0, 0, DISTANCE]; +const SOUTH: Vec3 = [0, -DISTANCE, 0]; +const EAST: Vec3 = [DISTANCE, 0, 0]; +const WEST: Vec3 = [-DISTANCE, 0, 0]; + +// Camera at position looking at the origin +function pose(position: Vec3, view_up: Vec3): CameraPose { + return { position, focal_point: ORIGIN, view_up }; +} + +function basisOf(cameraPose: CameraPose): ViewBasis { + return assertDefined(cameraViewBasis(cameraPose), "Expected a valid camera"); +} + +function headingFrom(position: Vec3, view_up: Vec3): number | undefined { + return compassHeading(basisOf(pose(position, view_up))); +} + +function labelsFrom(position: Vec3, view_up: Vec3): GlobeLabel[] { + return globeLabels(basisOf(pose(position, view_up)), RADIUS); +} + +function tiltFrom(position: Vec3, view_up: Vec3): number { + return compassTilt(basisOf(pose(position, view_up))); +} + +function northUpFrom(position: Vec3, view_up: Vec3): CameraPose { + const cameraPose = pose(position, view_up); + return assertDefined(northUpCameraPose(cameraPose, basisOf(cameraPose))); +} + +describe("orientation gizmo projection", () => { + test("reads a camera pose from the camera options", () => { + const options = { position: ABOVE, focal_point: ORIGIN, view_up: UP_Y }; + expect(toCameraPose(options)).toStrictEqual(options); + expect(toCameraPose({})).toBeUndefined(); + expect(toCameraPose({ ...options, position: [0, 0] })).toBeUndefined(); + }); + + test("a degenerate camera has no view basis", () => { + expect(cameraViewBasis(pose(ORIGIN, UP_Z))).toBeUndefined(); + expect(cameraViewBasis(pose(ABOVE, UP_Z))).toBeUndefined(); + }); + + test("seen from +Z with Y up, X labels right and Y up on screen", () => { + const labels = Object.fromEntries(labelsFrom(ABOVE, UP_Y).map((label) => [label.key, label])); + expect(labels.xplus?.x).toBeCloseTo(LABEL_DISTANCE, PRECISION); + // SVG y grows downwards + expect(labels.yplus?.y).toBeCloseTo(-LABEL_DISTANCE, PRECISION); + // Z points at the viewer: its label sits next to the center + expect(labels.zplus?.foreshortened).toBe(true); + }); + + test("draws the labels back to front", () => { + const keys = labelsFrom(EAST, UP_Z).map((label) => label.key); + expect(keys.at(-1)).toBe("xplus"); + }); +}); + +describe("orientation globe strata", () => { + test("seen from the side, the equator is a horizontal line", () => { + const ring = latitudeRing(basisOf(pose(SOUTH, UP_Z)), RADIUS, 0); + const heights = [...ring.front.matchAll(/[ML](?[-\d.]+) (?[-\d.]+)/gu)].map((match) => + Number(match.groups?.y), + ); + expect(heights.length).toBeGreaterThan(0); + expect(heights.every((height) => Math.abs(height) < FLAT)).toBe(true); + }); + + test("reads the world height under the screen, top and side views", () => { + const fromAbove = basisOf(pose(ABOVE, UP_Y)); + const fromSouth = basisOf(pose(SOUTH, UP_Z)); + // From above, the center of the globe is its north pole + expect(visibleHeight(fromAbove, 0, 0)).toBeCloseTo(1, PRECISION); + // From the side, the top of the globe is its north pole + expect(visibleHeight(fromSouth, 0, -1)).toBeCloseTo(1, PRECISION); + expect(visibleHeight(fromSouth, 1, 1)).toBeUndefined(); + }); + + test("alternates filled and clear strata", () => { + expect(strataOpacity(UPPER_STRATUM)).toBeGreaterThan(0); + expect(strataOpacity(MIDDLE_STRATUM)).toBe(0); + expect(strataOpacity(-MIDDLE_STRATUM)).toBeGreaterThan(0); + expect(strataOpacity(-UPPER_STRATUM)).toBe(0); + }); + + test("puts the north on the equator, at +Y", () => { + const north = northPoint(basisOf(pose(ABOVE, UP_Y)), RADIUS); + expect(north.x).toBeCloseTo(0, PRECISION); + expect(north.y).toBeCloseTo(-RADIUS, PRECISION); + }); + + test("reads the view as azimuth and elevation", () => { + const fromAbove = basisOf(pose(ABOVE, UP_Y)); + const fromSouth = basisOf(pose(SOUTH, UP_Z)); + expect(cameraElevation(fromAbove)).toBeCloseTo(QUARTER_TURN, PRECISION); + expect(cameraElevation(fromSouth)).toBeCloseTo(0, PRECISION); + expect(orientationReadout(ISO_HEADING, ISO_ELEVATION)).toBe("N 030° · 25°"); + expect(orientationReadout(WEST_HEADING, 0)).toBe("N 270° · 0°"); + }); +}); + +describe("orientation compass heading", () => { + test("looking north, east and west from the side", () => { + expect(headingFrom(SOUTH, UP_Z)).toBeCloseTo(0, PRECISION); + expect(headingFrom(WEST, UP_Z)).toBeCloseTo(EAST_HEADING, PRECISION); + expect(headingFrom(EAST, UP_Z)).toBeCloseTo(WEST_HEADING, PRECISION); + }); + + test("stays defined looking straight down, from the screen up direction", () => { + expect(headingFrom(ABOVE, UP_Y)).toBeCloseTo(0, PRECISION); + // East up on screen: the camera "looks" east + expect(headingFrom(ABOVE, UP_X)).toBeCloseTo(EAST_HEADING, PRECISION); + }); + + test("has no heading when the camera is rolled until its right is vertical", () => { + expect(headingFrom(SOUTH, UP_X)).toBeUndefined(); + }); + + test("flattens the dial with the elevation", () => { + expect(tiltFrom(ABOVE, UP_Y)).toBeCloseTo(1, PRECISION); + expect(tiltFrom(SOUTH, UP_Z)).toBe(MIN_COMPASS_TILT); + }); + + test("places the dial letters once turned and flattened", () => { + const north = compassDialPoint(0, LETTER_RADIUS, 0, HALF_TILT); + expect(north.x).toBeCloseTo(0, PRECISION); + expect(north.y).toBeCloseTo(-LETTER_RADIUS * HALF_TILT, PRECISION); + // Looking east, north is on the left + const turnedNorth = compassDialPoint(0, LETTER_RADIUS, EAST_HEADING, 1); + expect(turnedNorth.x).toBeCloseTo(-LETTER_RADIUS, PRECISION); + expect(turnedNorth.y).toBeCloseTo(0, PRECISION); + const south = compassDialPoint(HALF_TURN, LETTER_RADIUS, 0, 1); + expect(south.y).toBeCloseTo(LETTER_RADIUS, PRECISION); + }); + + test("turns the camera to face north, keeping its elevation and distance", () => { + const northUp = northUpFrom([-DISTANCE, 0, ELEVATION_HEIGHT], UP_Z); + expect(northUp.position[0]).toBeCloseTo(0, PRECISION); + expect(northUp.position[1]).toBeCloseTo(-DISTANCE, PRECISION); + expect(northUp.position[2]).toBeCloseTo(ELEVATION_HEIGHT, PRECISION); + expect(compassHeading(basisOf(northUp))).toBeCloseTo(0, PRECISION); + }); + + test("turns a top view so that north is up", () => { + const northUp = northUpFrom(ABOVE, UP_X); + expect(northUp.view_up[0]).toBeCloseTo(0, PRECISION); + expect(northUp.view_up[1]).toBeCloseTo(1, PRECISION); + expect(northUp.position[2]).toBeCloseTo(DISTANCE, PRECISION); + }); +}); From 957ac3390ffaf3273cbdf06f92435488ebc216c1 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Wed, 18 Nov 2026 11:56:14 +0100 Subject: [PATCH 08/34] feat(orientation): opt-in front orientation overlay instead of the VTK marker With ogwFront.orientationOverlay (app.config.ts, off by default so other apps keep the VTK marker), the viewer gets the "none" marker and the front draws the scene choice in the bottom right corner: the axes globe or the compass dial, at the same place and size. The scene style and saved projects keep "axes"/"compass". Needs OpenGeodeWeb-Viewer with the "none" marker. --- app/app.config.ts | 4 + app/components/HybridRenderingView.vue | 2 + app/components/Viewer/OrientationOverlay.vue | 43 +++++ app/composables/orientation_overlay.ts | 71 ++++++++ .../project_manager_helpers/reset.ts | 4 + app/stores/viewer.ts | 2 + internal/stores/data_style/scene.ts | 4 +- .../Viewer/OrientationOverlay.nuxt.test.ts | 156 ++++++++++++++++++ 8 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 app/components/Viewer/OrientationOverlay.vue create mode 100644 app/composables/orientation_overlay.ts create mode 100644 tests/unit/components/Viewer/OrientationOverlay.nuxt.test.ts diff --git a/app/app.config.ts b/app/app.config.ts index cbc9c0c23..94f9fa390 100644 --- a/app/app.config.ts +++ b/app/app.config.ts @@ -2,6 +2,7 @@ declare module "nuxt/schema" { interface AppConfigInput { ogwFront?: { chromeTheme?: string; + orientationOverlay?: boolean; }; } } @@ -13,5 +14,8 @@ export default defineAppConfig({ // Vuetify theme forced on the floating chrome (GlassCard panels, loading screen...). // "inherit" makes it follow the app's current theme instead. chromeTheme: "dark", + // Draw the orientation marker (axes or compass) as a front overlay instead of the viewer's VTK + // Marker, which is then hidden (see composables/orientation_overlay.ts). + orientationOverlay: false, }, }); diff --git a/app/components/HybridRenderingView.vue b/app/components/HybridRenderingView.vue index bee68dbbe..4c091d193 100644 --- a/app/components/HybridRenderingView.vue +++ b/app/components/HybridRenderingView.vue @@ -1,6 +1,7 @@ + + + + diff --git a/app/composables/orientation_overlay.ts b/app/composables/orientation_overlay.ts new file mode 100644 index 000000000..7d72fb76a --- /dev/null +++ b/app/composables/orientation_overlay.ts @@ -0,0 +1,71 @@ +import type { ComputedRef } from "vue"; +import type { SceneOrientationWidget } from "@ogw_internal/stores/data_style/types"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; + +// Marker value hiding the VTK orientation marker of the viewer +const NO_VIEWER_MARKER = "none"; + +type ViewerOrientationMarker = SceneOrientationWidget | typeof NO_VIEWER_MARKER; + +// Apps opt in with `ogwFront.orientationOverlay` in their app.config.ts: the front then draws the +// Orientation marker (Viewer/OrientationOverlay.vue) and the viewer draws none. +function readOrientationOverlay(appConfig: ReturnType): boolean { + // The resolved type holds the layer's literal default (false): widen it to the config input type + const ogwFront: { orientationOverlay?: boolean } | undefined = appConfig.ogwFront; + return ogwFront?.orientationOverlay === true; +} + +function isOrientationOverlayEnabled(): boolean { + return readOrientationOverlay(useAppConfig()); +} + +function useOrientationOverlay(): ComputedRef { + const appConfig = useAppConfig(); + return computed(() => readOrientationOverlay(appConfig)); +} + +// Marker sent to the viewer for the scene style choice: the scene style keeps the user's choice +function viewerOrientationMarker(marker: SceneOrientationWidget): ViewerOrientationMarker { + return isOrientationOverlayEnabled() ? NO_VIEWER_MARKER : marker; +} + +interface HideViewerMarkerRequest { + schema: typeof viewer_schemas.opengeodeweb_viewer.viewer.set_orientation_widget; + params: { marker: typeof NO_VIEWER_MARKER }; +} + +// Request hiding the VTK marker, undefined when the app keeps it +function hideViewerMarkerRequest(): HideViewerMarkerRequest | undefined { + if (!isOrientationOverlayEnabled()) { + return undefined; + } + return { + schema: viewer_schemas.opengeodeweb_viewer.viewer.set_orientation_widget, + params: { marker: NO_VIEWER_MARKER }, + }; +} + +// To call after each viewer reset, which brings the VTK axes back +async function hideViewerMarker( + request: (args: HideViewerMarkerRequest) => Promise, +): Promise { + const hideMarker = hideViewerMarkerRequest(); + if (!hideMarker) { + return; + } + try { + await request(hideMarker); + } catch { + // A viewer without the "none" marker keeps drawing its own: not a reason to fail the reset + } +} + +export { + NO_VIEWER_MARKER, + hideViewerMarker, + hideViewerMarkerRequest, + isOrientationOverlayEnabled, + useOrientationOverlay, + viewerOrientationMarker, +}; +export type { ViewerOrientationMarker }; diff --git a/app/composables/project_manager_helpers/reset.ts b/app/composables/project_manager_helpers/reset.ts index f9626997f..5bfd103ec 100644 --- a/app/composables/project_manager_helpers/reset.ts +++ b/app/composables/project_manager_helpers/reset.ts @@ -1,5 +1,6 @@ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; +import { hideViewerMarker } from "@ogw_front/composables/orientation_overlay"; import { releaseViewerDatabase } from "@ogw_front/composables/project_manager_helpers/viewer_session"; import { useBasemapStore } from "@ogw_front/stores/basemap"; import { useCrsStore } from "@ogw_front/stores/crs"; @@ -23,6 +24,9 @@ async function resetProject(): Promise { const resetVisualizationSchema = viewer_schemas.opengeodeweb_viewer.viewer.reset_visualization; const timeout = undefined; await viewerStore.request({ schema: resetVisualizationSchema, timeout }); + await hideViewerMarker(async (args) => { + await viewerStore.request(args); + }); treeviewStore.clear(); await dataStore.clear(); diff --git a/app/stores/viewer.ts b/app/stores/viewer.ts index be56b5506..9856f21fe 100644 --- a/app/stores/viewer.ts +++ b/app/stores/viewer.ts @@ -20,6 +20,7 @@ import { isCloudMode, } from "@ogw_front/utils/stores.js"; import { Status } from "@ogw_front/utils/status"; +import { hideViewerMarker } from "@ogw_front/composables/orientation_overlay"; import { useInfraStore } from "@ogw_front/stores/infra"; import type { @@ -135,6 +136,7 @@ export const useViewerStore = defineStore( schema, timeout, }); + await hideViewerMarker(request); status.value = Status.CONNECTED; } catch (error) { status.value = Status.NOT_CONNECTED; diff --git a/internal/stores/data_style/scene.ts b/internal/stores/data_style/scene.ts index 159ad49ea..3d9af6fd4 100644 --- a/internal/stores/data_style/scene.ts +++ b/internal/stores/data_style/scene.ts @@ -9,6 +9,7 @@ import { getTable } from "@ogw_internal/database/database"; import { useDataStyleState } from "./state"; import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; import { useViewerStore } from "@ogw_front/stores/viewer"; +import { viewerOrientationMarker } from "@ogw_front/composables/orientation_overlay"; // Local constants const text_style_schema = viewer_schemas.opengeodeweb_viewer.viewer.set_text_style; @@ -63,7 +64,8 @@ export function useSceneStyle(): { async function requestOrientationWidget(marker: SceneOrientationWidget): Promise { const result = await viewerStore.request( - { schema: orientation_widget_schema, params: { marker } }, + // With the front overlay, the viewer hides its marker while the scene style keeps the choice + { schema: orientation_widget_schema, params: { marker: viewerOrientationMarker(marker) } }, { response_function: async () => { await saveSceneStyle({ orientation_widget: marker }); diff --git a/tests/unit/components/Viewer/OrientationOverlay.nuxt.test.ts b/tests/unit/components/Viewer/OrientationOverlay.nuxt.test.ts new file mode 100644 index 000000000..29b42b6f8 --- /dev/null +++ b/tests/unit/components/Viewer/OrientationOverlay.nuxt.test.ts @@ -0,0 +1,156 @@ +// oxlint-disable vitest/require-mock-type-parameters +import { afterEach, describe, expect, test, vi } from "vitest"; +import type { VueWrapper } from "@vue/test-utils"; +import { mountSuspended } from "@nuxt/test-utils/runtime"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; + +import { + hideViewerMarker, + hideViewerMarkerRequest, + viewerOrientationMarker, +} from "@ogw_front/composables/orientation_overlay"; +import { mockAs, setupActivePinia, vuetify } from "@ogw_tests/utils"; +import type { CameraOptions } from "@ogw_internal/stores/hybrid_viewer/vtk_types"; +import OrientationOverlay from "@ogw_front/components/Viewer/OrientationOverlay.vue"; +import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; +import { useDataStyleStore } from "@ogw_front/stores/data_style"; +import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; +import { useViewerStore } from "@ogw_front/stores/viewer"; + +vi.setConfig({ testTimeout: 10_000 }); + +const DISTANCE = 10; +const HEIGHT = 5; +const VIEW_ANGLE = 30; +const OVERLAY = '[data-testid="orientationOverlay"]'; +const AXES = '[data-testid="orientationGlobe"]'; +const COMPASS = '[data-testid="orientationCompass"]'; +const { set_orientation_widget } = viewer_schemas.opengeodeweb_viewer.viewer; + +function setOrientationOverlay(enabled: boolean): void { + // The resolved app config type holds the layer's literal default + Object.assign(useAppConfig().ogwFront, { orientationOverlay: enabled }); +} + +// Camera looking east from the west of the scene, a bit above it +function setCamera(): void { + Object.assign(useHybridViewerStore().camera_options, { + position: [-DISTANCE, 0, HEIGHT], + focal_point: [0, 0, 0], + view_up: [0, 0, 1], + view_angle: VIEW_ANGLE, + clipping_range: [1, DISTANCE * DISTANCE], + distance: Math.hypot(DISTANCE, HEIGHT), + }); +} + +async function mountOverlay(): Promise { + const pinia = setupActivePinia(); + setCamera(); + const wrapper = await mountSuspended(OrientationOverlay, { + global: { plugins: [vuetify, pinia] }, + }); + return wrapper; +} + +function count(wrapper: VueWrapper, selector: string): number { + return wrapper.findAll(selector).length; +} + +describe("orientation overlay", () => { + afterEach(() => { + setOrientationOverlay(false); + }); + + test("renders nothing when the app keeps the VTK marker", async () => { + setOrientationOverlay(false); + const wrapper = await mountOverlay(); + expect(count(wrapper, OVERLAY)).toBe(0); + }); + + test("renders the axes globe, whose labels align the camera", async () => { + setOrientationOverlay(true); + const wrapper = await mountOverlay(); + expect(count(wrapper, OVERLAY)).toBe(1); + expect(count(wrapper, AXES)).toBe(1); + expect(count(wrapper, COMPASS)).toBe(0); + const hybridViewerStore = useHybridViewerStore(); + hybridViewerStore.setCameraOrientation = mockAs( + vi.fn(), + ); + await wrapper.get('[data-testid="orientationGlobe-xplus"]').trigger("click"); + expect(hybridViewerStore.setCameraOrientation).toHaveBeenCalledWith("xplus"); + }); + + test("renders the compass dial, which turns the camera to the north", async () => { + setOrientationOverlay(true); + const wrapper = await mountOverlay(); + useDataStyleState().sceneStyle.value = { + ...useDataStyleStore().sceneStyle, + orientation_widget: "compass", + }; + await wrapper.vm.$nextTick(); + expect(count(wrapper, AXES)).toBe(0); + const setCameraMock = vi.fn<(options: CameraOptions) => void>(); + const hybridViewerStore = useHybridViewerStore(); + hybridViewerStore.setCamera = setCameraMock; + expect(count(wrapper, COMPASS)).toBe(1); + await wrapper.get(COMPASS).trigger("click"); + const target = setCameraMock.mock.calls[0]?.[0]; + expect(target?.position[0]).toBeCloseTo(0); + expect(target?.position[1]).toBeCloseTo(-DISTANCE); + expect(target?.position[2]).toBeCloseTo(HEIGHT); + }); +}); + +describe("orientation marker sent to the viewer", () => { + afterEach(() => { + setOrientationOverlay(false); + }); + + test("is the scene style choice without the overlay", () => { + setOrientationOverlay(false); + expect(viewerOrientationMarker("compass")).toBe("compass"); + expect(hideViewerMarkerRequest()).toBeUndefined(); + }); + + test("hides the VTK marker after a viewer reset only with the overlay", async () => { + const request = vi.fn(async () => { + await Promise.reject(new Error("unknown marker")); + }); + setOrientationOverlay(false); + await hideViewerMarker(request); + expect(request).not.toHaveBeenCalled(); + setOrientationOverlay(true); + // An older viewer rejecting the "none" marker does not fail the reset + await expect(hideViewerMarker(request)).resolves.toBeUndefined(); + expect(request).toHaveBeenCalledWith({ + schema: set_orientation_widget, + params: { marker: "none" }, + }); + }); + + test("is none with the overlay, the scene style keeping the choice", async () => { + setupActivePinia(); + setOrientationOverlay(true); + expect(viewerOrientationMarker("compass")).toBe("none"); + expect(hideViewerMarkerRequest()).toStrictEqual({ + schema: set_orientation_widget, + params: { marker: "none" }, + }); + const viewerStore = useViewerStore(); + viewerStore.request = mockAs( + vi.fn(async (_args: unknown, callbacks: { response_function?: () => Promise }) => { + await callbacks.response_function?.(); + }), + ); + const dataStyleStore = useDataStyleStore(); + await dataStyleStore.setSceneOrientationWidget("compass"); + expect(viewerStore.request).toHaveBeenCalledWith( + { schema: set_orientation_widget, params: { marker: "none" } }, + // oxlint-disable-next-line no-unsafe-assignment -- expect.any(Function) is untyped by design + { response_function: expect.any(Function) }, + ); + expect(dataStyleStore.sceneStyle.orientation_widget).toBe("compass"); + }); +}); From 351c30e947b3831c148d4f9ebef6363b2adb2047 Mon Sep 17 00:00:00 2001 From: Tao Schiro Date: Wed, 18 Nov 2026 13:47:11 +0100 Subject: [PATCH 09/34] feat(ObjectTree): CSS hooks for the panel inset, radii, padding and toolbar icons Apps can align the object tree panels on their own shape system. The fallbacks keep the former look (16 px radius, 10 px padding, 28 px toolbar icons). --- .../Viewer/ObjectTree/Base/CommonTreeView.vue | 2 +- .../Viewer/ObjectTree/Base/Controls.vue | 16 ++++++++++++++-- app/components/Viewer/ObjectTree/Box.vue | 4 ++-- app/components/Viewer/ObjectTree/Layout.vue | 18 ++++++++++-------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/components/Viewer/ObjectTree/Base/CommonTreeView.vue b/app/components/Viewer/ObjectTree/Base/CommonTreeView.vue index c72ff9d9e..c9efedd57 100644 --- a/app/components/Viewer/ObjectTree/Base/CommonTreeView.vue +++ b/app/components/Viewer/ObjectTree/Base/CommonTreeView.vue @@ -293,7 +293,7 @@ const { handleKeyDown } = useTreeKeyboardNav( .tree-row-wrapper { min-height: 28px !important; cursor: pointer; - border-radius: 4px; + border-radius: var(--ogw-viewer-row-radius, 4px); margin: 0 2px; } diff --git a/app/components/Viewer/ObjectTree/Base/Controls.vue b/app/components/Viewer/ObjectTree/Base/Controls.vue index 4c265fb66..ef6978875 100644 --- a/app/components/Viewer/ObjectTree/Base/Controls.vue +++ b/app/components/Viewer/ObjectTree/Base/Controls.vue @@ -40,10 +40,10 @@ watch(