Non uniform scale along custom axis

Hi, I’m trying to create a small addon for creating pipes with a consistent radius from curves (trying to solve this problem).

I’m converting the curve into a mesh and want to resize the resulting circles in the corners to ellipses, according to previously calculated sizes, so the cylinders between those circles have parallel edges. The scaling has to be applied along a specified plane, like using the view orientation, not global or local. That way, the height (perpendicular to both edges connected by the circle) can stay unchanged.
The resize function however does not allow to enter vectors, it only accepts true or false for x/y/z to determine the constraints.

How can I set a custom constraint axis for the resize function?
Thanks in advance.

I found a workaround: Just rotate the part that has to be scaled, so it aligns with the global axis, scale it and rotate it back.

Here’s an example:

import bpy, bmesh
from mathutils import Matrix

# def angle(v1, v2): ...
# my_bmesh = ...
# my_selection = ...
# scale_factor = ...

# Create rotation matrices
rotation_axis = cross(normal, (0, 0, 1))
rotation_angle = angle(normal, (0, 0, 1))
rotation_matrix = Matrix.Rotation(rotation_angle, 4, rotation_axis)
undo_rotation_matrix = Matrix.Rotation(-rotation_angle, 4, rotation_axis)

# Rotate, scale, rotate back
bmesh.ops.rotate(my_bmesh, cent=(0, 0, 0), matrix=rotation_matrix, verts=my_selection)
bpy.ops.transform.resize(value=(scale_factor, scale_factor, 0), constraint_axis=(True, True, False))
bmesh.ops.rotate(my_bmesh, cent=(0, 0, 0), matrix=undo_rotation_matrix, verts=my_selection)
1 Like