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
2 changes: 1 addition & 1 deletion packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"default": "studio",
"pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$",
"scope": "resource",
"description": "IBL name used for new previews. Built-ins: bridge, studio; or an additional IBL name."
"description": "IBL name used for new previews. Defaults to the same generated Neutral Studio lighting as the viewer. Built-ins: bridge, studio; or an additional IBL name."
},
"mtlx.preview.defaultGeometry": {
"type": "string",
Expand Down
20 changes: 20 additions & 0 deletions packages/vscode-extension/src/previewSettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { expect, it } from 'vitest';
import { DEFAULT_VIEWER_SETTINGS } from 'mtlx-viewer/settings';
import { readFileSync } from 'node:fs';
import { normalizePreviewState } from './preview/state.js';
import { parsePreviewSettings, PREVIEW_NAME_PATTERN } from './previewSettings.js';
it('defaults to neutral studio, totem and rotation', () => {
expect(parsePreviewSettings({})).toMatchObject({
Expand Down Expand Up @@ -64,3 +67,20 @@ it('normalizes configured environment rotation and rejects invalid values', () =
warnings: ['environmentRotation must be finite degrees; using 0.'],
});
});

it('keeps new preview lighting and contributed VS Code defaults aligned with the viewer', () => {
const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
const properties = manifest.contributes.configuration.properties;
const settings = parsePreviewSettings({});
const state = normalizePreviewState({}, settings);
expect(properties['mtlx.preview.defaultIbl'].default).toBe(DEFAULT_VIEWER_SETTINGS.ibl);
expect(properties['mtlx.preview.background'].default).toBe(DEFAULT_VIEWER_SETTINGS.background);
expect(state.settings).toMatchObject({
ibl: DEFAULT_VIEWER_SETTINGS.ibl,
background: DEFAULT_VIEWER_SETTINGS.background,
});
expect(parsePreviewSettings({ defaultIbl: 'missing', background: 'invalid' })).toMatchObject({
defaultIbl: DEFAULT_VIEWER_SETTINGS.ibl,
background: DEFAULT_VIEWER_SETTINGS.background,
});
});
15 changes: 11 additions & 4 deletions packages/vscode-extension/src/previewSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BACKGROUND_OPTIONS,
DEFAULT_VIEWER_SETTINGS,
normalizeEnvironmentRotation,
TONE_MAPPING_OPTIONS,
type BackgroundKind,
Expand Down Expand Up @@ -67,15 +68,21 @@ export function parsePreviewSettings(input: Record<string, unknown>): PreviewSet
};
const toneMapping = TONE_MAPPING_OPTIONS.find((option) => option.value === (input.toneMapping ?? 'neutral'))?.value;
if (!toneMapping) warnings.push('toneMapping is unknown; using neutral.');
const background = BACKGROUND_OPTIONS.find((option) => option.value === (input.background ?? 'white'))?.value;
if (!background) warnings.push('background is unknown; using white.');
const background = BACKGROUND_OPTIONS.find(
(option) => option.value === (input.background ?? DEFAULT_VIEWER_SETTINGS.background),
)?.value;
if (!background) warnings.push(`background is unknown; using ${DEFAULT_VIEWER_SETTINGS.background}.`);
const environmentRotation = normalizeEnvironmentRotation(input.environmentRotation ?? 0);
if (environmentRotation === undefined) warnings.push('environmentRotation must be finite degrees; using 0.');
return {
environmentRotation: environmentRotation ?? 0,
ibls,
geometries,
defaultIbl: defaultName('defaultIbl', ['studio', 'bridge', ...ibls.map((asset) => asset.name)], 'studio'),
defaultIbl: defaultName(
'defaultIbl',
['studio', 'bridge', ...ibls.map((asset) => asset.name)],
DEFAULT_VIEWER_SETTINGS.ibl,
),
defaultGeometry: defaultName(
'defaultGeometry',
['totem', 'sphere', 'cube', 'plane', ...geometries.map((asset) => asset.name)],
Expand All @@ -85,7 +92,7 @@ export function parsePreviewSettings(input: Record<string, unknown>): PreviewSet
bloom: boolean('bloom'),
ao: boolean('ao'),
toneMapping: toneMapping ?? 'neutral',
background: background ?? 'white',
background: background ?? DEFAULT_VIEWER_SETTINGS.background,
warnings,
};
}
Loading