As the amount of AI technology continues to grow, so too should our uses for it. LLMs are likely to be the greatest piece of technology to come out of this decade, and it's important that we find uses for it beyond giving us the incorrect number of Rs in the word Strawberry.
I have used the 3D Software, Blender, as well as Microsoft's AI; Copilot, to generate a Python script capable of automating the animation process.
Step one : Generate Code with an LLM of your choosing.
So, as you can see here, I have chatted with the Microsoft Copilot AI, and asked it to generate blender compaitable code for my project. As long as your code request is possible, and simple, any AI Language model should be able to generate something of value.
however, sometimes the code generated will be entirely useless, this is typically because of user error, such as not specifying exactly what you want, but as seen in this image, the code generated didn't function properly, even though I was very specific of what I wanted. But the solution is simple,
all you have to do is ask the LLM again.
Step two: Put your code into Blender.
The version of blender you are using should not matter too much, as long as it is one that supports the scripting feature. Personally, I was using Blender 3.6.5. Anyways, so you have to look at the top bar of the blender
to see all of the different work stations. When you see the one titled "Scripting" Click on it to open the window. Next, press the new button to make a code file, then paste your code into blender. If all is done correctly, you should have your desired function be created and
appear in the 3D workspace one you click play.
In this example, I requested Co-Pilot to generate code that would move a box, whilst changing it's colour. I have included a download link below for my blender file, if you wish to see the code and the project.
Click here to download the file and check it out for yourself
import bpy
import math
# Create a new material
mat = bpy.data.materials.new(name="RainbowMaterial")
mat.use_nodes = True
nodes = mat.node_tree.nodes
bsdf = nodes.get("Principled BSDF")
# Function to update the color of the material
def update_color(frame, total_frames):
hue = (frame / total_frames) % 1.0
color = [math.sin(hue * 2 * math.pi) * 0.5 + 0.5, math.sin((hue + 1/3) * 2 * math.pi) * 0.5 + 0.5, math.sin((hue + 2/3) * 2 * math.pi) * 0.5 + 0.5, 1]
bsdf.inputs['Base Color'].default_value = color
# Function to animate the object
def animate_object(obj, total_frames):
for frame in range(total_frames):
bpy.context.scene.frame_set(frame)
obj.location.x -= 0.1 # Move the object to the left
update_color(frame, total_frames)
obj.keyframe_insert(data_path="location", index=-1)
bsdf.inputs['Base Color'].keyframe_insert(data_path="default_value", frame=frame)
# Create a block
bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0))
block = bpy.context.object
block.data.materials.append(mat)
# Animate the block
total_frames = 100
animate_object(block, total_frames)