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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions apps/desktop/e2e/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion apps/desktop/src/renderer/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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": {
Expand Down
10 changes: 9 additions & 1 deletion apps/desktop/src/renderer/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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": {
Expand Down
16 changes: 16 additions & 0 deletions apps/desktop/src/renderer/src/shell/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,22 @@ function GeneralSection() {
</Setting>
</Group>
<Group id="viewport">
<Setting id="viewportQuality">
<Segmented
id="viewportQuality"
value={app.viewportQuality}
options={(['performance', 'balanced', 'quality'] as const).map((id) => ({ 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"
/>
</Setting>
<Setting id="graphics" layout="block">
<GraphicsBlock />
</Setting>
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/renderer/src/shell/settingsIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/src/renderer/src/state/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -359,6 +361,7 @@ export const useStudio = create<StudioState>()((set, get) => ({
settingsSection: null,
settingsOption: null,
viewportStats: false,
viewportQuality: 'balanced',
setSettingsSection: (settingsSection, settingsOption = null) => {
set({ settingsSection, settingsOption });
},
Expand Down
9 changes: 5 additions & 4 deletions apps/desktop/src/renderer/src/viewer/SceneLook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<DirectionalLight>(null);
const invalidate = useThree((state) => state.invalidate);
const gl = useThree((state) => state.gl);
Expand Down Expand Up @@ -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}
Expand Down
18 changes: 12 additions & 6 deletions apps/desktop/src/renderer/src/viewer/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1065,12 +1068,15 @@ function Scene({ documentId, bodies, sketches, steps, layout }: { documentId: st
<Canvas
// Draws only when something changes or moves (each change calls invalidate): an idle view costs no GPU (#484).
frameloop="demand"
dpr={[1, 2]}
// The quality profile (issue #484); anti-aliasing belongs to the WebGL context, so a new profile builds the canvas anew.
key={profileName}
gl={{ antialias: profile.antialias }}
dpr={profile.dpr}
// While the camera moves, a large part may draw at a lower resolution for a moment (AdaptiveDpr).
performance={{ min: 0.5 }}
performance={{ min: profile.minDpr }}
// three 0.187 removed PCFSoftShadowMap (plain `shadows`) and fell back to PCF with a console
// warning; ask for PCF itself (audit X-04).
shadows="percentage"
shadows={profile.shadowMap > 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() }}
Expand All @@ -1094,8 +1100,8 @@ function Scene({ documentId, bodies, sketches, steps, layout }: { documentId: st
<StudioLight />
<SkyLight sky={colors.sky} ground={colors.ground} />
<directionalLight position={scene.keyLight} intensity={0.85} />
<ContactLight bodies={bodies} intensity={0.35} />
{moved ? null : <GroundShadow bodies={bodies} color={colors.shadow} opacity={colors.background.getHSL({ h: 0, s: 0, l: 0 }).l < 0.3 ? 0.35 : 0.12} />}
<ContactLight bodies={bodies} intensity={0.35} mapSize={profile.shadowMap} />
{moved || profile.shadowMap === 0 ? null : <GroundShadow bodies={bodies} color={colors.shadow} opacity={colors.background.getHSL({ h: 0, s: 0, l: 0 }).l < 0.3 ? 0.35 : 0.12} />}
<directionalLight position={scene.fillLight} intensity={0.3} />
{bodies.map((body, i) => (
<Body
Expand Down Expand Up @@ -1197,7 +1203,7 @@ export function Viewer() {
void platform()
.settings.app()
.then((app) => {
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.
Expand Down
20 changes: 20 additions & 0 deletions apps/desktop/src/renderer/src/viewer/quality.ts
Original file line number Diff line number Diff line change
@@ -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<ViewportQuality, QualityProfile> = {
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 },
};
6 changes: 5 additions & 1 deletion apps/desktop/src/shared/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof viewportQualitySchema>;
/** 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']);
Expand Down
6 changes: 4 additions & 2 deletions apps/desktop/src/shared/settings.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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). */
Expand Down Expand Up @@ -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<Exclude<SettingsReset, 'solidcraft' | 'print' | 'all'>, readonly SettingKey[]> = {
general: ['language', 'theme', 'projectsFolder', 'zoom', 'startPage', 'checkUpdates', 'viewportStats'],
general: ['language', 'theme', 'projectsFolder', 'zoom', 'startPage', 'checkUpdates', 'viewportStats', 'viewportQuality'],
assistant: ['webResearch', 'claudeApiBilling', 'models', 'phaseModels'],
};

Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/test/settingsStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -38,6 +38,7 @@ describe('settings store', () => {
startPage: 'home',
checkUpdates: true,
viewportStats: false,
viewportQuality: 'balanced',
setupDone: true,
webResearch: false,
claudeApiBilling: true,
Expand Down