[Bf-blender-cvs] [e29deba] wiggly-widgets: Graph Editor backdrop from camera

Julian Eisel noreply at git.blender.org
Sun Apr 5 23:48:21 CEST 2015


Commit: e29deba64e15281b9e6a27c7ff43782cddba0b51
Author: Julian Eisel
Date:   Sun Apr 5 23:47:52 2015 +0200
Branches: wiggly-widgets
https://developer.blender.org/rBe29deba64e15281b9e6a27c7ff43782cddba0b51

Graph Editor backdrop from camera

Adds an option for the Graph Editor to show the view plane of a
selectable camera as a backdrop.
Next step: Widgify it!

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

M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/screen/area.c
M	source/blender/editors/space_graph/graph_buttons.c
M	source/blender/editors/space_graph/space_graph.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index b4f7d80..cf0b428 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -67,6 +67,9 @@ void    ED_region_header(const struct bContext *C, struct ARegion *ar);
 void    ED_region_toggle_hidden(struct bContext *C, struct ARegion *ar);
 void    ED_region_info_draw(struct ARegion *ar, const char *text, int block, float fill_color[4]);
 void    ED_region_grid_draw(struct ARegion *ar, float zoomx, float zoomy);
+void    ED_region_draw_backdrop_view3d(const struct bContext *C, struct Object *camera, const float width, const float height,
+                                       const float x, const float y, const float zoomx, const float zoomy,
+                                       const bool draw_alpha, const bool draw_border);
 float	ED_region_blend_factor(struct ARegion *ar);
 void	ED_region_visible_rect(struct ARegion *ar, struct rcti *rect);
 
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 90c0907..25f87bb 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -44,6 +44,8 @@
 
 #include "BKE_context.h"
 #include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_scene.h"
 #include "BKE_screen.h"
 
 #include "RNA_access.h"
@@ -56,6 +58,7 @@
 #include "ED_screen.h"
 #include "ED_screen_types.h"
 #include "ED_space_api.h"
+#include "ED_view3d.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
@@ -66,6 +69,8 @@
 #include "UI_resources.h"
 #include "UI_view2d.h"
 
+#include "IMB_imbuf.h"
+
 #include "screen_intern.h"
 
 extern void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3); /* xxx temp */
@@ -2089,6 +2094,44 @@ void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
 	glEnd();
 }
 
+/* uses the viewplane from the given camera and draws it as a backdrop */
+void ED_region_draw_backdrop_view3d(const bContext *C, struct Object *camera, const float width, const float height,
+                                    const float x, const float y, const float zoomx, const float zoomy,
+                                    const bool draw_alpha, const bool draw_border)
+{
+	Main *bmain = CTX_data_main(C);
+	Scene *scene = CTX_data_scene(C);
+	char err_out[256] = "unknown";
+	struct ImBuf *ibuf;
+	int filter = GL_LINEAR;
+
+	BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, scene->lay);
+	ibuf = ED_view3d_draw_offscreen_imbuf_simple(scene, camera, width, height, (1 << 0),
+	                                             3, false, false, false, R_ADDSKY, err_out);
+
+	if (ibuf == NULL)
+		return;
+
+	glEnable(GL_BLEND);
+	glPushMatrix();
+	glScalef(zoomx, zoomy, 0.0f);
+	glTranslatef(x, y, 0.0f);
+
+	if (draw_alpha == true) {
+		fdrawcheckerboard(0.0f, 0.0f, width, height);
+	}
+	if (draw_border == true) {
+		glColor3f(0.1f, 0.1f, 0.1f);
+		fdrawbox(0.0f, 0.0f, width + 0.5f, height + 0.5f);
+	}
+	glaDrawImBuf_glsl_ctx(C, ibuf, 0.0f, 0.0f, filter);
+
+	glPopMatrix();
+	glDisable(GL_BLEND);
+
+	IMB_freeImBuf(ibuf);
+}
+
 /* If the area has overlapping regions, it returns visible rect for Region *ar */
 /* rect gets returned in local region coordinates */
 void ED_region_visible_rect(ARegion *ar, rcti *rect)
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c
index e0b6272..aac1308 100644
--- a/source/blender/editors/space_graph/graph_buttons.c
+++ b/source/blender/editors/space_graph/graph_buttons.c
@@ -139,6 +139,12 @@ static void graph_panel_view(const bContext *C, Panel *pa)
 	row = uiLayoutSplit(sub, 0.7f, true);
 	uiItemR(row, &spaceptr, "cursor_position_y", 0, IFACE_("Cursor Y"), ICON_NONE);
 	uiItemEnumO(row, "GRAPH_OT_snap", IFACE_("To Keys"), 0, "type", GRAPHKEYS_SNAP_VALUE);
+
+	col = uiLayoutColumn(pa->layout, false);
+	uiItemR(col, &spaceptr, "show_backdrop", 0, NULL, ICON_NONE);
+	col = uiLayoutColumn(pa->layout, true);
+	uiLayoutSetActive(col, RNA_boolean_get(&spaceptr, "show_backdrop"));
+	uiItemR(col, &spaceptr, "backdrop_camera", 0, "Camera", ICON_NONE);
 }
 
 /* ******************* active F-Curve ************** */
diff --git a/source/blender/editors/space_graph/space_graph.c b/source/blender/editors/space_graph/space_graph.c
index ad6f3ff..e352545 100644
--- a/source/blender/editors/space_graph/space_graph.c
+++ b/source/blender/editors/space_graph/space_graph.c
@@ -103,6 +103,8 @@ static SpaceLink *graph_new(const bContext *C)
 	
 	sipo->autosnap = SACTSNAP_FRAME;
 	
+	sipo->backdrop_camera = scene->camera;
+	
 	/* allocate DopeSheet data for Graph Editor */
 	sipo->ads = MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
 	sipo->ads->source = (ID *)scene;
@@ -225,12 +227,17 @@ static void graph_main_area_draw(const bContext *C, ARegion *ar)
 {
 	/* draw entirely, view changes should be handled here */
 	SpaceIpo *sipo = CTX_wm_space_graph(C);
+	Scene *scene = CTX_data_scene(C);
 	bAnimContext ac;
 	View2D *v2d = &ar->v2d;
 	View2DGrid *grid;
 	View2DScrollers *scrollers;
 	float col[3];
 	short unitx = 0, unity = V2D_UNIT_VALUES, flag = 0;
+	const bool draw_backdrop = ((sipo->flag & SIPO_DRAW_BACKDROP) && (sipo->backdrop_camera != NULL));
+	rctf rect_mask_orig;
+	
+	BLI_rctf_init(&rect_mask_orig, v2d->mask.xmin, v2d->mask.xmax, v2d->mask.ymin, v2d->mask.ymax);
 	
 	/* clear and setup matrix */
 	UI_GetThemeColor3fv(TH_BACK, col);
@@ -241,11 +248,25 @@ static void graph_main_area_draw(const bContext *C, ARegion *ar)
 	
 	/* grid */
 	unitx = (sipo->flag & SIPO_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMESCALE;
-	grid = UI_view2d_grid_calc(CTX_data_scene(C), v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
+	grid = UI_view2d_grid_calc(scene, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
 	UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
 	
 	ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
-
+	
+	if (draw_backdrop) {
+		int width = (scene->r.xsch * scene->r.size) / 100;
+		int height = (scene->r.ysch * scene->r.size) / 100;
+		float x = (rect_mask_orig.xmax - width) / 2; /* center of the screen */
+		float y = (rect_mask_orig.ymax - height - U.widget_unit); /* below upper edge with small offset */
+		
+		/* reset view matrix */
+		UI_view2d_view_restore(C);
+		
+		ED_region_draw_backdrop_view3d(C, sipo->backdrop_camera, width, height, x, y, 1.0f, 1.0f, true, true);
+		
+		UI_view2d_view_ortho(v2d);
+	}
+	
 	/* draw data */
 	if (ANIM_animdata_get_context(C, &ac)) {
 		/* draw ghost curves */
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 302718d..53cbdf3 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -321,6 +321,8 @@ typedef struct SpaceIpo {
 	
 	ListBase ghostCurves;   /* sampled snapshots of F-Curves used as in-session guides */
 	
+	struct Object *backdrop_camera; /* the view from this camera is used to draw the backdrop */
+	
 	short mode;             /* mode for the Graph editor (eGraphEdit_Mode) */
 	short autosnap;         /* time-transform autosnapping settings for Graph editor (eAnimEdit_AutoSnap in DNA_action_types.h) */
 	int flag;               /* settings for Graph editor (eGraphEdit_Flag) */
@@ -365,6 +367,7 @@ typedef enum eGraphEdit_Flag {
 	/* normalize curves on display */
 	SIPO_NORMALIZE            = (1 << 14),
 	SIPO_NORMALIZE_FREEZE     = (1 << 15),
+	SIPO_DRAW_BACKDROP        = (1 << 16),
 } eGraphEdit_Flag;
 
 /* SpaceIpo->mode (Graph Editor Mode) */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index b5cc516..e7e16fe 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -3304,6 +3304,17 @@ static void rna_def_space_graph(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Auto Normalization",
 	                         "Automatically recalculate curve normalization on every curve edit");
 	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_GRAPH, NULL);
+
+	prop = RNA_def_property(srna, "show_backdrop", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", SIPO_DRAW_BACKDROP);
+	RNA_def_property_ui_text(prop, "Show Backdrop", "Draw a backdrop showing the content of the 3D View");
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_GRAPH, NULL);
+
+	prop = RNA_def_property(srna, "backdrop_camera", PROP_POINTER, PROP_NONE);
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Camera_object_poll");
+	RNA_def_property_ui_text(prop, "Backdrop Camera", "The camera that is used to project the backdrop");
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_GRAPH, NULL);
 }
 
 static void rna_def_space_nla(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list