Skip to content

feat(viewer): colour elements with no material by their category - #350

Merged
DrunkOnJava merged 1 commit into
mainfrom
feat/viewer-category-colours
Sep 23, 2026
Merged

DrunkOnJava merged 1 commit into
mainfrom
feat/viewer-category-colours

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

The 3D viewer colours each element by its category when it has no material of its own. Record-backed elements carry no material yet, so every model drew as one grey mass.

Now the colours follow the hues of the plan export's existing palette:

  • doors blue, columns red, beams and members magenta;
  • windows and curtain panels translucent cyan;
  • furniture and planting green, stairs, ramps and railings amber;
  • walls light grey, slabs, roofs and coverings mid grey.

Rooms (IfcSpace) are drawn at 12% opacity, so they no longer hide the building they fill. An element's own material, when it has one, still wins.

Changes

  • src/ifc/gltf.rs:
    • category_colour gives the palette.
    • One material per category is added after the model's own, created only for categories that are drawn. The sRGB colours are linearised, as glTF base colours are linear.
    • Translucent categories use BLEND and are double-sided.
  • CHANGELOG and viewer-api.

Testing

  • Unit tests: category materials are shared per category, a door is a linear blue, a room is faint BLEND, and an element's own material wins.
  • The Khronos glTF validator reports 0 errors and 0 warnings on Snowdon Towers.
  • Viewer build and all 15 Playwright tests. A local screenshot of Snowdon shows doors, windows, columns, mullions, planting and stairs distinct.
  • fmt, clippy -D warnings, rustdoc -D warnings, and 1,171 library tests.

What this does not do

These are category colours, not materials: nothing is claimed about what an element is made of. The palette is a default that can change.

Legal and contribution hygiene

  • Apache-2.0

Note

Low Risk
Viewer-only glTF material assignment with no changes to IFC export, auth, or data handling; regression risk is limited to 3D appearance and glTF material counts.

Overview
The 3D glTF export no longer leaves record-backed elements as an undifferentiated grey mass when they have no material_index. Meshes without an assigned material now get a category fallback that reuses the plan view palette via new public gltf::category_colour.

During build_gltf, one shared glTF material is created per IFC type (after the model's own materials), with sRGB colours linearised for PBR. Translucent categories (IFCWINDOW, IFCPLATE, IFCSPACE) use BLEND and double-sided rendering so faint rooms and glass-like panels read correctly in the viewer.

An element's own material still wins when material_index is set. CHANGELOG and docs/viewer-api.md document the behaviour; unit tests cover per-category sharing, door blue / space faint blend, and material precedence.

Reviewed by Cursor Bugbot for commit 05742492ad145e09819a338246d3b38080da5011. Configure here.

@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) September 23, 2026 12:53
@cursor

cursor Bot commented Sep 23, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_c471d085-a5aa-4aa5-9e00-62041925e192)

@DrunkOnJava
DrunkOnJava force-pushed the feat/viewer-category-colours branch from 0574249 to 4396a42 Compare September 23, 2026 13:19
@DrunkOnJava
DrunkOnJava merged commit f1b05b6 into main Sep 23, 2026
21 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/viewer-category-colours branch September 23, 2026 13:21
DrunkOnJava added a commit that referenced this pull request Sep 23, 2026
…cheme (#352)

## Summary

The browser viewer is restyled on one design system, and gains a light
scheme that follows the system setting.

- A black 56px header over a white sheet with rounded top corners. One
blue accent carries every primary action, link, focus ring and
selection.
- Pill buttons, 8px fields and panels, 12px cards, hairline borders
instead of shadows.
- Every label is sans serif and sentence case. Figures that line up use
tabular numerals, not a monospace face.
- The 3D canvas, grid, lights, axes and selection highlight read their
colours from the same tokens and switch with the scheme.
- The category colours (#350) and the plan export's palette now come
from the design system's gray, blue, red, green and amber ramps. Blue-6
is left to the selection highlight.

## Motivation

The viewer is the first thing most people see of rvt-rs. It was dark
only, with an ad hoc palette and a monospace face on data, and the 3D
view drew every category darker than its colour.

## Changes

- viewer/src/tokens.css (new): the design system's tokens. The web-font
import is left out, so the viewer still makes no network requests, and
the two monospace tokens point at the sans face.
- viewer/src/styles.css (new): every viewer selector restyled on the
tokens. It replaces the 1,180-line inline style block in index.html, and
the link colours set inline in the markup.
- viewer/src/main.ts:
  - The scene theme comes from the tokens, rebuilt on a scheme change.
- Light intensities are set for three.js physical units: a matte face
returns its colour times its light over pi, so the old 0.8 and 0.7 drew
every face at about half its colour.
  - Status, progress and badge copy is sentence case.
- viewer/index.html: the wordmark, Export IFC as the one filled primary
action, and sentence-case placeholders.
- viewer/scripts/stage-demos.mjs: demo thumbnails are flat tiles in the
tint of their kind, with a building mark that reads at the card's 72 x
40.
- src/ifc/gltf.rs, src/ifc/sheet.rs: palettes on the ramps. The plan's
border and label grays match.
- The CHANGELOG, including the #350 entry's colour list, and the
README's plan-export row.

## Testing

- [x] Playwright: all 15 tests pass against Einhoven. The case-sensitive
status assertions now expect sentence case.
- [x] npm run typecheck and npm run build.
- [x] The wasm network-import audit passes.
- [x] Light and dark screenshots of the empty state, Einhoven and Core
Interior. Each category draws in its token colour.
- [x] cargo fmt, clippy -D warnings, rustdoc -D warnings, and the full
workspace suite.

## What this does not do

- There is no theme toggle in the page. The scheme follows the system;
`data-theme` on the root element forces one.
- Elements still carry no real materials. The colours are per category.

## Audit-honesty checklist

- [x] No capability claims change.
- [x] No emojis, private paths or personal data.

## Legal and contribution hygiene

- [x] Apache-2.0
- [x] No format-RE content.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Mostly UI, styling, and colour constants; no auth, parsing, or export
logic changes beyond palette values and viewer lighting.
> 
> **Overview**
> Restyles the browser viewer on a shared **Sonic Console** token set
(`viewer/src/tokens.css`, `viewer/src/styles.css`), replacing the large
inline stylesheet in `index.html`. The UI follows **system light/dark**
(semantic tokens + `prefers-color-scheme` / optional `data-theme`), with
a black header, white sheet, pill controls, sentence-case copy, and
tabular numerals instead of monospace.
> 
> The **Three.js** scene now reads canvas, grid, lights, axes, and
selection colours from those CSS tokens via `applySceneTheme()`, with
brighter hemisphere/directional lighting so category colours read closer
to their intended sRGB values.
> 
> **Export visuals stay in sync:** `category_colour` in `gltf.rs` and
plan SVG strokes/fills in `sheet.rs` move to the same
gray/blue/red/green/amber ramps (e.g. doors amber, windows translucent
blue); docs and changelog reflect the new hues. Demo gallery thumbnails
become flat tinted tiles with a simple building icon
(`stage-demos.mjs`).
> 
> Playwright expectations update for sentence-case status strings
(`Ready` / `Loaded`).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
70c753d. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant