[Bf-blender-cvs] [fe03bc2] master: Support rotation and flipping for background images, patch by Andre D. (T34583) with minor changes. Thanks for the patch!

Antony Riakiotakis noreply at git.blender.org
Wed Feb 4 15:05:50 CET 2015


Commit: fe03bc2a02a0c9e5ecd554f72839ae0a407a8e86
Author: Antony Riakiotakis
Date:   Wed Feb 4 15:05:22 2015 +0100
Branches: master
https://developer.blender.org/rBfe03bc2a02a0c9e5ecd554f72839ae0a407a8e86

Support rotation and flipping for background images, patch by Andre D.
(T34583) with minor changes. Thanks for the patch!

===================================================================

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index c45d639..265163d 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3177,12 +3177,19 @@ class VIEW3D_PT_background_image(Panel):
                     if bg.view_axis in {'CAMERA', 'ALL'}:
                         col.row().prop(bg, "frame_method", expand=True)
 
-                    row = col.row(align=True)
+                    box = col.box()
+                    row = box.row()
                     row.prop(bg, "offset_x", text="X")
                     row.prop(bg, "offset_y", text="Y")
 
+                    row = box.row()
+                    row.prop(bg, "flip_h")
+                    row.prop(bg, "flip_v")
+
+                    row = box.row()
                     if bg.view_axis != 'CAMERA':
-                        col.prop(bg, "size")
+                         row.prop(bg, "rotation")
+                         row.prop(bg, "size")
 
 
 class VIEW3D_PT_transform_orientations(Panel):
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 1a57e63..49cb24f 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1615,7 +1615,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
 		{
 			float image_aspect[2];
 			float fac, asp, zoomx, zoomy;
-			float x1, y1, x2, y2;
+			float x1, y1, x2, y2, centx, centy;
 
 			ImBuf *ibuf = NULL, *freeibuf, *releaseibuf;
 			void *lock;
@@ -1721,6 +1721,9 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
 					y2 += yof_scale;
 				}
 
+				centx = (x1 + x2) / 2.0f;
+				centy = (y1 + y2) / 2.0f;
+
 				/* aspect correction */
 				if (bgpic->flag & V3D_BGPIC_CAMERA_ASPECT) {
 					/* apply aspect from clip */
@@ -1738,16 +1741,14 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
 						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;
+							x1 = ((x1 - centx) * div) + centx;
+							x2 = ((x2 - centx) * div) + centx;
 						}
 						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;
+							y1 = ((y1 - centy) * div) + centy;
+							y2 = ((y2 - centy) * div) + centy;
 						}
 					}
 				}
@@ -1774,6 +1775,9 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
 				y1 =  sco[1] + asp * fac * (bgpic->yof - bgpic->size);
 				x2 =  sco[0] + fac * (bgpic->xof + bgpic->size);
 				y2 =  sco[1] + asp * fac * (bgpic->yof + bgpic->size);
+
+				centx = (x1 + x2) / 2.0f;
+				centy = (y1 + y2) / 2.0f;
 			}
 
 			/* complete clip? */
@@ -1824,6 +1828,19 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
 			glPushMatrix();
 			ED_region_pixelspace(ar);
 
+			glTranslatef(centx, centy, 0.0);
+			if(rv3d->persp != RV3D_CAMOB) {
+				glRotatef(RAD2DEGF(-bgpic->rotation), 0.0f, 0.0f, 1.0f);
+			}
+
+			if(bgpic->flag & V3D_BGPIC_FLIP_V) {
+				zoomy *= -1.0f;
+				y1 = y2;
+			}
+			if(bgpic->flag & V3D_BGPIC_FLIP_H) {
+				zoomx *= -1.0f;
+				x1 = x2;
+			}
 			glPixelZoom(zoomx, zoomy);
 			glColor4f(1.0f, 1.0f, 1.0f, 1.0f - bgpic->blend);
 
@@ -1831,7 +1848,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
 			 * glaDrawPixelsSafe in some cases, which will end up in missing
 			 * alpha transparency for the background image (sergey)
 			 */
-			glaDrawPixelsTex(x1, y1, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect);
+			glaDrawPixelsTex(x1 - centx, y1 - centy, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect);
 
 			glPixelZoom(1.0, 1.0);
 			glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 7a1cd88..e6f61fb 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -5004,8 +5004,9 @@ BGpic *ED_view3D_background_image_new(View3D *v3d)
 {
 	BGpic *bgpic = MEM_callocN(sizeof(BGpic), "Background Image");
 
-	bgpic->size = 5.0;
-	bgpic->blend = 0.5;
+	bgpic->rotation = 0.0f;
+	bgpic->size = 5.0f;
+	bgpic->blend = 0.5f;
 	bgpic->iuser.fie_ima = 2;
 	bgpic->iuser.ok = 1;
 	bgpic->view = 0; /* 0 for all */
diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h
index 069ea7a..0c290ab 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -74,10 +74,11 @@ typedef struct BGpic {
 	struct ImageUser iuser;
 	struct MovieClip *clip;
 	struct MovieClipUser cuser;
-	float xof, yof, size, blend;
+	float xof, yof, size, blend, rotation;
 	short view;
 	short flag;
-	short source, pad;
+	short source;
+	char pad[6];
 } BGpic;
 
 /* ********************************* */
@@ -340,7 +341,11 @@ enum {
 
 	/* 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 */
+	V3D_BGPIC_CAMERA_CROP   = (1 << 6),  /* crop out the image */
+
+	/* Axis flip options */
+	V3D_BGPIC_FLIP_H        = (1 << 7),
+	V3D_BGPIC_FLIP_V        = (1 << 8)
 };
 
 #define V3D_BGPIC_EXPANDED (V3D_BGPIC_EXPANDED | V3D_BGPIC_CAMERACLIP)
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index ff9df16..7eaf737 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -1700,7 +1700,22 @@ static void rna_def_background_image(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Size", "Scaling factor for the background image");
 	RNA_def_property_range(prop, 0.0, FLT_MAX);
 	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-	
+
+	prop = RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_EULER);
+	RNA_def_property_float_sdna(prop, NULL, "rotation");
+	RNA_def_property_ui_text(prop, "Rotation", "Rotation for the background image");
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+	prop = RNA_def_property(srna, "flip_h", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_FLIP_H);
+	RNA_def_property_ui_text(prop, "Flip Horizontally", "Flip the background image horizontally");
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+	prop = RNA_def_property(srna, "flip_v", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_FLIP_V);
+	RNA_def_property_ui_text(prop, "Flip Vertically", "Flip the background image vertically");
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
 	prop = RNA_def_property(srna, "opacity", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_sdna(prop, NULL, "blend");
 	RNA_def_property_float_funcs(prop, "rna_BackgroundImage_opacity_get", "rna_BackgroundImage_opacity_set", NULL);




More information about the Bf-blender-cvs mailing list