Skip to content

Implementation for BENTLEY_materials_line_style#8856

Open
danielzhong wants to merge 30 commits intomasterfrom
daniel/BENTLEY_materials_line_style
Open

Implementation for BENTLEY_materials_line_style#8856
danielzhong wants to merge 30 commits intomasterfrom
daniel/BENTLEY_materials_line_style

Conversation

@danielzhong
Copy link
Contributor

@danielzhong danielzhong commented Dec 11, 2025

Fixes #8836

This PR adds support for the proposed BENTLEY_materials_line_style glTF extension. The proposed specification can be found here.

This PR introduces support for the BENTLEY_materials_line_style extension in glTF. iTwin.js can now interpret and render line primitives with their specified width and pattern properties when loading glTF files. glTF materials can now specify a line width plus a 16‑bit dash bitfield, and we’ll map it either to one of the legacy LinePixels codes or dynamically append a fresh pattern to the shared line-code texture (which now auto-expands beyond the original 10 entries and reloads on demand)

To test this branch:

  1. Clone itwinjs-core
  2. Build test-apps/display-test-app
  3. Run display-test-app
  4. Open blank connection
image
  1. In the keyin field in the top left, enter the keyin: dta gltf
image
  1. Within the file open dialog, open test file line_style.zip

Find the following section in the material definition:

"extensions": {
        "BENTLEY_materials_line_style": {
          "width": 3,
          "pattern": 61694
        }
      }

Then, modify the width and pattern values as you like.

iTwin default line pattern values:

Line Style (LinePixels) 16-bit Pattern JSON / Decimal Description
Solid 0xFFFF 65535 Solid line
Code1 0x8080 32896 1 on, 7 off (dotted)
Code2 0xF8F8 63608 5 on, 3 off
Code3 0xFFE0 65504 11 on, 5 off
Code4 0xFE10 65040 7 on, 4 off, 1 on, 1 off
Code5 0xE0E0 57568 3 on, 5 off
Code6 0xF888 63624 5 on, 3 off, 1 on, 3 off, 1 on, 3 off
Code7 0xFF18 65304 8 on, 3 off, 2 on, 3 off
HiddenLine 0xCCCC 52428 Hidden line (2 on, 2 off)
Invisible 0x0001 1 Invisible line

More customize example:

Custom Pattern Decimal (JSON) Binary (LSB → MSB) Description
0x0F0F 3855 1111000011110000 4 pixels on / 4 pixels off (even rhythm)
0x00FF 255 1111111100000000 8 pixels on / 8 pixels off (long bright segment)
0xC003 49155 1100000000000011 2 on, 12 off, 2 on — isolated short bright spots
0xF0FE 61694 1111111000001111 4 long on, then alternating short on/off — “long–dot-dot” pattern
0xAA55 43605 1010101001010101 Alternating 2 on / 2 off — faster rhythm than the default dotted line (0xAAAA)
Display.Test.App.2025-12-11.15-48-20.mp4

@mergify
Copy link
Contributor

mergify bot commented Dec 11, 2025

This pull request is now in conflicts. Could you fix it @danielzhong? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

@aruniverse aruniverse requested a review from Copilot December 11, 2025 20:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements support for the proposed BENTLEY_materials_line_style glTF extension, enabling iTwin.js to render line primitives with custom widths and patterns from glTF materials. The implementation introduces a dynamic line code texture system that can expand beyond the original 10 predefined patterns to accommodate custom patterns defined in glTF files.

Key changes:

  • Added glTF schema and parser support for the BENTLEY_materials_line_style extension with width and pattern properties
  • Refactored the line code system from static 10-pattern texture to dynamic pattern registration supporting up to 256 patterns
  • Implemented automatic texture reloading when new patterns are registered at runtime

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
core/frontend/src/tile/GltfReader.ts Adds parsing logic for the line style extension, mapping glTF patterns to LinePixels codes and applying them to DisplayParams
core/frontend/src/test/render/webgl/LineCode.test.ts Updates test expectation to reflect dynamic pattern assignment instead of fallback to solid
core/frontend/src/internal/render/webgl/glsl/Polyline.ts Updates shader code to use dynamic capacity constant instead of hardcoded texture height
core/frontend/src/internal/render/webgl/Texture.ts Exports Texture2DCreateParams class to enable texture reloading from System
core/frontend/src/internal/render/webgl/System.ts Implements texture reload mechanism with event listener for dynamic pattern updates
core/frontend/src/internal/render/webgl/LineCode.ts Replaces static pattern data with dynamic texture generation using shared pattern registry
core/frontend/src/common/internal/render/LineCode.ts Implements core pattern registration system with Map-based lookup and event notification
core/frontend/src/common/gltf/GltfSchema.ts Defines TypeScript interface for the BENTLEY_materials_line_style extension

@pmconne
Copy link
Member

pmconne commented Dec 11, 2025

Do you intend to simultaneously enhance the tileset publisher to output this extension, so you can test both sets of changes against one another? Or will you do that later and submit a new PR for any decoding/rendering issues discovered afterward?

}

const textureSize = 32;
const maxLineCodeSlots = 256;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why specifically 256?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a random number. Do you have any suggestions for what a reasonable value would be?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the maximum number of possible unique patterns is 65,536, right? And the maximum height of the texture is given by System.maxTextureSize. It will be less than 65,536, but far more than 256 (typically, 16k). So, no more than the max texture size. (You could of course put more than one pattern on each row of the texture to get around that, but realistically you will never need that many).

@danielzhong
Copy link
Contributor Author

Do you intend to simultaneously enhance the tileset publisher to output this extension, so you can test both sets of changes against one another? Or will you do that later and submit a new PR for any decoding/rendering issues discovered afterward?

I prefer to do that later and follow up with a separate PR if any decoding or rendering issues come up.

@mergify
Copy link
Contributor

mergify bot commented Dec 11, 2025

This pull request is now in conflicts. Could you fix it @danielzhong? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

@danielzhong danielzhong force-pushed the daniel/BENTLEY_materials_line_style branch from 3ab04c3 to 2fc076a Compare December 11, 2025 22:25
@danielzhong danielzhong removed request for a team and rschili December 11, 2025 22:27
First segments look correct, some others are wrong/inconsistent. No creepy-crawly when panning, but when zooming yes.
@danielzhong
Copy link
Contributor Author

danielzhong commented Dec 23, 2025

I have verified the encoding works perfectly with this PR decoding. I also confirmed that both default and non-default line patterns render correctly.

FYI: @pmconne

Line_Style

@danielzhong
Copy link
Contributor Author

danielzhong commented Dec 23, 2025

Added a fix for BENTLEY_materials_point_style. The issue was not caused by this PR; it already exists on the main branch.

FYI: @markschlosseratbentley

@danielzhong danielzhong self-assigned this Dec 24, 2025
@mergify
Copy link
Contributor

mergify bot commented Dec 29, 2025

This pull request is now in conflicts. Could you fix it @danielzhong? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.

@mergify
Copy link
Contributor

mergify bot commented Feb 6, 2026

⚠️ The sha of the head commit of this PR conflicts with #8922. Mergify cannot evaluate rules on this PR. ⚠️

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.

Create iTwin.js reference implementation for proposed glTF extension BENTLEY_materials_line_style

3 participants