Skip to content

fix(ifc): a glTF body drawn whole whose materials are all transparent takes their alpha (#1812) - #2109

Merged
DrunkOnJava merged 2 commits into
DrunkOnJava:mainfrom
zenglanmu:fix/gltf-element-alpha
Nov 20, 2026
Merged

DrunkOnJava merged 2 commits into
DrunkOnJava:mainfrom
zenglanmu:fix/gltf-element-alpha

Conversation

@zenglanmu

@zenglanmu zenglanmu commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A body the glTF exporter draws whole, the shared box or its own mesh, in its category's colour, now takes the alpha of its materials where every one of them is transparent: on the open models, rac_basic's 8 water glasses on each of its 13 saves. A door, lamp or window with a glass part stays as on main, since which part of a saved mesh is the glass is not read. Before, such a body kept the category's alpha, so the transparency of its own materials was lost. @zenglanmu's Revit 2024 project showed it: by their count, 17 glass doors and 149 glass light fixtures drawn opaque in the GLB. #1818 fixed the emission of material alpha and added extras.alphaSource; the element-to-material selection for whole bodies still fell back to the category material. #1603 (missing materials on 2015 to 2023 family instances) is separate and not addressed here.

The rule, after review (Griffin's call): a body drawn whole in its category's colour takes the alpha of its materials only where it reads at least one and every one is read as transparent, and then the least transparent one's, so no part is drawn fainter than it is (all_transparent_alpha). The materials are its constituent set (several materials, or one whose colour was not read), a single-profile set whose colour was not read, or a layer set it is not drawn in. A body that also holds an opaque material, a material whose transparency was not read or lies outside 0 to 1, or a layer or index that names no material, keeps its category's alpha. Drawn at its glass's alpha, a door with a glass panel would look all glass, and which part of a saved mesh is the glass is not read (#2112).

  • Windows, curtain panels and rooms keep their translucent category colour as on main.
  • A see-through body's material is Category <class> transparent, BLEND and double-sided, with colourSource "rvt-rs" and alphaSource "file": its alpha is one minus a Revit material's own transparency. MaterialExtras and docs/viewer-api.md say so.
  • A body that keeps its category's alpha shares the category's one material, as on main.

Geometry, the IFC export and diagnostics.json are unchanged.

Original change by @zenglanmu (5686cddd, re-signed with their authorship); the rule above, the docs and the tests by the maintainer on review (fef2b7ad).

Testing

  • Six tests of all_transparent_alpha's failure modes in src/ifc/gltf.rs (no material; a transparency not read; an opaque frame beside glass; differing transparencies; a transparency outside 0 to 1, NaN or infinite; one fully transparent material). It is a pure helper, the one kind of unit test this repository takes; they run in CI's fast run on fef2b7ad, which is green. The hand-built-model test first proposed is removed.
  • Measured on every open model, against the rows, all of which hold (the reading): the Measure (44756684505) finds all 120 exports and 102 diagnostics.json identical and no scorer line moving; probe_2109_whole_body_alpha on this head and on main (44756695010, 44756704637) finds 104 IfcBuildingElementProxy on rac_basic's 13 saves newly see-through (16 at alpha 0.05, 88 at 0.15), no other class, windows, curtain panels and rooms as on main, and no category material written twice.

Evidence boundary

The Revit 2024 project that exposed this is not redistributable. Which elements the rule reaches on the open models is the probe's count above: on @zenglanmu's project, the glass doors and fixtures stay opaque unless every material they read is transparent, so a downstream patch carrying the first rule still differs from this.

DrunkOnJava added a commit that referenced this pull request Nov 20, 2026
…y name and alpha, and each translucent element's materials (#2109)
DrunkOnJava added a commit that referenced this pull request Nov 20, 2026
…y name and alpha, and each translucent element's materials (#2109)
@DrunkOnJava

Copy link
Copy Markdown
Owner

Thank you, @zenglanmu, for this and for #1812. What I read on c3c5b9af:

Where it applies. The changed branch takes every element that has no material of its own and no single material (single_material), and is not drawn in layers. That covers bodies drawn as the shared box and bodies drawn as their own mesh, so it can reach more than the boxes the description names; the probe below counts which. Such an element keeps its category's colour and takes the alpha of its most transparent read material.

Four things to settle before it can land.

  1. A second material for one category. The opaque fallback now goes into category_alpha_materials under (class, u32::MAX), while the layered branch (one node per layer) still fills category_materials for a layer with no colour. In a model with both, such as layered and unlayered walls, the GLB carries two Category IFCWALL materials. Every such file's GLB then changes, and the viewer test's pinned Einhoven material count can move. Keeping the opaque fallback in category_materials and only the translucent ones in the new map avoids it. Separately, a translucent material and the opaque one share the name Category X by design, so a consumer that keys materials by name sees two; a name that says which is translucent would help.
  2. Windows and curtain panels already have a translucent category colour (category_colour). The new alpha replaces it, so a window whose glass reads less transparent than the category's comes out more opaque than today.
  3. alphaSource: "rvt-rs" gains a meaning. MaterialExtras and docs/viewer-api.md say "rvt-rs" is a category's alpha, a translucent window's, or the opaque 1 of an unread transparency. It would now also carry a file material's transparency applied to a whole body, and those docs need that line.
  4. The test. CONTRIBUTING.md takes a test under tests/ that runs the real entry point on a fixture or a corpus file. The contract class is for published claims (the support matrix, the schemas, the committed synthetic IFC fixtures). The files under tests/ that build a model by hand guard those committed synthetic fixtures; a test that builds an IfcModel to check one exporter choice guards none, and I made the same call on fix(saved-graphics): count cylinder trim crossings inside each strip #2106. most_transparent_alpha is a pure helper, so its failure modes can have a few fast tests beside it in src/ifc/gltf.rs: no transparency read, all opaque, a value outside 0 to 1, NaN.

Nothing is needed from you meanwhile. Once the rule below is decided, I push points 1, 3 and 4 to your branch, as "Allow edits" permits. The ruleset also checks a pull request's own commits for signatures, so a squash does not cure an unsigned one: that push carries your commit re-signed, with your authorship.

What the runs can and cannot see. Its Measure (44734182906) cannot see an alpha: Measure deletes each GLB after its scorers run, and the GLB scorers read model materials and bodies, not category colours. So a probe on main and on this head (44735619849, probe_2109_whole_body_alpha on measure/2109-head) counts, on every open model, the elements drawn translucent in a category colour, by class, alpha and body shape; for each, how many materials it is associated with and how many were read as transparent; and any category colour that appears as two materials at one opacity.

Rows, registered before either run is read.

  1. Every ifc.sha256 and diagnostics.json is identical: only gltf.rs changes.
  2. On main, the probe counts no category material duplicated by name and alpha on any file.
  3. On this head, the elements drawn translucent in a category colour are counted by class, alpha and shape on each file, beside main's (windows and curtain panels already translucent there), and every class that newly appears is reported. If no open model has such an element, the change is unmeasured on real files, and that is said.
  4. On this head, any file with a category material duplicated by name and alpha is reported; that is point 1 above.
  5. No scorer line moves.
  6. On Einhoven, the probe's materials total is the same on both sides, or the viewer test's pin moves with it.

The rule itself is a visual choice for the maintainer. A body drawn whole at its most transparent material's alpha shows a glass door as glass, and also a door with a small vision panel as see-through, or a wall with one thin glass layer. It goes to Griffin with the probe's counts beside it, and I will post his answer here.

@DrunkOnJava

Copy link
Copy Markdown
Owner

The probe, read against the rows above (44735619849, 101 models): rows 1, 2, 3, 4 and 6 are read; row 5 waits for the Measure. The Measure's held-out offices job failed fetching the held-out models, before this head's code ran; its failed jobs are rerun when the run ends.

  1. Holds on the probe run's 101 models: every export and every diagnostics.json is identical.

  2. Holds. On main, no file has a category material duplicated by name and alpha.

  3. Read. On this head, 58 of the 101 files draw elements in a category colour at an alpha they did not have on main: 5,474 elements in all, all but the windows newly translucent.

    Class Elements Own mesh Shared box Files Alpha 0.1 or less 0.1 to 0.3 Above 0.3
    IfcLightFixture 3,445 2,486 959 32 26 2,359 1,060
    IfcDoor 928 635 293 55 681 247 0
    IfcWindow (already translucent) 669 340 329 39 643 26 0
    IfcBuildingElementProxy 281 122 159 14 44 133 104
    IfcFurniture 107 59 48 22 17 12 78
    IfcWall 28 24 4 1 28 0 0
    IfcSanitaryTerminal 16 16 0 4 16 0 0

    Every one of the 928 doors has exactly one transparent material among two to four, as do 3,095 of the light fixtures; only 104 proxies have every material transparent. So a door with a glass panel is drawn whole at its glass's alpha, and 681 doors come out at 0.1 or less. All 669 windows become more transparent than the category's 0.45 (Einhoven's two go to 0.25), the opposite of what point 2 above expected.

  4. Read: 18 files carry a duplicated category material. An opaque Category IFCSLAB on all 18, plus Category IFCWALL on 3 office files and Category IFCCOVERING on one housing file. That is point 1.

  5. Holds. On Einhoven, materials total is 39 on both sides. The viewer test pins the model's own material_count (36), not the GLB's materials, so point 1's worry about that pin was misplaced.

So the rule reaches doors on 55 files and light fixtures on 32, not only the boxes the description names. That is the visual choice above, and it goes to Griffin with these counts now.

DrunkOnJava added a commit that referenced this pull request Nov 20, 2026
zenglanmu and others added 2 commits November 20, 2026 09:40
An element whose body the glTF exporter draws as one piece (Revit 2008-2023
box bodies, and any body with no layers) kept its category colour and the
category's opaque alpha. The material's own transparency was lost whenever
the element's type drew in several materials (a glass door's glass + frame),
or a single material/profile whose colour was not read.

Take the minimum alpha of the associated materials that were read:
- material constituent sets of several materials, or one whose colour was
  not read;
- single-profile material sets with an unread colour;
- material layer sets whose layers the body is not drawn in.

All-opaque or unread materials keep the category alpha. The chosen alpha is
still marked extras.alphaSource = "rvt-rs", and the material becomes
double-sided / BLEND only when translucent.

Adds a tests/ contract target (gltf_element_alpha) that builds the IfcModel
directly and checks the glTF document; no unit tests.

Follow-up to DrunkOnJava#1812 (alpha emission) and the open DrunkOnJava#1603 (missing materials).
… it is made of is transparent, at the least transparent one's alpha; windows keep their tint (DrunkOnJava#2109)
@DrunkOnJava
DrunkOnJava force-pushed the fix/gltf-element-alpha branch from c3c5b9a to fef2b7a Compare November 20, 2026 14:45
@DrunkOnJava

DrunkOnJava commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Griffin's call on the rule: an element is drawn see-through only where every material it reads is transparent. A door or a lamp with a glass part keeps its category's colour, as on main, while we look for which part of a saved mesh is the glass. Neither route we have reads that today:

  • no saved part names a material: of the doors, lamps and windows this reaches with their own mesh on main (635, 2,486 and 340), none has a part that does (44742141242, probe_2109_part_materials);
  • none of the 212,216 tags on the parts of the 3,682 family instances it reads is a key of the tag-to-material map of the symbol that draws each instance (44744309480). 196 of the maps' 4,474 entries were not read, and some types' maps are empty.

The Measure's rerun is in (44734182906): rows 1 and 5 above hold, with all 120 exports and 102 diagnostics.json identical and no scorer line moving.

What I pushed to your branch (fef2b7ad, on your commit re-signed as 5686cddd with your authorship; GitHub shows both verified). The branch was force-updated from c3c5b9af, which is kept, so please reset your local copy to fef2b7ad before pushing again.

  • The rule (all_transparent_alpha): an element drawn in its category's colour, the shared box or its own mesh, takes the alpha of its materials only where it reads at least one and every one is read as transparent; then it takes the least transparent one's, so no part is drawn fainter than it is. No material, a layer or index that names none, one whose transparency was not read or lies outside 0 to 1, or one read as opaque, keeps the category's alpha.
  • Windows, curtain panels and rooms keep their translucent category colour exactly as on main, so point 2 above no longer arises.
  • Point 1: an element that keeps the category's alpha goes back to category_materials, so no category's opaque material is written twice. A see-through one is Category <class> transparent.
  • Point 3: its alphaSource is "file", not the "rvt-rs" point 3 above assumed: under this rule the alpha is one minus one Revit material's own transparency, which is what "file" means. Its colourSource stays "rvt-rs". MaterialExtras and docs/viewer-api.md say so; nothing in the viewer or the scorers reads either mark on a category material.
  • Point 4: tests/gltf_element_alpha.rs is gone, with its lines in the test manifest, and six tests of the helper's failure modes sit beside it in src/ifc/gltf.rs.
  • The changelog fragment says what the rule does and does not do.

Rows, registered before any run of fef2b7ad is read. The probe now also prints, for each element drawn translucent in a category colour, how many distinct transparencies its materials hold and how many of its layers or indices name no material; it runs on measure/2109-head2 (9039680b, this head) and measure/2109-base2 (9aefec4a, main at d089085b).

  1. Every ifc.sha256 and diagnostics.json is identical to main's: only the GLB changes.
  2. No file has a category material duplicated by name and alpha.
  3. The elements drawn translucent in a category colour that main draws opaque are counted by class, alpha and shape (shared box or own mesh). Each has every one of its materials transparent and none unresolved: in the probe's parts lines, transparent equals materials, above 0, and unresolved is 0. The count is reported beside the 104 of the earlier head, and any class other than proxies, or any such element at an alpha of 0.1 or less, is reported. If no open model has such an element, the change is unmeasured on real files, and that is said.
  4. Of those, the ones whose materials hold two or more distinct transparencies are counted; each takes the least transparent one's alpha.
  5. Windows, curtain panels and rooms: their translucent counts by class, alpha and shape equal main's.
  6. On Einhoven, materials total is the same on both sides.
  7. No scorer line moves.

Nothing is needed from you meanwhile.

@DrunkOnJava

Copy link
Copy Markdown
Owner

The rows for fef2b7ad, as read: all seven hold. The Measure (44756684505) and probe_2109_whole_body_alpha on this head and on main (44756695010, 44756704637; 101 models).

  1. Holds. All 120 exports and 102 diagnostics.json are identical to main's, and the same-project gates pass on fef2b7ad.
  2. Holds. No file has a category material duplicated by name and alpha, on either side.
  3. Read. 104 elements are drawn translucent in a category colour where main draws them opaque, all IfcBuildingElementProxy and all on rac_basic: its 8 Water Glass proxies on each of its 13 saves from Revit 2015 to 2027, whose type draws them in Glass - Crystal Wine Glass and Juice, with none unresolved. On the 2015 and 2016 saves both materials read 0.95 transparent, so the 16 glasses there come out at an alpha of 0.05, on the shared box; from 2017 they come out at 0.15 (48 on the shared box, 40 on their own mesh), so both read 0.85. main already writes those two materials with those transparencies (read for 2015 and 2016 in the exports of 44776183002); whether the sample's materials changed between saves is not read. No other class appears.
  4. Read. None of the 104 holds two distinct transparencies, so the choice of the least transparent one is not exercised on any open model; the helper's tests cover it.
  5. Holds. Windows, curtain panels and rooms are drawn translucent exactly as on main, by class, alpha and shape, on every file.
  6. Holds. On Einhoven, materials total is the same on both sides. On each rac_basic save it grows by one, the Category IFCBUILDINGELEMENTPROXY transparent material.
  7. Holds. No scorer line moves.

So on the open models the rule reaches rac_basic's water glasses and nothing else: no door, lamp or window. @zenglanmu, on your project that means your glass doors and fixtures stay opaque unless every material they read is transparent; which part of a saved mesh is the glass is now #2112. Next, the description is brought in line with the rule, and the pull request goes ready for full CI. Part of its diff is mine, so its approval is a maintainer's approval of my own code as well as yours.

@DrunkOnJava DrunkOnJava changed the title fix(ifc): keep material alpha for glTF bodies drawn whole fix(ifc): a glTF body drawn whole whose materials are all transparent takes their alpha (#1812) Nov 20, 2026
@DrunkOnJava
DrunkOnJava marked this pull request as ready for review November 20, 2026 16:48
@DrunkOnJava
DrunkOnJava self-requested a review as a code owner November 20, 2026 16:48
@DrunkOnJava
DrunkOnJava merged commit bc89a55 into DrunkOnJava:main Nov 20, 2026
65 checks passed
@DrunkOnJava

Copy link
Copy Markdown
Owner

Merged as bc89a55b. Thank you, @zenglanmu. As it landed, a body drawn whole in its category's colour takes its materials' alpha only where every material it reads is transparent; windows, curtain panels and rooms keep their translucent category colour as before. On the open models that reaches rac_basic's water glasses. A door or fixture of yours made only of transparent materials now turns see-through; one with a glass part stays opaque until we can tell which part of a saved mesh is the glass, which #2112 now tracks. One count on #2112 would help: how many of your 17 glass doors and 149 glass fixtures come out see-through on bc89a55b.

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.

2 participants