Fix/Refactor RNA ID preview getter creating preview data.

Same as with forcefields, accessors should never generate data.
This commit is contained in:
2021-05-25 10:38:23 +02:00
parent ad447705c0
commit e3faef686d
2 changed files with 23 additions and 12 deletions

View File

@@ -37,6 +37,9 @@ OBJECT_TYPES_RENDER = {'MESH', 'CURVE', 'SURFACE', 'META', 'FONT'}
def ids_nolib(bids):
return (bid for bid in bids if not bid.library)
def ids_nolib_with_preview(bids):
return (bid for bid in bids if (not bid.library and bid.preview))
def rna_backup_gen(data, include_props=None, exclude_props=None, root=()):
# only writable properties...
@@ -313,8 +316,9 @@ def do_previews(do_objects, do_collections, do_scenes, do_data_intern):
image = bpy.data.images[render_context.image, None]
item = getattr(bpy.data, item_container)[item_name, None]
image.reload()
item.preview.image_size = (RENDER_PREVIEW_SIZE, RENDER_PREVIEW_SIZE)
item.preview.image_pixels_float[:] = image.pixels
preview = item.preview_ensure()
preview.image_size = (RENDER_PREVIEW_SIZE, RENDER_PREVIEW_SIZE)
preview.image_pixels_float[:] = image.pixels
# And now, main code!
do_save = True
@@ -451,15 +455,15 @@ def do_clear_previews(do_objects, do_collections, do_scenes, do_data_intern):
bpy.ops.wm.previews_clear(id_type={'SHADING'})
if do_objects:
for ob in ids_nolib(bpy.data.objects):
for ob in ids_nolib_with_preview(bpy.data.objects):
ob.preview.image_size = (0, 0)
if do_collections:
for grp in ids_nolib(bpy.data.collections):
for grp in ids_nolib_with_preview(bpy.data.collections):
grp.preview.image_size = (0, 0)
if do_scenes:
for scene in ids_nolib(bpy.data.scenes):
for scene in ids_nolib_with_preview(bpy.data.scenes):
scene.preview.image_size = (0, 0)
print("Saving %s..." % bpy.data.filepath)