Fix/Refactor RNA ID preview getter creating preview data.
Same as with forcefields, accessors should never generate data.
This commit is contained in:
parent
ad447705c0
commit
e3faef686d
Notes:
blender-bot
2023-02-14 07:40:56 +01:00
Referenced by commit3e81d177ea
, Fix Grease Pencil materials added by Python missing Referenced by commit182edd4c35
, Fix T89284: Greasepencil top bar draw tool settings missing Referenced by issue #102566, Regression: Grease Pencil materials added via Python do not show up in "Change Active Material" Menu Referenced by issue #94418, No image.previews for some D.images Referenced by issue #89284, Grease pencil: top bar draw tool settings don't appear until material properties tab is clicked
|
@ -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)
|
||||
|
|
|
@ -1137,7 +1137,7 @@ static void rna_ImagePreview_icon_reload(PreviewImage *prv)
|
|||
static PointerRNA rna_IDPreview_get(PointerRNA *ptr)
|
||||
{
|
||||
ID *id = (ID *)ptr->data;
|
||||
PreviewImage *prv_img = BKE_previewimg_id_ensure(id);
|
||||
PreviewImage *prv_img = BKE_previewimg_id_get(id);
|
||||
|
||||
return rna_pointer_inherit_refine(ptr, &RNA_ImagePreview, prv_img);
|
||||
}
|
||||
|
@ -1707,12 +1707,12 @@ static void rna_def_ID(BlenderRNA *brna)
|
|||
srna, "override_library", "IDOverrideLibrary", "Library Override", "Library override data");
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
|
||||
prop = RNA_def_pointer(
|
||||
srna,
|
||||
"preview",
|
||||
"ImagePreview",
|
||||
"Preview",
|
||||
"Preview image and icon of this data-block (None if not supported for this type of data)");
|
||||
prop = RNA_def_pointer(srna,
|
||||
"preview",
|
||||
"ImagePreview",
|
||||
"Preview",
|
||||
"Preview image and icon of this data-block (always None if not supported "
|
||||
"for this type of data)");
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
|
||||
RNA_def_property_pointer_funcs(prop, "rna_IDPreview_get", NULL, NULL, NULL);
|
||||
|
@ -1826,6 +1826,13 @@ static void rna_def_ID(BlenderRNA *brna)
|
|||
"e.g. when calling :class:`bpy.types.Scene.update`");
|
||||
RNA_def_enum_flag(func, "refresh", update_flag_items, 0, "", "Type of updates to perform");
|
||||
|
||||
func = RNA_def_function(srna, "preview_ensure", "BKE_previewimg_id_ensure");
|
||||
RNA_def_function_ui_description(func,
|
||||
"Ensure that this ID has preview data (if ID type supports it)");
|
||||
parm = RNA_def_pointer(
|
||||
func, "preview_image", "ImagePreview", "", "The existing or created preview");
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
# ifdef WITH_PYTHON
|
||||
RNA_def_struct_register_funcs(srna, NULL, NULL, "rna_ID_instance");
|
||||
# endif
|
||||
|
|
Loading…
Reference in New Issue