[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47827] trunk/blender: framing options for camera background image: stretch/fit/crop

Campbell Barton ideasman42 at gmail.com
Wed Jun 13 14:58:10 CEST 2012


Revision: 47827
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47827
Author:   campbellbarton
Date:     2012-06-13 12:58:01 +0000 (Wed, 13 Jun 2012)
Log Message:
-----------
framing options for camera background image: stretch/fit/crop

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_view3d.py
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/makesdna/DNA_view3d_types.h
    trunk/blender/source/blender/makesrna/intern/rna_space.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_view3d.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_view3d.py	2012-06-13 12:34:56 UTC (rev 47826)
+++ trunk/blender/release/scripts/startup/bl_ui/space_view3d.py	2012-06-13 12:58:01 UTC (rev 47827)
@@ -2575,8 +2575,15 @@
 
                 if has_bg:
                     col = box.column()
-                    col.prop(bg, "show_on_foreground")
                     col.prop(bg, "opacity", slider=True)
+
+                    rowsub = col.row()
+                    rowsub.prop(bg, "draw_depth", expand=True)
+
+                    if bg.view_axis in {'CAMERA', 'ALL'}:
+                        rowsub = col.row()
+                        rowsub.prop(bg, "frame_method", expand=True)
+
                     if bg.view_axis != 'CAMERA':
                         col.prop(bg, "size")
                         row = col.row(align=True)

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2012-06-13 12:34:56 UTC (rev 47826)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2012-06-13 12:58:01 UTC (rev 47827)
@@ -1547,6 +1547,8 @@
 		    (bgpic->view & (1 << rv3d->view)) || /* check agaist flags */
 		    (rv3d->persp == RV3D_CAMOB && bgpic->view == (1 << RV3D_VIEW_CAMERA)))
 		{
+			float image_aspect[2];
+
 			/* disable individual images */
 			if ((bgpic->flag & V3D_BGPIC_DISABLED))
 				continue;
@@ -1558,6 +1560,9 @@
 					continue;
 				BKE_image_user_frame_calc(&bgpic->iuser, CFRA, 0);
 				ibuf = BKE_image_get_ibuf(ima, &bgpic->iuser);
+
+				image_aspect[0] = ima->aspx;
+				image_aspect[1] = ima->aspx;
 			}
 			else if (bgpic->source == V3D_BGPIC_MOVIE) {
 				clip = NULL;
@@ -1574,6 +1579,9 @@
 				BKE_movieclip_user_set_frame(&bgpic->cuser, CFRA);
 				ibuf = BKE_movieclip_get_ibuf(clip, &bgpic->cuser);
 
+				image_aspect[0] = clip->aspx;
+				image_aspect[1] = clip->aspx;
+
 				/* working with ibuf from image and clip has got different workflow now.
 				 * ibuf acquired from clip is referenced by cache system and should
 				 * be dereferenced after usage. */
@@ -1609,6 +1617,38 @@
 					x2 = ar->winrct.xmax;
 					y2 = ar->winrct.ymax;
 				}
+
+				/* aspect correction */
+				if (bgpic->flag & V3D_BGPIC_CAMERA_ASPECT)
+				{
+					/* apply aspect from clip */
+					const float w_src = ibuf->x * image_aspect[0];
+					const float h_src = ibuf->y * image_aspect[1];
+
+					/* destination aspect is already applied from the camera frame */
+					const float w_dst = x1 - x2;
+					const float h_dst = y1 - y2;
+
+					const float asp_src = w_src / h_src;
+					const float asp_dst = w_dst / h_dst;
+
+					if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) {
+						if ((asp_src > asp_dst) == ((bgpic->flag & V3D_BGPIC_CAMERA_CROP) != 0)) {
+							/* fit X */
+							const float div = asp_src / asp_dst;
+							const float cent = (x1 + x2) / 2.0f;
+							x1 = ((x1 - cent) * div) + cent;
+							x2 = ((x2 - cent) * div) + cent;
+						}
+						else {
+							/* fit Y */
+							const float div = asp_dst / asp_src;
+							const float cent = (y1 + y2) / 2.0f;
+							y1 = ((y1 - cent) * div) + cent;
+							y2 = ((y2 - cent) * div) + cent;
+						}
+					}
+				}
 			}
 			else {
 				float sco[2];

Modified: trunk/blender/source/blender/makesdna/DNA_view3d_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_view3d_types.h	2012-06-13 12:34:56 UTC (rev 47826)
+++ trunk/blender/source/blender/makesdna/DNA_view3d_types.h	2012-06-13 12:58:01 UTC (rev 47827)
@@ -311,12 +311,20 @@
 /* #define V3D_CALC_MANIPULATOR	4 */ /*UNUSED*/
 
 /* BGPic->flag */
-/* may want to use 1 for select ?*/
-#define V3D_BGPIC_EXPANDED		2
-#define V3D_BGPIC_CAMERACLIP	4
-#define V3D_BGPIC_DISABLED		8
-#define V3D_BGPIC_FOREGROUND		16
+/* may want to use 1 for select ? */
+enum {
+	V3D_BGPIC_EXPANDED      = (1 << 1),
+	V3D_BGPIC_CAMERACLIP    = (1 << 2),
+	V3D_BGPIC_DISABLED      = (1 << 3),
+	V3D_BGPIC_FOREGROUND    = (1 << 4),
 
+	/* Camera framing options */
+	V3D_BGPIC_CAMERA_ASPECT = (1 << 5),  /* don't stretch to fit the camera view  */
+	V3D_BGPIC_CAMERA_CROP   = (1 << 6)   /* crop out the image */
+};
+
+#define V3D_BGPIC_EXPANDED (V3D_BGPIC_EXPANDED | V3D_BGPIC_CAMERACLIP)
+
 /* BGPic->source */
 /* may want to use 1 for select ?*/
 #define V3D_BGPIC_IMAGE		0

Modified: trunk/blender/source/blender/makesrna/intern/rna_space.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_space.c	2012-06-13 12:34:56 UTC (rev 47826)
+++ trunk/blender/source/blender/makesrna/intern/rna_space.c	2012-06-13 12:58:01 UTC (rev 47827)
@@ -1297,6 +1297,19 @@
 		{0, NULL, 0, NULL, NULL}
 	};
 
+	static const EnumPropertyItem bgpic_camera_frame_items[] = {
+		{0, "STRETCH", 0, "Stretch", ""},
+		{V3D_BGPIC_CAMERA_ASPECT, "FIT", 0, "Fit", ""},
+		{V3D_BGPIC_CAMERA_ASPECT | V3D_BGPIC_CAMERA_CROP, "CROP", 0, "Crop", ""},
+		{0, NULL, 0, NULL, NULL}
+	};
+
+	static const EnumPropertyItem bgpic_draw_depth_items[] = {
+		{0, "BACK", 0, "Back", ""},
+		{V3D_BGPIC_FOREGROUND, "FRONT", 0, "Front", ""},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	srna = RNA_def_struct(brna, "BackgroundImage", NULL);
 	RNA_def_struct_sdna(srna, "BGpic");
 	RNA_def_struct_ui_text(srna, "Background Image", "Image and settings for display in the 3d View background");
@@ -1381,6 +1394,20 @@
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_FOREGROUND);
 	RNA_def_property_ui_text(prop, "Show On Foreground", "Show this image in front of objects in viewport");
 	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+	/* expose 1 flag as a enum of 2 items */
+	prop = RNA_def_property(srna, "draw_depth", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
+	RNA_def_property_enum_items(prop, bgpic_draw_depth_items);
+	RNA_def_property_ui_text(prop, "Depth", "Draw under or over everything");
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+	/* expose 2 flags as a enum of 3 items */
+	prop = RNA_def_property(srna, "frame_method", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
+	RNA_def_property_enum_items(prop, bgpic_camera_frame_items);
+	RNA_def_property_ui_text(prop, "Frame Method", "How the image fits in the camera frame");
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 }
 
 static void rna_def_backgroundImages(BlenderRNA *brna, PropertyRNA *cprop)




More information about the Bf-blender-cvs mailing list