iTwin / itwinjs-core

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

ViewState3d.lookAtGlobalLocation won't update view unless view area is passed #3390

Closed mdastous-bentley closed 2 years ago

mdastous-bentley commented 2 years ago

Describe the bug Calling ViewState3d.lookAtGlobalLocation with a GlobalLocation parameter that does not contain an area property, won't update the view.

Calling Camera.validateLens() prior to `ViewState3d.lookAtGlobalLocation solves the issue.

To Reproduce Please use this sandbox to reproduce the issue. Basically, the following call is made to center view around Exton office: view.lookAtGlobalLocation( 1000, Angle.createDegrees(65).radians, {center: Cartographic.fromDegrees({longitude: -75.696, latitude: 40.065757})} );

Expected behavior View should be tilted 65 degrees and have an elevation of 1000m

Screenshots

Desktop (please complete the applicable information):

Additional context

markschlosseratbentley commented 2 years ago

Thanks for reporting this issue. We will take a look.

markschlosseratbentley commented 2 years ago

@mdastous-bentley --

@Ellord207 can provide some more details about ViewSetup.getDefaultView, which your sandbox uses. Apparently, that method results in cameras with invalid lenses being returned, which resulted in this problem.

@Ellord207 also suggested to me an alternate approach to the sandbox which would be a preferred method for opening a default view.

Ellord207 commented 2 years ago

The main issues seems to be 2 fold:

The default view of any given iModel is whatever the creator has defined. Sometimes, it can be more contestant to create a new view from scratch than to use the default one. The ViewCreator3d is helpful for doing this.

I have forked and updated your sandbox to use ViewCreator3d(...).createDefaultView(...). After doing so ViewState3d.lookAtGlobalLocation works. I also reorganized the code to follow the best practices when initializing the view state. Here is the sandbox: https://www.itwinjs.org/sandboxes/NathanElrod/Re.GitHubDiscussions-3390

mdastous-bentley commented 2 years ago

All right, so my understanding is that the default view was not setup properly to support ViewState3d.lookAtGlobalLocation. It would be great to get an error code that indicates lookAtGlobalLocation cannot perform with the current view state.

pmconne commented 2 years ago

There's nothing wrong with an orthographic view having an "invalid" camera. lookAtGlobalLocation attempts to support orthographic views - it just doesn't do so properly and needs to be fixed.