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

[WIP] Snap to elements within section drawing attachments #7267

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
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
33 changes: 24 additions & 9 deletions core/frontend/src/DrawingViewState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { RenderGraphic } from "./render/RenderGraphic";
import { Scene } from "./render/Scene";
import { DisclosedTileTreeSet, TileGraphicType } from "./tile/internal";
import { SceneContext } from "./ViewContext";
import { OffScreenViewport } from "./Viewport";
import { OffScreenViewport, Viewport } from "./Viewport";
import { ViewRect } from "./common/ViewRect";
import { AttachToViewportArgs, ExtentLimits, ViewState2d, ViewState3d } from "./ViewState";
import { AttachToViewportArgs, ComputeDisplayTransformArgs, ExtentLimits, ViewState2d, ViewState3d } from "./ViewState";

/** Strictly for testing.
* @internal
Expand Down Expand Up @@ -167,7 +167,7 @@ class SectionTarget extends MockRender.OffScreenTarget {
*/
class SectionAttachment {
private readonly _viewFlagOverrides: ViewFlagOverrides;
private readonly _toDrawing: Transform;
public readonly toDrawing: Transform;
private readonly _fromDrawing: Transform;
private readonly _viewRect = new ViewRect(0, 0, 1, 1);
private readonly _originalFrustum = new Frustum();
Expand All @@ -187,13 +187,13 @@ class SectionAttachment {
}

public get drawingRange() {
const frustum3d = this._originalFrustum.transformBy(this._toDrawing);
const frustum3d = this._originalFrustum.transformBy(this.toDrawing);
return frustum3d.toRange();
}

public constructor(view: ViewState3d, toDrawing: Transform, fromDrawing: Transform, toSheet: Transform | undefined) {
// Save the input for clone(). Attach a copy to the viewport.
this._toDrawing = toDrawing;
this.toDrawing = toDrawing;
this._fromDrawing = fromDrawing;

this.viewport = OffScreenViewport.createViewport(view, new SectionTarget(this), true);
Expand All @@ -203,14 +203,15 @@ class SectionAttachment {
let clip = this.view.getViewClip();
if (clip) {
clip = clip.clone();
const clipTransform = toSheet ? toSheet.multiplyTransformTransform(this._toDrawing) : this._toDrawing;
const clipTransform = toSheet ? toSheet.multiplyTransformTransform(this.toDrawing) : this.toDrawing;
clip.transformInPlace(clipTransform);
clipVolume = IModelApp.renderSystem.createClipVolume(clip);
}

this._branchOptions = {
clipVolume,
hline: view.getDisplayStyle3d().settings.hiddenLineSettings,
viewAttachmentId: view.id,
frustum: {
is3d: true,
scale: { x: 1, y: 1 },
Expand All @@ -223,7 +224,7 @@ class SectionAttachment {
this.viewport.setupFromView();
this.viewport.viewingSpace.getFrustum(CoordSystem.World, true, this._originalFrustum);

const drawingFrustum = this._originalFrustum.transformBy(this._toDrawing);
const drawingFrustum = this._originalFrustum.transformBy(this.toDrawing);
const drawingRange = drawingFrustum.toRange();
this._drawingExtents = drawingRange.diagonal();
this._drawingExtents.z = Math.abs(this._drawingExtents.z);
Expand All @@ -242,7 +243,7 @@ class SectionAttachment {
return;

// Adjust offscreen viewport's frustum based on intersection with drawing view frustum.
const frustum3d = this._originalFrustum.transformBy(this._toDrawing);
const frustum3d = this._originalFrustum.transformBy(this.toDrawing);
const frustumRange3d = frustum3d.toRange();
const frustum2d = context.viewport.getWorldFrustum();
const frustumRange2d = frustum2d.toRange();
Expand Down Expand Up @@ -283,7 +284,7 @@ class SectionAttachment {
for (const graphic of source)
graphics.entries.push(graphic);

const branch = context.createGraphicBranch(graphics, this._toDrawing, this._branchOptions);
const branch = context.createGraphicBranch(graphics, this.toDrawing, this._branchOptions);
context.outputGraphic(branch);
};

Expand Down Expand Up @@ -502,4 +503,18 @@ export class DrawingViewState extends ViewState2d {
public override get secondaryViewports() {
return this._attachment ? [this._attachment.viewport] : super.secondaryViewports;
}

/** @internal */
public override getAttachmentViewport(id: Id64String): Viewport | undefined {
return id === this._attachment?.view.id ? this._attachment.viewport : undefined;
}

/** @internal */
public override computeDisplayTransform(args: ComputeDisplayTransformArgs): Transform | undefined {
if (args.viewAttachmentId === undefined || args.viewAttachmentId !== this._attachment?.view.id) {
return undefined;
}

return this._attachment.toDrawing;
}
}
Loading