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

Blender (.py) Scripts...

Automating Blender ..

 

Generate 3D Text Covered in Grass


You can convert some 2d text into 3d by extruding it (3d text) - then you'll convert it to a mesh surface - from which we can then use a particle system to add 'hair' to the surface. We'll make the hair a green color so it looks like grass.

This is the complete script to accomplish such a beautiful and fun effect.

import bpy

# Clear existing scene
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)

# Create 3D Text
bpy.ops.object.text_add(location=(000))
text_obj bpy.context.active_object
text_obj
.data.body "GRASS"
text_obj.data.extrude 0.1
text_obj
.data.bevel_depth 0.02
text_obj
.data.align_x 'CENTER'
text_obj.data.size 1.5

# Convert Text to Mesh
bpy.ops.object.convert(target='MESH')
bpy.ops.object.shade_smooth()

# Apply all transforms
bpy.ops.object.transform_apply(location=Truerotation=Truescale=True)

# Add Particle System for Grass
ps text_obj.modifiers.new(name="GrassParticles"type='PARTICLE_SYSTEM')
psys ps.particle_system
psettings 
psys.settings

psettings
.type 'HAIR'
psettings.use_advanced_hair True
psettings
.count 6000
psettings
.hair_length 0.25

# Hair appearance
psettings.use_rotations True
psettings
.rotation_mode 'NOR'
psettings.phase_factor_random 1.0
psettings
.child_type 'INTERPOLATED'
psettings.rendered_child_count 20
psettings
.clump_factor 0.1
psettings
.roughness_1 0.01

# Create Grass Material for Hair
grass_mat bpy.data.materials.new(name="GrassMaterial")
grass_mat.use_nodes True
bsdf 
grass_mat.node_tree.nodes.get("Principled BSDF")
bsdf.inputs["Base Color"].default_value = (0.10.60.11)
bsdf.inputs["Roughness"].default_value 0.5

# Assign material to text mesh
text_obj.data.materials.append(grass_mat)

# Lighting
bpy.ops.object.light_add(type='SUN'location=(5, -55))
sun bpy.context.active_object
sun
.data.energy 5

# Camera
bpy.ops.object.camera_add(location=(6, -63), rotation=(1.200.8))
cam bpy.context.active_object
bpy
.context.scene.camera cam

# Render settings
bpy.context.scene.render.engine 'CYCLES'
bpy.context.scene.cycles.samples 128
bpy
.context.scene.cycles.device 'GPU'

print("3D 'GRASS' with realistic grass hair created!")


Rough Grass and Camera


We can tweak the grass a bit to make it look 'rougher' - more wild and exciting. Also move the camera so it's just above the grass. And of course, move the grass down a bit so it's in the middle of the screen.

So when we render the final output, the text is now in the middle of the screen and the camera is looking diretly at it.

import bpy

# Clear existing scene
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)

# Create 3D Text
bpy.ops.object.text_add(location=(0, -0.50))
text_obj bpy.context.active_object
text_obj
.data.body "GRASS"
text_obj.data.extrude 0.1
text_obj
.data.bevel_depth 0.02
text_obj
.data.align_x 'CENTER'
text_obj.data.size 1.5

# Convert Text to Mesh
bpy.ops.object.convert(target='MESH')
bpy.ops.object.shade_smooth()

# Apply all transforms
bpy.ops.object.transform_apply(location=Truerotation=Truescale=True)

# Add Particle System for Grass
ps text_obj.modifiers.new(name="GrassParticles"type='PARTICLE_SYSTEM')
psys ps.particle_system
psettings 
psys.settings

psettings
.type 'HAIR'
psettings.use_advanced_hair True
psettings
.count 6000
psettings
.hair_length 0.25
psettings
.length_random 0.7  # Vary hair length

# Hair appearance
psettings.use_rotations True
psettings
.rotation_mode 'NOR'
psettings.phase_factor_random 1.0
psettings
.child_type 'INTERPOLATED'
psettings.rendered_child_count 20
psettings
.clump_factor 0.1
# psettings.roughness_1 = 0.01

# Add roughness to make grass look wilder
psettings.roughness_1 0.05
psettings
.roughness_2 0.02
psettings
.roughness_endpoint 0.1

# Hair strand thickness (no randomness, but nicely tapered)
#psettings.root_radius = 0.008   # Base of strand
#psettings.tip_radius = 0.002    # Tip of strand

# Create Grass Material for Hair
grass_mat bpy.data.materials.new(name="GrassMaterial")
grass_mat.use_nodes True
bsdf 
grass_mat.node_tree.nodes.get("Principled BSDF")
bsdf.inputs["Base Color"].default_value = (0.10.60.11)
bsdf.inputs["Roughness"].default_value 0.5

# Assign material to text mesh
text_obj.data.materials.append(grass_mat)

# Lighting
bpy.ops.object.light_add(type='SUN'location=(5, -55))
sun bpy.context.active_object
sun
.data.energy 5

# Camera
bpy.ops.object.camera_add(location=(006), rotation=(000.0))
cam bpy.context.active_object
bpy
.context.scene.camera cam

# Render settings
bpy.context.scene.render.engine 'CYCLES'
bpy.context.scene.cycles.samples 128
bpy
.context.scene.cycles.device 'GPU'

print("3D 'GRASS' with realistic grass hair created!")





 
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.