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

Set perspective camera distance based on bounding box diameter so we no longer get dizzy!!!! #7338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

n8bot
Copy link
Contributor

@n8bot n8bot commented Nov 24, 2021

Resolves #3699
Partially resolves #5484
Might help this person, too #3892
Fixes small beds having camera look very zoomed in.
Fixes an issue when a part is scaled too large by accident. When scaled back down, if the camera distance is too large, the GUI flickers.

Perspective camera distance is now constantly set to bounding box radius. It now shrinks smoothly, as well as growing, to accommodate new sizes, to a minimum distance equal to bounding box radius.

This will help a lot with Prusa XL, and other larger printers. Also helps with the mini, SL1S, and smaller printers. Also helps with medium printers. So, all printers.

Basically, no matter the size of the print bed, the camera perfectly scales to behave "the same," relatively. I.e., when a new printer config is loaded, the new bed is framed exactly as the previous one, regardless of size difference. The camera is virtually positioned just outside the edge of the bed, allowing the added sense of perspective. (Rather, a bounding box radius from center of bed, which from the top can be less than expected but still works well.)

The following screenshots were all taken with the default camera orientation. The camera always adapts to new scene sizes:
POV1
POV2
POV3
POV4

Notice the difference between perspective and orthographic cameras on the SL1S, patched vs unpatched:
POV5
POV6
POV7
POV8

This also allows for when people accidentally scale their models way too big, and need to scale it back down. The camera now recovers distance, and therefore FOV, smoothly with no glitching or flickering, as described in this old code comment from stock PrusaSlicer source:

// The following is commented out because it causes flickering of the 3D scene GUI
// when the bounding box of the scene gets large enough
// We need to introduce some smarter code to move the camera back and forth in such case

The reason for newly not including the gizmos in the bounding box is so when rescaling with the gizmo, there is no sudden jumps in camera view when exiting gizmo. (Rather -- not so many. Extreme scales still have weird jumps occasionally, but this is to be expected... try it out. This solution works unreasonably well compared to the previous commented-out method.)

All this said... the original comment called for a new "smarter code" solution. I don't think any of my "code" can be called smart. So I will let you all decide how to proceed.

Side note:
For some reason, when changing camera.cpp sometimes I get this MSVC compiler error on first build. This is fixed by rebuilding all projects, and sometimes just by clicking build again:

13>------ Build started: Project: PrusaSlicer, Configuration: RelWithDebInfo x64 ------
13>PrusaSlicer.cpp
13>   Creating library D:/source/repos/PrusaSlicer/build/src/RelWithDebInfo/PrusaSlicer.lib and object D:/source/repos/PrusaSlicer/build/src/RelWithDebInfo/PrusaSlicer.exp
13>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
13>LINK : fatal error LNK1201: error writing to program database ''; check for insufficient disk space, invalid path, or insufficient privilege
13>Done building project "PrusaSlicer.vcxproj" -- FAILED.

If you encounter the above error, please just try building again, and if that doesn't work, nuke the the build directory "RelWithDebInfo" or whatever and build all projects. I promise the code does compile in MSVC, from fresh projects/solution.

@bubnikv
Copy link
Collaborator

bubnikv commented Nov 29, 2021

makes me dizzy, not legit

@n8bot
Copy link
Contributor Author

n8bot commented Nov 29, 2021

Lol wat? Seeing perspective makes you dizzy? There is an orthographic camera for that. 😀

@n8bot
Copy link
Contributor Author

n8bot commented Dec 4, 2021

I might know why you got dizzy. With setting the camera at radius of bb, by viewing from top and focusing on bed, we have to move back to re-frame, and that causes a "vertigo" effect, from zooming and moving at the same time.

If you really really dislike this effect (I'm not personally bothered by it) the camera distance could be instead set to radius*2+min_z_distance. Aka, make sure we're setting the camera back enough so it doesn't get too close when viewed from top and the bed is the m_target.

Of course, this change would lower the effect of the perspective, it would still provide additional perspective effect over the stock prusaslicer 1 m distance, for beds/scenes up to 400 800 mm diameter. Then, the perspective effect would be even lower than stock prusaslicer... hmm. I think radius is best. lol

Restores camera position smoothly if bounding box is scaled up and down.
@n8bot n8bot force-pushed the n8_perspective_camera branch from 779cc47 to dda99ac Compare January 5, 2022 06:46
@n8bot
Copy link
Contributor Author

n8bot commented Jan 5, 2022

Ok. @bubnikv, you were correct. I too became dizzy with the previous changes I made. So I changed to be based on diameter, instead of radius, and everything seems much less nauseating.

Plz ignore the photos and other information in this thread because it was all showing the radius, not diameter-based perspective camera.

@n8bot n8bot changed the title Set perspective camera distance based on bounding box radius Set perspective camera distance based on bounding box diameter so we no longer get dizzy!!!! Jan 5, 2022
@araghon007
Copy link

Please, merge this PR to make the perspective camera actually useful. If you want to use the original camera view, just use orthographic as there is very little difference between the two at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants