Skip to content

Vis: graceful handling of scalar-only sources (physicallybased / 'tier=None') #222

@gerchowl

Description

@gerchowl

Source

Bernhard's mat-vis#313 + mat-vis#311 sub-bullet "Support physicallybased.info" + his comment in mat-vis#281:

some materials expect tier=None. Need to find out how to work with this

MorePET/mat-vis#313
MorePET/mat-vis#281 (comment)

Reported against pymat 3.10.0 + mat-vis-client 0.6.4. Bug persists on current dev (35681ce)_model.py:185 still has tier: str = "1k" and the textures path raises before the scalar-only short-circuit can kick in. Version line is provenance only.

Problem

Vis defaults tier="1k" (_model.py:185). For scalar-only sources (physicallybased), no 1k tier exists — the catalog uses tier="scalar" and there are no textures. Result: MaterialNotStagedError for every physicallybased material accessed via Vis.

Repro

from pymat.vis import Vis
v = Vis("physicallybased", "Aluminum")    # tier defaults to "1k"
v.to_threejs()
# MaterialNotStagedError: ... tier '1k' ...

Even passing the right tier explicitly is broken because of an upstream mat-vis bug (see "Cascade" below).

Two intertwined problems

  1. Default-tier mismatch (this repo): Vis should detect scalar-only sources and use tier="scalar" (or a None sentinel) automatically. Today the user must know the source's tier vocabulary up front.

  2. Catalog-side bug (mat-vis): mat-vis-client.materials("physicallybased", "scalar") returns [] because every physicallybased catalog entry has available_tiers=[]. Fix is in mat-vis (bake_scalar_source to populate available_tiers=["scalar"]). Will be filed separately on mat-vis. Both fixes need to land for bernhard's repro to pass; this issue tracks the pymat half.

Proposed fix in py-mat

When constructing Vis(source, material_id) without an explicit tier:

  • Look up the source's manifest entry; if it advertises scalar and no textured tiers, default tier="scalar".
  • Otherwise default tier="1k" (current behavior).

Alternatively (cleaner): make tier resolve at fetch time rather than construction time, so an unset tier picks the source's "preferred" tier per-source. Avoids the mismatch by design.

For the textures accessor: when tier="scalar" (or the source carries no textures at this tier), return {} instead of raising. Adapter (to_threejs()) already handles texture-less materials per the mat-vis-client #288 fix.

Acceptance

  • Vis("physicallybased", "Aluminum").to_threejs() returns a valid scalar-only material dict (no exception)
  • Vis("physicallybased", "Aluminum").scalars (per mat#220) returns the authored PBR
  • Vis("physicallybased", "Aluminum").textures returns {}
  • No regression on textured sources (Vis("gpuopen", "Aluminum Brushed", "1k") unchanged)
  • Forward verify after mat-vis fix lands: re-run bernhard's exact repro from mat-vis#313 end-to-end through Vis and confirm output. The mat-vis-side bake_scalar_source fix MUST be on the substrate the client reads (DEFAULT_TAG-pinned) before this acceptance can be validated. Don't claim closed on unit tests alone.

Cascade / related

  • mat#220 (Vis.scalars accessor — needed to read the result)
  • mat-vis#313 (the user-visible bug; needs both fixes — pymat-side + mat-vis catalog fix)
  • mat-vis-side fix: bake_scalar_source should populate available_tiers=["scalar"] — being filed as separate mat-vis issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions