[Bf-blender-cvs] [356ce71a5f2] greasepencil-object: GPencil Editors API: Added utility function to be called to get Copy-on-Write evaluated copies of data

Joshua Leung noreply at git.blender.org
Tue May 1 16:27:18 CEST 2018


Commit: 356ce71a5f23fe154a4471317cbb2b8aaba39668
Author: Joshua Leung
Date:   Tue May 1 15:57:44 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB356ce71a5f23fe154a4471317cbb2b8aaba39668

GPencil Editors API: Added utility function to be called to get Copy-on-Write evaluated copies of data

* Use ED_gpencil_get_active() for writing settings back to the original datablock
  (existing callback used in most operators now)

* Use ED_gpencil_get_active_evaluated() for getting the COW-evaluated geometry
  (i.e. with modifiers, etc.) applied. i.e.,
  ``` const bGPdata *gpd_eval = ED_gpencil_get_active_evaluated(C); ```

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

M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h

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

diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 23fdfa5aae2..f401b1126ea 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -78,6 +78,7 @@
 #include "GPU_immediate_util.h"
 
 #include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
 
 #include "gpencil_intern.h"
 
@@ -199,13 +200,39 @@ bGPdata *ED_gpencil_data_get_active_direct(ID *screen_id, Scene *scene, ScrArea
 	return (gpd_ptr) ? *(gpd_ptr) : NULL;
 }
 
-/* Get the active Grease Pencil datablock */
+/**
+ * Get the active Grease Pencil datablock
+ * \note This is the original (bmain) copy of the datablock, stored in files.
+ *       Do not use for reading evaluated copies of GP Objects data
+ */
 bGPdata *ED_gpencil_data_get_active(const bContext *C)
 {
 	bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
 	return (gpd_ptr) ? *(gpd_ptr) : NULL;
 }
 
+/**
+ * Get the evaluated copy of the active Grease Pencil datablock (where applicable)
+ * - For the 3D View (i.e. "GP Objects"), this gives the evaluated copy of the GP datablock
+ *   (i.e. a copy of the active GP datablock for the active object, where modifiers have been
+ *   applied). This is needed to correctly work with "Copy-on-Write"
+ * - For all other editors (i.e. "GP Annotations"), this just gives the active datablock
+ *   like for ED_gpencil_data_get_active()
+ */
+bGPdata *ED_gpencil_data_get_active_evaluated(const bContext *C)
+{
+	ID *screen_id = (ID *)CTX_wm_screen(C);
+	Scene *scene = CTX_data_scene(C);
+	ScrArea *sa = CTX_wm_area(C);
+	
+	const Depsgraph *depsgraph = CTX_data_depsgraph(C);
+	Object *ob = CTX_data_active_object(C);
+	Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
+	
+	/* if (ob && ob->type == OB_GPENCIL) BLI_assert(ob_eval->data == DEG_get_evaluated_id(ob->data)); */
+	return ED_gpencil_data_get_active_direct(screen_id, scene, sa, ob_eval);
+}
+
 /* -------------------------------------------------------- */
 
 // XXX: this should be removed... We really shouldn't duplicate logic like this!
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index ea82830fc1c..20f6d1be714 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -93,6 +93,7 @@ typedef struct tGPencilSort {
 /* Context-dependent */
 struct bGPdata **ED_gpencil_data_get_pointers(const struct bContext *C, struct PointerRNA *ptr);
 struct bGPdata  *ED_gpencil_data_get_active(const struct bContext *C);
+struct bGPdata  *ED_gpencil_data_get_active_evaluated(const struct bContext *C);
 
 /* Context independent (i.e. each required part is passed in instead) */
 struct bGPdata **ED_gpencil_data_get_pointers_direct(struct ID *screen_id, struct Scene *scene,



More information about the Bf-blender-cvs mailing list