diff --git a/e2e/viewer-spike.spec.ts b/e2e/viewer-spike.spec.ts new file mode 100644 index 00000000..687604ab --- /dev/null +++ b/e2e/viewer-spike.spec.ts @@ -0,0 +1,147 @@ +import { resolve } from 'node:path' +import { expect, test, type Page } from '@playwright/test' + +// Capture-review 3D view on the PuzlWerk viewer (spike); `?viewer=puzlwerk` selects it. +const fixtures = [ + ['4x4', 'test/fixtures/synthetic-4x4-high.zip', 4], + ['5x5', 'test/fixtures/orientation-recovery-5x5.zip', 5], + ['7x7', 'test/fixtures/orientation-recovery-7x7.zip', 7], +] as const + +async function openRecovery(page: Page, url: string, archive: string) { + await page.goto(url) + await page + .locator('.capture-alternatives input[type="file"]') + .setInputFiles(resolve(archive)) + await page + .getByRole('heading', { name: 'Does this match your cube?' }) + .waitFor({ timeout: 30000 }) + await page.getByRole('button', { name: /^Alternatives \([1-9]/ }).click() +} + +for (const [size, archive, n] of fixtures) { + test(`recovery preview ${size} uses the PuzlWerk viewer with the flag`, async ({ + page, + }) => { + const problems: string[] = [] + page.on('pageerror', (error) => problems.push(String(error))) + page.on('console', (message) => { + if (message.type() === 'error') problems.push(message.text()) + }) + await openRecovery(page, '/?viewer=puzlwerk', archive) + const view = page.locator('.spatial-workspace .cube-3d-puzlwerk') + await expect(view.locator('canvas')).toBeVisible() + await expect( + page.locator('.spatial-workspace .cube-3d-canvas'), + ).toHaveCount(0) + // The X/Y/Z axis gizmo of the old view is present, with the three axes. + const gizmo = view.locator( + 'svg[aria-label="Cube orientation axes X, Y and Z"]', + ) + await expect(gizmo).toBeVisible() + await expect(gizmo.locator('[data-axis]')).toHaveCount(3) + // The viewer's own floating panel stays hidden inside the dialog. + await expect(page.locator('.cube-appearance')).toBeHidden() + await expect(page.getByText('3D view unavailable')).toHaveCount(0) + // The inspected face is outlined: its n*n stickers, set after the projection loaded. + await expect(view).toHaveAttribute( + 'data-highlight', + new RegExp(`^[urfdlb]:${n * n}$`), + ) + // Inspecting a net face outlines exactly that face. + for (const [name, key] of [ + ['Up', 'u'], + ['Down', 'd'], + ['Left', 'l'], + ] as const) { + await page + .getByRole('button', { name: `Inspect ${name} face`, exact: true }) + .click() + await expect(view).toHaveAttribute('data-highlight', `${key}:${n * n}`) + } + expect(problems).toEqual([]) + }) +} + +test('the search dialog ("Find a matching cube") also uses the PuzlWerk viewer', async ({ + page, +}) => { + const problems: string[] = [] + page.on('pageerror', (error) => problems.push(String(error))) + page.on('console', (message) => { + if (message.type() === 'error') problems.push(message.text()) + }) + await page.goto('/?viewer=puzlwerk') + await page + .locator('.capture-alternatives input[type="file"]') + .setInputFiles( + resolve('test/fixtures/photo-identity-4x4-2026-11-16T21-28-43.zip'), + ) + await page + .getByRole('heading', { name: 'Does this match your cube?' }) + .waitFor({ timeout: 30000 }) + await page + .getByRole('button', { name: 'Find a matching cube', exact: true }) + .click() + const view = page.locator('.spatial-workspace .cube-3d-puzlwerk') + await expect(view.locator('canvas')).toBeVisible() + await expect(page.locator('.spatial-workspace .cube-3d-canvas')).toHaveCount( + 0, + ) + await expect(view).toHaveAttribute('data-highlight', /^[urfdlb]:16$/) + await page.getByRole('button', { name: 'Cancel', exact: true }).click() + await expect(page.locator('.cube-3d-puzlwerk')).toHaveCount(0) + expect(problems).toEqual([]) +}) + +test('closing the dialog releases the viewer WebGL context', async ({ + page, +}) => { + await openRecovery(page, '/?viewer=puzlwerk', fixtures[0][1]) + const canvas = page.locator('.spatial-workspace .cube-3d-puzlwerk canvas') + await expect(canvas).toBeVisible() + const handle = await canvas.elementHandle() + await page.getByRole('button', { name: 'Cancel', exact: true }).click() + await expect(page.locator('.cube-3d-puzlwerk')).toHaveCount(0) + expect( + await handle!.evaluate((element) => { + const canvas = element as HTMLCanvasElement + const gl = (canvas.getContext('webgl2') ?? + canvas.getContext('webgl')) as WebGLRenderingContext | null + return gl ? gl.isContextLost() : 'no context' + }), + ).toBe(true) +}) + +test('without WebGL the preview says so instead of staying empty', async ({ + page, +}) => { + await page.addInitScript(() => { + // Called back with the canvas as `this` below. + // eslint-disable-next-line @typescript-eslint/unbound-method + const original = HTMLCanvasElement.prototype.getContext + HTMLCanvasElement.prototype.getContext = function ( + this: HTMLCanvasElement, + kind: string, + ...rest: unknown[] + ) { + if (/webgl/.test(kind)) return null + return (original as (...args: unknown[]) => unknown).call( + this, + kind, + ...rest, + ) + } as typeof original + }) + await openRecovery(page, '/?viewer=puzlwerk', fixtures[0][1]) + await expect(page.getByRole('alert')).toContainText('3D view unavailable') + await expect(page.locator('.cube-3d-puzlwerk canvas')).toHaveCount(0) +}) + +test('recovery preview keeps the existing view without the flag', async ({ + page, +}) => { + await openRecovery(page, '/', fixtures[0][1]) + await expect(page.locator('.spatial-workspace .cube-3d-canvas')).toBeVisible() + await expect(page.locator('.cube-3d-puzlwerk')).toHaveCount(0) +}) diff --git a/package-lock.json b/package-lock.json index 59a7dcb2..6022f8d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@fontsource/ibm-plex-sans": "^5.3.0", "@fontsource/space-grotesk": "^5.3.0", "@puzlwerk/capture-recovery": "file:vendor/puzlwerk-capture-recovery-0.3.0-f1fa30ac.tgz", + "@puzlwerk/viewer": "file:vendor/puzlwerk-viewer-0.1.0-7e14cbd8.tgz", "fflate": "^0.8.3", "preact": "^11.2.0" }, @@ -540,6 +541,12 @@ "keyv": "^5.6.0" } }, + "node_modules/@dimforge/rapier3d-compat": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@dimforge/rapier3d-compat/-/rapier3d-compat-0.12.0.tgz", + "integrity": "sha512-uekIGetywIgopfD97oDL5PfeezkFpNhwlzlaEYNOA0N6ghdsOvh/HYjSMek5Q2O1PYvRSDFcqFVJl4r4ZBwOow==", + "license": "Apache-2.0" + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.10.1", "dev": true, @@ -922,6 +929,17 @@ "@rescript/runtime": "12.3.1" } }, + "node_modules/@puzlwerk/viewer": { + "version": "0.1.0", + "resolved": "file:vendor/puzlwerk-viewer-0.1.0-7e14cbd8.tgz", + "integrity": "sha512-NeiykZ3Nk/jk4mT04IjiaIUKqxTy0u7jERL7rDDzEfru6JYF6aDnVEp13F31mw82tYrlLsf54u5L+fDfJm0cvQ==", + "license": "AGPL-3.0-or-later", + "dependencies": { + "@rescript/runtime": "12.3.1", + "@types/three": "0.187.0", + "three": "0.187.0" + } + }, "node_modules/@rescript/darwin-arm64": { "version": "12.3.1", "cpu": [ @@ -1310,6 +1328,12 @@ } } }, + "node_modules/@tweenjs/tween.js": { + "version": "23.1.3", + "resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-23.1.3.tgz", + "integrity": "sha512-vJmvvwFxYuGnF2axRtPYocag6Clbb5YS7kLL+SO/TeVFzHqDIWrNKYtcsPMibjDx9O+bu+psAy9NKfWklassUA==", + "license": "MIT" + }, "node_modules/@types/chai": { "version": "5.2.3", "dev": true, @@ -1349,6 +1373,32 @@ "undici-types": "~8.9.0" } }, + "node_modules/@types/stats.js": { + "version": "0.17.4", + "resolved": "https://registry.npmjs.org/@types/stats.js/-/stats.js-0.17.4.tgz", + "integrity": "sha512-jIBvWWShCvlBqBNIZt0KAshWpvSjhkwkEu4ZUcASoAvhmrgAUI2t1dXrjSL4xXVLB4FznPrIsX3nKXFl/Dt4vA==", + "license": "MIT" + }, + "node_modules/@types/three": { + "version": "0.187.0", + "resolved": "https://registry.npmjs.org/@types/three/-/three-0.187.0.tgz", + "integrity": "sha512-v+vKNarUtk4n2QRZ4+CN5ygMM0ARUjXjIQl0R/unMUfmStFeVqGbgqarbrpoGTXRZoulSH16ePrVJVxPJEbMUA==", + "license": "MIT", + "dependencies": { + "@dimforge/rapier3d-compat": "~0.12.0", + "@tweenjs/tween.js": "~23.1.3", + "@types/stats.js": "*", + "@types/webxr": ">=0.5.17", + "fflate": "~0.8.3", + "meshoptimizer": "~1.1.1" + } + }, + "node_modules/@types/webxr": { + "version": "0.5.24", + "resolved": "https://registry.npmjs.org/@types/webxr/-/webxr-0.5.24.tgz", + "integrity": "sha512-h8fgEd/DpoS9CBrjEQXR+dIDraopAEfu4wYVNY2tEPwk60stPWhvZMf4Foo5FakuQ7HFZoa8WceaWFervK2Ovg==", + "license": "MIT" + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "8.72.2", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.72.2.tgz", @@ -2786,6 +2836,12 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, + "node_modules/meshoptimizer": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/meshoptimizer/-/meshoptimizer-1.1.1.tgz", + "integrity": "sha512-oRFNWJRDA/WTrVj7NWvqa5HqE1t9MYDj2VaWirQCzCCrAd2GHrqR/sQezCxiWATPNlKTcRaPRHPJwIRoPBAp5g==", + "license": "MIT" + }, "node_modules/minimatch": { "version": "10.2.6", "dev": true, @@ -3272,6 +3328,12 @@ "node": ">=10" } }, + "node_modules/three": { + "version": "0.187.0", + "resolved": "https://registry.npmjs.org/three/-/three-0.187.0.tgz", + "integrity": "sha512-Qiu7R+Cmh8CstZsY1uJOSWnVlfo7ZtNLV7mF8Jltk3LB3AtDu9cRZlcnRKkAk8Y4z6KKw35z7Y7Urd7jWY8etA==", + "license": "MIT" + }, "node_modules/tinybench": { "version": "6.2.2", "dev": true, diff --git a/package.json b/package.json index 16e867a3..b61af6cc 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "rescript:build": "rescript build --warn-error +a", "fixture:server": "node scripts/fixtureUploadServer.mjs", "build": "npm run rescript:build && vite build", - "typecheck": "npm run verify:capture-core && npm run rescript:build && tsc --noEmit", + "typecheck": "npm run verify:capture-core && npm run verify:viewer-vendor && npm run rescript:build && tsc --noEmit", "test": "npm run rescript:build && vitest run", "test:e2e": "playwright test", "test:watch": "npm run rescript:build && vitest", @@ -19,13 +19,15 @@ "lint": "npm run lint:typescript && npm run lint:biome && npm run lint:rescript", "format:check": "biome format . && rescript format --check", "format": "biome format --write . && rescript format", - "verify:capture-core": "node scripts/verifyCaptureCore.mjs" + "verify:capture-core": "node scripts/verifyCaptureCore.mjs", + "verify:viewer-vendor": "node scripts/verifyViewerVendor.mjs" }, "dependencies": { "@fontsource/ibm-plex-mono": "^5.3.0", "@fontsource/ibm-plex-sans": "^5.3.0", "@fontsource/space-grotesk": "^5.3.0", "@puzlwerk/capture-recovery": "file:vendor/puzlwerk-capture-recovery-0.3.0-f1fa30ac.tgz", + "@puzlwerk/viewer": "file:vendor/puzlwerk-viewer-0.1.0-7e14cbd8.tgz", "fflate": "^0.8.3", "preact": "^11.2.0" }, diff --git a/scripts/verifyViewerVendor.mjs b/scripts/verifyViewerVendor.mjs new file mode 100644 index 00000000..63e8cb32 --- /dev/null +++ b/scripts/verifyViewerVendor.mjs @@ -0,0 +1,31 @@ +import { createHash } from 'node:crypto' +import { existsSync, readFileSync } from 'node:fs' +import { resolve } from 'node:path' + +const readJSON = (path) => JSON.parse(readFileSync(path, 'utf8')) +const pin = readJSON('vendor/viewer.json') +const sha = createHash('sha256') + .update(readFileSync(resolve('vendor', pin.artifact))) + .digest('hex') +const readme = readFileSync('vendor/README.md', 'utf8') +if ( + !readme.includes(pin.artifact) || + !readme.includes(pin.sha256) || + !readme.includes(pin.sourceRevision) +) + throw new Error( + 'vendor/README.md does not match the pin in vendor/viewer.json', + ) +const installed = resolve('node_modules', pin.package) +const manifest = readJSON(resolve(installed, 'package.json')) +if ( + sha !== pin.sha256 || + manifest.name !== pin.package || + manifest.version !== pin.version || + !existsSync(resolve(installed, 'NOTICE')) || + !existsSync(resolve(installed, 'dist/bridge/index.mjs')) +) + throw new Error('Viewer package does not match vendor/viewer.json') +console.log( + `Viewer ${pin.version}: source ${pin.sourceRevision}, artifact sha256 matches, NOTICE and bridge present`, +) diff --git a/src/client/capture/explicitCaptureRecoveryDialog.tsx b/src/client/capture/explicitCaptureRecoveryDialog.tsx index fc228229..de0aff5e 100644 --- a/src/client/capture/explicitCaptureRecoveryDialog.tsx +++ b/src/client/capture/explicitCaptureRecoveryDialog.tsx @@ -19,7 +19,9 @@ import { import { STICKER_COLORS } from '../vision/stickerColorGeometry' const CubeView3D = lazy(() => - import('../view3d/cubeView3D').then((m) => ({ default: m.CubeView3D })), + import('../view3d/cubeView3DChoice').then((m) => ({ + default: m.CubeView3DChoice, + })), ) export function ExplicitCaptureRecoveryDialog({ diff --git a/src/client/capture/faceRecoveryDialog.tsx b/src/client/capture/faceRecoveryDialog.tsx index 2d737c70..537b1333 100644 --- a/src/client/capture/faceRecoveryDialog.tsx +++ b/src/client/capture/faceRecoveryDialog.tsx @@ -23,7 +23,9 @@ import { STICKER_COLORS } from '../vision/stickerColorGeometry' import { previewFaces } from './spatialOrientationWizard' const CubeView3D = lazy(() => - import('../view3d/cubeView3D').then((m) => ({ default: m.CubeView3D })), + import('../view3d/cubeView3DChoice').then((m) => ({ + default: m.CubeView3DChoice, + })), ) export function FaceRecoveryDialog({ recovery, diff --git a/src/client/view3d/cubeView3DChoice.tsx b/src/client/view3d/cubeView3DChoice.tsx new file mode 100644 index 00000000..21fbbde2 --- /dev/null +++ b/src/client/view3d/cubeView3DChoice.tsx @@ -0,0 +1,32 @@ +// Spike switch between the existing 3D view and the PuzlWerk viewer. The URL parameter +// `?viewer=puzlwerk` selects the new one; anything else keeps the existing view. +import { lazy } from 'preact/compat' +import type { CubeView3DProps } from './cubeView3D' + +const CubeView3D = lazy(() => + import('./cubeView3D').then((m) => ({ default: m.CubeView3D })), +) +const PuzlwerkCubeView = lazy(() => + import('./puzlwerkCubeView').then((m) => ({ default: m.PuzlwerkCubeView })), +) + +export const puzlwerkViewerRequested = (search: string): boolean => + new URLSearchParams(search).get('viewer') === 'puzlwerk' + +type ChoiceProps = Pick< + CubeView3DProps, + 'cube' | 'puzzleSize' | 'palette' | 'highlightedFace' | 'allowLayerMoves' +> + +export function CubeView3DChoice(props: ChoiceProps) { + if (puzlwerkViewerRequested(window.location.search)) + return ( + + ) + return +} diff --git a/src/client/view3d/puzlwerkCubeView.tsx b/src/client/view3d/puzlwerkCubeView.tsx new file mode 100644 index 00000000..38873ce2 --- /dev/null +++ b/src/client/view3d/puzlwerkCubeView.tsx @@ -0,0 +1,162 @@ +// Spike: the capture-review 3D view on the shared PuzlWerk viewer (@puzlwerk/viewer), view only. +// Selected by `?viewer=puzlwerk` (see cubeView3DChoice.tsx); the CubeState becomes wire-v1 documents +// in @puzlwerk/viewer/bridge, so no translation lives in this app. +import { useEffect, useRef, useState } from 'preact/hooks' +import { + createCubeStage, + cubePresentationRadius, + presentationCameraRadius, + type CubeStage, + type StageChild, +} from '@puzlwerk/viewer' +import { open } from '@puzlwerk/viewer/bridge' +import { + cubePresentation, + cubeStateDocuments, + faceStickerIds, +} from '@puzlwerk/viewer/bridge/cube-state' +import '../../../web/cube3d.css' +import type { CubeState, FaceKey } from '../../cube/cubeAssembly' +import { + DEFAULT_STICKER_HEX, + ISOMETRIC_PITCH, + ISOMETRIC_YAW, +} from './cubeView3DState' +import { eulerPitchYaw } from './puzlwerkOrientation' + +export interface PuzlwerkCubeViewProps { + cube: CubeState + puzzleSize: number + palette?: Record + highlightedFace?: FaceKey +} + +const faceName = (face: FaceKey) => + face.toLowerCase() as 'u' | 'r' | 'f' | 'd' | 'l' | 'b' + +export function PuzlwerkCubeView({ + cube, + puzzleSize, + palette = DEFAULT_STICKER_HEX, + highlightedFace, +}: PuzlwerkCubeViewProps) { + const hostRef = useRef(null) + const sceneRef = useRef<{ stage: CubeStage; child: StageChild } | null>(null) + const [stage, setStage] = useState<{ + stage: CubeStage + child: StageChild + } | null>(null) + const [problem, setProblem] = useState(null) + + // One stage per cube size: the camera fit and the shadow envelope depend on the nominal edge. + useEffect(() => { + const host = hostRef.current + if (!host) return + const radius = cubePresentationRadius( + cubePresentation(puzzleSize).nominalEdge / 2, + ) + const created = createCubeStage(host, { + appearanceControls: 'hidden', + resolveAsset: async (id) => ({ + ok: false, + error: { code: 'UnresolvedAsset', message: id }, + }), + initialOrientation: eulerPitchYaw(ISOMETRIC_PITCH, ISOMETRIC_YAW), + casterEnvelope: { radius, clearance: 0.08 }, + viewPolicy: (view) => { + const distance = + presentationCameraRadius(view.aspect, radius, view.fovDegrees) * + view.zoom + return { + distance, + far: Math.max(100, distance + 2 * radius), + groupScale: 1, + } + }, + }) + if (!created.ok) { + setProblem(created.error.message) + return + } + // The X/Y/Z axis gizmo of the existing view: the viewer's overlay, reference frame and colors as default. + const indicator = created.value.setOrientationIndicator({ + physicalOrientation: [0, 0, 0, 1], + solverFrame: [0, 0, 0, 1], + colors: { x: 0xd9493f, y: 0xf4f4f4, z: 0x4caf67 }, + }) + if (!indicator.ok) { + created.value.dispose() + setProblem(indicator.error.message) + return + } + const added = created.value.addCube({ position: [0, 0, 0] }) + if (!added.ok) { + created.value.dispose() + setProblem(added.error.message) + return + } + const value = { stage: created.value, child: added.value } + sceneRef.current = value + setStage(value) + return () => { + sceneRef.current = null + setStage(null) + created.value.dispose() + } + }, [puzzleSize]) + + useEffect(() => { + if (!stage) return + let current = true + const documents = cubeStateDocuments(puzzleSize, cube, palette) + if (!documents.ok) { + setProblem(documents.error.code) + return + } + const { definition, state, appearance, options } = documents.value + const opened = open(definition, state, appearance, options) + if (!opened.ok) { + setProblem(opened.error.code) + return + } + setProblem(null) + void stage.child.setProjection(opened.value.projection).then((result) => { + if (!current) return + if (!result.ok) { + setProblem(result.error.code) + return + } + const ids = highlightedFace + ? faceStickerIds(puzzleSize, faceName(highlightedFace)) + : undefined + const applied = stage.stage.setStickerHighlight(stage.child, ids) + // Signal for tests: the face of the outlined stickers (from their IDs) and their number. + const host = hostRef.current + if (host) + host.dataset.highlight = + applied.ok && ids + ? `${ids[0].slice(-1).toLowerCase()}:${ids.length}` + : '' + }) + return () => { + current = false + } + }, [stage, cube, puzzleSize, palette, highlightedFace]) + + return ( +
+ {problem && ( + + )} + + ) +} diff --git a/src/client/view3d/puzlwerkOrientation.ts b/src/client/view3d/puzlwerkOrientation.ts new file mode 100644 index 00000000..dd9cabe2 --- /dev/null +++ b/src/client/view3d/puzlwerkOrientation.ts @@ -0,0 +1,13 @@ +// Display orientation of the PuzlWerk viewer as a unit quaternion [x, y, z, w]: the XYZ Euler rotation +// (pitch about x, then yaw about y) of the existing isometric view, written out so the app needs no direct +// dependency on three. +export function eulerPitchYaw( + pitch: number, + yaw: number, +): [number, number, number, number] { + const c1 = Math.cos(pitch / 2) + const s1 = Math.sin(pitch / 2) + const c2 = Math.cos(yaw / 2) + const s2 = Math.sin(yaw / 2) + return [s1 * c2, c1 * s2, s1 * s2, c1 * c2] +} diff --git a/test/cubeView3DChoice.test.ts b/test/cubeView3DChoice.test.ts new file mode 100644 index 00000000..f67d99f9 --- /dev/null +++ b/test/cubeView3DChoice.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from 'vitest' +import { puzlwerkViewerRequested } from '../src/client/view3d/cubeView3DChoice' + +describe('puzlwerkViewerRequested', () => { + it('selects the PuzlWerk viewer only for viewer=puzlwerk', () => { + expect(puzlwerkViewerRequested('?viewer=puzlwerk')).toBe(true) + expect(puzlwerkViewerRequested('?x=1&viewer=puzlwerk')).toBe(true) + }) + it('keeps the existing view for everything else', () => { + for (const search of [ + '', + '?', + '?viewer=', + '?viewer=old', + '?viewer=PuzlWerk', + '?viewers=puzlwerk', + '?puzlwerk', + ]) + expect(puzlwerkViewerRequested(search), search).toBe(false) + }) +}) diff --git a/test/puzlwerkOrientation.test.ts b/test/puzlwerkOrientation.test.ts new file mode 100644 index 00000000..7af5df80 --- /dev/null +++ b/test/puzlwerkOrientation.test.ts @@ -0,0 +1,41 @@ +import { describe, expect, it } from 'vitest' +import { eulerPitchYaw } from '../src/client/view3d/puzlwerkOrientation' + +const rotate = (q: number[], v: number[]) => { + // v' = q * v * q^-1 for a unit quaternion + const [x, y, z, w] = q + const [a, b, c] = v + const tx = 2 * (y * c - z * b) + const ty = 2 * (z * a - x * c) + const tz = 2 * (x * b - y * a) + return [ + a + w * tx + (y * tz - z * ty), + b + w * ty + (z * tx - x * tz), + c + w * tz + (x * ty - y * tx), + ] +} + +describe('eulerPitchYaw', () => { + it('is a unit quaternion', () => { + for (const [p, y] of [ + [0.52, -0.74], + [0, 0], + [1, 2], + ]) + expect(Math.hypot(...eulerPitchYaw(p, y))).toBeCloseTo(1, 12) + }) + it('turns about x for pitch only and about y for yaw only', () => { + const half = Math.PI / 2 + const pitched = rotate(eulerPitchYaw(half, 0), [0, 0, 1]) + expect(pitched[1]).toBeCloseTo(-1, 12) + const yawed = rotate(eulerPitchYaw(0, half), [0, 0, 1]) + expect(yawed[0]).toBeCloseTo(1, 12) + }) + it('applies yaw first about the fixed y axis, then pitch (XYZ Euler order)', () => { + const v = rotate(eulerPitchYaw(Math.PI / 2, Math.PI / 2), [0, 0, 1]) + // z -> x by yaw, x stays under pitch about x + expect(v[0]).toBeCloseTo(1, 12) + expect(v[1]).toBeCloseTo(0, 12) + expect(v[2]).toBeCloseTo(0, 12) + }) +}) diff --git a/vendor/README.md b/vendor/README.md index e28988d9..498146ec 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -9,3 +9,19 @@ bindings, runtime modules, rebuildable ReScript sources, and source provenance. Core is licensed EUPL-1.2. The included CubeAssembler-derived material retains its MIT license and attribution. These notices do not relicense the package as MIT. Production distribution requires the owner's separate license acceptance gate. + +# PuzlWerk viewer (spike) + +`puzlwerk-viewer-0.1.0-7e14cbd8.tgz` is the private `@puzlwerk/viewer` package packed from +wstein/puzlwerk commit `7e14cbd8ba570bbafb02f2557e9c1b6e9ac09723` (`npm pack --workspace @puzlwerk/viewer` +after `npm run build`). SHA-256 of the archive: +`cfa25d8305954f210515dc99c038a44e123e218ff7226d2b0a0e573965fd2788`. `viewer.json` pins it and +`npm run verify:viewer-vendor` checks the archive, the installed package, its `NOTICE` and the bridge. No +registry publication, no gitlink. + +The package is AGPL-3.0-or-later (CubeAssembler is AGPL-3.0-or-later too). Its `NOTICE` and the license texts +inside the archive (`LICENSE`, `CUBE_ASSEMBLER_LICENSE.txt`, `THREE_LICENSE.txt`, `CORE_EUPL_LICENSE.txt`) stay +with it. `dist/bridge/core` holds compiled PuzlWerk Core modules under EUPL-1.2 OR AGPL-3.0-or-later (owner decision 2026-11-17; this project uses the AGPL choice); production distribution of that +combination is an owner license gate. Three.js 0.187.0 (MIT) is a dependency of the viewer. + +Used only by the spike view selected with `?viewer=puzlwerk` (`src/client/view3d/puzlwerkCubeView.tsx`). diff --git a/vendor/puzlwerk-viewer-0.1.0-7e14cbd8.tgz b/vendor/puzlwerk-viewer-0.1.0-7e14cbd8.tgz new file mode 100644 index 00000000..5051c9a5 Binary files /dev/null and b/vendor/puzlwerk-viewer-0.1.0-7e14cbd8.tgz differ diff --git a/vendor/viewer.json b/vendor/viewer.json new file mode 100644 index 00000000..0774c566 --- /dev/null +++ b/vendor/viewer.json @@ -0,0 +1,9 @@ +{ + "package": "@puzlwerk/viewer", + "version": "0.1.0", + "artifact": "puzlwerk-viewer-0.1.0-7e14cbd8.tgz", + "sha256": "cfa25d8305954f210515dc99c038a44e123e218ff7226d2b0a0e573965fd2788", + "sourceRevision": "7e14cbd8ba570bbafb02f2557e9c1b6e9ac09723", + "sourceRepository": "https://github.com/wstein/puzlwerk", + "license": "AGPL-3.0-or-later; compiled Core modules in dist/bridge/core are EUPL-1.2 OR AGPL-3.0-or-later, used here under the AGPL choice" +} diff --git a/web/cube3d.css b/web/cube3d.css index a127474c..208f0799 100644 --- a/web/cube3d.css +++ b/web/cube3d.css @@ -210,3 +210,11 @@ text-align: center; color: var(--color-text-secondary); } + +/* PuzlWerk viewer spike: its canvas fills the same backdrop box as the existing canvas. */ +.cube-3d-puzlwerk canvas { + width: 100%; + height: 100%; + display: block; + touch-action: none; +}