From fdea14acb4b79b59da44ec45149d94129e1e8a8c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 17 Apr 2012 20:51:11 +0000 Subject: save thumbnail from the 3D view if no camera is present. --- source/blender/windowmanager/intern/wm_files.c | 37 +++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 9ffea0e290b..e50fbaa624e 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -80,6 +80,7 @@ #include "BKE_packedFile.h" #include "BKE_report.h" #include "BKE_sound.h" +#include "BKE_screen.h" #include "BKE_texture.h" @@ -662,23 +663,47 @@ static void write_history(void) } } -static ImBuf *blend_file_thumb(Scene *scene, int **thumb_pt) +/* screen can be NULL */ +static ImBuf *blend_file_thumb(Scene *scene, bScreen *screen, int **thumb_pt) { /* will be scaled down, but gives some nice oversampling */ ImBuf *ibuf; int *thumb; char err_out[256] = "unknown"; + /* screen if no camera found */ + ScrArea *sa = NULL; + ARegion *ar = NULL; + View3D *v3d = NULL; + *thumb_pt = NULL; /* scene can be NULL if running a script at startup and calling the save operator */ - if (G.background || scene == NULL || scene->camera == NULL) + if (G.background || scene == NULL) + return NULL; + + if ((scene->camera == NULL) && (screen != NULL)) { + sa = BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0); + ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); + if (ar) { + v3d = sa->spacedata.first; + } + } + + if (scene->camera == NULL && v3d == NULL) { return NULL; + } /* gets scaled to BLEN_THUMB_SIZE */ - ibuf = ED_view3d_draw_offscreen_imbuf_simple(scene, scene->camera, - BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2, - IB_rect, OB_SOLID, FALSE, err_out); + if (scene->camera) { + ibuf = ED_view3d_draw_offscreen_imbuf_simple(scene, scene->camera, + BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2, + IB_rect, OB_SOLID, FALSE, err_out); + } + else { + ibuf = ED_view3d_draw_offscreen_imbuf(scene, v3d, ar, BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2, + IB_rect, FALSE, err_out); + } if (ibuf) { float aspect = (scene->r.xsch * scene->r.xasp) / (scene->r.ysch * scene->r.yasp); @@ -763,7 +788,7 @@ int WM_write_file(bContext *C, const char *target, int fileflags, ReportList *re /* blend file thumbnail */ /* save before exit_editmode, otherwise derivedmeshes for shared data corrupt #27765) */ if (U.flag & USER_SAVE_PREVIEWS) { - ibuf_thumb = blend_file_thumb(CTX_data_scene(C), &thumb); + ibuf_thumb = blend_file_thumb(CTX_data_scene(C), CTX_wm_screen(C), &thumb); } BLI_exec_cb(G.main, NULL, BLI_CB_EVT_SAVE_PRE); -- cgit v1.2.3