0
|
1 import bpy
|
|
2 from pathlib import Path
|
|
3
|
|
4 bl_info = {
|
|
5 "name": "Write animation",
|
|
6 "blender": (2, 80, 0),
|
|
7 "location": "Render > Write animation",
|
|
8 }
|
|
9
|
|
10
|
|
11 class WriteAnimation(bpy.types.Operator):
|
|
12 """Write a new webm next to the blend file"""
|
|
13 bl_idname = "render.write_animation" # Unique identifier for buttons and menu items to reference.
|
|
14 bl_label = "Write animation" # Display name in the interface.
|
|
15 bl_options = {'REGISTER'}
|
|
16
|
|
17 def execute(self, context):
|
|
18 if not bpy.data.filepath.replace('.', ''):
|
|
19 raise ValueError('Please save the file somewhere first.')
|
|
20 output_base = Path(bpy.data.filepath.replace('.blend', ''))
|
|
21 for num in range(1, 1000):
|
|
22 output_path = Path(f'{output_base}_{num}.webm')
|
|
23 if output_path.exists():
|
|
24 continue
|
|
25 break
|
|
26 else:
|
|
27 raise NotImplementedError()
|
|
28
|
|
29 render = context.scene.render
|
|
30
|
|
31 render.filepath = str(output_path)
|
|
32 render.image_settings.file_format = 'FFMPEG'
|
|
33 render.ffmpeg.format = 'WEBM'
|
|
34 render.ffmpeg.codec = 'WEBM'
|
|
35 render.ffmpeg.constant_rate_factor = 'HIGH'
|
|
36 render.image_settings.color_mode = 'RGBA'
|
|
37 bpy.ops.render.render('INVOKE_DEFAULT', animation=True)
|
|
38
|
|
39 return {'FINISHED'}
|
|
40
|
|
41
|
|
42 def register():
|
|
43 bpy.utils.register_class(WriteAnimation)
|
|
44
|
|
45
|
|
46 def unregister():
|
|
47 bpy.utils.unregister_class(WriteAnimation)
|
|
48
|
|
49
|
|
50 if __name__ == "__main__":
|
|
51 register()
|