diff --git a/apps/desktop/e2e/app.spec.ts b/apps/desktop/e2e/app.spec.ts index 8f7374bb..5f49d369 100644 --- a/apps/desktop/e2e/app.spec.ts +++ b/apps/desktop/e2e/app.spec.ts @@ -144,6 +144,38 @@ test('the settings say what the view draws with, and the frame counters show ove await expect(stats).toHaveAttribute('data-fps', '0', { timeout: 10_000 }); }); +test('the display quality changes resolution, smoothed edges and shadow of the view at once (issue 484)', async () => { + const { app } = await connectedApp(); + const { page } = app; + await expect(page.getByTestId('mesh-summary')).toContainText('41 faces'); + const look = () => + page.evaluate(() => { + type Gl = { getContextAttributes(): { antialias: boolean } | null; shadowMap: { enabled: boolean } }; + const canvas = (globalThis as unknown as { document: { querySelector(s: string): { __r3f?: () => { gl: Gl & { getContext(): Gl } } } | null } }).document.querySelector('[data-testid="viewport"] canvas'); + const gl = canvas?.__r3f?.().gl; + return gl ? { antialias: gl.getContext().getContextAttributes()?.antialias ?? null, shadows: gl.shadowMap.enabled } : null; + }); + await expect.poll(look).toEqual({ antialias: true, shadows: true }); + const choose = async (label: string) => { + await page.getByTestId('settings').click(); + const dialog = page.getByTestId('settings-dialog'); + await dialog.getByTestId('settings-viewport-quality').getByText(label).click(); + await page.keyboard.press('Escape'); + await expect(dialog).toHaveCount(0); + }; + await choose('Performance'); + await expect.poll(look).toEqual({ antialias: false, shadows: false }); + // The new canvas still shows the part and can be picked. + const box = await page.getByTestId('viewport').boundingBox(); + if (!box) throw new Error('viewport not visible'); + await expect(async () => { + await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2); + await expect(page.getByTestId('selected-face')).toHaveAttribute('data-name', /^F\d+:/, { timeout: 1000 }); + }).toPass({ timeout: 30_000 }); + await choose('Quality'); + await expect.poll(look).toEqual({ antialias: true, shadows: true }); +}); + test('the user undoes, redoes and exports without the assistant (ADR 0016)', async () => { launched = await launchApp(); fake = new FakeSolidCraft({ controlDir: launched.controlDir }); diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts index 8d912530..84ec32ad 100644 --- a/apps/desktop/src/main/index.ts +++ b/apps/desktop/src/main/index.ts @@ -549,7 +549,7 @@ if (!app.requestSingleInstanceLock()) { }); if (updates.enabled && settingsStore.get('checkUpdates')) setTimeout(() => void updates.check(), 10_000); // Interface size, start behaviour and update check (2026-11-07): the size applies at once, the rest at the next start. - const appSettings = () => ({ zoom: settingsStore.get('zoom'), startPage: settingsStore.get('startPage'), checkUpdates: settingsStore.get('checkUpdates'), viewportStats: settingsStore.get('viewportStats') }); + const appSettings = () => ({ zoom: settingsStore.get('zoom'), startPage: settingsStore.get('startPage'), checkUpdates: settingsStore.get('checkUpdates'), viewportStats: settingsStore.get('viewportStats'), viewportQuality: settingsStore.get('viewportQuality') }); const applyZoom = () => { const zoom = settingsStore.get('zoom'); mainWindow?.webContents.setZoomFactor(zoom); diff --git a/apps/desktop/src/renderer/src/i18n/de.json b/apps/desktop/src/renderer/src/i18n/de.json index 18f6dc3f..52467cd9 100644 --- a/apps/desktop/src/renderer/src/i18n/de.json +++ b/apps/desktop/src/renderer/src/i18n/de.json @@ -1031,6 +1031,13 @@ "unknown": "Vom Treiber nicht genannt", "none": "Kein WebGL 2" }, + "viewportQuality": { + "title": "Darstellungsqualität", + "hint": "Leistung zeichnet in der Grundauflösung des Bildschirms, ohne geglättete Kanten und Schatten: für langsame Grafik oder große Teile. Ausgewogen ist der Standard. Qualität behält beim Drehen die volle Auflösung und zeichnet einen feineren Schatten. Gilt sofort.", + "performance": "Leistung", + "balanced": "Ausgewogen", + "quality": "Qualität" + }, "viewportStats": { "title": "Bildrate in der 3D-Ansicht zeigen", "hint": "Bilder pro Sekunde, Bildzeit, Zeichenaufrufe und Dreiecke in der Ecke der Ansicht. Die Ansicht zeichnet nur, solange sich etwas bewegt; in Ruhe steht dort 0." @@ -1065,7 +1072,8 @@ "zoom": "Schrift Schriftgröße Zoom größer kleiner", "projectsFolder": "Speicherort Ordner Pfad Dokumente", "graphics": "GPU Grafikkarte Grafik WebGL Renderer Software Hardware Beschleunigung Treiber", - "viewportStats": "FPS Bildrate Bilder Leistung Performance Dreiecke Zeichenaufrufe Anzeige" + "viewportStats": "FPS Bildrate Bilder Leistung Performance Dreiecke Zeichenaufrufe Anzeige", + "viewportQuality": "Qualität Leistung schnell langsam Auflösung Kantenglättung Antialiasing Schatten Profil" } }, "print": { diff --git a/apps/desktop/src/renderer/src/i18n/en.json b/apps/desktop/src/renderer/src/i18n/en.json index 5984614d..76b0e14d 100644 --- a/apps/desktop/src/renderer/src/i18n/en.json +++ b/apps/desktop/src/renderer/src/i18n/en.json @@ -1031,6 +1031,13 @@ "unknown": "Not reported by the driver", "none": "No WebGL 2" }, + "viewportQuality": { + "title": "Display quality", + "hint": "Performance draws at the screen's base resolution, without smoothed edges and shadow: for slow graphics or large parts. Balanced is the default. Quality keeps the full resolution while turning and draws a finer shadow. Applies at once.", + "performance": "Performance", + "balanced": "Balanced", + "quality": "Quality" + }, "viewportStats": { "title": "Show frame rate in the 3D view", "hint": "Frames per second, frame time, draw calls and triangles in the corner of the view. The view only draws while something moves, so it reads 0 at rest." @@ -1065,7 +1072,8 @@ "zoom": "font text size zoom larger smaller", "projectsFolder": "location folder path documents", "graphics": "gpu graphics card adapter webgl renderer software hardware acceleration driver", - "viewportStats": "fps frame rate performance triangles draw calls overlay" + "viewportStats": "fps frame rate performance triangles draw calls overlay", + "viewportQuality": "quality performance speed resolution anti-aliasing shadow slow profile" } }, "print": { diff --git a/apps/desktop/src/renderer/src/shell/SettingsDialog.tsx b/apps/desktop/src/renderer/src/shell/SettingsDialog.tsx index d0b76fca..7a43aacb 100644 --- a/apps/desktop/src/renderer/src/shell/SettingsDialog.tsx +++ b/apps/desktop/src/renderer/src/shell/SettingsDialog.tsx @@ -401,6 +401,22 @@ function GeneralSection() { + + ({ id, label: t(`settings.viewportQuality.${id}`) }))} + onChange={(next) => { + void platform() + .settings.setApp({ key: 'viewportQuality', value: next }) + .then((stored) => { + setApp(stored); + useStudio.setState({ viewportQuality: stored.viewportQuality }); + }); + }} + testId="settings-viewport-quality" + /> + diff --git a/apps/desktop/src/renderer/src/shell/settingsIndex.ts b/apps/desktop/src/renderer/src/shell/settingsIndex.ts index d1cc0cb1..2696d966 100644 --- a/apps/desktop/src/renderer/src/shell/settingsIndex.ts +++ b/apps/desktop/src/renderer/src/shell/settingsIndex.ts @@ -26,6 +26,7 @@ export const SETTINGS: readonly SettingEntry[] = [ { id: 'zoom', section: 'general', group: 'appearance', label: 'settings.zoom.title', hint: 'settings.zoom.hint', keywords: 'settings.keywords.zoom' }, { id: 'startPage', section: 'general', group: 'startup', label: 'settings.startPage.title', hint: 'settings.startPage.hint' }, { id: 'projectsFolder', section: 'general', group: 'files', label: 'settings.projects.title', hint: 'settings.projects.hint', restart: true, keywords: 'settings.keywords.projectsFolder' }, + { id: 'viewportQuality', section: 'general', group: 'viewport', label: 'settings.viewportQuality.title', hint: 'settings.viewportQuality.hint', keywords: 'settings.keywords.viewportQuality' }, { id: 'graphics', section: 'general', group: 'viewport', label: 'settings.graphics.title', hint: 'settings.graphics.hint', keywords: 'settings.keywords.graphics' }, { id: 'viewportStats', section: 'general', group: 'viewport', label: 'settings.viewportStats.title', hint: 'settings.viewportStats.hint', keywords: 'settings.keywords.viewportStats' }, { id: 'engine', section: 'solidcraft', group: 'program', label: 'engine.program', hint: 'settings.engine.hint', restart: true }, diff --git a/apps/desktop/src/renderer/src/state/store.ts b/apps/desktop/src/renderer/src/state/store.ts index a084619a..eb6e8024 100644 --- a/apps/desktop/src/renderer/src/state/store.ts +++ b/apps/desktop/src/renderer/src/state/store.ts @@ -15,7 +15,7 @@ import type { FindingBox, PrintCheck, ViewerModel } from '@partbuddy/geometry'; import { create } from 'zustand'; import type { AssemblyPlan } from '../../../shared/assembly'; -import type { ConnectionStatus, DimensionMark, ExportFormat, MirroredSketch, NotesState, PartPrint, Structure } from '../../../shared/contract'; +import type { ConnectionStatus, DimensionMark, ExportFormat, MirroredSketch, NotesState, PartPrint, Structure, ViewportQuality } from '../../../shared/contract'; /** * The ready-to-print check of one revision of one design (M7). `measuring`: SolidCraft still measures gaps and the @@ -198,6 +198,8 @@ interface StudioState { setSettingsSection: (section: SettingsSection | null, option?: string | null) => void; /** The frame counters over the 3D view (issue #484), mirrored from the app settings. */ viewportStats: boolean; + /** The quality profile of the 3D view (issue #484), mirrored from the app settings. */ + viewportQuality: ViewportQuality; /** Which tab of the printer and material profiles shows. */ profilesTab: ProfilesTab; setProfilesTab: (tab: ProfilesTab) => void; @@ -359,6 +361,7 @@ export const useStudio = create()((set, get) => ({ settingsSection: null, settingsOption: null, viewportStats: false, + viewportQuality: 'balanced', setSettingsSection: (settingsSection, settingsOption = null) => { set({ settingsSection, settingsOption }); }, diff --git a/apps/desktop/src/renderer/src/viewer/SceneLook.tsx b/apps/desktop/src/renderer/src/viewer/SceneLook.tsx index f0a479c6..a1a44097 100644 --- a/apps/desktop/src/renderer/src/viewer/SceneLook.tsx +++ b/apps/desktop/src/renderer/src/viewer/SceneLook.tsx @@ -54,7 +54,8 @@ const OVERHEAD = new Vector3(0.12, -0.08, 1).normalize(); * shadow on the floor right under it and shades deep pockets a little. 1024 texels are plenty for * a soft shadow (the earlier side shadow needed 2048 and cost most of a frame in software WebGL). */ -export function ContactLight({ bodies, intensity }: { bodies: BodyModel[]; intensity: number }) { +/** `mapSize` comes from the quality profile; 0 throws no shadow. */ +export function ContactLight({ bodies, intensity, mapSize }: { bodies: BodyModel[]; intensity: number; mapSize: number }) { const light = useRef(null); const invalidate = useThree((state) => state.invalidate); const gl = useThree((state) => state.gl); @@ -85,9 +86,9 @@ export function ContactLight({ bodies, intensity }: { bodies: BodyModel[]; inten ref={light} position={position} intensity={intensity} - castShadow={placement !== null} - shadow-mapSize-width={1024} - shadow-mapSize-height={1024} + castShadow={placement !== null && mapSize > 0} + shadow-mapSize-width={Math.max(mapSize, 1)} + shadow-mapSize-height={Math.max(mapSize, 1)} shadow-bias={-0.0004} shadow-radius={8} shadow-normalBias={placement ? placement.radius * 0.003 : 0} diff --git a/apps/desktop/src/renderer/src/viewer/Viewer.tsx b/apps/desktop/src/renderer/src/viewer/Viewer.tsx index badcb751..14d70a7a 100644 --- a/apps/desktop/src/renderer/src/viewer/Viewer.tsx +++ b/apps/desktop/src/renderer/src/viewer/Viewer.tsx @@ -38,6 +38,7 @@ import { gridStep, lineScaleFor, needsReframe } from './framing'; import { pickBox, selectionBox, VIEW_DIRECTIONS, type PickArrays } from './camera'; import { ViewTools } from './ViewTools'; import { StatsOverlay, StatsProbe } from './ViewportStats'; +import { QUALITY } from './quality'; import { viewStateOf, type CameraView } from './viewState'; import { platform } from '../platform'; import { selectedStatus, useAssistant } from '../assistant/store'; @@ -1032,6 +1033,8 @@ function Scene({ documentId, bodies, sketches, steps, layout }: { documentId: st const { t } = useTranslation(); const displayMode = useStudio((s) => s.displayMode); const viewportStats = useStudio((s) => s.viewportStats); + const profileName = useStudio((s) => s.viewportQuality); + const profile = QUALITY[profileName]; const plane = useSectionPlane(bodies); const colors = useTokenColors(); // The exploded view, the playback and the plate are for looking: picks, notes and dimensions sit on the assembled part. @@ -1065,12 +1068,15 @@ function Scene({ documentId, bodies, sketches, steps, layout }: { documentId: st 0 ? 'percentage' : false} // The canvas starts with a camera of its own before ours takes over; with the same field of // view, a framing done in between keeps fitting. camera={{ fov: scene.fieldOfView, near: 0.5, far: 5000, position: lastView.position.toArray() }} @@ -1094,8 +1100,8 @@ function Scene({ documentId, bodies, sketches, steps, layout }: { documentId: st - - {moved ? null : } + + {moved || profile.shadowMap === 0 ? null : } {bodies.map((body, i) => ( { - useStudio.setState({ viewportStats: app.viewportStats }); + useStudio.setState({ viewportStats: app.viewportStats, viewportQuality: app.viewportQuality }); }); }, []); // Leaving a design of several parts for one of a single part closes what only the first had. diff --git a/apps/desktop/src/renderer/src/viewer/quality.ts b/apps/desktop/src/renderer/src/viewer/quality.ts new file mode 100644 index 00000000..81da8fe9 --- /dev/null +++ b/apps/desktop/src/renderer/src/viewer/quality.ts @@ -0,0 +1,20 @@ +import type { ViewportQuality } from '../../../shared/contract'; + +/** What a quality profile sets in the 3D view (issue #484). */ +export interface QualityProfile { + /** Device pixel ratio range of the canvas. */ + dpr: [number, number]; + /** How far the resolution may drop while the camera moves (AdaptiveDpr); 1 keeps it. */ + minDpr: number; + /** Multisampled edges; a property of the WebGL context, so a change builds the canvas anew. */ + antialias: boolean; + /** Side of the contact shadow's map in pixels; 0 draws no shadow. */ + shadowMap: number; +} + +export const QUALITY: Record = { + performance: { dpr: [1, 1], minDpr: 0.5, antialias: false, shadowMap: 0 }, + // How the view drew before the profiles came. + balanced: { dpr: [1, 2], minDpr: 0.5, antialias: true, shadowMap: 1024 }, + quality: { dpr: [1, 2], minDpr: 1, antialias: true, shadowMap: 2048 }, +}; diff --git a/apps/desktop/src/shared/contract.ts b/apps/desktop/src/shared/contract.ts index fe694e6d..2341fc43 100644 --- a/apps/desktop/src/shared/contract.ts +++ b/apps/desktop/src/shared/contract.ts @@ -372,13 +372,17 @@ export const ZOOM_STEPS = [0.9, 1, 1.1, 1.25, 1.5] as const; export const zoomSchema = z.number().min(Math.min(...ZOOM_STEPS)).max(Math.max(...ZOOM_STEPS)); /** What PartBuddy shows when it starts: the start page or the last project. */ export const startPageSchema = z.enum(['home', 'last']); +/** How the 3D view trades picture for speed (issue #484); balanced is how it drew before. */ +export const viewportQualitySchema = z.enum(['performance', 'balanced', 'quality']); +export type ViewportQuality = z.infer; /** The app-wide settings without a channel of their own, read and changed together. */ -export const appSettingsSchema = z.object({ zoom: zoomSchema, startPage: startPageSchema, checkUpdates: z.boolean(), viewportStats: z.boolean() }).strict(); +export const appSettingsSchema = z.object({ zoom: zoomSchema, startPage: startPageSchema, checkUpdates: z.boolean(), viewportStats: z.boolean(), viewportQuality: viewportQualitySchema }).strict(); export const appSettingRequestSchema = z.discriminatedUnion('key', [ z.object({ key: z.literal('zoom'), value: zoomSchema }).strict(), z.object({ key: z.literal('startPage'), value: startPageSchema }).strict(), z.object({ key: z.literal('checkUpdates'), value: z.boolean() }).strict(), z.object({ key: z.literal('viewportStats'), value: z.boolean() }).strict(), + z.object({ key: z.literal('viewportQuality'), value: viewportQualitySchema }).strict(), ]); /** A section of the settings to put back to its defaults, or all of them. */ export const settingsResetSchema = z.enum(['general', 'solidcraft', 'assistant', 'print', 'all']); diff --git a/apps/desktop/src/shared/settings.ts b/apps/desktop/src/shared/settings.ts index 88a956d1..e8ca52f0 100644 --- a/apps/desktop/src/shared/settings.ts +++ b/apps/desktop/src/shared/settings.ts @@ -1,6 +1,6 @@ import { z } from 'zod'; -import { agentKindSchema, languageSchema, modelChoiceSchema, phaseChoicesSchema, startPageSchema, themeSchema, zoomSchema, type SettingsReset } from './contract'; +import { agentKindSchema, languageSchema, modelChoiceSchema, phaseChoicesSchema, startPageSchema, themeSchema, viewportQualitySchema, zoomSchema, type SettingsReset } from './contract'; /** * Every stored setting of the installation with its type, default and validation, in one place. @@ -20,6 +20,8 @@ export const settingsSchema = z.object({ checkUpdates: z.boolean().catch(true), /** Frame rate, frame time, triangles and draw calls over the 3D view (issue #484). */ viewportStats: z.boolean().catch(false), + /** Resolution, anti-aliasing and shadows of the 3D view (issue #484). */ + viewportQuality: viewportQualitySchema.catch('balanced'), /** The first-start setup (B9) was finished or skipped. */ setupDone: z.boolean().catch(false), /** The assistant may search the web and read pages (B7). */ @@ -59,7 +61,7 @@ export type SettingKey = keyof Settings; /** What "reset" puts back per section of the settings dialog; the first-start flag is never reset. */ export const RESET_KEYS: Record, readonly SettingKey[]> = { - general: ['language', 'theme', 'projectsFolder', 'zoom', 'startPage', 'checkUpdates', 'viewportStats'], + general: ['language', 'theme', 'projectsFolder', 'zoom', 'startPage', 'checkUpdates', 'viewportStats', 'viewportQuality'], assistant: ['webResearch', 'claudeApiBilling', 'models', 'phaseModels'], }; diff --git a/apps/desktop/test/settingsStore.test.ts b/apps/desktop/test/settingsStore.test.ts index b2244306..7104495e 100644 --- a/apps/desktop/test/settingsStore.test.ts +++ b/apps/desktop/test/settingsStore.test.ts @@ -20,7 +20,7 @@ afterEach(() => { describe('settings store', () => { it('starts with the defaults', () => { const store = new SettingsStore(join(folder(), 'settings.json')); - expect(store.all()).toEqual({ language: 'system', theme: 'system', projectsFolder: null, zoom: 1, startPage: 'home', checkUpdates: true, viewportStats: false, setupDone: false, webResearch: true, claudeApiBilling: false, models: {}, phaseModels: {} }); + expect(store.all()).toEqual({ language: 'system', theme: 'system', projectsFolder: null, zoom: 1, startPage: 'home', checkUpdates: true, viewportStats: false, viewportQuality: 'balanced', setupDone: false, webResearch: true, claudeApiBilling: false, models: {}, phaseModels: {} }); }); it('takes over the files of earlier versions and leaves them in place', () => { @@ -38,6 +38,7 @@ describe('settings store', () => { startPage: 'home', checkUpdates: true, viewportStats: false, + viewportQuality: 'balanced', setupDone: true, webResearch: false, claudeApiBilling: true,