Skip to main content
added 45 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

Some improvements.

  • Use list comprehension
  • Only need to multiply the local average edge coord by matrix world once.
  • Multiply / divide a vector by a scalar, rather than on a per component basis.

Test script

import bpy
import bmesh

ob = bpy.context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)

mw = ob.matrix_world
elist = [(e, mw * (e.verts[0].co + e.verts[1].co) / 2) 
        for e in bm.edges if e.select]

could make a little helper routine. Will have a default of local avge if not passed a matrix.

def mid_edge(e, matrix=mathutils.Matrix()):       
    return matrix * (e.verts[0].co + e.verts[1].co) / 2

elist = [(e, mw * mid_edge(e)) 
        for e in bm.edges if e.select]        

Some improvements.

  • Use list comprehension
  • Only need to multiply the local average edge coord by matrix world once.
  • Multiply / divide a vector by a scalar, rather than on a per component basis.

Test script

import bpy
import bmesh

ob = bpy.context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)

mw = ob.matrix_world
elist = [(e, mw * (e.verts[0].co + e.verts[1].co) / 2) 
        for e in bm.edges if e.select]

could make a little helper routine. Will have a default of local avge if not passed a matrix.

def mid_edge(e, matrix=mathutils.Matrix()):       
    return matrix * (e.verts[0].co + e.verts[1].co) / 2
    

Some improvements.

  • Use list comprehension
  • Only need to multiply the local average edge coord by matrix world once.
  • Multiply / divide a vector by a scalar, rather than on a per component basis.

Test script

import bpy
import bmesh

ob = bpy.context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)

mw = ob.matrix_world
elist = [(e, mw * (e.verts[0].co + e.verts[1].co) / 2) 
        for e in bm.edges if e.select]

could make a little helper routine.

def mid_edge(e):       
    return (e.verts[0].co + e.verts[1].co) / 2

elist = [(e, mw * mid_edge(e)) 
        for e in bm.edges if e.select]        
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

Some improvements.

  • Use list comprehension
  • Only need to multiply the local average edge coord by matrix world once.
  • Multiply / divide a vector by a scalar, rather than on a per component basis.

Test script

import bpy
import bmesh

ob = bpy.context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)

mw = ob.matrix_world
elist = [(e, mw * (e.verts[0].co + e.verts[1].co) / 2) 
        for e in bm.edges if e.select]

could make a little helper routine. Will have a default of local avge if not passed a matrix.

def mid_edge(e, matrix=mathutils.Matrix()):       
    return matrix * (e.verts[0].co + e.verts[1].co) / 2