-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathblender_batch_render_animation.py
69 lines (56 loc) · 2.28 KB
/
blender_batch_render_animation.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import bpy
import os
import sys
def ini_render_settings():
print("initial render setting")
bpy.context.scene.unit_settings.scale_length = 0.01
bpy.context.scene.render.image_settings.file_format = 'FFMPEG'
bpy.context.scene.render.ffmpeg.format = 'MPEG4'
bpy.context.scene.render.ffmpeg.constant_rate_factor = 'MEDIUM'
bpy.context.scene.render.ffmpeg.codec = 'H264'
bpy.context.scene.render.fps = 60
def set_frame_number():
start_number = bpy.data.objects['head_geo'].animation_data.action.frame_range[0]
end_number = bpy.data.objects['head_geo'].animation_data.action.frame_range[1]
bpy.context.scene.frame_start = start_number
bpy.context.scene.frame_end = end_number
def adjust_view():
for area in bpy.context.screen.areas:
if area.type == "VIEW_3D":
break
for region in area.regions:
if region.type == "WINDOW":
break
space = area.spaces[0]
context = bpy.context.copy()
context['area'] = area
context['region'] = region
context['space_data'] = space
bpy.ops.view3d.view_selected(context)
bpy.ops.view3d.view_axis(context, type='FRONT')
context['space_data'].overlay.show_overlays = False
def render_animation(output_path):
for i in range(1, len(bpy.data.objects['head_geo'].data.shape_keys.key_blocks)):
bpy.data.objects['head_geo'].data.shape_keys.key_blocks[i].slider_min = -5
bpy.data.objects['head_geo'].data.shape_keys.key_blocks[i].slider_max = 5
set_frame_number()
bpy.context.scene.render.filepath = output_path
adjust_view()
bpy.ops.render.opengl(animation=True)
bpy.data.objects['head_geo'].select_set(True)
bpy.ops.object.delete(use_global=False)
def import_fbx(file):
bpy.ops.import_scene.fbx(filepath=file, global_scale=0.01) # bas
bpy.context.selected_objects[0].name ='head_geo'
if __name__ == "__main__":
input_dir =
print("input_dir is {}".format(input_dir))
output_dir =
print("output_dir is {}".format(output_dir))
ini_render_settings()
names = os.listdir(input_dir)
for name in names:
input_path = os.path.join(input_dir, name)
import_fbx(input_path)
output_path = os.path.join(output_dir, name[:-3]+'mp4')
render_animation(output_path)