Blender Geometric Shapes Workflow – Using Vibe Coding

Blender geometric shapes work flow

Blender Geometric Shapes Workflow - Using Vibe Coding

Art, Technology & Nature

I am working on my new series based on travel and cities. I've been diving heavily into geometrical shapes for composition. I often include these shapes in previous art.

Space Woman 01, ink, pencil and collage on paper

For me. thisaesthetic conveys a balance between nature, technology and life that ecounters these two poles.

In my new work, I want to investigate the geometric stacked as architectonic towers or shapes so I can use this as reference options in my sculptural art and also 2D paintings, drawings and traditional art.

The Limits Of Generic Blender Tools

I find when I build up complex shapes or use the snapping tool right in Blender can be a massive headache and super laborious. If I need to change the shapes, they need to be placed again by hand  and duplicate the pieces. Not what I want. Or you probably don't want that either.I want to spend that time on developing the art or sculpture piece particularly in real life using traditional tools. Getting into the flow of creativity.

blender complex GUI

Using Vibe Coding As A Cheat Code

 I couldn't really find a native solution or add-on that did what I wanted, so I decided to take a shortcut and use "vibe coding" with Claude and Gemini to make a custom Python script.

I only know some basic python for visual art.It took about an hour. Because the shapes are relatively simple, the AI picked right up on what I needed. More complex addons for less ordered geometric shapes probably would have taken a lot longer. I think AI likes geometric shapes as they have fewer variables.

I had to debug it though quite a few times, see some of the main things that caused problems -I managed to make it work. There are probably some bugs still there but it doesnt what I need, one of the main things I tell people to think about when I am tutoring. So now have a look at the Blender geometric shapes workflow - using vibe coding workflow for this problem.

How To Use The Addon Code

You can find the code at the end of this blog post to test, try and adapt. I only tested this in Blender 5.2, let me know if you encounter any bugs. Here is how the workflow works:Add a base shape in Blender and go to Edit Mode to select a face.Come out of edit mode and hit the Snap Face add-on on the right-hand bar.

Click the target instance to instantly generate and randomize the structural shape.I wanted the instances of the objects to grow and shrink in real time using the slider so I could easily scale the randomization and avoid annoying mesh intersections without constantly diving back into code.Check this video here for full instructions - 

Digital To Physical Art - Tradigital

Now, I've got this really useful digital reference tool. Instead of tracing or printing out projections, I keep the shapes up on screen and draw them traditionally onto my canvas, paper, or wooden boards.

For me, that’s where the magic happens: you use technology to solve the heavy lifting of architectural composition, but you bring the actual "spirit" and hand-drawn skill back into the physical world.

stacked geometric concrete architectonic structure

If you want to try out the script yourself, it’s completely free and available to download below for Blender 5.2 and up. Drop a comment if you need a hand implementing it, and stay tuned for the new artwork!If you need help with your projects,

I currently offer a free 30 minute trial session.
You can also subscribe to my newsletter below to get my latest art and lots of freebies and resources like this blog post.What repetitive Blender task could you make with your own vibe coded or hand coded addon? How would this improve your workflow and creativity?

Blender geometric shapes workflow

Downloads & Resources

Blender - for all things 3D and free 🙂
Gemini - for AI vibe coding
Claude - for AI vibe coding

The Code

🌐
filename.html
bl_info = {
    "name": "Snap Face to Face",
    "author": "You & Claude",
    "version": (1, 8, 0),
    "blender": (4, 0, 0),
    "location": "View3D > Sidebar (N) > Snap Face",
    "description": "Realtime growing generative structure supporting multiple independent systems.",
    "category": "Object",
}

import bpy
import bmesh
import mathutils
from mathutils.bvhtree import BVHTree
from mathutils import Matrix
import random

# Global registry to hold multiple independent structures keyed by module name
STRUCTURES = {}


def alive(obj):
    return obj is not None and obj.name in bpy.data.objects


def get_structure_key(module, base):
    return f"{module.name}_{base.name if base else 'single'}"


# Geometry helpers
def world_dir(mat, v_local):
    normal_mat = mat.to_3x3().inverted().transposed()
    return (normal_mat @ v_local).normalized()


def project_on_plane(v, n):
    v_proj = v - v.dot(n) * n
    if v_proj.length < 1e-9:
        return None
    return v_proj.normalized()


def get_shrunken_bvh(obj, scale_factor=0.95):
    bm = bmesh.new()
    bm.from_mesh(obj.data)
    bbox_corners = [mathutils.Vector(c) for c in obj.bound_box]
    center = sum(bbox_corners, mathutils.Vector()) / 8.0
    for v in bm.verts:
        v.co = center + (v.co - center) * scale_factor
    bm.transform(obj.matrix_world)
    bvh = BVHTree.FromBMesh(bm)
    bm.free()
    return bvh


def get_bmesh_face_data(obj, face_idx):
    bm = bmesh.new()
    bm.from_mesh(obj.data)
    bm.faces.ensure_lookup_table()
    face = bm.faces[face_idx]
    center = face.calc_center_median().copy()
    normal = face.normal.copy()
    verts = [v.co.copy() for v in face.verts]
    bm.free()
    return center, normal, verts


def get_matching_faces(obj, target_verts, target_area, exclude_idx=None):
    matches = []
    bm = bmesh.new()
    bm.from_mesh(obj.data)
    bm.faces.ensure_lookup_table()
    for f in bm.faces:
        if exclude_idx is not None and f.index == exclude_idx:
            continue
        if len(f.verts) == target_verts and abs(f.calc_area() - target_area) < 1e-4:
            matches.append(f.index)
    bm.free()
    return matches


def snap_objects(src_obj, src_face_idx, tgt_obj, tgt_face_idx):
    src_center_l, src_normal_l, src_verts_l = get_bmesh_face_data(src_obj, src_face_idx)
    tgt_center_l, tgt_normal_l, tgt_verts_l = get_bmesh_face_data(tgt_obj, tgt_face_idx)

    src_mat = src_obj.matrix_world.copy()
    tgt_mat = tgt_obj.matrix_world.copy()

    tgt_center_w = tgt_mat @ tgt_center_l
    tgt_normal_w = world_dir(tgt_mat, tgt_normal_l)
    tgt_verts_w = [tgt_mat @ v for v in tgt_verts_l]
    tgt_rel = [v - tgt_center_w for v in tgt_verts_w]

    src_normal_w = world_dir(src_mat, src_normal_l)
    src_center_w = src_mat @ src_center_l
    src_verts_w = [src_mat @ v for v in src_verts_l]
    src_rel = [v - src_center_w for v in src_verts_w]

    want_normal = -tgt_normal_w
    rot_align = src_normal_w.rotation_difference(want_normal).to_matrix()
    src_rel_aligned = [rot_align @ v for v in src_rel]

    n = len(tgt_rel)
    best_offset, best_error = 0, None
    for offset in range(n):
        v_src = project_on_plane(src_rel_aligned[0], want_normal)
        v_tgt = project_on_plane(tgt_rel[offset % n], want_normal)
        if v_src is None or v_tgt is None:
            continue
        angle = v_src.angle(v_tgt)
        if v_src.cross(v_tgt).dot(want_normal) < 0:
            angle = -angle
        rot = Matrix.Rotation(angle, 3, want_normal)
        error = 0.0
        for i in range(len(src_rel_aligned)):
            rotated = rot @ src_rel_aligned[i]
            target_pt = tgt_rel[(offset - i) % n]
            error += (rotated - target_pt).length_squared
        if best_error is None or error < best_error:
            best_error, best_offset = error, offset

    loc, rot, scale = src_mat.decompose()
    S_verts = [mathutils.Vector((v.x * scale.x, v.y * scale.y, v.z * scale.z)) for v in src_verts_l]
    T_verts = [tgt_verts_w[(best_offset - i) % n] for i in range(len(src_verts_l))]

    p0_s, p1_s = S_verts[0], S_verts[1]
    x_s = (p1_s - p0_s).normalized()
    idx2 = 2
    for i in range(2, len(S_verts)):
        test_y = S_verts[i] - p0_s
        test_y = test_y - test_y.project(x_s)
        if test_y.length > 1e-5:
            idx2 = i
            break
    p2_s = S_verts[idx2]
    v2_s = p2_s - p0_s
    y_s = (v2_s - v2_s.project(x_s)).normalized()
    z_s = x_s.cross(y_s).normalized()
    mat_s = mathutils.Matrix((x_s, y_s, z_s)).transposed()

    p0_t, p1_t, p2_t = T_verts[0], T_verts[1], T_verts[idx2]
    x_t = (p1_t - p0_t).normalized()
    v2_t = p2_t - p0_t
    y_t = (v2_t - v2_t.project(x_t)).normalized()
    z_t = x_t.cross(y_t).normalized()
    mat_t = mathutils.Matrix((x_t, y_t, z_t)).transposed()

    rot_3x3 = mat_t @ mat_s.inverted()
    src_center_s = mathutils.Vector((src_center_l.x * scale.x, src_center_l.y * scale.y, src_center_l.z * scale.z))
    rotated_center = rot_3x3 @ src_center_s
    translation = tgt_center_w - rotated_center

    src_obj.matrix_world = mathutils.Matrix.LocRotScale(translation, rot_3x3.to_quaternion(), scale)


def get_current_module_base(context):
    sel = context.selected_objects
    if not sel or len(sel) > 2:
        return None, None
    module = context.active_object
    if not module:
        return None, None
    base = next((o for o in sel if o is not module), module) if len(sel) == 2 else module
    return module, base


def try_build_root_slots(module, base):
    bm_mod = bmesh.new()
    bm_mod.from_mesh(module.data)
    bm_mod.faces.ensure_lookup_table()
    mod_sel = [f.index for f in bm_mod.faces if f.select]
    if len(mod_sel) != 1:
        bm_mod.free()
        return None, None
    plug_idx = mod_sel[0]
    target_verts = len(bm_mod.faces[plug_idx].verts)
    target_area = bm_mod.faces[plug_idx].calc_area()
    bm_mod.free()

    if base is not module:
        bm_base = bmesh.new()
        bm_base.from_mesh(base.data)
        bm_base.faces.ensure_lookup_table()
        base_sel = [f.index for f in bm_base.faces if f.select]
        bm_base.free()
        if len(base_sel) == 1:
            slots = [(base, base_sel[0])]
        else:
            slots = [(base, idx) for idx in get_matching_faces(base, target_verts, target_area)]
    else:
        slots = [(base, idx) for idx in get_matching_faces(base, target_verts, target_area, exclude_idx=plug_idx)]

    if not slots:
        return None, None
    return plug_idx, slots


def grow(data, context, target_count):
    module = data['module']
    plug_idx = data['plug_idx']

    bm_mod = bmesh.new()
    bm_mod.from_mesh(module.data)
    bm_mod.faces.ensure_lookup_table()
    target_verts = len(bm_mod.faces[plug_idx].verts)
    target_area = bm_mod.faces[plug_idx].calc_area()
    bm_mod.free()

    attempts = 0
    max_attempts = max(1, target_count - len(data['pieces'])) * 6

    while len(data['pieces']) < target_count and data['slots'] and attempts < max_attempts:
        attempts += 1
        slot_pos = random.randint(0, len(data['slots']) - 1)
        tgt_obj, tgt_face_idx = data['slots'].pop(slot_pos)

        new_obj = module.copy()
        new_obj.data = module.data.copy()
        context.collection.objects.link(new_obj)

        snap_objects(new_obj, plug_idx, tgt_obj, tgt_face_idx)
        context.view_layer.update()

        new_bvh = get_shrunken_bvh(new_obj, 0.95)
        collision = any(new_bvh.overlap(tree) for _, tree in data['bvh'])

        if collision:
            bpy.data.objects.remove(new_obj, do_unlink=True)
            continue

        own_slots = get_matching_faces(new_obj, target_verts, target_area, exclude_idx=plug_idx)

        data['pieces'].append({
            'obj': new_obj,
            'parent': (tgt_obj, tgt_face_idx),
            'own_slots': own_slots,
        })
        data['bvh'].append((new_obj, new_bvh))
        for idx in own_slots:
            data['slots'].append((new_obj, idx))


def shrink(data, target_count):
    while len(data['pieces']) > target_count:
        piece = data['pieces'].pop()
        obj = piece['obj']

        data['slots'] = [(o, f) for (o, f) in data['slots'] if o is not obj]
        data['bvh'] = [(o, b) for (o, b) in data['bvh'] if o is not obj]
        data['slots'].append(piece['parent'])

        if alive(obj):
            bpy.data.objects.remove(obj, do_unlink=True)


def execute_generative_build(context):
    if context.mode != 'OBJECT':
        return

    module, base = get_current_module_base(context)
    if module is None:
        return

    target_count = context.scene.snapface_iterations
    key = get_structure_key(module, base)

    # Initialize separate dictionary entry for this unique module/base pairing if missing
    if key not in STRUCTURES or not alive(STRUCTURES[key]['module']) or not alive(STRUCTURES[key]['base']):
        plug_idx, slots = try_build_root_slots(module, base)
        if plug_idx is None:
            return

        STRUCTURES[key] = {
            'module': module,
            'base': base,
            'plug_idx': plug_idx,
            'pieces': [],
            'slots': slots,
            'bvh': [(base, get_shrunken_bvh(base, 0.95))],
        }

    data = STRUCTURES[key]

    if target_count > len(data['pieces']):
        grow(data, context, target_count)
    elif target_count < len(data['pieces']):
        shrink(data, target_count)

    bpy.ops.object.select_all(action='DESELECT')
    if base is not module:
        base.select_set(True)
    module.select_set(True)
    context.view_layer.objects.active = module


def update_iterations_realtime(self, context):
    try:
        execute_generative_build(context)
    except Exception as e:
        print(f"[Snap Face to Face] realtime update error: {e}")


class SNAPFACE_OT_basic(bpy.types.Operator):
    bl_idname = "object.snapface_basic"
    bl_label = "Snap 1-to-1 (Edit Mode)"
    bl_options = {'REGISTER', 'UNDO'}

    @classmethod
    def poll(cls, context):
        return context.mode == 'EDIT_MESH' and len(context.selected_objects) == 2

    def execute(self, context):
        sel = context.selected_objects
        active = context.active_object
        target_obj = next(o for o in sel if o is not active)

        def get_sel_face_edit(obj):
            bm = bmesh.from_edit_mesh(obj.data)
            sel_faces = [f for f in bm.faces if f.select]
            if len(sel_faces) != 1:
                return None
            return sel_faces[0].index

        src_idx = get_sel_face_edit(active)
        tgt_idx = get_sel_face_edit(target_obj)

        if src_idx is None or tgt_idx is None:
            self.report({'ERROR'}, "Each object must have exactly ONE face selected.")
            return {'CANCELLED'}

        bpy.ops.object.mode_set(mode='OBJECT')
        snap_objects(active, src_idx, target_obj, tgt_idx)
        bpy.ops.object.mode_set(mode='EDIT')
        return {'FINISHED'}


class SNAPFACE_OT_clear(bpy.types.Operator):
    bl_idname = "object.snapface_clear"
    bl_label = "Clear Active Structure"
    bl_description = "Delete instances belonging to the current active setup"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):
        module, base = get_current_module_base(context)
        if module:
            key = get_structure_key(module, base)
            if key in STRUCTURES:
                for piece in STRUCTURES[key]['pieces']:
                    if alive(piece['obj']):
                        bpy.data.objects.remove(piece['obj'], do_unlink=True)
                del STRUCTURES[key]
        return {'FINISHED'}


class SNAPFACE_PT_panel(bpy.types.Panel):
    bl_label = "Face Snapping Tools"
    bl_idname = "SNAPFACE_PT_panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Snap Face"

    def draw(self, context):
        layout = self.layout
        scene = context.scene

        layout.label(text="Manual Snapping:")
        layout.operator("object.snapface_basic")

        layout.separator()

        layout.label(text="Realtime Growth:")
        layout.prop(scene, "snapface_iterations", text="Target Instances", slider=True)
        
        module, base = get_current_module_base(context)
        current_pieces = 0
        if module:
            key = get_structure_key(module, base)
            if key in STRUCTURES:
                current_pieces = len(STRUCTURES[key]['pieces'])

        layout.label(text=f"Active built count: {current_pieces}")
        layout.operator("object.snapface_clear", icon='TRASH')


classes = (SNAPFACE_OT_basic, SNAPFACE_OT_clear, SNAPFACE_PT_panel)


def register():
    for cls in classes:
        bpy.utils.register_class(cls)

    bpy.types.Scene.snapface_iterations = bpy.props.IntProperty(
        name="Instances",
        description="Drag to grow/shrink the structure in realtime",
        default=10,
        min=1,
        max=200,
        update=update_iterations_realtime
    )


def unregister():
    STRUCTURES.clear()
    for cls in reversed(classes):
        bpy.utils.unregister_class(cls)
    del bpy.types.Scene.snapface_iterations


if __name__ == "__main__":
    register()

Table of Contents

Explore Articles