1
$\begingroup$

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?

$\endgroup$
1
  • 1
    $\begingroup$ Indeed, that seems to have been the case. I set up a timer and had the modal respond to Timer events and now it works as expected. $\endgroup$
    – gcs_dev
    Commented Jul 5 at 0:06

1 Answer 1

1
$\begingroup$

Answered by comments: Without knowing too much about addon writing, it seems pretty evident to me from this function that it’s designed to run on some kind of GUI event (i.e. something happened with an input device while the GUI was focused). If the mouse isn’t moving, and nothing else is happening, there are no GUI events, and the functions is not called.

The user’s solution was to set up a timer and have the modal respond to Timer events.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .