iTwin / itwinjs-core

Monorepo for iTwin.js Library
https://www.itwinjs.org
MIT License
615 stars 210 forks source link

Colorize cut geometry #5910

Closed markschlosseratbentley closed 9 months ago

markschlosseratbentley commented 1 year ago

Allow section cuts to change the color for better visibility.

In the clipping fragment shader, if a fragment is within a certain distance of clip plane, instead of discarding it, change its color - color and distance being configurable.

This will result in colorizing geometry that is near the clip plane, emphasizing where the cut is happening.

For example, here is a manually edited screenshot of a public iModel where a clip plane is applied to the scene, but the circled area has geometry that is "cut" showing up as red because it is very near the clip plane. Note: this is just for illustration purposes! It would look better done for real, not done manually.

Image

pmconne commented 1 year ago

Example To exaggerate the effect in the above example, edit edgeWidth and edgeColor as follows:

  clippingPlanes = new Cesium.ClippingPlaneCollection({
    planes: [
      new Cesium.ClippingPlane(
        new Cesium.Cartesian3(0.0, 0.0, -1.0),
        0.0
      ),
    ],
    edgeWidth: viewModel.edgeStylingEnabled ? 5.0 : 0.0,
    edgeColor: Cesium.Color.RED,
  });

The glsl ought to be dead simple: compute min distance of fragment to any plane (in pixels, not meters - may need to convert). Probably add to ClipStyleProps something like:

  intersectStyle?: {
    color?: ColorDefProps; // default white
    width?: number; // in pixels, default 1
}
markschlosseratbentley commented 11 months ago

Transparency fixes are pushed to the branch. Pending resolution of remaining comments.

markschlosseratbentley commented 11 months ago

https://github.com/iTwin/itwinjs-core/pull/6008