Skip to content

Commit

Permalink
Add disableClipStyle to BranchState (#7109)
Browse files Browse the repository at this point in the history
Co-authored-by: andremig-bentley <andremig-bentley@users.noreply.github.com>
Co-authored-by: Ben Polinsky <78756012+ben-polinsky@users.noreply.github.com>
Co-authored-by: Paul Connelly <22944042+pmconne@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 9, 2024
1 parent 7e6467d commit b42bedd
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 10 deletions.
5 changes: 4 additions & 1 deletion common/api/core-frontend.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4562,6 +4562,7 @@ export interface GraphicBranchOptions {
// @internal (undocumented)
classifierOrDrape?: RenderPlanarClassifier | RenderTextureDrape;
clipVolume?: RenderClipVolume;
disableClipStyle?: true;
// @internal (undocumented)
frustum?: GraphicBranchFrustum;
hline?: HiddenLine.Settings;
Expand Down Expand Up @@ -9069,6 +9070,8 @@ export interface RealityMeshGraphicParams {
// (undocumented)
readonly baseTransparent: boolean;
// (undocumented)
readonly disableClipStyle?: true;
// (undocumented)
readonly featureTable: PackedFeatureTable;
// (undocumented)
readonly layerClassifiers?: MapLayerClassifiers;
Expand Down Expand Up @@ -10022,7 +10025,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;
// @internal (undocumented)
createGeometryFromMesh(mesh: Mesh, viOrigin: Point3d | undefined): RenderGeometry | undefined;
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 @@ -160,6 +160,10 @@ export interface GraphicBranchOptions {
* @internal
*/
viewAttachmentId?: Id64String;
/** If true, the view's [DisplayStyleSettings.clipStyle]($common) will be disabled for this branch.
* No [ClipStyle.insideColor]($common), [ClipStyle.outsideColor]($common), or [ClipStyle.intersectionStyle]($common) will be applied.
*/
disableClipStyle?: true;
}

/** 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?: true;
}
4 changes: 2 additions & 2 deletions core/frontend/src/render/RenderSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,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 @@ -46,6 +46,10 @@ export interface BranchStateOptions {
forceViewCoords?: boolean;
readonly viewAttachmentId?: Id64String;
groupNodeId?: number;
/** If true, the view's [DisplayStyleSettings.clipStyle]($common) will be disabled for this branch.
* No [ClipStyle.insideColor]($common), [ClipStyle.outsideColor]($common), or [ClipStyle.intersectionStyle]($common) will be applied.
*/
disableClipStyle?: true;
}

/**
Expand Down Expand Up @@ -73,6 +77,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 @@ -108,6 +113,7 @@ export class BranchState {
realityModelDisplaySettings: branch.branch.realityModelDisplaySettings ?? prev.realityModelDisplaySettings,
viewAttachmentId: branch.viewAttachmentId ?? prev.viewAttachmentId,
groupNodeId: branch.branch.groupNodeId ?? prev.groupNodeId,
disableClipStyle: branch.disableClipStyle ?? prev.disableClipStyle,
});
}

Expand Down
16 changes: 16 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,9 @@ export class BranchUniforms {
public pushBranch(branch: Branch): void {
desync(this);
this._stack.pushBranch(branch);

this.setClipStyle(this.top.disableClipStyle);

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

Expand All @@ -126,6 +130,7 @@ export class BranchUniforms {
this.clipStack.pop();

this._stack.pop();
this.setClipStyle(this.top.disableClipStyle);
}

public pushViewClip(): void {
Expand Down Expand Up @@ -251,4 +256,15 @@ export class BranchUniforms {

return true;
}

// set the clip style based on disableClipStyle
private setClipStyle(disableClipStyle: true | undefined) {
const vp = IModelApp.viewManager.selectedView;
if (vp) {
const style = vp.view.displayStyle.settings.clipStyle;
this.clipStack.insideColor.alpha = disableClipStyle ? 0 : (style.insideColor ? 1 : 0);
this.clipStack.outsideColor.alpha = disableClipStyle ? 0 : (style.outsideColor ? 1 : 0);
this.clipStack.intersectionStyle.alpha = disableClipStyle ? 0 : (style.intersectionStyle ? style.intersectionStyle.width : 0);
}
}
}
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 @@ -315,6 +315,7 @@ export class Branch extends Graphic {
public readonly appearanceProvider?: FeatureAppearanceProvider;
public readonly secondaryClassifiers?: PlanarClassifier[];
public readonly viewAttachmentId?: Id64String;
public disableClipStyle?: true;
public readonly transformFromExternalIModel?: Transform;

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

if (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 @@ -384,7 +384,7 @@ export class RealityMeshGeometry extends IndexedGeometry implements RenderGeomet
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
Loading

0 comments on commit b42bedd

Please sign in to comment.