I’ve written an operator which edits an image in the Image Editor, but it won't work properly with the undo system. I have created a minimal repro script:
import bpy
img = bpy.data.images['MyImage']
# fill bottom half with white pixels
for x in range(img.size[0] * img.size[1] * 2):
img.pixels[x] = 1
img.update()
Creating a small black RGBA image (e.g. 8x8) called "MyImage" and running the code above, I am not able to undo the effect of the script properly.
I have also tried using bpy.ops.ed.undo_push()
to try snapshotting before and after the image pixels are altered, as well as trying Image.pack()
to pack the image into the blend file in the hope it gets snapshotted, to no avail. The built-in texture paint tools are able to create undo states which properly work, so I am hoping there is some API that I can use for this.
To put it simply - undo states behave weirdly when pixels
is altered (the output seems different when undoing and redoing back to the same state) as can be seen in this video:
https://i.imgur.com/D9f5g5W.mp4
I have spent many hours searching for a solution. If anyone could offer any insights or workarounds I would greatly appreciate it.