-
Notifications
You must be signed in to change notification settings - Fork 0
/
animate.py
32 lines (27 loc) · 1 KB
/
animate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#Blender script to import OBJ and generate animation
#this script runs in blender
import bpy
import os
# obj_path
folder_path = r"D:\work\ComputerGraphics\PBF\pbf3d-master\data\01\obj"
# init params
start_frame = 0
end_frame = 299
last_obj = None
# Loop all files in the folder
for frame in range(start_frame, end_frame + 1):
# set current frame
bpy.context.scene.frame_set(frame)
# import obj file
filename = f"Frame_{frame+300}.obj"
file_path = os.path.join(folder_path, filename)
bpy.ops.import_scene.obj(filepath=file_path)
# set keyframe and change obj location to make animation
obj = bpy.context.selected_objects[0]
if(frame != 0):
last_obj.location[2] = 0
last_obj.keyframe_insert(data_path='location', frame=bpy.context.scene.frame_current)
obj.keyframe_insert(data_path='location', frame=bpy.context.scene.frame_current - 1)
obj.location[2] = 10
obj.keyframe_insert(data_path='location', frame=bpy.context.scene.frame_current)
last_obj = obj