iTwin / itwinjs-core

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

Disabling ProjectExtentsDecorations on a specific viewport #3563

Closed ImVeryLost closed 2 years ago

ImVeryLost commented 2 years ago

I noticed that the ProjectExtentsDecorations get displayed on all active spatial viewports, and its impossible to disable or skip a specific one.

I currently have 2 views using the horizontal split - the "default" 3D view, as well as an additional one that displays something else. The secondary viewport is a spatial one, but the decorations/geometry displayed might placed anywhere, e.g. not inside the projects extents range.

The secondary viewport uses a custom viewState, which extends OrthographicViewState.

Now, when the ProjectExtents tool is activated, it displays a range box both in the default view, an in the secondary one, even though its not relevant nor accurate for the second viewport.

It would be great to somehow disable the ProjectExtentsDecorations for the viewport, or otherwise be able to manipulate the decoration so its actually accurate.

pmconne commented 2 years ago

Did you try:

  class ExtentsDecoration extends ProjectExtentsDecoration {
    public decorate(context: DecorateContext): void {
      if (vp.view.isSpatialView() && vp.view.isCameraOn)
        super.decorate(context);
    }
  }

?

ImVeryLost commented 2 years ago

Did you try:

  class ExtentsDecoration extends ProjectExtentsDecoration {
    public decorate(context: DecorateContext): void {
      if (vp.view.isSpatialView() && vp.view.isCameraOn)
        super.decorate(context);
    }
  }

?

I'm running the ToggleProjectExtentsTool tool as is, rather than the decoration directly.

Technically that should do the trick since the secondary viewport does not have the camera on, but the ToggleProjectExtentsTool/ProjectExtentsDecoration would have to be updated... Is that possible to do?

pmconne commented 2 years ago

I'm running the ToggleProjectExtentsTool tool as is, rather than the decoration directly.

So extend or rewrite the tool, changing one word to make it use your customized decorator.

ImVeryLost commented 2 years ago

I'm running the ToggleProjectExtentsTool tool as is, rather than the decoration directly.

So extend or rewrite the tool, changing one word to make it use your customized decorator.

Considering the secondary viewport is part of a separate package than the rest of the viewer, made to be reusable and shared, that does not seem like the correct solution.

pmconne commented 2 years ago

the secondary viewport is part of a separate package than the rest of the viewer, made to be reusable and shared

Sorry, what does this mean?

ImVeryLost commented 2 years ago

the secondary viewport is part of a separate package than the rest of the viewer, made to be reusable and shared

Sorry, what does this mean?

Ah, my bad, that was not very clear. The secondary viewport is part of a separate tool, thats being developed as a separate npm package. So you can add it as a dependency and use it the same way you would use the ToggleProjectExtentsTool itself, or measure-tools, etc, by simply importing it to any project. In other words, I cannot really control how/if the ToggleProjectExtentsTool is used. And sure, i can try to specify how to update the ToggleProjectExtentsTool in consuming projects, or offer my own version, but that seems like the wrong approach.

ImVeryLost commented 2 years ago

Did you try:

  class ExtentsDecoration extends ProjectExtentsDecoration {
    public decorate(context: DecorateContext): void {
      if (vp.view.isSpatialView() && vp.view.isCameraOn)
        super.decorate(context);
    }
  }

?

Its also possible to turn the camera on/off in any view, so I'm not sure it's possible to use this workaround without causing more issues. image

pmconne commented 2 years ago

It sounds like you want a tool that allows you to specify in which viewport(s) to display the decoration. It should be easy for you to write such a tool - most of the code already exists in the frontend-devtools package. That would make for a very nice, simple, useful extension. (Extensions will be ready for use soon).

Please understand the contents of the frontend-devtools package are explicitly intended for use during development and debugging. All of its APIs are perpetually @beta and subject to change. They are not intended to be used as building blocks for user-facing aspects of your applications.

ImVeryLost commented 2 years ago

Well, to be exact, I thought that this specific tool did not work as I expected. In my opinion, assuming that project extents are relevant to all viewports isn't completely correct, as implies that everything should be displayed within project extents and that non-project related decorations aren't valid.

Of course, that might be the case and I just misunderstood how things should work.

pmconne commented 2 years ago

It's a tool for debugging issues with project extents. The person doing the debugging wouldn't use it on a viewport for which the project extents aren't relevant.

ImVeryLost commented 2 years ago

It's a tool for debugging issues with project extents. The person doing the debugging wouldn't use it on a viewport for which the project extents aren't relevant.

That's a fair point, its just a pity that there is no way to specify if the projects extents are relevant or not.