I’m creating an add-on to streamline the projecting of camera background images onto a model. This works very nicely for non-animated cameras (with still background images) but for an animated camera with a matching image sequence (one image for each frame) it only works when I am in ‘active camera view’ (numpad 0) or when I toggle active camera vie on and off. If i’m not currently in active camera view the background image doesn’t get updated for the current frame.
For example I’m in frame 1, in active camera view. I project my background image. I get the correct image applied. I then leave active camera view (numpad0) I then go to frame 2. Project the background image. I still get the (wrong)background image from frame 1. Toggle active camera view on and off (numpad 0 twice). project background image: now I get the correct image from frame 2.
So bpy.context.scene.camera.data.background_images.image is not getting updated unless I’m in ‘active camera’ view.
I can detect when the problem occurs (when bpy.context.scene.camera.data.background_images.image.source = ‘SEQUENCE’ ) but I don’t know how to update the image from python , if it is even possible? I tried bpy.( snip ).image.update() and .reload(), but neither worked.
Does anybody know if there is a python call to make sure the (cached?) image is updated for the current frame? Or is it a bug that it isn’t updated automagically?
Edit: I’m guessing it is a bug as bpy.context.scene.camera.data.background_images.image_user.use_auto_refresh = True and
bpy.context.scene.camera.data.background_images.image_user.frame_current does change when I change frames.
adding bgimage.image.gl_load(frame=bgimage.image_user.frame_current) before calling the actual projection operation seems to work. And calling a matching gl_free() afterwards, of course.
I’m not sure if this is the correct solution?