Straighten View

I have a similar question, but regarding repositioning the camera parallel to the closest front/left/right/back view in Perspective viewport while preserving the vertical position and inclination of the camera. With other words, with this command the camera must only rotate along the Z-axis and pan sideways, until it’s straight to one of the 4 main directions (even better, if it can do that to 3/4 views, too, which means 8 directions).

It would be even better, it that command pans horizontally the center of the scene to the center of the screen only when there are no currently selected objects; However, if there is at least one selected objects upon activating that command, it should pan horizontally to the center of its bounding box instead.

Take this, for example. The closest direction to the camera in image c1.png if front view, therefore this command should rotate it along the Z-axis and pan it sideways, so that the center of the scene is shown in the middle of the Perspevtive vievport (i.e. a locked horizontal pan) and the camera is exactly facing the front of the car (image c2.png). Note that the center of the scene (x0,y0,z0) must not move vertically. This is especially useful in product design, such like furniture, vehicles, boats, buildings etc.

Another example from side view:

PS: 3d connexion devices have either dedicated buttons or software commands to reset the viewports in the 4 main directions while in Perspevtive viewport, but they do it so that the camera is pointing exactly sideways towards the center of the scene, resulting in “parallel” Perspective views that sit very low relative to the 3d model.

PS2: I’m aware that I can unhide the camera with F6 and manually adjust it with the mouse, or I can adjust it with numbers from the View tab in the Properties panel, but both ways are too time consuming and require lots of mouse clicks and/or typing with the keyboard.

Hello - it should not be hard to script a version of this - if you think that would be helpful, I can have a try at it.

-Pascal

It would be really great if you can do a script with such functionality. It’s a much needed feature, both, during the design process and presentations. It also helps when the user wants to set specific views for a design patent and needs straight angles in the perspective viewport. :slight_smile:

3DS Max has a view cube on the upper right corner of the viewport that offers similar functionality and can rotate the camera along the Z-axis in the main 8 directions, but it lacks the ability to pan the camera sideways towards the center of the scene.

By the way, I think that it may also help if the “Turntable” command has an option to pick a point or a vertical line (or manually pick any point in the viewport with the Osnap turned on) and use it as an axis for rotation. The current implementation of that command uses the current camera target as an axis, which is a bit unpredictable for presentation purposes.

@Rhino_Bulgaria - see how this works-

To use the Python script use RunPythonScript, or a macro:

_-RunPythonScript "Full path to py file inside double-quotes"

@Rhino_Bulgaria - updated to center the view on the scene bounding box - this can be weird if camera and target are within the bounding box.
@Rhino_Bulgaria - updated again - any better?
@Rhino_Bulgaria - Updated yet again…
ViewSetter.py (1.6 KB)

-Pascal

1 Like

Thanks! :slight_smile: I used “Straighten view” as a tooltip for the command and set it to the RMB of the “Pan view” icon.
I tried the script and it really makes the view straight to front, back, left or right, depending on the closest direction. However, it will not move the camera’s target horizontally towards the center of the scene. If that could be added as well, the scripts will be exactly what I described in my original post.

Bobi

Hi Bobi - right, I am not moving the target , just ‘straigthening’ the view.- you want the target set to the center of the scene bounding box, correct?

-Pascal

The general idea is to preserve the vertical position of the center of the scene, while shifting the camera target to is x0 and y0 coordinate (but not the z one) and rotate it perpendicular to the world xy axles. I drew two new images to better explain what I mean. :slight_smile:
Currently, the script seems to use the exact center of the viewport as a rotation of the camera in order to straighten the view. However, that moves the center of the scene vertically relative to the viewport, wgich should be avoided if possible.

PS: I made the last image later, so the scale is a bit off, but I hope that you get the idea. :slight_smile:

I made two images to show what I mean in regards to the bold portion of the text from the quote above. This is especially useful in architecture, shoe industry, car industry or any other field where the intent is to straighten the view towards two or more selected object for comparison purposes during presentations or the design process, or even for rendering.

@Rhino_Bulgaria - I think the updated version above does this… ?

-Pascal

It definitely works a lot better now and does a fantastic job! Really useful. This script is a must have for Rhino 7. Please, consider it as an official tool.
If only there was a way to preserve the original height of the World grid while shifting the camera target sideways and parallel to the nearest axis, that would be awesome. I drew 3 new images that probably describe what I mean in a better way than my poor English. :slight_smile:

Hello - I’ll monkey with it some more - it should be holding the target’s CPlane Z constant but I may be doing it wrong.

-Pascal

1 Like

@Rhino_Bulgaria - it looks like my script is indeed holding the Z value of the camera target. However, this allows the x and y to move which will indeed, potentuially, move the visual position of the cplane in the perspective viewport, depending on just where the center of the bounding box is compared to the starting target. Hm.

So, it looks like, to make it work the way you want, there has to be some more shenanigans - I’ll see if I can make something work.

-Pascal

1 Like

Thank you for the time and effort you put into this functionality, Pascal! I really appreciate the fact that you do wonders with these scripts and they add so much value to Rhino. Even the current implementation of your script is very handy and makes quick visual comparisons between two models or just taking perpendicular perspective views for rendering purposes so much easier. As I mentioned in an earlier post, trying to manually adjust the camera that way with the F6 camera controls or via the Properties panel is very time consuming. :slight_smile:

Cheers,

Bobi

Hi Bobi - look ^^ up there for the latest attempt (updated) - I think that does what you want now…?

-Pascal

1 Like

Hi Pascal, it works mostly as expected. I only found one exception where the World axis will raise (in fact, the camera target goes down) after running the script and that’s when the view is from slightly above, like shown in the images below. I imagine that it’s related to the fact that initially the target points to the exact center of the viewport and it’s kind of difficult to simultaneously pan and rotate the camera in the 3d space so that the World axis is kept on the same level of the 2d screen itself.

I don’t know if I’ve done any good here, @Rhino_Bulgaria, but I tweaked things a bit more.

ViewSetter.py (1.6 KB)

-Pascal

1 Like

I ran some tests and for now I can’t notice a difference in the way the script repositions the camera compared to the previous version. But it’s still very useful in the current form, because any adjustments to the vertical inclination of the camera could be done afterwards, followed by running the script again to straighten the view. :slight_smile:

@Rhino_Bulgaria, a further little tweak - this is very slightly more ‘accurate’, perhaps. You decide…
ViewSetter.py (2.0 KB)

-Pascal

2 Likes

Oh, yes, this is a bit closer to the goal. I noticed that the World grid now goes almost horizontally towards the middle of the screen. :slight_smile: Thanks!