www.xbdev.net
xbdev - software development
Wednesday July 16, 2025
Home | Contact | Support | Blender (.py) Scripts... Automating Blender ..
     
 

Blender (.py) Scripts...

Automating Blender ..

 

Fractal Hand Mesh


A simple script that takes a mesh (a hand in this case) - and recursively clones it and places it at an offset - which is repeated! This is a fun fractal effect - and is applied to a 'hand' creating hands on fingers.


Hand has little hands on the fingers (depth of 2).
Hand has little hands on the fingers (depth of 2).


The script is very simple - the only thing you need to be careful about is either infinite recursion or the offsets/scales are wrong.

import bpy
import math
from mathutils import VectorEuler

# Settings
base_name "hand"
max_depth 2

initial_scale 
1.0
scale_factor 
0.30

offsets 
= [
    
Vector((0010)),
    
Vector((-0.18,  1.69.4)),
    
Vector((-0.2, -1.59.4)),
    
Vector((-0.4,  3.08.3)),
    
Vector((-2.4, -2.55.7)),
]

rotation_angles = [  # (X, Y, Z) in degrees
    
000),
    (-
1300),
    ( 
1000),
    ( -
3000),
    ( 
400, -80)
]



# Cleanup: remove all objects except the base
for obj in bpy.data.objects:
    if 
obj.type == 'MESH' and obj.name != base_name:
        
bpy.data.objects.remove(objdo_unlink=True)

# Locate original
original bpy.data.objects.get(base_name)
if 
not original:
    
raise ValueError(f"No object named '{base_name}' found.")

original.scale = (1.01.01.0)

def clone_branch(parent_objparent_locparent_rotparent_scaledepth):
    if 
depth == 0:
        return

    for 
i in range(len(offsets)):
        
# Compute new scale
        
new_scale parent_scale scale_factor

        
# Rotate the offset using only the parent’s rotation (not including this level’s rotation yet)
        
rotated_offset offsets[i].copy()
        
rotated_offset.rotate(parent_rot)

        
# Compute the location
        
new_loc parent_loc rotated_offset new_scale

        
# Compute new cumulative rotation (after this level's rotation)
        
level_rot Euler([math.radians(a) for a in rotation_angles[i]])
        
new_rot parent_rot.copy()
        
new_rot.rotate(level_rot)

        
# Duplicate the object
        
new_obj parent_obj.copy()
        
new_obj.data parent_obj.data.copy()
        
bpy.context.collection.objects.link(new_obj)

        
new_obj.scale = (new_scale,) * 3
        new_obj
.location new_loc
        new_obj
.rotation_euler new_rot

        
# Recurse into next level with updated transform
        
clone_branch(new_objnew_locnew_rotnew_scaledepth 1)

# Launch the fractal generation
clone_branch(originaloriginal.location.copy(), original.rotation_euler.copy(), 1.0max_depth)


If we go nuts and crank the depth up to 4 - we can get some really little fingers - I mean hands - I mean fingers!!


A fractal depth of 4 for the nested child meshes.
A fractal depth of 4 for the nested child meshes.


The blender file with the mesh and script can also be downloaded (LINK).












 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.