[Bf-blender-cvs] [1b13fdaf80e] greasepencil-object: Annotations: Restore 3D View support for annotations (WIP)

Joshua Leung noreply at git.blender.org
Fri Jun 29 16:57:56 CEST 2018


Commit: 1b13fdaf80e938664c712c01dd7dfa8e7bdb6956
Author: Joshua Leung
Date:   Sat Jun 30 02:50:39 2018 +1200
Branches: greasepencil-object
https://developer.blender.org/rB1b13fdaf80e938664c712c01dd7dfa8e7bdb6956

Annotations: Restore 3D View support for annotations  (WIP)

Initial support for getting annotations to show up in the 3D
viewport again.  WIP and slightly hacky, but it restores basic
working functionality so we can focus on polishing the "new" parts.

Ultimately, the way these callbacks are integrated into the
drawing loop will probably need to change. For example,
* Perhaps we might need a full overlay engine for this one case
  (as for motionpaths), though that may also be overkill, and would
  further split the code in different places.
* The draw order (relative to manipulators) needs review. It probably
  should be below both sets of manipulators, not sandwiched between them.

Other notes:
* For this to work, we currently need to use the original (non-evaluated)
  scene data, or else we don't get the newly drawn strokes, as the
  scene->gpd stuff isn't copied by COW yet.

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/draw/intern/draw_manager.c
M	source/blender/editors/gpencil/annotate_draw.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index a0d06f65477..3e25382ed80 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -20,6 +20,7 @@
 import bpy
 from bpy.types import Header, Menu, Panel
 from .properties_paint_common import UnifiedPaintPanel
+from .properties_grease_pencil_common import GreasePencilDataPanel
 from bpy.app.translations import contexts as i18n_contexts
 
 
@@ -4129,6 +4130,14 @@ class VIEW3D_PT_quad_view(Panel):
         row.prop(region, "use_box_clip")
 
 
+# Annotation properties
+class VIEW3D_PT_grease_pencil(GreasePencilDataPanel, Panel):
+    bl_space_type = 'VIEW_3D'
+    bl_region_type = 'UI'
+
+    # NOTE: this is just a wrapper around the generic GP Panel
+
+
 # TODO: Move to Overlays popover (when in GP Object Draw Mode)
 class VIEW3D_PT_gp_paper(Panel):
     bl_space_type = 'VIEW_3D'
@@ -4426,6 +4435,7 @@ classes = (
     VIEW3D_MT_view_pie,
     VIEW3D_PT_view3d_properties,
     VIEW3D_PT_view3d_cursor,
+    VIEW3D_PT_grease_pencil,
     VIEW3D_PT_gp_paper,
     VIEW3D_PT_quad_view,
     VIEW3D_PT_view3d_stereo,
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index da9c9967767..94a0141a5dd 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -47,6 +47,7 @@
 
 #include "ED_space_api.h"
 #include "ED_screen.h"
+#include "ED_gpencil.h"
 #include "ED_particle.h"
 #include "ED_view3d.h"
 
@@ -1246,6 +1247,7 @@ void DRW_draw_render_loop_ex(
 	Scene *scene = DEG_get_evaluated_scene(depsgraph);
 	ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
 	RegionView3D *rv3d = ar->regiondata;
+	bool do_annotations = (v3d->flag2 & V3D_SHOW_GPENCIL) != 0;
 
 	DST.draw_ctx.evil_C = evil_C;
 
@@ -1338,6 +1340,17 @@ void DRW_draw_render_loop_ex(
 
 	drw_engines_draw_scene();
 
+	/* annotations - temporary drawing buffer (3d space) */
+	/* XXX: Or should we use a proper draw/overlay engine for this case? */
+	if (((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
+	    (do_annotations))
+	{
+		glDisable(GL_DEPTH_TEST);
+		/* XXX: as scene->gpd is not copied for COW yet */
+		ED_gpencil_draw_view3d_annotations(DEG_get_input_scene(depsgraph), depsgraph, v3d, ar, true);
+		glEnable(GL_DEPTH_TEST);
+	}
+
 	DRW_draw_callbacks_post_scene();
 	if (DST.draw_ctx.evil_C) {
 		ED_region_draw_cb_draw(DST.draw_ctx.evil_C, DST.draw_ctx.ar, REGION_DRAW_POST_VIEW);
@@ -1362,6 +1375,17 @@ void DRW_draw_render_loop_ex(
 
 		DRW_draw_region_info();
 
+		/* annotations - temporary drawing buffer (screenspace) */
+		/* XXX: Or should we use a proper draw/overlay engine for this case? */
+		if (((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
+		    (do_annotations))
+		{
+			glDisable(GL_DEPTH_TEST);
+			/* XXX: as scene->gpd is not copied for COW yet */
+			ED_gpencil_draw_view3d_annotations(DEG_get_input_scene(depsgraph), depsgraph, v3d, ar, false);
+			glEnable(GL_DEPTH_TEST);
+		}
+
 		if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
 			/* Draw 2D after region info so we can draw on top of the camera passepartout overlay.
 			 * 'DRW_draw_region_info' sets the projection in pixel-space. */
diff --git a/source/blender/editors/gpencil/annotate_draw.c b/source/blender/editors/gpencil/annotate_draw.c
index e1dfd150874..f17fa09186a 100644
--- a/source/blender/editors/gpencil/annotate_draw.c
+++ b/source/blender/editors/gpencil/annotate_draw.c
@@ -1038,25 +1038,22 @@ void ED_gpencil_draw_view2d(const bContext *C, bool onlyv2d)
 	}
 }
 
-#if 0 // XXX: Reinstate, after renaming the functions
 
-/* draw grease-pencil sketches to specified 3d-view assuming that matrices are already set correctly
+/* draw annotations sketches to specified 3d-view assuming that matrices are already set correctly
  * Note: this gets called twice - first time with only3d=true to draw 3d-strokes,
  * second time with only3d=false for screen-aligned strokes */
-void ED_gpencil_draw_view3d(wmWindowManager *wm,
-                            Scene *scene,
-                            ViewLayer *view_layer,
-                            struct Depsgraph *depsgraph,
-                            View3D *v3d,
-                            ARegion *ar,
-                            bool only3d)
+void ED_gpencil_draw_view3d_annotations(
+        Scene *scene, struct Depsgraph *depsgraph,
+        View3D *v3d, ARegion *ar,
+        bool only3d)
 {
 	int dflag = 0;
 	RegionView3D *rv3d = ar->regiondata;
 	int offsx,  offsy,  winx,  winy;
 
 	/* check that we have grease-pencil stuff to draw */
-	bGPdata *gpd = ED_gpencil_data_get_active_v3d(scene, view_layer);
+	/* XXX: Hardcoded reference here may get out of sync if we change how we fetch annotation data */
+	bGPdata *gpd = scene->gpd;
 	if (gpd == NULL) return;
 
 	/* when rendering to the offscreen buffer we don't want to
@@ -1095,6 +1092,8 @@ void ED_gpencil_draw_view3d(wmWindowManager *wm,
 	gp_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype);
 }
 
+#if 0 // XXX: Reinstate, after renaming the functions
+
 void ED_gpencil_draw_ex(Scene *scene, bGPdata *gpd, int winx, int winy, const int cfra, const char spacetype)
 {
 	int dflag = GP_DRAWDATA_NOSTATUS | GP_DRAWDATA_ONLYV2D;
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index d9a826e7f9c..b324b6a927a 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -145,6 +145,10 @@ void ED_gpencil_draw_view3d(struct wmWindowManager *wm,
                             struct View3D *v3d,
                             struct ARegion *ar,
                             bool only3d);
+void ED_gpencil_draw_view3d_annotations(
+        struct Scene *scene, struct Depsgraph *depsgraph,
+        struct View3D *v3d, struct ARegion *ar,
+        bool only3d);
 void ED_gpencil_draw_view3d_object(struct wmWindowManager *wm,
                                    struct Scene *scene,
                                    struct Depsgraph *depsgraph,
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index ef1a064c44b..3f161930cca 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -6232,14 +6232,12 @@ void RNA_def_scene(BlenderRNA *brna)
 	RNA_def_function_return(func, parm);
 
 	/* Grease Pencil */
-#if 0 /* GPXX: Disable, but keep because maybe is reused for annotations  */
 	prop = RNA_def_property(srna, "grease_pencil", PROP_POINTER, PROP_NONE);
 	RNA_def_property_pointer_sdna(prop, NULL, "gpd");
 	RNA_def_property_struct_type(prop, "GreasePencil");
 	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
-	RNA_def_property_ui_text(prop, "Grease Pencil Data", "Grease Pencil data-block");
+	RNA_def_property_ui_text(prop, "Annotations", "Grease Pencil data-block used for annotations in the 3D view");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-#endif
 
 	prop = RNA_def_property(srna, "gpencil_object", PROP_POINTER, PROP_NONE);
 	RNA_def_property_pointer_sdna(prop, NULL, "gp_object");



More information about the Bf-blender-cvs mailing list