Skip to content

Keep zoom during rotation using the buttons of the 3D-viewport #4750

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

Merged
merged 16 commits into from
Aug 11, 2020

Conversation

MichaelBuessemeyer
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer commented Aug 3, 2020

This PR reworks the functionality of the rotation buttons of the 3D-Viewport. The zoom is now kept during rotation and the calculation is now shorted, commented and easier to understand.

URL of deployed dev instance (used for testing):

Steps to test:

  • View a dataset. The initial view of the 3d-viewport should show all three planes (independent of the z coordinate of the flycam). The whole width of the dataset should be displayed in the viewport.
  • Now rotate the dataset in the viewport a bit and change the zoom and use the rotation buttons as you like. The rotation of the camera should always be as expected.
  • One exception: The rotation of the buttons might look a bit off due to not using always the shortest path because we do not use quaternions for interpolation.

Issues:


@fm3 fm3 changed the title Keep zoom during toation using the buttons of the 3D-viewport Keep zoom during roation using the buttons of the 3D-viewport Aug 3, 2020
@daniel-wer daniel-wer changed the title Keep zoom during roation using the buttons of the 3D-viewport Keep zoom during rotation using the buttons of the 3D-viewport Aug 5, 2020
Copy link
Member

@daniel-wer daniel-wer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work digging into this and simplifying the code! 👍 I think there's still a little bit of room to make this work even better :)

One exception: The rotation of the buttons might look a bit off due to not using always the shortest path because we do not use quaternions for interpolation.

This distracts me more than I would've thought. The "crazy" rotations that happen sometimes make it hard to keep the correct spatial picture in my head. I tested the buttons using the old code, and there the rotations seem to always use the shortest path - What's the difference to the new code, why does it not work that way any longer?

On a more general note, please proofread the comments you're writing to make sure they're concise, understandable to future readers and without spelling mistakes. :)

b: squareCenterY - height / 2,
};
// Factor to reduce the clipping offset of the z coordinate to get a better angle on the dataset.
const zReductionFactor = 0.7;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed because of the different z-scale in relation to x and y? If so, shouldn't it be computed from the dataset scale automatically as dataset scales differ widely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of this as a way to simply change the view angle at the dataset. Here are two examples:
With zReductionFactor = 1:
image
With zReductionFactor = 0.7:
image
As you can see: The angle changed.

But if you compare these I think the first version is fine too and thus the factor can be omitted.

@MichaelBuessemeyer
Copy link
Contributor Author

This distracts me more than I would've thought. The "crazy" rotations that happen sometimes make it hard to keep the correct spatial picture in my head. I tested the buttons using the old code, and there the rotations seem to always use the shortest path - What's the difference to the new code, why does it not work that way any longer?

To be honest, I had trouble understanding how the previous code worked. That's why I cannot say what actually the difference is between before and this version. But maybe I should really investigate some more time into fine-tuning the rotation to not do something "crazy"

Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This distracts me more than I would've thought. The "crazy" rotations that happen sometimes make it hard to keep the correct spatial picture in my head. I tested the buttons using the old code, and there the rotations seem to always use the shortest path - What's the difference to the new code, why does it not work that way any longer?

To be honest, I had trouble understanding how the previous code worked. That's why I cannot say what actually the difference is between before and this version. But maybe I should really investigate some more time into fine-tuning the rotation to not do something "crazy"

Definitely kudos to you for digging through the old (and not easy-to-read) code and adapting it 👍 👍 👍
Regarding the rotations, maybe it's easiest to just use quaternions (which threejs supports actively) instead of trying to understand what changed in this PR (since the animation wasn't perfect before, either). Here's an example in threejs (code is linked, too):
https://threejs.org/examples/#webgl_math_orientation_transform

So, maybe this is worth a try to integrate quaternions? If this is too much of a hassle, we could re-consider the importance. But maybe it's "quite simple"? :)

@MichaelBuessemeyer
Copy link
Contributor Author

@daniel-wer I tried out using quaternions to smooth the rotation, but somehow the camera does not update after applying the desired quaternion. I pushed the code I used to test rotating a not used camera to branch try-out-quaternions.

-> Thus I would not invest more time into this unless a customer or so is really irritated by the weird rotation. Previously, the rotation was also a bit off in some cases.
=> I suggest to keep the code as it is. Is that ok with you?

@MichaelBuessemeyer
Copy link
Contributor Author

@daniel-wer I had another chat with @philippotto about the weird rotation and we found out that the "3D" preset had "wrong" values and corrected them to work fine with the other presets. Thus the rotation between all presets does not look weird anymore.

Nevertheless, the problem that the rotation in some cases is looks weird still exists. For that, we need to interpolate the position on a sphere. But this should be done in another pr 🙂

@MichaelBuessemeyer
Copy link
Contributor Author

@philippotto As daniel is currently unavailable, do you want to take over reviewing this pr?

@philippotto
Copy link
Member

@philippotto As daniel is currently unavailable, do you want to take over reviewing this pr?

Sure thing! I just gave it another test and this PR vastly improves the rotation 👍 Very pleasant to use.

However, I noticed one issue concerning the aspect ratio / scale.

If the 3D viewport is not square, the rendered plane is squished somehow:
image

Compare this to the current master:
image

In both cases, I clicked the XY button. Probably left-right and top-bottom need to be adapted to the aspect ratio of the 3D view? Something in this direction, I'd guess. If this is fixed, this PR should be good to merge :)

@MichaelBuessemeyer
Copy link
Contributor Author

@philippotto Thanks for finding this bug. I accidentally forgot to remove a reassignment of width and height. The bug should be fixed now

Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Looks and feels very good 👍 I left some last nitpick, but other than that, I think it's good to go :)

@MichaelBuessemeyer MichaelBuessemeyer merged commit 447f8bd into master Aug 11, 2020
@daniel-wer
Copy link
Member

Just wanted to say, the rotation is much better now! Really cool work 🚀

@jstriebel jstriebel deleted the keep-zoom-during-td-button-rotation branch September 10, 2020 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switching 3D view via button zooms away
3 participants