Nodes: add preview image storage to node group

This is part of T92811.

Differential Revision: https://developer.blender.org/D13105
This commit is contained in:
Jacques Lucke 2021-11-06 16:43:26 +01:00
parent 81baeec59b
commit f315a46982
Notes: blender-bot 2023-02-14 05:50:03 +01:00
Referenced by issue #90201, Support Preview Thumbnails
Referenced by issue #90067, Support Preview Image Storage for More Data-block Types
4 changed files with 22 additions and 0 deletions

View File

@ -35,6 +35,7 @@
#include "DNA_gpencil_types.h"
#include "DNA_light_types.h"
#include "DNA_material_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
@ -383,6 +384,7 @@ PreviewImage **BKE_previewimg_id_get_p(const ID *id)
ID_PRV_CASE(ID_SCE, Scene);
ID_PRV_CASE(ID_SCR, bScreen);
ID_PRV_CASE(ID_AC, bAction);
ID_PRV_CASE(ID_NT, bNodeTree);
#undef ID_PRV_CASE
default:
break;

View File

@ -66,6 +66,7 @@
#include "BKE_colortools.h"
#include "BKE_cryptomatte.h"
#include "BKE_global.h"
#include "BKE_icons.h"
#include "BKE_idprop.h"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
@ -248,6 +249,13 @@ static void ntree_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c
ntree_dst->field_inferencing_interface = node_field_inferencing_interface_copy(
*ntree_src->field_inferencing_interface);
}
if (flag & LIB_ID_COPY_NO_PREVIEW) {
ntree_dst->preview = NULL;
}
else {
BKE_previewimg_id_copy(&ntree_dst->id, &ntree_src->id);
}
}
static void ntree_free_data(ID *id)
@ -303,6 +311,8 @@ static void ntree_free_data(ID *id)
if (ntree->id.tag & LIB_TAG_LOCALIZED) {
BKE_libblock_free_data(&ntree->id, true);
}
BKE_previewimg_free(&ntree->preview);
}
static void library_foreach_node_socket(LibraryForeachIDData *data, bNodeSocket *sock)
@ -639,6 +649,8 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree)
LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) {
write_node_socket_interface(writer, sock);
}
BKE_previewimg_blend_write(writer, ntree->preview);
}
static void ntree_blend_write(BlendWriter *writer, ID *id, const void *id_address)
@ -832,6 +844,9 @@ void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree)
ntree->update |= NTREE_UPDATE_FIELD_INFERENCING;
}
BLO_read_data_address(reader, &ntree->preview);
BKE_previewimg_blend_read(reader, ntree->preview);
/* type verification is in lib-link */
}

View File

@ -347,6 +347,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *r_
case ID_GR: /* fall through */
case ID_SCE: /* fall through */
case ID_AC: /* fall through */
case ID_NT: /* fall through */
new_prv = MEM_callocN(sizeof(PreviewImage), "newpreview");
BLI_linklist_prepend(&previews, new_prv);
tot++;

View File

@ -46,6 +46,7 @@ struct bNodePreview;
struct bNodeTreeExec;
struct bNodeType;
struct uiBlock;
struct PreviewImage;
#define NODE_MAXSTR 64
@ -561,6 +562,9 @@ typedef struct bNodeTree {
int (*test_break)(void *);
void (*update_draw)(void *);
void *tbh, *prh, *sdh, *udh;
/** Image representing what the node group does. */
struct PreviewImage *preview;
} bNodeTree;
/* ntree->type, index */