Purpose
This Python script allows you to transfer the bounce animation, including squash and stretch deformations and Z-axis positional movement, from a Fusion composition (using the Anim Toys Bounce tool) to an object in your Blender scene.
Prerequisites
- You must have a CSV file exported from the Anim Toys Bounce tool in Fusion.
- You need an object in your Blender scene that you wish to animate.
Script Code
import bpy
import csv
# Path to your CSV file
csv_file_path = "path/to/yourbouncedata.csv"
# Name of the object to animate
object_name = "Sphere" # Replace with your object's name
# Get the object
obj = bpy.data.objects[object_name]
# Conversion factor: 1000 pixels = 4 meters (Adjust if your scale differs)
conversion_factor = 4 / 1000
# Read the CSV file
with open(csv_file_path, 'r') as file:
csv_reader = csv.DictReader(file)
for row in csv_reader:
frame = int(row['frame'])
# Convert center_y_px to Blender units for z-position (height)
z_position = float(row['center_y_px']) * conversion_factor
# Get x_size and y_size
x_size = float(row['x_size'])
y_size = float(row['y_size'])
# Set the keyframe for z-position (height)
obj.location[2] = z_position
obj.keyframe_insert(data_path="location", frame=frame, index=2)
# Set the keyframe for scale
obj.scale[0] = x_size # X scale
obj.scale[1] = x_size # Y scale (Blender's Y is often depth for 2D imported elements)
obj.scale[2] = y_size # Z scale (height)
obj.keyframe_insert(data_path="scale", frame=frame)
# Update the timeline to show all keyframes
bpy.context.scene.frame_end = frame
How to Use
- Export Data: In Fusion, use the Export Bounce Data button on your configured Bounce tool to save a
.csv
file. Remember to specify the full path and filename including the.csv
extension. - Open Blender: Open your Blender project.
- Open Scripting Tab: Go to the Scripting workspace in Blender.
- New Script: Click New to create a new text file in the Text Editor.
- Copy & Paste: Copy the Python script code above and paste it into Blender's Text Editor.
- Modify Script:
- Update the
csv_file_path
variable to the correct full path of your exported CSV file.
Example (Windows):csv_file_path = r"C:\Users\YourName\Documents\bouncedata.csv"
Example (Mac/Linux):csv_file_path = "/Users/YourName/Documents/bouncedata.csv"
- Change the
object_name
variable to match the exact name of the object in your Blender scene that you want to animate (e.g., Cube, MyBouncingBall). - Adjust the
conversion_factor
if needed. The script assumes that in your Fusion comp, theStarting Height
(and thuscenter_y_px
) refers to pixels, and you want to map this to Blender's meter units. The default4 / 1000
means 1000 pixels of height in Fusion will translate to 4 meters of Z movement in Blender. Change this based on your desired scale.
- Update the
- Run Script: Click the Run Script button (looks like a play icon) in the Text Editor's header.
- Check Animation: Your specified object in Blender should now have keyframes for its Z location and X, Y, Z scale, replicating the bounce animation. The script also updates the scene's end frame to match the last frame in the CSV data.
Notes
- The script animates the object's Z-axis location based on
center_y_px
from the CSV for height. X and Y location remain unchanged by this script. - The script applies
x_size
from the CSV to both X and Y scale in Blender, andy_size
to the Z scale. This typically works well for creating squash and stretch effects that appear correct from a frontal view. - This script is a reference. You may need to adapt it further depending on your specific Blender scene setup or desired animation mapping.