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

Blender (.py) Scripts...

Automating Blender ..

 

Fractured (Cell) Effect (Smashed)


We can use the 'fracture' effect to chop up the mesh into smaller pieces - we'll add in a bit of randomness as well so the cells arne't all equal and square.


Generate the 3D mesh for the word
Generate the 3D mesh for the word 'explode' - then we fracture it and convert it into pieces - so that it stands ou tmore we also offset each piece by a small amount.


import bpy

# --- Clean up ---
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)

# --- Create text ---
bpy.ops.object.text_add(location=(-1.500))
text_obj bpy.context.object
text_obj
.data.body "explode"
text_obj.data.extrude 0.2
bpy
.ops.object.convert(target='MESH')
text_obj.name "ExplodingText"

# --- Subdivide to add geometry for explosion ---
bpy.context.view_layer.objects.active text_obj
bpy
.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.subdivide(number_cuts=10)
bpy.ops.object.mode_set(mode='OBJECT')


obj bpy.context.active_object

if True:
    
bpy.ops.object.select_all(action='DESELECT')
    
obj.select_set(True)
    
bpy.context.view_layer.objects.active obj

    
print( bpy.ops.object.add_fracture_cell_objects.get_rna_type().properties.keys() )

    
bpy.ops.object.add_fracture_cell_objects(
        
#use_remove_original=True,
        #source='VERT_OWN',
        #cell_scale=cell_scale,
        
source_noise=0.3,          # <-- noise amount (float)
        #use_smooth_faces=True,
        #use_interior_voronoi=True,
        #recursion=recursion,
        #margin=0.001
    
)

    
bpy.data.objects.remove(objdo_unlink=True)



import bpy
import random
from mathutils import Vector

def random_color
():
    return (
random.random(), random.random(), random.random(), 1)

def random_offset(max_offset=0.1):
    return 
Vector((
        
random.uniform(-max_offsetmax_offset),
        
random.uniform(-max_offsetmax_offset),
        
random.uniform(-max_offsetmax_offset)
    ))

for 
obj in bpy.context.scene.objects:
    if 
obj.type == 'MESH':
        
# Add random color material
        
mat bpy.data.materials.new(name=f"RandomColor_{obj.name}")
        
mat.use_nodes True
        bsdf 
mat.node_tree.nodes.get('Principled BSDF')
        if 
bsdf:
            
bsdf.inputs['Base Color'].default_value random_color()
        if 
obj.data.materials:
            
obj.data.materials[0] = mat
        
else:
            
obj.data.materials.append(mat)
        
        
# Add random small offset to location
        
obj.location += random_offset(0.02)




# --- Add a camera ---
cam_data bpy.data.cameras.new("Camera")
cam_obj bpy.data.objects.new("Camera"cam_data)
bpy.context.collection.objects.link(cam_obj)
cam_obj.location = (005)
cam_obj.rotation_euler = (0.100)

# --- Add a light ---
light_data bpy.data.lights.new(name="Light"type='SUN')
light_obj bpy.data.objects.new(name="Light"object_data=light_data)
bpy.context.collection.objects.link(light_obj)
light_obj.location = (5, -55)
light_obj.rotation_euler = (0.70.30.8)

# --- Set camera as active ---
bpy.context.scene.camera cam_obj


Get Information (Function Parameters)


You can actually write a little script to see what the default arguemnts aned what arguments the fractal function takes (i.e.,
bpy.ops.object.add_fracture_cell_objects
).

import bpy

op bpy.ops.object.add_fracture_cell_objects
props 
op.get_rna_type().properties

print("Properties for bpy.ops.object.add_fracture_cell_objects:")
for 
prop_nameprop in props.items():
    
# Skip 'rna_type' property which is meta info
    
if prop_name == "rna_type":
        continue
    
    default = 
getattr(prop"default""<no default>")
    
prop_type type(prop).__name__
    
print(f"- {prop_name} (type: {prop_type}, default: {default})")



You get an output like this in the console window:

source (typeEnumProperty, default: )
source_limit (typeIntProperty, default: 100)
source_noise (typeFloatProperty, default: 0.0)
cell_scale (typeFloatProperty, default: 0.0)
recursion (typeIntProperty, default: 0)
recursion_source_limit (typeIntProperty, default: 8)
recursion_clamp (typeIntProperty, default: 250)
recursion_chance (typeFloatProperty, default: 0.25)
recursion_chance_select (typeEnumProperty, default: SIZE_MIN)
use_smooth_faces (typeBoolProperty, default: False)
use_sharp_edges (typeBoolProperty, default: True)
use_sharp_edges_apply (typeBoolProperty, default: True)
use_data_match (typeBoolProperty, default: True)
use_island_split (typeBoolProperty, default: True)
margin (typeFloatProperty, default: 0.0010000000474974513)
material_index (typeIntProperty, default: 0)
use_interior_vgroup (typeBoolProperty, default: False)
mass_mode (typeEnumProperty, default: VOLUME)
mass (typeFloatProperty, default: 1.0)
use_recenter (typeBoolProperty, default: True)
use_remove_original (typeBoolProperty, default: True)
collection_name (typeStringProperty, default: )
use_debug_points (typeBoolProperty, default: False)
use_debug_redraw (typeBoolProperty, default: True)
use_debug_bool (typeBoolProperty, default: False)





 
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.