Created
March 1, 2021 15:35
-
-
Save benhatsor/686e4b006f8ae05e18638fce8ed1d172 to your computer and use it in GitHub Desktop.
Animate Lego sets in Blender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
from mathutils import Vector | |
# Edit these: | |
offset = 1 # Offset is the interval between each brick appearance | |
startFrame = 0 # Start Frame is the frame that the brick animation starts on | |
# Variables | |
frameNum = startFrame | |
selectedBricks = bpy.context.selected_objects | |
# Bricks with lower z value get called first | |
sortedBricks = sorted(selectedBricks, key=lambda x: x.location[2]) | |
# Loop on all selected bricks | |
for brick in sortedBricks: | |
# Set new scale to brick | |
brick.scale = Vector((0, 0, 0)) | |
# Add keyframe | |
brick.keyframe_insert(data_path="scale", frame=frameNum, index=-1) | |
# Jump one frame | |
newFrame = frameNum + 1 | |
# Set new scale to brick | |
brick.scale = Vector((1.0, 1.0, 1.0)) | |
# Add keyframe | |
brick.keyframe_insert(data_path="scale", frame=newFrame, index=-1) | |
# Go to next offset | |
frameNum += offset | |
# Go to start frame | |
bpy.context.scene.frame_set(startFrame) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment