As Grease Pencil has no canvas flipping function, I'd like to write a script to invert the 3D view on its X axis.
It's possible to do this on a camera object by negating its local X scale, but no such option exists for the 3D view; I believe its matrix must be modified mathematically, which I'm not sure how to do.
I've been testing everything in the console. To find the view matrix, I start by grabbing the first 'VIEW_3D' area in the interface:
for area in bpy.context.window.screen.areas:
if ( area.type == 'VIEW_3D' ):
v3d = area;
Then, I can print its 3d view matrix with the following line:
v3d.spaces.active.region_3d.view_matrix
I can rotate the view by passing a quaternion to v3d.spaces.active.region_3d.view_rotation
, or translate it by changing the components of v3d.spaces.active.region_3d.view_matrix.translation
.
view_matrix
does have a Scale()
function, but I don't know how it works and can't find any examples.
So, is there a way to flip the 3D view on its X axis in Blender Python?
Additional context: I don't know if mirroring the view will affect the modals for rotations and translations, which is another potential problem.
Also, my previous attempt at canvas rotation/mirroring involved rotating the active camera rather than the view. This works (when I'm looking through the camera), but modifies the camera's transform and adds the operation to the Undo stack, meaning that hitting Ctrl+Z reverses the canvas manipulation; extremely cumbersome when sketching roughs in Grease Pencil and regularly undoing stroke operations.