[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45726] trunk/blender/source/blender/ windowmanager/intern/wm_files.c: save thumbnail from the 3D view if no camera is present.

Campbell Barton ideasman42 at gmail.com
Tue Apr 17 22:51:12 CEST 2012


Revision: 45726
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45726
Author:   campbellbarton
Date:     2012-04-17 20:51:11 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
save thumbnail from the 3D view if no camera is present.

Modified Paths:
--------------
    trunk/blender/source/blender/windowmanager/intern/wm_files.c

Modified: trunk/blender/source/blender/windowmanager/intern/wm_files.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_files.c	2012-04-17 19:51:40 UTC (rev 45725)
+++ trunk/blender/source/blender/windowmanager/intern/wm_files.c	2012-04-17 20:51:11 UTC (rev 45726)
@@ -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 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 @@
 	/* 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);




More information about the Bf-blender-cvs mailing list