I have writen a large Python script in Blender that does automatic sewing. First I will import a 3D-body, then import a T-shirt that is meant to be sewed. Then I place the body between the front & back of the T-shirt, assign cloth and collision modifiers.
Until this step all is good, then I play the animation using the code below, and intended to wait for the animation to stop at frame 30 then only continue execute the function after_sew()
.
def sew(body_name, garment_name):
body_obj = bpy.data.objects[body_name]
garment_obj = bpy.data.objects[garment_name]
s = bpy.context.scene
s.frame_start = 1
s.frame_end = 40
s.frame_current = 1
def stop_playback(scene):
if scene.frame_current == 30:
bpy.ops.screen.animation_cancel(restore_frame=False)
end = time()
print(f"Sewing completed in {round(end-start,2)} seconds.")
bpy.app.handlers.frame_change_post.append(stop_playback)
bpy.ops.screen.animation_play()
def after_sew():
print("Sewing done")
# Some other code
# Sewing
print("Now sewing... Please wait a few seconds.")
start = time()
sew(body_name, garment_name)
after_sew()
However, it is not going as expected. The script will call the sew()
function, then execute after_sew()
at the same time as animation is going. So I'm not able to get my desired output (at frame 30) in the after_sew()
function.
I have searched for this, but this is about stopping animation after a certain time. For my case, I won't know how much time will be needed for animation depends on user device. Besides this I haven't found any relevant issue on BlenderSE. Maybe this is a really easy configuration but I just didn't manage to get it.
I also searched for this, no answer is provided except the author himself, but I don't really know how to use bake option.