Skip to main content

Module style

Module style 

Source
Expand description

Canonical IFC styling — the single source of truth for mesh colors, shared between the HTTP server, the native pipeline, and the browser-side WASM bindings (issue #913).

This mirrors the [crate::symbolic] split: presentation logic that used to be copied into every consumer (wasm-bindings, processing, apps/server, the now-discontinued desktop app) lives here exactly once. See issue #913 for the design and rationale.

Phase 0 (this commit) introduces only the two pieces with no decoder or geometry dependency — the canonical Rgba color type and the single default_color_for_type table — and wires nothing into the pipeline yet. The decoder-driven resolver (StyleIndex, IfcStyledItem / IfcIndexedColourMap / material-chain resolution) arrives in Phase 2.

§Canonical contracts

  • f32 is canonical; u8 is transport-only. Colors are Rgba ([f32; 4], straight-alpha, 0.0..=1.0) end-to-end. The browser’s 8-bit SharedArrayBuffer transport is expressed only through Rgba::to_rgba8 / Rgba::from_rgba8; the backend stays exact. (Decision §8.3 of the plan.)
  • One default table. default_color_for_type is the only IFC-type → color map in Rust. A CI guard (Phase 1) fails the build if a second one appears.

Structs§

FullIndexedColourMap
A fully resolved IfcIndexedColourMap: the palette plus a per-triangle index into it (in CoordIndex order, which the triangulated-face-set processor preserves 1:1).
Rgba
Canonical straight-alpha RGBA color, components in 0.0..=1.0.

Constants§

TRANSPARENCY_ALPHA_THRESHOLD
Alpha at or above which a color is treated as opaque.

Functions§

build_element_material_colors
Build the element id → material colours map: every colour each element inherits from its associated material(s), in resolution order. The single general-path fallback picks the first opaque colour (pick_opaque_first); the opening sub-mesh path alternates transparent/opaque (pick_material_style_for_submesh) to split glass vs frame.
build_material_style_index
material id → colours, by following each material’s styled representations to the orphan styled items they reference.
default_color_for_type
The canonical default color for an IFC type.
extract_surface_style_colors
Extract the apparent surface colour (and an optional distinct shading colour) from an IfcSurfaceStyle, walking its Styles list (attr 2) and returning the first rendering’s (apparent, shading) pair.
flatten_material_color_index
Flatten a material id → colours map into material id → colour by picking the first opaque colour per material (pick_opaque_first). Used to key layered sub-mesh colour lookups on material id — each layer slice’s geometry_id is its IfcMaterial entity id.
pick_material_style_for_submesh
Pick a material colour for one sub-mesh, alternating preference so a window distributes its frame (opaque) and glazing (transparent) colours across sub-meshes instead of painting every part the same. prefer_transparent is toggled by the caller per sub-mesh.
pick_opaque_first
Pick the first opaque colour (alpha ≥ threshold), else the first colour.
resolve_indexed_colour_map_full
Resolve an IfcIndexedColourMap to its palette + per-triangle indices.
resolve_material_ids
Resolve a material SELECT to the individual IfcMaterial ids it contains.
resolve_submesh_color
Resolve one sub-mesh’s colour, given its already-resolved direct-style colour.
split_mesh_by_indexed_colour
Split a flat-shaded mesh into one sub-mesh per palette group.