0
$\begingroup$

I am looking into vectors and matrices but don't yet understand how I could achieve one of my goals for a script I'm making. I want to use bmesh.ops.scale() and scale selected verts relative to my active edge. It would be similar to setting Pivot to Active Element for the regular resize command in blender. The bmesh scale should also ignore the vector of the active edge itself. That would be similar to only scaling on X and Y but not Z for example. So in my case the axis exluded in the scaling would be my active edge vector, instead of Z.

Thanks for help!

$\endgroup$

1 Answer 1

1
$\begingroup$

Intersect point with line.

Rather than use the bmesh scale operator, another technique using the method

mathutils.geometry.intersect_point_line(...)

Takes a point and a line and returns a tuple with the closest point on the line and its distance from the first point of the line as a percentage of the length of the line.

To find the radial from each vertex to the axis of scale ie the active edge. For each vertex v in selection, find the closest point o to the line defined by the edge . Translate the vert along vector v.co - o from the point o by a scale factor.

Quick code, the verts of the edge could be removed from the selection. Since they are on the line there will be no (except error tolerance) transformation anyway.

import bpy
import bmesh
from mathutils.geometry import intersect_point_line

context = bpy.context
ob = context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)
scale_factor = 2
edge = bm.select_history.active
# if isinstance(edge, bmesh.types.BMEdge):
verts = [v for v in bm.verts if v.select]
for v in verts:
    o, pc = intersect_point_line(v.co, edge.verts[0].co, edge.verts[1].co)
    v.co = o + scale_factor * (v.co - o)

bmesh.update_edit_mesh(me)

enter image description here
Result of running on default cube, with active edge and its diagonally opposed edge selected

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .