UI: Automatic Blend Thumbnail Selection

Adds an "Auto" option to blend thumbnail types that will automatically
use Screenshot if there is no camera and 3dview, or workbench render
with shading settings from the largest 3dview.

See D12407 for more details.

Differential Revision: https://developer.blender.org/D12407

Reviewed by Campbell Barton
This commit is contained in:
Harley Acheson 2021-09-16 17:39:19 -07:00
parent a1c65748c4
commit 4fa0bbb5ac
Notes: blender-bot 2023-02-14 05:25:44 +01:00
Referenced by issue #93949, save_as_mainfile will crash if context has no screen
5 changed files with 31 additions and 13 deletions

View File

@ -231,7 +231,7 @@ const UserDef U_default = {
.collection_instance_empty_size = 1.0f,
.statusbar_flag = STATUSBAR_SHOW_VERSION,
.file_preview_type = USER_FILE_PREVIEW_CAMERA,
.file_preview_type = USER_FILE_PREVIEW_AUTO,
.runtime =
{

View File

@ -887,7 +887,7 @@ void blo_do_versions_userdef(UserDef *userdef)
if (!USER_VERSION_ATLEAST(300, 21)) {
/* Deprecated userdef->flag USER_SAVE_PREVIEWS */
userdef->file_preview_type = (userdef->flag & USER_FLAG_UNUSED_5) ? USER_FILE_PREVIEW_CAMERA :
userdef->file_preview_type = (userdef->flag & USER_FLAG_UNUSED_5) ? USER_FILE_PREVIEW_AUTO :
USER_FILE_PREVIEW_NONE;
/* Clear for reuse. */
userdef->flag &= ~USER_FLAG_UNUSED_5;

View File

@ -1015,6 +1015,7 @@ typedef enum eUserPref_Flag {
/** #UserDef.file_preview_type */
typedef enum eUserpref_File_Preview_Type {
USER_FILE_PREVIEW_NONE = 0,
USER_FILE_PREVIEW_AUTO,
USER_FILE_PREVIEW_SCREENSHOT,
USER_FILE_PREVIEW_CAMERA,
} eUserpref_File_Preview_Type;

View File

@ -6060,6 +6060,7 @@ static void rna_def_userdef_filepaths(BlenderRNA *brna)
static const EnumPropertyItem preview_type_items[] = {
{USER_FILE_PREVIEW_NONE, "NONE", 0, "None", "Do not create blend previews"},
{USER_FILE_PREVIEW_AUTO, "AUTO", 0, "Auto", "Automatically select best preview type"},
{USER_FILE_PREVIEW_SCREENSHOT, "SCREENSHOT", 0, "Screenshot", "Capture the entire window"},
{USER_FILE_PREVIEW_CAMERA, "CAMERA", 0, "Camera View", "Workbench render of scene"},
{0, NULL, 0, NULL, NULL},

View File

@ -1602,10 +1602,9 @@ static ImBuf *blend_file_thumb_from_camera(const bContext *C,
return NULL;
}
if ((scene->camera == NULL) && (screen != NULL)) {
if (screen != NULL) {
area = BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0);
region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
if (region) {
if (area) {
v3d = area->spacedata.first;
}
}
@ -1624,13 +1623,14 @@ static ImBuf *blend_file_thumb_from_camera(const bContext *C,
if (scene->camera) {
ibuf = ED_view3d_draw_offscreen_imbuf_simple(depsgraph,
scene,
NULL,
OB_SOLID,
(v3d) ? &v3d->shading : NULL,
(v3d) ? v3d->shading.type : OB_SOLID,
scene->camera,
PREVIEW_RENDER_LARGE_HEIGHT * 2,
PREVIEW_RENDER_LARGE_HEIGHT * 2,
IB_rect,
V3D_OFSDRAW_NONE,
(v3d) ? V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS :
V3D_OFSDRAW_NONE,
R_ALPHAPREMUL,
NULL,
NULL,
@ -1766,12 +1766,28 @@ static bool wm_file_write(bContext *C,
/* Main now can store a '.blend' thumbnail, useful for background mode
* or thumbnail customization. */
main_thumb = thumb = bmain->blen_thumb;
if (BLI_thread_is_main()) {
if (U.file_preview_type == USER_FILE_PREVIEW_SCREENSHOT) {
ibuf_thumb = blend_file_thumb_from_screenshot(C, &thumb);
if (BLI_thread_is_main() && U.file_preview_type != USER_FILE_PREVIEW_NONE) {
int file_preview_type = U.file_preview_type;
if (file_preview_type == USER_FILE_PREVIEW_AUTO) {
Scene *scene = CTX_data_scene(C);
bool do_render = (scene != NULL && scene->camera != NULL &&
(BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_VIEW3D, 0) != NULL));
file_preview_type = do_render ? USER_FILE_PREVIEW_CAMERA : USER_FILE_PREVIEW_SCREENSHOT;
}
else if (U.file_preview_type == USER_FILE_PREVIEW_CAMERA) {
ibuf_thumb = blend_file_thumb_from_camera(C, CTX_data_scene(C), CTX_wm_screen(C), &thumb);
switch (file_preview_type) {
case USER_FILE_PREVIEW_SCREENSHOT: {
ibuf_thumb = blend_file_thumb_from_screenshot(C, &thumb);
break;
}
case USER_FILE_PREVIEW_CAMERA: {
ibuf_thumb = blend_file_thumb_from_camera(C, CTX_data_scene(C), CTX_wm_screen(C), &thumb);
break;
}
default:
BLI_assert_unreachable();
}
}