Repository navigation
fix(vis): graceful scalar-only sources (closes #222) - #225
Merged
Merged
Conversation
Vis('physicallybased', 'Aluminum').to_threejs() previously raised
MaterialNotStagedError because the substrate path treated
physicallybased like a textured source — tier defaulted to "1k"
which doesn't exist in physicallybased's manifest, so
fetch_all_textures raised before scalars could be read.
Three pieces:
1. **Type widening**: `tier: str = "1k"` → `tier: str | None = "1k"`
matches the type already used in `set_identity` / `_validate_tier`.
Setting `vis.tier = None` is a documented un-mapping operation
(per `has_mapping` docstring).
2. **`__post_init__` auto-resolution** via new
`_auto_resolve_tier_from_manifest()`. When source + material_id
are set and the configured tier isn't in the source's manifest
tier list, fall back to "scalar" if available. Permissive on
client / manifest unavailability — mirrors `_validate_tier`'s
policy. The default stays "1k" (textured-source majority);
physicallybased silently re-resolves to "scalar".
3. **`_fetch` short-circuit**: when tier == "scalar", skip
`client.fetch_all_textures` entirely and mark the Vis fetched
with an empty texture dict. The scalars are already on the Vis
(loaded from TOML or set explicitly); downstream adapters fall
back to `Vis._PBR_DEFAULTS` for anything still None.
Closes the py-mat-side manifestation of mat-vis #313 — upstream
issue stays open for the substrate-path fix, but consumers no
longer hit the symptom because we route around it.
## Tests
- `tests/test_vis_bernhard_repros.py::TestIssue222ScalarOnlySources`
(added in PR #224 as strict-xfail) flips to passing — drops the
xfail marker.
- `tests/test_substrate_repros.py::TestMatVis313_PhysicallybasedAccess`
(added in PR #219 as strict-xfail) also flips to passing as a
cascade — drops the xfail, tightens the assertion to verify
tier auto-resolution lands on "scalar" rather than just "doesn't
raise."
Suite: 823 passed, 43 skipped, 15 xfailed (down from 17 — the two
that flipped were the #222 + #313 markers).
## Caller compatibility
- Existing `Vis(source="ambientcg", material_id="Wood095")` —
unchanged. Auto-resolution sees "1k" is in ambientcg's tier
list, leaves it alone.
- New `Vis(source="physicallybased", material_id="Aluminum")` —
auto-resolves tier to "scalar"; `.to_threejs()` returns
populated dict; `.textures` returns `{}`.
- Offline / cache-miss callers: auto-resolution silently skips
rather than blocking construction.
6 tasks done
7 tasks
gerchowl
added a commit
that referenced
this pull request
May 7, 2026
PR #225's #222 fix (graceful scalar-only sources) cascaded into PR #223's TestBernhardMatVis285_AdapterStructure_Scalar (10 tests) and the scalar-only param of TestBernhardMatVis285_Visual — both were strict-xfail on the assumption that physicallybased path raises MaterialNotStagedError. That assumption no longer holds: #225 auto-resolves tier→"scalar" in __post_init__ and short-circuits Vis._fetch when the source is scalar-only. The 10 + 1 tests now pass. Drop the strict-xfail markers: - TestBernhardMatVis285_AdapterStructure_Scalar — class-level xfail removed entirely; tests pass directly. - TestBernhardMatVis285_Visual.test_grid_renders_at_tier — split the xfail per-param via pytest.param(..., marks=...). Textured params (1k, 512, 256) keep their strict-xfail until upstream re-bakes for #285. The scalar-only param drops the xfail. Updated docstring on the scalar adapter class to reflect the new state: upstream mat-vis #313 stays open, but py-mat consumers no longer hit the symptom thanks to #225's substrate-bypass.
gerchowl
added a commit
that referenced
this pull request
May 7, 2026
#223) * test(visual): full Bernhard mat-vis #285 multi-material grid + reviewer gate Three pieces wiring up a hard visual-inspection gate so we can't ship a release that visually regressed without a human signing off. ## TestBernhardMatVis285Grid Renders Bernhard's exact 25-material grid from mat-vis #285's repro snippet — ``Aluminum Brushed``, ``Bronze Oxydized``, ``Stainless Steel Brushed``, ``Aluminum Corrugated``, ``Aluminum Hexagon``, ``Car Paint``, ``Carbon biColor Coat``, ``Perforated Metal``, ``Chrome``, ``Glass``, ``Red Wine``, ``Gold``, ``TH:`` series, ambientCG ``Metal 007`` / ``Fabric 004`` / ``Metal Plates 006``, polyhaven flooring + rock wall, physicallybased ``Plastic (Acrylic)``. Parametrized across three tiers (1k, 512, 256) — same scene at each texture resolution, so the artifact pair tells reviewers both "scalars got baked correctly" (metals look metallic at every tier) and "texture fidelity didn't regress at lower tiers" (no banding / mush). The actual assertion fingerprints the default-grey regression documented in mat-vis #285: at least 5 of the rendered materials must have NON-default scalars (metalness ≠ 0.0 OR roughness ≠ 0.5 OR color ≠ 0xCCCCCC). If everything matches the baker-default grey-plastic recipe, the test fails — that's the exact failure mode Bernhard's screenshots showed. Strict ``xfail`` today (the bug is open upstream); flips green when mat-vis-client 0.7.x ships PR mat-vis#294's baker fix and py-mat picks it up via ``>=mat-vis-client``. ## .github/CODEOWNERS Lists @gerchowl as code owner of: - ``CHANGELOG.md``, ``.release-please-manifest.json``, ``release-please-config.json`` — every release-please PR auto- requests his review. - ``src/pymat/data/**``, ``src/pymat/vis/**`` — vis surface and TOML changes that can shift the rendered look. - The visual-regression machinery (``tests/test_visual_regression.py``, ``tests/visual_render.html``, ``scripts/generate_previews.py``, the workflow files). Pair with branch-protection rule "Require review from Code Owners" on ``main`` for this to actually block merge — CODEOWNERS alone only auto-assigns the request. ## release-please-config.json Adds a single line to the release-reviewer checklist: - [ ] **Visual regression artifacts inspected** — download the latest catalog-previews / visual-regression workflow artifacts (incl. ``bernhard_285_grid_*.png`` at all baked tiers); confirm metals look metallic, glass transparent, distinct hues across the grid. See mat-vis #285 for the failure shape this gate exists to catch. Surgical one-line edit (preserves the existing array formatting + em-dashes that a json.dump round-trip would mangle). Closes the verification gap surfaced in build123d#1270: running our own test suite or Bernhard's integration tests passed cleanly even while the substrate was visually broken. The combination of the strict-xfail test (catches it on every run) + the reviewer checklist + CODEOWNERS auto-request (catches it before merge) makes the visual regression first-class in the release flow. * test(visual): expand PR #223 to full adapter matrix + scalar-only path Replaces the single TestBernhardMatVis285Grid with a comprehensive matrix of py-mat's substrate → adapter → renderer pipeline. 33 parametrized tests covering: ## TestBernhardMatVis285_AdapterStructure_Textured (10 tests) (to_threejs, to_gltf) × (1k, 512, 256, ktx2-1k, ktx2-512). Per-tier structural validation of the textured 24-material grid: dict shape right, scalar-fingerprint catches the mat-vis #285 default-grey regression. Strict-xfail on the scalar count assertion until substrate re-bakes. ## TestBernhardMatVis285_AdapterStructure_Scalar (10 tests) (to_threejs, to_gltf) × (Aluminum, Gold, Iron, Copper, Plastic- Acrylic). Closes the test-coverage gap from mat-vis #313 / py-mat #222: scalar-only physicallybased path must not raise MaterialNotStagedError. Strict-xfail. ## TestBernhardMatVis285_Ktx2Bytes (1 test) At tier='ktx2-1k', texture bytes must start with the KTX2 magic header (b'\\xabKTX 20\\xbb\\r\\n\\x1a\\n'). Catches a substrate regression where the KTX2 path silently falls back to PNG. ## TestBernhardMatVis285_MtlxExport (1 test) Vis.mtlx.export(dir) writes a self-contained .mtlx package; XML parses, surfacematerial nodes present, every <image file=...> attribute resolves to a sibling PNG on disk. Doesn't run an actual MaterialX renderer — that's downstream. ## TestBernhardMatVis285_Visual (4 tests) Renders Bernhard's grid via headless Three.js — bypassing build123d's glTF exporter entirely. Material specs come from to_threejs(vis); JS-side viewer instantiates THREE.MeshPhysical- Material directly; sphere geometry is created in JS. Isolates py-mat's surface from any downstream consumer's export-pipeline gaps. Parametrized: (textured, 1k/512/256) + (scalar, scalar). Output: 4 PNG artifacts per release + sidecar JSON with stripped scalars for human review. Strict-xfail until #285 re-bake. ## tests/visual_grid_render.html New programmatic Three.js viewer. Loads a JSON spec listing material spec dicts; instantiates one MeshPhysicalMaterial per spec; renders 5×5 grid of spheres. Bypasses glTF entirely — every texture data URI from to_threejs() is fed directly into TextureLoader, no glTF middleware. Uses Three.js's RoomEnvironment HDRI proxy + FOV-aware camera framing for full-scene visibility. ## Reviewer gate (release-please-config.json) Existing checklist line still applies — but now the artifacts to inspect are bernhard_grid_textured_*.png + bernhard_grid_scalar_- scalar.png across all 4 (scene, tier) combinations. Refs build123d#1270, mat-vis #285, mat-vis #294, mat-vis #298, mat-vis #313, mat-vis #340, py-mat #99, py-mat #100, py-mat #220-222 * test(visual): drop xfails on scalar-only path (closed by #225) PR #225's #222 fix (graceful scalar-only sources) cascaded into PR #223's TestBernhardMatVis285_AdapterStructure_Scalar (10 tests) and the scalar-only param of TestBernhardMatVis285_Visual — both were strict-xfail on the assumption that physicallybased path raises MaterialNotStagedError. That assumption no longer holds: #225 auto-resolves tier→"scalar" in __post_init__ and short-circuits Vis._fetch when the source is scalar-only. The 10 + 1 tests now pass. Drop the strict-xfail markers: - TestBernhardMatVis285_AdapterStructure_Scalar — class-level xfail removed entirely; tests pass directly. - TestBernhardMatVis285_Visual.test_grid_renders_at_tier — split the xfail per-param via pytest.param(..., marks=...). Textured params (1k, 512, 256) keep their strict-xfail until upstream re-bakes for #285. The scalar-only param drops the xfail. Updated docstring on the scalar adapter class to reflect the new state: upstream mat-vis #313 stays open, but py-mat consumers no longer hit the symptom thanks to #225's substrate-bypass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Vis(source='physicallybased', material_id='Aluminum').to_threejs()previously raisedMaterialNotStagedErrorbecause the substrate path treatedphysicallybasedlike a textured source —tierdefaulted to"1k"which doesn't exist inphysicallybased's manifest, sofetch_all_texturesraised before scalars could be read.Closes the py-mat-side manifestation of mat-vis #313. Upstream issue stays open for the substrate-path fix; consumers no longer hit the symptom because we route around it.
Three pieces
Type widening:
tier: str = "1k"→tier: str | None = "1k". Matches the type already used inset_identity/_validate_tier. Settingvis.tier = Noneis a documented un-mapping operation perhas_mappingdocstring.__post_init__auto-resolution via new_auto_resolve_tier_from_manifest(). When source + material_id are set and the configured tier isn't in the source's manifest tier list, fall back to"scalar"if available. Permissive on client / manifest unavailability — mirrors_validate_tier's policy. Default stays"1k"(textured-source majority);physicallybasedsilently re-resolves to"scalar"._fetchshort-circuit: whentier == "scalar", skipclient.fetch_all_texturesentirely and mark fetched with empty texture dict. Scalars are already on the Vis (loaded from TOML or set explicitly); downstream adapters fall back toVis._PBR_DEFAULTSfor anything stillNone.Caller compatibility
Vis(source="ambientcg", material_id="Wood095")"1k"is in ambientcg's tier listVis(source="physicallybased", material_id="Aluminum")tier → "scalar";.to_threejs()returns populated dict;.texturesreturns{}Tests
tests/test_vis_bernhard_repros.py::TestIssue222ScalarOnlySources(PR #224)tests/test_substrate_repros.py::TestMatVis313_PhysicallybasedAccess(PR #219)vis.tier == "scalar"after constructionSuite: 823 passed, 43 skipped, 15 xfailed (down from 17 xfailed — the two that flipped were the #222 + #313 markers).
Test plan
pytest tests/test_vis_bernhard_repros.py::TestIssue222ScalarOnlySources -v— 3 passedpytest tests/test_substrate_repros.py::TestMatVis313_PhysicallybasedAccess -v— 1 passedruff check .— cleanruff format --check .— cleanRefs #222, #313, #220, #221