[Bf-blender-cvs] [53238de1329] greasepencil-object: GP Object: Added missing support for the "Apply Transforms" operators

Joshua Leung noreply at git.blender.org
Sat Nov 4 05:49:01 CET 2017


Commit: 53238de1329038a74eac27f8afed217dd09a73e5
Author: Joshua Leung
Date:   Sat Nov 4 17:32:29 2017 +1300
Branches: greasepencil-object
https://developer.blender.org/rB53238de1329038a74eac27f8afed217dd09a73e5

GP Object: Added missing support for the "Apply Transforms" operators

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/object/object_transform.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 15e9930088d..53061f0961d 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -200,5 +200,7 @@ void BKE_gpencil_lattice_clear(struct Object *ob);
 void BKE_gpencil_stroke_normal(const struct bGPDstroke *gps, float r_normal[3]);
 void BKE_gpencil_simplify_stroke(struct bGPDlayer *gpl, struct bGPDstroke *gps, float factor);
 
+void BKE_gpencil_transform(struct bGPdata *gpd, float mat[4][4]);
+
 
 #endif /*  __BKE_GPENCIL_H__ */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index fece1957ad3..ec8e4767468 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -2152,6 +2152,43 @@ BoundBox *BKE_gpencil_boundbox_get(Object *ob)
 	return ob->bb;
 }
 
+/* ************************************************** */
+/* Apply Transforms */
+
+void BKE_gpencil_transform(bGPdata *gpd, float mat[4][4])
+{
+	if (gpd == NULL)
+		return;
+	
+	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		/* FIXME: For now, we just skip parented layers.
+		 * Otherwise, we have to update each frame to find
+		 * the current parent position/effects.
+		 */
+		if (gpl->parent) {
+			continue;
+		}
+		
+		for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+			for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+				bGPDspoint *pt;
+				int i;
+				
+				for (pt = gps->points, i = 0; i < gps->totpoints; pt++, i++) {
+					mul_m4_v3(mat, &pt->x);
+				}
+				
+				/* TODO: Do we need to do this? distortion may mean we need to re-triangulate */
+				gps->flag |= GP_STROKE_RECALC_CACHES;
+				gps->tot_triangles = 0;
+			}
+		}
+	}
+	
+	
+	BKE_gpencil_batch_cache_dirty(gpd);
+}
+
 /* ************************************************** */
 /* GP Object - Vertex Groups */
 
diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c
index 2f768159552..e424880bf49 100644
--- a/source/blender/editors/object/object_transform.c
+++ b/source/blender/editors/object/object_transform.c
@@ -441,7 +441,7 @@ static int apply_objects_internal(
 	/* first check if we can execute */
 	CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
 	{
-		if (ELEM(ob->type, OB_MESH, OB_ARMATURE, OB_LATTICE, OB_MBALL, OB_CURVE, OB_SURF, OB_FONT)) {
+		if (ELEM(ob->type, OB_MESH, OB_ARMATURE, OB_LATTICE, OB_MBALL, OB_CURVE, OB_SURF, OB_FONT, OB_GPENCIL)) {
 			ID *obdata = ob->data;
 			if (ID_REAL_USERS(obdata) > 1) {
 				BKE_reportf(reports, RPT_ERROR,
@@ -486,6 +486,38 @@ static int apply_objects_internal(
 				changed = false;
 			}
 		}
+		
+		if (ob->type == OB_GPENCIL) {
+			bGPdata *gpd = ob->data;
+			if (gpd) {
+				if (gpd->layers.first) {
+					/* Unsupported configuration */
+					bool has_unparented_layers = false;
+				
+					for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+						/* Parented layers aren't supported as we can't easily re-evaluate the scene to sample parent movement */
+						if (gpl->parent == NULL) {
+							has_unparented_layers = true;
+							break;
+						}
+					}
+					
+					if (has_unparented_layers == false) {
+						BKE_reportf(reports, RPT_ERROR,
+						            "Can't apply to a GP datablock where all layers are parented: Object \"%s\", %s \"%s\", aborting",
+						            ob->id.name + 2, BKE_idcode_to_name(ID_GD), gpd->id.name + 2);
+						changed = false;
+					}
+				}
+				else {
+					/* No layers/data */
+					BKE_reportf(reports, RPT_ERROR,
+					            "Can't apply to GP datablock with no layers: Object \"%s\", %s \"%s\", aborting",
+					            ob->id.name + 2, BKE_idcode_to_name(ID_GD), gpd->id.name + 2);
+					changed = false;
+				}
+			}
+		}
 	}
 	CTX_DATA_END;
 	
@@ -582,6 +614,10 @@ static int apply_objects_internal(
 				cu->fsize *= scale;
 			}
 		}
+		else if (ob->type == OB_GPENCIL) {
+			bGPdata *gpd = ob->data;
+			BKE_gpencil_transform(gpd, mat);
+		}
 		else if (ob->type == OB_CAMERA) {
 			MovieClip *clip = BKE_object_movieclip_get(scene, ob, false);



More information about the Bf-blender-cvs mailing list