Skip to main content
5 of 6
deleted 375 characters in body
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

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

enter image description here

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()
lattice_res = 8

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
lat.points_u = lattice_res
lat.points_v = lattice_res
lat.points_w = lattice_res

latmod = cube.modifiers.new("Oblique", type='LATTICE')
latmod.object = latob

lat.transform(mm(Sh, T))

Ok have it better now, the leading face of the cube stays in place.

Next step add shape keys for the projections eg TOP, LEFT, ... have FRONT

batFINGER
  • 85.2k
  • 10
  • 114
  • 244