Oblique projection Shear matrix to set lattice coords
Note: this is adjusting the lattice coordinates based on the shear required, not the camera. IIRC it has been asked as a feature request to add an Oblique projection to the camera, but AFAIK isn't available yet
Left to right test runs with shear distance set to 1, sqrt(2), and 2
Without getting into too much theory believe this is pretty much shearing the coordinates of the lattice.
For a front ortho projection will shear the XZ plane (side walls) along the x, y vector (1, 1) or some multiple of it.
Test code, adds a cube with an encompassing default lattice and shears it based on settings for front view.
EDIT. Oops forgot to scale the lattice object not the data How do you freeze or reset a lattice?
import bpy
from mathutils import Matrix, Vector
from bpy import context
shear_dist = 1 # sqrt(2) for (1, 1)
shear_vec = Vector((-1, 1)).normalized()
Sh = Matrix.Shear(
'XZ',
4,
shear_dist * shear_vec,
)
T = Matrix.Translation((0, 0.5, 0))
def mm(matrix, space=Matrix()):
return space.inverted() @ matrix @ space
bpy.ops.mesh.primitive_cube_add(
location=(0, 0, 0),
)
cube = context.object
bpy.ops.object.add(
type='LATTICE',
location=(0, 0, 0))
latob = context.object
latob.dimensions = cube.dimensions
lat = latob.data
latmod = cube.modifiers.new("Oblique", type='LATTICE')
latmod.object = latob
lat.transform(mm(Sh))
Of many improvements here possibly moving the origin of the lattice to its front face would be ideal to keep "front" of cube constant, and project back from it when changing the distance of the shear.
Make an operator so can fiddle the settings and visualize.
Add shapekeys for different views and settings, eg Basis is standard no deform, add shape for front view with deform as shown, then add shapekey for side view but shear XZ plane. These could be associated with a set up of ortho cameras or from the views direction vector. (be an interesting exersize)