I've written an addon for baking an animated material to a texture sequence. It works by creating a new image texture to bake to, baking to that image, saving the image to disk, and then moving on to the next frame and repeating the process.
It uses a modal which waits for the current texture's is_dirty parameter to be true at which point it saves the image and moves to the next frame.
def modal(self, context=bpy.types.Context, event=bpy.types.Event):
print("Running Modal")
if self.current_image.is_dirty:
# print("Bake Complete")
dir_path = r'D:\Docs\Blender Projects\Anim Baker Test\pt 1'
image_path = path.join(dir_path, self.current_image.name + ".jpg")
self.current_image.save(filepath=image_path)
if bpy.context.scene.frame_current >= bpy.context.scene.ab_props.end_frame:
bpy.context.scene.ab_props.running = False
self.restore(self)
return {'FINISHED'}
bpy.context.scene.frame_current += 1
self.setup_image_and_bake(self)
if event.type == 'ESC':
bpy.context.scene.ab_props.running = False
self.restore(self)
return {'CANCELLED'}
if event.type == 'RIGHTMOUSE' and event.value == 'RELEASE':
bpy.context.scene.ab_props.running = False
self.restore(self)
return {'CANCELLED'}
return {'RUNNING_MODAL'}
The issue is that the first 5 frames will bake and save nicely and quickly but the process will then halt until I move the mouse at which point it will bake another few frames then halt again until I move the mouse. If I keep the mouse moving throughout the process it goes smoothly and quickly.
What could be causing this and is there a way to remedy this apparent dependency on mouse movement?