www.xbdev.net
xbdev - software development
Thursday April 30, 2026
Home | Contact | Support | Blender (.py) Scripts... Automating Blender ..
     
 

Blender (.py) Scripts...

Automating Blender ..

 

Fluffy Clouds


We can create fluffy clouds in Blender by mixing some noise and the mesh to volume modifier - this can all be done in a script. To make it more fun and interesting - we'll apply the cloud effect to some text. We'll create a volume mesh from the words 'CLOUD' - which we'll subdivide and convert to volume.


An example of the rendered output for the cloud effect applied to some words - can you make out the word
An example of the rendered output for the cloud effect applied to some words - can you make out the word 'CLOUD'?


Mix in a bit of lighting and a material and we've got a sexy looking cloud effect.

<?php
import bpy
import math

# Clear existing objects
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()

bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.data.objects:
    bpy.data.objects.remove(obj, do_unlink=True)


bpy.ops.object.text_add(align='WORLD', location=(0, -0.5, 0))
text_obj = bpy.context.object
text_obj.name = "CloudText"
text_obj.data.body = "CLOUD"
text_obj.data.align_x = 'CENTER'
text_obj.data.extrude = 0.03
text_obj.data.bevel_depth = 0.14
text_obj.data.bevel_resolution = 4  # Higher for smoother bevels
text_obj.data.space_character = 1.5  # Letter spacing


# Convert text to mesh
bpy.ops.object.convert(target='MESH')

# Add solidify modifier to give thickness
solidify = text_obj.modifiers.new(name="Solidify", type='SOLIDIFY')
solidify.thickness = 0.0
solidify.offset = 0
bpy.ops.object.modifier_apply(modifier="Solidify")

# Add subdivision modifier
subdiv = text_obj.modifiers.new(name="Subdivision", type='SUBSURF')
subdiv.levels = 3
subdiv.render_levels = 3
bpy.ops.object.modifier_apply(modifier="Subdivision")

# Create empty volume (updated for Blender 4.1)
bpy.ops.object.volume_add(align='WORLD', location=(0, 0, 0))
volume_obj = bpy.context.object
volume_obj.name = "CLOUD_VOLUME"

# Add Mesh to Volume modifier to the volume object
mesh_to_volume = volume_obj.modifiers.new(name="MeshToVolume", type='MESH_TO_VOLUME')
mesh_to_volume.object = text_obj
mesh_to_volume.density = 22.0
mesh_to_volume.voxel_size = 0.08
mesh_to_volume.interior_band_width = 0.2
mesh_to_volume.resolution_mode = 'VOXEL_AMOUNT'
mesh_to_volume.voxel_amount = 128

# Hide the original text mesh
text_obj.hide_set(True)
text_obj.hide_render = True

# Add volume displace modifier
displace = volume_obj.modifiers.new(name="VolumeDisplace", type='VOLUME_DISPLACE')
displace.texture = bpy.data.textures.new(name="CloudNoise", type='CLOUDS')
displace.texture.noise_scale = 0.2
displace.strength = 0.5

# Set volume material
mat = bpy.data.materials.new(name="CloudMaterial")
mat.use_nodes = True
nodes = mat.node_tree.nodes
links = mat.node_tree.links

# Clear default nodes
for node in nodes:
    nodes.remove(node)


# Create volume scatter node
volume_scatter = nodes.new(type='ShaderNodeVolumeScatter')
volume_scatter.inputs['Density'].default_value = 5
volume_scatter.inputs['Anisotropy'].default_value = 0

# Create principled volume node (updated for Blender 4.1)
principled_volume = nodes.new(type='ShaderNodeVolumePrincipled') 
principled_volume.inputs['Density'].default_value = 2
principled_volume.inputs['Anisotropy'].default_value = 0
principled_volume.inputs['Color'].default_value = (1, 1, 1, 1)

# Create material output node
output = nodes.new(type='ShaderNodeOutputMaterial')

# Link nodes
links.new(principled_volume.outputs['Volume'], output.inputs['Volume'])

# Assign material to volume object
if volume_obj.data.materials:
    volume_obj.data.materials[0] = mat
else:
    volume_obj.data.materials.append(mat)

# Add lighting
bpy.ops.object.light_add(type='SUN', location=(10, 10, 20))
sun = bpy.context.object
sun.data.energy = 5
sun.data.angle = math.radians(5)

bpy.ops.object.light_add(type='SUN', location=(-10, -10, 20))
sun2 = bpy.context.object
sun2.data.energy = 3
sun2.data.angle = math.radians(5)
sun2.data.color = (0.8, 0.9, 1.0)

# Add camera
bpy.ops.object.camera_add(location=(0, 0, 7))
camera = bpy.context.object
bpy.context.scene.camera = camera

# Add world background
world = bpy.context.scene.world
world.use_nodes = True
bg = world.node_tree.nodes['Background']
#bg.inputs['Strength'].default_value = 1.5
#bg.inputs['Color'].default_value = (0.7, 0.8, 1.0, 1.0)

# Set render settings
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.cycles.samples = 128
bpy.context.scene.cycles.volume_bounces = 8






 
Advert (Support Website)

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