[Bf-blender-cvs] [f25541be38c] greasepencil-object: Fix: If the active object is not a GP object, starting to draw with D-LMB would create a new GP object

Joshua Leung noreply at git.blender.org
Mon Sep 25 14:16:20 CEST 2017


Commit: f25541be38c131f623c4f12c4357d7813863997a
Author: Joshua Leung
Date:   Tue Sep 26 01:14:47 2017 +1300
Branches: greasepencil-object
https://developer.blender.org/rBf25541be38c131f623c4f12c4357d7813863997a

Fix: If the active object is not a GP object, starting to draw
with D-LMB would create a new GP object

This was behaviour was bad if you were trying to use GPencil for
anything other than 2D-3D art (e.g. for creating freehand input
for addons/Pose Sketching, annotating your work in EditMode, etc.)
as you could easily end up with all your annotations/sketches in heaps
of separate GP objects.

This commit improves the sitation slightly, by introducing an
"GPencil Object" property to Scene (similar to the existing "Active Camera"
and "Active Clip" settings).
* The idea is that the first GP object added to the scene as the "default
  GPencil Object".
* Everytime you start sketching with GPencil AND the active object isn't
  a GPencil Object, this "default GPencil Object" will become the active object,
  and any strokes you draw will be added to this object (instead of a new
  GP object being created)

TODO:
* Investigate if we can do this without losing whatever mode the user was
  in previously. This new workflow makes GPencil a lot less useful for a
  bunch of different annotation/addon workflows it could be used for in 2.7

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

M	release/scripts/startup/bl_ui/properties_scene.py
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/properties_scene.py b/release/scripts/startup/bl_ui/properties_scene.py
index cf1b4024aff..3529ba0e8cc 100644
--- a/release/scripts/startup/bl_ui/properties_scene.py
+++ b/release/scripts/startup/bl_ui/properties_scene.py
@@ -80,6 +80,7 @@ class SCENE_PT_scene(SceneButtonsPanel, Panel):
         layout.prop(scene, "background_set", text="Background")
         if context.scene.render.engine != 'BLENDER_GAME':
             layout.prop(scene, "active_clip", text="Active Clip")
+        layout.prop(scene, "gpencil_object")
 
 
 class SCENE_PT_unit(SceneButtonsPanel, Panel):
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 8dbde20894f..0fbfb0861c4 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -796,6 +796,7 @@ void BKE_gpencil_stroke_weights_duplicate(bGPDstroke *gps_src, bGPDstroke *gps_d
 	if (gps_src == NULL) {
 		return;
 	}
+	BLI_assert(gps_src->totpoints == gps_dst->totpoints);
 	for (int i = 0; i < gps_src->totpoints; ++i) {
 		bGPDspoint *pt_dst = &gps_dst->points[i];
 		bGPDspoint *pt_src = &gps_src->points[i];
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 0419af81d36..e975b064050 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -46,28 +46,30 @@
 
 #include "PIL_time.h"
 
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_gpencil_types.h"
+#include "DNA_brush_types.h"
+#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
+
 #include "BKE_main.h"
 #include "BKE_paint.h"
 #include "BKE_gpencil.h"
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_report.h"
+#include "BKE_layer.h"
 #include "BKE_screen.h"
 #include "BKE_tracking.h"
 #include "BKE_colortools.h"
 #include "BKE_workspace.h"
 
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_gpencil_types.h"
-#include "DNA_brush_types.h"
-#include "DNA_windowmanager_types.h"
-#include "DNA_workspace_types.h"
-
 #include "UI_view2d.h"
 
 #include "ED_gpencil.h"
 #include "ED_screen.h"
+#include "ED_object.h"
 #include "ED_view3d.h"
 #include "ED_clip.h"
 
@@ -173,6 +175,8 @@ typedef struct tGPsdata {
 	int lock_axis;       /* lock drawing to one axis */
 
 	short keymodifier;   /* key used for invoking the operator */
+	
+	ReportList *reports;
 } tGPsdata;
 
 /* ------ */
@@ -1405,11 +1409,40 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
 					printf("Error: 3D-View active region doesn't have any region data, so cannot be drawable\n");
 				return 0;
 			}
-			/* if not active a OB_GPENCIL, create one */
+			
+			/* if active object doesn't exist or it's not a Grease Pencil object, 
+			 * use the scene's gp_object (), or create one if it doesn't exist
+			 */
 			float *cur = ED_view3d_cursor3d_get(p->scene, v3d);
 			if ((!obact) || (obact->type != OB_GPENCIL)) {
-				obact = ED_add_gpencil_object(C, p->scene, cur);
+				if (p->scene->gp_object) {
+					/* use existing default */
+					/* XXX: This will still lose whatever mode we were in before,
+					 *      making GP less convenient for annotations than it used to be
+					 */
+					obact = p->scene->gp_object;
+					
+					/* temporarily activate the object */
+					SceneLayer *sl = CTX_data_scene_layer(C);
+					Base *base = BKE_scene_layer_base_find(sl, obact);
+					if (base) {
+						if (CTX_data_edit_object(C)) 
+							ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO);  /* freedata, and undo */
+						
+						sl->basact = base;
+						ED_base_object_activate(C, base);
+					}
+					else {
+						printf("ERROR: Couldn't find base for active gp_object (sl = %p, obact = %s)\n", sl, obact->id.name);
+					}
+				}
+				else {
+					/* create new default */
+					obact = ED_add_gpencil_object(C, p->scene, cur);
+					p->scene->gp_object = obact;
+				}
 			}
+			
 			/* set grease pencil mode to object */
 			ts->gpencil_src = GP_TOOL_SOURCE_OBJECT;
 			break;
@@ -1993,6 +2026,8 @@ static int gpencil_draw_init(bContext *C, wmOperator *op, const wmEvent *event)
 		p->keymodifier = -1;
 	}
 	
+	p->reports = op->reports;
+	
 	/* everything is now setup ok */
 	return 1;
 }
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index f27421066bc..4537c6221e1 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1733,18 +1733,19 @@ typedef struct Scene {
 	/* Units */
 	struct UnitSettings unit;
 	
-	/* Grease Pencil */
-	struct bGPdata *gpd;
+	/* Movie Tracking */
+	struct MovieClip *clip;			/* active movie clip */
 
 	/* Physics simulation settings */
 	struct PhysicsSettings physics_settings;
 
 	uint64_t customdata_mask;	/* XXX. runtime flag for drawing, actually belongs in the window, only used by BKE_object_handle_update() */
 	uint64_t customdata_mask_modal; /* XXX. same as above but for temp operator use (gl renders) */
-
-	/* Movie Tracking */
-	struct MovieClip *clip;			/* active movie clip */
-
+	
+	/* Grease Pencil */
+	struct bGPdata *gpd;
+	struct Object *gp_object;     /* default GP object for annotations */
+	
 	/* Color Management */
 	ColorManagedViewSettings view_settings;
 	ColorManagedDisplaySettings display_settings;
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 00b1b53ad71..a1dfd269cca 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -247,6 +247,7 @@ void rna_TextureSlot_update(struct bContext *C, struct PointerRNA *ptr);
 int rna_Armature_object_poll(struct PointerRNA *ptr, struct PointerRNA value);
 int rna_Camera_object_poll(struct PointerRNA *ptr, struct PointerRNA value);
 int rna_Curve_object_poll(struct PointerRNA *ptr, struct PointerRNA value);
+int rna_GPencil_object_poll(struct PointerRNA *ptr, struct PointerRNA value);
 int rna_Lamp_object_poll(struct PointerRNA *ptr, struct PointerRNA value);
 int rna_Lattice_object_poll(struct PointerRNA *ptr, struct PointerRNA value);
 int rna_Mesh_object_poll(struct PointerRNA *ptr, struct PointerRNA value);
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 420e5d98ac7..8bee0e7ee46 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -1681,6 +1681,11 @@ int rna_Lamp_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
 	return ((Object *)value.id.data)->type == OB_LAMP;
 }
 
+int rna_GPencil_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
+{
+	return ((Object *)value.id.data)->type == OB_GPENCIL;
+}
+
 int rna_DupliObject_index_get(PointerRNA *ptr)
 {
 	DupliObject *dob = (DupliObject *)ptr->data;
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index c14dcefa2ca..ead57c67ec4 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -9716,6 +9716,13 @@ void RNA_def_scene(BlenderRNA *brna)
 	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_update(prop, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+	
+	prop = RNA_def_property(srna, "gpencil_object", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "gp_object");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_GPencil_object_poll");
+	RNA_def_property_ui_text(prop, "GPencil Object", "Grease Pencil object where scene annotations are stored by default");
+	RNA_def_property_update(prop, NC_GPENCIL | NA_EDITED, NULL);
 
 	/* active MovieClip */
 	prop = RNA_def_property(srna, "active_clip", PROP_POINTER, PROP_NONE);



More information about the Bf-blender-cvs mailing list