Spiri
Spiri

Reputation: 419

Bevel in blender with bmesh after extrusion

I've been trying to bevel with bmesh in Blender for a few hours. With bpy.ops this works without any problems but that's exactly what I want to avoid. Switching to edit mode makes the code very slow if you iterate through 100 objects or more.

All my attempts so far have resulted in incorrect bevel results. I just can't manage to select the outer edges after extrusion with bmesh in order to then bevel them.

if extrude:
    bpy.context.view_layer.objects.active = obj
    obj.select_set( True )

    for other_obj in bpy.context.view_layer.objects:
        if other_obj != obj:
            other_obj.select_set( False )

    if bpy.context.object and bpy.context.object.type == 'MESH':
        obj = bpy.context.object
                    
        mesh = obj.data

        bm = bmesh.new()
        bm.from_mesh( mesh )

        bmesh.ops.remove_doubles( bm, verts=bm.verts, dist = merge_threshold ) 

        vertices = [ v.co for v in obj.data.vertices if v.select ]

        center = sum( vertices, mathutils.Vector( ( 0.0, 0.0, 0.0 ) ) ) / len( vertices )

        direction = mathutils.Vector( ( 0, 0, center.z ) ) - center
        direction.normalize()
        distance = brickheight

        geom_extrude = bmesh.ops.extrude_face_region(bm, geom = bm.faces)

        bmesh.ops.translate( bm, vec = direction * distance, verts=[ v for v in geom_extrude["geom"] if isinstance( v, bmesh.types.BMVert ) ] )
                
        #-----------------------------------------

        #Does anyone know what is best suited to beveling the outer edges with bmesh?


        #-----------------------------------------

        bm.to_mesh( mesh )
        bm.free()
    
    
                    
        #bpy.ops.object.mode_set( mode='EDIT' )
        #bpy.ops.mesh.edges_select_sharp( sharpness=0.523599 )
        #bpy.ops.mesh.bevel( offset=bevel_amount, segments=bevel_segments, profile = 0.5, clamp_overlap = True )
        #bpy.ops.object.mode_set( mode='OBJECT' )
                    
                    
obj.select_set( False )

Upvotes: 0

Views: 17

Answers (0)

Related Questions