Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disableClipStyle to BranchState #7109

Merged
merged 29 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ad66bc7
Add overrideClipStyle BranchUniform to fix map tile bug
andremig-bentley Aug 26, 2024
acde094
Merge branch 'master' into andremig/clipstyle-bug
andremig-bentley Aug 26, 2024
270d635
rush change
andremig-bentley Aug 26, 2024
a20792e
Update core/frontend/src/render/webgl/BranchUniforms.ts
andremig-bentley Aug 26, 2024
c304bc9
cleanup
andremig-bentley Aug 26, 2024
6eac2f3
Merge branch 'master' into andremig/clipstyle-bug
andremig-bentley Sep 3, 2024
b0b1c6f
Change name to disable, add disable to MapTiles, add unit test
andremig-bentley Sep 3, 2024
ce86e67
Merge branch 'master' into andremig/clipstyle-bug
andremig-bentley Sep 3, 2024
bf81771
extract-api cleanup
andremig-bentley Sep 3, 2024
3994c45
rush lint
andremig-bentley Sep 3, 2024
f71ba30
cleanup
andremig-bentley Sep 4, 2024
33aeaee
Merge branch 'master' into andremig/clipstyle-bug
andremig-bentley Sep 5, 2024
aa926c5
Merge branch 'master' into andremig/clipstyle-bug
andremig-bentley Sep 25, 2024
87dfebf
Merge branch 'master' into andremig/clipstyle-bug
andremig-bentley Sep 25, 2024
a35549e
Merge branch 'andremig/clipstyle-bug' of /~https://github.com/iTwin/itw…
andremig-bentley Sep 25, 2024
d74beed
adding disableClipStyle inheritance from the top of the stack
andremig-bentley Sep 25, 2024
7cad058
Merge branch 'master' into andremig/clipstyle-bug
andremig-bentley Oct 2, 2024
cdce204
Merge branch 'master' into andremig/clipstyle-bug
andremig-bentley Oct 4, 2024
157a0e0
Merge branch 'master' into andremig/clipstyle-bug
pmconne Oct 7, 2024
cc4f8ab
Merge branch 'master' into andremig/clipstyle-bug
pmconne Oct 7, 2024
2ede4fc
disableClipStyle reset on pop, full inheritance from top of stack, ad…
andremig-bentley Oct 9, 2024
b1994b6
setClipStyle based on newly created branchState
andremig-bentley Oct 9, 2024
6c095d5
Merge branch 'master' into andremig/clipstyle-bug
andremig-bentley Oct 9, 2024
509c670
bug fix, test additions
andremig-bentley Oct 9, 2024
86c765c
Merge branch 'master' into andremig/clipstyle-bug
pmconne Oct 9, 2024
da0c702
Merge branch 'master' into andremig/clipstyle-bug
andremig-bentley Oct 9, 2024
3db9a8f
doc fix
andremig-bentley Oct 9, 2024
aa0aba6
Update core/frontend/src/test/render/webgl/BranchUniforms.test.ts
andremig-bentley Oct 9, 2024
cbfa8ab
Merge branch 'master' into andremig/clipstyle-bug
andremig-bentley Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion common/api/core-frontend.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4519,6 +4519,7 @@ export interface GraphicBranchOptions {
// @internal (undocumented)
classifierOrDrape?: RenderPlanarClassifier | RenderTextureDrape;
clipVolume?: RenderClipVolume;
disableClipStyle?: boolean;
// @internal (undocumented)
frustum?: GraphicBranchFrustum;
hline?: HiddenLine.Settings;
Expand Down Expand Up @@ -8915,6 +8916,8 @@ export interface RealityMeshGraphicParams {
// (undocumented)
readonly baseTransparent: boolean;
// (undocumented)
readonly disableClipStyle?: boolean;
// (undocumented)
readonly featureTable: PackedFeatureTable;
// (undocumented)
readonly layerClassifiers?: MapLayerClassifiers;
Expand Down Expand Up @@ -9831,7 +9834,7 @@ export abstract class RenderSystem implements IDisposable {
// @internal (undocumented)
createBackgroundMapDrape(_drapedTree: TileTreeReference, _mapTree: MapTileTreeReference): RenderTextureDrape | undefined;
abstract createBatch(graphic: RenderGraphic, features: RenderFeatureTable, range: ElementAlignedBox3d, options?: BatchOptions): RenderGraphic;
createBranch(branch: GraphicBranch, transform: Transform): RenderGraphic;
createBranch(branch: GraphicBranch, transform: Transform, options?: GraphicBranchOptions): RenderGraphic;
createClipVolume(_clipVector: ClipVector): RenderClipVolume | undefined;
abstract createGraphic(options: CustomGraphicBuilderOptions | ViewportGraphicBuilderOptions): GraphicBuilder;
abstract createGraphicBranch(branch: GraphicBranch, transform: Transform, options?: GraphicBranchOptions): RenderGraphic;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-frontend",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/core-frontend"
}
4 changes: 4 additions & 0 deletions core/frontend/src/render/GraphicBranch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ export interface GraphicBranchOptions {
* @internal
*/
viewAttachmentId?: Id64String;
/** If true, the view's [[DisplayStyleSettings.clipStyle]] will be disabled for this branch.
* No [[ClipStyle.insideColor]], [[ClipStyle.outsideColor]], or [[ClipStyle.intersectionStyle]] will be applied.
*/
disableClipStyle?: boolean;
pmconne marked this conversation as resolved.
Show resolved Hide resolved
}

/** Clip/Transform for a branch that are varied over time.
Expand Down
1 change: 1 addition & 0 deletions core/frontend/src/render/RealityMeshGraphicParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export interface RealityMeshGraphicParams {
readonly baseTransparent: boolean;
readonly textures?: TerrainTexture[];
readonly layerClassifiers?: MapLayerClassifiers;
readonly disableClipStyle?: boolean;
}
4 changes: 2 additions & 2 deletions core/frontend/src/render/RenderSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ export abstract class RenderSystem implements IDisposable {
public abstract createGraphicList(primitives: RenderGraphic[]): RenderGraphic;

/** Create a RenderGraphic consisting of a list of Graphics, with optional transform and symbology overrides applied to the list */
public createBranch(branch: GraphicBranch, transform: Transform): RenderGraphic {
return this.createGraphicBranch(branch, transform);
public createBranch(branch: GraphicBranch, transform: Transform, options?: GraphicBranchOptions): RenderGraphic {
return this.createGraphicBranch(branch, transform, options);
}

/** Create a graphic from a [[GraphicBranch]]. */
Expand Down
6 changes: 6 additions & 0 deletions core/frontend/src/render/webgl/BranchState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export interface BranchStateOptions {
forceViewCoords?: boolean;
readonly viewAttachmentId?: Id64String;
groupNodeId?: number;
/** If true, the view's [[DisplayStyleSettings.clipStyle]] will be disabled for this branch.
* No [[ClipStyle.insideColor]], [[ClipStyle.outsideColor]], or [[ClipStyle.intersectionStyle]] will be applied.
pmconne marked this conversation as resolved.
Show resolved Hide resolved
*/
disableClipStyle?: boolean;
}

/**
Expand All @@ -71,6 +75,7 @@ export class BranchState {
public get realityModelDisplaySettings() { return this._opts.realityModelDisplaySettings; }
public get viewAttachmentId() { return this._opts.viewAttachmentId; }
public get groupNodeId() { return this._opts.groupNodeId; }
public get disableClipStyle() { return this._opts.disableClipStyle;}

public get symbologyOverrides() {
return this._opts.symbologyOverrides;
Expand Down Expand Up @@ -105,6 +110,7 @@ export class BranchState {
realityModelDisplaySettings: branch.branch.realityModelDisplaySettings ?? prev.realityModelDisplaySettings,
viewAttachmentId: branch.viewAttachmentId ?? prev.viewAttachmentId,
groupNodeId: branch.branch.groupNodeId ?? prev.groupNodeId,
disableClipStyle: branch.disableClipStyle,
});
}

Expand Down
14 changes: 14 additions & 0 deletions core/frontend/src/render/webgl/BranchUniforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { RenderCommands } from "./RenderCommands";
import { desync, sync, SyncToken } from "./Sync";
import { Target } from "./Target";
import { ClipStack } from "./ClipStack";
import { IModelApp } from "../../IModelApp";

function equalXYZs(a: XYZ | undefined, b: XYZ | undefined): boolean {
if (a === b)
Expand Down Expand Up @@ -103,6 +104,19 @@ export class BranchUniforms {
public pushBranch(branch: Branch): void {
desync(this);
this._stack.pushBranch(branch);

const vp = IModelApp.viewManager.selectedView;
if (vp) {

/** If the branch has disableClipStyle set, we set these alphas to 0, therefore disabling the clip style.
* Otherwise, we leave it to the viewport's clip style.
*/
const style = vp.view.displayStyle.settings.clipStyle;
pmconne marked this conversation as resolved.
Show resolved Hide resolved
this.clipStack.insideColor.alpha = branch.disableClipStyle ? 0 : (style.insideColor ? 1 : 0);
this.clipStack.outsideColor.alpha = branch.disableClipStyle ? 0 : (style.outsideColor ? 1 : 0);
this.clipStack.intersectionStyle.alpha = branch.disableClipStyle ? 0 : (style.intersectionStyle ? style.intersectionStyle.width : 0);
}

if (this.top.clipVolume)
this.clipStack.push(this.top.clipVolume);

Expand Down
2 changes: 2 additions & 0 deletions core/frontend/src/render/webgl/Graphic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export class Branch extends Graphic {
public readonly appearanceProvider?: FeatureAppearanceProvider;
public readonly secondaryClassifiers?: PlanarClassifier[];
public readonly viewAttachmentId?: Id64String;
public readonly disableClipStyle?: boolean;

public constructor(branch: GraphicBranch, localToWorld: Transform, viewFlags?: ViewFlags, opts?: GraphicBranchOptions) {
super();
Expand All @@ -328,6 +329,7 @@ export class Branch extends Graphic {
this.iModel = opts.iModel;
this.frustum = opts.frustum;
this.viewAttachmentId = opts.viewAttachmentId;
this.disableClipStyle = opts.disableClipStyle;

if (opts.hline)
this.edgeSettings = EdgeSettings.create(opts.hline);
Expand Down
2 changes: 1 addition & 1 deletion core/frontend/src/render/webgl/RealityMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export class RealityMeshGeometry extends IndexedGeometry implements IDisposable,
branch.add(system.createBatch(primitive!, featureTable, mesh.getRange(), { tileId }));
}

return system.createBranch(branch, realityMesh._transform ? realityMesh._transform : Transform.createIdentity());
return system.createBranch(branch, realityMesh._transform ? realityMesh._transform : Transform.createIdentity(), {disableClipStyle: params.disableClipStyle});
}

public collectStatistics(stats: RenderMemory.Statistics): void {
Expand Down
59 changes: 54 additions & 5 deletions core/frontend/src/test/render/webgl/BranchUniforms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { expect } from "chai";
import { dispose } from "@itwin/core-bentley";
import { ClipVector, Point3d, Transform } from "@itwin/core-geometry";
import { ClipVector, Point3d, Transform, Vector3d } from "@itwin/core-geometry";
import { IModelApp } from "../../../IModelApp";
import { ViewRect } from "../../../common/ViewRect";
import { createEmptyRenderPlan } from "../../../render/RenderPlan";
Expand All @@ -13,7 +13,11 @@ import { Branch } from "../../../render/webgl/Graphic";
import { ClipVolume } from "../../../render/webgl/ClipVolume";
import { ClipStack } from "../../../render/webgl/ClipStack";
import { Target } from "../../../render/webgl/Target";
import { EmptyLocalization } from "@itwin/core-common";
import { ClipStyle, EmptyLocalization } from "@itwin/core-common";
import { BranchUniforms } from "../../../render/webgl/BranchUniforms";
import { ScreenViewport } from "../../../Viewport";
import { SpatialViewState } from "../../../core-frontend";
import { createBlankConnection } from "../../createBlankConnection";

function makeClipVolume(): ClipVolume {
const vec = ClipVector.createEmpty();
Expand All @@ -26,14 +30,14 @@ function makeClipVolume(): ClipVolume {
interface ClipInfo {
clip?: ClipVolume;
noViewClip?: boolean; // undefined means inherit from parent on branch stack
disableClipStyle?: boolean;
}

function makeBranch(info: ClipInfo): Branch {
const branch = new GraphicBranch();
if (undefined !== info.noViewClip)
branch.viewFlagOverrides.clipVolume = !info.noViewClip;

const graphic = IModelApp.renderSystem.createGraphicBranch(branch, Transform.identity, { clipVolume: info.clip });
const graphic = IModelApp.renderSystem.createGraphicBranch(branch, Transform.identity, { clipVolume: info.clip, disableClipStyle: info.disableClipStyle });
expect(graphic instanceof Branch).to.be.true;
return graphic as Branch;
}
Expand All @@ -59,13 +63,20 @@ function expectClipStack(target: Target, expected: Array<{ numRows: number }>):
expect(actual[i]).to.equal(expected[i]);
}

function expectClipStyle(uniforms: BranchUniforms, expectedAlphas: number[]): void {
expect(uniforms.clipStack.insideColor.alpha).to.equal(expectedAlphas[0]);
expect(uniforms.clipStack.outsideColor.alpha).to.equal(expectedAlphas[1]);
expect(uniforms.clipStack.intersectionStyle.alpha).to.equal(expectedAlphas[2]);
}

/** Inputs:
* - The view clip and ViewFlags.clipVolume
* - A stack of branches to be pushed
* - The expected stack of ClipVolumes on the ClipStack, including the view clip, after pushing all branches.
* - Whether we expect the view's clip to apply to the top branch.
* - Optionally, the expected Alpha values of the ClipStack's ClipStyle.
*/
function testBranches(viewClip: ClipInfo, branches: ClipInfo[], expectViewClip: boolean, expectedClips: Array<{ numRows: number }>): void {
function testBranches(viewClip: ClipInfo, branches: ClipInfo[], expectViewClip: boolean, expectedClips: Array<{ numRows: number }>, expectedClipStyleAlphaValues?: number[]): void {
const plan = { ...createEmptyRenderPlan(), clip: viewClip.clip?.clipVector };
plan.viewFlags = plan.viewFlags.with("clipVolume", true !== viewClip.noViewClip);

Expand All @@ -86,6 +97,9 @@ function testBranches(viewClip: ClipInfo, branches: ClipInfo[], expectViewClip:
expect(uniforms.clipStack.hasClip).to.equal(expectViewClip || expectedClips.length > 1);
expectClipStack(target, expectedClips);

if (expectedClipStyleAlphaValues)
expectClipStyle(uniforms, expectedClipStyleAlphaValues);

for (const _branch of branches)
target.popBranch();

Expand Down Expand Up @@ -140,4 +154,39 @@ describe("BranchUniforms", async () => {

testBranches({ clip: viewClip }, [{ clip: outerClip }, { clip: innerClip }], true, [viewClip, outerClip, innerClip]);
});

it ("should disable clip style", async () => {
const viewClip = makeClipVolume();
const branchClip = makeClipVolume();

// create a viewport
const imodel = createBlankConnection("imodel");
const viewDiv = document.createElement("div");
viewDiv.style.width = viewDiv.style.height = "100px";
document.body.appendChild(viewDiv);
const view = SpatialViewState.createBlank(imodel, new Point3d(), new Vector3d(1, 1, 1));
const vp = ScreenViewport.create(viewDiv, view);
IModelApp.viewManager.addViewport(vp);
await IModelApp.viewManager.setSelectedView(vp);

// create a clip style and assign it to the viewport
const testStyle = ClipStyle.fromJSON({
insideColor: {r: 255, g: 0, b: 0},
outsideColor: {r: 0, g: 255, b: 0},
intersectionStyle: {
color: {r: 0, g: 0, b: 255},
width: 1,
},
});
vp.clipStyle = testStyle;

// disableClipStyle is false, so we expect the inside color, outside color, and intersection style width to all be 1
testBranches({ clip: viewClip }, [{ clip: branchClip, disableClipStyle: false }], true, [viewClip, branchClip], [1,1,1]);

// disableClipStyle is true, so we expect the branch to have disabled the inside color, outside color, and intersection style width,
// setting all of their alpha values to 0
testBranches({ clip: viewClip }, [{ clip: branchClip, disableClipStyle: true }], true, [viewClip, branchClip], [0,0,0]);

IModelApp.viewManager.dropViewport(vp);
});
});
2 changes: 1 addition & 1 deletion core/frontend/src/tile/map/MapTile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ export class MapTile extends RealityTile {

const textures = this.getDrapeTextures();
const { baseColor, baseTransparent, layerClassifiers } = this.mapTree;
const graphic = IModelApp.renderSystem.createRealityMeshGraphic({ realityMesh: geometry, projection: this.getProjection(), tileRectangle: this.rectangle, featureTable: PackedFeatureTable.pack(this.mapLoader.featureTable), tileId: this.contentId, baseColor, baseTransparent, textures, layerClassifiers }, true);
const graphic = IModelApp.renderSystem.createRealityMeshGraphic({ realityMesh: geometry, projection: this.getProjection(), tileRectangle: this.rectangle, featureTable: PackedFeatureTable.pack(this.mapLoader.featureTable), tileId: this.contentId, baseColor, baseTransparent, textures, layerClassifiers, disableClipStyle: true }, true);

// If there are no layer classifiers then we can save this graphic for re-use. If layer classifiers exist they are regenerated based on view and we must collate them with the imagery.
if (this.imageryIsReady && 0 === this.mapTree.layerClassifiers.size)
Expand Down
Loading