I have a draw_handler_add
like this:
import bpy,gpu
def draw():
global to_draw, begin
if to_draw:
print("drawing")
framebuffer = gpu.state.active_framebuffer_get()
viewport_info = gpu.state.viewport_get()
width = viewport_info[2]
height = viewport_info[3]
framebuffer_image.scale(width, height)
pixelBuffer = framebuffer.read_color(0, 0, width, height, 4, 0, 'FLOAT')
pixelBuffer.dimensions = width * height * 4
framebuffer_image.pixels.foreach_set(pixelBuffer)
framebuffer_image.filepath_raw = "/.../MyImage.png"
framebuffer_image.save()
to_draw=False
if __name__ == "__main__":
global to_draw,b
to_draw=False
if "color_buffer_copy" in bpy.data.images:
framebuffer_image = bpy.data.images["color_buffer_copy"]
else:
framebuffer_image = bpy.data.images.new("color_buffer_copy" , 32, 32, float_buffer=True,alpha=True)
bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'PRE_VIEW')
bpy.data.objects['Cube'].rotation_euler[0] = 1.5
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
to_draw=True
The problem is that the draw()
is being invoked after the script it completed
but I want it to be invoked while the script itself is running, so how do I achieve this?
(just for context my ultimate aim is to setup a server)