Merge branch 'blender-v3.0-release'

This commit is contained in:
Julian Eisel 2021-11-22 21:26:39 +01:00
commit 456d5e14b8
4 changed files with 48 additions and 24 deletions

View File

@ -360,31 +360,23 @@ void BKE_previewimg_id_copy(ID *new_id, const ID *old_id)
PreviewImage **BKE_previewimg_id_get_p(const ID *id)
{
switch (GS(id->name)) {
case ID_OB: {
Object *ob = (Object *)id;
/* Currently, only object types with real geometry can be rendered as preview. */
if (!OB_TYPE_IS_GEOMETRY(ob->type)) {
return nullptr;
}
return &ob->preview;
}
#define ID_PRV_CASE(id_code, id_struct) \
case id_code: { \
return &((id_struct *)id)->preview; \
} \
((void)0)
ID_PRV_CASE(ID_MA, Material);
ID_PRV_CASE(ID_TE, Tex);
ID_PRV_CASE(ID_WO, World);
ID_PRV_CASE(ID_LA, Light);
ID_PRV_CASE(ID_IM, Image);
ID_PRV_CASE(ID_BR, Brush);
ID_PRV_CASE(ID_GR, Collection);
ID_PRV_CASE(ID_SCE, Scene);
ID_PRV_CASE(ID_SCR, bScreen);
ID_PRV_CASE(ID_AC, bAction);
ID_PRV_CASE(ID_NT, bNodeTree);
ID_PRV_CASE(ID_OB, Object);
ID_PRV_CASE(ID_MA, Material);
ID_PRV_CASE(ID_TE, Tex);
ID_PRV_CASE(ID_WO, World);
ID_PRV_CASE(ID_LA, Light);
ID_PRV_CASE(ID_IM, Image);
ID_PRV_CASE(ID_BR, Brush);
ID_PRV_CASE(ID_GR, Collection);
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

@ -82,6 +82,8 @@ typedef enum ePreviewRenderMethod {
void ED_preview_ensure_dbase(void);
void ED_preview_free_dbase(void);
bool ED_preview_id_is_supported(const struct ID *id);
void ED_preview_shader_job(const struct bContext *C,
void *owner,
struct ID *id,

View File

@ -2037,11 +2037,22 @@ void UI_icon_render_id(
const bContext *C, Scene *scene, ID *id, const enum eIconSizes size, const bool use_job)
{
PreviewImage *pi = BKE_previewimg_id_ensure(id);
if (pi == NULL) {
return;
}
/* For objects, first try if a preview can created via the object data. */
if (GS(id->name) == ID_OB) {
Object *ob = (Object *)id;
if (ED_preview_id_is_supported(ob->data)) {
id = ob->data;
}
}
if (!ED_preview_id_is_supported(id)) {
return;
}
ui_id_preview_image_render_size(C, scene, id, pi, size, use_job);
}

View File

@ -786,6 +786,11 @@ struct ObjectPreviewData {
int sizey;
};
static bool object_preview_is_type_supported(const Object *ob)
{
return OB_TYPE_IS_GEOMETRY(ob->type);
}
static Object *object_preview_camera_create(Main *preview_main,
ViewLayer *view_layer,
Object *preview_object)
@ -1658,9 +1663,12 @@ static void icon_preview_startjob_all_sizes(void *customdata,
if (ip->id != NULL) {
switch (GS(ip->id->name)) {
case ID_OB:
/* Much simpler than the ShaderPreview mess used for other ID types. */
object_preview_render(ip, cur_size);
continue;
if (object_preview_is_type_supported((Object *)ip->id)) {
/* Much simpler than the ShaderPreview mess used for other ID types. */
object_preview_render(ip, cur_size);
continue;
}
break;
case ID_AC:
action_preview_render(ip, cur_size);
continue;
@ -1749,6 +1757,17 @@ static void icon_preview_free(void *customdata)
MEM_freeN(ip);
}
/**
* Check if \a id is supported by the automatic preview render.
*/
bool ED_preview_id_is_supported(const ID *id)
{
if (GS(id->name) == ID_OB) {
return object_preview_is_type_supported((const Object *)id);
}
return BKE_previewimg_id_get_p(id) != NULL;
}
void ED_preview_icon_render(
const bContext *C, Scene *scene, ID *id, uint *rect, int sizex, int sizey)
{