Skip to content

_scalars_for should resolve display names (symmetric with fetch_all_textures) #367

Closed

Description

@gerchowl

Problem

client._scalars_for(source, material_id) does an exact entry[\"id\"] != material_id comparison and silently returns {} for unmatched names. Meanwhile fetch_all_textures resolves display names → canonical id via _resolve_material_id. The two surfaces are asymmetric.

Concrete repro on dev + [email protected]:

```python
from mat_vis_client import get_client
c = get_client()

Texture path resolves names (via _resolve_material_id)

c.fetch_all_textures("gpuopen", "Aluminum Brushed", tier="1k") # ✅ resolves

Scalar path does NOT resolve names

c._scalars_for("gpuopen", "Aluminum Brushed") # → {} (silent miss)
c._scalars_for("gpuopen", "") # → {'roughness': 1.0, 'metalness': 0.0, ...}
```

Same asymmetry surfaces through client.asset(...):

```python
m = c.search(source="gpuopen", tier="1k", limit=1)[0]

c.asset(m).scalars # ✅ canonical id from Match
c.asset(m.ref).scalars # ✅ "source/id" slashed form
c.asset(source=m.source, id=m.id).scalars # ✅ UUID kwargs
c.asset(source=m.source, id=m.mat_vis['name']).scalars # ❌ returns {}
```

Where the Match flow sidesteps it

Idiomatic dev usage (search → Match → asset) carries the canonical id end-to-end, so users hitting the recommended path never see the bug. But:

  • pymat's Vis(source=\"gpuopen\", material_id=\"Aluminum Brushed\").to_threejs() quietly returns sparse output instead of catalog-authored scalars
  • Anyone constructing an asset from a (source, name) pair from external sources (CSV, scene file, user input) silently loses scalars

Proposed fix

One-line shape: _scalars_for should call _resolve_material_id first (or wrap the existing lookup in the same name-aware path). This preserves the silent-on-failure contract for genuine misses while making name input symmetric with fetch_all_textures.

```python
def _scalars_for(self, source: str, material_id: str) -> dict:
try:
resolved = self._resolve_material_id(source, material_id, tier=...) # tier-agnostic variant
except (UnknownMaterialError, MaterialNotStagedError):
return {} # preserve silent-on-miss contract
# ... rest unchanged, using resolved for the entry["id"] match
```

The wrinkle: _resolve_material_id takes a tier argument because staging-status is tier-dependent. _scalars_for is tier-agnostic. Options:

  1. Add a tier-agnostic _resolve_id that ignores staging, just maps name → canonical id. Use it in _scalars_for.
  2. Make _scalars_for accept an optional tier= and pass through.
  3. Iterate index entries and match on entry[\"id\"] OR entry[\"mat_vis\"][\"name\"] directly — duplicates resolve logic but keeps signature stable.

(1) is cleanest.

Acceptance

  • c._scalars_for(\"gpuopen\", \"Aluminum Brushed\") returns the same dict as c._scalars_for(\"gpuopen\", \"<resolved-uuid>\")
  • c.asset(source=\"gpuopen\", id=\"Aluminum Brushed\").scalars works (currently returns {})
  • c._scalars_for(\"gpuopen\", \"NotAMaterial\") still returns {} silently (no exception)
  • client.asset(match).scalars unchanged (Match path already canonical)
  • Forward verify: Vis(source=\"gpuopen\", material_id=\"Aluminum Brushed\", tier=\"1k\").to_threejs() from py-mat returns full PBR scalars (color, metalness, roughness from catalog) instead of sparse defaults

Context

Activity

  1. gerchowl commented on May 8, 2026

    @gerchowl
    ContributorAuthor

    Already closed by 70d6d2b ("fix(client): scalar-only path — case-insensitive lookup + tier='scalar' sentinel (#368, #370)") — that commit's three-way name-resolution block in _scalars_for (canonical id exact, normalized id, normalized mat_vis.name) covers the symmetry this issue requested.

    Live verification against gerchowl/[email protected]:

    ```
    _scalars_for('gpuopen', 'Aluminum Brushed') → {'roughness': 1.0, 'metalness': 1.0, 'ior': 1.5, 'color_hex': '#FFFFFF'}
    _scalars_for('gpuopen', 'aluminum brushed') → same
    _scalars_for('gpuopen', '') → same
    ```

    Original repro returning `{}` was hitting `v2026.04.2` prod, which predates the procedural-PBR walker (#316/#346) — gpuopen pbr.roughness/metalness/ior were null in that bake regardless of how the lookup was keyed. The new tst-full bake closes that data gap; the lookup symmetry was already in place.

    Closing as already fixed.

  2. gerchowl commented on May 8, 2026

    @gerchowl
    ContributorAuthor

    Reopening — my prior closure verified against gerchowl/[email protected] after the #371 (feature/368-scalar-only-fixes) branch was already installed locally. On current origin/dev (without #371 merged), _scalars_for('gpuopen', 'Aluminum Brushed') still returns {} for display-name input. PR #371 closes this once it lands; in the meantime the bug is real. Tracking the helper-consolidation cleanup separately in #372.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions