import bpy
# Clean everything from the scene
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
# Create credit text
credits_text = """\
Producer
Name1
Name2
Director
Name1
Name2
CAST
Ending Credit Example
"""
# Create text object
text_data = bpy.data.curves.new(name="CreditsText", type='FONT')
text_data.body = credits_text
text_object = bpy.data.objects.new(name="Credits", object_data=text_data)
bpy.context.scene.collection.objects.link(text_object)
# Adjust text font size and alignment
text_object.data.align_x = 'CENTER'
text_object.data.size = 1
# Set the text position
text_object.location = (0, 0, -10) # Start off-screen at the bottom
text_object.scale = (0.5, 0.5, 0.5)
# Add animation: text moving upward
frame_start = 1
frame_end = 120 # Adjust for how long you want the credits to last
text_object.keyframe_insert(data_path="location", frame=frame_start)
text_object.location = (0, 0, 10) # Move up off-screen at the top
text_object.keyframe_insert(data_path="location", frame=frame_end)
# Add a fade-in effect
# Create a material for text
material = bpy.data.materials.new(name="FadeMaterial")
material.use_nodes = True
text_object.data.materials.append(material)
# Get the material's node tree
nodes = material.node_tree.nodes
links = material.node_tree.links
nodes.clear()
# Create node setup for fading
output_node = nodes.new(type='ShaderNodeOutputMaterial')
emission_node = nodes.new(type='ShaderNodeEmission')
fade_node = nodes.new(type='ShaderNodeMath')
fade_node.operation = 'MULTIPLY'
# Link emission to output
links.new(emission_node.outputs[0], output_node.inputs[0])
# Add Keyframes for fade-in effect
fade_node.inputs[1].default_value = 0 # Start with 0 opacity
fade_node.inputs[1].keyframe_insert(data_path="default_value", frame=frame_start)
fade_node.inputs[1].default_value = 1 # Full opacity
fade_node.inputs[1 key